-
Notifications
You must be signed in to change notification settings - Fork 139
/
types.ts
130 lines (112 loc) · 2.93 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
export type BinSpec = {[key: string]: string};
export type BinList = Array<string>;
export enum SupportedPackageManagers {
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,
}
export const SupportedPackageManagerSet = new Set<SupportedPackageManagers>(
Object.values(SupportedPackageManagers),
);
export const SupportedPackageManagerSetWithoutNpm = new Set<SupportedPackageManagers>(
Object.values(SupportedPackageManagers),
);
// npm is distributed with Node as a builtin; we don't want Corepack to override it unless the npm team is on board
SupportedPackageManagerSetWithoutNpm.delete(SupportedPackageManagers.Npm);
export function isSupportedPackageManager(value: string): value is SupportedPackageManagers {
return SupportedPackageManagerSet.has(value as SupportedPackageManagers);
}
export interface NpmRegistrySpec {
type: `npm`;
package: string;
}
export interface UrlRegistrySpec {
type: `url`;
url: string;
fields: {
tags: string;
versions: string;
};
}
export type RegistrySpec =
| NpmRegistrySpec
| UrlRegistrySpec;
/**
* Defines how the package manager is meant to be downloaded and accessed.
*/
export interface PackageManagerSpec {
url: string;
bin: BinSpec | BinList;
registry: RegistrySpec;
npmRegistry?: NpmRegistrySpec;
commands?: {
use?: Array<string>;
};
}
export interface InstallSpec {
location: string;
bin?: BinList | BinSpec;
hash: string;
}
/**
* The data structure found in config.json
*/
export interface Config {
definitions: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[name in SupportedPackageManagers]?: {
/**
* Defines the version that needs to be used when running commands within
* projects that don't list any preference.
*/
default: string;
/**
* Defines how to fetch the latest version from a remote registry.
*/
fetchLatestFrom: RegistrySpec;
/**
* Defines a set of commands that are fine to run even if the user isn't
* in a project configured for the specified package manager. For instance,
* we would use that to be able to run "pnpx" even inside Yarn projects.
*/
transparent: {
default?: string;
commands: Array<Array<string>>;
};
/**
* Defines how to retrieve the package manager's sources, depending on
* the chosen version.
*/
ranges: {
[range: string]: PackageManagerSpec;
};
};
};
}
/**
* A structure containing the information needed to locate the package
* manager to use for the active project.
*/
export interface Descriptor {
/**
* The name of the package manager required.
*/
name: string;
/**
* The range of versions allowed.
*/
range: string;
}
/**
*
*/
export interface Locator {
/**
* The name of the package manager required.
*/
name: string;
/**
* The exact version required.
*/
reference: string;
}