fix: write allow-build value to pnpm-workspace.yaml (#9404)

This commit is contained in:
btea
2025-04-14 17:43:03 +08:00
committed by GitHub
parent 17b7e9fbb3
commit 4d95e93040
6 changed files with 26 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": patch
pnpm: patch
---
If there is no pnpm related configuration in `package.json`, `onlyBuiltDependencies` will be written to `pnpm-workspace.yaml` file [#9404](https://github.com/pnpm/pnpm/pull/9404).

View File

@@ -7,9 +7,9 @@ import { prepareExecutionEnv } from '@pnpm/plugin-commands-env'
import { createOrConnectStoreController } from '@pnpm/store-connection-manager'
import pick from 'ramda/src/pick'
import renderHelp from 'render-help'
import { createProjectManifestWriter } from './createProjectManifestWriter'
import { type InstallCommandOptions } from './install'
import { installDeps } from './installDeps'
import { writeSettings } from '@pnpm/config.config-writer'
export function rcOptionsTypes (): Record<string, unknown> {
return pick([
@@ -250,10 +250,13 @@ export async function handler (
])).sort((a, b) => a.localeCompare(b))
if (opts.rootProjectManifestDir) {
opts.rootProjectManifest = opts.rootProjectManifest ?? {}
opts.rootProjectManifest.pnpm = opts.rootProjectManifest.pnpm ?? {}
opts.rootProjectManifest.pnpm.onlyBuiltDependencies = opts.onlyBuiltDependencies
const writeProjectManifest = await createProjectManifestWriter(opts.rootProjectManifestDir)
await writeProjectManifest(opts.rootProjectManifest)
await writeSettings({
...opts,
workspaceDir: opts.workspaceDir ?? opts.rootProjectManifestDir,
updatedSettings: {
onlyBuiltDependencies: opts.onlyBuiltDependencies,
},
})
}
}
return installDeps({

3
pnpm-lock.yaml generated
View File

@@ -6201,6 +6201,9 @@ importers:
'@pnpm/workspace.pkgs-graph':
specifier: workspace:*
version: link:../workspace/pkgs-graph
'@pnpm/workspace.read-manifest':
specifier: workspace:*
version: link:../workspace/read-manifest
'@pnpm/workspace.state':
specifier: workspace:*
version: link:../workspace/state

View File

@@ -133,6 +133,7 @@
"@pnpm/worker": "workspace:*",
"@pnpm/workspace.find-packages": "workspace:*",
"@pnpm/workspace.pkgs-graph": "workspace:*",
"@pnpm/workspace.read-manifest": "workspace:*",
"@pnpm/workspace.state": "workspace:*",
"@pnpm/write-project-manifest": "workspace:*",
"@types/cross-spawn": "catalog:",

View File

@@ -8,6 +8,7 @@ import loadJsonFile from 'load-json-file'
import writeYamlFile from 'write-yaml-file'
import { execPnpm, execPnpmSync, pnpmBinLocation } from '../utils'
import { getIntegrity } from '@pnpm/registry-mock'
import { readWorkspaceManifest } from '@pnpm/workspace.read-manifest'
const pkgRoot = path.join(__dirname, '..', '..')
const pnpmPkg = loadJsonFile.sync<PackageManifest>(path.join(pkgRoot, 'package.json'))
@@ -175,7 +176,7 @@ test('selectively allow scripts in some dependencies by onlyBuiltDependenciesFil
})
test('selectively allow scripts in some dependencies by --allow-build flag', async () => {
prepare({})
const project = prepare({})
execPnpmSync(['add', '--allow-build=@pnpm.e2e/install-script-example', '@pnpm.e2e/pre-and-postinstall-scripts-example@1.0.0', '@pnpm.e2e/install-script-example'])
expect(fs.existsSync('node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeFalsy()
@@ -183,7 +184,9 @@ test('selectively allow scripts in some dependencies by --allow-build flag', asy
expect(fs.existsSync('node_modules/@pnpm.e2e/install-script-example/generated-by-install.js')).toBeTruthy()
const manifest = loadJsonFile.sync<ProjectManifest>('package.json')
expect(manifest.pnpm?.onlyBuiltDependencies).toStrictEqual(['@pnpm.e2e/install-script-example'])
expect(manifest.pnpm?.onlyBuiltDependencies).toStrictEqual(undefined)
const modulesManifest = await readWorkspaceManifest(project.dir())
expect(modulesManifest?.onlyBuiltDependencies).toStrictEqual(['@pnpm.e2e/install-script-example'])
})
test('selectively allow scripts in some dependencies by --allow-build flag overlap ignoredBuiltDependencies', async () => {

View File

@@ -177,6 +177,9 @@
{
"path": "../workspace/pkgs-graph"
},
{
"path": "../workspace/read-manifest"
},
{
"path": "../workspace/state"
}