Skip to content

Commit df42412

Browse files
committed
fix: rebuild detection step
1 parent 0732e16 commit df42412

4 files changed

Lines changed: 44 additions & 16 deletions

File tree

lib/node-expat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const util = require('util')
44
const path = require('path')
5-
const expat = require('node-gyp-build')(path.join(__dirname, '..'))
5+
const expat = require(path.join(__dirname, '..', 'build', 'Release', 'node_expat.node'))
66
const Stream = require('stream').Stream
77

88
const Parser = function (encoding) {

package-lock.json

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"parsing"
1414
],
1515
"scripts": {
16-
"install": "node-gyp-build",
16+
"install": "node scripts/install.js",
1717
"rebuild": "node-gyp rebuild",
1818
"preversion": "npm test",
1919
"lint": "standard",
@@ -22,7 +22,6 @@
2222
"benchmark": "node ./benchmark.js"
2323
},
2424
"dependencies": {
25-
"node-gyp-build": "^4.8.4",
2625
"nan": "^2.25.0",
2726
"node-gyp": "^12.2.0"
2827
},

scripts/install.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
4+
const path = require('path')
5+
const { spawnSync } = require('child_process')
6+
7+
const bindingPath = path.join(__dirname, '..', 'build', 'Release', 'node_expat.node')
8+
9+
function bindingLoadsCleanly () {
10+
try {
11+
require(bindingPath)
12+
return true
13+
} catch (_) {
14+
return false
15+
}
16+
}
17+
18+
if (bindingLoadsCleanly()) {
19+
console.log('node-expat: existing binding loads on this runtime, skipping rebuild')
20+
process.exit(0)
21+
}
22+
23+
console.log('node-expat: binding missing or incompatible for this runtime, running node-gyp rebuild')
24+
25+
let nodeGypBin
26+
try {
27+
const nodeGypPkg = require('node-gyp/package.json')
28+
const binEntry = typeof nodeGypPkg.bin === 'string' ? nodeGypPkg.bin : nodeGypPkg.bin['node-gyp']
29+
nodeGypBin = path.join(path.dirname(require.resolve('node-gyp/package.json')), binEntry)
30+
} catch (_) {
31+
nodeGypBin = null
32+
}
33+
34+
const result = nodeGypBin
35+
? spawnSync(process.execPath, [nodeGypBin, 'rebuild'], { stdio: 'inherit' })
36+
: spawnSync(process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], {
37+
stdio: 'inherit',
38+
shell: process.platform === 'win32',
39+
})
40+
41+
process.exit(result.status == null ? 1 : result.status)

0 commit comments

Comments
 (0)