Skip to content

Commit fa50d02

Browse files
committed
feat: allow bracers when processing vars
1 parent 6967476 commit fa50d02

16 files changed

+37
-16
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
- **Upgrade**: Upgraded dependency `commander` to `5.x`
66
- **Upgrade**: Upgraded devDependencies `ts-standard`, `sinon`
7+
- **Feature**: support both `$var` and `${var}` when expanding vars
78

89
## 10.1.0
910

1011
- **Feature**: Added support for expanding vars using the `-x` flag.
1112
Note: only supports `$var` syntax
12-
- **Feature**: Added support for `--silent` flag that ignores env-cmd errors and missing files and
13+
- **Feature**: Added support for `--silent` flag that ignores env-cmd errors and missing files and
1314
only terminates on caught signals
1415
- **Feature**: Added a new `--verbose` flag that prints additional debugging info to `console.info`
1516
- **Upgrade**: Upgraded dependency `commander` to `4.x`

Diff for: dist/env-cmd.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.EnvCmd = exports.CLI = void 0;
34
const spawn_1 = require("./spawn");
45
const signal_termination_1 = require("./signal-termination");
56
const parse_args_1 = require("./parse-args");

Diff for: dist/expand-envs.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* expandEnvs Replaces $var in args and command with environment variables
2+
* expandEnvs Replaces $var and ${var} in args and command with environment variables
33
* the environment variable doesn't exist, it leaves it as is.
44
*/
55
export declare function expandEnvs(str: string, envs: {

Diff for: dist/expand-envs.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.expandEnvs = void 0;
34
/**
4-
* expandEnvs Replaces $var in args and command with environment variables
5+
* expandEnvs Replaces $var and ${var} in args and command with environment variables
56
* the environment variable doesn't exist, it leaves it as is.
67
*/
78
function expandEnvs(str, envs) {
8-
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => {
9-
const varValue = envs[varName.slice(1)];
9+
return str.replace(/(?<!\\)\$\{?[a-zA-Z0-9_]+\}?/g, varName => {
10+
const varValue = envs[varName.startsWith('${') ? varName.substr(2, varName.length - 3) : varName.substr(1)];
1011
return varValue === undefined ? varName : varValue;
1112
});
1213
}

Diff for: dist/get-env-vars.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getRCFile = exports.getEnvFile = exports.getEnvVars = void 0;
34
const parse_rc_file_1 = require("./parse-rc-file");
45
const parse_env_file_1 = require("./parse-env-file");
56
const RC_FILE_DEFAULT_LOCATIONS = ['./.env-cmdrc', './.env-cmdrc.js', './.env-cmdrc.json'];

Diff for: dist/index.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
"use strict";
2-
function __export(m) {
3-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4-
}
2+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3+
if (k2 === undefined) k2 = k;
4+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5+
}) : (function(o, m, k, k2) {
6+
if (k2 === undefined) k2 = k;
7+
o[k2] = m[k];
8+
}));
9+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
10+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11+
};
512
Object.defineProperty(exports, "__esModule", { value: true });
13+
exports.GetEnvVars = void 0;
614
const get_env_vars_1 = require("./get-env-vars");
7-
__export(require("./env-cmd"));
15+
// Export the core env-cmd API
16+
__exportStar(require("./types"), exports);
17+
__exportStar(require("./env-cmd"), exports);
818
exports.GetEnvVars = get_env_vars_1.getEnvVars;

Diff for: dist/parse-args.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.parseArgsUsingCommander = exports.parseArgs = void 0;
34
const commander = require("commander");
45
const utils_1 = require("./utils");
56
// Use commonjs require to prevent a weird folder hierarchy in dist

Diff for: dist/parse-env-file.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.stripEmptyLines = exports.stripComments = exports.parseEnvVars = exports.parseEnvString = exports.getEnvFileVars = void 0;
34
const fs = require("fs");
45
const path = require("path");
56
const utils_1 = require("./utils");

Diff for: dist/parse-rc-file.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.getRCFileVars = void 0;
34
const fs_1 = require("fs");
45
const util_1 = require("util");
56
const path_1 = require("path");

Diff for: dist/signal-termination.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export declare class TermSignals {
1515
/**
1616
* Terminate parent process helper
1717
*/
18-
_terminateProcess(code?: number, signal?: NodeJS.Signals): void;
18+
_terminateProcess(code?: number, signal?: NodeJS.Signals): boolean | void;
1919
/**
2020
* Exit event listener clean up helper
2121
*/

Diff for: dist/signal-termination.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.TermSignals = void 0;
34
const SIGNALS_TO_HANDLE = [
45
'SIGINT', 'SIGTERM', 'SIGHUP'
56
];

Diff for: dist/spawn.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.spawn = void 0;
34
const spawn = require("cross-spawn");
45
exports.spawn = spawn;

Diff for: dist/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.isPromise = exports.parseArgList = exports.resolveEnvFilePath = void 0;
34
const path = require("path");
45
const os = require("os");
56
/**

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"Eric Lanehart <[email protected]>",
4040
"Jon Scheiding <[email protected]>",
4141
"serapath (Alexander Praetorius) <[email protected]>",
42-
"Anton Versal <[email protected]>"
42+
"Anton Versal <[email protected]>",
43+
"Nicholas Krul <[email protected]>"
4344
],
4445
"license": "MIT",
4546
"bugs": {

Diff for: src/expand-envs.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
/**
3-
* expandEnvs Replaces $var in args and command with environment variables
3+
* expandEnvs Replaces $var and ${var} in args and command with environment variables
44
* the environment variable doesn't exist, it leaves it as is.
55
*/
66
export function expandEnvs (str: string, envs: { [key: string]: any }): string {
7-
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => {
8-
const varValue = envs[varName.slice(1)]
7+
return str.replace(/(?<!\\)\$\{?[a-zA-Z0-9_]+\}?/g, varName => {
8+
const varValue = envs[varName.startsWith('${') ? varName.substr(2, varName.length - 3) : varName.substr(1)]
99
return varValue === undefined ? varName : varValue
1010
})
1111
}

Diff for: test/expand-envs.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('expandEnvs', (): void => {
99
PING: 'PONG',
1010
IP1: '127.0.0.1'
1111
}
12-
const args = ['notvar', '$dollar', '\\$notvar', '-4', '$PING', '$IP1', '\\$IP1', '$NONEXIST']
13-
const argsExpanded = ['notvar', 'money', '\\$notvar', '-4', 'PONG', '127.0.0.1', '\\$IP1', '$NONEXIST']
12+
const args = ['notvar', '$dollar', '\\$notvar', '-4', '$PING', '$IP1', '\\$IP1', '$NONEXIST', '${PING}', '${NONEXIST}'] /* eslint-disable-line */
13+
const argsExpanded = ['notvar', 'money', '\\$notvar', '-4', 'PONG', '127.0.0.1', '\\$IP1', '$NONEXIST', 'PONG', '${NONEXIST}'] /* eslint-disable-line */
1414

1515
it('should replace environment variables in args', (): void => {
1616
const res = args.map(arg => expandEnvs(arg, envs))

0 commit comments

Comments
 (0)