Skip to content

Commit eacec5f

Browse files
authoredOct 30, 2023
fix: add back bin/node-gyp-bin/node-gyp files (#6941)
This was an unintended breaking change as part of #6554. The `node-gyp` bin files are not used by the CLI directly but they are relied on by other tooling. This partially reverts commit 3a7378d.
1 parent dfb6298 commit eacec5f

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed
 

‎.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/configure text eol=lf
88

99
# our cmd scripts always need to be CRLF
10-
/bin/*.cmd text eol=crlf
10+
/bin/**/*.cmd text eol=crlf
1111

1212
# ignore all line endings in node_modules since we dont control that
1313
/node_modules/** -text

‎bin/node-gyp-bin/node-gyp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
if [ "x$npm_config_node_gyp" = "x" ]; then
3+
node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$@"
4+
else
5+
"$npm_config_node_gyp" "$@"
6+
fi

‎bin/node-gyp-bin/node-gyp.cmd

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if not defined npm_config_node_gyp (
2+
node "%~dp0\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
3+
) else (
4+
node "%npm_config_node_gyp%" %*
5+
)

‎test/bin/windows-shims.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
const t = require('tap')
22
const { spawnSync } = require('child_process')
33
const { resolve, join, extname, basename, sep } = require('path')
4-
const { copyFileSync, readFileSync, chmodSync, readdirSync, rmSync } = require('fs')
4+
const { copyFileSync, readFileSync, chmodSync, readdirSync, rmSync, statSync } = require('fs')
55
const Diff = require('diff')
66
const { sync: which } = require('which')
77
const { version } = require('../../package.json')
88

9-
const ROOT = resolve(__dirname, '../..')
10-
const BIN = join(ROOT, 'bin')
11-
const SHIMS = readdirSync(BIN).reduce((acc, shim) => {
12-
if (extname(shim) !== '.js') {
13-
acc[shim] = readFileSync(join(BIN, shim), 'utf-8')
9+
const readNonJsFiles = (dir) => readdirSync(dir).reduce((acc, shim) => {
10+
const p = join(dir, shim)
11+
if (extname(p) !== '.js' && !statSync(p).isDirectory()) {
12+
acc[shim] = readFileSync(p, 'utf-8')
1413
}
1514
return acc
1615
}, {})
1716

17+
const ROOT = resolve(__dirname, '../..')
18+
const BIN = join(ROOT, 'bin')
19+
const SHIMS = readNonJsFiles(BIN)
20+
const NODE_GYP = readNonJsFiles(join(BIN, 'node-gyp-bin'))
1821
const SHIM_EXTS = [...new Set(Object.keys(SHIMS).map(p => extname(p)))]
1922

2023
// windows requires each segment of a command path to be quoted when using shell: true
@@ -63,6 +66,21 @@ t.test('shim contents', t => {
6366
})
6467
})
6568

69+
t.test('node-gyp', t => {
70+
// these files need to exist to avoid breaking yarn 1.x
71+
72+
for (const [key, file] of Object.entries(NODE_GYP)) {
73+
t.match(file, /npm_config_node_gyp/, `${key} contains env var`)
74+
t.match(
75+
file,
76+
/[\\/]\.\.[\\/]\.\.[\\/]node_modules[\\/]node-gyp[\\/]bin[\\/]node-gyp\.js/,
77+
`${key} contains path`
78+
)
79+
}
80+
81+
t.end()
82+
})
83+
6684
t.test('run shims', t => {
6785
const path = t.testdir({
6886
...SHIMS,

0 commit comments

Comments
 (0)
Please sign in to comment.