UNPKG

1.98 kBTypeScriptView Raw
1import * as Filesystem from "./filesystem";
2import * as MappingEntry from "./mapping-entry";
3/**
4 * Function that can match a path
5 */
6export interface MatchPath {
7 (requestedModule: string, readJson?: Filesystem.ReadJsonSync, fileExists?: (name: string) => boolean, extensions?: ReadonlyArray<string>): string | undefined;
8}
9/**
10 * Creates a function that can resolve paths according to tsconfig paths property.
11 *
12 * @param absoluteBaseUrl Absolute version of baseUrl as specified in tsconfig.
13 * @param paths The paths as specified in tsconfig.
14 * @param mainFields A list of package.json field names to try when resolving module files. Select a nested field using an array of field names.
15 * @param addMatchAll Add a match-all "*" rule if none is present
16 * @returns a function that can resolve paths.
17 */
18export declare function createMatchPath(absoluteBaseUrl: string, paths: {
19 [key: string]: Array<string>;
20}, mainFields?: (string | string[])[], addMatchAll?: boolean): MatchPath;
21/**
22 * Finds a path from tsconfig that matches a module load request.
23 *
24 * @param absolutePathMappings The paths to try as specified in tsconfig but resolved to absolute form.
25 * @param requestedModule The required module name.
26 * @param readJson Function that can read json from a path (useful for testing).
27 * @param fileExists Function that checks for existence of a file at a path (useful for testing).
28 * @param extensions File extensions to probe for (useful for testing).
29 * @param mainFields A list of package.json field names to try when resolving module files. Select a nested field using an array of field names.
30 * @returns the found path, or undefined if no path was found.
31 */
32export declare function matchFromAbsolutePaths(absolutePathMappings: ReadonlyArray<MappingEntry.MappingEntry>, requestedModule: string, readJson?: Filesystem.ReadJsonSync, fileExists?: Filesystem.FileExistsSync, extensions?: Array<string>, mainFields?: (string | string[])[]): string | undefined;