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

Commit

Permalink
Set INIT_CWD environ to cwd if not already set in environment
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 10, 2020
1 parent 3c373cf commit 7070885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const setEnvs = (config) => {
else
env.PREFIX = globalPrefix

env.INIT_CWD = env.INIT_CWD || process.cwd()

// if the key is the default value,
// if the environ is NOT the default value,
// set the environ
Expand Down
8 changes: 7 additions & 1 deletion test/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const setEnvs = require('../lib/set-envs.js')
const t = require('tap')
const defaults = require('./fixtures/defaults.js')
const { execPath } = process
const cwd = process.cwd()

t.test('set envs that are not defaults and not already in env', t => {
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
Expand Down Expand Up @@ -48,13 +50,15 @@ t.test('set envs that are not defaults and not already in env, array style', t =
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
INIT_CWD: '/some/other/path',
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
npm_execpath: require.main.filename,
npm_node_execpath: execPath,
}
const env = {}
// make sure it's sticky
const env = { INIT_CWD: '/some/other/path' }
const config = { list: [cliConf, envConf], env, defaults, execPath }
setEnvs(config)
t.strictSame(env, { ...extras }, 'no new environment vars to create')
Expand Down Expand Up @@ -84,6 +88,7 @@ t.test('set envs that are not defaults and not already in env, boolean edition',
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
PREFIX: undefined,
Expand Down Expand Up @@ -124,6 +129,7 @@ t.test('set PREFIX based on DESTDIR', t => {
const envConf = Object.create(d)
const cliConf = Object.create(envConf)
const extras = {
INIT_CWD: cwd,
HOME: undefined,
PREFIX: '/usr/local',
DESTDIR: '/some/dest',
Expand Down

0 comments on commit 7070885

Please sign in to comment.