diff --git a/.changeset/solid-suns-wear.md b/.changeset/solid-suns-wear.md new file mode 100644 index 0000000000..ba2d77264c --- /dev/null +++ b/.changeset/solid-suns-wear.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-installation": patch +"pnpm": patch +--- + +The parameter set by the `--allow-build` flag is written to `allowBuilds`. diff --git a/exec/build-commands/test/approveBuilds.test.ts b/exec/build-commands/test/approveBuilds.test.ts index 16192df72c..f84d43ae69 100644 --- a/exec/build-commands/test/approveBuilds.test.ts +++ b/exec/build-commands/test/approveBuilds.test.ts @@ -116,7 +116,8 @@ test('approve no builds', async () => { const manifest = readYamlFile(path.resolve('pnpm-workspace.yaml')) // eslint-disable-line expect(manifest.onlyBuiltDependencies).toBeUndefined() - expect(manifest.ignoredBuiltDependencies?.sort()).toStrictEqual([ + expect(manifest.ignoredBuiltDependencies).toBeUndefined() + expect(Object.keys(manifest.allowBuilds ?? {}).sort()).toStrictEqual([ '@pnpm.e2e/install-script-example', '@pnpm.e2e/pre-and-postinstall-scripts-example', ]) @@ -147,8 +148,10 @@ test("works when root project manifest doesn't exist in a workspace", async () = expect(readYamlFile(workspaceManifestFile)).toStrictEqual({ packages: ['packages/*'], - onlyBuiltDependencies: ['@pnpm.e2e/pre-and-postinstall-scripts-example'], - ignoredBuiltDependencies: ['@pnpm.e2e/install-script-example'], + allowBuilds: { + '@pnpm.e2e/install-script-example': false, + '@pnpm.e2e/pre-and-postinstall-scripts-example': true, + }, }) }) @@ -226,7 +229,9 @@ test('should approve builds with package.json that has no onlyBuiltDependencies expect(readYamlFile(workspaceManifestFile)).toStrictEqual({ packages: ['packages/*'], - onlyBuiltDependencies: ['@pnpm.e2e/pre-and-postinstall-scripts-example'], - ignoredBuiltDependencies: ['@pnpm.e2e/install-script-example'], + allowBuilds: { + '@pnpm.e2e/install-script-example': false, + '@pnpm.e2e/pre-and-postinstall-scripts-example': true, + }, }) }) diff --git a/pnpm/test/install/lifecycleScripts.ts b/pnpm/test/install/lifecycleScripts.ts index 877d3b29a9..850c3c55d9 100644 --- a/pnpm/test/install/lifecycleScripts.ts +++ b/pnpm/test/install/lifecycleScripts.ts @@ -186,7 +186,8 @@ test('selectively allow scripts in some dependencies by --allow-build flag', asy const manifest = loadJsonFileSync('package.json') expect(manifest.pnpm?.onlyBuiltDependencies).toBeUndefined() const modulesManifest = await readWorkspaceManifest(project.dir()) - expect(modulesManifest?.onlyBuiltDependencies).toStrictEqual(['@pnpm.e2e/install-script-example']) + expect(modulesManifest?.onlyBuiltDependencies).toBeUndefined() + expect(modulesManifest?.allowBuilds).toStrictEqual({ '@pnpm.e2e/install-script-example': true }) }) test('--allow-build flag should specify the package', async () => { diff --git a/workspace/manifest-writer/src/index.ts b/workspace/manifest-writer/src/index.ts index df449c99c7..cfacd3d463 100644 --- a/workspace/manifest-writer/src/index.ts +++ b/workspace/manifest-writer/src/index.ts @@ -47,7 +47,7 @@ export async function updateWorkspaceManifest (dir: string, opts: { // If the current manifest has allowBuilds, convert old fields to allowBuilds format const updatedFields = { ...opts.updatedFields } - if (manifest.allowBuilds != null && (updatedFields.onlyBuiltDependencies != null || updatedFields.ignoredBuiltDependencies != null)) { + if (manifest.allowBuilds != null || (manifest.onlyBuiltDependencies == null && manifest.ignoredBuiltDependencies == null)) { const allowBuilds: Record = { ...manifest.allowBuilds } // Convert onlyBuiltDependencies to allowBuilds with true values @@ -65,7 +65,9 @@ export async function updateWorkspaceManifest (dir: string, opts: { } // Update allowBuilds instead of the old fields - updatedFields.allowBuilds = allowBuilds + if (manifest.allowBuilds != null || Object.keys(allowBuilds).length > 0) { + updatedFields.allowBuilds = allowBuilds + } delete updatedFields.onlyBuiltDependencies delete updatedFields.ignoredBuiltDependencies } diff --git a/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts b/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts index 31a39995cf..6d45b3bcd6 100644 --- a/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts +++ b/workspace/manifest-writer/test/updateWorkspaceManifest.test.ts @@ -8,7 +8,7 @@ import { sync as writeYamlFile } from 'write-yaml-file' test('updateWorkspaceManifest adds a new setting', async () => { const dir = tempDir(false) const filePath = path.join(dir, WORKSPACE_MANIFEST_FILENAME) - writeYamlFile(filePath, { packages: ['*'] }) + writeYamlFile(filePath, { packages: ['*'], onlyBuiltDependencies: [] }) await updateWorkspaceManifest(dir, { updatedFields: { onlyBuiltDependencies: [] }, })