diff --git a/.changeset/clean-worms-fetch.md b/.changeset/clean-worms-fetch.md new file mode 100644 index 0000000000..511f770867 --- /dev/null +++ b/.changeset/clean-worms-fetch.md @@ -0,0 +1,5 @@ +--- +"@pnpm/resolve-dependencies": patch +--- + +The lockfile needs to be updated when the value of neverBuiltDependencies changes. diff --git a/packages/resolve-dependencies/src/updateLockfile.ts b/packages/resolve-dependencies/src/updateLockfile.ts index da3d3ae244..493301f844 100644 --- a/packages/resolve-dependencies/src/updateLockfile.ts +++ b/packages/resolve-dependencies/src/updateLockfile.ts @@ -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) } diff --git a/packages/supi/test/install/lifecycleScripts.ts b/packages/supi/test/install/lifecycleScripts.ts index fd34c973b1..f2724cffa1 100644 --- a/packages/supi/test/install/lifecycleScripts.ts +++ b/packages/supi/test/install/lifecycleScripts.ts @@ -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() + } +})