mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
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:
parent
0523d994be
commit
86edc944ed
@ -20,17 +20,29 @@ function parseArgs(args) {
|
||||
const command = program.args[0];
|
||||
const commandArgs = program.args.slice(1);
|
||||
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 {
|
||||
command,
|
||||
commandArgs,
|
||||
envFile: {
|
||||
filePath: program.file,
|
||||
fallback: program.fallback
|
||||
},
|
||||
rc: {
|
||||
environments: program.environments,
|
||||
filePath: program.rcFile
|
||||
},
|
||||
envFile,
|
||||
rc,
|
||||
options: {
|
||||
noOverride
|
||||
}
|
||||
|
||||
@ -60,7 +60,9 @@ function parseEnvVars(envString) {
|
||||
const key = match[2].trim();
|
||||
const value = match[3].trim() || '';
|
||||
// remove any surrounding quotes
|
||||
matches[key] = value.replace(/(^['"]|['"]$)/g, '');
|
||||
matches[key] = value
|
||||
.replace(/(^['"]|['"]$)/g, '')
|
||||
.replace(`\\n`, `\n`);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
@ -30,7 +30,8 @@ function getRCFileVars({ environments, filePath }) {
|
||||
const ext = path_1.extname(absolutePath).toLowerCase();
|
||||
let parsedData;
|
||||
if (ext === '.json' || ext === '.js') {
|
||||
parsedData = require(absolutePath);
|
||||
const possiblePromise = require(absolutePath); /* eslint-disable-line */
|
||||
parsedData = utils_1.isPromise(possiblePromise) ? yield possiblePromise : possiblePromise;
|
||||
}
|
||||
else {
|
||||
const file = yield readFileAsync(absolutePath, { encoding: 'utf8' });
|
||||
|
||||
@ -42,10 +42,10 @@ class TermSignals {
|
||||
* Terminate parent process helper
|
||||
*/
|
||||
_terminateProcess(code, signal) {
|
||||
if (signal !== undefined) {
|
||||
if (signal != null) {
|
||||
return process.kill(process.pid, signal);
|
||||
}
|
||||
if (code !== undefined) {
|
||||
if (code != null) {
|
||||
return process.exit(code);
|
||||
}
|
||||
throw new Error('Unable to terminate parent process successfully');
|
||||
|
||||
@ -21,17 +21,32 @@ export function parseArgs (args: string[]): EnvCmdOptions {
|
||||
const command = program.args[0]
|
||||
const commandArgs = program.args.slice(1)
|
||||
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 {
|
||||
command,
|
||||
commandArgs,
|
||||
envFile: {
|
||||
filePath: program.file,
|
||||
fallback: program.fallback
|
||||
},
|
||||
rc: {
|
||||
environments: program.environments,
|
||||
filePath: program.rcFile
|
||||
},
|
||||
envFile,
|
||||
rc,
|
||||
options: {
|
||||
noOverride
|
||||
}
|
||||
|
||||
@ -45,10 +45,10 @@ export class TermSignals {
|
||||
* Terminate parent process helper
|
||||
*/
|
||||
public _terminateProcess (code?: number, signal?: string): void {
|
||||
if (signal !== undefined) {
|
||||
if (signal != null) {
|
||||
return process.kill(process.pid, signal)
|
||||
}
|
||||
if (code !== undefined) {
|
||||
if (code != null) {
|
||||
return process.exit(code)
|
||||
}
|
||||
throw new Error('Unable to terminate parent process successfully')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user