diff --git a/package.json b/package.json index f54476f..7e258c0 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,10 @@ ], "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", - "is-string-and-not-blank": "^0.0.2", - "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 e463705..f703964 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 isInvalidPath = require('is-invalid-path'); const later = require('@breejs/later'); const pWaitFor = require('p-wait-for'); const { setTimeout, setInterval } = require('safe-timers'); const { + isSANB, isSchedule, getName, getHumanToMs, @@ -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 4e77964..19e05b3 100644 --- a/src/job-builder.js +++ b/src/job-builder.js @@ -1,9 +1,7 @@ const { join } = require('node:path'); -const isSANB = require('is-string-and-not-blank'); -const isValidPath = require('is-valid-path'); +const isInvalidPath = require('is-invalid-path'); const later = require('@breejs/later'); -const { boolean } = require('boolean'); -const { isSchedule, parseValue, getJobPath } = require('./job-utils'); +const { isSANB, isSchedule, parseValue, getJobPath } = require('./job-utils'); later.date.localTime(); @@ -66,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; } } @@ -93,9 +91,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 ); } } 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..850654e 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 isInvalidPath = require('is-invalid-path'); +const { + getName, + isSANB, + isSchedule, + parseValue, + getJobPath +} = require('./job-utils'); const validateReservedJobName = (name) => { // Don't allow a job to have the `index` file name @@ -89,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()) {