UNPKG

3.19 kBTypeScriptView Raw
1import { FakeFS, PortablePath } from '@yarnpkg/fslib';
2import { Cache } from './Cache';
3import { Project } from './Project';
4import { Report } from './Report';
5import { LocatorHash, Locator } from './types';
6export declare type MinimalFetchOptions = {
7 project: Project;
8 fetcher: Fetcher;
9};
10export declare type FetchOptions = MinimalFetchOptions & {
11 cache: Cache;
12 checksums: Map<LocatorHash, string | null>;
13 report: Report;
14 skipIntegrityCheck?: boolean;
15};
16export declare type FetchResult = {
17 packageFs: FakeFS<PortablePath>;
18 /**
19 * If set, this function will be called once the fetch result isn't needed
20 * anymore. Typically used to release the ZipFS memory.
21 */
22 releaseFs?: () => void;
23 /**
24 * The path where the package can be found within the `packageFs`. This is
25 * typically the "node_modules/<scope>/<name>` path.
26 */
27 prefixPath: PortablePath;
28 /**
29 * The "true" place where we can find the sources. We use that in order to
30 * compute the `file:` and `link:` relative paths.
31 */
32 localPath?: PortablePath | null;
33 /**
34 * The checksum for the fetch result.
35 */
36 checksum?: string;
37 /**
38 * If true, the package location won't be considered for package lookups (so
39 * for example with can use this flag to indicate that the `link:` protocol
40 * should be resolvable, but should never be used to detect the package that
41 * owns a path).
42 */
43 discardFromLookup?: boolean;
44};
45/**
46 * Fetchers are the component tasked from taking a locator and fetching its
47 * file data from whatever location the fetcher deems right. For example, the
48 * npm fetcher would download them from the npm registry while the workspace
49 * fetcher would simply return an plain link to the filesystem.
50 */
51export interface Fetcher {
52 /**
53 * This function must return true if the specified locator is understood by
54 * this resolver (only its syntax is checked, it doesn't have to be valid
55 * and it's fine if the `fetch` ends up returning a 404).
56 *
57 * @param locator The locator that needs to be validated.
58 * @param opts The fetch options.
59 */
60 supports(locator: Locator, opts: MinimalFetchOptions): boolean;
61 /**
62 * This function must return the local path for the given package. The local
63 * path is the one that's used to resolve relative dependency sources, for
64 * example "file:./foo".
65 *
66 * @param locator The source locator.
67 * @param opts The fetch options.
68 */
69 getLocalPath(locator: Locator, opts: FetchOptions): PortablePath | null;
70 /**
71 * This function must return a object describing where the package manager
72 * can find the data for the specified package on disk.
73 *
74 * The return value is a more complex than a regular path (cf FetchResult)
75 * because the fetchers are allowed to return virtual paths that point to
76 * things that don't actually exist (for example directories stored within
77 * zip archives).
78 *
79 * @param locator The source locator.
80 * @param opts The fetch options.
81 */
82 fetch(locator: Locator, opts: FetchOptions): Promise<FetchResult>;
83}