fix: allow scope registry cli option without --config. prefix (#9089)

close #9084.
close #9085
This commit is contained in:
Naru
2025-02-25 10:29:39 +09:00
committed by GitHub
parent 529696182f
commit 48b487177e
3 changed files with 12 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/parse-cli-args": patch
"pnpm": patch
---
Allow scope registry CLI option without `--config.` prefix such as `--@scope:registry=https://scope.example.com/npm` [#9089](https://github.com/pnpm/pnpm/pull/9089).

View File

@@ -225,13 +225,17 @@ function getUnknownOptions (usedOptions: string[], knownOptions: Set<string>): M
const unknownOptions = new Map<string, string[]>()
const closestMatches = getClosestOptionMatches.bind(null, Array.from(knownOptions))
for (const usedOption of usedOptions) {
if (knownOptions.has(usedOption) || usedOption.startsWith('//')) continue
if (knownOptions.has(usedOption) || usedOption.startsWith('//') || isScopeRegistryOption(usedOption)) continue
unknownOptions.set(usedOption, closestMatches(usedOption))
}
return unknownOptions
}
function isScopeRegistryOption (optionName: string): boolean {
return /^@[a-z0-9][\w.-]*:registry$/.test(optionName)
}
function getClosestOptionMatches (knownOptions: string[], option: string): string[] {
return didYouMean(option, knownOptions, {
returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,

View File

@@ -114,7 +114,7 @@ test('detect unknown options', async () => {
return {}
},
universalOptionsTypes: { filter: [String, Array] },
}, ['install', '--save-dev', '--registry=https://example.com', '--qar', '--filter=packages'])
}, ['install', '--save-dev', '--registry=https://example.com', '--@scope:registry=https://scope.example.com/npm', '--qar', '--filter=packages'])
expect(Array.from(unknownOptions.entries())).toStrictEqual([['save-dev', []], ['qar', ['bar']]])
})