@0xrama/bnpm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -0
- package/dist/package.json +45 -0
- package/dist/src/cache/archive.d.ts +15 -0
- package/dist/src/cache/archive.js +163 -0
- package/dist/src/cache/archive.js.map +1 -0
- package/dist/src/cache/commands.d.ts +15 -0
- package/dist/src/cache/commands.js +168 -0
- package/dist/src/cache/commands.js.map +1 -0
- package/dist/src/cache/quarantine.d.ts +18 -0
- package/dist/src/cache/quarantine.js +104 -0
- package/dist/src/cache/quarantine.js.map +1 -0
- package/dist/src/cache/store.d.ts +10 -0
- package/dist/src/cache/store.js +155 -0
- package/dist/src/cache/store.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +4 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/diff.d.ts +34 -0
- package/dist/src/commands/diff.js +223 -0
- package/dist/src/commands/diff.js.map +1 -0
- package/dist/src/commands/doctor.d.ts +14 -0
- package/dist/src/commands/doctor.js +42 -0
- package/dist/src/commands/doctor.js.map +1 -0
- package/dist/src/commands/edit.d.ts +12 -0
- package/dist/src/commands/edit.js +100 -0
- package/dist/src/commands/edit.js.map +1 -0
- package/dist/src/commands/fund.d.ts +10 -0
- package/dist/src/commands/fund.js +32 -0
- package/dist/src/commands/fund.js.map +1 -0
- package/dist/src/commands/graph.d.ts +29 -0
- package/dist/src/commands/graph.js +90 -0
- package/dist/src/commands/graph.js.map +1 -0
- package/dist/src/commands/index.d.ts +20 -0
- package/dist/src/commands/index.js +1753 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/navigation.d.ts +2 -0
- package/dist/src/commands/navigation.js +47 -0
- package/dist/src/commands/navigation.js.map +1 -0
- package/dist/src/commands/outdated.d.ts +17 -0
- package/dist/src/commands/outdated.js +69 -0
- package/dist/src/commands/outdated.js.map +1 -0
- package/dist/src/commands/process.d.ts +11 -0
- package/dist/src/commands/process.js +189 -0
- package/dist/src/commands/process.js.map +1 -0
- package/dist/src/commands/prompts.d.ts +6 -0
- package/dist/src/commands/prompts.js +86 -0
- package/dist/src/commands/prompts.js.map +1 -0
- package/dist/src/commands/query.d.ts +48 -0
- package/dist/src/commands/query.js +639 -0
- package/dist/src/commands/query.js.map +1 -0
- package/dist/src/commands/rebuild.d.ts +16 -0
- package/dist/src/commands/rebuild.js +44 -0
- package/dist/src/commands/rebuild.js.map +1 -0
- package/dist/src/commands/sbom.d.ts +6 -0
- package/dist/src/commands/sbom.js +31 -0
- package/dist/src/commands/sbom.js.map +1 -0
- package/dist/src/commands/script-approvals.d.ts +22 -0
- package/dist/src/commands/script-approvals.js +128 -0
- package/dist/src/commands/script-approvals.js.map +1 -0
- package/dist/src/commands/shrinkwrap.d.ts +6 -0
- package/dist/src/commands/shrinkwrap.js +97 -0
- package/dist/src/commands/shrinkwrap.js.map +1 -0
- package/dist/src/commands/stage.d.ts +20 -0
- package/dist/src/commands/stage.js +40 -0
- package/dist/src/commands/stage.js.map +1 -0
- package/dist/src/commands/token.d.ts +2 -0
- package/dist/src/commands/token.js +47 -0
- package/dist/src/commands/token.js.map +1 -0
- package/dist/src/commands/trust.d.ts +5 -0
- package/dist/src/commands/trust.js +41 -0
- package/dist/src/commands/trust.js.map +1 -0
- package/dist/src/config/commands.d.ts +5 -0
- package/dist/src/config/commands.js +91 -0
- package/dist/src/config/commands.js.map +1 -0
- package/dist/src/config/configuration.d.ts +40 -0
- package/dist/src/config/configuration.js +157 -0
- package/dist/src/config/configuration.js.map +1 -0
- package/dist/src/config/interactive.d.ts +16 -0
- package/dist/src/config/interactive.js +19 -0
- package/dist/src/config/interactive.js.map +1 -0
- package/dist/src/config/paths.d.ts +22 -0
- package/dist/src/config/paths.js +46 -0
- package/dist/src/config/paths.js.map +1 -0
- package/dist/src/config/types.d.ts +15 -0
- package/dist/src/config/types.js +6 -0
- package/dist/src/config/types.js.map +1 -0
- package/dist/src/core/cli-parser.d.ts +102 -0
- package/dist/src/core/cli-parser.js +1148 -0
- package/dist/src/core/cli-parser.js.map +1 -0
- package/dist/src/core/cli-runner.d.ts +15 -0
- package/dist/src/core/cli-runner.js +261 -0
- package/dist/src/core/cli-runner.js.map +1 -0
- package/dist/src/core/exit-codes.d.ts +13 -0
- package/dist/src/core/exit-codes.js +13 -0
- package/dist/src/core/exit-codes.js.map +1 -0
- package/dist/src/core/output.d.ts +23 -0
- package/dist/src/core/output.js +123 -0
- package/dist/src/core/output.js.map +1 -0
- package/dist/src/installer/install.d.ts +73 -0
- package/dist/src/installer/install.js +596 -0
- package/dist/src/installer/install.js.map +1 -0
- package/dist/src/installer/mutations.d.ts +5 -0
- package/dist/src/installer/mutations.js +160 -0
- package/dist/src/installer/mutations.js.map +1 -0
- package/dist/src/linker/project-linker.d.ts +9 -0
- package/dist/src/linker/project-linker.js +223 -0
- package/dist/src/linker/project-linker.js.map +1 -0
- package/dist/src/lockfile/index.d.ts +27 -0
- package/dist/src/lockfile/index.js +221 -0
- package/dist/src/lockfile/index.js.map +1 -0
- package/dist/src/package/authoring.d.ts +31 -0
- package/dist/src/package/authoring.js +125 -0
- package/dist/src/package/authoring.js.map +1 -0
- package/dist/src/package/pack.d.ts +22 -0
- package/dist/src/package/pack.js +238 -0
- package/dist/src/package/pack.js.map +1 -0
- package/dist/src/package/provenance.d.ts +28 -0
- package/dist/src/package/provenance.js +162 -0
- package/dist/src/package/provenance.js.map +1 -0
- package/dist/src/package/publish.d.ts +28 -0
- package/dist/src/package/publish.js +189 -0
- package/dist/src/package/publish.js.map +1 -0
- package/dist/src/package/trusted-publishing.d.ts +7 -0
- package/dist/src/package/trusted-publishing.js +84 -0
- package/dist/src/package/trusted-publishing.js.map +1 -0
- package/dist/src/project/dependency-error.d.ts +3 -0
- package/dist/src/project/dependency-error.js +7 -0
- package/dist/src/project/dependency-error.js.map +1 -0
- package/dist/src/project/dev-engines.d.ts +10 -0
- package/dist/src/project/dev-engines.js +70 -0
- package/dist/src/project/dev-engines.js.map +1 -0
- package/dist/src/project/discovery.d.ts +6 -0
- package/dist/src/project/discovery.js +51 -0
- package/dist/src/project/discovery.js.map +1 -0
- package/dist/src/project/global.d.ts +3 -0
- package/dist/src/project/global.js +43 -0
- package/dist/src/project/global.js.map +1 -0
- package/dist/src/project/invalidation.d.ts +3 -0
- package/dist/src/project/invalidation.js +21 -0
- package/dist/src/project/invalidation.js.map +1 -0
- package/dist/src/project/link.d.ts +21 -0
- package/dist/src/project/link.js +152 -0
- package/dist/src/project/link.js.map +1 -0
- package/dist/src/project/manifest.d.ts +27 -0
- package/dist/src/project/manifest.js +378 -0
- package/dist/src/project/manifest.js.map +1 -0
- package/dist/src/project/pkg.d.ts +5 -0
- package/dist/src/project/pkg.js +94 -0
- package/dist/src/project/pkg.js.map +1 -0
- package/dist/src/project/recovery.d.ts +2 -0
- package/dist/src/project/recovery.js +82 -0
- package/dist/src/project/recovery.js.map +1 -0
- package/dist/src/project/workspaces.d.ts +4 -0
- package/dist/src/project/workspaces.js +59 -0
- package/dist/src/project/workspaces.js.map +1 -0
- package/dist/src/registry/account.d.ts +79 -0
- package/dist/src/registry/account.js +305 -0
- package/dist/src/registry/account.js.map +1 -0
- package/dist/src/registry/audit.d.ts +18 -0
- package/dist/src/registry/audit.js +74 -0
- package/dist/src/registry/audit.js.map +1 -0
- package/dist/src/registry/client.d.ts +19 -0
- package/dist/src/registry/client.js +102 -0
- package/dist/src/registry/client.js.map +1 -0
- package/dist/src/registry/configuration.d.ts +36 -0
- package/dist/src/registry/configuration.js +133 -0
- package/dist/src/registry/configuration.js.map +1 -0
- package/dist/src/registry/operations.d.ts +163 -0
- package/dist/src/registry/operations.js +502 -0
- package/dist/src/registry/operations.js.map +1 -0
- package/dist/src/registry/types.d.ts +30 -0
- package/dist/src/registry/types.js +2 -0
- package/dist/src/registry/types.js.map +1 -0
- package/dist/src/resolver/registry-resolver.d.ts +40 -0
- package/dist/src/resolver/registry-resolver.js +354 -0
- package/dist/src/resolver/registry-resolver.js.map +1 -0
- package/dist/src/resolver/source-provider.d.ts +17 -0
- package/dist/src/resolver/source-provider.js +336 -0
- package/dist/src/resolver/source-provider.js.map +1 -0
- package/dist/src/resolver/types.d.ts +28 -0
- package/dist/src/resolver/types.js +2 -0
- package/dist/src/resolver/types.js.map +1 -0
- package/dist/src/security/analyzer.d.ts +38 -0
- package/dist/src/security/analyzer.js +241 -0
- package/dist/src/security/analyzer.js.map +1 -0
- package/dist/src/security/audit.d.ts +19 -0
- package/dist/src/security/audit.js +61 -0
- package/dist/src/security/audit.js.map +1 -0
- package/dist/src/security/findings.d.ts +23 -0
- package/dist/src/security/findings.js +2 -0
- package/dist/src/security/findings.js.map +1 -0
- package/dist/src/security/integrity.d.ts +14 -0
- package/dist/src/security/integrity.js +40 -0
- package/dist/src/security/integrity.js.map +1 -0
- package/dist/src/security/policy.d.ts +16 -0
- package/dist/src/security/policy.js +24 -0
- package/dist/src/security/policy.js.map +1 -0
- package/dist/src/security/recent-release.d.ts +19 -0
- package/dist/src/security/recent-release.js +27 -0
- package/dist/src/security/recent-release.js.map +1 -0
- package/dist/src/security/script-runner.d.ts +13 -0
- package/dist/src/security/script-runner.js +73 -0
- package/dist/src/security/script-runner.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,1148 @@
|
|
|
1
|
+
import npa from "npm-package-arg";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
export class UsageError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(`Usage: ${message}`);
|
|
6
|
+
this.name = "UsageError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const commandAliases = {
|
|
10
|
+
install: "install",
|
|
11
|
+
i: "install",
|
|
12
|
+
ci: "install",
|
|
13
|
+
add: "add",
|
|
14
|
+
remove: "remove",
|
|
15
|
+
uninstall: "remove",
|
|
16
|
+
rm: "remove",
|
|
17
|
+
un: "remove",
|
|
18
|
+
r: "remove",
|
|
19
|
+
update: "update",
|
|
20
|
+
outdated: "outdated",
|
|
21
|
+
list: "list",
|
|
22
|
+
ls: "list",
|
|
23
|
+
ll: "list",
|
|
24
|
+
la: "list",
|
|
25
|
+
why: "why",
|
|
26
|
+
explain: "why",
|
|
27
|
+
query: "query",
|
|
28
|
+
diff: "diff",
|
|
29
|
+
"find-dupes": "find-dupes",
|
|
30
|
+
bin: "bin",
|
|
31
|
+
prefix: "prefix",
|
|
32
|
+
root: "root",
|
|
33
|
+
run: "run",
|
|
34
|
+
"run-script": "run",
|
|
35
|
+
test: "run",
|
|
36
|
+
start: "run",
|
|
37
|
+
stop: "run",
|
|
38
|
+
restart: "restart",
|
|
39
|
+
"install-test": "install-test",
|
|
40
|
+
it: "install-test",
|
|
41
|
+
"install-ci-test": "install-ci-test",
|
|
42
|
+
cit: "install-ci-test",
|
|
43
|
+
audit: "audit",
|
|
44
|
+
exec: "exec",
|
|
45
|
+
explore: "explore",
|
|
46
|
+
edit: "edit",
|
|
47
|
+
pack: "pack",
|
|
48
|
+
publish: "publish",
|
|
49
|
+
stage: "stage",
|
|
50
|
+
unpublish: "unpublish",
|
|
51
|
+
access: "access",
|
|
52
|
+
owner: "owner",
|
|
53
|
+
token: "token",
|
|
54
|
+
star: "star",
|
|
55
|
+
unstar: "unstar",
|
|
56
|
+
stars: "stars",
|
|
57
|
+
org: "org",
|
|
58
|
+
team: "team",
|
|
59
|
+
profile: "profile",
|
|
60
|
+
trust: "trust",
|
|
61
|
+
login: "login",
|
|
62
|
+
adduser: "login",
|
|
63
|
+
logout: "logout",
|
|
64
|
+
whoami: "whoami",
|
|
65
|
+
view: "view",
|
|
66
|
+
info: "view",
|
|
67
|
+
search: "search",
|
|
68
|
+
repo: "repo",
|
|
69
|
+
docs: "docs",
|
|
70
|
+
bugs: "bugs",
|
|
71
|
+
dist: "dist-tag",
|
|
72
|
+
"dist-tag": "dist-tag",
|
|
73
|
+
deprecate: "deprecate",
|
|
74
|
+
undeprecate: "deprecate",
|
|
75
|
+
config: "config",
|
|
76
|
+
get: "config",
|
|
77
|
+
set: "config",
|
|
78
|
+
init: "init",
|
|
79
|
+
create: "init",
|
|
80
|
+
innit: "init",
|
|
81
|
+
version: "version",
|
|
82
|
+
verison: "version",
|
|
83
|
+
shrinkwrap: "shrinkwrap",
|
|
84
|
+
prune: "prune",
|
|
85
|
+
dedupe: "dedupe",
|
|
86
|
+
ddp: "dedupe",
|
|
87
|
+
rebuild: "rebuild",
|
|
88
|
+
rb: "rebuild",
|
|
89
|
+
"install-scripts": "install-scripts",
|
|
90
|
+
"approve-scripts": "approve-scripts",
|
|
91
|
+
"deny-scripts": "deny-scripts",
|
|
92
|
+
fund: "fund",
|
|
93
|
+
cache: "cache",
|
|
94
|
+
ping: "ping",
|
|
95
|
+
doctor: "doctor",
|
|
96
|
+
completion: "completion",
|
|
97
|
+
pkg: "pkg",
|
|
98
|
+
sbom: "sbom",
|
|
99
|
+
link: "link",
|
|
100
|
+
unlink: "unlink",
|
|
101
|
+
};
|
|
102
|
+
const saveFlags = {
|
|
103
|
+
"--save-prod": "prod",
|
|
104
|
+
"--save-dev": "dev",
|
|
105
|
+
"-D": "dev",
|
|
106
|
+
"--save-optional": "optional",
|
|
107
|
+
"-O": "optional",
|
|
108
|
+
"--save-peer": "peer",
|
|
109
|
+
};
|
|
110
|
+
function requireOverride(flag, value) {
|
|
111
|
+
if (!value) {
|
|
112
|
+
throw new UsageError(`${flag} requires an exact name@version value`);
|
|
113
|
+
}
|
|
114
|
+
const at = value.lastIndexOf("@");
|
|
115
|
+
if (at <= 0 || at === value.length - 1 || value.slice(at + 1).includes("@")) {
|
|
116
|
+
throw new UsageError(`${flag} requires an exact name@version value`);
|
|
117
|
+
}
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = npa(value);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
throw new UsageError(`${flag} requires an exact name@version value`);
|
|
124
|
+
}
|
|
125
|
+
if (parsed.type !== "version" || parsed.name === undefined || parsed.rawSpec !== value.slice(at + 1)) {
|
|
126
|
+
throw new UsageError(`${flag} requires an exact name@version value`);
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
function consumeGlobal(args) {
|
|
131
|
+
let json = false;
|
|
132
|
+
let details = false;
|
|
133
|
+
let registry;
|
|
134
|
+
const allowRecent = [];
|
|
135
|
+
const allowDangerous = [];
|
|
136
|
+
let index = 0;
|
|
137
|
+
while (index < args.length) {
|
|
138
|
+
const arg = args[index];
|
|
139
|
+
if (arg === undefined) {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (arg === "--json") {
|
|
143
|
+
json = true;
|
|
144
|
+
index += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (arg === "--details") {
|
|
148
|
+
details = true;
|
|
149
|
+
index += 1;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (arg === "--registry" || arg.startsWith("--registry=")) {
|
|
153
|
+
const value = arg === "--registry" ? args[index + 1] : arg.slice("--registry=".length);
|
|
154
|
+
let parsed;
|
|
155
|
+
try {
|
|
156
|
+
parsed = new URL(value ?? "");
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
throw new UsageError("--registry requires an absolute HTTPS URL");
|
|
160
|
+
}
|
|
161
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash) {
|
|
162
|
+
throw new UsageError("--registry requires an HTTPS URL without embedded credentials, query, or fragment");
|
|
163
|
+
}
|
|
164
|
+
registry = parsed.href;
|
|
165
|
+
index += arg === "--registry" ? 2 : 1;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (arg === "--allow-recent" || arg === "--allow-dangerous") {
|
|
169
|
+
const value = args[index + 1];
|
|
170
|
+
const override = requireOverride(arg, value);
|
|
171
|
+
(arg === "--allow-recent" ? allowRecent : allowDangerous).push(override);
|
|
172
|
+
index += 2;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (arg.startsWith("--allow-recent=")) {
|
|
176
|
+
allowRecent.push(requireOverride("--allow-recent", arg.slice("--allow-recent=".length)));
|
|
177
|
+
index += 1;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (arg.startsWith("--allow-dangerous=")) {
|
|
181
|
+
allowDangerous.push(requireOverride("--allow-dangerous", arg.slice("--allow-dangerous=".length)));
|
|
182
|
+
index += 1;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return { options: { json, ...(details ? { details: true } : {}), ...(registry === undefined ? {} : { registry }), allowRecent, allowDangerous }, rest: args.slice(index) };
|
|
188
|
+
}
|
|
189
|
+
function validateSpecifier(specifier) {
|
|
190
|
+
let parsed;
|
|
191
|
+
try {
|
|
192
|
+
parsed = npa(specifier);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
if (/^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*@workspace:(?:[*~^]|[~^]?\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/.test(specifier)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
throw new UsageError(`invalid package specification: ${specifier}`);
|
|
199
|
+
}
|
|
200
|
+
if (parsed.type === "directory") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (parsed.type === "file") {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (parsed.type === "remote") {
|
|
207
|
+
const url = new URL(parsed.fetchSpec);
|
|
208
|
+
if (url.protocol === "https:" && !url.username && !url.password && !url.hash)
|
|
209
|
+
return;
|
|
210
|
+
throw new UsageError(`HTTPS tarball specifications must not embed credentials or fragments: ${specifier}`);
|
|
211
|
+
}
|
|
212
|
+
if (parsed.type === "git") {
|
|
213
|
+
const hosted = parsed.hosted;
|
|
214
|
+
const value = typeof parsed.fetchSpec === "string" ? parsed.fetchSpec : hosted?.https({ noCommittish: true, noGitPlus: true });
|
|
215
|
+
const url = new URL(value ?? "");
|
|
216
|
+
const secureTransport = (url.protocol === "https:" && !url.username) || url.protocol === "ssh:";
|
|
217
|
+
if (secureTransport && !url.password && !url.search && !url.hash && (parsed.gitRange === undefined || semver.validRange(parsed.gitRange)))
|
|
218
|
+
return;
|
|
219
|
+
throw new UsageError(`Git specifications must use HTTPS or SSH without embedded passwords: ${specifier}`);
|
|
220
|
+
}
|
|
221
|
+
if (!["version", "range", "tag", "alias"].includes(parsed.type)) {
|
|
222
|
+
throw new UsageError(`unsupported package source: ${specifier}`);
|
|
223
|
+
}
|
|
224
|
+
if (parsed.type === "alias" && "subSpec" in parsed && parsed.subSpec) {
|
|
225
|
+
validateSpecifier(parsed.subSpec.raw);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function parseCommandOptions(args, global) {
|
|
229
|
+
let frozenLockfile = false;
|
|
230
|
+
let offline = false;
|
|
231
|
+
const omitted = new Set(process.env.NODE_ENV === "production" ? ["dev"] : []);
|
|
232
|
+
let saveSection;
|
|
233
|
+
let saveExact = false;
|
|
234
|
+
let noSave = false;
|
|
235
|
+
let globalInstall = false;
|
|
236
|
+
let dryRun = false;
|
|
237
|
+
let packDestination;
|
|
238
|
+
let tag;
|
|
239
|
+
let access;
|
|
240
|
+
let otp;
|
|
241
|
+
let provenance = false;
|
|
242
|
+
let provenanceFile;
|
|
243
|
+
let yes = false;
|
|
244
|
+
let force = false;
|
|
245
|
+
let workspaces = false;
|
|
246
|
+
const workspaceNames = [];
|
|
247
|
+
let includeWorkspaceRoot = false;
|
|
248
|
+
let ifPresent = false;
|
|
249
|
+
let ignoreScripts = false;
|
|
250
|
+
let sbomFormat;
|
|
251
|
+
let trustFile;
|
|
252
|
+
let trustRepository;
|
|
253
|
+
let trustProject;
|
|
254
|
+
let trustEnvironment;
|
|
255
|
+
let trustOrganizationId;
|
|
256
|
+
let trustProjectId;
|
|
257
|
+
let trustPipelineDefinitionId;
|
|
258
|
+
let trustVcsOrigin;
|
|
259
|
+
const trustContextIds = [];
|
|
260
|
+
let allowPublish = false;
|
|
261
|
+
let allowStagePublish = false;
|
|
262
|
+
let tokenName;
|
|
263
|
+
let tokenDescription;
|
|
264
|
+
let tokenExpires;
|
|
265
|
+
const tokenPackages = [];
|
|
266
|
+
let tokenPackagesAll = false;
|
|
267
|
+
const tokenScopes = [];
|
|
268
|
+
const tokenOrganizations = [];
|
|
269
|
+
let tokenPackagesPermission;
|
|
270
|
+
let tokenOrganizationsPermission;
|
|
271
|
+
const tokenCidrs = [];
|
|
272
|
+
let tokenBypass2fa = false;
|
|
273
|
+
let tokenReadOnly = false;
|
|
274
|
+
let authType;
|
|
275
|
+
let expectResults;
|
|
276
|
+
let expectResultCount;
|
|
277
|
+
let packageLockOnly = false;
|
|
278
|
+
const execPackages = [];
|
|
279
|
+
let gitTagVersion = true;
|
|
280
|
+
let commitHooks = true;
|
|
281
|
+
let signGitTag = false;
|
|
282
|
+
let versionMessage;
|
|
283
|
+
let preid;
|
|
284
|
+
let allowSameVersion = false;
|
|
285
|
+
const diffSpecs = [];
|
|
286
|
+
let diffNameOnly = false;
|
|
287
|
+
let diffUnified;
|
|
288
|
+
let diffIgnoreAllSpace = false;
|
|
289
|
+
let diffNoPrefix = false;
|
|
290
|
+
let diffSrcPrefix;
|
|
291
|
+
let diffDstPrefix;
|
|
292
|
+
let diffText = false;
|
|
293
|
+
let index = 0;
|
|
294
|
+
while (index < args.length) {
|
|
295
|
+
const arg = args[index];
|
|
296
|
+
if (arg === undefined) {
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
if (arg === "--frozen-lockfile") {
|
|
300
|
+
frozenLockfile = true;
|
|
301
|
+
}
|
|
302
|
+
else if (arg === "--offline") {
|
|
303
|
+
offline = true;
|
|
304
|
+
}
|
|
305
|
+
else if (arg === "--production" || arg === "--production=true" || arg === "--only=prod" || arg === "--only=production") {
|
|
306
|
+
omitted.add("dev");
|
|
307
|
+
}
|
|
308
|
+
else if (arg === "--omit" || arg.startsWith("--omit=")) {
|
|
309
|
+
const value = arg === "--omit" ? args[index + 1] : arg.slice("--omit=".length);
|
|
310
|
+
const values = value?.split(",") ?? [];
|
|
311
|
+
if (values.length === 0 || values.some((entry) => !["dev", "optional", "peer"].includes(entry)))
|
|
312
|
+
throw new UsageError("--omit requires dev, optional, or peer");
|
|
313
|
+
for (const entry of values)
|
|
314
|
+
omitted.add(entry);
|
|
315
|
+
if (arg === "--omit")
|
|
316
|
+
index += 1;
|
|
317
|
+
}
|
|
318
|
+
else if (arg === "--include" || arg.startsWith("--include=") || arg === "--production=false") {
|
|
319
|
+
const value = arg === "--production=false" ? "dev" : arg === "--include" ? args[index + 1] : arg.slice("--include=".length);
|
|
320
|
+
const values = value?.split(",") ?? [];
|
|
321
|
+
if (values.length === 0 || values.some((entry) => !["dev", "optional", "peer", "prod"].includes(entry)))
|
|
322
|
+
throw new UsageError("--include requires prod, dev, optional, or peer");
|
|
323
|
+
for (const entry of values)
|
|
324
|
+
if (entry !== "prod")
|
|
325
|
+
omitted.delete(entry);
|
|
326
|
+
if (arg === "--include")
|
|
327
|
+
index += 1;
|
|
328
|
+
}
|
|
329
|
+
else if (arg === "--save-exact" || arg === "-E") {
|
|
330
|
+
saveExact = true;
|
|
331
|
+
}
|
|
332
|
+
else if (arg === "--no-save") {
|
|
333
|
+
noSave = true;
|
|
334
|
+
}
|
|
335
|
+
else if (arg === "--global" || arg === "-g") {
|
|
336
|
+
globalInstall = true;
|
|
337
|
+
}
|
|
338
|
+
else if (arg === "--dry-run") {
|
|
339
|
+
dryRun = true;
|
|
340
|
+
}
|
|
341
|
+
else if (arg === "--pack-destination" || arg.startsWith("--pack-destination=")) {
|
|
342
|
+
const value = arg === "--pack-destination" ? args[index + 1] : arg.slice("--pack-destination=".length);
|
|
343
|
+
if (!value || value.startsWith("-"))
|
|
344
|
+
throw new UsageError("--pack-destination requires a directory");
|
|
345
|
+
packDestination = value;
|
|
346
|
+
if (arg === "--pack-destination")
|
|
347
|
+
index += 1;
|
|
348
|
+
}
|
|
349
|
+
else if (arg === "--tag" || arg.startsWith("--tag=")) {
|
|
350
|
+
const value = arg === "--tag" ? args[index + 1] : arg.slice("--tag=".length);
|
|
351
|
+
if (!value || value.startsWith("-") || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value))
|
|
352
|
+
throw new UsageError("--tag requires a valid distribution tag");
|
|
353
|
+
tag = value;
|
|
354
|
+
if (arg === "--tag")
|
|
355
|
+
index += 1;
|
|
356
|
+
}
|
|
357
|
+
else if (arg === "--access" || arg.startsWith("--access=")) {
|
|
358
|
+
const value = arg === "--access" ? args[index + 1] : arg.slice("--access=".length);
|
|
359
|
+
if (value === "private")
|
|
360
|
+
access = "restricted";
|
|
361
|
+
else if (value === "public" || value === "restricted")
|
|
362
|
+
access = value;
|
|
363
|
+
else
|
|
364
|
+
throw new UsageError("--access must be public, restricted, or private");
|
|
365
|
+
if (arg === "--access")
|
|
366
|
+
index += 1;
|
|
367
|
+
}
|
|
368
|
+
else if (arg === "--otp" || arg.startsWith("--otp=")) {
|
|
369
|
+
const value = arg === "--otp" ? args[index + 1] : arg.slice("--otp=".length);
|
|
370
|
+
if (!value || value.startsWith("-") || !/^\d{6,10}$/.test(value))
|
|
371
|
+
throw new UsageError("--otp requires a 6-10 digit one-time password");
|
|
372
|
+
otp = value;
|
|
373
|
+
if (arg === "--otp")
|
|
374
|
+
index += 1;
|
|
375
|
+
}
|
|
376
|
+
else if (arg === "--provenance") {
|
|
377
|
+
provenance = true;
|
|
378
|
+
}
|
|
379
|
+
else if (arg === "--yes" || arg === "-y") {
|
|
380
|
+
yes = true;
|
|
381
|
+
}
|
|
382
|
+
else if (arg === "--force") {
|
|
383
|
+
force = true;
|
|
384
|
+
}
|
|
385
|
+
else if (arg === "--workspaces") {
|
|
386
|
+
workspaces = true;
|
|
387
|
+
}
|
|
388
|
+
else if (arg === "--workspace" || arg === "-w" || arg.startsWith("--workspace=")) {
|
|
389
|
+
const value = arg === "--workspace" || arg === "-w" ? args[index + 1] : arg.slice("--workspace=".length);
|
|
390
|
+
if (!value || value.startsWith("-") || value.includes("\0"))
|
|
391
|
+
throw new UsageError("--workspace requires a workspace name or path");
|
|
392
|
+
workspaceNames.push(value);
|
|
393
|
+
if (arg === "--workspace" || arg === "-w")
|
|
394
|
+
index += 1;
|
|
395
|
+
}
|
|
396
|
+
else if (arg === "--include-workspace-root") {
|
|
397
|
+
includeWorkspaceRoot = true;
|
|
398
|
+
}
|
|
399
|
+
else if (arg === "--if-present") {
|
|
400
|
+
ifPresent = true;
|
|
401
|
+
}
|
|
402
|
+
else if (arg === "--ignore-scripts") {
|
|
403
|
+
ignoreScripts = true;
|
|
404
|
+
}
|
|
405
|
+
else if (arg === "--sbom-format" || arg.startsWith("--sbom-format=")) {
|
|
406
|
+
const value = arg === "--sbom-format" ? args[index + 1] : arg.slice("--sbom-format=".length);
|
|
407
|
+
if (value !== "cyclonedx" && value !== "spdx")
|
|
408
|
+
throw new UsageError("--sbom-format must be cyclonedx or spdx");
|
|
409
|
+
sbomFormat = value;
|
|
410
|
+
if (arg === "--sbom-format")
|
|
411
|
+
index += 1;
|
|
412
|
+
}
|
|
413
|
+
else if (["--file", "--repository", "--repo", "--project", "--environment", "--env", "--org-id", "--project-id", "--pipeline-definition-id", "--vcs-origin", "--context-id"].some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
414
|
+
const equals = arg.indexOf("=");
|
|
415
|
+
const flag = equals < 0 ? arg : arg.slice(0, equals);
|
|
416
|
+
const value = arg === flag ? args[index + 1] : arg.slice(flag.length + 1);
|
|
417
|
+
if (!value || value.startsWith("-") || value.includes("\0"))
|
|
418
|
+
throw new UsageError(`${flag} requires a value`);
|
|
419
|
+
if (flag === "--file")
|
|
420
|
+
trustFile = value;
|
|
421
|
+
else if (flag === "--repository" || flag === "--repo")
|
|
422
|
+
trustRepository = value;
|
|
423
|
+
else if (flag === "--project")
|
|
424
|
+
trustProject = value;
|
|
425
|
+
else if (flag === "--environment" || flag === "--env")
|
|
426
|
+
trustEnvironment = value;
|
|
427
|
+
else if (flag === "--org-id")
|
|
428
|
+
trustOrganizationId = value;
|
|
429
|
+
else if (flag === "--project-id")
|
|
430
|
+
trustProjectId = value;
|
|
431
|
+
else if (flag === "--pipeline-definition-id")
|
|
432
|
+
trustPipelineDefinitionId = value;
|
|
433
|
+
else if (flag === "--vcs-origin")
|
|
434
|
+
trustVcsOrigin = value;
|
|
435
|
+
else
|
|
436
|
+
trustContextIds.push(value);
|
|
437
|
+
if (arg === flag)
|
|
438
|
+
index += 1;
|
|
439
|
+
}
|
|
440
|
+
else if (arg === "--allow-publish") {
|
|
441
|
+
allowPublish = true;
|
|
442
|
+
}
|
|
443
|
+
else if (arg === "--allow-stage-publish" || arg === "--allow-staged-publish") {
|
|
444
|
+
allowStagePublish = true;
|
|
445
|
+
}
|
|
446
|
+
else if (["--name", "--token-description", "--expires", "--packages", "--scopes", "--orgs", "--packages-and-scopes-permission", "--orgs-permission", "--cidr"].some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
447
|
+
const equals = arg.indexOf("=");
|
|
448
|
+
const flag = equals < 0 ? arg : arg.slice(0, equals);
|
|
449
|
+
const value = equals < 0 ? args[index + 1] : arg.slice(equals + 1);
|
|
450
|
+
if (!value || value.startsWith("-") || value.includes("\0"))
|
|
451
|
+
throw new UsageError(`${flag} requires a value`);
|
|
452
|
+
if (flag === "--name")
|
|
453
|
+
tokenName = value;
|
|
454
|
+
else if (flag === "--token-description")
|
|
455
|
+
tokenDescription = value;
|
|
456
|
+
else if (flag === "--expires") {
|
|
457
|
+
const days = Number(value);
|
|
458
|
+
if (!Number.isSafeInteger(days) || days < 1 || days > 3650)
|
|
459
|
+
throw new UsageError("--expires requires 1-3650 days");
|
|
460
|
+
tokenExpires = days;
|
|
461
|
+
}
|
|
462
|
+
else if (flag === "--packages")
|
|
463
|
+
tokenPackages.push(...value.split(",").filter(Boolean));
|
|
464
|
+
else if (flag === "--scopes")
|
|
465
|
+
tokenScopes.push(...value.split(",").filter(Boolean));
|
|
466
|
+
else if (flag === "--orgs")
|
|
467
|
+
tokenOrganizations.push(...value.split(",").filter(Boolean));
|
|
468
|
+
else if (flag === "--packages-and-scopes-permission") {
|
|
469
|
+
if (value !== "read-only" && value !== "read-write")
|
|
470
|
+
throw new UsageError(`${flag} must be read-only or read-write`);
|
|
471
|
+
tokenPackagesPermission = value;
|
|
472
|
+
}
|
|
473
|
+
else if (flag === "--orgs-permission") {
|
|
474
|
+
if (value !== "read-only" && value !== "read-write")
|
|
475
|
+
throw new UsageError(`${flag} must be read-only or read-write`);
|
|
476
|
+
tokenOrganizationsPermission = value;
|
|
477
|
+
}
|
|
478
|
+
else
|
|
479
|
+
tokenCidrs.push(...value.split(",").filter(Boolean));
|
|
480
|
+
if (equals < 0)
|
|
481
|
+
index += 1;
|
|
482
|
+
}
|
|
483
|
+
else if (arg === "--packages-all") {
|
|
484
|
+
tokenPackagesAll = true;
|
|
485
|
+
}
|
|
486
|
+
else if (arg === "--bypass-2fa") {
|
|
487
|
+
tokenBypass2fa = true;
|
|
488
|
+
}
|
|
489
|
+
else if (arg === "--read-only") {
|
|
490
|
+
tokenReadOnly = true;
|
|
491
|
+
}
|
|
492
|
+
else if (arg === "--auth-type" || arg.startsWith("--auth-type=")) {
|
|
493
|
+
const value = arg === "--auth-type" ? args[index + 1] : arg.slice("--auth-type=".length);
|
|
494
|
+
if (value !== "web" && value !== "legacy")
|
|
495
|
+
throw new UsageError("--auth-type must be web or legacy");
|
|
496
|
+
authType = value;
|
|
497
|
+
if (arg === "--auth-type")
|
|
498
|
+
index += 1;
|
|
499
|
+
}
|
|
500
|
+
else if (arg === "--expect-results") {
|
|
501
|
+
expectResults = true;
|
|
502
|
+
}
|
|
503
|
+
else if (arg === "--no-expect-results") {
|
|
504
|
+
expectResults = false;
|
|
505
|
+
}
|
|
506
|
+
else if (arg === "--expect-result-count" || arg.startsWith("--expect-result-count=")) {
|
|
507
|
+
const value = arg === "--expect-result-count" ? args[index + 1] : arg.slice("--expect-result-count=".length);
|
|
508
|
+
const count = Number(value);
|
|
509
|
+
if (!Number.isSafeInteger(count) || count < 0)
|
|
510
|
+
throw new UsageError("--expect-result-count requires a non-negative integer");
|
|
511
|
+
expectResultCount = count;
|
|
512
|
+
if (arg === "--expect-result-count")
|
|
513
|
+
index += 1;
|
|
514
|
+
}
|
|
515
|
+
else if (arg === "--package-lock-only") {
|
|
516
|
+
packageLockOnly = true;
|
|
517
|
+
}
|
|
518
|
+
else if (arg === "--no-git-tag-version") {
|
|
519
|
+
gitTagVersion = false;
|
|
520
|
+
}
|
|
521
|
+
else if (arg === "--git-tag-version") {
|
|
522
|
+
gitTagVersion = true;
|
|
523
|
+
}
|
|
524
|
+
else if (arg === "--no-commit-hooks") {
|
|
525
|
+
commitHooks = false;
|
|
526
|
+
}
|
|
527
|
+
else if (arg === "--commit-hooks") {
|
|
528
|
+
commitHooks = true;
|
|
529
|
+
}
|
|
530
|
+
else if (arg === "--sign-git-tag") {
|
|
531
|
+
signGitTag = true;
|
|
532
|
+
}
|
|
533
|
+
else if (arg === "--allow-same-version") {
|
|
534
|
+
allowSameVersion = true;
|
|
535
|
+
}
|
|
536
|
+
else if (arg === "--message" || arg === "-m" || arg.startsWith("--message=")) {
|
|
537
|
+
const value = arg === "--message" || arg === "-m" ? args[index + 1] : arg.slice("--message=".length);
|
|
538
|
+
if (!value || value.includes("\0"))
|
|
539
|
+
throw new UsageError("--message requires a commit message");
|
|
540
|
+
versionMessage = value;
|
|
541
|
+
if (arg === "--message" || arg === "-m")
|
|
542
|
+
index += 1;
|
|
543
|
+
}
|
|
544
|
+
else if (arg === "--preid" || arg.startsWith("--preid=")) {
|
|
545
|
+
const value = arg === "--preid" ? args[index + 1] : arg.slice("--preid=".length);
|
|
546
|
+
if (!value || !/^[0-9A-Za-z-]+$/.test(value))
|
|
547
|
+
throw new UsageError("--preid requires an alphanumeric prerelease identifier");
|
|
548
|
+
preid = value;
|
|
549
|
+
if (arg === "--preid")
|
|
550
|
+
index += 1;
|
|
551
|
+
}
|
|
552
|
+
else if (arg === "--package" || arg.startsWith("--package=")) {
|
|
553
|
+
const value = arg === "--package" ? args[index + 1] : arg.slice("--package=".length);
|
|
554
|
+
if (!value || value.startsWith("-") || value.includes("\0"))
|
|
555
|
+
throw new UsageError("--package requires a package specification");
|
|
556
|
+
validateSpecifier(value);
|
|
557
|
+
execPackages.push(value);
|
|
558
|
+
if (arg === "--package")
|
|
559
|
+
index += 1;
|
|
560
|
+
}
|
|
561
|
+
else if (["--diff", "--diff-unified", "--diff-src-prefix", "--diff-dst-prefix"].some((flag) => arg === flag || arg.startsWith(`${flag}=`))) {
|
|
562
|
+
const equals = arg.indexOf("=");
|
|
563
|
+
const flag = equals < 0 ? arg : arg.slice(0, equals);
|
|
564
|
+
const value = equals < 0 ? args[index + 1] : arg.slice(equals + 1);
|
|
565
|
+
if (value === undefined || value === "" || (flag !== "--diff-src-prefix" && flag !== "--diff-dst-prefix" && value.startsWith("-")))
|
|
566
|
+
throw new UsageError(`${flag} requires a value`);
|
|
567
|
+
if (flag === "--diff") {
|
|
568
|
+
if (diffSpecs.length >= 2)
|
|
569
|
+
throw new UsageError("--diff may be specified at most twice");
|
|
570
|
+
diffSpecs.push(value);
|
|
571
|
+
}
|
|
572
|
+
else if (flag === "--diff-unified") {
|
|
573
|
+
const count = Number(value);
|
|
574
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > 10_000)
|
|
575
|
+
throw new UsageError("--diff-unified requires an integer from 0 to 10000");
|
|
576
|
+
diffUnified = count;
|
|
577
|
+
}
|
|
578
|
+
else if (flag === "--diff-src-prefix")
|
|
579
|
+
diffSrcPrefix = value;
|
|
580
|
+
else
|
|
581
|
+
diffDstPrefix = value;
|
|
582
|
+
if (equals < 0)
|
|
583
|
+
index += 1;
|
|
584
|
+
}
|
|
585
|
+
else if (arg === "--diff-name-only") {
|
|
586
|
+
diffNameOnly = true;
|
|
587
|
+
}
|
|
588
|
+
else if (arg === "--diff-ignore-all-space") {
|
|
589
|
+
diffIgnoreAllSpace = true;
|
|
590
|
+
}
|
|
591
|
+
else if (arg === "--diff-no-prefix") {
|
|
592
|
+
diffNoPrefix = true;
|
|
593
|
+
}
|
|
594
|
+
else if (arg === "--diff-text") {
|
|
595
|
+
diffText = true;
|
|
596
|
+
}
|
|
597
|
+
else if (arg === "--provenance-file" || arg.startsWith("--provenance-file=")) {
|
|
598
|
+
const value = arg === "--provenance-file" ? args[index + 1] : arg.slice("--provenance-file=".length);
|
|
599
|
+
if (!value || value.startsWith("-"))
|
|
600
|
+
throw new UsageError("--provenance-file requires a file path");
|
|
601
|
+
provenanceFile = value;
|
|
602
|
+
if (arg === "--provenance-file")
|
|
603
|
+
index += 1;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
const section = saveFlags[arg];
|
|
607
|
+
if (section !== undefined) {
|
|
608
|
+
if (saveSection !== undefined && saveSection !== section) {
|
|
609
|
+
throw new UsageError("save-section flags are mutually exclusive");
|
|
610
|
+
}
|
|
611
|
+
saveSection = section;
|
|
612
|
+
}
|
|
613
|
+
else if (arg.startsWith("-")) {
|
|
614
|
+
throw new UsageError(`unknown option: ${arg}`);
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
index += 1;
|
|
621
|
+
}
|
|
622
|
+
if (noSave && (saveSection !== undefined || saveExact)) {
|
|
623
|
+
throw new UsageError("--no-save conflicts with save flags");
|
|
624
|
+
}
|
|
625
|
+
if (provenance && provenanceFile !== undefined)
|
|
626
|
+
throw new UsageError("--provenance and --provenance-file are mutually exclusive");
|
|
627
|
+
if (expectResults !== undefined && expectResultCount !== undefined)
|
|
628
|
+
throw new UsageError("--expect-results and --expect-result-count are mutually exclusive");
|
|
629
|
+
return {
|
|
630
|
+
options: {
|
|
631
|
+
...global,
|
|
632
|
+
globalInstall,
|
|
633
|
+
dryRun,
|
|
634
|
+
...(packDestination === undefined ? {} : { packDestination }),
|
|
635
|
+
...(tag === undefined ? {} : { tag }),
|
|
636
|
+
...(access === undefined ? {} : { access }),
|
|
637
|
+
...(otp === undefined ? {} : { otp }),
|
|
638
|
+
...(provenance ? { provenance: true } : {}),
|
|
639
|
+
...(provenanceFile === undefined ? {} : { provenanceFile }),
|
|
640
|
+
...(yes ? { yes: true } : {}),
|
|
641
|
+
...(force ? { force: true } : {}),
|
|
642
|
+
...(workspaces ? { workspaces: true } : {}),
|
|
643
|
+
...(workspaceNames.length === 0 ? {} : { workspaceNames }),
|
|
644
|
+
...(includeWorkspaceRoot ? { includeWorkspaceRoot: true } : {}),
|
|
645
|
+
...(ifPresent ? { ifPresent: true } : {}),
|
|
646
|
+
...(ignoreScripts ? { ignoreScripts: true } : {}),
|
|
647
|
+
...(sbomFormat === undefined ? {} : { sbomFormat }),
|
|
648
|
+
...(trustFile === undefined ? {} : { trustFile }),
|
|
649
|
+
...(trustRepository === undefined ? {} : { trustRepository }),
|
|
650
|
+
...(trustProject === undefined ? {} : { trustProject }),
|
|
651
|
+
...(trustEnvironment === undefined ? {} : { trustEnvironment }),
|
|
652
|
+
...(trustOrganizationId === undefined ? {} : { trustOrganizationId }),
|
|
653
|
+
...(trustProjectId === undefined ? {} : { trustProjectId }),
|
|
654
|
+
...(trustPipelineDefinitionId === undefined ? {} : { trustPipelineDefinitionId }),
|
|
655
|
+
...(trustVcsOrigin === undefined ? {} : { trustVcsOrigin }),
|
|
656
|
+
...(trustContextIds.length === 0 ? {} : { trustContextIds }),
|
|
657
|
+
...(allowPublish ? { allowPublish: true } : {}),
|
|
658
|
+
...(allowStagePublish ? { allowStagePublish: true } : {}),
|
|
659
|
+
...(tokenName === undefined ? {} : { tokenName }),
|
|
660
|
+
...(tokenDescription === undefined ? {} : { tokenDescription }),
|
|
661
|
+
...(tokenExpires === undefined ? {} : { tokenExpires }),
|
|
662
|
+
...(tokenPackages.length === 0 ? {} : { tokenPackages }),
|
|
663
|
+
...(tokenPackagesAll ? { tokenPackagesAll: true } : {}),
|
|
664
|
+
...(tokenScopes.length === 0 ? {} : { tokenScopes }),
|
|
665
|
+
...(tokenOrganizations.length === 0 ? {} : { tokenOrganizations }),
|
|
666
|
+
...(tokenPackagesPermission === undefined ? {} : { tokenPackagesPermission }),
|
|
667
|
+
...(tokenOrganizationsPermission === undefined ? {} : { tokenOrganizationsPermission }),
|
|
668
|
+
...(tokenCidrs.length === 0 ? {} : { tokenCidrs }),
|
|
669
|
+
...(tokenBypass2fa ? { tokenBypass2fa: true } : {}),
|
|
670
|
+
...(tokenReadOnly ? { tokenReadOnly: true } : {}),
|
|
671
|
+
...(authType === undefined ? {} : { authType }),
|
|
672
|
+
...(expectResults === undefined ? {} : { expectResults }),
|
|
673
|
+
...(expectResultCount === undefined ? {} : { expectResultCount }),
|
|
674
|
+
...(packageLockOnly ? { packageLockOnly: true } : {}),
|
|
675
|
+
...(execPackages.length === 0 ? {} : { execPackages }),
|
|
676
|
+
...(gitTagVersion ? {} : { gitTagVersion: false }),
|
|
677
|
+
...(commitHooks ? {} : { commitHooks: false }),
|
|
678
|
+
...(signGitTag ? { signGitTag: true } : {}),
|
|
679
|
+
...(versionMessage === undefined ? {} : { versionMessage }),
|
|
680
|
+
...(preid === undefined ? {} : { preid }),
|
|
681
|
+
...(allowSameVersion ? { allowSameVersion: true } : {}),
|
|
682
|
+
...(diffSpecs.length === 0 ? {} : { diffSpecs }),
|
|
683
|
+
...(diffNameOnly ? { diffNameOnly: true } : {}),
|
|
684
|
+
...(diffUnified === undefined ? {} : { diffUnified }),
|
|
685
|
+
...(diffIgnoreAllSpace ? { diffIgnoreAllSpace: true } : {}),
|
|
686
|
+
...(diffNoPrefix ? { diffNoPrefix: true } : {}),
|
|
687
|
+
...(diffSrcPrefix === undefined ? {} : { diffSrcPrefix }),
|
|
688
|
+
...(diffDstPrefix === undefined ? {} : { diffDstPrefix }),
|
|
689
|
+
...(diffText ? { diffText: true } : {}),
|
|
690
|
+
frozenLockfile,
|
|
691
|
+
offline,
|
|
692
|
+
omitDev: omitted.has("dev"),
|
|
693
|
+
...(omitted.size === 0 ? {} : { omit: [...omitted].sort() }),
|
|
694
|
+
...(saveSection === undefined ? {} : { saveSection }),
|
|
695
|
+
saveExact,
|
|
696
|
+
noSave,
|
|
697
|
+
},
|
|
698
|
+
operands: args.slice(index),
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
function normalizeQueryArguments(args) {
|
|
702
|
+
const options = [];
|
|
703
|
+
const operands = [];
|
|
704
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
705
|
+
const value = args[index] ?? "";
|
|
706
|
+
if (value === "--expect-result-count") {
|
|
707
|
+
options.push(value);
|
|
708
|
+
if (args[index + 1] !== undefined)
|
|
709
|
+
options.push(args[++index]);
|
|
710
|
+
}
|
|
711
|
+
else if (["--expect-results", "--no-expect-results", "--package-lock-only", "--global", "-g", "--workspaces"].includes(value) || value.startsWith("--expect-result-count="))
|
|
712
|
+
options.push(value);
|
|
713
|
+
else
|
|
714
|
+
operands.push(value);
|
|
715
|
+
}
|
|
716
|
+
return [...options, ...operands];
|
|
717
|
+
}
|
|
718
|
+
function normalizeDiffArguments(args) {
|
|
719
|
+
const options = [];
|
|
720
|
+
const operands = [];
|
|
721
|
+
const valued = new Set(["--diff", "--diff-unified", "--diff-src-prefix", "--diff-dst-prefix"]);
|
|
722
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
723
|
+
const value = args[index] ?? "";
|
|
724
|
+
const flag = value.split("=", 1)[0] ?? value;
|
|
725
|
+
if (valued.has(flag)) {
|
|
726
|
+
options.push(value);
|
|
727
|
+
if (value === flag && args[index + 1] !== undefined)
|
|
728
|
+
options.push(args[++index]);
|
|
729
|
+
}
|
|
730
|
+
else if (["--diff-name-only", "--diff-ignore-all-space", "--diff-no-prefix", "--diff-text", "--global", "-g"].includes(value))
|
|
731
|
+
options.push(value);
|
|
732
|
+
else
|
|
733
|
+
operands.push(value);
|
|
734
|
+
}
|
|
735
|
+
return [...options, ...operands];
|
|
736
|
+
}
|
|
737
|
+
function parseChildArguments(name, operands) {
|
|
738
|
+
const primary = operands[0];
|
|
739
|
+
if (!primary || primary === "--" || !/^[A-Za-z0-9._:-]+$/.test(primary)) {
|
|
740
|
+
throw new UsageError(`${name} requires an exact ${name === "run" ? "script" : "binary"} name`);
|
|
741
|
+
}
|
|
742
|
+
return [primary, ...(operands[1] === "--" ? operands.slice(2) : operands.slice(1))];
|
|
743
|
+
}
|
|
744
|
+
function normalizeExecArguments(args) {
|
|
745
|
+
const separator = args.indexOf("--");
|
|
746
|
+
if (separator < 0)
|
|
747
|
+
return args;
|
|
748
|
+
return [...args.slice(0, separator), ...args.slice(separator + 1)];
|
|
749
|
+
}
|
|
750
|
+
function normalizeInitArguments(args) {
|
|
751
|
+
const separator = args.indexOf("--");
|
|
752
|
+
const before = separator < 0 ? args : args.slice(0, separator);
|
|
753
|
+
const forwarded = separator < 0 ? [] : args.slice(separator + 1);
|
|
754
|
+
const options = [];
|
|
755
|
+
const operands = [];
|
|
756
|
+
for (let index = 0; index < before.length; index += 1) {
|
|
757
|
+
const value = before[index] ?? "";
|
|
758
|
+
if (["--yes", "-y", "--include-workspace-root"].includes(value) || value.startsWith("--workspace="))
|
|
759
|
+
options.push(value);
|
|
760
|
+
else if (value === "--workspace" || value === "-w") {
|
|
761
|
+
options.push(value);
|
|
762
|
+
if (before[index + 1] !== undefined)
|
|
763
|
+
options.push(before[++index]);
|
|
764
|
+
}
|
|
765
|
+
else
|
|
766
|
+
operands.push(value);
|
|
767
|
+
}
|
|
768
|
+
return [...options, ...operands, ...forwarded];
|
|
769
|
+
}
|
|
770
|
+
function normalizeVersionArguments(args) {
|
|
771
|
+
const options = [];
|
|
772
|
+
const operands = [];
|
|
773
|
+
const valued = new Set(["--message", "-m", "--preid", "--workspace", "-w"]);
|
|
774
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
775
|
+
const value = args[index] ?? "";
|
|
776
|
+
const flag = value.split("=", 1)[0] ?? value;
|
|
777
|
+
if (valued.has(flag)) {
|
|
778
|
+
options.push(value);
|
|
779
|
+
if (value === flag && args[index + 1] !== undefined)
|
|
780
|
+
options.push(args[++index]);
|
|
781
|
+
}
|
|
782
|
+
else if (["--no-git-tag-version", "--git-tag-version", "--no-commit-hooks", "--commit-hooks", "--sign-git-tag", "--allow-same-version", "--force", "--ignore-scripts", "--no-save", "--workspaces", "--include-workspace-root"].includes(value) || value.startsWith("--message=") || value.startsWith("--preid=") || value.startsWith("--workspace="))
|
|
783
|
+
options.push(value);
|
|
784
|
+
else
|
|
785
|
+
operands.push(value);
|
|
786
|
+
}
|
|
787
|
+
return [...options, ...operands];
|
|
788
|
+
}
|
|
789
|
+
export function parseInvocation(args, invokedAsBnpmx = false) {
|
|
790
|
+
const { options: global, rest } = consumeGlobal(args);
|
|
791
|
+
const first = rest[0];
|
|
792
|
+
if (!invokedAsBnpmx && (first === "help" || first === "help-search")) {
|
|
793
|
+
if (rest.length > 2 || rest[1]?.startsWith("-"))
|
|
794
|
+
throw new UsageError(`${first} accepts at most one topic`);
|
|
795
|
+
return { kind: "help", json: global.json };
|
|
796
|
+
}
|
|
797
|
+
if (first === "--help" || first === "-h") {
|
|
798
|
+
if (!rest.slice(1).every((argument) => argument === "--json")) {
|
|
799
|
+
throw new UsageError("--help cannot be combined with command operands");
|
|
800
|
+
}
|
|
801
|
+
return { kind: "help", json: global.json || rest.slice(1).includes("--json") };
|
|
802
|
+
}
|
|
803
|
+
if (first === "--version" || first === "-v") {
|
|
804
|
+
if (!rest.slice(1).every((argument) => argument === "--json")) {
|
|
805
|
+
throw new UsageError("--version cannot be combined with command operands");
|
|
806
|
+
}
|
|
807
|
+
return { kind: "version", json: global.json || rest.slice(1).includes("--json") };
|
|
808
|
+
}
|
|
809
|
+
if (rest.length === 0 && !invokedAsBnpmx) {
|
|
810
|
+
return { kind: "help", json: global.json };
|
|
811
|
+
}
|
|
812
|
+
if (invokedAsBnpmx) {
|
|
813
|
+
if (!first || first.startsWith("-")) {
|
|
814
|
+
throw new UsageError("bnpmx requires one package specification");
|
|
815
|
+
}
|
|
816
|
+
validateSpecifier(first);
|
|
817
|
+
const trailing = rest.slice(1);
|
|
818
|
+
if (trailing[0] !== undefined && trailing[0] !== "--") {
|
|
819
|
+
throw new UsageError("bnpmx target arguments must follow --");
|
|
820
|
+
}
|
|
821
|
+
return { kind: "bnpmx", options: global, specifier: first, targetArgs: trailing.slice(trailing[0] === "--" ? 1 : 0) };
|
|
822
|
+
}
|
|
823
|
+
const canonicalName = first === undefined ? undefined : commandAliases[first];
|
|
824
|
+
if (!first || canonicalName === undefined) {
|
|
825
|
+
throw new UsageError(`unknown command: ${first ?? ""}`);
|
|
826
|
+
}
|
|
827
|
+
const name = canonicalName;
|
|
828
|
+
const scriptAlias = first === "test" || first === "start" || first === "stop";
|
|
829
|
+
const commandArguments = scriptAlias
|
|
830
|
+
? [first, ...rest.slice(1)]
|
|
831
|
+
: first === "get"
|
|
832
|
+
? ["get", ...rest.slice(1)]
|
|
833
|
+
: first === "set"
|
|
834
|
+
? rest.length === 2 && rest[1]?.includes("=") ? ["set", ...rest[1].split(/=(.*)/s).slice(0, 2)] : ["set", ...rest.slice(1)]
|
|
835
|
+
: first === "undeprecate"
|
|
836
|
+
? [...rest.slice(1), ""]
|
|
837
|
+
: name === "stage"
|
|
838
|
+
? rest.slice(2)
|
|
839
|
+
: name === "trust"
|
|
840
|
+
? rest.slice(2)
|
|
841
|
+
: name === "token"
|
|
842
|
+
? rest.slice(2)
|
|
843
|
+
: name === "query"
|
|
844
|
+
? normalizeQueryArguments(rest.slice(1))
|
|
845
|
+
: name === "diff"
|
|
846
|
+
? normalizeDiffArguments(rest.slice(1))
|
|
847
|
+
: name === "exec"
|
|
848
|
+
? normalizeExecArguments(rest.slice(1))
|
|
849
|
+
: name === "init"
|
|
850
|
+
? normalizeInitArguments(rest.slice(1))
|
|
851
|
+
: name === "version"
|
|
852
|
+
? normalizeVersionArguments(rest.slice(1))
|
|
853
|
+
: name === "audit" && rest.includes("--dry-run")
|
|
854
|
+
? ["--dry-run", ...rest.slice(1).filter((value) => value !== "--dry-run")]
|
|
855
|
+
: name === "install-scripts" && rest.includes("--dry-run")
|
|
856
|
+
? ["--dry-run", ...rest.slice(1).filter((value) => value !== "--dry-run")]
|
|
857
|
+
: name === "cache" && rest.at(-1) === "--force"
|
|
858
|
+
? ["--force", ...rest.slice(1, -1)]
|
|
859
|
+
: rest.slice(1);
|
|
860
|
+
const parsed = parseCommandOptions(commandArguments, global);
|
|
861
|
+
const ci = first === "ci" || name === "install-ci-test";
|
|
862
|
+
if (ci && (parsed.operands.length > 0 || parsed.options.saveSection !== undefined || parsed.options.saveExact)) {
|
|
863
|
+
throw new UsageError("ci accepts no package operands or save flags");
|
|
864
|
+
}
|
|
865
|
+
const options = ci
|
|
866
|
+
? { ...parsed.options, frozenLockfile: true, noSave: true }
|
|
867
|
+
: first === "adduser" ? { ...parsed.options, accountCreate: true } : parsed.options;
|
|
868
|
+
if (name === "edit" && options.json)
|
|
869
|
+
throw new UsageError("edit is interactive and cannot use --json");
|
|
870
|
+
const operands = name === "stage" || name === "trust" || name === "token" ? [rest[1] ?? "", ...parsed.operands] : parsed.operands;
|
|
871
|
+
const hasAuthoringOptions = options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.otp !== undefined || options.provenance === true || options.provenanceFile !== undefined;
|
|
872
|
+
const hasNonDryAuthoringOptions = options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.otp !== undefined || options.provenance === true || options.provenanceFile !== undefined;
|
|
873
|
+
if (!["pack", "publish", "stage", "unpublish", "access", "owner", "token", "star", "unstar", "org", "team", "profile", "trust", "login", "deprecate", "dist-tag", "diff"].includes(name) && hasNonDryAuthoringOptions)
|
|
874
|
+
throw new UsageError("package authoring options are not valid for this command");
|
|
875
|
+
if (options.dryRun && !["install", "add", "remove", "update", "prune", "dedupe", "pack", "publish", "stage", "unpublish", "deprecate", "trust", "install-scripts", "audit"].includes(name))
|
|
876
|
+
throw new UsageError("--dry-run is not valid for this command");
|
|
877
|
+
if (name === "pack" && (options.tag !== undefined || options.access !== undefined || options.otp !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
878
|
+
throw new UsageError("publish options are not valid for pack");
|
|
879
|
+
if (name === "publish" && options.packDestination !== undefined)
|
|
880
|
+
throw new UsageError("--pack-destination is only valid for pack");
|
|
881
|
+
if (name === "stage" && options.packDestination !== undefined)
|
|
882
|
+
throw new UsageError("--pack-destination is not valid for stage");
|
|
883
|
+
if (options.yes && name !== "init" && name !== "trust")
|
|
884
|
+
throw new UsageError("--yes is only valid for init or trust");
|
|
885
|
+
if (options.force && name !== "cache" && name !== "unpublish" && name !== "version")
|
|
886
|
+
throw new UsageError("--force is only valid for cache clean, unpublish, or version");
|
|
887
|
+
const workspaceCommands = ["install", "install-test", "install-ci-test", "add", "remove", "update", "outdated", "list", "run", "query", "init", "version"];
|
|
888
|
+
if (options.workspaces && !workspaceCommands.includes(name))
|
|
889
|
+
throw new UsageError("--workspaces is not valid for this command");
|
|
890
|
+
if (options.workspaceNames !== undefined && !workspaceCommands.includes(name))
|
|
891
|
+
throw new UsageError("--workspace is not valid for this command");
|
|
892
|
+
if (options.includeWorkspaceRoot && !workspaceCommands.includes(name))
|
|
893
|
+
throw new UsageError("--include-workspace-root is not valid for this command");
|
|
894
|
+
if (options.includeWorkspaceRoot && !options.workspaces && options.workspaceNames === undefined)
|
|
895
|
+
throw new UsageError("--include-workspace-root requires --workspaces or --workspace");
|
|
896
|
+
if (name === "init" && (options.workspaces || options.includeWorkspaceRoot))
|
|
897
|
+
throw new UsageError("init supports one --workspace path, not --workspaces or --include-workspace-root");
|
|
898
|
+
if (options.ifPresent && name !== "run")
|
|
899
|
+
throw new UsageError("--if-present is only valid for run");
|
|
900
|
+
if (options.ignoreScripts && !["install", "install-test", "install-ci-test", "add", "remove", "update", "prune", "dedupe", "rebuild", "pack", "publish", "run", "version"].includes(name))
|
|
901
|
+
throw new UsageError("--ignore-scripts is not valid for this command");
|
|
902
|
+
if (options.sbomFormat && name !== "sbom")
|
|
903
|
+
throw new UsageError("--sbom-format is only valid for sbom");
|
|
904
|
+
const hasTrustOptions = options.trustFile !== undefined || options.trustRepository !== undefined || options.trustProject !== undefined || options.trustEnvironment !== undefined || options.trustOrganizationId !== undefined || options.trustProjectId !== undefined || options.trustPipelineDefinitionId !== undefined || options.trustVcsOrigin !== undefined || options.trustContextIds !== undefined || options.allowPublish === true || options.allowStagePublish === true;
|
|
905
|
+
if (hasTrustOptions && name !== "trust")
|
|
906
|
+
throw new UsageError("trusted-publisher options are only valid for trust");
|
|
907
|
+
const hasTokenOptions = options.tokenName !== undefined || options.tokenDescription !== undefined || options.tokenExpires !== undefined || options.tokenPackages !== undefined || options.tokenPackagesAll === true || options.tokenScopes !== undefined || options.tokenOrganizations !== undefined || options.tokenPackagesPermission !== undefined || options.tokenOrganizationsPermission !== undefined || options.tokenCidrs !== undefined || options.tokenBypass2fa === true || options.tokenReadOnly === true;
|
|
908
|
+
if (hasTokenOptions && name !== "token")
|
|
909
|
+
throw new UsageError("token creation options are only valid for token");
|
|
910
|
+
if (hasTokenOptions && name === "token" && operands[0] !== "create")
|
|
911
|
+
throw new UsageError("token creation options require token create");
|
|
912
|
+
if (options.authType !== undefined && name !== "login")
|
|
913
|
+
throw new UsageError("--auth-type is only valid for login or adduser");
|
|
914
|
+
if ((options.expectResults !== undefined || options.expectResultCount !== undefined) && name !== "query")
|
|
915
|
+
throw new UsageError("query expectation options are only valid for query");
|
|
916
|
+
if (options.packageLockOnly === true && name !== "query" && name !== "install")
|
|
917
|
+
throw new UsageError("--package-lock-only is only valid for query or install");
|
|
918
|
+
const hasDiffOptions = options.diffSpecs !== undefined || options.diffNameOnly || options.diffUnified !== undefined || options.diffIgnoreAllSpace || options.diffNoPrefix || options.diffSrcPrefix !== undefined || options.diffDstPrefix !== undefined || options.diffText;
|
|
919
|
+
if (hasDiffOptions && name !== "diff")
|
|
920
|
+
throw new UsageError("diff options are only valid for diff");
|
|
921
|
+
if ((name === "deprecate" || name === "dist-tag") && (options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
922
|
+
throw new UsageError("unsupported package authoring option for registry mutation");
|
|
923
|
+
if (name === "unpublish" && (options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
924
|
+
throw new UsageError("unsupported package authoring option for unpublish");
|
|
925
|
+
if ((name === "access" || name === "owner") && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
926
|
+
throw new UsageError(`unsupported package authoring option for ${name}`);
|
|
927
|
+
if (name === "token" && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
928
|
+
throw new UsageError("unsupported package authoring option for token");
|
|
929
|
+
if ((name === "star" || name === "unstar") && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
930
|
+
throw new UsageError(`unsupported package authoring option for ${name}`);
|
|
931
|
+
if ((name === "org" || name === "team") && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
932
|
+
throw new UsageError(`unsupported package authoring option for ${name}`);
|
|
933
|
+
if (name === "profile" && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
934
|
+
throw new UsageError("unsupported package authoring option for profile");
|
|
935
|
+
if (name === "trust" && (options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
936
|
+
throw new UsageError("unsupported package authoring option for trust");
|
|
937
|
+
if (name === "login" && (options.dryRun || options.packDestination !== undefined || options.tag !== undefined || options.access !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
938
|
+
throw new UsageError("only --otp is valid as a package-authoring option for legacy login");
|
|
939
|
+
if (name === "diff" && (options.dryRun || options.packDestination !== undefined || options.access !== undefined || options.otp !== undefined || options.provenance === true || options.provenanceFile !== undefined))
|
|
940
|
+
throw new UsageError("only --tag is valid as a package-authoring option for diff");
|
|
941
|
+
if (ci && options.globalInstall)
|
|
942
|
+
throw new UsageError("ci cannot be used with --global");
|
|
943
|
+
if (options.globalInstall && !["install", "add", "remove", "update", "outdated", "list", "why", "query", "bin", "prefix", "root", "audit", "exec"].includes(name)) {
|
|
944
|
+
throw new UsageError(`--global is not supported for ${name}`);
|
|
945
|
+
}
|
|
946
|
+
if (options.execPackages !== undefined && name !== "exec")
|
|
947
|
+
throw new UsageError("--package is only valid for exec");
|
|
948
|
+
if (options.execPackages !== undefined && options.globalInstall)
|
|
949
|
+
throw new UsageError("exec --package cannot be combined with --global");
|
|
950
|
+
const hasVersionOptions = options.gitTagVersion === false || options.commitHooks === false || options.signGitTag === true || options.versionMessage !== undefined || options.preid !== undefined || options.allowSameVersion === true;
|
|
951
|
+
if (hasVersionOptions && name !== "version")
|
|
952
|
+
throw new UsageError("version-control options are only valid for version");
|
|
953
|
+
if (name === "version" && options.signGitTag && options.gitTagVersion === false)
|
|
954
|
+
throw new UsageError("--sign-git-tag cannot be combined with --no-git-tag-version");
|
|
955
|
+
const hasInstallPolicy = options.frozenLockfile || options.offline || options.omit !== undefined || (options.packageLockOnly === true && name !== "query");
|
|
956
|
+
const hasSaveIntent = options.saveSection !== undefined || options.saveExact || options.noSave;
|
|
957
|
+
if (name !== "install" && name !== "install-test" && name !== "install-ci-test" && name !== "prune" && name !== "dedupe" && hasInstallPolicy) {
|
|
958
|
+
if (name !== "update" || options.frozenLockfile || options.offline)
|
|
959
|
+
throw new UsageError("install policy options are only valid for install");
|
|
960
|
+
}
|
|
961
|
+
if (name !== "install" && name !== "install-test" && name !== "install-ci-test" && name !== "add" && !(name === "version" && options.noSave && options.saveSection === undefined && !options.saveExact) && hasSaveIntent) {
|
|
962
|
+
throw new UsageError("save options are only valid for install, add, or version --no-save");
|
|
963
|
+
}
|
|
964
|
+
if (name === "audit") {
|
|
965
|
+
if (operands.length > 1 || (operands.length === 1 && operands[0] !== "fix") || (options.dryRun && operands[0] !== "fix"))
|
|
966
|
+
throw new UsageError("audit accepts no operands or fix [--dry-run]");
|
|
967
|
+
}
|
|
968
|
+
else if (name === "bin" || name === "prefix" || name === "root" || name === "login" || name === "logout" || name === "whoami" || name === "shrinkwrap" || name === "prune" || name === "dedupe" || name === "find-dupes" || name === "fund" || name === "ping" || name === "doctor" || name === "completion" || name === "sbom" || name === "restart" || name === "install-test" || name === "install-ci-test") {
|
|
969
|
+
if (operands.length !== 0) {
|
|
970
|
+
throw new UsageError(`${name} accepts no operands`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
else if (name === "pkg") {
|
|
974
|
+
const action = operands[0];
|
|
975
|
+
if (!((action === "get" && operands.length >= 1) || (action === "set" && operands.length >= 2) || (action === "delete" && operands.length >= 2)))
|
|
976
|
+
throw new UsageError("pkg requires get [key...], set <key=value...>, or delete <key...>");
|
|
977
|
+
}
|
|
978
|
+
else if (name === "cache") {
|
|
979
|
+
const valid = (operands[0] === "verify" && operands.length === 1 && !options.force)
|
|
980
|
+
|| (operands[0] === "clean" && operands.length <= 2 && options.force)
|
|
981
|
+
|| (["ls", "list", "info"].includes(operands[0] ?? "") && operands.length <= 2 && !options.force)
|
|
982
|
+
|| (operands[0] === "add" && operands.length === 2 && !options.force);
|
|
983
|
+
if (!valid)
|
|
984
|
+
throw new UsageError("cache requires add <spec>, ls [name@version], verify, or clean [name@version] --force");
|
|
985
|
+
if (operands[0] === "add")
|
|
986
|
+
validateSpecifier(operands[1] ?? "");
|
|
987
|
+
}
|
|
988
|
+
else if (name === "install-scripts") {
|
|
989
|
+
const action = operands[0];
|
|
990
|
+
const names = operands.slice(1);
|
|
991
|
+
const validNames = names.every((operand) => /^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/.test(operand));
|
|
992
|
+
if (!validNames || !((action === "approve" || action === "deny") && names.length > 0 && !options.dryRun) && !(action === "ls" && names.length === 0 && !options.dryRun) && !(action === "prune" && names.length === 0))
|
|
993
|
+
throw new UsageError("install-scripts requires approve <pkg...>, deny <pkg...>, ls, or prune [--dry-run]");
|
|
994
|
+
}
|
|
995
|
+
else if (name === "init") {
|
|
996
|
+
if (operands[0]?.startsWith("-") || operands[0]?.includes("\0"))
|
|
997
|
+
throw new UsageError("init accepts an initializer package followed by arguments");
|
|
998
|
+
}
|
|
999
|
+
else if (name === "version") {
|
|
1000
|
+
if (operands.length > 1 || operands[0]?.startsWith("-"))
|
|
1001
|
+
throw new UsageError("version accepts at most one version or release type");
|
|
1002
|
+
}
|
|
1003
|
+
else if (name === "config") {
|
|
1004
|
+
const action = operands[0];
|
|
1005
|
+
const valid = (action === "list" && operands.length === 1) || (action === "get" && operands.length === 2) || (action === "delete" && operands.length === 2) || (action === "set" && operands.length === 3);
|
|
1006
|
+
if (!valid)
|
|
1007
|
+
throw new UsageError("config requires list, get <key>, set <key> <value>, or delete <key>");
|
|
1008
|
+
}
|
|
1009
|
+
else if (name === "view") {
|
|
1010
|
+
if (operands.length !== 1 || operands[0]?.startsWith("-"))
|
|
1011
|
+
throw new UsageError("view requires one package specification");
|
|
1012
|
+
}
|
|
1013
|
+
else if (name === "search") {
|
|
1014
|
+
if (operands.length === 0)
|
|
1015
|
+
throw new UsageError("search requires at least one term");
|
|
1016
|
+
}
|
|
1017
|
+
else if (name === "repo" || name === "docs" || name === "bugs") {
|
|
1018
|
+
if (operands.length > 1 || operands[0]?.startsWith("-"))
|
|
1019
|
+
throw new UsageError(`${name} accepts at most one package name`);
|
|
1020
|
+
}
|
|
1021
|
+
else if (name === "dist-tag") {
|
|
1022
|
+
const action = operands[0];
|
|
1023
|
+
const valid = (action === "add" && operands.length >= 2 && operands.length <= 3) || (["rm", "remove"].includes(action ?? "") && operands.length === 3) || (["ls", "list"].includes(action ?? "") && operands.length === 2);
|
|
1024
|
+
if (!valid)
|
|
1025
|
+
throw new UsageError("dist-tag requires add <package@version> [tag], rm <package> <tag>, or ls <package>");
|
|
1026
|
+
}
|
|
1027
|
+
else if (name === "deprecate") {
|
|
1028
|
+
if (operands.length !== 2)
|
|
1029
|
+
throw new UsageError("deprecate requires <package@range> <message>");
|
|
1030
|
+
}
|
|
1031
|
+
else if (name === "unpublish") {
|
|
1032
|
+
if (operands.length !== 1 || operands[0]?.startsWith("-"))
|
|
1033
|
+
throw new UsageError("unpublish requires one exact package@version or package@*");
|
|
1034
|
+
}
|
|
1035
|
+
else if (name === "stage") {
|
|
1036
|
+
const action = operands[0];
|
|
1037
|
+
const uuidValue = operands[1] ?? "";
|
|
1038
|
+
const valid = (action === "publish" && operands.length <= 2 && !operands[1]?.startsWith("-")) || (action === "list" && operands.length <= 2) || (["view", "download", "approve", "reject"].includes(action ?? "") && operands.length === 2 && /^[0-9a-f-]{36}$/i.test(uuidValue));
|
|
1039
|
+
if (!valid)
|
|
1040
|
+
throw new UsageError("stage requires publish [directory], list [package], or view|download|approve|reject <stage-id>");
|
|
1041
|
+
}
|
|
1042
|
+
else if (name === "access") {
|
|
1043
|
+
const valid = (operands[0] === "get" && operands[1] === "status" && operands.length >= 2 && operands.length <= 3)
|
|
1044
|
+
|| (operands[0] === "set" && /^(?:status=(?:public|private)|mfa=(?:none|publish|automation)|2fa=(?:none|publish|automation))$/.test(operands[1] ?? "") && operands.length >= 2 && operands.length <= 3)
|
|
1045
|
+
|| (["list", "ls"].includes(operands[0] ?? "") && ((operands[1] === "collaborators" && operands.length >= 2 && operands.length <= 3) || (operands[1] === "packages" && operands.length >= 2 && operands.length <= 3)))
|
|
1046
|
+
|| (operands[0] === "grant" && ["read-only", "read-write"].includes(operands[1] ?? "") && operands.length >= 3 && operands.length <= 4)
|
|
1047
|
+
|| (operands[0] === "revoke" && operands.length >= 2 && operands.length <= 3);
|
|
1048
|
+
if (!valid)
|
|
1049
|
+
throw new UsageError("access requires get status [pkg], set status|mfa=<value> [pkg], list collaborators [pkg], list packages [owner], grant <permission> <team> [pkg], or revoke <team> [pkg]");
|
|
1050
|
+
}
|
|
1051
|
+
else if (name === "owner") {
|
|
1052
|
+
const valid = (["ls", "list"].includes(operands[0] ?? "") && operands.length >= 1 && operands.length <= 2) || (operands[0] === "add" && operands.length >= 2 && operands.length <= 3) || (["rm", "remove"].includes(operands[0] ?? "") && operands.length >= 2 && operands.length <= 3);
|
|
1053
|
+
if (!valid)
|
|
1054
|
+
throw new UsageError("owner requires ls [pkg], add <user> [pkg], or rm <user> [pkg]");
|
|
1055
|
+
}
|
|
1056
|
+
else if (name === "token") {
|
|
1057
|
+
const valid = (["list", "ls"].includes(operands[0] ?? "") && operands.length === 1) || (["revoke", "rm", "remove", "delete"].includes(operands[0] ?? "") && operands.length >= 2) || (operands[0] === "create" && operands.length === 1);
|
|
1058
|
+
if (!valid)
|
|
1059
|
+
throw new UsageError("token requires list, create, or revoke <id...>");
|
|
1060
|
+
}
|
|
1061
|
+
else if (name === "star" || name === "unstar") {
|
|
1062
|
+
if (operands.length === 0)
|
|
1063
|
+
throw new UsageError(`${name} requires at least one package name`);
|
|
1064
|
+
for (const operand of operands)
|
|
1065
|
+
validateSpecifier(operand);
|
|
1066
|
+
}
|
|
1067
|
+
else if (name === "stars") {
|
|
1068
|
+
if (operands.length > 1 || (operands[0] !== undefined && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(operands[0])))
|
|
1069
|
+
throw new UsageError("stars accepts at most one registry username");
|
|
1070
|
+
}
|
|
1071
|
+
else if (name === "org") {
|
|
1072
|
+
const valid = (["ls", "list"].includes(operands[0] ?? "") && operands.length >= 2 && operands.length <= 3) || (["set", "add"].includes(operands[0] ?? "") && operands.length >= 3 && operands.length <= 4 && (operands[3] === undefined || ["developer", "admin", "owner"].includes(operands[3]))) || (["rm", "remove"].includes(operands[0] ?? "") && operands.length === 3);
|
|
1073
|
+
if (!valid)
|
|
1074
|
+
throw new UsageError("org requires ls <org> [user], set <org> <user> [role], or rm <org> <user>");
|
|
1075
|
+
}
|
|
1076
|
+
else if (name === "team") {
|
|
1077
|
+
const valid = (["create", "destroy"].includes(operands[0] ?? "") && operands.length === 2) || (["add", "rm", "remove"].includes(operands[0] ?? "") && operands.length === 3) || (["ls", "list"].includes(operands[0] ?? "") && operands.length === 2);
|
|
1078
|
+
if (!valid)
|
|
1079
|
+
throw new UsageError("team requires create|destroy <scope:team>, add|rm <scope:team> <user>, or ls <scope|scope:team>");
|
|
1080
|
+
}
|
|
1081
|
+
else if (name === "profile") {
|
|
1082
|
+
const action = operands[0];
|
|
1083
|
+
const valid = (action === "get" && operands.length <= 2)
|
|
1084
|
+
|| (action === "set" && ((operands[1] === "password" && operands.length === 2) || (operands.length === 3 && ["email", "fullname", "homepage", "freenode", "twitter", "github"].includes(operands[1] ?? ""))))
|
|
1085
|
+
|| (["enable-2fa", "enable-tfa", "enable2fa", "enabletfa"].includes(action ?? "") && operands.length <= 2 && (operands[1] === undefined || ["auth-only", "auth-and-writes"].includes(operands[1])))
|
|
1086
|
+
|| (["disable-2fa", "disable-tfa", "disable2fa", "disabletfa"].includes(action ?? "") && operands.length === 1);
|
|
1087
|
+
if (!valid)
|
|
1088
|
+
throw new UsageError("profile supports get [key], set <field> <value>, set password, enable-2fa [auth-only|auth-and-writes], or disable-2fa");
|
|
1089
|
+
if (options.json && ["set", "enable-2fa", "enable-tfa", "enable2fa", "enabletfa", "disable-2fa", "disable-tfa", "disable2fa", "disabletfa"].includes(action ?? "") && (operands[1] === "password" || action !== "set"))
|
|
1090
|
+
throw new UsageError("secret-bearing profile changes are interactive and cannot use --json");
|
|
1091
|
+
}
|
|
1092
|
+
else if (name === "trust") {
|
|
1093
|
+
const provider = operands[0];
|
|
1094
|
+
const valid = (provider === "list" && operands.length >= 1 && operands.length <= 2)
|
|
1095
|
+
|| (provider === "revoke" && operands.length >= 2 && operands.length <= 3)
|
|
1096
|
+
|| (["github", "gitlab", "circleci"].includes(provider ?? "") && operands.length >= 1 && operands.length <= 2 && (options.allowPublish === true || options.allowStagePublish === true));
|
|
1097
|
+
if (!valid)
|
|
1098
|
+
throw new UsageError("trust supports list [package], revoke [package] <id>, or github|gitlab|circleci [package] with provider options and at least one publish permission");
|
|
1099
|
+
}
|
|
1100
|
+
else if (name === "pack" || name === "publish") {
|
|
1101
|
+
if (operands.length > 1 || operands[0]?.startsWith("-"))
|
|
1102
|
+
throw new UsageError(`${name} accepts at most one package directory`);
|
|
1103
|
+
}
|
|
1104
|
+
else if (name === "run" || name === "exec") {
|
|
1105
|
+
if (name === "run" && operands.length === 0)
|
|
1106
|
+
return { kind: "command", name, options, args: [] };
|
|
1107
|
+
return { kind: "command", name, options, args: parseChildArguments(name, operands) };
|
|
1108
|
+
}
|
|
1109
|
+
else if (name === "explore") {
|
|
1110
|
+
const packageName = operands[0];
|
|
1111
|
+
if (!packageName || !/^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/.test(packageName) || (operands.length > 1 && operands[1] !== "--"))
|
|
1112
|
+
throw new UsageError("explore requires <package> [-- <command> [args...]]");
|
|
1113
|
+
return { kind: "command", name, options, args: [packageName, ...operands.slice(operands[1] === "--" ? 2 : 1)] };
|
|
1114
|
+
}
|
|
1115
|
+
else if (name === "edit") {
|
|
1116
|
+
if (operands.length !== 1 || !/^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/.test(operands[0] ?? ""))
|
|
1117
|
+
throw new UsageError("edit requires one exact installed package name");
|
|
1118
|
+
}
|
|
1119
|
+
else if (name === "link" || name === "unlink") {
|
|
1120
|
+
if (operands.some((operand) => !/^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/.test(operand)))
|
|
1121
|
+
throw new UsageError(`${name} accepts only exact package names`);
|
|
1122
|
+
}
|
|
1123
|
+
else if (name === "query") {
|
|
1124
|
+
if (operands.length !== 1 || !operands[0]?.trim())
|
|
1125
|
+
throw new UsageError("query requires one dependency selector");
|
|
1126
|
+
}
|
|
1127
|
+
else if (name === "diff") {
|
|
1128
|
+
if (operands.some((operand) => operand.startsWith("-") || operand.includes("\0")))
|
|
1129
|
+
throw new UsageError("diff paths must not be options or contain NUL bytes");
|
|
1130
|
+
}
|
|
1131
|
+
else if (name === "remove" || name === "update" || name === "outdated" || name === "list" || name === "why" || name === "rebuild" || name === "approve-scripts" || name === "deny-scripts") {
|
|
1132
|
+
if ((name === "remove" && operands.length === 0) ||
|
|
1133
|
+
(name === "why" && operands.length !== 1) ||
|
|
1134
|
+
operands.some((operand) => !/^(?:@[^/@\s]+\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/.test(operand))) {
|
|
1135
|
+
throw new UsageError(name === "why" ? "why requires one exact package name" : `${name} accepts only exact dependency names${name === "remove" ? " and requires at least one" : ""}`);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
if (name === "add" && operands.length === 0) {
|
|
1140
|
+
throw new UsageError("add requires at least one package specification");
|
|
1141
|
+
}
|
|
1142
|
+
for (const specifier of operands) {
|
|
1143
|
+
validateSpecifier(specifier);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return { kind: "command", name, options, args: operands };
|
|
1147
|
+
}
|
|
1148
|
+
//# sourceMappingURL=cli-parser.js.map
|