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: $npm_execpath always points to npm, even when running npx #6762

Merged
merged 7 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,6 @@ Object {
"nodeBin": "{NODE}",
"nodeVersion": "2.2.2",
"noProxy": "",
"npmBin": "{CWD}/{TESTDIR}/docs.js",
"npmCommand": "version",
"npmVersion": "3.3.3",
"npxCache": "{CWD}/cache/_npx",
Expand Down
7 changes: 0 additions & 7 deletions workspaces/config/lib/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ const flatten = (obj, flat = {}) => {
flat[key] = val
}
}

// XXX make this the bin/npm-cli.js file explicitly instead
// otherwise using npm programmatically is a bit of a pain.
flat.npmBin = require.main ? require.main.filename
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
: /* istanbul ignore next - not configurable property */ undefined
flat.nodeBin = process.env.NODE || process.execPath

return flat
}

Expand Down
3 changes: 3 additions & 0 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Config {
this.defaults = defaults

this.npmPath = npmPath
this.npmBin = join(this.npmPath, 'bin/npm-cli.js')
this.argv = argv
this.env = env
this.execPath = execPath
Expand Down Expand Up @@ -231,6 +232,8 @@ class Config {
for (const { data } of this.data.values()) {
this.#flatten(data, this.#flatOptions)
}
this.#flatOptions.nodeBin = process.env.NODE || this.execPath
rotu marked this conversation as resolved.
Show resolved Hide resolved
this.#flatOptions.npmBin = this.npmBin
process.emit('timeEnd', 'config:load:flatten')

return this.#flatOptions
Expand Down
5 changes: 1 addition & 4 deletions workspaces/config/lib/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ const setEnvs = (config) => {
if (cliConf['node-options']) {
env.NODE_OPTIONS = cliConf['node-options']
}

if (require.main && require.main.filename) {
env.npm_execpath = require.main.filename
}
env.npm_execpath = config.npmBin
env.NODE = env.npm_node_execpath = config.execPath
rotu marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading