MCPcopy
hub / github.com/node-cron/node-cron / solvePath

Function solvePath

src/node-cron.ts:103–123  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

101 * @private
102 */
103export function solvePath(filePath: string): string {
104 // Convert to file URL
105 if(path.isAbsolute(filePath)) return pathToFileURL(filePath).href;
106
107 // Return immediately if it's a file URL
108 if (filePath.startsWith('file://')) return filePath;
109
110 const stackLines = new Error().stack?.split('\n');
111 if(stackLines){
112 stackLines?.shift();
113 const callerLine = stackLines?.find((line) => { return line.indexOf(moduleFilename) === -1; });
114 const match = callerLine?.match(/(file:\/\/)?(((\/?)(\w:))?([/\\].+)):\d+:\d+/);
115
116 if (match) {
117 const dir = `${match[5] ?? ""}${path.dirname(match[6])}`;
118 return pathToFileURL(path.resolve(dir, filePath)).href;
119 }
120 }
121
122 throw new Error(`Could not locate task file ${filePath}`);
123}
124
125/**
126 * Validates a cron expression to ensure it follows the correct format.

Callers 2

node-cron.test.tsFile · 0.90
createTaskFunction · 0.85

Calls 1

matchMethod · 0.65

Tested by

no test coverage detected