mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-01 19:48:13 -05:00
fix: every command should read settings from the root workspace project (#8671)
close #8667
This commit is contained in:
6
.changeset/sour-experts-cough.md
Normal file
6
.changeset/sour-experts-cough.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/parse-cli-args": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
All commands should read settings from the `package.json` at the root of the workspace [#8667](https://github.com/pnpm/pnpm/issues/8667).
|
||||
@@ -17,7 +17,7 @@ export interface ParsedCliArgs {
|
||||
cmd: string | null
|
||||
unknownOptions: Map<string, string[]>
|
||||
fallbackCommandUsed: boolean
|
||||
workspaceDir?: string
|
||||
workspaceDir: string | undefined
|
||||
}
|
||||
|
||||
export async function parseCliArgs (
|
||||
@@ -62,7 +62,10 @@ export async function parseCliArgs (
|
||||
// The run command has special casing for --help and is handled further below.
|
||||
} else if (cmd !== 'run') {
|
||||
if (noptExploratoryResults['help']) {
|
||||
return getParsedArgsForHelp()
|
||||
return {
|
||||
...getParsedArgsForHelp(),
|
||||
workspaceDir: await getWorkspaceDir(noptExploratoryResults),
|
||||
}
|
||||
}
|
||||
if (noptExploratoryResults['version'] || noptExploratoryResults['v']) {
|
||||
return {
|
||||
@@ -74,11 +77,12 @@ export async function parseCliArgs (
|
||||
params: noptExploratoryResults.argv.remain,
|
||||
unknownOptions: new Map(),
|
||||
fallbackCommandUsed: false,
|
||||
workspaceDir: await getWorkspaceDir(noptExploratoryResults),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getParsedArgsForHelp (): ParsedCliArgs {
|
||||
function getParsedArgsForHelp (): Omit<ParsedCliArgs, 'workspaceDir'> {
|
||||
return {
|
||||
argv: noptExploratoryResults.argv,
|
||||
cmd: 'help',
|
||||
@@ -137,11 +141,15 @@ export async function parseCliArgs (
|
||||
0,
|
||||
{ escapeArgs: getEscapeArgsWithSpecialCaseForRun() }
|
||||
)
|
||||
const workspaceDir = await getWorkspaceDir(options)
|
||||
|
||||
// For the run command, it's not clear whether --help should be passed to the
|
||||
// underlying script or invoke pnpm's help text until an additional nopt call.
|
||||
if (cmd === 'run' && options['help']) {
|
||||
return getParsedArgsForHelp()
|
||||
return {
|
||||
...getParsedArgsForHelp(),
|
||||
workspaceDir,
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.renamedOptions != null) {
|
||||
@@ -164,10 +172,6 @@ export async function parseCliArgs (
|
||||
cmd = subCmd
|
||||
}
|
||||
}
|
||||
const dir = options['dir'] ?? process.cwd()
|
||||
const workspaceDir = options['global'] || options['ignore-workspace']
|
||||
? undefined
|
||||
: await findWorkspaceDir(dir)
|
||||
if (options['workspace-root']) {
|
||||
if (options['global']) {
|
||||
throw new PnpmError('OPTIONS_CONFLICT', '--workspace-root may not be used with --global')
|
||||
@@ -233,3 +237,9 @@ function getClosestOptionMatches (knownOptions: string[], option: string): strin
|
||||
returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
|
||||
})
|
||||
}
|
||||
|
||||
async function getWorkspaceDir (parsedOpts: Record<string, unknown>): Promise<string | undefined> {
|
||||
if (parsedOpts['global'] || parsedOpts['ignore-workspace']) return undefined
|
||||
const dir = parsedOpts['dir'] ?? process.cwd()
|
||||
return findWorkspaceDir(dir as string)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user