From 675225b50e26dbbfe60853c9a1e169fad45c18c2 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 15:42:34 -0600 Subject: [PATCH 1/9] feat: support ecmascript syntax --- .gitignore | 1 + README.md | 2 +- package.json | 72 +++++++++++++++------- src/logger.ts | 4 +- test/logger.spec.ts | 130 ---------------------------------------- test/production.spec.ts | 80 +++++++++++++++++++++++++ test/test.spec.ts | 47 +++++++++++++++ tsconfig.cjs.json | 14 +++++ tsconfig.eslint.json | 2 +- tsconfig.json | 7 ++- 10 files changed, 199 insertions(+), 160 deletions(-) delete mode 100644 test/logger.spec.ts create mode 100644 test/production.spec.ts create mode 100644 test/test.spec.ts create mode 100644 tsconfig.cjs.json diff --git a/.gitignore b/.gitignore index e6c82ad..1837f26 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ web_modules/ # TypeScript cache *.tsbuildinfo +.tsimp/ # Optional npm cache directory .npm diff --git a/README.md b/README.md index f24a21e..a72cf62 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It will pretty-print logs when run locally, but it will write logs in JSON when ## Install ``` -npm i @byu-oit/logger +npm i @byu-oit/logger ``` ## Usage diff --git a/package.json b/package.json index 3d60a12..055242e 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "@byu-oit/logger", "version": "0.4.2", "description": "Default configuration for pino logger", + "engines": { + "node": ">=18" + }, "contributors": [ { "name": "Scott Hutching", @@ -12,56 +15,79 @@ "email": "stuft2@byu.edu" } ], - "main": "dist/logger.js", - "types": "dist/logger.d.ts", + "type": "module", + "main": "./dist/cjs/index.js", + "types": "./dist/cjs/index.d.ts", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/esm/index.d.ts", + "default": "./dist/esm/index.js" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + } + } + }, "files": [ "dist" ], "scripts": { - "build": "npx rimraf dist && tsc", - "coverage": "npm run test -- --coverage || exit 0", + "build": "rimraf dist && concurrently \"npm:build:*\" -c cyanBright", + "build:cjs": "tsc -p tsconfig.cjs.json && echo-cli \"{\\\"type\\\": \\\"commonjs\\\"}\" > dist/cjs/package.json", + "build:esm": "tsc -p tsconfig.json && echo-cli \"{\\\"type\\\": \\\"module\\\"}\" > dist/esm/package.json", + "clean": "rimraf dist", + "coverage": "c8 ava", "lint": "npx ts-standard | snazzy", "lint:fix": "npx ts-standard --fix | snazzy", - "test": "jest", + "test": "ava", "prepublishOnly": "npm run build" }, "author": "Brigham Young University - Office of Information Technology", "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "git+https://github.com/byu-oit/logger.git" + }, + "bugs": { + "url": "https://github.com/byu-oit/logger/issues" + }, "dependencies": { "deepmerge": "^4.2.2", "pino": "^8.11.0", "pino-http": "^6.6.0" }, "devDependencies": { - "@tsconfig/node12": "^1.0.11", + "@tsconfig/node18": "^18.2.4", "@types/jest": "^29.5.0", - "@types/node": "^16.9.1", - "jest": "^29.5.0", + "@types/node": "^18.19.42", + "@types/sinon": "^17.0.3", + "ava": "^6.1.3", + "c8": "^10.1.2", + "concurrently": "^8.2.2", + "echo-cli": "^2.0.0", "lint-staged": "^12.0.2", "pino-pretty": "^10.0.0", + "rimraf": "^6.0.1", + "sinon": "^18.0.0", "snazzy": "^9.0.0", - "ts-jest": "^29.1.0", + "tsimp": "^2.0.11", "typescript": "^5.0.3" }, "optionalDependencies": { "pino-pretty": ">=7" }, - "engines": { - "node": ">=12" - }, - "jest": { - "transform": { - "^.+\\.(ts|tsx)$": "ts-jest" - } - }, "lint-staged": { "*.ts": "npm run lint:fix" }, - "repository": { - "type": "git", - "url": "git+https://github.com/byu-oit/logger.git" - }, - "bugs": { - "url": "https://github.com/byu-oit/logger/issues" + "ava": { + "extensions": { + "ts": "module" + }, + "nodeArguments": [ + "--import=tsimp" + ] } } diff --git a/src/logger.ts b/src/logger.ts index 03c9d5a..98504ba 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,6 +1,6 @@ -import { Logger, LoggerOptions, pino } from 'pino' -import { getLevel, isInstalled, isProduction } from './util' import deepmerge from 'deepmerge' +import { Logger, LoggerOptions, pino } from 'pino' +import { getLevel, isInstalled, isProduction } from './util.js' export function ByuLogger (options?: LoggerOptions): Logger { const defaultOptions: LoggerOptions = { diff --git a/test/logger.spec.ts b/test/logger.spec.ts deleted file mode 100644 index 62a4ded..0000000 --- a/test/logger.spec.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { ByuLogger } from '../src/logger' -import { Logger } from 'pino' - -const jan1st = new Date(2021, 0, 1) -const dateNowStub = jest.fn(() => jan1st.getTime()) -const realDateNow = Date.now.bind(global.Date) -let logged: string = '' -let logger: Logger - -beforeAll(() => { - process.stdout.write = (buffer: string) => { - logged += buffer - return true - } -}) - -beforeEach(() => { - logged = '' - global.Date.now = dateNowStub -}) - -afterEach(() => { - global.Date.now = realDateNow -}) - -// Pino v7+ implements transports which are problematic in Jest environments. -// Docs: https://github.com/pinojs/pino-pretty#usage-with-jest -// describe('In local env', () => { -// beforeEach(() => { -// process.env.NODE_ENV = 'local' -// logger = ByuLogger() -// }) -// -// test('default logger should default to debug level', () => { -// logger.debug('debug works') -// -// expect(logger.level).toEqual('debug') -// expect(logged).toContain('DEBUG') // must contain the debug level -// expect(logged).toContain('debug works') // must contain the message -// }) -// -// test('default logger should still display info', () => { -// logger.info('info works') -// -// expect(logged).toContain('INFO') // must contain the info level -// expect(logged).toContain('info works') // must contain the message -// }) -// -// test('default logger displays logs with iso datetime format', () => { -// logger.info('iso date works') -// -// expect(logged).toContain(`[${jan1st.toISOString()}]`) -// }) -// -// test('default logger displays logs in pretty printed format', () => { -// logger.info('pretty print works') -// -// expect(logged).not.toContain('{') -// }) -// -// // TODO - Figure out how to stub `require` to throw a fake MODULE_NOT_FOUND error -// // test('default logger does not pretty print if pino-pretty is not installed', async () => { -// // proxyquire('../src/logger', { -// // 'pino-pretty': null -// // }) -// // -// // const logger = ByuLogger() -// // logger.info('pretty print disabled') -// // expect(logged).toContain('{') -// // }) -// }) - -describe('In production env', () => { - beforeEach(() => { - process.env.NODE_ENV = 'production' - logger = ByuLogger() - }) - - test('default logger should default to info level', () => { - logger.debug('debug does not work') - - expect(logger.level).toEqual('info') - expect(logged).toEqual('') // no logs should have happened - }) - - test('default logger displays logs in JSON format', () => { - logger.info('json works') - - expect(logged).toContain('{') - const jsonLogEntry = JSON.parse(logged) - expect(jsonLogEntry.message).toBeTruthy() - expect(jsonLogEntry.level).toBeTruthy() - expect(jsonLogEntry.time).toBeTruthy() - }) - - test('default logger should display info logs', () => { - logger.info('info works') - - const jsonLogEntry = JSON.parse(logged) - expect(jsonLogEntry.message).toEqual('info works') - expect(jsonLogEntry.level).toEqual('info') - }) - - test('default logger displays logs with epoch datetime format', () => { - logger.info('iso date works') - - const jsonLogEntry = JSON.parse(logged) - expect(jsonLogEntry.time).toEqual(jan1st.getTime()) - }) -}) - -describe('In test env', () => { - beforeEach(() => { - process.env.NODE_ENV = 'test' - logger = ByuLogger() - }) - - test('default logger should default to silent level', () => { - logger.debug('debug does not work') - - expect(logger.level).toEqual('silent') - expect(logged).toEqual('') // no logs should have happened - }) - - test('default logger should not display logs', () => { - logger.info('info works') - - expect(logged).toEqual('') - }) -}) diff --git a/test/production.spec.ts b/test/production.spec.ts new file mode 100644 index 0000000..3a9c8dd --- /dev/null +++ b/test/production.spec.ts @@ -0,0 +1,80 @@ +import ava, { TestFn } from 'ava' +import sinon, { SinonFakeTimers } from 'sinon' +import { Logger } from 'pino' +import { ByuLogger } from '../src/logger.js' + +type Context = { + logged: string + logger: Logger + clock: SinonFakeTimers + now: Date +} + +const test = ava as TestFn + +test.beforeEach((t) => { + /* Capture the stdout pipe */ + process.stdout.write = (buffer: string) => { + t.context.logged += buffer + return true + } + + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) + + process.env.NODE_ENV = 'production' + t.context.logged = '' + t.context.logger = ByuLogger() +}) + +test.afterEach((t) => { + t.context.clock.restore() +}) + +test.serial('default logger should default to info level', (t) => { + t.context.logger.debug('debug does not work') + + t.is(t.context.logger.level, 'info') + t.is(t.context.logged, '') // no logs should have happened +}) + +test.serial('default logger displays logs in JSON format', (t) => { + t.context.logger.info('json works') + + try { + const parsedLog = JSON.parse(t.context.logged) + t.truthy(parsedLog.message) + t.truthy(parsedLog.level) + t.truthy(parsedLog.time) + } catch (e) { + t.log(e) + t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + } +}) + +test.serial('default logger should display info logs', (t) => { + t.context.logger.info('info works') + + try { + const parsedLog = JSON.parse(t.context.logged) + t.is(parsedLog.message, 'info works') + t.is(parsedLog.level, 'info') + } catch (e) { + t.log(e) + t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + } +}) + +test.serial('default logger displays logs with epoch datetime format', (t) => { + t.context.logger.info('iso date works') + + try { + const parsedLog = JSON.parse(t.context.logged) + t.is(parsedLog.time, t.context.now.getTime()) + } catch (e) { + t.log(e) + t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + } +}) diff --git a/test/test.spec.ts b/test/test.spec.ts new file mode 100644 index 0000000..6e41405 --- /dev/null +++ b/test/test.spec.ts @@ -0,0 +1,47 @@ +import ava, { TestFn } from 'ava' +import sinon, { SinonFakeTimers } from 'sinon' +import { Logger } from 'pino' +import { ByuLogger } from '../src/logger.js' + +type Context = { + logged: string + logger: Logger + clock: SinonFakeTimers + now: Date +} + +const test = ava as TestFn + +test.beforeEach((t) => { + /* Capture the stdout pipe */ + process.stdout.write = (buffer: string) => { + t.context.logged += buffer + return true + } + + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) + + process.env.NODE_ENV = 'test' + t.context.logged = '' + t.context.logger = ByuLogger() +}) + +test.afterEach((t) => { + t.context.clock.restore() +}) + +test.serial('default logger should default to silent level', (t) => { + t.context.logger.debug('debug does not work') + + t.is(t.context.logger.level, 'silent') + t.is(t.context.logged, '') // no logs should have happened +}) + +test.serial('default logger should not display logs', (t) => { + t.context.logger.info('info works') + + t.is(t.context.logged, '') +}) diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..d79581a --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,14 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "module": "CommonJS", + "moduleResolution": "node", + "declarationDir": "dist/cjs", + "outDir": "dist/cjs" + }, + "include": [ + "src" + ] +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 59d64d7..dceb2b9 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,6 +1,6 @@ { "extends": "./tsconfig.json", "include": [ - "test/**/*" + "test" ] } diff --git a/tsconfig.json b/tsconfig.json index b75f6f7..c624ec8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,11 @@ { - "extends": "@tsconfig/node12/tsconfig.json", + "extends": "@tsconfig/node18/tsconfig.json", "compilerOptions": { "declaration": true, - "outDir": "dist" + "declarationDir": "dist/esm", + "outDir": "dist/esm" }, "include": [ - "src/**/*" + "src" ] } From 0931d20db56e434e908686b4a955b0a75242eea4 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 15:57:58 -0600 Subject: [PATCH 2/9] chore: update dependencies --- package.json | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 055242e..9293cb3 100644 --- a/package.json +++ b/package.json @@ -55,26 +55,24 @@ "url": "https://github.com/byu-oit/logger/issues" }, "dependencies": { - "deepmerge": "^4.2.2", - "pino": "^8.11.0", - "pino-http": "^6.6.0" + "deepmerge": "^4.3.1", + "pino": "^9.3.2", + "pino-http": "^10.2.0" }, "devDependencies": { "@tsconfig/node18": "^18.2.4", - "@types/jest": "^29.5.0", "@types/node": "^18.19.42", "@types/sinon": "^17.0.3", "ava": "^6.1.3", "c8": "^10.1.2", "concurrently": "^8.2.2", "echo-cli": "^2.0.0", - "lint-staged": "^12.0.2", - "pino-pretty": "^10.0.0", + "pino-pretty": "^11.2.2", "rimraf": "^6.0.1", "sinon": "^18.0.0", "snazzy": "^9.0.0", "tsimp": "^2.0.11", - "typescript": "^5.0.3" + "typescript": "^5.5.4" }, "optionalDependencies": { "pino-pretty": ">=7" From bf35dbc4e9a524877b62467a9b3ab87afb44b32a Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:03:16 -0600 Subject: [PATCH 3/9] style: lint --- test/production.spec.ts | 8 ++++---- test/test.spec.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/production.spec.ts b/test/production.spec.ts index 3a9c8dd..da8bd64 100644 --- a/test/production.spec.ts +++ b/test/production.spec.ts @@ -3,7 +3,7 @@ import sinon, { SinonFakeTimers } from 'sinon' import { Logger } from 'pino' import { ByuLogger } from '../src/logger.js' -type Context = { +interface Context { logged: string logger: Logger clock: SinonFakeTimers @@ -50,7 +50,7 @@ test.serial('default logger displays logs in JSON format', (t) => { t.truthy(parsedLog.time) } catch (e) { t.log(e) - t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + t.fail('The log format should be stringified JSON but parsing failed. See the logged error for details.') } }) @@ -63,7 +63,7 @@ test.serial('default logger should display info logs', (t) => { t.is(parsedLog.level, 'info') } catch (e) { t.log(e) - t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + t.fail('The log format should be stringified JSON but parsing failed. See the logged error for details.') } }) @@ -75,6 +75,6 @@ test.serial('default logger displays logs with epoch datetime format', (t) => { t.is(parsedLog.time, t.context.now.getTime()) } catch (e) { t.log(e) - t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) + t.fail('The log format should be stringified JSON but parsing failed. See the logged error for details.') } }) diff --git a/test/test.spec.ts b/test/test.spec.ts index 6e41405..274e9e3 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -3,7 +3,7 @@ import sinon, { SinonFakeTimers } from 'sinon' import { Logger } from 'pino' import { ByuLogger } from '../src/logger.js' -type Context = { +interface Context { logged: string logger: Logger clock: SinonFakeTimers From 0968693b62c8757f3f45bc0554cc6dd56138d5bb Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:06:35 -0600 Subject: [PATCH 4/9] ci: bump action versions --- .github/workflows/ci.yml | 18 +++++++++--------- .github/workflows/deploy.yml | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22ffa74..7ea0f68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: - .github/workflows/bump.yml env: - node_version: "18.x" + node_version: "20.x" jobs: test: @@ -20,13 +20,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x] + node-version: [16.x, 18.x, 20.x] fail-fast: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} @@ -42,7 +42,7 @@ jobs: - name: Upload coverage to Codecov if: ${{ matrix.node-version == env.node_version }} # just run coverage if node 16 - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true @@ -51,10 +51,10 @@ jobs: name: Lint Module runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ env.node_version }} @@ -70,14 +70,14 @@ jobs: runs-on: ubuntu-latest needs: [test, lint] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - id: version run: echo ::set-output name=version::$(node -p 'require("./package.json").version') - name: Draft release id: draft - uses: release-drafter/release-drafter@v5 + uses: release-drafter/release-drafter@v6 with: version: ${{ steps.version.outputs.version }} env: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6f81061..6720dfb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,7 +12,7 @@ on: - .github/workflows/bump.yml env: - node_version: "18.x" + node_version: "20.x" jobs: env: @@ -41,10 +41,10 @@ jobs: name: Test Module runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ env.node_version }} @@ -56,7 +56,7 @@ jobs: npm run coverage - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true @@ -65,10 +65,10 @@ jobs: name: Lint Module runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ env.node_version }} @@ -86,7 +86,7 @@ jobs: matrix: ${{ fromJson(needs.env.outputs.matrix) }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Disallow Concurrent Runs uses: byu-oit/github-action-disallow-concurrent-runs@v2 @@ -94,7 +94,7 @@ jobs: token: ${{ github.token }} - name: Set up Node.js - uses: actions/setup-node@v2.1.4 + uses: actions/setup-node@v4 with: node-version: ${{ env.node_version }} registry-url: ${{ matrix.registry.url }} @@ -117,13 +117,13 @@ jobs: runs-on: ubuntu-latest needs: [publish] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - id: version run: echo ::set-output name=version::$(node -p 'require("./package.json").version') - name: Publish Release - uses: release-drafter/release-drafter@v5 + uses: release-drafter/release-drafter@v6 with: publish: true version: ${{ steps.version.outputs.version }} From 50189ad4531f7a22142d7f9213bd4e21d47779c6 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:20:52 -0600 Subject: [PATCH 5/9] test: fix faked clock --- test/production.spec.ts | 14 ++++++++------ test/test.spec.ts | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/production.spec.ts b/test/production.spec.ts index da8bd64..4a25238 100644 --- a/test/production.spec.ts +++ b/test/production.spec.ts @@ -12,6 +12,13 @@ interface Context { const test = ava as TestFn +test.before((t) => { + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) +}) + test.beforeEach((t) => { /* Capture the stdout pipe */ process.stdout.write = (buffer: string) => { @@ -19,17 +26,12 @@ test.beforeEach((t) => { return true } - /* Stub the date time */ - const jan1st = new Date(2021, 0, 1) - t.context.now = jan1st - t.context.clock = sinon.useFakeTimers(jan1st.getTime()) - process.env.NODE_ENV = 'production' t.context.logged = '' t.context.logger = ByuLogger() }) -test.afterEach((t) => { +test.after((t) => { t.context.clock.restore() }) diff --git a/test/test.spec.ts b/test/test.spec.ts index 274e9e3..8c98003 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -12,6 +12,13 @@ interface Context { const test = ava as TestFn +test.before((t) => { + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) +}) + test.beforeEach((t) => { /* Capture the stdout pipe */ process.stdout.write = (buffer: string) => { @@ -19,17 +26,12 @@ test.beforeEach((t) => { return true } - /* Stub the date time */ - const jan1st = new Date(2021, 0, 1) - t.context.now = jan1st - t.context.clock = sinon.useFakeTimers(jan1st.getTime()) - process.env.NODE_ENV = 'test' t.context.logged = '' t.context.logger = ByuLogger() }) -test.afterEach((t) => { +test.after((t) => { t.context.clock.restore() }) From f9dbc1638f93316cb575ba7da1f6ec34e576f91a Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:22:09 -0600 Subject: [PATCH 6/9] ci: drop tests on node.js 16 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ea0f68..dbc8f33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: - .github/workflows/bump.yml env: - node_version: "20.x" + node_version: "22.x" jobs: test: @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x, 22.x] fail-fast: false steps: - uses: actions/checkout@v4 From 1df242c67eada0d291e24dfb9267cb2046a98b26 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:23:16 -0600 Subject: [PATCH 7/9] style: lint --- test/production.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/production.spec.ts b/test/production.spec.ts index 4a25238..a3304a3 100644 --- a/test/production.spec.ts +++ b/test/production.spec.ts @@ -14,9 +14,9 @@ const test = ava as TestFn test.before((t) => { /* Stub the date time */ - const jan1st = new Date(2021, 0, 1) - t.context.now = jan1st - t.context.clock = sinon.useFakeTimers(jan1st.getTime()) + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) }) test.beforeEach((t) => { From 586894042b9671856ea1b80b0fdaa610ce7d72b7 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:35:45 -0600 Subject: [PATCH 8/9] build: parallelize build --- .github/workflows/ci.yml | 9 +++++---- .github/workflows/deploy.yml | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbc8f33..b45f9ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,8 @@ jobs: strategy: matrix: node-version: [18.x, 20.x, 22.x] + node_index: [0, 1] + total_nodes: [2] fail-fast: false steps: - uses: actions/checkout@v4 @@ -34,11 +36,10 @@ jobs: run: npm install - name: npm test - run: npm run test - - - name: npm test with coverage - if: ${{ matrix.node-version == env.node_version }} # just run coverage if node 16 run: npm run coverage + env: + CI_NODE_INDEX: ${{ matrix.node_index }} + CI_NODE_TOTAL: ${{ matrix.total_nodes }} - name: Upload coverage to Codecov if: ${{ matrix.node-version == env.node_version }} # just run coverage if node 16 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6720dfb..53ce90b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,6 +40,11 @@ jobs: test: name: Test Module runs-on: ubuntu-latest + strategy: + matrix: + node_index: [0, 1] + total_nodes: [2] + fail-fast: false steps: - uses: actions/checkout@v4 @@ -52,8 +57,10 @@ jobs: run: npm install - name: npm test - run: | - npm run coverage + run: npm run coverage + env: + CI_NODE_INDEX: ${{ matrix.node_index }} + CI_NODE_TOTAL: ${{ matrix.total_nodes }} - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From 461eaeb89b5eed915a91d2655103c1c1a90c2b42 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:40:50 -0600 Subject: [PATCH 9/9] chore: bump version 1.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9293cb3..8e673b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@byu-oit/logger", - "version": "0.4.2", + "version": "1.0.0", "description": "Default configuration for pino logger", "engines": { "node": ">=18"