Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Do not set the PREFIX environment variable (#13)
Browse files Browse the repository at this point in the history
* Restore npm v6 behavior with INIT_CWD

This should always be set to the npm cwd, even if already in the env.

Fix: npm/cli#2578

* Do not set the PREFIX environment variable

Fix: npm/cli#2398
  • Loading branch information
isaacs authored Feb 2, 2021
1 parent 4c6be4a commit bbebc66
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
6 changes: 0 additions & 6 deletions lib/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ const setEnvs = (config) => {
list: [cliConf, envConf],
} = config

const { DESTDIR } = env
if (platform !== 'win32' && DESTDIR && globalPrefix.indexOf(DESTDIR) === 0)
env.PREFIX = globalPrefix.substr(DESTDIR.length)
else
env.PREFIX = globalPrefix

env.INIT_CWD = process.cwd()

// if the key is the default value,
Expand Down
30 changes: 0 additions & 30 deletions test/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ t.test('set envs that are not defaults and not already in env', t => {
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
npm_execpath: require.main.filename,
npm_node_execpath: execPath,
}
Expand Down Expand Up @@ -56,7 +55,6 @@ t.test('set envs that are not defaults and not already in env, array style', t =
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
npm_execpath: require.main.filename,
npm_node_execpath: execPath,
}
Expand Down Expand Up @@ -95,7 +93,6 @@ t.test('set envs that are not defaults and not already in env, boolean edition',
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
npm_execpath: require.main.filename,
npm_node_execpath: execPath,
}
Expand Down Expand Up @@ -127,33 +124,6 @@ t.test('set envs that are not defaults and not already in env, boolean edition',
t.end()
})

t.test('set PREFIX based on DESTDIR', t => {
// also, don't set editor
const d = { ...defaults, editor: null }
const envConf = Object.create(d)
const cliConf = Object.create(envConf)
const extras = {
NODE,
INIT_CWD: cwd,
HOME: undefined,
PREFIX: '/usr/local',
DESTDIR: '/some/dest',
npm_execpath: require.main.filename,
npm_node_execpath: execPath,
}
const env = { DESTDIR: '/some/dest' }
const config = {
list: [cliConf, envConf],
env,
defaults: d,
globalPrefix: '/some/dest/usr/local',
execPath,
}
setEnvs(config)
t.strictSame(env, { ...extras })
t.end()
})

t.test('dont set npm_execpath if require.main.filename is not set', t => {
const { filename } = require.main
t.teardown(() => require.main.filename = filename)
Expand Down

0 comments on commit bbebc66

Please sign in to comment.