feat: print warnings if unknown settings are found in .npmrc (#3074)

* feat: print warnings if unknown settings are found in .npmrc

close #2981

* feat: pnpm takes all cmd config option

* fix: add more sources

* refactor: make some improvements

* fix: don't warn about @scope:registry

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Yao Ding
2021-01-23 10:22:55 -05:00
committed by GitHub
parent 9ad8c27bf0
commit 548f28df9a
13 changed files with 115 additions and 47 deletions

View File

@@ -0,0 +1,5 @@
---
"pnpm": minor
---
feat: pnpm takes all cmd config

View File

@@ -0,0 +1,5 @@
---
"@pnpm/default-reporter": minor
---
Export `formatWarn(warningMessage: string): string`.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/cli-utils": patch
---
Format the printed warnings.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/config": minor
---
print warnings if unknown settings are found in .npmrc

View File

@@ -35,6 +35,7 @@
"dependencies": {
"@pnpm/cli-meta": "workspace:1.0.1",
"@pnpm/config": "workspace:11.11.1",
"@pnpm/default-reporter": "workspace:7.9.16",
"@pnpm/error": "workspace:1.4.0",
"@pnpm/manifest-utils": "workspace:1.1.4",
"@pnpm/package-is-installable": "workspace:4.0.18",

View File

@@ -1,5 +1,6 @@
import packageManager from '@pnpm/cli-meta'
import getConfig, { CliOptions } from '@pnpm/config'
import { formatWarn } from '@pnpm/default-reporter'
export default async function (
cliOptions: CliOptions,
@@ -24,7 +25,7 @@ export default async function (
}
if (warnings.length > 0) {
console.log(warnings.join('\n'))
console.log(warnings.map((warning) => formatWarn(warning)).join('\n'))
}
return config

View File

@@ -15,6 +15,9 @@
{
"path": "../config"
},
{
"path": "../default-reporter"
},
{
"path": "../error"
},

View File

@@ -186,12 +186,15 @@ export default async (
'workspace-concurrency': 4,
'workspace-prefix': opts.workspaceDir,
})
delete cliOptions.prefix
process.execPath = originalExecPath
const rcOptions = Object.keys(rcOptionsTypes)
const pnpmConfig: ConfigWithDeprecatedSettings = R.fromPairs([
...Object.keys(rcOptionsTypes).map((configKey) => [camelcase(configKey), npmConfig.get(configKey)]) as any, // eslint-disable-line
...rcOptions.map((configKey) => [camelcase(configKey), npmConfig.get(configKey)]) as any, // eslint-disable-line
...Object.entries(cliOptions).filter(([name, value]) => typeof value !== 'undefined').map(([name, value]) => [camelcase(name), value]),
]) as unknown as ConfigWithDeprecatedSettings
const cwd = (cliOptions.dir && path.resolve(cliOptions.dir)) ?? npmConfig.localPrefix
@@ -388,6 +391,21 @@ export default async (
pnpmConfig.noProxy = getProcessEnv('no_proxy')
}
pnpmConfig.enablePnp = pnpmConfig['nodeLinker'] === 'pnp'
const settingKeys = Object.keys({
...npmConfig?.sources?.workspace?.data,
...npmConfig?.sources?.project?.data,
})
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(', ')}`)
}
return { config: pnpmConfig, warnings }
}

View File

@@ -627,3 +627,28 @@ test('dir is resolved to real path', async () => {
})
expect(config.dir).toBe(realDir)
})
test('warn user unknown settings in npmrc', async () => {
const tmp = tempy.directory()
process.chdir(tmp)
const npmrc = [
'typo-setting=true',
'mistake-setting=false',
'//foo.bar:_authToken=aaa',
'@qar:registry=https://registry.example.org/',
].join('\n')
await fs.writeFile('.npmrc', npmrc, 'utf8')
const { warnings } = await getConfig({
cliOptions: {},
packageManager: {
name: 'pnpm',
version: '1.0.0',
},
})
expect(warnings).toStrictEqual([
'Your .npmrc file contains unknown setting: typo-setting, mistake-setting',
])
})

View File

@@ -6,9 +6,12 @@ import { map, mergeAll } from 'rxjs/operators'
import { EOL } from './constants'
import mergeOutputs from './mergeOutputs'
import reporterForClient from './reporterForClient'
import formatWarn from './reporterForClient/utils/formatWarn'
import reporterForServer from './reporterForServer'
import createDiffer = require('ansi-diff')
export { formatWarn }
export default function (
opts: {
streamParser: object

View File

@@ -86,10 +86,10 @@ const commands: Array<{
const handlerByCommandName: Record<string, Command> = {}
const helpByCommandName: Record<string, () => string> = {}
const cliOptionsTypesByCommandName: Record<string, () => Object> = {}
const rcOptionsTypesByCommandName: Record<string, () => Record<string, unknown>> = {}
const aliasToFullName: Map<string, string> = new Map()
const completionByCommandName: Record<string, CompletionFunc> = {}
const shorthandsByCommandName: Record<string, Record<string, string | string[]>> = {}
const rcOptionsTypes: Record<string, unknown> = {}
for (let i = 0; i < commands.length; i++) {
const {
@@ -108,11 +108,11 @@ for (let i = 0; i < commands.length; i++) {
handlerByCommandName[commandName] = handler as Command
helpByCommandName[commandName] = help
cliOptionsTypesByCommandName[commandName] = cliOptionsTypes
rcOptionsTypesByCommandName[commandName] = rcOptionsTypes
shorthandsByCommandName[commandName] = shorthands ?? {}
if (completion) {
completionByCommandName[commandName] = completion
}
Object.assign(rcOptionsTypes, rcOptionsTypes())
}
if (commandNames.length > 1) {
const fullName = commandNames[0]
@@ -141,14 +141,9 @@ export function getCliOptionsTypes (commandName: string) {
return cliOptionsTypesByCommandName[commandName]?.() || {}
}
export function getRCOptionsTypes (commandName: string | null) {
if (!commandName) return {}
return rcOptionsTypesByCommandName[commandName]?.() ?? {}
}
export function getCommandFullName (commandName: string) {
return aliasToFullName.get(commandName) ??
(handlerByCommandName[commandName] ? commandName : null)
}
export { shorthandsByCommandName }
export { shorthandsByCommandName, rcOptionsTypes }

View File

@@ -12,7 +12,7 @@ import findWorkspacePackages from '@pnpm/find-workspace-packages'
import logger from '@pnpm/logger'
import { ParsedCliArgs } from '@pnpm/parse-cli-args'
import checkForUpdates from './checkForUpdates'
import pnpmCmds, { getRCOptionsTypes } from './cmd'
import pnpmCmds, { rcOptionsTypes } from './cmd'
import { formatUnknownOptionsError } from './formatError'
import './logging/fileLogger'
import parseCliArgs from './parseCliArgs'
@@ -91,7 +91,7 @@ export default async function run (inputArgv: string[]) {
config = await getConfig(cliOptions, {
excludeReporter: false,
globalDirShouldAllowWrite,
rcOptionsTypes: getRCOptionsTypes(cmd),
rcOptionsTypes,
workspaceDir,
}) as typeof config
config.forceSharedLockfile = typeof config.workspaceDir === 'string' && config.sharedWorkspaceLockfile === true

72
pnpm-lock.yaml generated
View File

@@ -1,7 +1,7 @@
importers:
.:
devDependencies:
'@changesets/cli': 2.13.0
'@changesets/cli': 2.13.1
'@commitlint/cli': 11.0.0
'@commitlint/config-conventional': 11.0.0
'@commitlint/prompt-cli': 11.0.0
@@ -168,6 +168,7 @@ importers:
dependencies:
'@pnpm/cli-meta': link:../cli-meta
'@pnpm/config': link:../config
'@pnpm/default-reporter': link:../default-reporter
'@pnpm/error': link:../error
'@pnpm/manifest-utils': link:../manifest-utils
'@pnpm/package-is-installable': link:../package-is-installable
@@ -183,6 +184,7 @@ importers:
'@pnpm/cli-meta': workspace:1.0.1
'@pnpm/cli-utils': 'link:'
'@pnpm/config': workspace:11.11.1
'@pnpm/default-reporter': workspace:7.9.16
'@pnpm/error': workspace:1.4.0
'@pnpm/logger': ^3.2.3
'@pnpm/manifest-utils': workspace:1.1.4
@@ -742,7 +744,7 @@ importers:
load-json-file: 6.2.0
mz: 2.7.0
npm-run-all: 4.1.5
sinon: 9.2.3
sinon: 9.2.4
tempy: 1.0.0
write-json-file: 4.3.0
specifiers:
@@ -1733,7 +1735,7 @@ importers:
path-name: 1.0.0
proxyquire: 2.1.3
read-yaml-file: 2.0.0
sinon: 9.2.3
sinon: 9.2.4
tempy: 1.0.0
write-json-file: 4.3.0
write-pkg: 4.0.0
@@ -2028,7 +2030,7 @@ importers:
'@types/sinon': 9.0.10
execa: 5.0.0
path-exists: 4.0.0
sinon: 9.2.3
sinon: 9.2.4
write-yaml-file: 4.1.3
specifiers:
'@pnpm/cli-utils': workspace:0.4.46
@@ -2211,7 +2213,7 @@ importers:
execa: 5.0.0
load-json-file: 6.2.0
path-exists: 4.0.0
sinon: 9.2.3
sinon: 9.2.4
ssri: 6.0.1
tempy: 1.0.0
specifiers:
@@ -2311,7 +2313,7 @@ importers:
deep-require-cwd: 1.0.0
delay: 4.4.0
dir-is-case-sensitive: 1.0.2
esbuild: 0.8.33
esbuild: 0.8.34
execa: 5.0.0
exists-link: 2.0.0
graceful-fs: 4.2.4
@@ -2850,7 +2852,7 @@ importers:
path-name: 1.0.0
read-yaml-file: 2.0.0
resolve-link-target: 1.0.1
sinon: 9.2.3
sinon: 9.2.4
supi: 'link:'
symlink-dir: 4.1.0
write-json-file: 4.3.0
@@ -3484,7 +3486,7 @@ packages:
dev: true
resolution:
integrity: sha512-1UqJpX5Tj2kGtcI3anG3vsLFfX6na5fLsPaxwgS7T/zt1jJ1hv0cMC+iP6fd9BuCHvcFn22GT74bcRaVnAvm3Q==
/@changesets/cli/2.13.0:
/@changesets/cli/2.13.1:
dependencies:
'@babel/runtime': 7.12.5
'@changesets/apply-release-plan': 4.1.0
@@ -3519,7 +3521,7 @@ packages:
dev: true
hasBin: true
resolution:
integrity: sha512-z5b2CkubunWkT5jtGLIioz6swhsSd9ks7cxQNrf721JE3cr2si+Qy/3Zrw9jfbQTHheionD3LAEsc6wauZg3WQ==
integrity: sha512-pG8/X57tD60WGVN9zFN190GktXXF3O4e1ApWPAtDNLh7A3ccgl8QaOg2npOARmkr4lBOPJHLjUILd8Z+u4B7+Q==
/@changesets/config/1.4.0:
dependencies:
'@changesets/errors': 0.1.4
@@ -4095,10 +4097,10 @@ packages:
node: '>=10.13'
resolution:
integrity: sha512-tShDC50o4zc4B3lGK2TAe5p3K2ebbD4z+6YN6fX5eJ1pganxtNEbivchFX5/fEoGefcYyxZYQ0++te77O9apjg==
/@pnpm/cli-utils/0.4.45_@pnpm+logger@3.2.3:
/@pnpm/cli-utils/0.4.46_@pnpm+logger@3.2.3:
dependencies:
'@pnpm/cli-meta': 1.0.1
'@pnpm/config': 11.11.0
'@pnpm/config': 11.11.1
'@pnpm/error': 1.4.0
'@pnpm/logger': 3.2.3
'@pnpm/manifest-utils': 1.1.4_@pnpm+logger@3.2.3
@@ -4112,7 +4114,7 @@ packages:
peerDependencies:
'@pnpm/logger': ^3.2.3
resolution:
integrity: sha512-6vUHNDKV8ZTLWdSqHAbD01oVhyGcDOhbn27bcW1masgElGubyyD3iyxwW19mRsGOyZ/bUqFAg5esNRhhU2bz6Q==
integrity: sha512-XtSD8/T45ShHXSylJiA5ki9lmyKVfVnMO+rLPXXK1qaey24ygUC30RG4JOCzF56SYZHkUa06UgaMignF00Tdag==
/@pnpm/colorize-semver-diff/1.0.1:
dependencies:
chalk: 4.1.0
@@ -4121,11 +4123,11 @@ packages:
node: '>=10'
resolution:
integrity: sha512-qP4E7mzmCBhB4so6szszeIdVDrcKGTTCxBazCKoiPUG34xLha6r57zJuFBkTmD65i3TB7++lf3BwpQruUwf/BQ==
/@pnpm/config/11.11.0:
/@pnpm/config/11.11.1:
dependencies:
'@pnpm/constants': 4.1.0
'@pnpm/error': 1.4.0
'@pnpm/global-bin-dir': 1.2.5
'@pnpm/global-bin-dir': 1.2.6
'@pnpm/types': 6.3.1
'@zkochan/npm-conf': 2.0.2
camelcase: 6.2.0
@@ -4137,7 +4139,7 @@ packages:
engines:
node: '>=10.16'
resolution:
integrity: sha512-Bd38XXHhKn3Lw+zL4ywgub+S2J9QU9M1b//BYvhipicRS78QMhb1WJ5Neo6wUEoDec3TrhlCjYb11gl4srft0w==
integrity: sha512-Q9/qfd8+dRIP3aItXhLXz8xQ6YS6G9f/V0G0dW6cOsUC4VufTruCkzjrADfb4Fymu9BZ1ofkJoNqf4LyEJEhRA==
/@pnpm/constants/4.1.0:
dev: true
engines:
@@ -4189,9 +4191,9 @@ packages:
node: '>=10.16'
resolution:
integrity: sha512-xgDjjJwnf2cH7+LjdfzG4sbvGJtn903IpJ8eDraEjD4V/a9VdMV2GtC7lw4nLyNXsY8bqtn4jkHwiYnUpyXm5g==
/@pnpm/find-workspace-packages/2.3.31_@pnpm+logger@3.2.3:
/@pnpm/find-workspace-packages/2.3.32_@pnpm+logger@3.2.3:
dependencies:
'@pnpm/cli-utils': 0.4.45_@pnpm+logger@3.2.3
'@pnpm/cli-utils': 0.4.46_@pnpm+logger@3.2.3
'@pnpm/constants': 4.1.0
'@pnpm/types': 6.3.1
find-packages: 7.0.22
@@ -4202,8 +4204,8 @@ packages:
peerDependencies:
'@pnpm/logger': '*'
resolution:
integrity: sha512-xSSn9ZVuKHD0GvdOxkFbYrnsb6AA1OI2zVkPzOiP2lIaZzZ6SPUU/qnLanoKrS3s+lOux6KOufZfNrQrpecmRQ==
/@pnpm/global-bin-dir/1.2.5:
integrity: sha512-B1SDKjGE1pAl/MCPG0P2CZm00yuP88antkcLKPc+fbyr4R2v6Pn5nXk0OjTrX4NACLiqWAfHrOHH3z/jouzN2A==
/@pnpm/global-bin-dir/1.2.6:
dependencies:
'@pnpm/error': 1.4.0
can-write-to-dir: 1.0.1
@@ -4212,7 +4214,7 @@ packages:
engines:
node: '>=10.16'
resolution:
integrity: sha512-RB3oHl0dx6t/p+kQs7AKrxY4hijAL0zRAV8HXVzk8SR3k6fxqv1nLoZbVt7NpRHcTiyw8HcWo87pOU4gejVJCg==
integrity: sha512-xHTzK9WlCfvoNQwmFsTcPKRMguhrClXc/9f1ywrBRpHDRfZzcIX8hh3ZNr1kKL5CBeMM/Db2mDfpqo9hs+UuXQ==
/@pnpm/logger/3.2.3:
dependencies:
bole: /@zkochan/bole/3.0.4
@@ -4236,7 +4238,7 @@ packages:
/@pnpm/meta-updater/0.0.0:
dependencies:
'@pnpm/find-workspace-dir': 2.0.0
'@pnpm/find-workspace-packages': 2.3.31_@pnpm+logger@3.2.3
'@pnpm/find-workspace-packages': 2.3.32_@pnpm+logger@3.2.3
'@pnpm/logger': 3.2.3
'@pnpm/types': 6.3.1
load-json-file: 6.2.0
@@ -4431,7 +4433,7 @@ packages:
/@types/braces/3.0.0:
dev: true
resolution:
integrity: sha1-faHA1E/xx+tmCjbsB46mG6frQss=
integrity: sha512-TbH79tcyi9FHwbyboOKeRachRq63mSuWYXOflsNO9ZyE5ClQ/JaozNKl+aWUq87qPNsXasXxi2AbgfwIJ+8GQw==
/@types/byline/4.2.32:
dependencies:
'@types/node': 14.14.22
@@ -4554,7 +4556,7 @@ packages:
'@types/braces': 3.0.0
dev: true
resolution:
integrity: sha1-k4FEndZZ/Dgj/SpBkM6syYUIO8c=
integrity: sha512-my6fLBvpY70KattTNzYOK6KU1oR1+UCz9ug/JbcF5UrEmeCt9P7DV2t7L8+t18mMPINqGQCE4O8PLOPbI84gxw==
/@types/minimatch/3.0.3:
resolution:
integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
@@ -7023,7 +7025,7 @@ packages:
engines:
node: '>=10'
resolution:
integrity: sha1-C0DQMyzqdD8WFPgYvk/rcXcUyVI=
integrity: sha512-1shh9DQ23L16oXSZKB2JxpL7iMy2E0S9d517ptA1P8iw0alkPtQcrKH7ru31rYtKwF499HkTu+DRzq3TCKDFRQ==
/delay/4.4.0:
engines:
node: '>=6'
@@ -7343,12 +7345,12 @@ packages:
dev: false
resolution:
integrity: sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
/esbuild/0.8.33:
/esbuild/0.8.34:
dev: true
hasBin: true
requiresBuild: true
resolution:
integrity: sha512-2ms/P6Y9zJfopR9dKo2vHzhXKfGSNlquVVoVOF8YnhjuzZVrvManMVBPadBsR/t7jzIkRnwqvxrs7d4f3C3eyg==
integrity: sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ==
/escalade/3.1.1:
dev: true
engines:
@@ -9224,7 +9226,7 @@ packages:
engines:
node: '>=6'
resolution:
integrity: sha1-Z9Q7gmZKe1GR/ZEZEn6zAASKn9s=
integrity: sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ==
/is-path-inside/3.0.2:
engines:
node: '>=8'
@@ -11553,7 +11555,7 @@ packages:
engines:
node: '>=10'
resolution:
integrity: sha1-uy+Vpe2i7BaOySdOBqdHw+KQTSs=
integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==
/p-memoize/4.0.1:
dependencies:
mem: 6.1.1
@@ -13096,7 +13098,7 @@ packages:
dev: false
resolution:
integrity: sha1-UKmYnafJjCxh2tEZvJdHDvhSgSk=
/sinon/9.2.3:
/sinon/9.2.4:
dependencies:
'@sinonjs/commons': 1.8.2
'@sinonjs/fake-timers': 6.0.1
@@ -13106,7 +13108,7 @@ packages:
supports-color: 7.2.0
dev: true
resolution:
integrity: sha512-m+DyAWvqVHZtjnjX/nuShasykFeiZ+nPuEfD4G3gpvKGkXRhkF/6NSt2qN2FjZhfrcHXFzUzI+NLnk+42fnLEw==
integrity: sha512-zljcULZQsJxVra28qIAL6ow1Z9tpattkCTEJR4RBP3TGc00FcttsP5pK284Nas5WjMZU5Yzy3kAIp3B3KRf5Yg==
/sisteransi/1.0.5:
dev: true
resolution:
@@ -13685,7 +13687,7 @@ packages:
engines:
node: '>=8'
resolution:
integrity: sha1-vekrBb3+sVFugEycAK1FF38xMh4=
integrity: sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==
/tempy/0.6.0:
dependencies:
is-stream: 2.0.0
@@ -13707,7 +13709,7 @@ packages:
engines:
node: '>=10'
resolution:
integrity: sha1-TxkrPuMyiiaE0OP8XEkUJTlaq2U=
integrity: sha512-eLXG5B1G0mRPHmgH2WydPl5v4jH35qEn3y/rA/aahKhIa91Pn119SsU7n7v/433gtT9ONzC8ISvNHIh2JSTm0w==
/term-size/1.2.0:
dependencies:
execa: 0.7.0
@@ -14018,10 +14020,10 @@ packages:
resolution:
integrity: sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw==
/tslib/1.14.1:
dev: false
resolution:
integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
/tslib/1.9.0:
dev: true
resolution:
integrity: sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==
/tslint-config-standard/9.0.0:
@@ -14049,7 +14051,7 @@ packages:
integrity: sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==
/tsutils/3.19.1:
dependencies:
tslib: 1.9.0
tslib: 1.14.1
engines:
node: '>= 6'
peerDependencies:
@@ -14116,7 +14118,7 @@ packages:
engines:
node: '>=10'
resolution:
integrity: sha1-MkC4kaeLDerpENvrhlU+VSoUiGA=
integrity: sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==
/type-fest/0.18.1:
dev: true
engines: