Skip to content
Myr

Extend environment by default - fixes #87 (#88)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sam Verschueren · committed by Sindre Sorhus · parent b82905c · Browse files · 4 files+35 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+35 added−1 removed

  • other:+35 added−1 removed

4 files+35 added−1 removed

added:fixtures/environment+4 added
1#!/usr/bin/env node2'use strict';3console.log(process.env.FOO);4console.log(process.env.BAR);
modified:index.js+4 added
14 unmodified lines
1516function handleArgs(cmd, args, opts) {17 let parsed;1819 if (opts && opts.env && opts.extendEnv !== false) {20 opts.env = Object.assign({}, process.env, opts.env);21 }2223 if (opts && opts.__winShell === true) {24 delete opts.__winShell;25 parsed = {26 command: cmd,
282 unmodified lines
modified:readme.md+8 added-1 removed
112 unmodified lines
113114Type: `Object`<br>115Default: `process.env`116117Environment key-value pairs.117Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.118119#### extendEnv120121Type: `boolean`<br>122Default: `true`123124Set to `false` if you don't want to extend the environment variables when providing the `env` property.125126#### argv0127128Type: `string`129
143 unmodified lines
modified:test.js+19 added
8 unmodified lines
9import tempfile from 'tempfile';10import m from './';1112process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;13process.env.FOO = 'foo';1415test('execa()', async t => {16 const {stdout} = await m('noop', ['foo']);17 t.is(stdout, 'foo');
400 unmodified lines
418 t.is(err.code, 'EPIPE');419 }420 });421}422423test('extend environment variables by default', async t => {424 const result = await m.stdout('environment', [], {env: {BAR: 'bar'}});425426 t.deepEqual(result.split('\n'), [427 'foo',428 'bar'429 ]);430});431432test('do not extend environment with `envExtend` option', async t => {433 const result = await m.stdout('environment', [], {env: {BAR: 'bar', PATH: process.env.PATH}, extendEnv: false});434435 t.deepEqual(result.split('\n'), [436 'undefined',437 'bar'438 ]);439});