mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-31 13:32:18 -04:00
6
.changeset/allow-builds-pnpmfile-fix.md
Normal file
6
.changeset/allow-builds-pnpmfile-fix.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/cli-utils": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Fixed `allowBuilds` not working when set via `.pnpmfile.cjs` [#10516](https://github.com/pnpm/pnpm/issues/10516).
|
||||
@@ -116,4 +116,24 @@ function applyDerivedConfig (config: Config): void {
|
||||
delete config.hoistPattern
|
||||
delete config.publicHoistPattern
|
||||
}
|
||||
if (config.allowBuilds) {
|
||||
config.onlyBuiltDependencies ??= []
|
||||
config.ignoredBuiltDependencies ??= []
|
||||
const onlyBuiltSet = new Set(config.onlyBuiltDependencies)
|
||||
const ignoredBuiltSet = new Set(config.ignoredBuiltDependencies)
|
||||
for (const [packagePattern, build] of Object.entries(config.allowBuilds)) {
|
||||
switch (build) {
|
||||
case true:
|
||||
if (!onlyBuiltSet.has(packagePattern)) {
|
||||
config.onlyBuiltDependencies.push(packagePattern)
|
||||
}
|
||||
break
|
||||
case false:
|
||||
if (!ignoredBuiltSet.has(packagePattern)) {
|
||||
config.ignoredBuiltDependencies.push(packagePattern)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,3 +42,43 @@ test('hoist: false removes hoistPattern', async () => {
|
||||
expect(config.hoist).toBe(false)
|
||||
expect(config.hoistPattern).toBeUndefined()
|
||||
})
|
||||
|
||||
test('allowBuilds populates onlyBuiltDependencies and ignoredBuiltDependencies', async () => {
|
||||
prepare()
|
||||
|
||||
const config = await getConfig({
|
||||
allowBuilds: {
|
||||
'allowed-pkg': true,
|
||||
'another-allowed': true,
|
||||
'blocked-pkg': false,
|
||||
},
|
||||
}, {
|
||||
workspaceDir: '.',
|
||||
excludeReporter: false,
|
||||
rcOptionsTypes: {},
|
||||
})
|
||||
|
||||
expect(config.onlyBuiltDependencies).toContain('allowed-pkg')
|
||||
expect(config.onlyBuiltDependencies).toContain('another-allowed')
|
||||
expect(config.ignoredBuiltDependencies).toContain('blocked-pkg')
|
||||
})
|
||||
|
||||
test('allowBuilds does not add duplicates', async () => {
|
||||
prepare()
|
||||
|
||||
const config = await getConfig({
|
||||
onlyBuiltDependencies: ['already-allowed'],
|
||||
ignoredBuiltDependencies: ['already-blocked'],
|
||||
allowBuilds: {
|
||||
'already-allowed': true,
|
||||
'already-blocked': false,
|
||||
},
|
||||
}, {
|
||||
workspaceDir: '.',
|
||||
excludeReporter: false,
|
||||
rcOptionsTypes: {},
|
||||
})
|
||||
|
||||
expect(config.onlyBuiltDependencies).toEqual(['already-allowed'])
|
||||
expect(config.ignoredBuiltDependencies).toEqual(['already-blocked'])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user