From 76187c13ed26b092b535ef7f074ab049f9d09d38 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 19 Feb 2025 22:44:45 +0100 Subject: [PATCH 1/3] fix: remove deprecated and unnecessary dependency "boolean" `hasSeconds` has type `boolean`, the same is in the documentation, so using `boolean()` is unnecessary. Moreover, the "boolean" package is marked as deprecated on npmjs.org. --- package.json | 1 - src/job-builder.js | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index f54476f..a0b086d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ ], "dependencies": { "@breejs/later": "^4.2.0", - "boolean": "^3.2.0", "combine-errors": "^3.0.3", "cron-validate": "^1.4.5", "human-interval": "^2.0.1", diff --git a/src/job-builder.js b/src/job-builder.js index 4e77964..272e6eb 100644 --- a/src/job-builder.js +++ b/src/job-builder.js @@ -2,7 +2,6 @@ const { join } = require('node:path'); const isSANB = require('is-string-and-not-blank'); const isValidPath = require('is-valid-path'); const later = require('@breejs/later'); -const { boolean } = require('boolean'); const { isSchedule, parseValue, getJobPath } = require('./job-utils'); later.date.localTime(); @@ -93,9 +92,7 @@ const buildJob = (job, config) => { } else { job.interval = later.parse.cron( job.cron, - boolean( - job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds - ) + job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds ); } } From 05338ce684a9f83ca04095dd2d3da42489a696cf Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 19 Feb 2025 23:02:02 +0100 Subject: [PATCH 2/3] chore: replace unnecessary dependency "is-string-and-not-blank" This package must be a joke, it contains literally three lines of code and another dependency - is-string-blank. The is-string-blank package is 6 years old and the source repository is gone. Moreover, it can be replaced with just a single line of code - it's used to check just a very short strings so the performance difference is negligible, if it still exists. --- package.json | 1 - src/index.js | 2 +- src/job-builder.js | 3 +-- src/job-utils.js | 12 +++++++++++- src/job-validator.js | 9 +++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a0b086d..f461b93 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "combine-errors": "^3.0.3", "cron-validate": "^1.4.5", "human-interval": "^2.0.1", - "is-string-and-not-blank": "^0.0.2", "is-valid-path": "^0.1.1", "ms": "^2.1.3", "p-wait-for": "3", diff --git a/src/index.js b/src/index.js index e463705..ba5eb44 100644 --- a/src/index.js +++ b/src/index.js @@ -9,12 +9,12 @@ 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 { + isSANB, isSchedule, getName, getHumanToMs, diff --git a/src/job-builder.js b/src/job-builder.js index 272e6eb..a92f040 100644 --- a/src/job-builder.js +++ b/src/job-builder.js @@ -1,8 +1,7 @@ const { join } = require('node:path'); -const isSANB = require('is-string-and-not-blank'); const isValidPath = require('is-valid-path'); const later = require('@breejs/later'); -const { isSchedule, parseValue, getJobPath } = require('./job-utils'); +const { isSANB, isSchedule, parseValue, getJobPath } = require('./job-utils'); later.date.localTime(); diff --git a/src/job-utils.js b/src/job-utils.js index 2d6037b..8bb445c 100644 --- a/src/job-utils.js +++ b/src/job-utils.js @@ -1,8 +1,17 @@ const humanInterval = require('human-interval'); -const isSANB = require('is-string-and-not-blank'); const later = require('@breejs/later'); const ms = require('ms'); +/** + * Returns true if `val` is a string and it's not blank. + * + * @param {any} value + * @returns {boolean} + */ +const isSANB = (value) => { + return typeof value === 'string' && value.trim().length > 0; +}; + /** * Naively checks if passed value is of later.js schedule format (https://breejs.github.io/later/schedules.html) * @@ -124,6 +133,7 @@ module.exports = { getJobNames, getJobPath, getName, + isSANB, isSchedule, parseValue }; diff --git a/src/job-validator.js b/src/job-validator.js index d0c6bb7..50336c3 100644 --- a/src/job-validator.js +++ b/src/job-validator.js @@ -2,9 +2,14 @@ const fs = require('node:fs'); const { join } = require('node:path'); 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 { + getName, + isSANB, + isSchedule, + parseValue, + getJobPath +} = require('./job-utils'); const validateReservedJobName = (name) => { // Don't allow a job to have the `index` file name From a15d91cac9aef69457dec91ba142929a3f7d4eef Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 19 Feb 2025 23:25:48 +0100 Subject: [PATCH 3/3] chore: replace is-valid path dependency with is-invalid-path is-valid-path is literally just `isInvalidPath(value) === false`, so we can use is-invalid-path directly and skip one unnecessary dependency. --- package.json | 2 +- src/index.js | 4 ++-- src/job-builder.js | 8 ++++---- src/job-validator.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index f461b93..7e258c0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "combine-errors": "^3.0.3", "cron-validate": "^1.4.5", "human-interval": "^2.0.1", - "is-valid-path": "^0.1.1", + "is-invalid-path": "^0.1.0", "ms": "^2.1.3", "p-wait-for": "3", "safe-timers": "^1.1.0" diff --git a/src/index.js b/src/index.js index ba5eb44..f703964 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const { Worker } = require('node:worker_threads'); const { join, resolve } = require('node:path'); const { debuglog } = require('node:util'); const combineErrors = require('combine-errors'); -const isValidPath = require('is-valid-path'); +const isInvalidPath = require('is-invalid-path'); const later = require('@breejs/later'); const pWaitFor = require('p-wait-for'); const { setTimeout, setInterval } = require('safe-timers'); @@ -203,7 +203,7 @@ class Bree extends EventEmitter { // if ( isSANB(this.config.root) /* istanbul ignore next */ && - isValidPath(this.config.root) + !isInvalidPath(this.config.root) ) { const stats = await fs.promises.stat(this.config.root); if (!stats.isDirectory()) { diff --git a/src/job-builder.js b/src/job-builder.js index a92f040..19e05b3 100644 --- a/src/job-builder.js +++ b/src/job-builder.js @@ -1,5 +1,5 @@ const { join } = require('node:path'); -const isValidPath = require('is-valid-path'); +const isInvalidPath = require('is-invalid-path'); const later = require('@breejs/later'); const { isSANB, isSchedule, parseValue, getJobPath } = require('./job-utils'); @@ -64,14 +64,14 @@ const buildJob = (job, config) => { ) ); - if (isValidPath(path)) { - job.path = path; - } else { + if (isInvalidPath(path)) { // Assume that it's a transformed eval string job.worker = { eval: true, ...job.worker }; + } else { + job.path = path; } } diff --git a/src/job-validator.js b/src/job-validator.js index 50336c3..850654e 100644 --- a/src/job-validator.js +++ b/src/job-validator.js @@ -2,7 +2,7 @@ const fs = require('node:fs'); const { join } = require('node:path'); const combineErrors = require('combine-errors'); const cron = require('cron-validate'); -const isValidPath = require('is-valid-path'); +const isInvalidPath = require('is-invalid-path'); const { getName, isSANB, @@ -94,7 +94,7 @@ const validateJobPath = async (job, prefix, config) => { config.defaultExtension ) ); - if (isValidPath(path)) { + if (!isInvalidPath(path)) { try { const stats = await fs.promises.stat(path); if (!stats.isFile()) {