From bbebc668888f71dba57959682364b6ff26ff4fac Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 2 Feb 2021 08:27:26 -0800 Subject: [PATCH] Do not set the PREFIX environment variable (#13) * Restore npm v6 behavior with INIT_CWD This should always be set to the npm cwd, even if already in the env. Fix: https://github.com/npm/cli/issues/2578 * Do not set the PREFIX environment variable Fix: https://github.com/npm/cli/issues/2398 --- lib/set-envs.js | 6 ------ test/set-envs.js | 30 ------------------------------ 2 files changed, 36 deletions(-) diff --git a/lib/set-envs.js b/lib/set-envs.js index af6ea58..36d3714 100644 --- a/lib/set-envs.js +++ b/lib/set-envs.js @@ -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, diff --git a/test/set-envs.js b/test/set-envs.js index 04c3012..9d373e5 100644 --- a/test/set-envs.js +++ b/test/set-envs.js @@ -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, } @@ -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, } @@ -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, } @@ -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)