mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
fix(run): don't run pre/post script on recursive run (#3940)
close #3903
This commit is contained in:
5
.changeset/bright-kiwis-press.md
Normal file
5
.changeset/bright-kiwis-press.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
---
|
||||
|
||||
Do not run pre/post scripts by default on recursive run.
|
||||
@@ -13,6 +13,7 @@ import realpathMissing from 'realpath-missing'
|
||||
import existsInDir from './existsInDir'
|
||||
|
||||
export type RecursiveRunOpts = Pick<Config,
|
||||
| 'enablePrePostScripts'
|
||||
| 'unsafePerm'
|
||||
| 'rawConfig'
|
||||
| 'scriptShell'
|
||||
@@ -81,11 +82,19 @@ export default async (
|
||||
if (pnpPath) {
|
||||
lifecycleOpts.extraEnv = makeNodeRequireOption(pnpPath)
|
||||
}
|
||||
if (pkg.package.manifest.scripts[`pre${scriptName}`]) {
|
||||
if (
|
||||
opts.enablePrePostScripts &&
|
||||
pkg.package.manifest.scripts?.[`pre${scriptName}`] &&
|
||||
!pkg.package.manifest.scripts[scriptName].includes(`pre${scriptName}`)
|
||||
) {
|
||||
await runLifecycleHooks(`pre${scriptName}`, pkg.package.manifest, lifecycleOpts)
|
||||
}
|
||||
await runLifecycleHooks(scriptName, pkg.package.manifest, { ...lifecycleOpts, args: passedThruArgs })
|
||||
if (pkg.package.manifest.scripts[`post${scriptName}`]) {
|
||||
if (
|
||||
opts.enablePrePostScripts &&
|
||||
pkg.package.manifest.scripts?.[`post${scriptName}`] &&
|
||||
!pkg.package.manifest.scripts[scriptName].includes(`post${scriptName}`)
|
||||
) {
|
||||
await runLifecycleHooks(`post${scriptName}`, pkg.package.manifest, lifecycleOpts)
|
||||
}
|
||||
result.passes++
|
||||
|
||||
@@ -78,6 +78,79 @@ test('pnpm recursive run', async () => {
|
||||
const { default: outputs1 } = await import(path.resolve('output1.json'))
|
||||
const { default: outputs2 } = await import(path.resolve('output2.json'))
|
||||
|
||||
expect(outputs1).toStrictEqual(['project-1', 'project-2'])
|
||||
expect(outputs2).toStrictEqual(['project-1', 'project-3'])
|
||||
})
|
||||
|
||||
test('pnpm recursive run with enable-pre-post-scripts', 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 && node -e "process.stdout.write(\'project-1\')" | json-append ../output2.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',
|
||||
postbuild: 'node -e "process.stdout.write(\'project-2-postbuild\')" | json-append ../output1.json',
|
||||
prebuild: 'node -e "process.stdout.write(\'project-2-prebuild\')" | 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 ../output2.json',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project-0',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {},
|
||||
},
|
||||
])
|
||||
|
||||
const { allProjects, selectedProjectsGraph } = await readProjects(process.cwd(), [])
|
||||
await execa(pnpmBin, [
|
||||
'install',
|
||||
'-r',
|
||||
'--registry',
|
||||
REGISTRY,
|
||||
'--store-dir',
|
||||
path.resolve(DEFAULT_OPTS.storeDir),
|
||||
])
|
||||
await run.handler({
|
||||
...DEFAULT_OPTS,
|
||||
allProjects,
|
||||
dir: process.cwd(),
|
||||
enablePrePostScripts: true,
|
||||
recursive: true,
|
||||
selectedProjectsGraph,
|
||||
workspaceDir: process.cwd(),
|
||||
}, ['build'])
|
||||
|
||||
const { default: outputs1 } = await import(path.resolve('output1.json'))
|
||||
const { default: outputs2 } = await import(path.resolve('output2.json'))
|
||||
|
||||
expect(outputs1).toStrictEqual(['project-1', 'project-2-prebuild', 'project-2', 'project-2-postbuild'])
|
||||
expect(outputs2).toStrictEqual(['project-1', 'project-3'])
|
||||
})
|
||||
@@ -151,7 +224,7 @@ test('pnpm recursive run reversed', async () => {
|
||||
const { default: outputs1 } = await import(path.resolve('output1.json'))
|
||||
const { default: outputs2 } = await import(path.resolve('output2.json'))
|
||||
|
||||
expect(outputs1).toStrictEqual(['project-2-prebuild', 'project-2', 'project-2-postbuild', 'project-1'])
|
||||
expect(outputs1).toStrictEqual(['project-2', 'project-1'])
|
||||
expect(outputs2).toStrictEqual(['project-3', 'project-1'])
|
||||
})
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ test('run -r: pass the args to the command that is specfied in the build script'
|
||||
await fs.writeFile('project/args.json', '[]', 'utf8')
|
||||
await fs.writeFile('project/recordArgs.js', RECORD_ARGS_FILE, 'utf8')
|
||||
|
||||
await execPnpm(['run', '-r', 'foo', 'arg', '--', '--flag=true'])
|
||||
await execPnpm(['run', '-r', '--config.enable-pre-post-scripts', 'foo', 'arg', '--', '--flag=true'])
|
||||
|
||||
const { default: args } = await import(path.resolve('project/args.json'))
|
||||
expect(args).toStrictEqual([
|
||||
|
||||
Reference in New Issue
Block a user