UNPKG

6.06 kBTypeScriptView Raw
1/// <reference types="node" />
2import { PortablePath } from '@yarnpkg/fslib';
3import querystring from 'querystring';
4import { Configuration } from './Configuration';
5import { Workspace } from './Workspace';
6import { Ident, Descriptor, Locator, Package } from './types';
7export declare function makeIdent(scope: string | null, name: string): Ident;
8export declare function makeDescriptor(ident: Ident, range: string): Descriptor;
9export declare function makeLocator(ident: Ident, reference: string): Locator;
10export declare function convertToIdent(source: Descriptor | Locator | Package): Ident;
11export declare function convertDescriptorToLocator(descriptor: Descriptor): Locator;
12export declare function convertLocatorToDescriptor(locator: Locator): Descriptor;
13export declare function convertPackageToLocator(pkg: Package): Locator;
14export declare function renamePackage(pkg: Package, locator: Locator): Package;
15export declare function copyPackage(pkg: Package): Package;
16export declare function virtualizeDescriptor(descriptor: Descriptor, entropy: string): Descriptor;
17export declare function virtualizePackage(pkg: Package, entropy: string): Package;
18export declare function isVirtualDescriptor(descriptor: Descriptor): boolean;
19export declare function isVirtualLocator(locator: Locator): boolean;
20export declare function devirtualizeDescriptor(descriptor: Descriptor): Descriptor;
21export declare function devirtualizeLocator(locator: Locator): Locator;
22export declare function bindDescriptor(descriptor: Descriptor, params: {
23 [key: string]: string;
24}): Descriptor;
25export declare function bindLocator(locator: Locator, params: {
26 [key: string]: string;
27}): Locator;
28export declare function areIdentsEqual(a: Ident, b: Ident): boolean;
29export declare function areDescriptorsEqual(a: Descriptor, b: Descriptor): boolean;
30export declare function areLocatorsEqual(a: Locator, b: Locator): boolean;
31/**
32 * Virtual packages are considered equivalent when they belong to the same
33 * package identity and have the same dependencies. Note that equivalence
34 * is not the same as equality, as the references may be different.
35 */
36export declare function areVirtualPackagesEquivalent(a: Package, b: Package): boolean;
37export declare function parseIdent(string: string): Ident;
38export declare function tryParseIdent(string: string): Ident | null;
39export declare function parseDescriptor(string: string, strict?: boolean): Descriptor;
40export declare function tryParseDescriptor(string: string, strict?: boolean): Descriptor | null;
41export declare function parseLocator(string: string, strict?: boolean): Locator;
42export declare function tryParseLocator(string: string, strict?: boolean): Locator | null;
43declare type ParseRangeOptions = {
44 requireBindings?: boolean;
45 requireProtocol?: boolean | string;
46 requireSource?: boolean;
47 parseSelector?: boolean;
48};
49declare type ParseRangeReturnType<Opts extends ParseRangeOptions> = ({
50 params: Opts extends {
51 requireBindings: true;
52 } ? querystring.ParsedUrlQuery : querystring.ParsedUrlQuery | null;
53}) & ({
54 protocol: Opts extends {
55 requireProtocol: true | string;
56 } ? string : string | null;
57}) & ({
58 source: Opts extends {
59 requireSource: true;
60 } ? string : string | null;
61}) & ({
62 selector: Opts extends {
63 parseSelector: true;
64 } ? querystring.ParsedUrlQuery : string;
65});
66export declare function parseRange<Opts extends ParseRangeOptions>(range: string, opts?: Opts): ParseRangeReturnType<Opts>;
67export declare function parseFileStyleRange(range: string, { protocol }: {
68 protocol: string;
69}): {
70 parentLocator: Locator;
71 path: PortablePath;
72};
73export declare function makeRange({ protocol, source, selector, params }: {
74 protocol: string | null;
75 source: string | null;
76 selector: string;
77 params: querystring.ParsedUrlQuery | null;
78}): string;
79/**
80 * The range used internally may differ from the range stored in the
81 * Manifest (package.json). This removes any params indicated for internal use.
82 * An internal param starts with "__".
83 * @param range range to convert
84 */
85export declare function convertToManifestRange(range: string): string;
86export declare function requirableIdent(ident: Ident): string;
87export declare function stringifyIdent(ident: Ident): string;
88export declare function stringifyDescriptor(descriptor: Descriptor): string;
89export declare function stringifyLocator(locator: Locator): string;
90export declare function slugifyIdent(ident: Ident): string;
91export declare function slugifyLocator(locator: Locator): import("@yarnpkg/fslib").Filename;
92export declare function prettyIdent(configuration: Configuration, ident: Ident): string;
93export declare function prettyRange(configuration: Configuration, range: string): string;
94export declare function prettyDescriptor(configuration: Configuration, descriptor: Descriptor): string;
95export declare function prettyReference(configuration: Configuration, reference: string): string;
96export declare function prettyLocator(configuration: Configuration, locator: Locator): string;
97export declare function prettyLocatorNoColors(locator: Locator): string;
98export declare function sortDescriptors(descriptors: Iterable<Descriptor>): Descriptor[];
99export declare function prettyWorkspace(configuration: Configuration, workspace: Workspace): string;
100/**
101 * The presence of a `node_modules` directory in the path is extremely common
102 * in the JavaScript ecosystem to denote whether a path belongs to a vendor
103 * or not. I considered using a more generic path for packages that aren't
104 * always JS-only (such as when using the Git fetcher), but that unfortunately
105 * caused various JS apps to start showing errors when working with git repos.
106 *
107 * As a result, all packages from all languages will follow this convention. At
108 * least it'll be consistent, and linkers will always have the ability to remap
109 * them to a different location if that's a critical requirement.
110 */
111export declare function getIdentVendorPath(ident: Ident): PortablePath;
112export {};