UNPKG

10.2 kBTypeScriptView Raw
1import {LiteralUnion} from '..';
2
3declare namespace PackageJson {
4 /**
5 A person who has been involved in creating or maintaining the package.
6 */
7 export type Person =
8 | string
9 | {
10 name: string;
11 url?: string;
12 email?: string;
13 };
14
15 export type BugsLocation =
16 | string
17 | {
18 /**
19 The URL to the package's issue tracker.
20 */
21 url?: string;
22
23 /**
24 The email address to which issues should be reported.
25 */
26 email?: string;
27 };
28
29 export interface DirectoryLocations {
30 /**
31 Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
32 */
33 bin?: string;
34
35 /**
36 Location for Markdown files.
37 */
38 doc?: string;
39
40 /**
41 Location for example scripts.
42 */
43 example?: string;
44
45 /**
46 Location for the bulk of the library.
47 */
48 lib?: string;
49
50 /**
51 Location for man pages. Sugar to generate a `man` array by walking the folder.
52 */
53 man?: string;
54
55 /**
56 Location for test files.
57 */
58 test?: string;
59
60 [directoryType: string]: unknown;
61 }
62
63 export type Scripts = {
64 /**
65 Run **before** the package is published (Also run on local `npm install` without any arguments).
66 */
67 prepublish?: string;
68
69 /**
70 Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`.
71 */
72 prepare?: string;
73
74 /**
75 Run **before** the package is prepared and packed, **only** on `npm publish`.
76 */
77 prepublishOnly?: string;
78
79 /**
80 Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
81 */
82 prepack?: string;
83
84 /**
85 Run **after** the tarball has been generated and moved to its final destination.
86 */
87 postpack?: string;
88
89 /**
90 Run **after** the package is published.
91 */
92 publish?: string;
93
94 /**
95 Run **after** the package is published.
96 */
97 postpublish?: string;
98
99 /**
100 Run **before** the package is installed.
101 */
102 preinstall?: string;
103
104 /**
105 Run **after** the package is installed.
106 */
107 install?: string;
108
109 /**
110 Run **after** the package is installed and after `install`.
111 */
112 postinstall?: string;
113
114 /**
115 Run **before** the package is uninstalled and before `uninstall`.
116 */
117 preuninstall?: string;
118
119 /**
120 Run **before** the package is uninstalled.
121 */
122 uninstall?: string;
123
124 /**
125 Run **after** the package is uninstalled.
126 */
127 postuninstall?: string;
128
129 /**
130 Run **before** bump the package version and before `version`.
131 */
132 preversion?: string;
133
134 /**
135 Run **before** bump the package version.
136 */
137 version?: string;
138
139 /**
140 Run **after** bump the package version.
141 */
142 postversion?: string;
143
144 /**
145 Run with the `npm test` command, before `test`.
146 */
147 pretest?: string;
148
149 /**
150 Run with the `npm test` command.
151 */
152 test?: string;
153
154 /**
155 Run with the `npm test` command, after `test`.
156 */
157 posttest?: string;
158
159 /**
160 Run with the `npm stop` command, before `stop`.
161 */
162 prestop?: string;
163
164 /**
165 Run with the `npm stop` command.
166 */
167 stop?: string;
168
169 /**
170 Run with the `npm stop` command, after `stop`.
171 */
172 poststop?: string;
173
174 /**
175 Run with the `npm start` command, before `start`.
176 */
177 prestart?: string;
178
179 /**
180 Run with the `npm start` command.
181 */
182 start?: string;
183
184 /**
185 Run with the `npm start` command, after `start`.
186 */
187 poststart?: string;
188
189 /**
190 Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
191 */
192 prerestart?: string;
193
194 /**
195 Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
196 */
197 restart?: string;
198
199 /**
200 Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
201 */
202 postrestart?: string;
203 } & {
204 [scriptName: string]: string;
205 };
206
207 /**
208 Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
209 */
210 export interface Dependency {
211 [packageName: string]: string;
212 }
213
214 export interface NonStandardEntryPoints {
215 /**
216 An ECMAScript module ID that is the primary entry point to the program.
217 */
218 module?: string;
219
220 /**
221 A module ID with untranspiled code that is the primary entry point to the program.
222 */
223 esnext?:
224 | string
225 | {
226 main?: string;
227 browser?: string;
228 [moduleName: string]: string | undefined;
229 };
230
231 /**
232 A hint to JavaScript bundlers or component tools when packaging modules for client side use.
233 */
234 browser?:
235 | string
236 | {
237 [moduleName: string]: string | false;
238 };
239 }
240
241 export interface TypeScriptConfiguration {
242 /**
243 Location of the bundled TypeScript declaration file.
244 */
245 types?: string;
246
247 /**
248 Location of the bundled TypeScript declaration file. Alias of `types`.
249 */
250 typings?: string;
251 }
252
253 export interface YarnConfiguration {
254 /**
255 If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command line, set this to `true`.
256
257 Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an application), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
258 */
259 flat?: boolean;
260
261 /**
262 Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
263 */
264 resolutions?: Dependency;
265 }
266
267 export interface JSPMConfiguration {
268 /**
269 JSPM configuration.
270 */
271 jspm?: PackageJson;
272 }
273}
274
275/**
276Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
277*/
278export type PackageJson = {
279 /**
280 The name of the package.
281 */
282 name?: string;
283
284 /**
285 Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
286 */
287 version?: string;
288
289 /**
290 Package description, listed in `npm search`.
291 */
292 description?: string;
293
294 /**
295 Keywords associated with package, listed in `npm search`.
296 */
297 keywords?: string[];
298
299 /**
300 The URL to the package's homepage.
301 */
302 homepage?: LiteralUnion<'.', string>;
303
304 /**
305 The URL to the package's issue tracker and/or the email address to which issues should be reported.
306 */
307 bugs?: PackageJson.BugsLocation;
308
309 /**
310 The license for the package.
311 */
312 license?: string;
313
314 /**
315 The licenses for the package.
316 */
317 licenses?: Array<{
318 type?: string;
319 url?: string;
320 }>;
321
322 author?: PackageJson.Person;
323
324 /**
325 A list of people who contributed to the package.
326 */
327 contributors?: PackageJson.Person[];
328
329 /**
330 A list of people who maintain the package.
331 */
332 maintainers?: PackageJson.Person[];
333
334 /**
335 The files included in the package.
336 */
337 files?: string[];
338
339 /**
340 The module ID that is the primary entry point to the program.
341 */
342 main?: string;
343
344 /**
345 The executable files that should be installed into the `PATH`.
346 */
347 bin?:
348 | string
349 | {
350 [binary: string]: string;
351 };
352
353 /**
354 Filenames to put in place for the `man` program to find.
355 */
356 man?: string | string[];
357
358 /**
359 Indicates the structure of the package.
360 */
361 directories?: PackageJson.DirectoryLocations;
362
363 /**
364 Location for the code repository.
365 */
366 repository?:
367 | string
368 | {
369 type: string;
370 url: string;
371 };
372
373 /**
374 Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
375 */
376 scripts?: PackageJson.Scripts;
377
378 /**
379 Is used to set configuration parameters used in package scripts that persist across upgrades.
380 */
381 config?: {
382 [configKey: string]: unknown;
383 };
384
385 /**
386 The dependencies of the package.
387 */
388 dependencies?: PackageJson.Dependency;
389
390 /**
391 Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
392 */
393 devDependencies?: PackageJson.Dependency;
394
395 /**
396 Dependencies that are skipped if they fail to install.
397 */
398 optionalDependencies?: PackageJson.Dependency;
399
400 /**
401 Dependencies that will usually be required by the package user directly or via another dependency.
402 */
403 peerDependencies?: PackageJson.Dependency;
404
405 /**
406 Package names that are bundled when the package is published.
407 */
408 bundledDependencies?: string[];
409
410 /**
411 Alias of `bundledDependencies`.
412 */
413 bundleDependencies?: string[];
414
415 /**
416 Engines that this package runs on.
417 */
418 engines?: {
419 [EngineName in 'npm' | 'node' | string]: string;
420 };
421
422 /**
423 @deprecated
424 */
425 engineStrict?: boolean;
426
427 /**
428 Operating systems the module runs on.
429 */
430 os?: Array<LiteralUnion<
431 | 'aix'
432 | 'darwin'
433 | 'freebsd'
434 | 'linux'
435 | 'openbsd'
436 | 'sunos'
437 | 'win32'
438 | '!aix'
439 | '!darwin'
440 | '!freebsd'
441 | '!linux'
442 | '!openbsd'
443 | '!sunos'
444 | '!win32',
445 string
446 >>;
447
448 /**
449 CPU architectures the module runs on.
450 */
451 cpu?: Array<LiteralUnion<
452 | 'arm'
453 | 'arm64'
454 | 'ia32'
455 | 'mips'
456 | 'mipsel'
457 | 'ppc'
458 | 'ppc64'
459 | 's390'
460 | 's390x'
461 | 'x32'
462 | 'x64'
463 | '!arm'
464 | '!arm64'
465 | '!ia32'
466 | '!mips'
467 | '!mipsel'
468 | '!ppc'
469 | '!ppc64'
470 | '!s390'
471 | '!s390x'
472 | '!x32'
473 | '!x64',
474 string
475 >>;
476
477 /**
478 If set to `true`, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.
479
480 @deprecated
481 */
482 preferGlobal?: boolean;
483
484 /**
485 If set to `true`, then npm will refuse to publish it.
486 */
487 private?: boolean;
488
489 /**
490 * A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
491 */
492 publishConfig?: {
493 [config: string]: unknown;
494 };
495} &
496PackageJson.NonStandardEntryPoints &
497PackageJson.TypeScriptConfiguration &
498PackageJson.YarnConfiguration &
499PackageJson.JSPMConfiguration & {
500 [key: string]: unknown;
501};