@pnpm/cli.parse-cli-args 1100.1.1 → 1100.1.3
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/lib/index.js +55 -14
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function parseCliArgs(opts, inputArgv) {
|
|
|
30
30
|
if (noptExploratoryResults['help']) {
|
|
31
31
|
return {
|
|
32
32
|
...getParsedArgsForHelp(),
|
|
33
|
-
workspaceDir: await getWorkspaceDir(noptExploratoryResults),
|
|
33
|
+
workspaceDir: await getWorkspaceDir(noptExploratoryResults, opts.renamedOptions),
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
if (noptExploratoryResults['version'] || noptExploratoryResults['v']) {
|
|
@@ -38,12 +38,13 @@ export async function parseCliArgs(opts, inputArgv) {
|
|
|
38
38
|
argv: noptExploratoryResults.argv,
|
|
39
39
|
cmd: null,
|
|
40
40
|
options: {
|
|
41
|
+
...pickUniversalOptions(),
|
|
41
42
|
version: true,
|
|
42
43
|
},
|
|
43
44
|
params: noptExploratoryResults.argv.remain,
|
|
44
45
|
unknownOptions: new Map(),
|
|
45
46
|
fallbackCommandUsed: false,
|
|
46
|
-
workspaceDir: await getWorkspaceDir(noptExploratoryResults),
|
|
47
|
+
workspaceDir: await getWorkspaceDir(noptExploratoryResults, opts.renamedOptions),
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
}
|
|
@@ -51,12 +52,32 @@ export async function parseCliArgs(opts, inputArgv) {
|
|
|
51
52
|
return {
|
|
52
53
|
argv: noptExploratoryResults.argv,
|
|
53
54
|
cmd: 'help',
|
|
54
|
-
options:
|
|
55
|
+
options: pickUniversalOptions(),
|
|
55
56
|
params: noptExploratoryResults.argv.remain,
|
|
56
57
|
unknownOptions: new Map(),
|
|
57
58
|
fallbackCommandUsed: false,
|
|
58
59
|
};
|
|
59
60
|
}
|
|
61
|
+
// The --help and --version short-circuits skip the per-command nopt
|
|
62
|
+
// parse, so we still need to surface universal options the user typed
|
|
63
|
+
// alongside them — most importantly --pm-on-fail, which gates the
|
|
64
|
+
// packageManager / devEngines.packageManager check (#11487). Universal
|
|
65
|
+
// options were already typed and parsed by the exploratory nopt call,
|
|
66
|
+
// so we just pluck them back out and apply the same renamedOptions
|
|
67
|
+
// mapping the regular parse path uses (e.g. --prefix → dir), so
|
|
68
|
+
// consumers see consistent option names regardless of which path
|
|
69
|
+
// produced the result. Command-specific options are intentionally
|
|
70
|
+
// dropped; they belong to a command we are not running.
|
|
71
|
+
function pickUniversalOptions() {
|
|
72
|
+
const result = {};
|
|
73
|
+
for (const key of Object.keys(opts.universalOptionsTypes)) {
|
|
74
|
+
if (!(key in noptExploratoryResults))
|
|
75
|
+
continue;
|
|
76
|
+
const renamed = opts.renamedOptions?.[key] ?? key;
|
|
77
|
+
result[renamed] = noptExploratoryResults[key];
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
60
81
|
const types = {
|
|
61
82
|
...opts.universalOptionsTypes,
|
|
62
83
|
...opts.getTypesByCommandName(commandName),
|
|
@@ -116,6 +137,23 @@ export async function parseCliArgs(opts, inputArgv) {
|
|
|
116
137
|
const { argv: _, ...configOptions } = nopt({}, {}, configDotArgs, 0);
|
|
117
138
|
Object.assign(options, configOptions);
|
|
118
139
|
}
|
|
140
|
+
// Apply renamedOptions before workspace detection so `--prefix=foo`
|
|
141
|
+
// (renamed to `dir`) participates in finding the workspace root.
|
|
142
|
+
// Otherwise getWorkspaceDir falls back to process.cwd() and the
|
|
143
|
+
// workspace manifest at the prefix dir is missed (#11535).
|
|
144
|
+
// The canonical option wins if both are supplied (e.g. `--prefix=foo
|
|
145
|
+
// --dir=bar` keeps `dir=bar`); the alias is always dropped.
|
|
146
|
+
if (opts.renamedOptions != null) {
|
|
147
|
+
for (const [cliOption, optionValue] of Object.entries(options)) {
|
|
148
|
+
const target = opts.renamedOptions[cliOption];
|
|
149
|
+
if (target) {
|
|
150
|
+
if (!(target in options)) {
|
|
151
|
+
options[target] = optionValue;
|
|
152
|
+
}
|
|
153
|
+
delete options[cliOption];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
119
157
|
const workspaceDir = await getWorkspaceDir(options);
|
|
120
158
|
// For the run command, it's not clear whether --help should be passed to the
|
|
121
159
|
// underlying script or invoke pnpm's help text until an additional nopt call.
|
|
@@ -125,14 +163,6 @@ export async function parseCliArgs(opts, inputArgv) {
|
|
|
125
163
|
workspaceDir,
|
|
126
164
|
};
|
|
127
165
|
}
|
|
128
|
-
if (opts.renamedOptions != null) {
|
|
129
|
-
for (const [cliOption, optionValue] of Object.entries(options)) {
|
|
130
|
-
if (opts.renamedOptions[cliOption]) {
|
|
131
|
-
options[opts.renamedOptions[cliOption]] = optionValue;
|
|
132
|
-
delete options[cliOption];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
166
|
const params = argv.remain.slice(1);
|
|
137
167
|
if (options['recursive'] !== true && (options['filter'] || options['filter-prod'] || recursiveCommandUsed)) {
|
|
138
168
|
options['recursive'] = true;
|
|
@@ -201,10 +231,21 @@ function getClosestOptionMatches(knownOptions, option) {
|
|
|
201
231
|
returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
|
|
202
232
|
});
|
|
203
233
|
}
|
|
204
|
-
async function getWorkspaceDir(parsedOpts) {
|
|
234
|
+
async function getWorkspaceDir(parsedOpts, renamedOptions) {
|
|
205
235
|
if (parsedOpts['global'] || parsedOpts['ignore-workspace'])
|
|
206
236
|
return undefined;
|
|
207
|
-
|
|
208
|
-
|
|
237
|
+
// Look up dir, also honoring renamed options like `prefix → dir` so that
|
|
238
|
+
// `--prefix` works even on code paths that read parsedOpts before the
|
|
239
|
+
// rename loop has run (e.g. the --help/--version short-circuits).
|
|
240
|
+
let dir = parsedOpts['dir'];
|
|
241
|
+
if (dir == null && renamedOptions != null) {
|
|
242
|
+
for (const [from, to] of Object.entries(renamedOptions)) {
|
|
243
|
+
if (to === 'dir' && parsedOpts[from] != null) {
|
|
244
|
+
dir = parsedOpts[from];
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return findWorkspaceDir((dir ?? process.cwd()));
|
|
209
250
|
}
|
|
210
251
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/cli.parse-cli-args",
|
|
3
|
-
"version": "1100.1.
|
|
3
|
+
"version": "1100.1.3",
|
|
4
4
|
"description": "Parses the CLI args passed to pnpm",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@jest/globals": "30.3.0",
|
|
34
34
|
"tempy": "3.0.0",
|
|
35
|
-
"@pnpm/cli.parse-cli-args": "1100.1.
|
|
35
|
+
"@pnpm/cli.parse-cli-args": "1100.1.3"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=22.13"
|