Skip to content

Commit 13b797f

Browse files
authored
Merge pull request #260 from jirutka/deps
Cleanup dependencies
2 parents 95d1800 + f6fbd4d commit 13b797f

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
],
1414
"dependencies": {
1515
"@breejs/later": "^4.2.0",
16-
"boolean": "^3.2.0",
1716
"combine-errors": "^3.0.3",
1817
"cron-validate": "^1.5.3",
1918
"human-interval": "^2.0.1",
20-
"is-string-and-not-blank": "^0.0.2",
21-
"is-valid-path": "^0.1.1",
19+
"is-invalid-path": "^0.1.0",
2220
"ms": "^2.1.3",
2321
"p-wait-for": "3",
2422
"safe-timers": "^1.1.0"

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const { Worker } = require('node:worker_threads');
99
const { join, resolve } = require('node:path');
1010
const { debuglog } = require('node:util');
1111
const combineErrors = require('combine-errors');
12-
const isSANB = require('is-string-and-not-blank');
13-
const isValidPath = require('is-valid-path');
12+
const isInvalidPath = require('is-invalid-path');
1413
const later = require('@breejs/later');
1514
const pWaitFor = require('p-wait-for');
1615
const { setTimeout, setInterval } = require('safe-timers');
1716
const {
17+
isSANB,
1818
isSchedule,
1919
getName,
2020
getHumanToMs,
@@ -203,7 +203,7 @@ class Bree extends EventEmitter {
203203
// <https://nodejs.org/api/esm.html#esm_mandatory_file_extensions>
204204
if (
205205
isSANB(this.config.root) /* istanbul ignore next */ &&
206-
isValidPath(this.config.root)
206+
!isInvalidPath(this.config.root)
207207
) {
208208
const stats = await fs.promises.stat(this.config.root);
209209
if (!stats.isDirectory()) {

src/job-builder.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const { join } = require('node:path');
2-
const isSANB = require('is-string-and-not-blank');
3-
const isValidPath = require('is-valid-path');
2+
const isInvalidPath = require('is-invalid-path');
43
const later = require('@breejs/later');
5-
const { boolean } = require('boolean');
6-
const { isSchedule, parseValue, getJobPath } = require('./job-utils');
4+
const { isSANB, isSchedule, parseValue, getJobPath } = require('./job-utils');
75

86
later.date.localTime();
97

@@ -66,14 +64,14 @@ const buildJob = (job, config) => {
6664
)
6765
);
6866

69-
if (isValidPath(path)) {
70-
job.path = path;
71-
} else {
67+
if (isInvalidPath(path)) {
7268
// Assume that it's a transformed eval string
7369
job.worker = {
7470
eval: true,
7571
...job.worker
7672
};
73+
} else {
74+
job.path = path;
7775
}
7876
}
7977

@@ -93,9 +91,7 @@ const buildJob = (job, config) => {
9391
} else {
9492
job.interval = later.parse.cron(
9593
job.cron,
96-
boolean(
97-
job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds
98-
)
94+
job.hasSeconds === undefined ? config.hasSeconds : job.hasSeconds
9995
);
10096
}
10197
}

src/job-utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
const humanInterval = require('human-interval');
2-
const isSANB = require('is-string-and-not-blank');
32
const later = require('@breejs/later');
43
const ms = require('ms');
54

5+
/**
6+
* Returns true if `val` is a string and it's not blank.
7+
*
8+
* @param {any} value
9+
* @returns {boolean}
10+
*/
11+
const isSANB = (value) => {
12+
return typeof value === 'string' && value.trim().length > 0;
13+
};
14+
615
/**
716
* Naively checks if passed value is of later.js schedule format (https://breejs.github.io/later/schedules.html)
817
*
@@ -124,6 +133,7 @@ module.exports = {
124133
getJobNames,
125134
getJobPath,
126135
getName,
136+
isSANB,
127137
isSchedule,
128138
parseValue
129139
};

src/job-validator.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const fs = require('node:fs');
22
const { join } = require('node:path');
33
const combineErrors = require('combine-errors');
4+
const isInvalidPath = require('is-invalid-path');
5+
const {
6+
getName,
7+
isSANB,
8+
isSchedule,
9+
parseValue,
10+
getJobPath
11+
} = require('./job-utils');
412
const { default: cron } = require('cron-validate');
5-
const isSANB = require('is-string-and-not-blank');
6-
const isValidPath = require('is-valid-path');
7-
const { getName, isSchedule, parseValue, getJobPath } = require('./job-utils');
813

914
const validateReservedJobName = (name) => {
1015
// Don't allow a job to have the `index` file name
@@ -89,7 +94,7 @@ const validateJobPath = async (job, prefix, config) => {
8994
config.defaultExtension
9095
)
9196
);
92-
if (isValidPath(path)) {
97+
if (!isInvalidPath(path)) {
9398
try {
9499
const stats = await fs.promises.stat(path);
95100
if (!stats.isFile()) {

0 commit comments

Comments
 (0)