Skip to content

Commit

Permalink
Patch node-pre-gyp on Windows
Browse files Browse the repository at this point in the history
Updated node-pre-gyp attempting to resolve this issue, but it is still
unresolved upstream. For now, hack in a patch. Once upstream fixes
this, we can update to the fixed version and drop this hack.

For more details, see mapbox/node-pre-gyp#715
  • Loading branch information
kadler committed Aug 21, 2024
1 parent 05defab commit 3a2b35b
Show file tree
Hide file tree
Showing 3 changed files with 249 additions and 539 deletions.
34 changes: 34 additions & 0 deletions .github/fix-node-pre-gyp-windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Patch node-pre-gyp to work around unresolved issue on Windows
// See https://github.com/mapbox/node-pre-gyp/issues/715
// Need to set shell: true on the spawn API on Windows now
const fs = require('node:fs/promises');

const path = 'node_modules/@mapbox/node-pre-gyp/lib/util/compile.js';

const before = " const cmd = cp.spawn(shell_cmd, final_args, { cwd: undefined, env: process.env, stdio: [0, 1, 2] });";
const after = " const cmd = cp.spawn(shell_cmd, final_args, { cwd: undefined, env: process.env, stdio: [0, 1, 2], shell: process.platform === 'win32' });";

(async function script() {
const fh = await fs.open(path, 'r+');

let i = 0;
let out = '';
for await (let line of fh.readLines({autoClose: false})) {
i++;;

if (i == 80) {
if (line != before) {
console.error("Patch failed!\n");
process.exit(1);
}
line = after;
}

out += line + "\n";
}

await fh.write(out, 0);

await fh.close();
})();

4 changes: 4 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
run: npm install -g node-gyp
- name: Install npm dependencies
run: npm ci --production
- name: Patch node-pre-gyp on Windows
if: ${{ startsWith(matrix.os, 'windows') }}
# https://github.com/mapbox/node-pre-gyp/issues/715
run: node .github/fix-node-pre-gyp-windows.js
- name: Build Binary
run: ./node_modules/.bin/node-pre-gyp rebuild --production
- name: Package Binary
Expand Down
Loading

0 comments on commit 3a2b35b

Please sign in to comment.