UNPKG

2.48 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
6 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
7 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
8 * Google as part of the polymer project is also subject to an additional IP
9 * rights grant found at http://polymer.github.io/PATENTS.txt
10 */
11export declare type OnDemandDependencies = Map<string, string>;
12/**
13 * Asynchronously checks to see if a module is resolvable. This gives the
14 * invoker information that is similar to what they would get from using
15 * require.resolve. However, require.resolve is backed by an unclearable
16 * internal cache, which this helper bypasses via a child process.
17 *
18 * @see https://github.com/nodejs/node/issues/31803
19 */
20export declare const assertResolvable: (id: string) => Promise<void>;
21export interface ContainsOnDemandDependencies {
22 [index: string]: unknown;
23 installsOnDemand?: string[];
24}
25export declare const getPackageJSONPath: () => Promise<string | null>;
26export declare const getPackageRoot: () => Promise<string | null>;
27/**
28 * Extract a map of allowed "on-demand" dependencies from a given
29 * package.json-shaped object.
30 */
31export declare const onDemandDependenciesFromPackageJSON: (packageJSON: ContainsOnDemandDependencies) => OnDemandDependencies;
32/**
33 * So-called "on-demand" dependencies are any packages that match the
34 * following requirements:
35 *
36 * - They are enumerated in the non-normative package.json field
37 * "installsOnDemand"
38 *
39 * This function resolves a map of package names and semver ranges including all
40 * packages that match these requirements.
41 */
42export declare const getOnDemandDependencies: () => Promise<OnDemandDependencies>;
43/**
44 * Install an "on-demand" package, resolving after the package has been
45 * installed. Only packages designated as installable on-demand can be
46 * installed this way (see documentation for "getOnDemandDependenies" for more
47 * details). An attempt to install any other package this way will be rejected.
48 *
49 * On-demand packages are installed to this package's node_modules directory.
50 * Any package that can already be resolved from this package's root directory
51 * will be skipped.
52 */
53export declare const installOnDemand: (packageName: string) => Promise<void>;