UNPKG

@sidequest/engine

Version:

@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.

58 lines (56 loc) 2.56 kB
/** * Tag used to indicate that a job script should be resolved manually * by searching the filesystem rather than importing directly. */ declare const MANUAL_SCRIPT_TAG = "sidequest.jobs.js"; /** * Finds a file by searching in the current directory and walking up through parent directories. * * @param fileName - The name of the file to search for. Defaults to "sidequest.jobs.js" * @param startDir - The directory to start searching from. Defaults to process.cwd() * @returns The file URL path to the found file * @throws {Error} If the file is not found in any directory up to the root * * @example * ```typescript * // Find sidequest.jobs.js starting from current directory * const jobsFile = findFileInParentDirs(); * * // Find a specific file starting from current directory * const configFile = findFileInParentDirs("config.json"); * * // Find a file starting from a specific directory * const packageFile = findFileInParentDirs("package.json", "/some/project/dir"); * ``` */ declare function findSidequestJobsScriptInParentDirs(fileName?: string, startDir?: string): string; /** * Resolves a script path to a file URL, handling various path formats and resolution strategies. * * This function attempts to resolve script paths in the following order: * 1. If the path is already a valid URL, returns it as-is (for file: protocol URLs) * 2. If the path is absolute, converts it directly to a file URL * 3. If the path is relative, searches for the file in directories from the call stack, * starting from the caller's directory and walking up the stack * * The stack-based resolution helps resolve relative paths based on the script's * execution context rather than the current working directory. * * @param scriptPath - The script path to resolve. Can be a relative path, absolute path, or URL string. * @returns The resolved file URL as a string * @throws {Error} When scriptPath is empty or when the file cannot be found in any searched location * * @example * ```typescript * // Absolute path * resolveScriptPath('/path/to/script.js') // Returns 'file:///path/to/script.js' * * // Relative path (searches based on call stack) * resolveScriptPath('./script.js') // Returns file URL of script.js found in caller's directory * * // Already a URL * resolveScriptPath('file:///path/to/script.js') // Returns 'file:///path/to/script.js' * ``` */ declare function resolveScriptPath(scriptPath: string): string; export { MANUAL_SCRIPT_TAG, findSidequestJobsScriptInParentDirs, resolveScriptPath };