fix: install dependencies execute preprepare and postprepare scripts (#8989)

* fix: install dependencies execute preprepare script

* chore: remove unnecessary code

* fix: postprepare should run

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
btea
2025-01-27 03:31:00 +08:00
committed by GitHub
parent 0858c0660d
commit 2b49ee77c7
5 changed files with 13 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/headless": patch
"@pnpm/core": patch
pnpm: patch
---
When running `pnpm install`, the `preprepare` and `postprepare` scripts of the project should be executed [#8989](https://github.com/pnpm/pnpm/pull/8989).

View File

@@ -179,6 +179,7 @@
"postbuild",
"postfoo",
"postpack",
"postprepare",
"postpublish",
"postrestart",
"postshrinkwrap",

View File

@@ -1268,7 +1268,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
}
}
const projectsToBeBuilt = projectsWithTargetDirs.filter(({ mutation }) => mutation === 'install') as ProjectToBeInstalled[]
await runLifecycleHooksConcurrently(['preinstall', 'install', 'postinstall', 'prepare'],
await runLifecycleHooksConcurrently(['preinstall', 'install', 'postinstall', 'preprepare', 'prepare', 'postprepare'],
projectsToBeBuilt,
opts.childConcurrency,
opts.scriptsOpts

View File

@@ -134,11 +134,13 @@ test('run install scripts in the current project', async () => {
install: `node -e "console.log('install-' + process.cwd())" | ${server.generateSendStdinScript()}`,
postinstall: `node -e "console.log('postinstall-' + process.cwd())" | ${server.generateSendStdinScript()}`,
preinstall: `node -e "console.log('preinstall-' + process.cwd())" | ${server.generateSendStdinScript()}`,
preprepare: `node -e "console.log('preprepare-' + process.cwd())" | ${server.generateSendStdinScript()}`,
postprepare: `node -e "console.log('postprepare-' + process.cwd())" | ${server.generateSendStdinScript()}`,
},
}, [], testDefaults({ fastUnpack: false }))
await install(manifest, testDefaults({ fastUnpack: false }))
expect(server.getLines()).toStrictEqual([`preinstall-${process.cwd()}`, `install-${process.cwd()}`, `postinstall-${process.cwd()}`])
expect(server.getLines()).toStrictEqual([`preinstall-${process.cwd()}`, `install-${process.cwd()}`, `postinstall-${process.cwd()}`, `preprepare-${process.cwd()}`, `postprepare-${process.cwd()}`])
expect(serverForDevPreinstall.getLines()).toStrictEqual([
// The pnpm:devPreinstall script runs twice in this test. Once for the
// initial "addDependenciesToPackage" test setup stage and again for the

View File

@@ -651,7 +651,7 @@ export async function headlessInstall (opts: HeadlessOptions): Promise<Installat
if (!opts.ignoreScripts && !opts.ignorePackageManifest) {
await runLifecycleHooksConcurrently(
['preinstall', 'install', 'postinstall', 'prepare'],
['preinstall', 'install', 'postinstall', 'preprepare', 'prepare', 'postprepare'],
projectsToBeBuilt,
opts.childConcurrency ?? 5,
scriptsOpts