From 6e5504a469aec862c3b5b06b5d7247d39b30fe4c Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Mon, 20 Nov 2023 23:46:28 -0600 Subject: [PATCH] fix: version bump, attempt to fix ts issues, drop node v12 from tests --- .github/workflows/ci.yml | 1 - .xo-config.js | 3 ++- examples/commonjs/jobs/job.js | 1 - examples/email-queue/jobs/email.js | 7 +++-- examples/esmodules/jobs/job.js | 1 - examples/typescript-esm/jobs/job.ts | 1 - .../typescript-jobserver/jobs/defaults.ts | 1 - examples/typescript-jobserver/jobs/job.ts | 1 - examples/typescript/jobs/job.ts | 1 - package.json | 18 ++++++------- src/index.js | 9 +++---- src/job-builder.js | 24 ++++++++--------- src/job-validator.js | 27 +++++++------------ test/add.js | 2 -- test/get-worker-metadata.js | 2 -- test/index.js | 3 --- test/issues/issue-152.js | 2 -- test/issues/issue-171.js | 2 -- test/issues/issue-180/test.js | 2 -- test/job-builder.js | 3 +-- test/job-utils.js | 1 - test/job-validator.js | 1 - test/jobs/message.js | 1 - test/plugins/index.js | 1 - test/plugins/init.js | 1 - test/remove.js | 1 - test/run.js | 2 -- test/start.js | 2 -- test/stop.js | 2 -- types/tests.ts | 1 - 30 files changed, 39 insertions(+), 85 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0ecf8c..5d1a8de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ jobs: # TODO: re-enable windows #- windows-latest node_version: - - 12 - 14 - 16 - 18 diff --git a/.xo-config.js b/.xo-config.js index dc59383..bac53ed 100644 --- a/.xo-config.js +++ b/.xo-config.js @@ -8,7 +8,8 @@ module.exports = { 'unicorn/catch-error-name': 'off', 'unicorn/require-post-message-target-origin': 'off', 'unicorn/prefer-node-protocol': 'warn', - 'unicorn/prefer-top-level-await': 'warn' + 'unicorn/prefer-top-level-await': 'warn', + 'unicorn/prefer-event-target': 'off' }, overrides: [ { diff --git a/examples/commonjs/jobs/job.js b/examples/commonjs/jobs/job.js index 6247efb..3782719 100644 --- a/examples/commonjs/jobs/job.js +++ b/examples/commonjs/jobs/job.js @@ -5,5 +5,4 @@ console.log('Hello Commonjs!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/examples/email-queue/jobs/email.js b/examples/email-queue/jobs/email.js index 7ccadf3..4460c20 100644 --- a/examples/email-queue/jobs/email.js +++ b/examples/email-queue/jobs/email.js @@ -1,7 +1,6 @@ -const os = require('os'); -const process = require('process'); -const { parentPort } = require('worker_threads'); - +const os = require('node:os'); +const process = require('node:process'); +const { parentPort } = require('node:worker_threads'); const Cabin = require('cabin'); const Email = require('email-templates'); const pMap = require('p-map'); diff --git a/examples/esmodules/jobs/job.js b/examples/esmodules/jobs/job.js index eb64074..4b2534a 100644 --- a/examples/esmodules/jobs/job.js +++ b/examples/esmodules/jobs/job.js @@ -5,5 +5,4 @@ console.log('Hello ESM!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/examples/typescript-esm/jobs/job.ts b/examples/typescript-esm/jobs/job.ts index dea6f08..473f90a 100644 --- a/examples/typescript-esm/jobs/job.ts +++ b/examples/typescript-esm/jobs/job.ts @@ -5,5 +5,4 @@ console.log('Hello TypeScript with ESM!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/examples/typescript-jobserver/jobs/defaults.ts b/examples/typescript-jobserver/jobs/defaults.ts index 17f7599..dd4e8cc 100644 --- a/examples/typescript-jobserver/jobs/defaults.ts +++ b/examples/typescript-jobserver/jobs/defaults.ts @@ -5,5 +5,4 @@ console.log('Hello TypeScript Defaults!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/examples/typescript-jobserver/jobs/job.ts b/examples/typescript-jobserver/jobs/job.ts index 981171c..9bc76f8 100644 --- a/examples/typescript-jobserver/jobs/job.ts +++ b/examples/typescript-jobserver/jobs/job.ts @@ -5,5 +5,4 @@ console.log('Hello TypeScript!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/examples/typescript/jobs/job.ts b/examples/typescript/jobs/job.ts index 981171c..9bc76f8 100644 --- a/examples/typescript/jobs/job.ts +++ b/examples/typescript/jobs/job.ts @@ -5,5 +5,4 @@ console.log('Hello TypeScript!'); // signal to parent that the job is done if (parentPort) parentPort.postMessage('done'); -// eslint-disable-next-line unicorn/no-process-exit else process.exit(0); diff --git a/package.json b/package.json index e0fc8d2..4d51773 100644 --- a/package.json +++ b/package.json @@ -27,26 +27,26 @@ "@commitlint/cli": "^18.4.3", "@commitlint/config-conventional": "^18.4.3", "@goto-bus-stop/envify": "^5.0.0", - "@sinonjs/fake-timers": "^9.1.2", - "@types/node": "^17.0.41", - "@types/safe-timers": "^1.1.0", - "@typescript-eslint/eslint-plugin": "^5.27.1", - "@typescript-eslint/parser": "^5.27.1", - "ava": "^4.3.0", + "@sinonjs/fake-timers": "^11.2.2", + "@types/node": "^20.9.3", + "@types/safe-timers": "^1.1.2", + "@typescript-eslint/eslint-plugin": "^6.12.0", + "@typescript-eslint/parser": "^6.12.0", + "ava": "^5.3.1", "cross-env": "^7.0.3", - "delay": "^5.0.0", + "delay": "5", "dtslint": "^4.2.1", "eslint": "8.39.0", "eslint-config-xo-lass": "^2.0.1", "events.once": "^2.0.2", "fixpack": "^4.0.0", "husky": "^8.0.3", - "into-stream": "^7.0.0", + "into-stream": "7", "lint-staged": "^15.1.0", "nyc": "^15.1.0", "remark-cli": "11", "remark-preset-github": "^4.0.4", - "xo": "0.52" + "xo": "0.56" }, "engines": { "node": ">=12.17.0 <13.0.0-0||>=13.2.0" diff --git a/src/index.js b/src/index.js index a801132..e463705 100644 --- a/src/index.js +++ b/src/index.js @@ -8,14 +8,12 @@ const { pathToFileURL } = require('node:url'); const { Worker } = require('node:worker_threads'); const { join, resolve } = require('node:path'); const { debuglog } = require('node:util'); - const combineErrors = require('combine-errors'); const isSANB = require('is-string-and-not-blank'); const isValidPath = require('is-valid-path'); const later = require('@breejs/later'); const pWaitFor = require('p-wait-for'); const { setTimeout, setInterval } = require('safe-timers'); - const { isSchedule, getName, @@ -328,8 +326,7 @@ class Bree extends EventEmitter { } if (!this.config.outputWorkerMetadata && !job.outputWorkerMetadata) { - return meta && - (typeof meta.err !== 'undefined' || typeof meta.message !== 'undefined') + return meta && (meta.err !== undefined || meta.message !== undefined) ? meta : undefined; } @@ -371,8 +368,8 @@ class Bree extends EventEmitter { debug('starting worker', name); const object = { - ...(this.config.worker ? this.config.worker : {}), - ...(job.worker ? job.worker : {}), + ...this.config.worker, + ...job.worker, workerData: { job: { ...job, diff --git a/src/job-builder.js b/src/job-builder.js index 7b82547..4e77964 100644 --- a/src/job-builder.js +++ b/src/job-builder.js @@ -77,16 +77,16 @@ const buildJob = (job, config) => { } } - if (typeof job.timeout !== 'undefined') { + if (job.timeout !== undefined) { job.timeout = parseValue(job.timeout); } - if (typeof job.interval !== 'undefined') { + if (job.interval !== undefined) { job.interval = parseValue(job.interval); } // Build cron - if (typeof job.cron !== 'undefined') { + if (job.cron !== undefined) { if (isSchedule(job.cron)) { job.interval = job.cron; // Delete job.cron; @@ -94,9 +94,7 @@ const buildJob = (job, config) => { job.interval = later.parse.cron( job.cron, boolean( - typeof job.hasSeconds === 'undefined' - ? config.hasSeconds - : job.hasSeconds + job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds ) ); } @@ -108,10 +106,10 @@ const buildJob = (job, config) => { if ( Number.isFinite(config.timeout) && config.timeout >= 0 && - typeof job.timeout === 'undefined' && - typeof job.cron === 'undefined' && - typeof job.date === 'undefined' && - typeof job.interval === 'undefined' + job.timeout === undefined && + job.cron === undefined && + job.date === undefined && + job.interval === undefined ) { job.timeout = config.timeout; } @@ -122,9 +120,9 @@ const buildJob = (job, config) => { if ( ((Number.isFinite(config.interval) && config.interval > 0) || isSchedule(config.interval)) && - typeof job.interval === 'undefined' && - typeof job.cron === 'undefined' && - typeof job.date === 'undefined' + job.interval === undefined && + job.cron === undefined && + job.date === undefined ) { job.interval = config.interval; } diff --git a/src/job-validator.js b/src/job-validator.js index 7500298..b73d948 100644 --- a/src/job-validator.js +++ b/src/job-validator.js @@ -4,7 +4,6 @@ const combineErrors = require('combine-errors'); const cron = require('cron-validate'); const isSANB = require('is-string-and-not-blank'); const isValidPath = require('is-valid-path'); - const { getName, isSchedule, parseValue, getJobPath } = require('./job-utils'); const validateReservedJobName = (name) => { @@ -111,8 +110,8 @@ const cronValidateWithSeconds = (job, config) => { job.cronValidate && job.cronValidate.preset ? job.cronValidate.preset : config.cronValidate && config.cronValidate.preset - ? config.cronValidate.preset - : 'default'; + ? config.cronValidate.preset + : 'default'; const override = { ...(config.cronValidate && config.cronValidate.override ? config.cronValidate.override @@ -223,14 +222,14 @@ const validate = async (job, i, names, config) => { errors.push(...(await validateJobPath(job, prefix, config))); // Don't allow users to mix interval AND cron - if (typeof job.interval !== 'undefined' && typeof job.cron !== 'undefined') { + if (job.interval !== undefined && job.cron !== undefined) { errors.push( new Error(`${prefix} cannot have both interval and cron configuration`) ); } // Don't allow users to mix timeout AND date - if (typeof job.timeout !== 'undefined' && typeof job.date !== 'undefined') { + if (job.timeout !== undefined && job.date !== undefined) { errors.push(new Error(`${prefix} cannot have both timeout and date`)); } @@ -240,12 +239,12 @@ const validate = async (job, i, names, config) => { } // Validate date - if (typeof job.date !== 'undefined' && !(job.date instanceof Date)) { + if (job.date !== undefined && !(job.date instanceof Date)) { errors.push(new Error(`${prefix} had an invalid Date of ${job.date}`)); } for (const prop of ['timeout', 'interval']) { - if (typeof job[prop] !== 'undefined') { + if (job[prop] !== undefined) { try { parseValue(job[prop]); } catch (err) { @@ -260,10 +259,7 @@ const validate = async (job, i, names, config) => { } // Validate hasSeconds - if ( - typeof job.hasSeconds !== 'undefined' && - typeof job.hasSeconds !== 'boolean' - ) { + if (job.hasSeconds !== undefined && typeof job.hasSeconds !== 'boolean') { errors.push( new Error( `${prefix} had hasSeconds value of ${job.hasSeconds} (it must be a Boolean)` @@ -272,10 +268,7 @@ const validate = async (job, i, names, config) => { } // Validate cronValidate - if ( - typeof job.cronValidate !== 'undefined' && - typeof job.cronValidate !== 'object' - ) { + if (job.cronValidate !== undefined && typeof job.cronValidate !== 'object') { errors.push( new Error( `${prefix} had cronValidate value set, but it must be an Object` @@ -283,13 +276,13 @@ const validate = async (job, i, names, config) => { ); } - if (typeof job.cron !== 'undefined') { + if (job.cron !== undefined) { errors.push(...validateCron(job, prefix, config)); } // Validate closeWorkerAfterMs if ( - typeof job.closeWorkerAfterMs !== 'undefined' && + job.closeWorkerAfterMs !== undefined && (!Number.isFinite(job.closeWorkerAfterMs) || job.closeWorkerAfterMs <= 0) ) { errors.push( diff --git a/test/add.js b/test/add.js index 9d0d045..bcc18b6 100644 --- a/test/add.js +++ b/test/add.js @@ -1,8 +1,6 @@ const path = require('node:path'); const FakeTimers = require('@sinonjs/fake-timers'); - const test = require('ava'); - const Bree = require('../src'); const root = path.join(__dirname, 'jobs'); diff --git a/test/get-worker-metadata.js b/test/get-worker-metadata.js index a020d2a..7c2e392 100644 --- a/test/get-worker-metadata.js +++ b/test/get-worker-metadata.js @@ -1,7 +1,5 @@ const path = require('node:path'); - const test = require('ava'); - const delay = require('delay'); const Bree = require('../src'); diff --git a/test/index.js b/test/index.js index f480d7e..299c4d2 100644 --- a/test/index.js +++ b/test/index.js @@ -1,12 +1,9 @@ const path = require('node:path'); const { once } = require('node:events'); - const test = require('ava'); - const delay = require('delay'); const humanInterval = require('human-interval'); const FakeTimers = require('@sinonjs/fake-timers'); - const Bree = require('../src'); const root = path.join(__dirname, 'jobs'); diff --git a/test/issues/issue-152.js b/test/issues/issue-152.js index cd5c8ec..1ed2e04 100644 --- a/test/issues/issue-152.js +++ b/test/issues/issue-152.js @@ -1,8 +1,6 @@ const path = require('node:path'); const { once } = require('node:events'); - const test = require('ava'); - const Bree = require('../../src'); const root = path.join(__dirname, '../jobs'); diff --git a/test/issues/issue-171.js b/test/issues/issue-171.js index 2442759..7ec2b58 100644 --- a/test/issues/issue-171.js +++ b/test/issues/issue-171.js @@ -1,8 +1,6 @@ const path = require('node:path'); const { SHARE_ENV } = require('node:worker_threads'); - const test = require('ava'); - const Bree = require('../../src'); const root = path.join(__dirname, '../jobs'); diff --git a/test/issues/issue-180/test.js b/test/issues/issue-180/test.js index 892b890..1485352 100644 --- a/test/issues/issue-180/test.js +++ b/test/issues/issue-180/test.js @@ -1,8 +1,6 @@ const path = require('node:path'); const { once } = require('node:events'); - const test = require('ava'); - const Bree = require('../../../src'); const root = path.join(__dirname, 'jobs'); diff --git a/test/job-builder.js b/test/job-builder.js index 15d5b5e..99c6de7 100644 --- a/test/job-builder.js +++ b/test/job-builder.js @@ -1,7 +1,6 @@ const path = require('node:path'); const test = require('ava'); const later = require('@breejs/later'); - const jobBuilder = require('../src/job-builder'); const root = path.join(__dirname, 'jobs'); @@ -18,7 +17,7 @@ const baseConfig = { function job(t, _job, config, expected) { t.deepEqual( - jobBuilder(_job ? _job : 'basic', { ...baseConfig, ...config }), + jobBuilder(_job || 'basic', { ...baseConfig, ...config }), expected ); } diff --git a/test/job-utils.js b/test/job-utils.js index 8af4e8a..287f79b 100644 --- a/test/job-utils.js +++ b/test/job-utils.js @@ -1,5 +1,4 @@ const test = require('ava'); - const jobUtils = require('../src/job-utils'); test('isSchedule: passes for valid schedule object', (t) => { diff --git a/test/job-validator.js b/test/job-validator.js index d04a1a6..7e5dab8 100644 --- a/test/job-validator.js +++ b/test/job-validator.js @@ -1,7 +1,6 @@ const path = require('node:path'); const test = require('ava'); const later = require('@breejs/later'); - const jobValidator = require('../src/job-validator'); const root = path.join(__dirname, 'jobs'); diff --git a/test/jobs/message.js b/test/jobs/message.js index 7ae5739..ff1be8d 100644 --- a/test/jobs/message.js +++ b/test/jobs/message.js @@ -1,6 +1,5 @@ const process = require('node:process'); const { parentPort } = require('node:worker_threads'); - const delay = require('delay'); setInterval(() => {}, 10); diff --git a/test/plugins/index.js b/test/plugins/index.js index e20256d..e601448 100644 --- a/test/plugins/index.js +++ b/test/plugins/index.js @@ -1,6 +1,5 @@ const path = require('node:path'); const test = require('ava'); - const Bree = require('../../src'); const root = path.join(__dirname, '..', 'jobs'); diff --git a/test/plugins/init.js b/test/plugins/init.js index 2d342bb..a7ad86c 100644 --- a/test/plugins/init.js +++ b/test/plugins/init.js @@ -1,6 +1,5 @@ const path = require('node:path'); const test = require('ava'); - const Bree = require('../../src'); const root = path.join(__dirname, '..', 'jobs'); diff --git a/test/remove.js b/test/remove.js index 7fb8970..4ec815b 100644 --- a/test/remove.js +++ b/test/remove.js @@ -1,7 +1,6 @@ const path = require('node:path'); const delay = require('delay'); const test = require('ava'); - const Bree = require('../src'); const root = path.join(__dirname, 'jobs'); diff --git a/test/run.js b/test/run.js index ab75d40..fd91b48 100644 --- a/test/run.js +++ b/test/run.js @@ -1,8 +1,6 @@ const path = require('node:path'); const { once } = require('node:events'); - const test = require('ava'); - const delay = require('delay'); const Bree = require('../src'); diff --git a/test/start.js b/test/start.js index e40163f..5276ac5 100644 --- a/test/start.js +++ b/test/start.js @@ -1,9 +1,7 @@ const path = require('node:path'); const { once } = require('node:events'); const FakeTimers = require('@sinonjs/fake-timers'); - const test = require('ava'); - const later = require('@breejs/later'); const delay = require('delay'); const Bree = require('../src'); diff --git a/test/stop.js b/test/stop.js index f841a10..0486f05 100644 --- a/test/stop.js +++ b/test/stop.js @@ -1,8 +1,6 @@ const path = require('node:path'); const { once } = require('node:events'); - const test = require('ava'); - const delay = require('delay'); const Bree = require('../src'); diff --git a/types/tests.ts b/types/tests.ts index a971022..77fdb20 100644 --- a/types/tests.ts +++ b/types/tests.ts @@ -1,5 +1,4 @@ import * as path from 'node:path'; - import * as Bree from 'bree'; Bree.extend((o, b) => {}, {});