Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate process.env-related logic to its own function #341

Merged
merged 2 commits into from Jul 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions index.js
Expand Up @@ -14,6 +14,16 @@ const {joinCommand, parseCommand} = require('./lib/command.js');

const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;

const getEnv = ({env: envOption, extendEnv, preferLocal, localDir}) => {
const env = extendEnv ? {...process.env, ...envOption} : envOption;

if (preferLocal) {
return npmRunPath.env({env, cwd: localDir});
}

return env;
};

const handleArgs = (file, args, options = {}) => {
const parsed = crossSpawn._parse(file, args, options);
file = parsed.command;
Expand All @@ -24,6 +34,7 @@ const handleArgs = (file, args, options = {}) => {
maxBuffer: DEFAULT_MAX_BUFFER,
buffer: true,
stripFinalNewline: true,
extendEnv: true,
preferLocal: false,
localDir: options.cwd || process.cwd(),
encoding: 'utf8',
Expand All @@ -33,19 +44,7 @@ const handleArgs = (file, args, options = {}) => {
windowsHide: true
};

if (options.extendEnv !== false) {
options.env = {
...process.env,
...options.env
};
}

if (options.preferLocal) {
options.env = npmRunPath.env({
...options,
cwd: options.localDir
});
}
options.env = getEnv(options);

options.stdio = normalizeStdio(options);

Expand Down