Fix issue where rc file option was always defined

- Fix signal termination bug by changing strict undefined checks to
also include null
This commit is contained in:
Todd Bluhm 2019-05-04 04:37:10 -05:00
parent 0523d994be
commit 86edc944ed
No known key found for this signature in database
GPG Key ID: 9CF312607477B8AB
6 changed files with 52 additions and 22 deletions

View File

@ -20,17 +20,29 @@ function parseArgs(args) {
const command = program.args[0]; const command = program.args[0];
const commandArgs = program.args.slice(1); const commandArgs = program.args.slice(1);
const noOverride = !program.override; const noOverride = !program.override;
let rc;
if (program.environments && program.environments.length) {
rc = rc || {};
rc.environments = program.environments;
}
if (program.rcFile) {
rc = rc || {};
rc.filePath = program.rcFile;
}
let envFile;
if (program.file) {
envFile = envFile || {};
envFile.filePath = program.file;
}
if (program.fallback != null) {
envFile = envFile || {};
envFile.fallback = program.fallback;
}
return { return {
command, command,
commandArgs, commandArgs,
envFile: { envFile,
filePath: program.file, rc,
fallback: program.fallback
},
rc: {
environments: program.environments,
filePath: program.rcFile
},
options: { options: {
noOverride noOverride
} }

View File

@ -60,7 +60,9 @@ function parseEnvVars(envString) {
const key = match[2].trim(); const key = match[2].trim();
const value = match[3].trim() || ''; const value = match[3].trim() || '';
// remove any surrounding quotes // remove any surrounding quotes
matches[key] = value.replace(/(^['"]|['"]$)/g, ''); matches[key] = value
.replace(/(^['"]|['"]$)/g, '')
.replace(`\\n`, `\n`);
} }
return matches; return matches;
} }

View File

@ -30,7 +30,8 @@ function getRCFileVars({ environments, filePath }) {
const ext = path_1.extname(absolutePath).toLowerCase(); const ext = path_1.extname(absolutePath).toLowerCase();
let parsedData; let parsedData;
if (ext === '.json' || ext === '.js') { if (ext === '.json' || ext === '.js') {
parsedData = require(absolutePath); const possiblePromise = require(absolutePath); /* eslint-disable-line */
parsedData = utils_1.isPromise(possiblePromise) ? yield possiblePromise : possiblePromise;
} }
else { else {
const file = yield readFileAsync(absolutePath, { encoding: 'utf8' }); const file = yield readFileAsync(absolutePath, { encoding: 'utf8' });

View File

@ -42,10 +42,10 @@ class TermSignals {
* Terminate parent process helper * Terminate parent process helper
*/ */
_terminateProcess(code, signal) { _terminateProcess(code, signal) {
if (signal !== undefined) { if (signal != null) {
return process.kill(process.pid, signal); return process.kill(process.pid, signal);
} }
if (code !== undefined) { if (code != null) {
return process.exit(code); return process.exit(code);
} }
throw new Error('Unable to terminate parent process successfully'); throw new Error('Unable to terminate parent process successfully');

View File

@ -21,17 +21,32 @@ export function parseArgs (args: string[]): EnvCmdOptions {
const command = program.args[0] const command = program.args[0]
const commandArgs = program.args.slice(1) const commandArgs = program.args.slice(1)
const noOverride = !program.override const noOverride = !program.override
let rc: any
if (program.environments && program.environments.length) {
rc = rc || {}
rc.environments = program.environments
}
if (program.rcFile) {
rc = rc || {}
rc.filePath = program.rcFile
}
let envFile: any
if (program.file) {
envFile = envFile || {}
envFile.filePath = program.file
}
if (program.fallback != null) {
envFile = envFile || {}
envFile.fallback = program.fallback
}
return { return {
command, command,
commandArgs, commandArgs,
envFile: { envFile,
filePath: program.file, rc,
fallback: program.fallback
},
rc: {
environments: program.environments,
filePath: program.rcFile
},
options: { options: {
noOverride noOverride
} }

View File

@ -45,10 +45,10 @@ export class TermSignals {
* Terminate parent process helper * Terminate parent process helper
*/ */
public _terminateProcess (code?: number, signal?: string): void { public _terminateProcess (code?: number, signal?: string): void {
if (signal !== undefined) { if (signal != null) {
return process.kill(process.pid, signal) return process.kill(process.pid, signal)
} }
if (code !== undefined) { if (code != null) {
return process.exit(code) return process.exit(code)
} }
throw new Error('Unable to terminate parent process successfully') throw new Error('Unable to terminate parent process successfully')