Skip to content

Commit

Permalink
fix: add back bin/node-gyp-bin/node-gyp files (#6941)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lukekarrys authored Oct 30, 2023
1 parent dfb6298 commit eacec5f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/configure text eol=lf

# our cmd scripts always need to be CRLF
/bin/*.cmd text eol=crlf
/bin/**/*.cmd text eol=crlf

# ignore all line endings in node_modules since we dont control that
/node_modules/** -text
Expand Down
6 changes: 6 additions & 0 deletions bin/node-gyp-bin/node-gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
if [ "x$npm_config_node_gyp" = "x" ]; then
node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$@"
else
"$npm_config_node_gyp" "$@"
fi
5 changes: 5 additions & 0 deletions bin/node-gyp-bin/node-gyp.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if not defined npm_config_node_gyp (
node "%~dp0\..\..\node_modules\node-gyp\bin\node-gyp.js" %*
) else (
node "%npm_config_node_gyp%" %*
)
30 changes: 24 additions & 6 deletions test/bin/windows-shims.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const t = require('tap')
const { spawnSync } = require('child_process')
const { resolve, join, extname, basename, sep } = require('path')
const { copyFileSync, readFileSync, chmodSync, readdirSync, rmSync } = require('fs')
const { copyFileSync, readFileSync, chmodSync, readdirSync, rmSync, statSync } = require('fs')
const Diff = require('diff')
const { sync: which } = require('which')
const { version } = require('../../package.json')

const ROOT = resolve(__dirname, '../..')
const BIN = join(ROOT, 'bin')
const SHIMS = readdirSync(BIN).reduce((acc, shim) => {
if (extname(shim) !== '.js') {
acc[shim] = readFileSync(join(BIN, shim), 'utf-8')
const readNonJsFiles = (dir) => readdirSync(dir).reduce((acc, shim) => {
const p = join(dir, shim)
if (extname(p) !== '.js' && !statSync(p).isDirectory()) {
acc[shim] = readFileSync(p, 'utf-8')
}
return acc
}, {})

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

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

t.test('node-gyp', t => {
// these files need to exist to avoid breaking yarn 1.x

for (const [key, file] of Object.entries(NODE_GYP)) {
t.match(file, /npm_config_node_gyp/, `${key} contains env var`)
t.match(
file,
/[\\/]\.\.[\\/]\.\.[\\/]node_modules[\\/]node-gyp[\\/]bin[\\/]node-gyp\.js/,
`${key} contains path`
)
}

t.end()
})

t.test('run shims', t => {
const path = t.testdir({
...SHIMS,
Expand Down

0 comments on commit eacec5f

Please sign in to comment.