mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
13
.changeset/fresh-moles-switch.md
Normal file
13
.changeset/fresh-moles-switch.md
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
Added `--reverse` option support to `pnpm exec` [#3984](https://github.com/pnpm/pnpm/issues/3972).
|
||||
|
||||
Usage example:
|
||||
|
||||
```
|
||||
pnpm --reverse -r exec pwd
|
||||
```
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"test-with-preview": "ts-node test",
|
||||
"_test": "jest",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"start": "pnpm tsc --watch",
|
||||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix"
|
||||
},
|
||||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/config",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"_test": "jest",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"prepublishOnly": "pnpm run compile",
|
||||
"start": "pnpm tsc --watch",
|
||||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix"
|
||||
},
|
||||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/parse-cli-args",
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7778 pnpm run test:e2e",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"prepublishOnly": "pnpm run compile",
|
||||
"start": "pnpm tsc --watch",
|
||||
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix"
|
||||
},
|
||||
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/plugin-commands-script-runners",
|
||||
|
||||
@@ -35,6 +35,7 @@ export function rcOptionsTypes () {
|
||||
export const cliOptionsTypes = () => ({
|
||||
...rcOptionsTypes(),
|
||||
recursive: Boolean,
|
||||
reverse: Boolean,
|
||||
})
|
||||
|
||||
export function help () {
|
||||
@@ -66,6 +67,7 @@ export async function handler (
|
||||
bail?: boolean
|
||||
unsafePerm?: boolean
|
||||
rawConfig: object
|
||||
reverse?: boolean
|
||||
sort?: boolean
|
||||
workspaceConcurrency?: number
|
||||
} & Pick<Config, 'extraBinPaths' | 'lockfileDir' | 'dir' | 'recursive' | 'workspaceDir'>,
|
||||
@@ -87,6 +89,9 @@ export async function handler (
|
||||
chunks = opts.sort
|
||||
? sortPackages(opts.selectedProjectsGraph)
|
||||
: [Object.keys(opts.selectedProjectsGraph).sort()]
|
||||
if (opts.reverse) {
|
||||
chunks = chunks.reverse()
|
||||
}
|
||||
} else {
|
||||
chunks = [[opts.dir]]
|
||||
const project = await tryReadProjectManifest(opts.dir)
|
||||
|
||||
@@ -64,6 +64,7 @@ export function cliOptionsTypes () {
|
||||
], allTypes),
|
||||
...IF_PRESENT_OPTION,
|
||||
recursive: Boolean,
|
||||
reverse: Boolean,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,68 @@ test('pnpm recursive exec --no-sort', async () => {
|
||||
expect(outputs).toStrictEqual(['a-dependent', 'b-dependency'])
|
||||
})
|
||||
|
||||
test('pnpm recursive exec --reverse', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'json-append': '1',
|
||||
},
|
||||
scripts: {
|
||||
build: 'node -e "process.stdout.write(\'project-1\')" | json-append ../output1.json',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project-2',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'json-append': '1',
|
||||
'project-1': '1',
|
||||
},
|
||||
scripts: {
|
||||
build: 'node -e "process.stdout.write(\'project-2\')" | json-append ../output1.json',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project-3',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
'json-append': '1',
|
||||
'project-1': '1',
|
||||
},
|
||||
scripts: {
|
||||
build: 'node -e "process.stdout.write(\'project-3\')" | json-append ../output1.json',
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
const { selectedProjectsGraph } = await readProjects(process.cwd(), [])
|
||||
await execa(pnpmBin, [
|
||||
'install',
|
||||
'-r',
|
||||
'--registry',
|
||||
REGISTRY,
|
||||
'--store-dir',
|
||||
path.resolve(DEFAULT_OPTS.storeDir),
|
||||
])
|
||||
await exec.handler({
|
||||
...DEFAULT_OPTS,
|
||||
dir: process.cwd(),
|
||||
selectedProjectsGraph,
|
||||
recursive: true,
|
||||
sort: true,
|
||||
reverse: true,
|
||||
}, ['npm', 'run', 'build'])
|
||||
|
||||
const { default: outputs1 } = await import(path.resolve('output1.json'))
|
||||
|
||||
expect(outputs1).toStrictEqual(['project-2', 'project-3', 'project-1'])
|
||||
})
|
||||
|
||||
test('pnpm exec on single project', async () => {
|
||||
prepare({})
|
||||
|
||||
|
||||
@@ -15,3 +15,6 @@ ${COMPATIBILITY_PAGE}`)
|
||||
}
|
||||
|
||||
require('../dist/pnpm.cjs')
|
||||
|
||||
// if you want to debug at your local env, you can use this
|
||||
// require('../lib/pnpm')
|
||||
Reference in New Issue
Block a user