Skip to content

Commit d389a45

Browse files
authored
feat: support pnpm v11 and allowBuilds (#3)
1 parent 8f6bd82 commit d389a45

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

pnpmfile.cjs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
module.exports = {
22
hooks: {
33
updateConfig (config) {
4-
if (config.onlyBuiltDependencies == null) {
5-
config.onlyBuiltDependencies = []
6-
}
4+
const pnpmMajor = parseInt(config.packageManager?.version?.split('.')[0] ?? '0', 10)
5+
const useAllowBuilds = pnpmMajor >= 11
76
const defaultAllowed = require('./allow.json')
8-
if (!config.ignoredBuiltDependencies?.length) {
9-
config.onlyBuiltDependencies.push(...defaultAllowed)
10-
} else {
11-
const ignored = new Set(config.ignoredBuiltDependencies)
7+
if (useAllowBuilds) {
8+
if (config.allowBuilds == null) {
9+
config.allowBuilds = {}
10+
}
1211
for (const allowed of defaultAllowed) {
13-
if (!ignored.has(allowed)) {
14-
config.onlyBuiltDependencies.push(allowed)
12+
if (config.allowBuilds[allowed] == null) {
13+
config.allowBuilds[allowed] = true
14+
}
15+
}
16+
} else {
17+
if (config.onlyBuiltDependencies == null) {
18+
config.onlyBuiltDependencies = []
19+
}
20+
if (!config.ignoredBuiltDependencies?.length) {
21+
config.onlyBuiltDependencies.push(...defaultAllowed)
22+
} else {
23+
const ignored = new Set(config.ignoredBuiltDependencies)
24+
for (const allowed of defaultAllowed) {
25+
if (!ignored.has(allowed)) {
26+
config.onlyBuiltDependencies.push(allowed)
27+
}
1528
}
1629
}
1730
}

test.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,42 @@ test('TRUSTED_PACKAGE_NAMES', () => {
88
assert.equal(typeof TRUSTED_PACKAGE_NAMES[0], 'string')
99
})
1010

11-
test('do not reenable dependency builds', () => {
11+
test('populates onlyBuiltDependencies for pnpm < 11', () => {
1212
const config = {
13+
packageManager: { version: '10.28.1' },
14+
}
15+
pnpmfile.hooks.updateConfig(config)
16+
assert(config.onlyBuiltDependencies.includes('@apollo/rover'))
17+
assert.equal(config.allowBuilds, undefined)
18+
})
19+
20+
test('do not reenable dependency builds for pnpm < 11', () => {
21+
const config = {
22+
packageManager: { version: '10.28.1' },
1323
ignoredBuiltDependencies: ['esbuild'],
1424
}
1525
pnpmfile.hooks.updateConfig(config)
1626
assert(!config.onlyBuiltDependencies.includes('esbuild'))
1727
assert(config.onlyBuiltDependencies.includes('@apollo/rover'))
1828
})
29+
30+
test('populates allowBuilds for pnpm >= 11', () => {
31+
const config = {
32+
packageManager: { version: '11.0.0' },
33+
}
34+
pnpmfile.hooks.updateConfig(config)
35+
assert.equal(typeof config.allowBuilds, 'object')
36+
assert(!Array.isArray(config.allowBuilds))
37+
assert.equal(config.allowBuilds['@apollo/rover'], true)
38+
assert.equal(config.onlyBuiltDependencies, undefined)
39+
})
40+
41+
test('do not reenable dependency builds for pnpm >= 11', () => {
42+
const config = {
43+
packageManager: { version: '11.0.0' },
44+
allowBuilds: { esbuild: false },
45+
}
46+
pnpmfile.hooks.updateConfig(config)
47+
assert.equal(config.allowBuilds.esbuild, false)
48+
assert.equal(config.allowBuilds['@apollo/rover'], true)
49+
})

0 commit comments

Comments
 (0)