From 4c6be4a66a3e89ae607e08172b8543b588a95fb5 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 2 Feb 2021 08:25:17 -0800 Subject: [PATCH] Restore npm v6 behavior with INIT_CWD (#12) This should always be set to the npm cwd, even if already in the env. Fix: https://github.com/npm/cli/issues/2578 --- lib/set-envs.js | 2 +- test/set-envs.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/set-envs.js b/lib/set-envs.js index 0893337..af6ea58 100644 --- a/lib/set-envs.js +++ b/lib/set-envs.js @@ -59,7 +59,7 @@ const setEnvs = (config) => { else env.PREFIX = globalPrefix - env.INIT_CWD = env.INIT_CWD || process.cwd() + env.INIT_CWD = process.cwd() // if the key is the default value, // if the environ is NOT the default value, diff --git a/test/set-envs.js b/test/set-envs.js index 3854d71..04c3012 100644 --- a/test/set-envs.js +++ b/test/set-envs.js @@ -53,14 +53,14 @@ t.test('set envs that are not defaults and not already in env, array style', t = const cliConf = Object.create(envConf) const extras = { NODE, - INIT_CWD: '/some/other/path', + INIT_CWD: cwd, EDITOR: 'vim', HOME: undefined, PREFIX: undefined, npm_execpath: require.main.filename, npm_node_execpath: execPath, } - // make sure it's sticky + // make sure it's not sticky const env = { INIT_CWD: '/some/other/path' } const config = { list: [cliConf, envConf], env, defaults, execPath } setEnvs(config)