Date: Fri, 7 Mar 2025 08:42:00 -0800
Subject: [PATCH 2/3] feat: use nodeGyp option (#230)
This allows for a `nodeGyp` option to be passed in to define where the
node-gyp bin is to run.
It also allows for the environment variable `npm_config_node_gyp` to
already be set, and not override it if it is.
This is an extension of #222
Closes: https://github.com/npm/cli/issues/2839
Co-author: @legobeat
---------
Co-authored-by: legobt <6wbvkn0j@anonaddy.me>
---
lib/make-spawn-args.js | 23 ++++++++++++++++++-----
lib/run-script-pkg.js | 22 ++++++++++++----------
test/make-spawn-args.js | 21 ++++++++++++++++++++-
3 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/lib/make-spawn-args.js b/lib/make-spawn-args.js
index 8a32d71..1c9f02c 100644
--- a/lib/make-spawn-args.js
+++ b/lib/make-spawn-args.js
@@ -1,21 +1,34 @@
/* eslint camelcase: "off" */
const setPATH = require('./set-path.js')
const { resolve } = require('path')
-const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
+
+let npm_config_node_gyp
const makeSpawnArgs = options => {
const {
+ args,
+ binPaths,
+ cmd,
+ env,
event,
+ nodeGyp,
path,
scriptShell = true,
- binPaths,
- env,
stdio,
- cmd,
- args,
stdioString,
} = options
+ if (nodeGyp) {
+ // npm already pulled this from env and passes it in to options
+ npm_config_node_gyp = nodeGyp
+ } else if (env.npm_config_node_gyp) {
+ // legacy mode for standalone user
+ npm_config_node_gyp = env.npm_config_node_gyp
+ } else {
+ // default
+ npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
+ }
+
const spawnEnv = setPATH(path, binPaths, {
// we need to at least save the PATH environment var
...process.env,
diff --git a/lib/run-script-pkg.js b/lib/run-script-pkg.js
index 9900c96..161caeb 100644
--- a/lib/run-script-pkg.js
+++ b/lib/run-script-pkg.js
@@ -7,18 +7,19 @@ const isServerPackage = require('./is-server-package.js')
const runScriptPkg = async options => {
const {
- event,
- path,
- scriptShell,
+ args = [],
binPaths = false,
env = {},
- stdio = 'pipe',
+ event,
+ nodeGyp,
+ path,
pkg,
- args = [],
- stdioString,
+ scriptShell,
// how long to wait for a process.kill signal
// only exposed here so that we can make the test go a bit faster.
signalTimeout = 500,
+ stdio = 'pipe',
+ stdioString,
} = options
const { scripts = {}, gypfile } = pkg
@@ -63,14 +64,15 @@ const runScriptPkg = async options => {
}
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
+ args,
+ binPaths,
+ cmd,
+ env: { ...env, ...packageEnvs(pkg) },
event,
+ nodeGyp,
path,
scriptShell,
- binPaths,
- env: { ...env, ...packageEnvs(pkg) },
stdio,
- cmd,
- args,
stdioString,
})
diff --git a/test/make-spawn-args.js b/test/make-spawn-args.js
index 83e90a0..110f28f 100644
--- a/test/make-spawn-args.js
+++ b/test/make-spawn-args.js
@@ -62,13 +62,15 @@ t.test('spawn args', async t => {
/.*/,
a => a.includes('echo test'),
e => {
- return e.env.test_fixture === 'a string'
+ return e.env.test_fixture === 'a string' &&
+ e.env.npm_config_node_gyp === '/test/path.js'
}
)
await t.resolves(() => runScript({
pkg,
path: testdir,
env: {
+ npm_config_node_gyp: '/test/path.js',
test_fixture: 'a string',
},
event: 'test',
@@ -76,6 +78,23 @@ t.test('spawn args', async t => {
t.ok(spawk.done())
})
+ await t.test('provided options.nodeGyp', async t => {
+ spawk.spawn(
+ /.*/,
+ a => a.includes('echo test'),
+ e => {
+ return e.env.npm_config_node_gyp === '/test/path.js'
+ }
+ )
+ await t.resolves(() => runScript({
+ pkg,
+ path: testdir,
+ nodeGyp: '/test/path.js',
+ event: 'test',
+ }))
+ t.ok(spawk.done())
+ })
+
await t.test('provided args', async t => {
spawk.spawn(
/.*/,
From 1aad88a8b6968b135e2087e1ed0e83bfd676f823 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Fri, 7 Mar 2025 08:51:38 -0800
Subject: [PATCH 3/3] chore: release 9.1.0 (#232)
:robot: I have created a release *beep* *boop*
---
## [9.1.0](https://github.com/npm/run-script/compare/v9.0.2...v9.1.0)
(2025-03-07)
### Features
*
[`21694f2`](https://github.com/npm/run-script/commit/21694f2098d27f3391a137a8885d20b34363faed)
[#230](https://github.com/npm/run-script/pull/230) use nodeGyp option
(#230) (@wraithgar, @legobeat)
### Chores
*
[`fea1ba3`](https://github.com/npm/run-script/commit/fea1ba381afd9ff695ade023634a16024ffdc1d9)
[#229](https://github.com/npm/run-script/pull/229) bump
@npmcli/template-oss from 4.23.4 to 4.23.5 (#229) (@dependabot[bot],
@npm-cli-bot)
---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
---
.release-please-manifest.json | 2 +-
CHANGELOG.md | 6 ++++++
package.json | 2 +-
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index c6101b7..9695e0e 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "9.0.2"
+ ".": "9.1.0"
}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fcf8b2..32d92d9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## [9.1.0](https://github.com/npm/run-script/compare/v9.0.2...v9.1.0) (2025-03-07)
+### Features
+* [`21694f2`](https://github.com/npm/run-script/commit/21694f2098d27f3391a137a8885d20b34363faed) [#230](https://github.com/npm/run-script/pull/230) use nodeGyp option (#230) (@wraithgar, @legobeat)
+### Chores
+* [`fea1ba3`](https://github.com/npm/run-script/commit/fea1ba381afd9ff695ade023634a16024ffdc1d9) [#229](https://github.com/npm/run-script/pull/229) bump @npmcli/template-oss from 4.23.4 to 4.23.5 (#229) (@dependabot[bot], @npm-cli-bot)
+
## [9.0.2](https://github.com/npm/run-script/compare/v9.0.1...v9.0.2) (2024-12-04)
### Dependencies
* [`74f7e7a`](https://github.com/npm/run-script/commit/74f7e7a87252099fdcb5f516f846061cb9731139) [#227](https://github.com/npm/run-script/pull/227) `node-gyp@11.0.0` (#227)
diff --git a/package.json b/package.json
index 51b78f1..6003a73 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@npmcli/run-script",
- "version": "9.0.2",
+ "version": "9.1.0",
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
"author": "GitHub Inc.",
"license": "ISC",
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy