mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-31 19:18:19 -05:00
feat(exec): no need to use -- (#3492)
This commit is contained in:
5
.changeset/cyan-wolves-jog.md
Normal file
5
.changeset/cyan-wolves-jog.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": minor
|
||||
---
|
||||
|
||||
`--` is ignored, when it is passed in as the first parameter to the exec command. This is for backward compatibility.
|
||||
6
.changeset/light-needles-tap.md
Normal file
6
.changeset/light-needles-tap.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/parse-cli-args": minor
|
||||
---
|
||||
|
||||
A new option added: `escapeArgs`. `escapeArgs` is an array of arguments that stop arguments parsing.
|
||||
By default, everything after `--` is not parsed as key-value. This option allows to add new keywords to stop parsing.
|
||||
5
.changeset/tender-lamps-relax.md
Normal file
5
.changeset/tender-lamps-relax.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
There is no need to escape the command shell with `--`, when using the exec command. So just `pnpm exec rm -rf dir` instead of `pnpm exec -- rm -rf dir`.
|
||||
@@ -56,7 +56,8 @@
|
||||
"table@^6.0.3": "6.0.4",
|
||||
"js-yaml@^4.0.0": "npm:@zkochan/js-yaml@0.0.4",
|
||||
"lodash@<4.17.19": "^4.17.9",
|
||||
"hosted-git-info@<3.0.8": "^3.0.8"
|
||||
"hosted-git-info@<3.0.8": "^3.0.8",
|
||||
"nopt@5": "npm:@pnpm/nopt@^0.2.1"
|
||||
},
|
||||
"neverBuiltDependencies": [
|
||||
"core-js",
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/parse-cli-args#readme",
|
||||
"devDependencies": {
|
||||
"@types/nopt": "^3.0.29",
|
||||
"tempy": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pnpm/error": "workspace:2.0.0",
|
||||
"@pnpm/find-workspace-dir": "workspace:3.0.1",
|
||||
"didyoumean2": "^5.0.0",
|
||||
"nopt": "^5.0.0"
|
||||
"@pnpm/nopt": "^0.2.1",
|
||||
"didyoumean2": "^5.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import PnpmError from '@pnpm/error'
|
||||
import findWorkspaceDir from '@pnpm/find-workspace-dir'
|
||||
import nopt from '@pnpm/nopt'
|
||||
import didYouMean, { ReturnTypeEnums } from 'didyoumean2'
|
||||
import nopt from 'nopt'
|
||||
|
||||
const RECURSIVE_CMDS = new Set(['recursive', 'multi', 'm'])
|
||||
|
||||
@@ -22,6 +22,7 @@ export interface ParsedCliArgs {
|
||||
|
||||
export default async function parseCliArgs (
|
||||
opts: {
|
||||
escapeArgs?: string[]
|
||||
fallbackCommand?: string
|
||||
getCommandLongName: (commandName: string) => string | null
|
||||
getTypesByCommandName: (commandName: string) => object
|
||||
@@ -46,7 +47,8 @@ export default async function parseCliArgs (
|
||||
...opts.universalShorthands,
|
||||
},
|
||||
inputArgv,
|
||||
0
|
||||
0,
|
||||
{ escapeArgs: opts.escapeArgs }
|
||||
)
|
||||
|
||||
const recursiveCommandUsed = RECURSIVE_CMDS.has(noptExploratoryResults.argv.remain[0])
|
||||
@@ -92,7 +94,8 @@ export default async function parseCliArgs (
|
||||
...opts.shorthandsByCommandName[commandName],
|
||||
},
|
||||
inputArgv,
|
||||
0
|
||||
0,
|
||||
{ escapeArgs: opts.escapeArgs }
|
||||
)
|
||||
|
||||
if (opts.renamedOptions != null) {
|
||||
|
||||
@@ -245,3 +245,22 @@ test('--workspace-root fails if used outside of a workspace', async () => {
|
||||
expect(err).toBeTruthy()
|
||||
expect(err.code).toBe('ERR_PNPM_NOT_IN_WORKSPACE')
|
||||
})
|
||||
|
||||
test('everything after an escape arg is a parameter', async () => {
|
||||
const { params, options, cmd } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
escapeArgs: ['exec'],
|
||||
}, ['-r', 'exec', 'rm', '-rf', 'node_modules'])
|
||||
expect(cmd).toBe('exec')
|
||||
expect(options).toHaveProperty(['recursive'])
|
||||
expect(params).toStrictEqual(['rm', '-rf', 'node_modules'])
|
||||
})
|
||||
|
||||
test('everything after an escape arg is a parameter, even if it has a help option', async () => {
|
||||
const { params, cmd } = await parseCliArgs({
|
||||
...DEFAULT_OPTS,
|
||||
escapeArgs: ['exec'],
|
||||
}, ['exec', 'rm', '--help'])
|
||||
expect(cmd).toBe('exec')
|
||||
expect(params).toStrictEqual(['rm', '--help'])
|
||||
})
|
||||
|
||||
@@ -55,7 +55,7 @@ For options that may be used with `-r`, see "pnpm help recursive"',
|
||||
],
|
||||
},
|
||||
],
|
||||
usages: ['pnpm exec -- <command> [args...]'],
|
||||
usages: ['pnpm [-r] exec <command> [args...]'],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -69,6 +69,10 @@ export async function handler (
|
||||
} & Pick<Config, 'extraBinPaths' | 'lockfileDir' | 'dir' | 'recursive' | 'workspaceDir'>,
|
||||
params: string[]
|
||||
) {
|
||||
// For backward compatibility
|
||||
if (params[0] === '--') {
|
||||
params.shift()
|
||||
}
|
||||
const limitRun = pLimit(opts.workspaceConcurrency ?? 4)
|
||||
|
||||
const result = {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"@pnpm/lockfile-types": "workspace:3.0.0",
|
||||
"@pnpm/logger": "^4.0.0",
|
||||
"@pnpm/modules-yaml": "workspace:9.0.1",
|
||||
"@pnpm/nopt": "^0.2.1",
|
||||
"@pnpm/parse-cli-args": "workspace:4.2.2",
|
||||
"@pnpm/pick-registry-for-package": "workspace:2.0.1",
|
||||
"@pnpm/plugin-commands-audit": "workspace:4.1.5",
|
||||
@@ -63,7 +64,6 @@
|
||||
"@types/is-ci": "^3.0.0",
|
||||
"@types/is-windows": "^1.0.0",
|
||||
"@types/ncp": "^2.0.4",
|
||||
"@types/nopt": "^3.0.29",
|
||||
"@types/ramda": "0.27.39",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@types/which": "^2.0.0",
|
||||
@@ -87,7 +87,6 @@
|
||||
"load-json-file": "^6.2.0",
|
||||
"loud-rejection": "^2.2.0",
|
||||
"ncp": "^2.0.0",
|
||||
"nopt": "^5.0.0",
|
||||
"normalize-newline": "3.0.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"p-any": "3.0.0",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import nopt from 'nopt'
|
||||
import nopt from '@pnpm/nopt'
|
||||
import fromPairs from 'ramda/src/fromPairs'
|
||||
import omit from 'ramda/src/omit'
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ const RENAMED_OPTIONS = {
|
||||
export default async function parseCliArgs (inputArgv: string[]) {
|
||||
return parseCliArgsLib({
|
||||
fallbackCommand: 'run',
|
||||
escapeArgs: ['exec'],
|
||||
getCommandLongName: getCommandFullName,
|
||||
getTypesByCommandName: getCliOptionsTypes,
|
||||
renamedOptions: RENAMED_OPTIONS,
|
||||
|
||||
33
pnpm-lock.yaml
generated
33
pnpm-lock.yaml
generated
@@ -11,6 +11,7 @@ overrides:
|
||||
js-yaml@^4.0.0: npm:@zkochan/js-yaml@0.0.4
|
||||
lodash@<4.17.19: ^4.17.9
|
||||
hosted-git-info@<3.0.8: ^3.0.8
|
||||
nopt@5: npm:@pnpm/nopt@^0.2.1
|
||||
|
||||
importers:
|
||||
|
||||
@@ -1641,19 +1642,17 @@ importers:
|
||||
specifiers:
|
||||
'@pnpm/error': workspace:2.0.0
|
||||
'@pnpm/find-workspace-dir': workspace:3.0.1
|
||||
'@pnpm/nopt': ^0.2.1
|
||||
'@pnpm/parse-cli-args': 'link:'
|
||||
'@types/nopt': ^3.0.29
|
||||
didyoumean2: ^5.0.0
|
||||
nopt: ^5.0.0
|
||||
tempy: ^1.0.0
|
||||
dependencies:
|
||||
'@pnpm/error': link:../error
|
||||
'@pnpm/find-workspace-dir': link:../find-workspace-dir
|
||||
'@pnpm/nopt': 0.2.1
|
||||
didyoumean2: 5.0.0
|
||||
nopt: 5.0.0
|
||||
devDependencies:
|
||||
'@pnpm/parse-cli-args': 'link:'
|
||||
'@types/nopt': 3.0.29
|
||||
tempy: 1.0.1
|
||||
|
||||
packages/parse-wanted-dependency:
|
||||
@@ -2396,6 +2395,7 @@ importers:
|
||||
'@pnpm/lockfile-types': workspace:3.0.0
|
||||
'@pnpm/logger': ^4.0.0
|
||||
'@pnpm/modules-yaml': workspace:9.0.1
|
||||
'@pnpm/nopt': ^0.2.1
|
||||
'@pnpm/parse-cli-args': workspace:4.2.2
|
||||
'@pnpm/pick-registry-for-package': workspace:2.0.1
|
||||
'@pnpm/plugin-commands-audit': workspace:4.1.5
|
||||
@@ -2423,7 +2423,6 @@ importers:
|
||||
'@types/is-ci': ^3.0.0
|
||||
'@types/is-windows': ^1.0.0
|
||||
'@types/ncp': ^2.0.4
|
||||
'@types/nopt': ^3.0.29
|
||||
'@types/ramda': 0.27.39
|
||||
'@types/semver': ^7.3.4
|
||||
'@types/which': ^2.0.0
|
||||
@@ -2448,7 +2447,6 @@ importers:
|
||||
loud-rejection: ^2.2.0
|
||||
ncp: ^2.0.0
|
||||
node-gyp: ^8.0.0
|
||||
nopt: ^5.0.0
|
||||
normalize-newline: 3.0.0
|
||||
npm-run-all: ^4.1.5
|
||||
p-any: 3.0.0
|
||||
@@ -2490,6 +2488,7 @@ importers:
|
||||
'@pnpm/lockfile-types': link:../lockfile-types
|
||||
'@pnpm/logger': 4.0.0
|
||||
'@pnpm/modules-yaml': link:../modules-yaml
|
||||
'@pnpm/nopt': 0.2.1
|
||||
'@pnpm/parse-cli-args': link:../parse-cli-args
|
||||
'@pnpm/pick-registry-for-package': link:../pick-registry-for-package
|
||||
'@pnpm/plugin-commands-audit': link:../plugin-commands-audit
|
||||
@@ -2517,7 +2516,6 @@ importers:
|
||||
'@types/is-ci': 3.0.0
|
||||
'@types/is-windows': 1.0.0
|
||||
'@types/ncp': 2.0.4
|
||||
'@types/nopt': 3.0.29
|
||||
'@types/ramda': 0.27.39
|
||||
'@types/semver': 7.3.6
|
||||
'@types/which': 2.0.0
|
||||
@@ -2541,7 +2539,6 @@ importers:
|
||||
load-json-file: 6.2.0
|
||||
loud-rejection: 2.2.0
|
||||
ncp: 2.0.0
|
||||
nopt: 5.0.0
|
||||
normalize-newline: 3.0.0
|
||||
npm-run-all: 4.1.5
|
||||
p-any: 3.0.0
|
||||
@@ -4451,6 +4448,13 @@ packages:
|
||||
write-json-file: 4.3.0
|
||||
dev: true
|
||||
|
||||
/@pnpm/nopt/0.2.1:
|
||||
resolution: {integrity: sha512-zkgDE6q3Y6KeZPjqXCk/hRQ2t6iw9JXbdnYZghwpe/HR73e4VmV5JZ5QSFypmSd5Sx4+gjNfAqME5BVAOBCk9g==}
|
||||
engines: {node: '>=6'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
abbrev: 1.1.1
|
||||
|
||||
/@pnpm/package-is-installable/4.0.19_@pnpm+logger@3.2.3:
|
||||
resolution: {integrity: sha512-+NYzUDuiBtXUpfoNM1INjXOQs/7imE4FC4iLwkXJrtYtGFPyA39maW44sGQSAmpR1uYih29EcTNdbFZkYVYvFA==}
|
||||
engines: {node: '>=10.16'}
|
||||
@@ -4811,10 +4815,6 @@ packages:
|
||||
resolution: {integrity: sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==}
|
||||
dev: true
|
||||
|
||||
/@types/nopt/3.0.29:
|
||||
resolution: {integrity: sha1-8Z3z20yX7hRZonQAKDIKcdcJZM4=}
|
||||
dev: true
|
||||
|
||||
/@types/normalize-package-data/2.4.0:
|
||||
resolution: {integrity: sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==}
|
||||
dev: true
|
||||
@@ -10946,7 +10946,7 @@ packages:
|
||||
glob: 7.1.7
|
||||
graceful-fs: 4.2.6
|
||||
make-fetch-happen: 8.0.14
|
||||
nopt: 5.0.0
|
||||
nopt: /@pnpm/nopt/0.2.1
|
||||
npmlog: 4.1.2
|
||||
rimraf: 3.0.2
|
||||
semver: 7.3.5
|
||||
@@ -10984,13 +10984,6 @@ packages:
|
||||
dependencies:
|
||||
abbrev: 1.1.1
|
||||
|
||||
/nopt/5.0.0:
|
||||
resolution: {integrity: sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==}
|
||||
engines: {node: '>=6'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
abbrev: 1.1.1
|
||||
|
||||
/normalize-newline/3.0.0:
|
||||
resolution: {integrity: sha1-HL6oBKukNgAfg5OKsh7AOdaa6dM=}
|
||||
engines: {node: '>=4'}
|
||||
|
||||
Reference in New Issue
Block a user