UNPKG

@velcro/resolver

Version:

Resolve references to absolute urls using the node module resolution algorithm using an generic host interface

53 lines 2.02 kB
import { CancellationToken } from './cancellation'; import { Decoder } from './decoder'; import { PackageMainField, PackageJson, ResolveDetails } from './types'; import { dirname, basename, resolve, extname } from './util'; import { ResolverHost } from './resolver_host'; interface ResolverOptions { packageMain?: Array<PackageMainField>; extensions?: string[]; } interface ResolverResolveOptions extends ResolverOptions { ignoreBrowserOverrides?: boolean; token?: CancellationToken; } export declare class Resolver { readonly host: ResolverHost; static readonly defaultExtensions: ReadonlyArray<string>; private readonly extensions; private readonly packageMain; readonly decoder: Decoder; constructor(host: ResolverHost, options?: ResolverOptions); resolve(url: URL | string, options?: Partial<ResolverResolveOptions>): Promise<ResolveDetails>; /** * Resolve a reference treating it as a directory * * 1. If there is a `package.json` file and this has a `main` entry, use that * 2. Assume `index` if no main file is found in the `package.json` manifest * * The outcome of this process will then be resolved as if it were a file. */ private resolveAsDirectory; /** * Resolve a reference treating it as a file * * 1. List entries in the containing directory * 2. Look for an exact file match or a file match with one of the supplied extensions * 3. Look for a matching child directory and attempt to resolve that as a directory */ private resolveAsFile; readParentPackageJson(url: URL, options?: { token?: CancellationToken; }): Promise<{ packageJson: PackageJson; url: URL; } | undefined>; static path: { basename: typeof basename; dirname: typeof dirname; extname: typeof extname; resolve: typeof resolve; }; } export {}; //# sourceMappingURL=resolver.d.ts.map