mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: only display unknown settings warning for install command (#3130)
This commit is contained in:
5
.changeset/eighty-geese-fly.md
Normal file
5
.changeset/eighty-geese-fly.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
only display unknown settings for install command
|
||||
6
.changeset/strange-llamas-refuse.md
Normal file
6
.changeset/strange-llamas-refuse.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/cli-utils": minor
|
||||
"@pnpm/config": minor
|
||||
---
|
||||
|
||||
add option to check unknown settings
|
||||
@@ -9,6 +9,7 @@ export default async function (
|
||||
globalDirShouldAllowWrite?: boolean
|
||||
rcOptionsTypes: Record<string, unknown>
|
||||
workspaceDir: string | undefined
|
||||
checkUnknownSetting?: boolean
|
||||
}
|
||||
) {
|
||||
const { config, warnings } = await getConfig({
|
||||
@@ -17,6 +18,7 @@ export default async function (
|
||||
packageManager,
|
||||
rcOptionsTypes: opts.rcOptionsTypes,
|
||||
workspaceDir: opts.workspaceDir,
|
||||
checkUnknownSetting: opts.checkUnknownSetting,
|
||||
})
|
||||
config.cliOptions = cliOptions
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ export default async (
|
||||
}
|
||||
rcOptionsTypes?: Record<string, unknown>
|
||||
workspaceDir?: string | undefined
|
||||
checkUnknownSetting?: boolean
|
||||
}
|
||||
): Promise<{ config: Config, warnings: string[] }> => {
|
||||
const packageManager = opts.packageManager ?? { name: 'pnpm', version: 'undefined' }
|
||||
@@ -393,18 +394,20 @@ export default async (
|
||||
}
|
||||
pnpmConfig.enablePnp = pnpmConfig['nodeLinker'] === 'pnp'
|
||||
|
||||
const settingKeys = Object.keys({
|
||||
...npmConfig?.sources?.workspace?.data,
|
||||
...npmConfig?.sources?.project?.data,
|
||||
}).filter(key => key.trim() !== '')
|
||||
const unknownKeys = []
|
||||
for (const key of settingKeys) {
|
||||
if (!rcOptions.includes(key) && !key.startsWith('//') && !(key.startsWith('@') && key.endsWith(':registry'))) {
|
||||
unknownKeys.push(key)
|
||||
if (opts.checkUnknownSetting) {
|
||||
const settingKeys = Object.keys({
|
||||
...npmConfig?.sources?.workspace?.data,
|
||||
...npmConfig?.sources?.project?.data,
|
||||
}).filter(key => key.trim() !== '')
|
||||
const unknownKeys = []
|
||||
for (const key of settingKeys) {
|
||||
if (!rcOptions.includes(key) && !key.startsWith('//') && !(key.startsWith('@') && key.endsWith(':registry'))) {
|
||||
unknownKeys.push(key)
|
||||
}
|
||||
}
|
||||
if (unknownKeys.length) {
|
||||
warnings.push(`Your .npmrc file contains unknown setting: ${unknownKeys.join(', ')}`)
|
||||
}
|
||||
}
|
||||
if (unknownKeys.length) {
|
||||
warnings.push(`Your .npmrc file contains unknown setting: ${unknownKeys.join(', ')}`)
|
||||
}
|
||||
|
||||
return { config: pnpmConfig, warnings }
|
||||
|
||||
@@ -647,9 +647,20 @@ test('warn user unknown settings in npmrc', async () => {
|
||||
name: 'pnpm',
|
||||
version: '1.0.0',
|
||||
},
|
||||
checkUnknownSetting: true,
|
||||
})
|
||||
|
||||
expect(warnings).toStrictEqual([
|
||||
'Your .npmrc file contains unknown setting: typo-setting, mistake-setting',
|
||||
])
|
||||
|
||||
const { warnings: noWarnings } = await getConfig({
|
||||
cliOptions: {},
|
||||
packageManager: {
|
||||
name: 'pnpm',
|
||||
version: '1.0.0',
|
||||
},
|
||||
})
|
||||
|
||||
expect(noWarnings).toStrictEqual([])
|
||||
})
|
||||
|
||||
@@ -88,11 +88,13 @@ export default async function run (inputArgv: string[]) {
|
||||
// When we just want to print the location of the global bin directory,
|
||||
// we don't need the write permission to it. Related issue: #2700
|
||||
const globalDirShouldAllowWrite = cmd !== 'root'
|
||||
const checkUnknownSetting = cmd === 'install'
|
||||
config = await getConfig(cliOptions, {
|
||||
excludeReporter: false,
|
||||
globalDirShouldAllowWrite,
|
||||
rcOptionsTypes,
|
||||
workspaceDir,
|
||||
checkUnknownSetting,
|
||||
}) as typeof config
|
||||
config.forceSharedLockfile = typeof config.workspaceDir === 'string' && config.sharedWorkspaceLockfile === true
|
||||
config.argv = argv
|
||||
|
||||
Reference in New Issue
Block a user