Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow overriding npm_ env vars via env #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/make-spawn-args.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/* 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
try {
/* istanbul ignore next */
if (typeof require === 'function' && typeof require.resolve === 'function') {
npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
}
} catch (er) {
/* istanbul ignore next */
}

const makeSpawnArgs = options => {
const {
Expand All @@ -19,12 +27,15 @@ const makeSpawnArgs = options => {
const spawnEnv = setPATH(path, binPaths, {
// we need to at least save the PATH environment var
...process.env,
...env,
npm_package_json: resolve(path, 'package.json'),
npm_lifecycle_event: event,
npm_lifecycle_script: cmd,
npm_config_node_gyp,
...env,
})
/* istanbul ignore next */
if (typeof npm_config_node_gyp === 'string') {
spawnEnv.npm_config_node_gyp = npm_config_node_gyp
}

const spawnOpts = {
env: spawnEnv,
Expand Down