UNPKG

17 kBTypeScriptView Raw
1// Type definitions for npm 7.19.0
2// Project: https://github.com/npm/cli
3// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node" />
7
8declare var npm: npm.Static;
9export = npm;
10
11declare namespace npm {
12 export interface Static extends NodeJS.EventEmitter {
13 config: Config;
14 commands: Commands;
15 rollbacks: any[];
16 spinner: Spinner;
17 fullList: string[];
18 abbrevs: Dictionary<string>;
19
20 prefix: string;
21 bin: string;
22 globalBin: string;
23 dir: string;
24 globalDir: string;
25 root: string;
26 cache: string;
27 tmp: string;
28
29
30 load(callback?: SimpleCallback<void>): Promise<void>;
31
32 deref(command: string): string;
33 }
34
35 //#region Commands Interfaces
36
37 export interface Commands {
38 install: CommandFunction;
39 uninstall: CommandFunction;
40 cache: CommandFunction;
41 config: CommandFunction;
42 set: CommandFunction;
43 get: CommandFunction;
44 update: CommandFunction;
45 outdated: CommandFunction;
46 prune: CommandFunction;
47 submodule: CommandFunction;
48 pack: CommandFunction;
49 dedupe: CommandFunction;
50
51 /** https://docs.npmjs.com/cli/v7/commands/npm-access */
52 access: CommandFunction;
53 /** https://docs.npmjs.com/cli/v7/commands/npm-audit */
54 audit: CommandFunction;
55 /** https://docs.npmjs.com/cli/v7/commands/npm-ci */
56 ci: CommandFunction;
57 /** https://docs.npmjs.com/cli/v7/commands/npm-diff */
58 diff: CommandFunction;
59 /** https://docs.npmjs.com/cli/v7/commands/npm-dist-tag */
60 "dist-tag": CommandFunction;
61 /** https://docs.npmjs.com/cli/v7/commands/npm-doctor */
62 doctor: CommandFunction;
63 /** https://docs.npmjs.com/cli/v7/commands/npm-exec */
64 exec: CommandFunction;
65 /** https://docs.npmjs.com/cli/v7/commands/npm-explain */
66 explain: CommandFunction;
67 /** https://docs.npmjs.com/cli/v7/commands/npm-fund */
68 fund: CommandFunction;
69 /** https://docs.npmjs.com/cli/v7/commands/npm-hook */
70 hook: CommandFunction;
71 /** https://docs.npmjs.com/cli/v7/commands/npm-install-ci-test */
72 "install-ci-test": CommandFunction;
73 /** https://docs.npmjs.com/cli/v7/commands/npm-install-test */
74 "install-test": CommandFunction;
75 /** https://docs.npmjs.com/cli/v7/commands/npm-logout */
76 logout: CommandFunction;
77 /** https://docs.npmjs.com/cli/v7/commands/npm-org */
78 org: CommandFunction;
79 /** https://docs.npmjs.com/cli/v7/commands/npm-ping */
80 ping: CommandFunction;
81 /** https://docs.npmjs.com/cli/v7/commands/npm-profile */
82 profile: CommandFunction;
83 /** https://docs.npmjs.com/cli/v7/commands/npm-set-script */
84 "set-script": CommandFunction;
85 /** https://docs.npmjs.com/cli/v7/commands/npm-team */
86 team: CommandFunction;
87 /** https://docs.npmjs.com/cli/v7/commands/npm-token */
88 token: CommandFunction;
89
90 rebuild: CommandFunction;
91 link: CommandFunction;
92
93 publish: CommandFunction;
94 star: CommandFunction;
95 stars: CommandFunction;
96 tag: CommandFunction;
97 adduser: CommandFunction;
98 unpublish: CommandFunction;
99 owner: CommandFunction;
100 deprecate: CommandFunction;
101 shrinkwrap: CommandFunction;
102
103 help: CommandFunction;
104 "help-search": CommandFunction;
105 ls: CommandFunction;
106 search: CommandFunction;
107 init: CommandFunction;
108 version: CommandFunction;
109 edit: CommandFunction;
110 explore: CommandFunction;
111 docs: CommandFunction;
112 repo: CommandFunction;
113 bugs: CommandFunction;
114 faq: CommandFunction;
115 root: CommandFunction;
116 prefix: CommandFunction;
117 bin: CommandFunction;
118 whoami: CommandFunction;
119
120 // view and its aliases
121 view(args: string[], callback: CommandCallback): void;
122 view(args: string[], silent: boolean, callback: CommandCallback): void;
123 info(args: string[], callback: CommandCallback): void;
124 info(args: string[], silent: boolean, callback: CommandCallback): void;
125 show(args: string[], callback: CommandCallback): void;
126 show(args: string[], silent: boolean, callback: CommandCallback): void;
127 v(args: string[], callback: CommandCallback): void;
128 v(args: string[], silent: boolean, callback: CommandCallback): void;
129
130 test: CommandFunction;
131 stop: CommandFunction;
132 start: CommandFunction;
133 restart: CommandFunction;
134 "run-script": CommandFunction;
135 completion: CommandFunction;
136
137 //Aliases
138 rm: CommandFunction; // uninstall
139 r: CommandFunction; // uninstall
140 un: CommandFunction; // uninstall
141 unlink: CommandFunction; // uninstall
142 remove: CommandFunction; // uninstall
143 rb: CommandFunction; // rebuild
144 list: CommandFunction; // ls
145 la: CommandFunction; // ls
146 ll: CommandFunction; // ls
147 i: CommandFunction; // install
148 isntall: CommandFunction; // install
149 up: CommandFunction; // update
150 c: CommandFunction; // config
151 find: CommandFunction; // search
152 s: CommandFunction; // search
153 se: CommandFunction; // search
154 author: CommandFunction; // owner
155 home: CommandFunction; // docs
156 issues: CommandFunction; // bugs
157 unstar: CommandFunction; // star
158 apihelp: CommandFunction; // help
159 long: CommandFunction; // adduser
160 "add-user": CommandFunction; // adduser
161 tst: CommandFunction; // test
162 t: CommandFunction; // test
163 "find-dupes": CommandFunction; // dedupe
164 ddp: CommandFunction; // dedupe
165 /**
166 * Alias for `dist-tag`
167 *
168 * https://docs.npmjs.com/cli/v7/commands/npm-dist-tag
169 */
170 "dist-tags": CommandFunction;
171 /**
172 * Alias for `exec`
173 *
174 * https://docs.npmjs.com/cli/v7/commands/npm-exec
175 */
176 x: CommandFunction;
177 /**
178 * Alias for `explain`
179 *
180 * https://docs.npmjs.com/cli/v7/commands/npm-dist-tag
181 */
182 why: CommandFunction;
183 /**
184 * Alias for `install-ci-test`
185 *
186 * https://docs.npmjs.com/cli/v7/commands/npm-install-ci-test
187 */
188 cit: CommandFunction;
189 /**
190 * Alias for `install-test`
191 *
192 * https://docs.npmjs.com/cli/v7/commands/npm-install-test
193 */
194 it: CommandFunction;
195
196
197 // plumbing
198 build: CommandFunction;
199 unbuild: CommandFunction;
200 xmas: CommandFunction;
201 substack: CommandFunction;
202 visnup: CommandFunction;
203
204 }
205 export interface CommandFunction {
206 (args: string[], callback: CommandCallback): void;
207 }
208 export interface CommandCallback {
209 (err?: Error, result?: any, result2?: any, result3?: any, result4?: any): void;
210 }
211
212 //#endregion
213
214 //#region Other Interfaces
215
216 export interface Spinner {
217 int: string;
218 started: boolean;
219 start(): void;
220 stop(): void;
221 }
222
223 //#endregion
224
225 //#region Config Interfaces
226
227 export interface ConfigStatic {
228 new (base: Config): Config;
229 (base: Config): Config;
230 }
231
232 export interface Config {
233 loaded: boolean;
234 sources: Dictionary<ConfigSource>;
235 rootConf: Config;
236 usingBuiltin: boolean;
237 root?: Config | undefined;
238 Conf: ConfigStatic;
239 defs: ConfigDefs;
240
241 get(setting: string): any;
242 set(setting: string, value: any): void;
243
244 loadPrefix(cb: ErrorCallback): void;
245 loadCAFile(caFilePath: string, cb: ErrorCallback): void;
246 loadUid(cb: SimpleCallback<string>): void;
247 setUser(cb: ErrorCallback): void;
248 findPrefix(prefix: string, cb: SimpleCallback<string>): void;
249 getCredentialsByURI(uri: string): Credentials;
250 setCredentialsByURI(uri: string, cred: Credentials): void;
251
252 loadExtras(cb: ErrorCallback): void;
253 save(where: string, cb: ErrorCallback): Config;
254 addFile(file: string, name: string): Config;
255 parse(content: string, file: string): any;
256 add(data: Object, marker: Object): any;
257 addEnv(env: Dictionary<string>): any;
258 }
259
260 export interface ConfigDefs {
261 defaults: ConfigOptions;
262 types: ConfigTypes;
263 }
264
265 export interface ConfigOptions {
266 "always-auth"?: boolean | undefined;
267 "bin-links"?: boolean | undefined;
268 browser?: string | undefined;
269
270 ca?: any; // string | string[]
271 cafile?: string | undefined;
272
273 cache?: string | undefined;
274
275 "cache-lock-stale"?: number | undefined;
276 "cache-lock-retries"?: number | undefined;
277 "cache-lock-wait"?: number | undefined;
278
279 "cache-max"?: number | undefined;
280 "cache-min"?: number | undefined;
281
282 cert?: string | undefined;
283
284 color?: any; // boolean | string ("always")
285 depth?: number | undefined;
286 description?: boolean | undefined;
287 dev?: boolean | undefined;
288 editor?: string | undefined;
289 "engine-strict"?: boolean | undefined;
290 force?: boolean | undefined;
291
292 "fetch-retries"?: number | undefined;
293 "fetch-retry-factor"?: number | undefined;
294 "fetch-retry-mintimeout"?: number | undefined;
295 "fetch-retry-maxtimeout"?: number | undefined;
296
297 git?: string | undefined;
298 "git-tag-version"?: boolean | undefined;
299
300 global?: boolean | undefined;
301 globalconfig?: string | undefined;
302 group?: any; // number | string
303 heading?: string | undefined;
304 "ignore-scripts"?: boolean | undefined;
305 "init-module"?: string | undefined;
306 "init.author.name"?: string | undefined;
307 "init.author.email"?: string | undefined;
308 "init.author.url"?: string | undefined;
309 "init.version"?: string | undefined;
310 "init.license"?: string | undefined;
311 json?: boolean | undefined;
312 key?: string | undefined;
313 link?: boolean | undefined;
314 "local-address"?: string | undefined;
315 loglevel?: string | undefined;
316 logstream?: NodeJS.ReadWriteStream | undefined;
317 long?: boolean | undefined;
318 message?: string | undefined;
319 "node-version"?: string | undefined;
320 npat?: boolean | undefined;
321 "onload-script"?: boolean | undefined;
322 optional?: boolean | undefined;
323 parseable?: boolean | undefined;
324 prefix?: string | undefined;
325 production?: boolean | undefined;
326 "proprietary-attribs"?: boolean | undefined;
327 proxy?: any; // boolean | string
328 "https-proxy"?: string | undefined;
329 "user-agent"?: string | undefined;
330 "rebuild-bundle"?: boolean | undefined;
331 registry?: string | undefined;
332 rollback?: boolean | undefined;
333 save?: boolean | undefined;
334 "save-bundle"?: boolean | undefined;
335 "save-dev"?: boolean | undefined;
336 "save-exact"?: boolean | undefined;
337 "save-optional"?: boolean | undefined;
338 "save-prefix"?: string | undefined;
339 scope?: string | undefined;
340 searchopts?: string | undefined;
341 searchexclude?: string | undefined;
342 searchsort?: string | undefined;
343 shell?: string | undefined;
344 shrinkwrap?: boolean | undefined;
345 "sign-git-tag"?: boolean | undefined;
346 spin?: any; // boolean | string ("always")
347 "strict-ssl"?: boolean | undefined;
348 tag?: string | undefined;
349 tmp?: string | undefined;
350 unicode?: boolean | undefined;
351 "unsafe-perm"?: boolean | undefined;
352 usage?: boolean | undefined;
353 user?: any; // string | number
354 userconfig?: string | undefined;
355 umask?: number | undefined;
356 version?: boolean | undefined;
357 versions?: boolean | undefined;
358 viewer?: string | undefined;
359
360 _exit?: boolean | undefined;
361 }
362
363 export interface ConfigTypes {
364 "always-auth": typeof Boolean;
365 "bin-links": typeof Boolean;
366 browser: any[];
367
368 ca: any[];
369 cafile: typeof String;
370 cache: typeof String;
371
372 "cache-lock-stale": typeof Number;
373 "cache-lock-retries": typeof Number;
374 "cache-lock-wait": typeof Number;
375
376 "cache-max": typeof Number;
377 "cache-min": typeof Number;
378
379 cert: typeof String;
380
381 color: any[];
382 depth: typeof Number;
383 description: typeof Boolean;
384 dev: typeof Boolean;
385 editor: typeof String;
386 "engine-strict": typeof Boolean;
387 force: typeof Boolean;
388
389 "fetch-retries": typeof Number;
390 "fetch-retry-factor": typeof Number;
391 "fetch-retry-mintimeout": typeof Number;
392 "fetch-retry-maxtimeout": typeof Number;
393
394 git: typeof String;
395 "git-tag-version": typeof Boolean;
396
397 global: typeof Boolean;
398 globalconfig: typeof String;
399 group: any[];
400 heading: typeof String;
401 "ignore-scripts": typeof Boolean;
402 "init-module": typeof String;
403 "init.author.name": typeof String;
404 "init.author.email": typeof String;
405 "init.author.url": typeof String;
406 "init.version": typeof String;
407 "init.license": typeof String;
408 json: typeof Boolean;
409 key: any[];
410 link: typeof Boolean;
411 "local-address": typeof String;
412 loglevel: any[];
413 logstream: any; // typeof stream.Stream
414 long: typeof Boolean;
415 message: typeof String;
416 "node-version": any[];
417 npat: typeof Boolean;
418 "onload-script": any[];
419 optional: typeof Boolean;
420 parseable: typeof Boolean;
421 prefix: typeof String;
422 production: typeof Boolean;
423 "proprietary-attribs": typeof Boolean;
424 proxy: any[];
425 "https-proxy": any[];
426 "user-agent": typeof String;
427 "rebuild-bundle": Boolean;
428 registry: any[];
429 rollback: typeof Boolean;
430 save: typeof Boolean;
431 "save-bundle": typeof Boolean;
432 "save-dev": typeof Boolean;
433 "save-exact": typeof Boolean;
434 "save-optional": typeof Boolean;
435 "save-prefix": typeof String;
436 scope: typeof String;
437 searchopts: typeof String;
438 searchexclude: any[];
439 searchsort: any[];
440 shell: typeof String;
441 shrinkwrap: typeof Boolean;
442 "sign-git-tag": typeof Boolean;
443 spin: any[];
444 "strict-ssl": typeof Boolean;
445 tag: typeof String;
446 tmp: typeof String;
447 unicode: typeof Boolean;
448 "unsafe-perm": typeof Boolean;
449 usage: typeof Boolean;
450 user: any; // String | Number
451 userconfig: typeof String;
452 umask: typeof Number;
453 version: typeof Boolean;
454 versions: typeof Boolean;
455 viewer: typeof String;
456
457 _exit: typeof Boolean;
458 }
459
460 export interface ConfigShorthands {
461 s: any[];
462 d: any[];
463 dd: any[];
464 ddd: any[];
465 noreg: any[];
466 N: any[];
467 reg: any[];
468 "no-reg": any[];
469 silent: any[];
470 verbose: any[];
471 quiet: any[];
472 q: any[];
473 h: any[];
474 H: any[];
475 "?": any[];
476 help: any[];
477 v: any[];
478 f: any[];
479 gangster: any[];
480 gangsta: any[];
481 desc: any[];
482 "no-desc": any[];
483 "local": any[];
484 l: any[];
485 m: any[];
486 p: any[];
487 porcelain: any[];
488 g: any[];
489 S: any[];
490 D: any[];
491 E: any[];
492 O: any[];
493 y: any[];
494 n: any[];
495 B: any[];
496 C: any[];
497 }
498
499 export interface ConfigSource {
500 path: string;
501 type: string;
502 }
503
504 export interface Credentials {
505 scope: string;
506 token?: string | undefined;
507 password?: string | undefined;
508 username?: string | undefined;
509 email?: string | undefined;
510 auth?: string | undefined;
511 }
512
513 //#endregion
514
515 //#region Utilities Interfaces
516
517 export interface Dictionary<T> {
518 [key: string]: T;
519 }
520
521 export interface ErrorCallback {
522 (err?: Error): void;
523 }
524
525 export interface SimpleCallback<T> {
526 (err?: Error, result?: T): void;
527 }
528
529 //#endregion
530}