fix: lockfile needs to be updated on change of neverBuiltDependencies

This commit is contained in:
Zoltan Kochan
2021-01-24 04:52:53 +02:00
parent 92450c9eda
commit 7578a5ad4b
3 changed files with 43 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
The lockfile needs to be updated when the value of neverBuiltDependencies changes.

View File

@@ -146,7 +146,11 @@ function toLockfileDependency (
if (pkg.hasBin) {
result['hasBin'] = true
}
if (opts.prevSnapshot) {
if (pkg.requiresBuild !== undefined) {
if (pkg.requiresBuild) {
result['requiresBuild'] = true
}
} else if (opts.prevSnapshot) {
if (opts.prevSnapshot.requiresBuild) {
result['requiresBuild'] = opts.prevSnapshot.requiresBuild
}
@@ -156,10 +160,6 @@ function toLockfileDependency (
} else if (pkg.prepare) {
result['prepare'] = true
result['requiresBuild'] = true
} else if (pkg.requiresBuild !== undefined) {
if (pkg.requiresBuild) {
result['requiresBuild'] = true
}
} else {
pendingRequiresBuilds.push(opts.depPath)
}

View File

@@ -458,3 +458,36 @@ test('selectively ignore scripts in some dependencies', async () => {
expect(await exists('node_modules/pre-and-postinstall-scripts-example/generated-by-postinstall.js')).toBeFalsy()
expect(await exists('node_modules/install-script-example/generated-by-install.js')).toBeTruthy()
})
test('lockfile is updated if neverBuiltDependencies is changed', async () => {
const project = prepareEmpty()
const manifest = await addDependenciesToPackage({},
['pre-and-postinstall-scripts-example', 'install-script-example'],
await testDefaults({ fastUnpack: false })
)
{
const lockfile = await project.readLockfile()
expect(lockfile.neverBuiltDependencies).toBeFalsy()
expect(lockfile.packages['/pre-and-postinstall-scripts-example/1.0.0'].requiresBuild).toBeTruthy()
expect(lockfile.packages['/install-script-example/1.0.0'].requiresBuild).toBeTruthy()
}
const neverBuiltDependencies = ['pre-and-postinstall-scripts-example']
manifest.pnpm = { neverBuiltDependencies }
await mutateModules([
{
buildIndex: 0,
manifest,
mutation: 'install',
rootDir: process.cwd(),
},
], await testDefaults())
{
const lockfile = await project.readLockfile()
expect(lockfile.neverBuiltDependencies).toStrictEqual(neverBuiltDependencies)
expect(lockfile.packages['/pre-and-postinstall-scripts-example/1.0.0'].requiresBuild).toBe(undefined)
expect(lockfile.packages['/install-script-example/1.0.0'].requiresBuild).toBeTruthy()
}
})