-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
npm.ts
1608 lines (1573 loc) · 46.1 KB
/
npm.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function uninstallSubcommand(named: string | string[]): Fig.Subcommand {
return {
name: named,
description: "Uninstall a package",
args: {
name: "package",
generators: dependenciesGenerator,
filterStrategy: "fuzzy",
isVariadic: true,
},
options: npmUninstallOptions,
};
}
const atsInStr = (s: string) => (s.match(/@/g) || []).length;
export const createNpmSearchHandler =
(keywords?: string[]) =>
async (
context: string[],
executeShellCommand: Fig.ExecuteCommandFunction,
shellContext: Fig.ShellContext
): Promise<Fig.Suggestion[]> => {
const searchTerm = context[context.length - 1];
if (searchTerm === "") {
return [];
}
// Add optional keyword parameter
const keywordParameter =
keywords?.length > 0 ? `+keywords:${keywords.join(",")}` : "";
const queryPackagesUrl = keywordParameter
? `https://api.npms.io/v2/search?size=20&q=${searchTerm}${keywordParameter}`
: `https://api.npms.io/v2/search/suggestions?q=${searchTerm}&size=20`;
// Query the API with the package name
const queryPackages = [
"-s",
"-H",
"Accept: application/json",
queryPackagesUrl,
];
// We need to remove the '@' at the end of the searchTerm before querying versions
const queryVersions = [
"-s",
"-H",
"Accept: application/vnd.npm.install-v1+json",
`https://registry.npmjs.org/${searchTerm.slice(0, -1)}`,
];
// If the end of our token is '@', then we want to generate version suggestions
// Otherwise, we want packages
const out = (query: string) =>
executeShellCommand({
command: "curl",
args: query[query.length - 1] === "@" ? queryVersions : queryPackages,
});
// If our token starts with '@', then a 2nd '@' tells us we want
// versions.
// Otherwise, '@' anywhere else in the string will indicate the same.
const shouldGetVersion = searchTerm.startsWith("@")
? atsInStr(searchTerm) > 1
: searchTerm.includes("@");
try {
const data = JSON.parse((await out(searchTerm)).stdout);
if (shouldGetVersion) {
// create dist tags suggestions
const versions = Object.entries(data["dist-tags"] || {}).map(
([key, value]) => ({
name: key,
description: value,
})
) as Fig.Suggestion[];
// create versions
versions.push(
...Object.keys(data.versions)
.map((version) => ({ name: version }) as Fig.Suggestion)
.reverse()
);
return versions;
}
const results = keywordParameter ? data.results : data;
return results.map((item) => ({
name: item.package.name,
description: item.package.description,
})) as Fig.Suggestion[];
} catch (error) {
console.error({ error });
return [];
}
};
// GENERATORS
export const npmSearchGenerator: Fig.Generator = {
trigger: (newToken, oldToken) => {
// If the package name starts with '@', we want to trigger when
// the 2nd '@' is typed because we'll need to generate version
// suggetsions
// e.g. @typescript-eslint/types
if (oldToken.startsWith("@")) {
return !(atsInStr(oldToken) > 1 && atsInStr(newToken) > 1);
}
// If the package name doesn't start with '@', then trigger when
// we see the first '@' so we can generate version suggestions
return !(oldToken.includes("@") && newToken.includes("@"));
},
getQueryTerm: "@",
cache: {
ttl: 1000 * 60 * 60 * 24 * 2, // 2 days
},
custom: createNpmSearchHandler(),
};
const workspaceGenerator: Fig.Generator = {
// script: "cat $(npm prefix)/package.json",
custom: async (tokens, executeShellCommand) => {
const { stdout: npmPrefix } = await executeShellCommand({
command: "npm",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: ["prefix"],
});
const { stdout: out } = await executeShellCommand({
command: "cat",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: [`${npmPrefix}/package.json`],
});
const suggestions = [];
try {
if (out.trim() == "") {
return suggestions;
}
const packageContent = JSON.parse(out);
const workspaces = packageContent["workspaces"];
if (workspaces) {
for (const workspace of workspaces) {
suggestions.push({
name: workspace,
description: "Workspaces",
});
}
}
} catch (e) {
console.log(e);
}
return suggestions;
},
};
/** Generator that lists package.json dependencies */
export const dependenciesGenerator: Fig.Generator = {
trigger: (newToken) => newToken === "-g" || newToken === "--global",
custom: async function (tokens, executeShellCommand) {
if (!tokens.includes("-g") && !tokens.includes("--global")) {
const { stdout: npmPrefix } = await executeShellCommand({
command: "npm",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: ["prefix"],
});
const { stdout: out } = await executeShellCommand({
command: "cat",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: [`${npmPrefix}/package.json`],
});
const packageContent = JSON.parse(out);
const dependencies = packageContent["dependencies"] ?? {};
const devDependencies = packageContent["devDependencies"];
const optionalDependencies = packageContent["optionalDependencies"] ?? {};
Object.assign(dependencies, devDependencies, optionalDependencies);
return Object.keys(dependencies)
.filter((pkgName) => {
const isListed = tokens.some((current) => current === pkgName);
return !isListed;
})
.map((pkgName) => ({
name: pkgName,
icon: "📦",
description: dependencies[pkgName]
? "dependency"
: optionalDependencies[pkgName]
? "optionalDependency"
: "devDependency",
}));
} else {
const { stdout } = await executeShellCommand({
command: "bash",
args: ["-c", "ls -1 `npm root -g`"],
});
return stdout.split("\n").map((name) => ({
name,
icon: "📦",
description: "Global dependency",
}));
}
},
};
/** Generator that lists package.json scripts (with the respect to the `fig` field) */
export const npmScriptsGenerator: Fig.Generator = {
cache: {
strategy: "stale-while-revalidate",
cacheByDirectory: true,
},
script: [
"bash",
"-c",
"until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json",
],
postProcess: function (out, [npmClient]) {
if (out.trim() == "") {
return [];
}
try {
const packageContent = JSON.parse(out);
const scripts = packageContent["scripts"];
const figCompletions = packageContent["fig"] || {};
if (scripts) {
return Object.entries(scripts).map(([scriptName, scriptContents]) => {
const icon =
npmClient === "yarn"
? "fig://icon?type=yarn"
: "fig://icon?type=npm";
const customScripts: Fig.Suggestion = figCompletions[scriptName];
return {
name: scriptName,
icon,
description: scriptContents as string,
priority: 51,
/**
* If there are custom definitions for the scripts
* we want to override the default values
* */
...customScripts,
};
});
}
} catch (e) {
console.error(e);
}
return [];
},
};
const globalOption: Fig.Option = {
name: ["-g", "--global"],
description:
"Operates in 'global' mode, so that packages are installed into the prefix folder instead of the current working directory",
};
const jsonOption: Fig.Option = {
name: "--json",
description: "Show output in json format",
};
const omitOption: Fig.Option = {
name: "--omit",
description: "Dependency types to omit from the installation tree on disk",
args: {
name: "Package type",
default: "dev",
suggestions: ["dev", "optional", "peer"],
},
isRepeatable: 3,
};
const parseableOption: Fig.Option = {
name: ["-p", "--parseable"],
description:
"Output parseable results from commands that write to standard output",
};
const longOption: Fig.Option = {
name: ["-l", "--long"],
description: "Show extended information",
};
const workSpaceOptions: Fig.Option[] = [
{
name: ["-w", "--workspace"],
description:
"Enable running a command in the context of the configured workspaces of the current project",
args: {
name: "workspace",
generators: workspaceGenerator,
isVariadic: true,
},
},
{
name: ["-ws", "--workspaces"],
description:
"Enable running a command in the context of all the configured workspaces",
},
];
const npmUninstallOptions: Fig.Option[] = [
{
name: ["-S", "--save"],
description: "Package will be removed from your dependencies",
},
{
name: ["-D", "--save-dev"],
description: "Package will appear in your `devDependencies`",
},
{
name: ["-O", "--save-optional"],
description: "Package will appear in your `optionalDependencies`",
},
{
name: "--no-save",
description: "Prevents saving to `dependencies`",
},
{
name: "-g",
description: "Uninstall global package",
},
...workSpaceOptions,
];
const npmListOptions: Fig.Option[] = [
{
name: ["-a", "-all"],
description: "Show all outdated or installed packages",
},
jsonOption,
longOption,
parseableOption,
{
name: "--depth",
description: "The depth to go when recursing packages",
args: { name: "depth" },
},
{
name: "--link",
description: "Limits output to only those packages that are linked",
},
{
name: "--package-lock-only",
description:
"Current operation will only use the package-lock.json, ignoring node_modules",
},
{
name: "--no-unicode",
description: "Uses unicode characters in the tree output",
},
globalOption,
omitOption,
...workSpaceOptions,
];
const registryOption: Fig.Option = {
name: "--registry",
description: "The base URL of the npm registry",
args: { name: "registry" },
};
const verboseOption: Fig.Option = {
name: "--verbose",
description: "Show extra information",
args: { name: "verbose" },
};
const otpOption: Fig.Option = {
name: "--otp",
description: "One-time password from a two-factor authenticator",
args: { name: "otp" },
};
const ignoreScriptsOption: Fig.Option = {
name: "--ignore-scripts",
description:
"If true, npm does not run scripts specified in package.json files",
};
const scriptShellOption: Fig.Option = {
name: "--script-shell",
description:
"The shell to use for scripts run with the npm exec, npm run and npm init <pkg> commands",
args: { name: "script-shell" },
};
const dryRunOption: Fig.Option = {
name: "--dry-run",
description:
"Indicates that you don't want npm to make any changes and that it should only report what it would have done",
};
const completionSpec: Fig.Spec = {
name: "npm",
parserDirectives: {
flagsArePosixNoncompliant: true,
},
description: "Node package manager",
subcommands: [
{
name: ["install", "i", "add"],
description: "Install a package and its dependencies",
args: {
name: "package",
isOptional: true,
generators: npmSearchGenerator,
debounce: true,
isVariadic: true,
},
options: [
{
name: ["-P", "--save-prod"],
description:
"Package will appear in your `dependencies`. This is the default unless `-D` or `-O` are present",
},
{
name: ["-D", "--save-dev"],
description: "Package will appear in your `devDependencies`",
},
{
name: ["-O", "--save-optional"],
description: "Package will appear in your `optionalDependencies`",
},
{
name: "--no-save",
description: "Prevents saving to `dependencies`",
},
{
name: ["-E", "--save-exact"],
description:
"Saved dependencies will be configured with an exact version rather than using npm's default semver range operator",
},
{
name: ["-B", "--save-bundle"],
description:
"Saved dependencies will also be added to your bundleDependencies list",
},
globalOption,
{
name: "--global-style",
description:
"Causes npm to install the package into your local node_modules folder with the same layout it uses with the global node_modules folder",
},
{
name: "--legacy-bundling",
description:
"Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package",
},
{
name: "--legacy-peer-deps",
description:
"Bypass peerDependency auto-installation. Emulate install behavior of NPM v4 through v6",
},
{
name: "--strict-peer-deps",
description:
"If set to true, and --legacy-peer-deps is not set, then any conflicting peerDependencies will be treated as an install failure",
},
{
name: "--no-package-lock",
description: "Ignores package-lock.json files when installing",
},
registryOption,
verboseOption,
omitOption,
ignoreScriptsOption,
{
name: "--no-audit",
description:
"Submit audit reports alongside the current npm command to the default registry and all registries configured for scopes",
},
{
name: "--no-bin-links",
description:
"Tells npm to not create symlinks (or .cmd shims on Windows) for package executables",
},
{
name: "--no-fund",
description:
"Hides the message at the end of each npm install acknowledging the number of dependencies looking for funding",
},
dryRunOption,
...workSpaceOptions,
],
},
{
name: ["run", "run-script"],
description: "Run arbitrary package scripts",
options: [
...workSpaceOptions,
{
name: "--if-present",
description:
"Npm will not exit with an error code when run-script is invoked for a script that isn't defined in the scripts section of package.json",
},
{
name: "--silent",
description: "",
},
ignoreScriptsOption,
scriptShellOption,
{
name: "--",
args: {
name: "args",
isVariadic: true,
// TODO: load the spec based on the runned script (see yarn spec `yarnScriptParsedDirectives`)
},
},
],
args: {
name: "script",
description: "Script to run from your package.json",
filterStrategy: "fuzzy",
generators: npmScriptsGenerator,
},
},
{
name: "init",
description: "Trigger the initialization",
options: [
{
name: ["-y", "--yes"],
description:
"Automatically answer 'yes' to any prompts that npm might print on the command line",
},
{
name: "-w",
description:
"Create the folders and boilerplate expected while also adding a reference to your project workspaces property",
args: { name: "dir" },
},
],
},
{ name: "access", description: "Set access controls on private packages" },
{
name: ["adduser", "login"],
description: "Add a registry user account",
options: [
registryOption,
{
name: "--scope",
description:
"Associate an operation with a scope for a scoped registry",
args: {
name: "scope",
description: "Scope name",
},
},
],
},
{
name: "audit",
description: "Run a security audit",
subcommands: [
{
name: "fix",
description:
"If the fix argument is provided, then remediations will be applied to the package tree",
options: [
dryRunOption,
{
name: ["-f", "--force"],
description:
"Removes various protections against unfortunate side effects, common mistakes, unnecessary performance degradation, and malicious input",
isDangerous: true,
},
...workSpaceOptions,
],
},
],
options: [
...workSpaceOptions,
{
name: "--audit-level",
description:
"The minimum level of vulnerability for npm audit to exit with a non-zero exit code",
args: {
name: "audit",
suggestions: [
"info",
"low",
"moderate",
"high",
"critical",
"none",
],
},
},
{
name: "--package-lock-only",
description:
"Current operation will only use the package-lock.json, ignoring node_modules",
},
jsonOption,
omitOption,
],
},
{
name: "bin",
description: "Print the folder where npm will install executables",
options: [globalOption],
},
{
name: ["bugs", "issues"],
description: "Report bugs for a package in a web browser",
args: {
name: "package",
isOptional: true,
generators: npmSearchGenerator,
debounce: true,
isVariadic: true,
},
options: [
{
name: "--no-browser",
description: "Display in command line instead of browser",
exclusiveOn: ["--browser"],
},
{
name: "--browser",
description:
"The browser that is called by the npm bugs command to open websites",
args: { name: "browser" },
exclusiveOn: ["--no-browser"],
},
registryOption,
],
},
{
name: "cache",
description: "Manipulates packages cache",
subcommands: [
{
name: "add",
description: "Add the specified packages to the local cache",
},
{
name: "clean",
description: "Delete all data out of the cache folder",
},
{
name: "verify",
description:
"Verify the contents of the cache folder, garbage collecting any unneeded data, and verifying the integrity of the cache index and all cached data",
},
],
options: [
{
name: "--cache",
args: { name: "cache" },
description: "The location of npm's cache directory",
},
],
},
{
name: ["ci", "clean-install", "install-clean"],
description: "Install a project with a clean slate",
options: [
{
name: "--audit",
description:
'When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes',
args: {
name: "audit",
suggestions: ["true", "false"],
},
exclusiveOn: ["--no-audit"],
},
{
name: "--no-audit",
description:
"Do not submit audit reports alongside the current npm command",
exclusiveOn: ["--audit"],
},
ignoreScriptsOption,
scriptShellOption,
verboseOption,
registryOption,
],
},
{
name: "cit",
description: "Install a project with a clean slate and run tests",
},
{
name: "clean-install-test",
description: "Install a project with a clean slate and run tests",
},
{ name: "completion", description: "Tab completion for npm" },
{
name: ["config", "c"],
description: "Manage the npm configuration files",
subcommands: [
{
name: "set",
description: "Sets the config key to the value",
args: [{ name: "key" }, { name: "value" }],
options: [
{ name: ["-g", "--global"], description: "Sets it globally" },
],
},
{
name: "get",
description: "Echo the config value to stdout",
args: { name: "key" },
},
{
name: "list",
description: "Show all the config settings",
options: [
{ name: "-g", description: "Lists globally installed packages" },
{ name: "-l", description: "Also shows defaults" },
jsonOption,
],
},
{
name: "delete",
description: "Deletes the key from all configuration files",
args: { name: "key" },
},
{
name: "edit",
description: "Opens the config file in an editor",
options: [
{ name: "--global", description: "Edits the global config" },
],
},
],
},
{ name: "create", description: "Create a package.json file" },
{
name: ["dedupe", "ddp"],
description: "Reduce duplication in the package tree",
},
{
name: "deprecate",
description: "Deprecate a version of a package",
options: [registryOption],
},
{ name: "dist-tag", description: "Modify package distribution tags" },
{
name: ["docs", "home"],
description: "Open documentation for a package in a web browser",
args: {
name: "package",
isOptional: true,
generators: npmSearchGenerator,
debounce: true,
isVariadic: true,
},
options: [
...workSpaceOptions,
registryOption,
{
name: "--no-browser",
description: "Display in command line instead of browser",
exclusiveOn: ["--browser"],
},
{
name: "--browser",
description:
"The browser that is called by the npm docs command to open websites",
args: { name: "browser" },
exclusiveOn: ["--no-browser"],
},
],
},
{
name: "doctor",
description: "Check your npm environment",
options: [registryOption],
},
{
name: "edit",
description: "Edit an installed package",
options: [
{
name: "--editor",
description: "The command to run for npm edit or npm config edit",
},
],
},
{
name: "explore",
description: "Browse an installed package",
args: {
name: "package",
filterStrategy: "fuzzy",
generators: dependenciesGenerator,
},
},
{ name: "fund", description: "Retrieve funding information" },
{ name: "get", description: "Echo the config value to stdout" },
{
name: "help",
description: "Get help on npm",
args: {
name: "term",
isVariadic: true,
description: "Terms to search for",
},
options: [
{
name: "--viewer",
description: "The program to use to view help content",
args: {
name: "viewer",
},
},
],
},
{
name: "help-search",
description: "Search npm help documentation",
args: {
name: "text",
description: "Text to search for",
},
options: [longOption],
},
{ name: "hook", description: "Manage registry hooks" },
{
name: "install-ci-test",
description: "Install a project with a clean slate and run tests",
},
{ name: "install-test", description: "Install package(s) and run tests" },
{ name: "it", description: "Install package(s) and run tests" },
{
name: "link",
description: "Symlink a package folder",
args: { name: "path", template: "filepaths" },
},
{ name: "ln", description: "Symlink a package folder" },
{
name: "logout",
description: "Log out of the registry",
options: [
registryOption,
{
name: "--scope",
description:
"Associate an operation with a scope for a scoped registry",
args: {
name: "scope",
description: "Scope name",
},
},
],
},
{
name: ["ls", "list"],
description: "List installed packages",
options: npmListOptions,
args: { name: "[@scope]/pkg", isVariadic: true },
},
{
name: "org",
description: "Manage orgs",
subcommands: [
{
name: "set",
description: "Add a user to an org or manage roles",
args: [
{
name: "orgname",
description: "Organization name",
},
{
name: "username",
description: "User name",
},
{
name: "role",
isOptional: true,
suggestions: ["developer", "admin", "owner"],
},
],
options: [registryOption, otpOption],
},
{
name: "rm",
description: "Remove a user from an org",
args: [
{
name: "orgname",
description: "Organization name",
},
{
name: "username",
description: "User name",
},
],
options: [registryOption, otpOption],
},
{
name: "ls",
description:
"List users in an org or see what roles a particular user has in an org",
args: [
{
name: "orgname",
description: "Organization name",
},
{
name: "username",
description: "User name",
isOptional: true,
},
],
options: [registryOption, otpOption, jsonOption, parseableOption],
},
],
},
{
name: "outdated",
description: "Check for outdated packages",
args: {
name: "[<@scope>/]<pkg>",
isVariadic: true,
isOptional: true,
},
options: [
{
name: ["-a", "-all"],
description: "Show all outdated or installed packages",
},
jsonOption,
longOption,
parseableOption,
{
name: "-g",
description: "Checks globally",
},
...workSpaceOptions,
],
},
{
name: ["owner", "author"],
description: "Manage package owners",
subcommands: [
{
name: "ls",
description:
"List all the users who have access to modify a package and push new versions. Handy when you need to know who to bug for help",
args: { name: "[@scope/]pkg" },
options: [registryOption],
},
{
name: "add",
description:
"Add a new user as a maintainer of a package. This user is enabled to modify metadata, publish new versions, and add other owners",
args: [{ name: "user" }, { name: "[@scope/]pkg" }],
options: [registryOption, otpOption],
},
{
name: "rm",
description:
"Remove a user from the package owner list. This immediately revokes their privileges",
args: [{ name: "user" }, { name: "[@scope/]pkg" }],
options: [registryOption, otpOption],
},
],
},
{
name: "pack",
description: "Create a tarball from a package",
args: {
name: "[<@scope>/]<pkg>",
},
options: [
jsonOption,
dryRunOption,
...workSpaceOptions,
{
name: "--pack-destination",
description: "Directory in which npm pack will save tarballs",
args: {
name: "pack-destination",
template: ["folders"],
},
},
],
},
{
name: "ping",
description: "Ping npm registry",
options: [registryOption],
},
{
name: "pkg",
description: "Manages your package.json",
subcommands: [
{
name: "get",
description:
"Retrieves a value key, defined in your package.json file. It is possible to get multiple values and values for child fields",