@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
114 lines • 4.72 kB
text/typescript
//#region src/resolve.d.ts
declare const DEFAULT_EXTENSIONS: string[];
interface ResolveOptions {
/**
* Paths to resolve the package from
*/
paths?: string[];
/**
* File extensions to consider when resolving the module
*
* @remarks
* Extensions can be provided with or without the leading dot. The resolver utilities will handle both cases.
*
* @defaultValue ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json", "jsonc", "json5", "node", "wasm"]
*/
extensions?: string[];
/**
* Conditions to consider when resolving package exports.
*/
conditions?: string[];
}
/**
* Get the resolution paths based on the provided paths, current working directory, and workspace root.
*
* @param paths - An array of paths to include in the resolution.
* @returns An array of unique, corrected resolution paths.
*/
declare function getResolutionPaths(paths?: string[]): string[];
/**
* Get the node_modules resolution paths based on the provided paths.
*
* @param paths - An array of paths to include in the resolution.
* @returns An array of unique, corrected node_modules resolution paths.
*/
declare function getNodeModulesPaths(paths?: string[]): string[];
interface ResolutionCombinationOptions extends ResolveOptions {
/**
* Whether to include additional paths (like node_modules) in the resolution combinations. If set to false, only the provided paths will be used for generating combinations. This can be useful for scenarios where you want to limit the resolution to specific directories without considering the default node_modules paths.
*
* @defaultValue true
*/
useAdditionalPaths?: boolean;
}
/**
* Get all combinations of resolution paths for a given path and options.
*
* @param path - The base path to combine with resolution paths.
* @param options - The options containing resolution paths.
* @returns An array of unique, corrected resolution paths.
*/
declare function getResolutionCombinations(path: string, options?: ResolutionCombinationOptions): string[];
/**
* Resolve the path to a specified module
*
* @param path - The path to the module
* @param options - The options to use when resolving the module
* @returns A promise for the path to the module
*/
declare function resolve(path: string, options?: ResolveOptions): Promise<string>;
/**
* Resolve the path to a specified module
*
* @param path - The path to the module
* @param options - The options to use when resolving the module
* @returns The path to the module or undefined
*/
declare function resolveSync(path: string, options?: ResolveOptions): string;
/**
* Resolve the path to a specified module with error handling
*
* @param name - The name of the module
* @param options - The options to use when resolving the module
* @returns A promise for the path to the module
*/
declare function resolveSafe(name: string, options?: ResolveOptions): Promise<string | undefined>;
/**
* Resolve the path to a specified module with error handling
*
* @param name - The name of the module
* @param options - The options to use when resolving the module
* @returns The path to the module or undefined
*/
declare function resolveSafeSync(name: string, options?: ResolveOptions): string | undefined;
/**
* Import a module from a specified path
*
* @param path - The path to the module
* @returns The module
*/
declare function importModule<T = any>(path: string): Promise<T>;
/**
* Resolve the path to a specified package asynchronously
*
* @remarks
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
*
* @param name - The name of the module
* @returns A promise for the module or undefined
*/
declare function resolvePackage(name: string, options?: ResolveOptions): Promise<string | undefined>;
/**
* Resolve the path to a specified package synchronously
*
* @remarks
* This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
*
* @param name - The name of the module
* @param options - The options to use when resolving the module
* @returns The module or undefined
*/
declare function resolvePackageSync(name: string, options?: ResolveOptions): string | undefined;
//#endregion
export { DEFAULT_EXTENSIONS, ResolutionCombinationOptions, ResolveOptions, getNodeModulesPaths, getResolutionCombinations, getResolutionPaths, importModule, resolve, resolvePackage, resolvePackageSync, resolveSafe, resolveSafeSync, resolveSync };
//# sourceMappingURL=resolve.d.cts.map