fix: git dependencies respect dangerouslyAllowAllBuilds (#10387)

close #10376
This commit is contained in:
Zoltan Kochan
2025-12-30 19:02:27 +01:00
committed by GitHub
parent b773199eb0
commit 82f461026a
4 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/builder.policy": minor
"pnpm": patch
---
Git dependencies with build scripts should respect the `dangerouslyAllowAllBuilds` settings [#10376](https://github.com/pnpm/pnpm/issues/10376).

View File

@@ -4,11 +4,13 @@ import fs from 'fs'
export function createAllowBuildFunction (
opts: {
dangerouslyAllowAllBuilds?: boolean
neverBuiltDependencies?: string[]
onlyBuiltDependencies?: string[]
onlyBuiltDependenciesFile?: string
}
): undefined | AllowBuild {
if (opts.dangerouslyAllowAllBuilds) return () => true
if (opts.onlyBuiltDependenciesFile != null || opts.onlyBuiltDependencies != null) {
const onlyBuiltDeps = opts.onlyBuiltDependencies ?? []
if (opts.onlyBuiltDependenciesFile) {

View File

@@ -55,3 +55,11 @@ it('should onlyBuiltDependencies set via a file and config', () => {
it('should return undefined if no policy is set', () => {
expect(createAllowBuildFunction({})).toBeUndefined()
})
it('should allow everything when dangerouslyAllowAllBuilds is true', () => {
const allowBuild = createAllowBuildFunction({
dangerouslyAllowAllBuilds: true,
})
expect(typeof allowBuild).toBe('function')
expect(allowBuild!('foo', '1.0.0')).toBeTruthy()
})

View File

@@ -299,3 +299,14 @@ test('the list of ignored builds is preserved after a repeat install', async ()
'esbuild@0.25.0',
])
})
test('git dependencies with preparation scripts should be installed when dangerouslyAllowAllBuilds is true', async () => {
prepare({})
await writeYamlFile('pnpm-workspace.yaml', { dangerouslyAllowAllBuilds: true })
// 'test-git-fetch' has a prepare script that builds the package.
const result = execPnpmSync(['add', 'https://github.com/pnpm/test-git-fetch.git#8b333f12d5357f4f25a654c305c826294cb073bf'])
expect(result.status).toBe(0)
expect(fs.existsSync('node_modules/test-git-fetch/dist/index.js')).toBeTruthy()
})