mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: do not run node-gyp rebuild if preinstall lifecycle script is present (#7206)
This commit is contained in:
6
.changeset/swift-ducks-talk.md
Normal file
6
.changeset/swift-ducks-talk.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/lifecycle": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Do not run node-gyp rebuild if `preinstall` lifecycle script is present [#7206](https://github.com/pnpm/pnpm/pull/7206).
|
||||
@@ -27,7 +27,7 @@ export async function runPostinstallHooks (
|
||||
pkg.scripts = {}
|
||||
}
|
||||
|
||||
if (!pkg.scripts.install) {
|
||||
if (!pkg.scripts.install && !pkg.scripts.preinstall) {
|
||||
await checkBindingGyp(opts.pkgRoot, pkg.scripts)
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ export async function runPostinstallHooks (
|
||||
}
|
||||
|
||||
/**
|
||||
* Run node-gyp when binding.gyp is available. Only do this when there's no
|
||||
* `install` script (see `npm help scripts`).
|
||||
* Run node-gyp when binding.gyp is available. Only do this when there are no
|
||||
* `install` and `preinstall` scripts (see `npm help scripts`).
|
||||
*/
|
||||
async function checkBindingGyp (
|
||||
root: string,
|
||||
|
||||
8
exec/lifecycle/test/fixtures/gyp-with-preinstall/binding.gyp
vendored
Normal file
8
exec/lifecycle/test/fixtures/gyp-with-preinstall/binding.gyp
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "binding",
|
||||
"sources": [ "binding.cc" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
exec/lifecycle/test/fixtures/gyp-with-preinstall/package.json
vendored
Normal file
7
exec/lifecycle/test/fixtures/gyp-with-preinstall/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "gyp-with-preinstall",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"preinstall": "node -e \"process.stdout.write('preinstall')\" | json-append output.json"
|
||||
}
|
||||
}
|
||||
@@ -84,3 +84,18 @@ test('runLifecycleHook() should throw an error while missing script start or fil
|
||||
})
|
||||
).rejects.toThrow(new PnpmError('NO_SCRIPT_OR_SERVER', 'Missing script start or file server.js'))
|
||||
})
|
||||
|
||||
test('preinstall script does not trigger node-gyp rebuild', async () => {
|
||||
const pkgRoot = f.find('gyp-with-preinstall')
|
||||
await rimraf(path.join(pkgRoot, 'output.json'))
|
||||
await runPostinstallHooks({
|
||||
depPath: '/gyp-with-preinstall/1.0.0',
|
||||
optional: false,
|
||||
pkgRoot,
|
||||
rawConfig: {},
|
||||
rootModulesDir,
|
||||
unsafePerm: true,
|
||||
})
|
||||
|
||||
expect(loadJsonFile.sync(path.join(pkgRoot, 'output.json'))).toStrictEqual(['preinstall'])
|
||||
})
|
||||
Reference in New Issue
Block a user