From e66cfc10f11e6e7b096d0186012cab9932cffb06 Mon Sep 17 00:00:00 2001 From: Todd Bluhm Date: Fri, 20 Mar 2020 17:20:18 -0500 Subject: [PATCH] chore(package): update dependencies --- CHANGELOG.md | 12 +++++++----- dist/env-cmd.js | 2 +- dist/get-env-vars.js | 4 ++-- dist/parse-args.d.ts | 4 ++-- dist/parse-args.js | 11 +++++++---- dist/signal-termination.js | 12 ++++++------ package.json | 6 +++--- src/env-cmd.ts | 2 +- src/get-env-vars.ts | 4 ++-- src/parse-args.ts | 13 ++++++++----- test/parse-args.spec.ts | 2 +- 11 files changed, 40 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2562961..d8f6d49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,19 @@ # Changelog -## 10.1.1 - Pending -- **Upgrade**: Updated devDependencies `ts-standard` +## 10.1.1 - In Development + +- **Upgrade**: Upgraded dependency `commander` to `5.x` +- **Upgrade**: Upgraded devDependencies `ts-standard`, `sinon` ## 10.1.0 -- **Feature**: Added support for expanding vars using the `-x` flag. +- **Feature**: Added support for expanding vars using the `-x` flag. Note: only supports `$var` syntax - **Feature**: Added support for `--silent` flag that ignores env-cmd errors and missing files and only terminates on caught signals - **Feature**: Added a new `--verbose` flag that prints additional debugging info to `console.info` -- **Upgrade**: Updated dependency `commander` to `v4` -- **Upgrade**: Updated devDependencies `sinon`, `nyc`, and `ts-standard` +- **Upgrade**: Upgraded dependency `commander` to `4.x` +- **Upgrade**: Upgraded devDependencies `sinon`, `nyc`, and `ts-standard` - **Fix**: Handle case where the termination signal is the termination code ## 10.0.1 diff --git a/dist/env-cmd.js b/dist/env-cmd.js index 28b032b..a499ed5 100644 --- a/dist/env-cmd.js +++ b/dist/env-cmd.js @@ -39,7 +39,7 @@ async function EnvCmd({ command, commandArgs, envFile, rc, options = {} }) { env = await get_env_vars_1.getEnvVars({ envFile, rc, verbose: options.verbose }); } catch (e) { - if (!(_a = options.silent, (_a !== null && _a !== void 0 ? _a : false))) { + if (!((_a = options.silent) !== null && _a !== void 0 ? _a : false)) { throw e; } } diff --git a/dist/get-env-vars.js b/dist/get-env-vars.js index dea1338..4bd3c02 100644 --- a/dist/get-env-vars.js +++ b/dist/get-env-vars.js @@ -8,13 +8,13 @@ async function getEnvVars(options = {}) { options.envFile = options.envFile !== undefined ? options.envFile : {}; // Check for rc file usage if (options.rc !== undefined) { - return getRCFile({ + return await getRCFile({ environments: options.rc.environments, filePath: options.rc.filePath, verbose: options.verbose }); } - return getEnvFile({ + return await getEnvFile({ filePath: options.envFile.filePath, fallback: options.envFile.fallback, verbose: options.verbose diff --git a/dist/parse-args.d.ts b/dist/parse-args.d.ts index 02aa6d1..0c68100 100644 --- a/dist/parse-args.d.ts +++ b/dist/parse-args.d.ts @@ -1,7 +1,7 @@ -import { Command } from 'commander'; +import * as commander from 'commander'; import { EnvCmdOptions } from './types'; /** * Parses the arguments passed into the cli */ export declare function parseArgs(args: string[]): EnvCmdOptions; -export declare function parseArgsUsingCommander(args: string[]): Command; +export declare function parseArgsUsingCommander(args: string[]): commander.Command; diff --git a/dist/parse-args.js b/dist/parse-args.js index 544aad4..5e1f894 100644 --- a/dist/parse-args.js +++ b/dist/parse-args.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const commander_1 = require("commander"); +const commander = require("commander"); const utils_1 = require("./utils"); // Use commonjs require to prevent a weird folder hierarchy in dist const packageJson = require('../package.json'); /* eslint-disable-line */ @@ -8,11 +8,13 @@ const packageJson = require('../package.json'); /* eslint-disable-line */ * Parses the arguments passed into the cli */ function parseArgs(args) { - // Get the command and command args + // Run the initial arguments through commander in order to determine + // which value in the args array is the `command` to execute let program = parseArgsUsingCommander(args); const command = program.args[0]; + // Grab all arguments after the `command` in the args array const commandArgs = args.splice(args.indexOf(command) + 1); - // Reprocess the args with the command and command args removed + // Reprocess the args with the command and command arguments removed program = parseArgsUsingCommander(args.slice(0, args.indexOf(command))); // Set values for provided options let noOverride = false; @@ -70,7 +72,7 @@ function parseArgs(args) { } exports.parseArgs = parseArgs; function parseArgsUsingCommander(args) { - const program = new commander_1.Command(); + const program = new commander.Command(); return program .version(packageJson.version, '-v, --version') .usage('[options] [...args]') @@ -83,6 +85,7 @@ function parseArgsUsingCommander(args) { .option('--use-shell', 'Execute the command in a new shell with the given environment') .option('--verbose', 'Print helpful debugging information') .option('-x, --expand-envs', 'Replace $var in args and command with environment variables') + .allowUnknownOption(true) .parse(['_', '_', ...args]); } exports.parseArgsUsingCommander = parseArgsUsingCommander; diff --git a/dist/signal-termination.js b/dist/signal-termination.js index 6517239..136d7d6 100644 --- a/dist/signal-termination.js +++ b/dist/signal-termination.js @@ -27,7 +27,7 @@ class TermSignals { // Use the signal code if it is an error code let correctSignal; if (typeof signal === 'number') { - if (signal > ((code !== null && code !== void 0 ? code : 0))) { + if (signal > (code !== null && code !== void 0 ? code : 0)) { code = signal; correctSignal = 'SIGINT'; } @@ -36,7 +36,7 @@ class TermSignals { correctSignal = signal; } // Kill the child process - proc.kill((correctSignal !== null && correctSignal !== void 0 ? correctSignal : code)); + proc.kill(correctSignal !== null && correctSignal !== void 0 ? correctSignal : code); // Terminate the parent process this._terminateProcess(code, correctSignal); } @@ -49,8 +49,8 @@ class TermSignals { this._removeProcessListeners(); if (!this._exitCalled) { if (this.verbose) { - console.info(`Child process exited with code: ${((code !== null && code !== void 0 ? code : '')).toString()} and signal:` + - ((signal !== null && signal !== void 0 ? signal : '')).toString() + + console.info(`Child process exited with code: ${(code !== null && code !== void 0 ? code : '').toString()} and signal:` + + (signal !== null && signal !== void 0 ? signal : '').toString() + '. Terminating parent process...'); } // Mark shared state so we do not run into a signal/exit loop @@ -58,13 +58,13 @@ class TermSignals { // Use the signal code if it is an error code let correctSignal; if (typeof signal === 'number') { - if (signal > ((code !== null && code !== void 0 ? code : 0))) { + if (signal > (code !== null && code !== void 0 ? code : 0)) { code = signal; correctSignal = 'SIGINT'; } } else { - correctSignal = (signal !== null && signal !== void 0 ? signal : undefined); + correctSignal = signal !== null && signal !== void 0 ? signal : undefined; } // Terminate the parent process this._terminateProcess(code, correctSignal); diff --git a/package.json b/package.json index 4af6842..ef7a722 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ }, "homepage": "https://github.com/toddbluhm/env-cmd#readme", "dependencies": { - "commander": "^4.0.0", + "commander": "^5.0.0", "cross-spawn": "^7.0.0" }, "devDependencies": { @@ -63,9 +63,9 @@ "husky": "^4.0.0", "mocha": "^7.0.0", "nyc": "^15.0.0", - "sinon": "^8.0.0", + "sinon": "^9.0.0", "ts-node": "^8.0.0", - "ts-standard": "^5.0.0", + "ts-standard": "^7.0.0", "typescript": "^3.7.0" }, "nyc": { diff --git a/src/env-cmd.ts b/src/env-cmd.ts index 659698a..cc3179a 100644 --- a/src/env-cmd.ts +++ b/src/env-cmd.ts @@ -17,7 +17,7 @@ export async function CLI (args: string[]): Promise<{ [key: string]: any }> { // Run EnvCmd try { - return await exports.EnvCmd(parsedArgs) + return await (exports.EnvCmd(parsedArgs) as Promise<{ [key: string]: any }>) } catch (e) { console.error(e) return process.exit(1) diff --git a/src/get-env-vars.ts b/src/get-env-vars.ts index 746e7d7..f89f847 100644 --- a/src/get-env-vars.ts +++ b/src/get-env-vars.ts @@ -9,13 +9,13 @@ export async function getEnvVars (options: GetEnvVarOptions = {}): Promise<{ [ke options.envFile = options.envFile !== undefined ? options.envFile : {} // Check for rc file usage if (options.rc !== undefined) { - return getRCFile({ + return await getRCFile({ environments: options.rc.environments, filePath: options.rc.filePath, verbose: options.verbose }) } - return getEnvFile({ + return await getEnvFile({ filePath: options.envFile.filePath, fallback: options.envFile.fallback, verbose: options.verbose diff --git a/src/parse-args.ts b/src/parse-args.ts index 892798b..bbd4c56 100644 --- a/src/parse-args.ts +++ b/src/parse-args.ts @@ -1,4 +1,4 @@ -import { Command } from 'commander' +import * as commander from 'commander' import { EnvCmdOptions } from './types' import { parseArgList } from './utils' @@ -9,12 +9,14 @@ const packageJson = require('../package.json') /* eslint-disable-line */ * Parses the arguments passed into the cli */ export function parseArgs (args: string[]): EnvCmdOptions { - // Get the command and command args + // Run the initial arguments through commander in order to determine + // which value in the args array is the `command` to execute let program = parseArgsUsingCommander(args) const command = program.args[0] + // Grab all arguments after the `command` in the args array const commandArgs = args.splice(args.indexOf(command) + 1) - // Reprocess the args with the command and command args removed + // Reprocess the args with the command and command arguments removed program = parseArgsUsingCommander(args.slice(0, args.indexOf(command))) // Set values for provided options @@ -75,8 +77,8 @@ export function parseArgs (args: string[]): EnvCmdOptions { return options } -export function parseArgsUsingCommander (args: string[]): Command { - const program = new Command() +export function parseArgsUsingCommander (args: string[]): commander.Command { + const program = new commander.Command() return program .version(packageJson.version, '-v, --version') .usage('[options] [...args]') @@ -89,5 +91,6 @@ export function parseArgsUsingCommander (args: string[]): Command { .option('--use-shell', 'Execute the command in a new shell with the given environment') .option('--verbose', 'Print helpful debugging information') .option('-x, --expand-envs', 'Replace $var in args and command with environment variables') + .allowUnknownOption(true) .parse(['_', '_', ...args]) } diff --git a/test/parse-args.spec.ts b/test/parse-args.spec.ts index 79a8783..79accab 100644 --- a/test/parse-args.spec.ts +++ b/test/parse-args.spec.ts @@ -5,7 +5,7 @@ import { parseArgs } from '../src/parse-args' describe('parseArgs', (): void => { const command = 'command' - const commandArgs = ['cmda1', 'cmda2', '--cmda3', '-4', 'cmda4'] + const commandArgs = ['cmda1', 'cmda2', '--cmda3', '-4', 'cmda4', '--fallback'] const environments = ['development', 'production'] const rcFilePath = './.env-cmdrc' const envFilePath = './.env'