-
Notifications
You must be signed in to change notification settings - Fork 622
/
Copy pathIPackageJson.ts
339 lines (299 loc) · 10.1 KB
/
IPackageJson.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the
* "dependencies", "optionalDependencies", and "devDependencies" fields.
* @public
*/
export interface IPackageJsonDependencyTable {
/**
* The key is the name of a dependency. The value is a Semantic Versioning (SemVer)
* range specifier.
*/
[dependencyName: string]: string;
}
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the
* "scripts" field.
* @public
*/
export interface IPackageJsonScriptTable {
/**
* The key is the name of the script hook. The value is the script body which may
* be a file path or shell script command.
*/
[scriptName: string]: string;
}
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the
* "repository" field.
* @public
*/
export interface IPackageJsonRepository {
/**
* The source control type for the repository that hosts the project. This is typically "git".
*/
type: string;
/**
* The URL of the repository that hosts the project.
*/
url: string;
/**
* If the project does not exist at the root of the repository, its path is specified here.
*/
directory?: string;
}
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the
* "peerDependenciesMeta" field.
* @public
*/
export interface IPeerDependenciesMetaTable {
[dependencyName: string]: {
optional?: boolean;
};
}
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the
* "dependenciesMeta" field.
* @public
*/
export interface IDependenciesMetaTable {
[dependencyName: string]: {
injected?: boolean;
[key: string]: unknown;
};
}
/**
* This interface is part of the {@link IPackageJson} file format. It is used for the values
* of the "exports" field.
*
* See {@link https://nodejs.org/api/packages.html#conditional-exports | Node.js documentation on Conditional Exports} and
* {@link https://nodejs.org/api/packages.html#community-conditions-definitions | Node.js documentation on Community Conditional Exports}.
*
* @public
*/
export interface IPackageJsonExports {
/**
* This export is like {@link IPackageJsonExports.node} in that it matches for any NodeJS environment.
* This export is specifically for native C++ addons.
*/
'node-addons'?: string | IPackageJsonExports;
/**
* This export matches for any NodeJS environment.
*/
node?: string | IPackageJsonExports;
/**
* This export matches when loaded via ESM syntax (i.e. - `import '...'` or `import('...')`).
* This is always mutually exclusive with {@link IPackageJsonExports.require}.
*/
import?: string | IPackageJsonExports;
/**
* This export matches when loaded via `require()`.
* This is always mutually exclusive with {@link IPackageJsonExports.import}.
*/
require?: string | IPackageJsonExports;
/**
* This export matches as a fallback when no other conditions match. Because exports are evaluated in
* the order that they are specified in the `package.json` file, this condition should always come last
* as no later exports will match if this one does.
*/
default?: string | IPackageJsonExports;
/**
* This export matches when loaded by the typing system (i.e. - the TypeScript compiler).
*/
types?: string | IPackageJsonExports;
/**
* Any web browser environment.
*/
browser?: string | IPackageJsonExports;
/**
* This export matches in development-only environments.
* This is always mutually exclusive with {@link IPackageJsonExports.production}.
*/
development?: string | IPackageJsonExports;
/**
* This export matches in production-only environments.
* This is always mutually exclusive with {@link IPackageJsonExports.development}.
*/
production?: string | IPackageJsonExports;
}
/**
* An interface for accessing common fields from a package.json file whose version field may be missing.
*
* @remarks
* This interface is the same as {@link IPackageJson}, except that the `version` field is optional.
* According to the {@link https://docs.npmjs.com/files/package.json | NPM documentation}
* and {@link http://wiki.commonjs.org/wiki/Packages/1.0 | CommonJS Packages specification}, the `version` field
* is normally a required field for package.json files.
*
* However, NodeJS relaxes this requirement for its `require()` API. The
* {@link https://nodejs.org/dist/latest-v10.x/docs/api/modules.html#modules_folders_as_modules
* | "Folders as Modules" section} from the NodeJS documentation gives an example of a package.json file
* that has only the `name` and `main` fields. NodeJS does not consider the `version` field during resolution,
* so it can be omitted. Some libraries do this.
*
* Use the `INodePackageJson` interface when loading such files. Use `IPackageJson` for package.json files
* that are installed from an NPM registry, or are otherwise known to have a `version` field.
*
* @public
*/
export interface INodePackageJson {
/**
* The name of the package.
*/
name: string;
/**
* A version number conforming to the Semantic Versioning (SemVer) standard.
*/
version?: string;
/**
* Indicates whether this package is allowed to be published or not.
*/
private?: boolean;
/**
* A brief description of the package.
*/
description?: string;
/**
* The URL of the project's repository.
*/
repository?: string | IPackageJsonRepository;
/**
* The URL to the project's web page.
*/
homepage?: string;
/**
* The name of the license.
*/
license?: string;
/**
* The path to the module file that will act as the main entry point.
*/
main?: string;
/**
* The path to the TypeScript *.d.ts file describing the module file
* that will act as the main entry point.
*/
types?: string;
/**
* Alias for `types`
*/
typings?: string;
/**
* The path to the TSDoc metadata file.
* This is still being standardized: https://github.com/microsoft/tsdoc/issues/7#issuecomment-442271815
* @beta
*/
tsdocMetadata?: string;
/**
* The main entry point for the package.
*/
bin?: string | Record<string, string>;
/**
* An array of dependencies that must always be installed for this package.
*/
dependencies?: IPackageJsonDependencyTable;
/**
* An array of optional dependencies that may be installed for this package.
*/
optionalDependencies?: IPackageJsonDependencyTable;
/**
* An array of dependencies that must only be installed for developers who will
* build this package.
*/
devDependencies?: IPackageJsonDependencyTable;
/**
* An array of dependencies that must be installed by a consumer of this package,
* but which will not be automatically installed by this package.
*/
peerDependencies?: IPackageJsonDependencyTable;
/**
* An array of metadata for dependencies declared inside dependencies, optionalDependencies, and devDependencies.
* https://pnpm.io/package_json#dependenciesmeta
*/
dependenciesMeta?: IDependenciesMetaTable;
/**
* An array of metadata about peer dependencies.
*/
peerDependenciesMeta?: IPeerDependenciesMetaTable;
/**
* A table of script hooks that a package manager or build tool may invoke.
*/
scripts?: IPackageJsonScriptTable;
/**
* A table of package version resolutions. This feature is only implemented by the Yarn package manager.
*
* @remarks
* See the {@link https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md
* | 0000-selective-versions-resolutions.md RFC} for details.
*/
resolutions?: Record<string, string>;
/**
* A table of TypeScript *.d.ts file paths that are compatible with specific TypeScript version
* selectors. This data take a form similar to that of the {@link INodePackageJson.exports} field,
* with fallbacks listed in order in the value array for example:
*
* ```JSON
* "typesVersions": {
* ">=3.1": {
* "*": ["./types-3.1/*", "./types-3.1-fallback/*"]
* },
* ">=3.0": {
* "*": ["./types-legacy/*"]
* }
* }
* ```
*
* or
*
* ```JSON
* "typesVersions": {
* ">=3.1": {
* "app/*": ["./app/types-3.1/*"],
* "lib/*": ["./lib/types-3.1/*"]
* },
* ">=3.0": {
* "app/*": ["./app/types-legacy/*"],
* "lib/*": ["./lib/types-legacy/*"]
* }
* }
* ```
*
* See the
* {@link https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions
* | TypeScript documentation} for details.
*/
typesVersions?: Record<string, Record<string, [string, ...string[]]>>;
/**
* The "exports" field is used to specify the entry points for a package.
* See {@link https://nodejs.org/api/packages.html#exports | Node.js documentation}
*/
// eslint-disable-next-line @rushstack/no-new-null
exports?: string | string[] | Record<string, null | string | IPackageJsonExports>;
/**
* The "files" field is an array of file globs that should be included in the package during publishing.
*
* See the {@link https://docs.npmjs.com/cli/v6/configuring-npm/package-json#files | NPM documentation}.
*/
files?: string[];
}
/**
* An interface for accessing common fields from a package.json file.
*
* @remarks
* This interface describes a package.json file format whose `name` and `version` field are required.
* In some situations, the `version` field is optional; in that case, use the {@link INodePackageJson}
* interface instead.
*
* More fields may be added to this interface in the future. For documentation about the package.json file format,
* see the {@link http://wiki.commonjs.org/wiki/Packages/1.0 | CommonJS Packages specification}
* and the {@link https://docs.npmjs.com/files/package.json | NPM manual page}.
*
* @public
*/
export interface IPackageJson extends INodePackageJson {
// Make the "version" field non-optional.
/** {@inheritDoc INodePackageJson.version} */
version: string;
}