Skip to content

Commit

Permalink
fix: version bump, attempt to fix ts issues, drop node v12 from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Nov 21, 2023
1 parent 8482d16 commit 6e5504a
Show file tree
Hide file tree
Showing 30 changed files with 39 additions and 85 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
# TODO: re-enable windows
#- windows-latest
node_version:
- 12
- 14
- 16
- 18
Expand Down
3 changes: 2 additions & 1 deletion .xo-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
1 change: 0 additions & 1 deletion examples/commonjs/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
7 changes: 3 additions & 4 deletions examples/email-queue/jobs/email.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
1 change: 0 additions & 1 deletion examples/esmodules/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 0 additions & 1 deletion examples/typescript-esm/jobs/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 0 additions & 1 deletion examples/typescript-jobserver/jobs/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 0 additions & 1 deletion examples/typescript-jobserver/jobs/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 0 additions & 1 deletion examples/typescript/jobs/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 11 additions & 13 deletions src/job-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,24 @@ 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;
} else {
job.interval = later.parse.cron(
job.cron,
boolean(
typeof job.hasSeconds === 'undefined'
? config.hasSeconds
: job.hasSeconds
job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds
)
);
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
27 changes: 10 additions & 17 deletions src/job-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`));
}

Expand All @@ -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) {
Expand All @@ -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)`
Expand All @@ -272,24 +268,21 @@ 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`
)
);
}

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(
Expand Down
2 changes: 0 additions & 2 deletions test/add.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 0 additions & 2 deletions test/get-worker-metadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const path = require('node:path');

const test = require('ava');

const delay = require('delay');
const Bree = require('../src');

Expand Down
3 changes: 0 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 0 additions & 2 deletions test/issues/issue-152.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 0 additions & 2 deletions test/issues/issue-171.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 0 additions & 2 deletions test/issues/issue-180/test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 1 addition & 2 deletions test/job-builder.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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
);
}
Expand Down
1 change: 0 additions & 1 deletion test/job-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const test = require('ava');

const jobUtils = require('../src/job-utils');

test('isSchedule: passes for valid schedule object', (t) => {
Expand Down
1 change: 0 additions & 1 deletion test/job-validator.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
1 change: 0 additions & 1 deletion test/jobs/message.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const process = require('node:process');
const { parentPort } = require('node:worker_threads');

const delay = require('delay');

setInterval(() => {}, 10);
Expand Down
1 change: 0 additions & 1 deletion test/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('node:path');
const test = require('ava');

const Bree = require('../../src');

const root = path.join(__dirname, '..', 'jobs');
Expand Down
1 change: 0 additions & 1 deletion test/plugins/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('node:path');
const test = require('ava');

const Bree = require('../../src');

const root = path.join(__dirname, '..', 'jobs');
Expand Down
Loading

0 comments on commit 6e5504a

Please sign in to comment.