diff --git a/.gitignore b/.gitignore
index c1a17c9..a0d992f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,6 @@ package-lock.json
# Code Editor directory
.vscode
+
+# Ignore compiled dist/tests
+dist/test
diff --git a/dist/get-env-vars.js b/dist/get-env-vars.js
deleted file mode 100644
index 99f8a99..0000000
--- a/dist/get-env-vars.js
+++ /dev/null
@@ -1,66 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-const parse_rc_file_1 = require("./parse-rc-file");
-const parse_env_file_1 = require("./parse-env-file");
-const RC_FILE_DEFAULT_LOCATIONS = ['./.env-cmdrc', './.env-cmdrc.js', './.env-cmdrc.json'];
-const ENV_FILE_DEFAULT_LOCATIONS = ['./.env', './.env.js', './.env.json'];
-function getEnvVars(options) {
- return __awaiter(this, void 0, void 0, function* () {
- options = options || {};
- options.envFile = options.envFile || {};
- // Check for rc file usage
- if (options.rc) {
- return getRCFile({ environments: options.rc.environments, filePath: options.rc.filePath });
- }
- return getEnvFile({ filePath: options.envFile.filePath, fallback: options.envFile.fallback });
- });
-}
-exports.getEnvVars = getEnvVars;
-function getEnvFile({ filePath, fallback }) {
- return __awaiter(this, void 0, void 0, function* () {
- // Use env file
- if (filePath) {
- try {
- return yield parse_env_file_1.getEnvFileVars(filePath);
- }
- catch (e) { }
- if (!fallback) {
- throw new Error(`Unable to locate env file at location (${filePath})`);
- }
- }
- // Use the default env file locations
- for (const path of ENV_FILE_DEFAULT_LOCATIONS) {
- try {
- return yield parse_env_file_1.getEnvFileVars(path);
- }
- catch (e) { }
- }
- throw new Error(`Unable to locate env file at default locations (${ENV_FILE_DEFAULT_LOCATIONS})`);
- });
-}
-exports.getEnvFile = getEnvFile;
-async function getRCFile({ environments, filePath }) {
- // User provided an .rc file path
- if (filePath) {
- try {
- return await parse_rc_file_1.getRCFileVars({ environments, filePath });
- }
- catch (e) {
- if (e.name !== 'PathError')
- console.log(e);
- throw new Error(`Unable to locate .rc file at location (${filePath})`);
- }
- }
- // Use the default .rc file locations
- for (const filePath of RC_FILE_DEFAULT_LOCATIONS) {
- try {
- return await parse_rc_file_1.getRCFileVars({ environments, filePath });
- }
- catch (e) {
- if (e.name !== 'PathError')
- console.log(e);
- }
- }
- throw new Error(`Unable to locate .rc file at default locations (${RC_FILE_DEFAULT_LOCATIONS})`);
-}
-exports.getRCFile = getRCFile;
diff --git a/dist/env-cmd.d.ts b/dist/src/env-cmd.d.ts
similarity index 100%
rename from dist/env-cmd.d.ts
rename to dist/src/env-cmd.d.ts
diff --git a/dist/env-cmd.js b/dist/src/env-cmd.js
similarity index 96%
rename from dist/env-cmd.js
rename to dist/src/env-cmd.js
index 8a3f4bc..8f24b2e 100644
--- a/dist/env-cmd.js
+++ b/dist/src/env-cmd.js
@@ -31,11 +31,10 @@ exports.CLI = CLI;
* @param {EnvCmdOptions} { command, commandArgs, envFile, rc, options }
* @returns {Promise<{ [key: string]: any }>} Returns an object containing [environment variable name]: value
*/
-async function EnvCmd({ command, commandArgs, envFile, rc, options }) {
- options = options || {};
+async function EnvCmd({ command, commandArgs, envFile, rc, options = {} }) {
let env = await get_env_vars_1.getEnvVars({ envFile, rc });
// Override the merge order if --no-override flag set
- if (options.noOverride) {
+ if (options.noOverride === true) {
env = Object.assign({}, env, process.env);
}
else {
diff --git a/dist/get-env-vars.d.ts b/dist/src/get-env-vars.d.ts
similarity index 100%
rename from dist/get-env-vars.d.ts
rename to dist/src/get-env-vars.d.ts
diff --git a/dist/src/get-env-vars.js b/dist/src/get-env-vars.js
new file mode 100644
index 0000000..3723f59
--- /dev/null
+++ b/dist/src/get-env-vars.js
@@ -0,0 +1,61 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const parse_rc_file_1 = require("./parse-rc-file");
+const parse_env_file_1 = require("./parse-env-file");
+const RC_FILE_DEFAULT_LOCATIONS = ['./.env-cmdrc', './.env-cmdrc.js', './.env-cmdrc.json'];
+const ENV_FILE_DEFAULT_LOCATIONS = ['./.env', './.env.js', './.env.json'];
+async function getEnvVars(options = {}) {
+ options.envFile = options.envFile !== undefined ? options.envFile : {};
+ // Check for rc file usage
+ if (options.rc !== undefined) {
+ return getRCFile({ environments: options.rc.environments, filePath: options.rc.filePath });
+ }
+ return getEnvFile({ filePath: options.envFile.filePath, fallback: options.envFile.fallback });
+}
+exports.getEnvVars = getEnvVars;
+async function getEnvFile({ filePath, fallback }) {
+ // Use env file
+ if (filePath !== undefined) {
+ try {
+ return await parse_env_file_1.getEnvFileVars(filePath);
+ }
+ catch (e) { }
+ if (fallback !== true) {
+ throw new Error(`Unable to locate env file at location (${filePath})`);
+ }
+ }
+ // Use the default env file locations
+ for (const path of ENV_FILE_DEFAULT_LOCATIONS) {
+ try {
+ return await parse_env_file_1.getEnvFileVars(path);
+ }
+ catch (e) { }
+ }
+ throw new Error(`Unable to locate env file at default locations (${ENV_FILE_DEFAULT_LOCATIONS})`);
+}
+exports.getEnvFile = getEnvFile;
+async function getRCFile({ environments, filePath }) {
+ // User provided an .rc file path
+ if (filePath !== undefined) {
+ try {
+ return await parse_rc_file_1.getRCFileVars({ environments, filePath });
+ }
+ catch (e) {
+ if (e.name !== 'PathError')
+ console.error(e);
+ throw new Error(`Unable to locate .rc file at location (${filePath})`);
+ }
+ }
+ // Use the default .rc file locations
+ for (const filePath of RC_FILE_DEFAULT_LOCATIONS) {
+ try {
+ return await parse_rc_file_1.getRCFileVars({ environments, filePath });
+ }
+ catch (e) {
+ if (e.name !== 'PathError')
+ console.error(e);
+ }
+ }
+ throw new Error(`Unable to locate .rc file at default locations (${RC_FILE_DEFAULT_LOCATIONS})`);
+}
+exports.getRCFile = getRCFile;
diff --git a/dist/index.d.ts b/dist/src/index.d.ts
similarity index 100%
rename from dist/index.d.ts
rename to dist/src/index.d.ts
diff --git a/dist/index.js b/dist/src/index.js
similarity index 100%
rename from dist/index.js
rename to dist/src/index.js
diff --git a/dist/parse-args.d.ts b/dist/src/parse-args.d.ts
similarity index 100%
rename from dist/parse-args.d.ts
rename to dist/src/parse-args.d.ts
diff --git a/dist/parse-args.js b/dist/src/parse-args.js
similarity index 83%
rename from dist/parse-args.js
rename to dist/src/parse-args.js
index 7419174..11d93df 100644
--- a/dist/parse-args.js
+++ b/dist/src/parse-args.js
@@ -15,16 +15,18 @@ function parseArgs(args) {
const noOverride = !program.override;
const useShell = !!program.useShell;
let rc;
- if (program.environments && program.environments.length) {
- rc = rc || {};
- rc.environments = program.environments;
- rc.filePath = program.rcFile;
+ if (program.environments !== undefined && program.environments.length !== 0) {
+ rc = {
+ environments: program.environments,
+ filePath: program.rcFile
+ };
}
let envFile;
- if (program.file) {
- envFile = envFile || {};
- envFile.filePath = program.file;
- envFile.fallback = program.fallback;
+ if (program.file !== undefined) {
+ envFile = {
+ filePath: program.file,
+ fallback: program.fallback
+ };
}
return {
command,
diff --git a/dist/parse-env-file.d.ts b/dist/src/parse-env-file.d.ts
similarity index 100%
rename from dist/parse-env-file.d.ts
rename to dist/src/parse-env-file.d.ts
diff --git a/dist/parse-env-file.js b/dist/src/parse-env-file.js
similarity index 95%
rename from dist/parse-env-file.js
rename to dist/src/parse-env-file.js
index 57ff58a..c049c5c 100644
--- a/dist/parse-env-file.js
+++ b/dist/src/parse-env-file.js
@@ -15,7 +15,7 @@ async function getEnvFileVars(envFilePath) {
// Get the file extension
const ext = path.extname(absolutePath).toLowerCase();
let env = {};
- if (~REQUIRE_HOOK_EXTENSIONS.indexOf(ext)) {
+ if (REQUIRE_HOOK_EXTENSIONS.indexOf(ext) > -1) {
const possiblePromise = require(absolutePath); /* eslint-disable-line */
env = utils_1.isPromise(possiblePromise) ? await possiblePromise : possiblePromise;
}
@@ -48,11 +48,11 @@ function parseEnvVars(envString) {
while ((match = envParseRegex.exec(envString)) !== null) {
// Note: match[1] is the full env=var line
const key = match[2].trim();
- const value = match[3].trim() || '';
+ const value = match[3].trim();
// remove any surrounding quotes
matches[key] = value
.replace(/(^['"]|['"]$)/g, '')
- .replace(/\\n/g, `\n`);
+ .replace(/\\n/g, '\n');
}
return matches;
}
diff --git a/dist/parse-rc-file.d.ts b/dist/src/parse-rc-file.d.ts
similarity index 100%
rename from dist/parse-rc-file.d.ts
rename to dist/src/parse-rc-file.d.ts
diff --git a/dist/parse-rc-file.js b/dist/src/parse-rc-file.js
similarity index 95%
rename from dist/parse-rc-file.js
rename to dist/src/parse-rc-file.js
index 1c00e4e..b8a6f3e 100644
--- a/dist/parse-rc-file.js
+++ b/dist/src/parse-rc-file.js
@@ -35,7 +35,7 @@ async function getRCFileVars({ environments, filePath }) {
let environmentFound = false;
environments.forEach((name) => {
const envVars = parsedData[name];
- if (envVars) {
+ if (envVars !== undefined) {
environmentFound = true;
result = Object.assign({}, result, envVars);
}
@@ -63,7 +63,7 @@ function parseRCFile(fileData) {
console.error(`Error:
Failed to parse the .rc file.
Please make sure its a valid JSON format.`);
- throw new Error(`Unable to parse JSON in .rc file.`);
+ throw new Error('Unable to parse JSON in .rc file.');
}
return data;
}
diff --git a/dist/signal-termination.d.ts b/dist/src/signal-termination.d.ts
similarity index 91%
rename from dist/signal-termination.d.ts
rename to dist/src/signal-termination.d.ts
index e7d97fd..18a2b35 100644
--- a/dist/signal-termination.d.ts
+++ b/dist/src/signal-termination.d.ts
@@ -1,7 +1,7 @@
///
import { ChildProcess } from 'child_process';
export declare class TermSignals {
- private terminateSpawnedProcessFuncHandlers;
+ private readonly terminateSpawnedProcessFuncHandlers;
_exitCalled: boolean;
handleTermSignals(proc: ChildProcess): void;
/**
diff --git a/dist/signal-termination.js b/dist/src/signal-termination.js
similarity index 95%
rename from dist/signal-termination.js
rename to dist/src/signal-termination.js
index 0ee320b..d0a59b9 100644
--- a/dist/signal-termination.js
+++ b/dist/src/signal-termination.js
@@ -22,7 +22,7 @@ class TermSignals {
};
process.once(signal, this.terminateSpawnedProcessFuncHandlers[signal]);
});
- process.once('exit', this.terminateSpawnedProcessFuncHandlers['SIGTERM']);
+ process.once('exit', this.terminateSpawnedProcessFuncHandlers.SIGTERM);
// Terminate parent process if child process receives termination events
proc.on('exit', (code, signal) => {
this._removeProcessListeners();
@@ -42,10 +42,10 @@ class TermSignals {
* Terminate parent process helper
*/
_terminateProcess(code, signal) {
- if (signal != null) {
+ if (signal !== undefined) {
return process.kill(process.pid, signal);
}
- if (code != null) {
+ if (code !== undefined) {
return process.exit(code);
}
throw new Error('Unable to terminate parent process successfully');
@@ -57,7 +57,7 @@ class TermSignals {
SIGNALS_TO_HANDLE.forEach((signal) => {
process.removeListener(signal, this.terminateSpawnedProcessFuncHandlers[signal]);
});
- process.removeListener('exit', this.terminateSpawnedProcessFuncHandlers['SIGTERM']);
+ process.removeListener('exit', this.terminateSpawnedProcessFuncHandlers.SIGTERM);
}
/**
* General exception handler
diff --git a/dist/spawn.d.ts b/dist/src/spawn.d.ts
similarity index 100%
rename from dist/spawn.d.ts
rename to dist/src/spawn.d.ts
diff --git a/dist/spawn.js b/dist/src/spawn.js
similarity index 100%
rename from dist/spawn.js
rename to dist/src/spawn.js
diff --git a/dist/types.d.ts b/dist/src/types.d.ts
similarity index 100%
rename from dist/types.d.ts
rename to dist/src/types.d.ts
diff --git a/dist/types.js b/dist/src/types.js
similarity index 100%
rename from dist/types.js
rename to dist/src/types.js
diff --git a/dist/utils.d.ts b/dist/src/utils.d.ts
similarity index 93%
rename from dist/utils.d.ts
rename to dist/src/utils.d.ts
index 13e3d81..d3714a7 100644
--- a/dist/utils.d.ts
+++ b/dist/src/utils.d.ts
@@ -9,4 +9,4 @@ export declare function parseArgList(list: string): string[];
/**
* A simple function to test if the value is a promise
*/
-export declare function isPromise(value: any | PromiseLike