Skip to content

Commit 6e5504a

Browse files
committed
fix: version bump, attempt to fix ts issues, drop node v12 from tests
1 parent 8482d16 commit 6e5504a

File tree

30 files changed

+39
-85
lines changed

30 files changed

+39
-85
lines changed

Diff for: .github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
# TODO: re-enable windows
1313
#- windows-latest
1414
node_version:
15-
- 12
1615
- 14
1716
- 16
1817
- 18

Diff for: .xo-config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module.exports = {
88
'unicorn/catch-error-name': 'off',
99
'unicorn/require-post-message-target-origin': 'off',
1010
'unicorn/prefer-node-protocol': 'warn',
11-
'unicorn/prefer-top-level-await': 'warn'
11+
'unicorn/prefer-top-level-await': 'warn',
12+
'unicorn/prefer-event-target': 'off'
1213
},
1314
overrides: [
1415
{

Diff for: examples/commonjs/jobs/job.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello Commonjs!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: examples/email-queue/jobs/email.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const os = require('os');
2-
const process = require('process');
3-
const { parentPort } = require('worker_threads');
4-
1+
const os = require('node:os');
2+
const process = require('node:process');
3+
const { parentPort } = require('node:worker_threads');
54
const Cabin = require('cabin');
65
const Email = require('email-templates');
76
const pMap = require('p-map');

Diff for: examples/esmodules/jobs/job.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello ESM!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: examples/typescript-esm/jobs/job.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello TypeScript with ESM!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: examples/typescript-jobserver/jobs/defaults.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello TypeScript Defaults!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: examples/typescript-jobserver/jobs/job.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello TypeScript!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: examples/typescript/jobs/job.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ console.log('Hello TypeScript!');
55

66
// signal to parent that the job is done
77
if (parentPort) parentPort.postMessage('done');
8-
// eslint-disable-next-line unicorn/no-process-exit
98
else process.exit(0);

Diff for: package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@
2727
"@commitlint/cli": "^18.4.3",
2828
"@commitlint/config-conventional": "^18.4.3",
2929
"@goto-bus-stop/envify": "^5.0.0",
30-
"@sinonjs/fake-timers": "^9.1.2",
31-
"@types/node": "^17.0.41",
32-
"@types/safe-timers": "^1.1.0",
33-
"@typescript-eslint/eslint-plugin": "^5.27.1",
34-
"@typescript-eslint/parser": "^5.27.1",
35-
"ava": "^4.3.0",
30+
"@sinonjs/fake-timers": "^11.2.2",
31+
"@types/node": "^20.9.3",
32+
"@types/safe-timers": "^1.1.2",
33+
"@typescript-eslint/eslint-plugin": "^6.12.0",
34+
"@typescript-eslint/parser": "^6.12.0",
35+
"ava": "^5.3.1",
3636
"cross-env": "^7.0.3",
37-
"delay": "^5.0.0",
37+
"delay": "5",
3838
"dtslint": "^4.2.1",
3939
"eslint": "8.39.0",
4040
"eslint-config-xo-lass": "^2.0.1",
4141
"events.once": "^2.0.2",
4242
"fixpack": "^4.0.0",
4343
"husky": "^8.0.3",
44-
"into-stream": "^7.0.0",
44+
"into-stream": "7",
4545
"lint-staged": "^15.1.0",
4646
"nyc": "^15.1.0",
4747
"remark-cli": "11",
4848
"remark-preset-github": "^4.0.4",
49-
"xo": "0.52"
49+
"xo": "0.56"
5050
},
5151
"engines": {
5252
"node": ">=12.17.0 <13.0.0-0||>=13.2.0"

Diff for: src/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ const { pathToFileURL } = require('node:url');
88
const { Worker } = require('node:worker_threads');
99
const { join, resolve } = require('node:path');
1010
const { debuglog } = require('node:util');
11-
1211
const combineErrors = require('combine-errors');
1312
const isSANB = require('is-string-and-not-blank');
1413
const isValidPath = require('is-valid-path');
1514
const later = require('@breejs/later');
1615
const pWaitFor = require('p-wait-for');
1716
const { setTimeout, setInterval } = require('safe-timers');
18-
1917
const {
2018
isSchedule,
2119
getName,
@@ -328,8 +326,7 @@ class Bree extends EventEmitter {
328326
}
329327

330328
if (!this.config.outputWorkerMetadata && !job.outputWorkerMetadata) {
331-
return meta &&
332-
(typeof meta.err !== 'undefined' || typeof meta.message !== 'undefined')
329+
return meta && (meta.err !== undefined || meta.message !== undefined)
333330
? meta
334331
: undefined;
335332
}
@@ -371,8 +368,8 @@ class Bree extends EventEmitter {
371368

372369
debug('starting worker', name);
373370
const object = {
374-
...(this.config.worker ? this.config.worker : {}),
375-
...(job.worker ? job.worker : {}),
371+
...this.config.worker,
372+
...job.worker,
376373
workerData: {
377374
job: {
378375
...job,

Diff for: src/job-builder.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,24 @@ const buildJob = (job, config) => {
7777
}
7878
}
7979

80-
if (typeof job.timeout !== 'undefined') {
80+
if (job.timeout !== undefined) {
8181
job.timeout = parseValue(job.timeout);
8282
}
8383

84-
if (typeof job.interval !== 'undefined') {
84+
if (job.interval !== undefined) {
8585
job.interval = parseValue(job.interval);
8686
}
8787

8888
// Build cron
89-
if (typeof job.cron !== 'undefined') {
89+
if (job.cron !== undefined) {
9090
if (isSchedule(job.cron)) {
9191
job.interval = job.cron;
9292
// Delete job.cron;
9393
} else {
9494
job.interval = later.parse.cron(
9595
job.cron,
9696
boolean(
97-
typeof job.hasSeconds === 'undefined'
98-
? config.hasSeconds
99-
: job.hasSeconds
97+
job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds
10098
)
10199
);
102100
}
@@ -108,10 +106,10 @@ const buildJob = (job, config) => {
108106
if (
109107
Number.isFinite(config.timeout) &&
110108
config.timeout >= 0 &&
111-
typeof job.timeout === 'undefined' &&
112-
typeof job.cron === 'undefined' &&
113-
typeof job.date === 'undefined' &&
114-
typeof job.interval === 'undefined'
109+
job.timeout === undefined &&
110+
job.cron === undefined &&
111+
job.date === undefined &&
112+
job.interval === undefined
115113
) {
116114
job.timeout = config.timeout;
117115
}
@@ -122,9 +120,9 @@ const buildJob = (job, config) => {
122120
if (
123121
((Number.isFinite(config.interval) && config.interval > 0) ||
124122
isSchedule(config.interval)) &&
125-
typeof job.interval === 'undefined' &&
126-
typeof job.cron === 'undefined' &&
127-
typeof job.date === 'undefined'
123+
job.interval === undefined &&
124+
job.cron === undefined &&
125+
job.date === undefined
128126
) {
129127
job.interval = config.interval;
130128
}

Diff for: src/job-validator.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const combineErrors = require('combine-errors');
44
const cron = require('cron-validate');
55
const isSANB = require('is-string-and-not-blank');
66
const isValidPath = require('is-valid-path');
7-
87
const { getName, isSchedule, parseValue, getJobPath } = require('./job-utils');
98

109
const validateReservedJobName = (name) => {
@@ -111,8 +110,8 @@ const cronValidateWithSeconds = (job, config) => {
111110
job.cronValidate && job.cronValidate.preset
112111
? job.cronValidate.preset
113112
: config.cronValidate && config.cronValidate.preset
114-
? config.cronValidate.preset
115-
: 'default';
113+
? config.cronValidate.preset
114+
: 'default';
116115
const override = {
117116
...(config.cronValidate && config.cronValidate.override
118117
? config.cronValidate.override
@@ -223,14 +222,14 @@ const validate = async (job, i, names, config) => {
223222
errors.push(...(await validateJobPath(job, prefix, config)));
224223

225224
// Don't allow users to mix interval AND cron
226-
if (typeof job.interval !== 'undefined' && typeof job.cron !== 'undefined') {
225+
if (job.interval !== undefined && job.cron !== undefined) {
227226
errors.push(
228227
new Error(`${prefix} cannot have both interval and cron configuration`)
229228
);
230229
}
231230

232231
// Don't allow users to mix timeout AND date
233-
if (typeof job.timeout !== 'undefined' && typeof job.date !== 'undefined') {
232+
if (job.timeout !== undefined && job.date !== undefined) {
234233
errors.push(new Error(`${prefix} cannot have both timeout and date`));
235234
}
236235

@@ -240,12 +239,12 @@ const validate = async (job, i, names, config) => {
240239
}
241240

242241
// Validate date
243-
if (typeof job.date !== 'undefined' && !(job.date instanceof Date)) {
242+
if (job.date !== undefined && !(job.date instanceof Date)) {
244243
errors.push(new Error(`${prefix} had an invalid Date of ${job.date}`));
245244
}
246245

247246
for (const prop of ['timeout', 'interval']) {
248-
if (typeof job[prop] !== 'undefined') {
247+
if (job[prop] !== undefined) {
249248
try {
250249
parseValue(job[prop]);
251250
} catch (err) {
@@ -260,10 +259,7 @@ const validate = async (job, i, names, config) => {
260259
}
261260

262261
// Validate hasSeconds
263-
if (
264-
typeof job.hasSeconds !== 'undefined' &&
265-
typeof job.hasSeconds !== 'boolean'
266-
) {
262+
if (job.hasSeconds !== undefined && typeof job.hasSeconds !== 'boolean') {
267263
errors.push(
268264
new Error(
269265
`${prefix} had hasSeconds value of ${job.hasSeconds} (it must be a Boolean)`
@@ -272,24 +268,21 @@ const validate = async (job, i, names, config) => {
272268
}
273269

274270
// Validate cronValidate
275-
if (
276-
typeof job.cronValidate !== 'undefined' &&
277-
typeof job.cronValidate !== 'object'
278-
) {
271+
if (job.cronValidate !== undefined && typeof job.cronValidate !== 'object') {
279272
errors.push(
280273
new Error(
281274
`${prefix} had cronValidate value set, but it must be an Object`
282275
)
283276
);
284277
}
285278

286-
if (typeof job.cron !== 'undefined') {
279+
if (job.cron !== undefined) {
287280
errors.push(...validateCron(job, prefix, config));
288281
}
289282

290283
// Validate closeWorkerAfterMs
291284
if (
292-
typeof job.closeWorkerAfterMs !== 'undefined' &&
285+
job.closeWorkerAfterMs !== undefined &&
293286
(!Number.isFinite(job.closeWorkerAfterMs) || job.closeWorkerAfterMs <= 0)
294287
) {
295288
errors.push(

Diff for: test/add.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const path = require('node:path');
22
const FakeTimers = require('@sinonjs/fake-timers');
3-
43
const test = require('ava');
5-
64
const Bree = require('../src');
75

86
const root = path.join(__dirname, 'jobs');

Diff for: test/get-worker-metadata.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const path = require('node:path');
2-
32
const test = require('ava');
4-
53
const delay = require('delay');
64
const Bree = require('../src');
75

Diff for: test/index.js

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
const path = require('node:path');
22
const { once } = require('node:events');
3-
43
const test = require('ava');
5-
64
const delay = require('delay');
75
const humanInterval = require('human-interval');
86
const FakeTimers = require('@sinonjs/fake-timers');
9-
107
const Bree = require('../src');
118

129
const root = path.join(__dirname, 'jobs');

Diff for: test/issues/issue-152.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const path = require('node:path');
22
const { once } = require('node:events');
3-
43
const test = require('ava');
5-
64
const Bree = require('../../src');
75

86
const root = path.join(__dirname, '../jobs');

Diff for: test/issues/issue-171.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const path = require('node:path');
22
const { SHARE_ENV } = require('node:worker_threads');
3-
43
const test = require('ava');
5-
64
const Bree = require('../../src');
75

86
const root = path.join(__dirname, '../jobs');

Diff for: test/issues/issue-180/test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const path = require('node:path');
22
const { once } = require('node:events');
3-
43
const test = require('ava');
5-
64
const Bree = require('../../../src');
75

86
const root = path.join(__dirname, 'jobs');

Diff for: test/job-builder.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('node:path');
22
const test = require('ava');
33
const later = require('@breejs/later');
4-
54
const jobBuilder = require('../src/job-builder');
65

76
const root = path.join(__dirname, 'jobs');
@@ -18,7 +17,7 @@ const baseConfig = {
1817

1918
function job(t, _job, config, expected) {
2019
t.deepEqual(
21-
jobBuilder(_job ? _job : 'basic', { ...baseConfig, ...config }),
20+
jobBuilder(_job || 'basic', { ...baseConfig, ...config }),
2221
expected
2322
);
2423
}

Diff for: test/job-utils.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const test = require('ava');
2-
32
const jobUtils = require('../src/job-utils');
43

54
test('isSchedule: passes for valid schedule object', (t) => {

Diff for: test/job-validator.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('node:path');
22
const test = require('ava');
33
const later = require('@breejs/later');
4-
54
const jobValidator = require('../src/job-validator');
65

76
const root = path.join(__dirname, 'jobs');

Diff for: test/jobs/message.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const process = require('node:process');
22
const { parentPort } = require('node:worker_threads');
3-
43
const delay = require('delay');
54

65
setInterval(() => {}, 10);

Diff for: test/plugins/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require('node:path');
22
const test = require('ava');
3-
43
const Bree = require('../../src');
54

65
const root = path.join(__dirname, '..', 'jobs');

Diff for: test/plugins/init.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require('node:path');
22
const test = require('ava');
3-
43
const Bree = require('../../src');
54

65
const root = path.join(__dirname, '..', 'jobs');

0 commit comments

Comments
 (0)