fix: only display unknown settings warning for install command (#3130)

This commit is contained in:
Yao Ding
2021-02-08 18:39:18 -05:00
committed by GitHub
parent a5e9d903cb
commit cb040ae185
6 changed files with 40 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"pnpm": patch
---
only display unknown settings for install command

View File

@@ -0,0 +1,6 @@
---
"@pnpm/cli-utils": minor
"@pnpm/config": minor
---
add option to check unknown settings

View File

@@ -9,6 +9,7 @@ export default async function (
globalDirShouldAllowWrite?: boolean globalDirShouldAllowWrite?: boolean
rcOptionsTypes: Record<string, unknown> rcOptionsTypes: Record<string, unknown>
workspaceDir: string | undefined workspaceDir: string | undefined
checkUnknownSetting?: boolean
} }
) { ) {
const { config, warnings } = await getConfig({ const { config, warnings } = await getConfig({
@@ -17,6 +18,7 @@ export default async function (
packageManager, packageManager,
rcOptionsTypes: opts.rcOptionsTypes, rcOptionsTypes: opts.rcOptionsTypes,
workspaceDir: opts.workspaceDir, workspaceDir: opts.workspaceDir,
checkUnknownSetting: opts.checkUnknownSetting,
}) })
config.cliOptions = cliOptions config.cliOptions = cliOptions

View File

@@ -108,6 +108,7 @@ export default async (
} }
rcOptionsTypes?: Record<string, unknown> rcOptionsTypes?: Record<string, unknown>
workspaceDir?: string | undefined workspaceDir?: string | undefined
checkUnknownSetting?: boolean
} }
): Promise<{ config: Config, warnings: string[] }> => { ): Promise<{ config: Config, warnings: string[] }> => {
const packageManager = opts.packageManager ?? { name: 'pnpm', version: 'undefined' } const packageManager = opts.packageManager ?? { name: 'pnpm', version: 'undefined' }
@@ -393,6 +394,7 @@ export default async (
} }
pnpmConfig.enablePnp = pnpmConfig['nodeLinker'] === 'pnp' pnpmConfig.enablePnp = pnpmConfig['nodeLinker'] === 'pnp'
if (opts.checkUnknownSetting) {
const settingKeys = Object.keys({ const settingKeys = Object.keys({
...npmConfig?.sources?.workspace?.data, ...npmConfig?.sources?.workspace?.data,
...npmConfig?.sources?.project?.data, ...npmConfig?.sources?.project?.data,
@@ -406,6 +408,7 @@ export default async (
if (unknownKeys.length) { if (unknownKeys.length) {
warnings.push(`Your .npmrc file contains unknown setting: ${unknownKeys.join(', ')}`) warnings.push(`Your .npmrc file contains unknown setting: ${unknownKeys.join(', ')}`)
} }
}
return { config: pnpmConfig, warnings } return { config: pnpmConfig, warnings }
} }

View File

@@ -647,9 +647,20 @@ test('warn user unknown settings in npmrc', async () => {
name: 'pnpm', name: 'pnpm',
version: '1.0.0', version: '1.0.0',
}, },
checkUnknownSetting: true,
}) })
expect(warnings).toStrictEqual([ expect(warnings).toStrictEqual([
'Your .npmrc file contains unknown setting: typo-setting, mistake-setting', '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([])
}) })

View File

@@ -88,11 +88,13 @@ export default async function run (inputArgv: string[]) {
// When we just want to print the location of the global bin directory, // 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 // we don't need the write permission to it. Related issue: #2700
const globalDirShouldAllowWrite = cmd !== 'root' const globalDirShouldAllowWrite = cmd !== 'root'
const checkUnknownSetting = cmd === 'install'
config = await getConfig(cliOptions, { config = await getConfig(cliOptions, {
excludeReporter: false, excludeReporter: false,
globalDirShouldAllowWrite, globalDirShouldAllowWrite,
rcOptionsTypes, rcOptionsTypes,
workspaceDir, workspaceDir,
checkUnknownSetting,
}) as typeof config }) as typeof config
config.forceSharedLockfile = typeof config.workspaceDir === 'string' && config.sharedWorkspaceLockfile === true config.forceSharedLockfile = typeof config.workspaceDir === 'string' && config.sharedWorkspaceLockfile === true
config.argv = argv config.argv = argv