feat!: don't execute pre/post scripts automatically (#3285)

close #2891
This commit is contained in:
Zoltan Kochan
2021-03-27 14:58:38 +02:00
committed by GitHub
parent aa2fcfa9a6
commit 34338d2d05
4 changed files with 11 additions and 44 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": major
---
Arbitrary pre/post hooks for user-defined scripts (such as `prestart`) are not executed automatically.

View File

@@ -171,13 +171,7 @@ so you may run "pnpm -w ${scriptName}"`,
lifecycleOpts.extraEnv = makeNodeRequireOption(pnpPath)
}
try {
if (manifest.scripts?.[`pre${scriptName}`]) {
await runLifecycleHooks(`pre${scriptName}`, manifest, lifecycleOpts)
}
await runLifecycleHooks(scriptName, manifest, { ...lifecycleOpts, args: passedThruArgs })
if (manifest.scripts?.[`post${scriptName}`]) {
await runLifecycleHooks(`post${scriptName}`, manifest, lifecycleOpts)
}
} catch (err) {
if (opts.bail !== false) {
throw err

View File

@@ -84,11 +84,7 @@ test('run: pass the args to the command that is specfied in the build script', a
}, ['foo', 'arg', '--flag=true', '--help', '-h'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
[],
['arg', '--flag=true', '--help', '-h'],
[],
])
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
})
test('run: pass the args to the command that is specfied in the build script of a package.yaml manifest', async () => {
@@ -109,11 +105,7 @@ test('run: pass the args to the command that is specfied in the build script of
}, ['foo', 'arg', '--flag=true', '--help', '-h'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
[],
['arg', '--flag=true', '--help', '-h'],
[],
])
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
})
test('test: pass the args to the command that is specfied in the build script of a package.yaml manifest', async () => {
@@ -134,11 +126,7 @@ test('test: pass the args to the command that is specfied in the build script of
}, ['arg', '--flag=true', '--help', '-h'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
[],
['arg', '--flag=true', '--help', '-h'],
[],
])
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
})
test('run start: pass the args to the command that is specfied in the build script of a package.yaml manifest', async () => {
@@ -159,11 +147,7 @@ test('run start: pass the args to the command that is specfied in the build scri
}, ['start', 'arg', '--flag=true', '--help', '-h'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
[],
['arg', '--flag=true', '--help', '-h'],
[],
])
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
})
test('run stop: pass the args to the command that is specfied in the build script of a package.yaml manifest', async () => {
@@ -184,11 +168,7 @@ test('run stop: pass the args to the command that is specfied in the build scrip
}, ['stop', 'arg', '--flag=true', '--help', '-h'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
[],
['arg', '--flag=true', '--help', '-h'],
[],
])
expect(args).toStrictEqual([['arg', '--flag=true', '--help', '-h']])
})
test('restart: run stop, restart and start', async () => {
@@ -217,15 +197,9 @@ test('restart: run stop, restart and start', async () => {
const { default: scriptsRan } = await import(path.resolve('output.json'))
expect(scriptsRan).toStrictEqual([
'prestop',
'stop',
'poststop',
'prerestart',
'restart',
'postrestart',
'prestart',
'start',
'poststart',
])
})

View File

@@ -56,8 +56,6 @@ test('install-test: install dependencies and runs tests', async () => {
'json-append': '1',
},
scripts: {
posttest: 'node -e "process.stdout.write(\'posttest\')" | json-append ./output.json',
pretest: 'node -e "process.stdout.write(\'pretest\')" | json-append ./output.json',
test: 'node -e "process.stdout.write(\'test\')" | json-append ./output.json',
},
}, { manifestFormat: 'JSON5' })
@@ -65,11 +63,7 @@ test('install-test: install dependencies and runs tests', async () => {
await execPnpm(['install-test'])
const { default: scriptsRan } = await import(path.resolve('output.json'))
expect(scriptsRan).toStrictEqual([
'pretest',
'test',
'posttest',
])
expect(scriptsRan).toStrictEqual(['test'])
})
test('silent run only prints the output of the child process', async () => {