Skip to content

Commit 43fb612

Browse files
committed
fix: opt out of node-gyp on install via gypfile:false
Dropping the no-op install script in #363 stopped Yarn Berry's YN0007 warning, but it let npm's publish-time normalization take over: with binding.gyp present in the dev tree (and excluded from the tarball) and no install/preinstall script, npm synthesizes "gypfile": true and "install": "node-gyp rebuild" into the published manifest. Consumers on npm then run node-gyp rebuild against a binding.gyp that isn't in the package and the install fails, which shipped broken in 5.16.0. Setting "gypfile": false suppresses that implicit hook while keeping the manifest free of lifecycle scripts, so both npm and Yarn Berry install the prebuilt binaries without a build step. The regression test now also pins gypfile:false alongside the no-lifecycle-scripts assertion. Fixes: #364 (review)
1 parent eab8480 commit 43fb612

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"main": "out/src/index.js",
1010
"types": "out/src/index.d.ts",
11+
"gypfile": false,
1112
"scripts": {
1213
"build:asan": "node-gyp configure build --jobs=max --address_sanitizer",
1314
"build:tsan": "node-gyp configure build --jobs=max --thread_sanitizer",

ts/test/test-no-build-scripts.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@ import * as fs from 'fs';
33
import * as path from 'path';
44

55
describe('package manifest', () => {
6+
const manifest = path.join(__dirname, '..', '..', 'package.json');
7+
const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'));
8+
69
it('declares no npm build lifecycle scripts (Yarn Berry YN0007)', () => {
7-
const manifest = path.join(__dirname, '..', '..', 'package.json');
8-
const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'));
910
const scripts = pkg.scripts || {};
1011
const hooks = ['preinstall', 'install', 'postinstall'];
1112
const present = hooks.filter(name => scripts[name] !== undefined);
1213
assert.deepStrictEqual(present, []);
1314
});
15+
16+
it('opts out of node-gyp on install via gypfile:false (npm implicit rebuild)', () => {
17+
// binding.gyp lives in the dev tree (excluded from the published tarball).
18+
// Without gypfile:false, npm's publish-time normalization synthesizes
19+
// "gypfile": true and "install": "node-gyp rebuild" into the registry
20+
// manifest, so consumers run node-gyp rebuild against a missing
21+
// binding.gyp and the install fails. Pinning gypfile:false suppresses
22+
// that hook while keeping the manifest free of lifecycle scripts.
23+
assert.strictEqual(pkg.gypfile, false);
24+
});
1425
});

0 commit comments

Comments
 (0)