Comparing version
import { ScheduledTask, TaskFn, TaskOptions } from "./tasks/scheduled-task"; | ||
export declare function schedule(expression: string, func: TaskFn | string, options?: TaskOptions): ScheduledTask; | ||
export declare function createTask(expression: string, func: TaskFn | string, options?: TaskOptions): ScheduledTask; | ||
export declare function solvePath(filePath: string): string; | ||
export declare function validate(expression: string): boolean; | ||
@@ -5,0 +6,0 @@ export declare const getTasks: () => Map<string, ScheduledTask>; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.createTask = createTask; | ||
exports.solvePath = solvePath; | ||
exports.validate = validate; | ||
@@ -16,2 +17,3 @@ const inline_scheduled_task_1 = require("./tasks/inline-scheduled-task"); | ||
const path_1 = __importDefault(require("path")); | ||
const url_1 = require("url"); | ||
const registry = new task_registry_1.TaskRegistry(); | ||
@@ -37,2 +39,4 @@ function schedule(expression, func, options) { | ||
if (path_1.default.isAbsolute(filePath)) | ||
return (0, url_1.pathToFileURL)(filePath).href; | ||
if (filePath.startsWith('file://')) | ||
return filePath; | ||
@@ -43,6 +47,6 @@ const stackLines = new Error().stack?.split('\n'); | ||
const callerLine = stackLines?.find((line) => { return line.indexOf(__filename) === -1; }); | ||
const match = callerLine?.match(/(file:\/\/|)(\/.+):\d+:\d+/); | ||
const match = callerLine?.match(/(file:\/\/)?(((\/?)(\w:))?([/\\].+)):\d+:\d+/); | ||
if (match) { | ||
const dir = path_1.default.dirname(match[2]); | ||
return path_1.default.resolve(dir, filePath); | ||
const dir = `${match[5] ?? ""}${path_1.default.dirname(match[6])}`; | ||
return (0, url_1.pathToFileURL)(path_1.default.resolve(dir, filePath)).href; | ||
} | ||
@@ -49,0 +53,0 @@ } |
@@ -98,3 +98,3 @@ "use strict"; | ||
command: 'task:start', | ||
path: (0, path_1.resolve)(this.taskPath), | ||
path: this.taskPath, | ||
cron: this.cronExpression, | ||
@@ -101,0 +101,0 @@ options: this.options |
@@ -41,6 +41,13 @@ "use strict"; | ||
exports.bind = bind; | ||
const url_1 = require("url"); | ||
const logger_1 = __importDefault(require("../../logger")); | ||
const inline_scheduled_task_1 = require("../inline-scheduled-task"); | ||
async function startDaemon(message) { | ||
const script = await Promise.resolve(`${message.path}`).then(s => __importStar(require(s))); | ||
let script; | ||
try { | ||
script = await Promise.resolve(`${message.path}`).then(s => __importStar(require(s))); | ||
} | ||
catch { | ||
script = await Promise.resolve(`${(0, url_1.fileURLToPath)(message.path)}`).then(s => __importStar(require(s))); | ||
} | ||
const task = new inline_scheduled_task_1.InlineScheduledTask(message.cron, script.task, message.options); | ||
@@ -47,0 +54,0 @@ task.on('task:started', (context => sendEvent('task:started', context))); |
import { ScheduledTask, TaskFn, TaskOptions } from "./tasks/scheduled-task"; | ||
export declare function schedule(expression: string, func: TaskFn | string, options?: TaskOptions): ScheduledTask; | ||
export declare function createTask(expression: string, func: TaskFn | string, options?: TaskOptions): ScheduledTask; | ||
export declare function solvePath(filePath: string): string; | ||
export declare function validate(expression: string): boolean; | ||
@@ -5,0 +6,0 @@ export declare const getTasks: () => Map<string, ScheduledTask>; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.createTask = createTask; | ||
exports.solvePath = solvePath; | ||
exports.validate = validate; | ||
@@ -16,2 +17,3 @@ const inline_scheduled_task_1 = require("./tasks/inline-scheduled-task"); | ||
const path_1 = __importDefault(require("path")); | ||
const url_1 = require("url"); | ||
const registry = new task_registry_1.TaskRegistry(); | ||
@@ -37,2 +39,4 @@ function schedule(expression, func, options) { | ||
if (path_1.default.isAbsolute(filePath)) | ||
return (0, url_1.pathToFileURL)(filePath).href; | ||
if (filePath.startsWith('file://')) | ||
return filePath; | ||
@@ -43,6 +47,6 @@ const stackLines = new Error().stack?.split('\n'); | ||
const callerLine = stackLines?.find((line) => { return line.indexOf(__filename) === -1; }); | ||
const match = callerLine?.match(/(file:\/\/|)(\/.+):\d+:\d+/); | ||
const match = callerLine?.match(/(file:\/\/)?(((\/?)(\w:))?([/\\].+)):\d+:\d+/); | ||
if (match) { | ||
const dir = path_1.default.dirname(match[2]); | ||
return path_1.default.resolve(dir, filePath); | ||
const dir = `${match[5] ?? ""}${path_1.default.dirname(match[6])}`; | ||
return (0, url_1.pathToFileURL)(path_1.default.resolve(dir, filePath)).href; | ||
} | ||
@@ -49,0 +53,0 @@ } |
@@ -98,3 +98,3 @@ "use strict"; | ||
command: 'task:start', | ||
path: (0, path_1.resolve)(this.taskPath), | ||
path: this.taskPath, | ||
cron: this.cronExpression, | ||
@@ -101,0 +101,0 @@ options: this.options |
@@ -8,6 +8,13 @@ "use strict"; | ||
exports.bind = bind; | ||
const url_1 = require("url"); | ||
const logger_1 = __importDefault(require("../../logger")); | ||
const inline_scheduled_task_1 = require("../inline-scheduled-task"); | ||
async function startDaemon(message) { | ||
const script = await import(message.path); | ||
let script; | ||
try { | ||
script = await import(message.path); | ||
} | ||
catch { | ||
script = await import((0, url_1.fileURLToPath)(message.path)); | ||
} | ||
const task = new inline_scheduled_task_1.InlineScheduledTask(message.cron, script.task, message.options); | ||
@@ -14,0 +21,0 @@ task.on('task:started', (context => sendEvent('task:started', context))); |
{ | ||
"name": "node-cron", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "A Lightweight Task Scheduler for Node.js", | ||
@@ -25,2 +25,3 @@ "author": "Lucas Merencia", | ||
"test": "c8 --reporter text --reporter=lcov --exclude '**/*.test.ts' mocha --recursive './src/**/*.test.ts'", | ||
"test:nocov": "mocha --recursive **/*.test.ts", | ||
"lint": "./node_modules/.bin/eslint ./src", | ||
@@ -27,0 +28,0 @@ "check": "npm run lint && npm test", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
221178
0.72%3205
0.75%2
100%