Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup dependencies #260

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -203,7 +203,7 @@ class Bree extends EventEmitter {
// <https://nodejs.org/api/esm.html#esm_mandatory_file_extensions>
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()) {
Expand Down
16 changes: 6 additions & 10 deletions src/job-builder.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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
);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/job-utils.js
Original file line number Diff line number Diff line change
@@ -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)
*
Expand Down Expand Up @@ -124,6 +133,7 @@ module.exports = {
getJobNames,
getJobPath,
getName,
isSANB,
isSchedule,
parseValue
};
13 changes: 9 additions & 4 deletions src/job-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down