@mono-labs/cli 0.1.289 → 0.1.292
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/commands/build-process/buildBaseEnv.d.ts +9 -1
- package/dist/lib/commands/build-process/buildBaseEnv.d.ts.map +1 -1
- package/dist/lib/commands/build-process/buildBaseEnv.js +16 -5
- package/dist/lib/commands/build-process/cliFactory.d.ts.map +1 -1
- package/dist/lib/commands/build-process/cliFactory.js +18 -20
- package/dist/lib/commands/build-process/runMonoCommand.d.ts +13 -0
- package/dist/lib/commands/build-process/runMonoCommand.d.ts.map +1 -1
- package/dist/lib/commands/build-process/runMonoCommand.js +74 -5
- package/dist/lib/commands/build-process/runners/errors.d.ts +16 -0
- package/dist/lib/commands/build-process/runners/errors.d.ts.map +1 -0
- package/dist/lib/commands/build-process/runners/errors.js +42 -0
- package/dist/lib/commands/build-process/runners/processManager.d.ts +5 -0
- package/dist/lib/commands/build-process/runners/processManager.d.ts.map +1 -1
- package/dist/lib/commands/build-process/runners/processManager.js +29 -19
- package/dist/lib/commands/build-process/runners/runBackground.d.ts +2 -1
- package/dist/lib/commands/build-process/runners/runBackground.d.ts.map +1 -1
- package/dist/lib/commands/build-process/runners/runBackground.js +5 -5
- package/dist/lib/commands/build-process/runners/runForeground.d.ts.map +1 -1
- package/dist/lib/commands/build-process/runners/runForeground.js +3 -4
- package/dist/lib/commands/prune/prune.d.ts.map +1 -1
- package/dist/lib/commands/prune/prune.js +3 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +26 -13
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/build-process/buildBaseEnv.ts +19 -8
- package/lib/commands/build-process/cliFactory.ts +18 -19
- package/lib/commands/build-process/runMonoCommand.ts +89 -6
- package/lib/commands/build-process/runners/errors.ts +42 -0
- package/lib/commands/build-process/runners/processManager.ts +25 -16
- package/lib/commands/build-process/runners/runBackground.ts +7 -5
- package/lib/commands/build-process/runners/runForeground.ts +3 -6
- package/lib/commands/prune/prune.ts +3 -1
- package/lib/index.ts +29 -13
- package/package.json +4 -4
|
@@ -5,13 +5,21 @@ export type BaseEnvResult = {
|
|
|
5
5
|
keymap: Record<string, string>;
|
|
6
6
|
/** Absolute paths of the env files considered for this command. */
|
|
7
7
|
files: string[];
|
|
8
|
+
/** True when this command's own `envFiles` was ignored for a parent command's files. */
|
|
9
|
+
inheritedFromParent: boolean;
|
|
8
10
|
};
|
|
11
|
+
/** True when a parent mono command chose env files with `envFiles` and passed them down. */
|
|
12
|
+
export declare function parentLockedEnvFiles(env?: NodeJS.ProcessEnv): boolean;
|
|
9
13
|
/**
|
|
10
14
|
* Build the base environment for a mono command, honoring a per-command `envFiles` list.
|
|
11
15
|
*
|
|
12
16
|
* Without `envFiles`, the files loaded at startup are kept as-is. With it, keys injected at
|
|
13
17
|
* startup are stripped and the command's own files are loaded instead (real shell vars still win).
|
|
18
|
+
*
|
|
19
|
+
* When a parent mono command chose its files with `envFiles`, those files win: this command's
|
|
20
|
+
* `envFiles` is ignored and the parent's files (loaded at startup from MONOLABS_ENV_FILES) are
|
|
21
|
+
* kept, for this command and everything it launches.
|
|
14
22
|
*/
|
|
15
|
-
export declare function buildBaseEnv(configObject: any,
|
|
23
|
+
export declare function buildBaseEnv(configObject: any, _globalConfig?: any): BaseEnvResult;
|
|
16
24
|
export default buildBaseEnv;
|
|
17
25
|
//# sourceMappingURL=buildBaseEnv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBaseEnv.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/buildBaseEnv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildBaseEnv.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/buildBaseEnv.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,aAAa,GAAG;IAC1B,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAC,UAAU,CAAA;IAC1B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,mEAAmE;IACnE,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,wFAAwF;IACxF,mBAAmB,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAElF;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,GAAG,EAAE,aAAa,GAAE,GAAQ,GAAG,aAAa,CA6CtF;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -3,20 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parentLockedEnvFiles = parentLockedEnvFiles;
|
|
6
7
|
exports.buildBaseEnv = buildBaseEnv;
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const project_1 = require("@mono-labs/project");
|
|
9
10
|
const dataLayer_1 = require("./dataLayer");
|
|
11
|
+
/** True when a parent mono command chose env files with `envFiles` and passed them down. */
|
|
12
|
+
function parentLockedEnvFiles(env = process.env) {
|
|
13
|
+
return env[project_1.ENV_FILES_LOCKED_VAR] === '1' && env[project_1.ENV_FILES_VAR] !== undefined;
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* Build the base environment for a mono command, honoring a per-command `envFiles` list.
|
|
12
17
|
*
|
|
13
18
|
* Without `envFiles`, the files loaded at startup are kept as-is. With it, keys injected at
|
|
14
19
|
* startup are stripped and the command's own files are loaded instead (real shell vars still win).
|
|
20
|
+
*
|
|
21
|
+
* When a parent mono command chose its files with `envFiles`, those files win: this command's
|
|
22
|
+
* `envFiles` is ignored and the parent's files (loaded at startup from MONOLABS_ENV_FILES) are
|
|
23
|
+
* kept, for this command and everything it launches.
|
|
15
24
|
*/
|
|
16
|
-
function buildBaseEnv(configObject,
|
|
25
|
+
function buildBaseEnv(configObject, _globalConfig = {}) {
|
|
17
26
|
const commandFiles = configObject?.envFiles;
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
const inheritedFromParent = commandFiles !== undefined && parentLockedEnvFiles();
|
|
28
|
+
if (commandFiles === undefined || inheritedFromParent) {
|
|
20
29
|
const files = (0, project_1.getLoadedEnvFiles)();
|
|
21
30
|
const injected = (0, project_1.getInjectedEnvKeys)();
|
|
22
31
|
return {
|
|
@@ -25,8 +34,9 @@ function buildBaseEnv(configObject, globalConfig = {}) {
|
|
|
25
34
|
[project_1.ENV_FILES_VAR]: files.join(node_path_1.default.delimiter),
|
|
26
35
|
[project_1.INJECTED_KEYS_VAR]: injected.join(','),
|
|
27
36
|
},
|
|
28
|
-
keymap: (0, project_1.readEnvFiles)(
|
|
37
|
+
keymap: (0, project_1.readEnvFiles)(files),
|
|
29
38
|
files,
|
|
39
|
+
inheritedFromParent,
|
|
30
40
|
};
|
|
31
41
|
}
|
|
32
42
|
if (!Array.isArray(commandFiles)) {
|
|
@@ -47,6 +57,7 @@ function buildBaseEnv(configObject, globalConfig = {}) {
|
|
|
47
57
|
}
|
|
48
58
|
baseEnv[project_1.ENV_FILES_VAR] = files.join(node_path_1.default.delimiter);
|
|
49
59
|
baseEnv[project_1.INJECTED_KEYS_VAR] = injected.join(',');
|
|
50
|
-
|
|
60
|
+
baseEnv[project_1.ENV_FILES_LOCKED_VAR] = '1';
|
|
61
|
+
return { baseEnv, keymap, files, inheritedFromParent: false };
|
|
51
62
|
}
|
|
52
63
|
exports.default = buildBaseEnv;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliFactory.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/cliFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE;QACT,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,OAAO,CAAC,EAAE,MAAM,CACd,MAAM,EACN;QACE,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CACF,CAAA;IACD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACtD,4HAA4H;IAC5H,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAmCD;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAmB9C;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAW3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"cliFactory.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/cliFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE;QACT,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,OAAO,CAAC,EAAE,MAAM,CACd,MAAM,EACN;QACE,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CACF,CAAA;IACD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACtD,4HAA4H;IAC5H,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAmCD;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAmB9C;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAW3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,IAAI,CAwG7E;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -112,30 +112,28 @@ function buildCommands(files) {
|
|
|
112
112
|
envDefaults[item.name] = item.default;
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
catch (err) {
|
|
132
|
-
console.error('Error executing mono command:', err?.message);
|
|
133
|
-
}
|
|
115
|
+
// Errors are deliberately not caught here: they must reach the top-level handler in
|
|
116
|
+
// lib/index.ts, which prints them and sets a non-zero exit code.
|
|
117
|
+
const optionVals = {
|
|
118
|
+
...envDefaults,
|
|
119
|
+
...(cmd.opts ? cmd.opts() : cmd),
|
|
120
|
+
};
|
|
121
|
+
Object.keys(optionVals).forEach((k) => {
|
|
122
|
+
optionVals[k] = (0, validators_1.verifyOptionValue)(k, optionVals[k], optionsData);
|
|
123
|
+
});
|
|
124
|
+
optionVals['prod'] = optionVals[config.prodFlag] || false;
|
|
125
|
+
const defaultLookups = buildDefaultLookup(configObject);
|
|
126
|
+
const argVal = arg || configObject.argument?.default;
|
|
127
|
+
const args = { ...defaultLookups, arg: argVal };
|
|
128
|
+
(0, dataLayer_1.mergeData)({ ...optionVals, ...args });
|
|
129
|
+
configObject.name = configObject.name || commandName;
|
|
130
|
+
await (0, runMonoCommand_1.default)(configObject, optionVals);
|
|
134
131
|
});
|
|
135
132
|
});
|
|
136
133
|
}
|
|
137
134
|
catch (err) {
|
|
138
|
-
|
|
135
|
+
// A broken .mono definition must fail the run, not leave a partially registered CLI.
|
|
136
|
+
throw new Error(`Failed to register mono commands: ${err?.message ?? err}`);
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
139
|
exports.default = buildCommands;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
export declare function getAllowAllKeys(cfg: any): string[];
|
|
2
|
+
/**
|
|
3
|
+
* AWS profile for a command. Highest priority first:
|
|
4
|
+
* 1. the command's `environments` block (direct config, `$KEY` refs already resolved)
|
|
5
|
+
* 2. real shell variables
|
|
6
|
+
* 3. values from the command's env files
|
|
7
|
+
* Within each source CDK_DEPLOY_PROFILE wins over AWS_PROFILE.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveAwsProfile(envConfig: Record<string, any>, baseEnv: NodeJS.ProcessEnv): string;
|
|
10
|
+
export type AwsProfileSource = 'config' | 'shell' | 'files' | 'default';
|
|
11
|
+
export declare function resolveAwsProfileWithSource(envConfig: Record<string, any>, baseEnv: NodeJS.ProcessEnv): {
|
|
12
|
+
profile: string;
|
|
13
|
+
source: AwsProfileSource;
|
|
14
|
+
};
|
|
2
15
|
/**
|
|
3
16
|
* Orchestrate execution of a single mono command definition.
|
|
4
17
|
* Phases:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runMonoCommand.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/runMonoCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runMonoCommand.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/runMonoCommand.ts"],"names":[],"mappings":"AAUA,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,CAUlD;AAID;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9B,OAAO,EAAE,MAAM,CAAC,UAAU,GACzB,MAAM,CAER;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAEvE,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9B,OAAO,EAAE,MAAM,CAAC,UAAU,GACzB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAkB/C;AAaD;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+FxF;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAllowAllKeys = getAllowAllKeys;
|
|
4
|
+
exports.resolveAwsProfile = resolveAwsProfile;
|
|
5
|
+
exports.resolveAwsProfileWithSource = resolveAwsProfileWithSource;
|
|
4
6
|
exports.runMonoCommand = runMonoCommand;
|
|
5
7
|
const runForeground_1 = require("./runners/runForeground");
|
|
6
8
|
const runBackground_1 = require("./runners/runBackground");
|
|
@@ -9,6 +11,7 @@ const loadFromRoot_1 = require("../loadFromRoot");
|
|
|
9
11
|
const buildBaseEnv_1 = require("./buildBaseEnv");
|
|
10
12
|
const dataLayer_1 = require("./dataLayer");
|
|
11
13
|
const shared_1 = require("@mono-labs/shared");
|
|
14
|
+
const project_1 = require("@mono-labs/project");
|
|
12
15
|
function getAllowAllKeys(cfg) {
|
|
13
16
|
const decls = cfg.options ?? {};
|
|
14
17
|
return Object.entries(decls)
|
|
@@ -17,6 +20,47 @@ function getAllowAllKeys(cfg) {
|
|
|
17
20
|
v.options.length > 0)
|
|
18
21
|
.map(([k]) => k);
|
|
19
22
|
}
|
|
23
|
+
const PROFILE_KEYS = ['CDK_DEPLOY_PROFILE', 'AWS_PROFILE'];
|
|
24
|
+
/**
|
|
25
|
+
* AWS profile for a command. Highest priority first:
|
|
26
|
+
* 1. the command's `environments` block (direct config, `$KEY` refs already resolved)
|
|
27
|
+
* 2. real shell variables
|
|
28
|
+
* 3. values from the command's env files
|
|
29
|
+
* Within each source CDK_DEPLOY_PROFILE wins over AWS_PROFILE.
|
|
30
|
+
*/
|
|
31
|
+
function resolveAwsProfile(envConfig, baseEnv) {
|
|
32
|
+
return resolveAwsProfileWithSource(envConfig, baseEnv).profile;
|
|
33
|
+
}
|
|
34
|
+
function resolveAwsProfileWithSource(envConfig, baseEnv) {
|
|
35
|
+
const injected = new Set((baseEnv[project_1.INJECTED_KEYS_VAR] ?? '').split(',').filter(Boolean));
|
|
36
|
+
const fromConfig = (k) => envConfig[k];
|
|
37
|
+
const fromShell = (k) => (injected.has(k) ? undefined : baseEnv[k]);
|
|
38
|
+
const fromFiles = (k) => (injected.has(k) ? baseEnv[k] : undefined);
|
|
39
|
+
const sources = [
|
|
40
|
+
['config', fromConfig],
|
|
41
|
+
['shell', fromShell],
|
|
42
|
+
['files', fromFiles],
|
|
43
|
+
];
|
|
44
|
+
for (const [source, read] of sources) {
|
|
45
|
+
for (const key of PROFILE_KEYS) {
|
|
46
|
+
const value = read(key);
|
|
47
|
+
if (typeof value === 'string' && value.trim())
|
|
48
|
+
return { profile: value, source };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { profile: 'default', source: 'default' };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Record in baseEnv whether the AWS_PROFILE mono hands to children is injected. A profile from
|
|
55
|
+
* env files or the 'default' fallback is injected, so a nested mono command may replace it; one
|
|
56
|
+
* from the shell or the environments block is explicit and is kept like a shell variable.
|
|
57
|
+
*/
|
|
58
|
+
function markAwsProfileProvenance(baseEnv, source) {
|
|
59
|
+
const keys = (baseEnv[project_1.INJECTED_KEYS_VAR] ?? '').split(',').filter((k) => k && k !== 'AWS_PROFILE');
|
|
60
|
+
if (source === 'files' || source === 'default')
|
|
61
|
+
keys.push('AWS_PROFILE');
|
|
62
|
+
baseEnv[project_1.INJECTED_KEYS_VAR] = keys.join(',');
|
|
63
|
+
}
|
|
20
64
|
/**
|
|
21
65
|
* Orchestrate execution of a single mono command definition.
|
|
22
66
|
* Phases:
|
|
@@ -30,9 +74,8 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
30
74
|
(0, shared_1.writeLog)('configObject:', JSON.stringify(configObject, null, 2));
|
|
31
75
|
(0, dataLayer_1.mergeData)({ ...options });
|
|
32
76
|
// Resolve which env files this command loads (per-command `envFiles` or the defaults)
|
|
33
|
-
const { baseEnv, keymap, files: envFiles } = (0, buildBaseEnv_1.buildBaseEnv)(configObject, config);
|
|
77
|
+
const { baseEnv, keymap, files: envFiles, inheritedFromParent } = (0, buildBaseEnv_1.buildBaseEnv)(configObject, config);
|
|
34
78
|
const prodConfig = configObject.environments?.prod ?? {};
|
|
35
|
-
const awsProfile = process.env.CDK_DEPLOY_PROFILE || process.env.AWS_PROFILE || 'default';
|
|
36
79
|
const envObjBase = options.prod ? { ...prodConfig } : { ...devConfig };
|
|
37
80
|
Object.keys(envObjBase).forEach((k) => {
|
|
38
81
|
if (typeof envObjBase[k] === 'string' &&
|
|
@@ -42,7 +85,9 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
42
85
|
envObjBase[k] = keymap[refKey] || '';
|
|
43
86
|
}
|
|
44
87
|
});
|
|
88
|
+
const { profile: awsProfile, source: awsProfileSource } = resolveAwsProfileWithSource(envObjBase, baseEnv);
|
|
45
89
|
envObjBase.AWS_PROFILE = awsProfile;
|
|
90
|
+
markAwsProfileProvenance(baseEnv, awsProfileSource);
|
|
46
91
|
const envKeys = Object.keys(baseEnv).filter((k) => k.startsWith('MONO_'));
|
|
47
92
|
const envMapList = config.envMap ?? ['FAILURE'];
|
|
48
93
|
const combinedEnv = { ...baseEnv, ...envObjBase };
|
|
@@ -58,7 +103,8 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
58
103
|
console.log(`→ Executing mono command: ${configObject.name || 'Unnamed Command'}`);
|
|
59
104
|
console.log(`→ Using AWS profile: ${awsProfile}`);
|
|
60
105
|
console.log(`→ Using environment: ${options.stage ? 'stage' : 'dev'}`);
|
|
61
|
-
console.log(`→ Env files: ${envFiles.length ? envFiles.join(', ') : '(none)'}`
|
|
106
|
+
console.log(`→ Env files: ${envFiles.length ? envFiles.join(', ') : '(none)'}` +
|
|
107
|
+
(inheritedFromParent ? " (from parent mono command; this command's envFiles ignored)" : ''));
|
|
62
108
|
console.log('→ Environment variables:', envObj);
|
|
63
109
|
// Run preactions sequentially
|
|
64
110
|
for (const cmd of preactions) {
|
|
@@ -68,13 +114,36 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
68
114
|
return;
|
|
69
115
|
const bg = actions.slice(0, -1);
|
|
70
116
|
const fg = actions[actions.length - 1];
|
|
117
|
+
// A background action that fails while the foreground is still running fails the whole
|
|
118
|
+
// command: the foreground is stopped and mono exits with the background's code. Once the
|
|
119
|
+
// foreground is done, background exits are caused by our own cleanup kill and are ignored.
|
|
120
|
+
let stopping = false;
|
|
121
|
+
let fgChild;
|
|
122
|
+
let failBackground = () => { };
|
|
123
|
+
const backgroundFailed = new Promise((_, reject) => {
|
|
124
|
+
failBackground = reject;
|
|
125
|
+
});
|
|
126
|
+
backgroundFailed.catch(() => { }); // only observed through the race below
|
|
71
127
|
for (const cmd of bg) {
|
|
72
|
-
|
|
128
|
+
(0, runBackground_1.runBackground)(cmd, envObj, 'background', false, baseEnv).catch((err) => {
|
|
129
|
+
if (stopping)
|
|
130
|
+
return;
|
|
131
|
+
console.error(`✖ Background action failed: ${err?.message ?? err}`);
|
|
132
|
+
failBackground(err);
|
|
133
|
+
});
|
|
73
134
|
}
|
|
74
135
|
try {
|
|
75
|
-
await
|
|
136
|
+
await Promise.race([
|
|
137
|
+
(0, runBackground_1.runBackground)(fg, envObj, 'foreground', true, baseEnv, (child) => {
|
|
138
|
+
fgChild = child;
|
|
139
|
+
}),
|
|
140
|
+
backgroundFailed,
|
|
141
|
+
]);
|
|
76
142
|
}
|
|
77
143
|
finally {
|
|
144
|
+
stopping = true;
|
|
145
|
+
if (fgChild)
|
|
146
|
+
(0, processManager_1.killTree)(fgChild);
|
|
78
147
|
(0, processManager_1.killAllBackground)();
|
|
79
148
|
}
|
|
80
149
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failure that knows which exit code mono should end with.
|
|
3
|
+
*
|
|
4
|
+
* Every runner rejects with this, and the top-level handler in `lib/index.ts` turns it into
|
|
5
|
+
* `process.exitCode`. Nothing between the runner and that handler may swallow it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MonoCommandError extends Error {
|
|
8
|
+
readonly exitCode: number;
|
|
9
|
+
constructor(message: string, exitCode?: number);
|
|
10
|
+
}
|
|
11
|
+
/** Shell convention: a child killed by a signal exits with 128 + the signal number. */
|
|
12
|
+
export declare function exitCodeFromChild(code: number | null, signal: NodeJS.Signals | null): number;
|
|
13
|
+
export declare function childFailure(cmd: string, code: number | null, signal: NodeJS.Signals | null, detail?: string): MonoCommandError;
|
|
14
|
+
/** Exit code to use for any error reaching the top level. */
|
|
15
|
+
export declare function exitCodeOf(err: unknown): number;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;gBAEb,OAAO,EAAE,MAAM,EAAE,QAAQ,SAAI;CAM1C;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,GAAG,MAAM,CAM5F;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,EAC7B,MAAM,SAAK,GACV,gBAAgB,CAGlB;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAE/C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MonoCommandError = void 0;
|
|
7
|
+
exports.exitCodeFromChild = exitCodeFromChild;
|
|
8
|
+
exports.childFailure = childFailure;
|
|
9
|
+
exports.exitCodeOf = exitCodeOf;
|
|
10
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
11
|
+
/**
|
|
12
|
+
* A failure that knows which exit code mono should end with.
|
|
13
|
+
*
|
|
14
|
+
* Every runner rejects with this, and the top-level handler in `lib/index.ts` turns it into
|
|
15
|
+
* `process.exitCode`. Nothing between the runner and that handler may swallow it.
|
|
16
|
+
*/
|
|
17
|
+
class MonoCommandError extends Error {
|
|
18
|
+
exitCode;
|
|
19
|
+
constructor(message, exitCode = 1) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'MonoCommandError';
|
|
22
|
+
// 0 would report success for a failure, so never allow it here.
|
|
23
|
+
this.exitCode = Number.isInteger(exitCode) && exitCode > 0 ? exitCode : 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MonoCommandError = MonoCommandError;
|
|
27
|
+
/** Shell convention: a child killed by a signal exits with 128 + the signal number. */
|
|
28
|
+
function exitCodeFromChild(code, signal) {
|
|
29
|
+
if (signal) {
|
|
30
|
+
const num = node_os_1.default.constants.signals[signal];
|
|
31
|
+
return num ? 128 + num : 1;
|
|
32
|
+
}
|
|
33
|
+
return code ?? 1;
|
|
34
|
+
}
|
|
35
|
+
function childFailure(cmd, code, signal, detail = '') {
|
|
36
|
+
const how = signal ? `was killed by signal ${signal}` : `exited with code ${code}`;
|
|
37
|
+
return new MonoCommandError(`${cmd} ${how}${detail}`, exitCodeFromChild(code, signal));
|
|
38
|
+
}
|
|
39
|
+
/** Exit code to use for any error reaching the top level. */
|
|
40
|
+
function exitCodeOf(err) {
|
|
41
|
+
return err instanceof MonoCommandError ? err.exitCode : 1;
|
|
42
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type ChildProcess } from 'child_process';
|
|
2
2
|
export declare const bgChildren: Set<ChildProcess>;
|
|
3
3
|
export declare function registerBackground(child: ChildProcess): void;
|
|
4
|
+
/**
|
|
5
|
+
* Kill a child and everything it started, if it is still running.
|
|
6
|
+
* `detached` children lead their own process group on POSIX, so the whole group is signalled.
|
|
7
|
+
*/
|
|
8
|
+
export declare function killTree(child: ChildProcess, detached?: boolean): void;
|
|
4
9
|
export declare function killAllBackground(): void;
|
|
5
10
|
export declare function ensureSignalHandlers(): void;
|
|
6
11
|
//# sourceMappingURL=processManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processManager.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/processManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAGxD,eAAO,MAAM,UAAU,mBAA0B,CAAA;AAEjD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAW5D;AAOD,wBAAgB,iBAAiB,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"processManager.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/processManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAGxD,eAAO,MAAM,UAAU,mBAA0B,CAAA;AAEjD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAW5D;AAOD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,UAAQ,GAAG,IAAI,CAiBpE;AAED,wBAAgB,iBAAiB,IAAI,IAAI,CAOxC;AAGD,wBAAgB,oBAAoB,IAAI,IAAI,CA+B3C"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bgChildren = void 0;
|
|
4
4
|
exports.registerBackground = registerBackground;
|
|
5
|
+
exports.killTree = killTree;
|
|
5
6
|
exports.killAllBackground = killAllBackground;
|
|
6
7
|
exports.ensureSignalHandlers = ensureSignalHandlers;
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
@@ -23,28 +24,37 @@ function registerBackground(child) {
|
|
|
23
24
|
function isRunning(child) {
|
|
24
25
|
return Boolean(child.pid) && child.exitCode === null && child.signalCode === null;
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Kill a child and everything it started, if it is still running.
|
|
29
|
+
* `detached` children lead their own process group on POSIX, so the whole group is signalled.
|
|
30
|
+
*/
|
|
31
|
+
function killTree(child, detached = false) {
|
|
32
|
+
if (!isRunning(child))
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
if (process.platform === 'win32') {
|
|
36
|
+
(0, child_process_1.spawn)('taskkill', ['/PID', String(child.pid), '/T', '/F'], {
|
|
37
|
+
shell: true,
|
|
38
|
+
stdio: 'ignore',
|
|
39
|
+
windowsHide: true,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if (detached) {
|
|
43
|
+
process.kill(-child.pid, 'SIGTERM');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
child.kill('SIGTERM');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// ignore
|
|
51
|
+
}
|
|
52
|
+
}
|
|
26
53
|
function killAllBackground() {
|
|
27
54
|
for (const child of Array.from(exports.bgChildren)) {
|
|
28
55
|
exports.bgChildren.delete(child);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
if (process.platform === 'win32') {
|
|
33
|
-
(0, child_process_1.spawn)('taskkill', ['/PID', String(child.pid), '/T', '/F'], {
|
|
34
|
-
shell: true,
|
|
35
|
-
stdio: 'ignore',
|
|
36
|
-
windowsHide: true,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
// Registered children are always spawned `detached`, so they lead their own process
|
|
41
|
-
// group and the negative-pid form is ours to signal.
|
|
42
|
-
process.kill(-child.pid, 'SIGTERM');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
// ignore
|
|
47
|
-
}
|
|
56
|
+
// Registered children are always spawned `detached`.
|
|
57
|
+
killTree(child, true);
|
|
48
58
|
}
|
|
49
59
|
exports.bgChildren.clear();
|
|
50
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ChildProcess } from 'child_process';
|
|
2
|
+
export declare function runBackground(cmd: string, envObj?: Record<string, unknown>, logName?: string, attached?: boolean, baseEnv?: NodeJS.ProcessEnv, onSpawn?: (child: ChildProcess) => void): Promise<void>;
|
|
2
3
|
export default runBackground;
|
|
3
4
|
//# sourceMappingURL=runBackground.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runBackground.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/runBackground.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runBackground.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/runBackground.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AAexD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,SAAe,EACtB,QAAQ,UAAQ,EAChB,OAAO,GAAE,MAAM,CAAC,UAAwB,EACxC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACtC,OAAO,CAAC,IAAI,CAAC,CAsCf;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -5,6 +5,7 @@ const child_process_1 = require("child_process");
|
|
|
5
5
|
const dataLayer_1 = require("../dataLayer");
|
|
6
6
|
const processManager_1 = require("./processManager");
|
|
7
7
|
const shared_1 = require("@mono-labs/shared");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
8
9
|
function createdExpandedEnv(envObj) {
|
|
9
10
|
const expandedEnv = {};
|
|
10
11
|
for (const k of Object.keys(envObj)) {
|
|
@@ -13,7 +14,7 @@ function createdExpandedEnv(envObj) {
|
|
|
13
14
|
}
|
|
14
15
|
return expandedEnv;
|
|
15
16
|
}
|
|
16
|
-
function runBackground(cmd, envObj = {}, logName = 'background', attached = false, baseEnv = process.env) {
|
|
17
|
+
function runBackground(cmd, envObj = {}, logName = 'background', attached = false, baseEnv = process.env, onSpawn) {
|
|
17
18
|
const isWin = process.platform === 'win32';
|
|
18
19
|
// Replace ${field} tokens in env values using dataLayer
|
|
19
20
|
const expandedEnv = createdExpandedEnv(envObj);
|
|
@@ -36,15 +37,14 @@ function runBackground(cmd, envObj = {}, logName = 'background', attached = fals
|
|
|
36
37
|
// time `runMonoCommand`'s `finally` fires, its pid is the OS's to reuse.
|
|
37
38
|
if (!attached)
|
|
38
39
|
(0, processManager_1.registerBackground)(child);
|
|
40
|
+
onSpawn?.(child);
|
|
39
41
|
child.once('error', (err) => {
|
|
40
42
|
reject(err);
|
|
41
43
|
});
|
|
42
44
|
child.once('exit', (code, signal) => {
|
|
43
|
-
if (signal)
|
|
44
|
-
return reject(new Error(`${cmd} exited via signal ${signal}`));
|
|
45
|
-
if (code === 0)
|
|
45
|
+
if (code === 0 && !signal)
|
|
46
46
|
return resolve();
|
|
47
|
-
reject(
|
|
47
|
+
reject((0, errors_1.childFailure)(outCmd, code, signal));
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runForeground.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/runForeground.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runForeground.d.ts","sourceRoot":"","sources":["../../../../../lib/commands/build-process/runners/runForeground.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,MAAM,CAAC,UAAe,EAC9B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACtC,OAAO,GAAE,MAAM,CAAC,UAAwB,GACtC,OAAO,CAAC,MAAM,CAAC,CA0CjB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.runForeground = runForeground;
|
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const dataLayer_1 = require("../dataLayer");
|
|
6
6
|
const filterUnwantedEnvVars_1 = require("../../../filterUnwantedEnvVars");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
7
8
|
// Regex to capture tokens like: {out:field value}
|
|
8
9
|
const TOKEN_RX = /\{out:(?<field>[^\s}]+)\s+(?<value>[^\s}]+)\}/g;
|
|
9
10
|
/**
|
|
@@ -41,11 +42,9 @@ function runForeground(cmd, envObj = {}, _options = {}, baseEnv = process.env) {
|
|
|
41
42
|
(0, dataLayer_1.setData)(groups.field, groups.value);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
if (signal)
|
|
45
|
-
return reject(new Error(`${cmd} exited via signal ${signal}`));
|
|
46
|
-
if (code === 0)
|
|
45
|
+
if (code === 0 && !signal)
|
|
47
46
|
return resolve(lastLine);
|
|
48
|
-
reject(
|
|
47
|
+
reject((0, errors_1.childFailure)(newCmd, code, signal, `. Last line: ${lastLine}`));
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../../lib/commands/prune/prune.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../../lib/commands/prune/prune.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,SA+CxB"}
|
|
@@ -25,7 +25,7 @@ function pruneRepo() {
|
|
|
25
25
|
const branchesToDelete = localBranches.filter((branch) => !remoteBranches.includes(branch));
|
|
26
26
|
if (branchesToDelete.length === 0) {
|
|
27
27
|
log('No local branches to delete.');
|
|
28
|
-
|
|
28
|
+
return;
|
|
29
29
|
}
|
|
30
30
|
// Delete untracked local branches
|
|
31
31
|
log('Deleting local branches that are not on origin...');
|
|
@@ -38,6 +38,7 @@ function pruneRepo() {
|
|
|
38
38
|
catch (caught) {
|
|
39
39
|
const error = caught;
|
|
40
40
|
err(`Failed to delete branch ${branch}:`, error.message ?? String(caught));
|
|
41
|
+
process.exitCode = 1;
|
|
41
42
|
}
|
|
42
43
|
});
|
|
43
44
|
log('Cleanup complete!');
|
|
@@ -45,5 +46,6 @@ function pruneRepo() {
|
|
|
45
46
|
catch (caught) {
|
|
46
47
|
const error = caught;
|
|
47
48
|
err('An error occurred:', error.message ?? String(caught));
|
|
49
|
+
process.exitCode = 1;
|
|
48
50
|
}
|
|
49
51
|
}
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAeA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,gCAAgC,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -12,10 +12,12 @@ const app_1 = require("./app");
|
|
|
12
12
|
require("./commands/prune/index");
|
|
13
13
|
require("./commands/build-process/index");
|
|
14
14
|
const loadFromRoot_1 = require("./commands/loadFromRoot");
|
|
15
|
+
const errors_1 = require("./commands/build-process/runners/errors");
|
|
15
16
|
const test_1 = require("./commands/build-process/test");
|
|
16
17
|
const { config } = (0, loadFromRoot_1.getMonoConfig)();
|
|
17
|
-
//
|
|
18
|
-
|
|
18
|
+
// MONOLABS_ENV_FILES (the selection of a parent mono command) wins, then .mono/config.json
|
|
19
|
+
// `envFiles`, then .env + .env.local
|
|
20
|
+
(0, project_1.loadMergedEnv)((0, project_1.envFilesFromEnv)() ?? config.envFiles);
|
|
19
21
|
const homeBin = node_path_1.default.join(node_os_1.default.homedir(), 'bin');
|
|
20
22
|
const PATH = [homeBin, process.env.PATH].filter(Boolean).join(node_path_1.default.delimiter);
|
|
21
23
|
const workspacemap = config.workspace?.packageMaps || {};
|
|
@@ -36,22 +38,33 @@ app_1.program.on('command:*', (operands) => {
|
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
40
|
const args = ['workspace', workspace, ...rest];
|
|
41
|
+
// Every child (workspace preactions and the yarn fallback) gets the full env, injected values included
|
|
42
|
+
const childEnv = {
|
|
43
|
+
...process.env,
|
|
44
|
+
...envObj,
|
|
45
|
+
PATH,
|
|
46
|
+
[project_1.ENV_FILES_VAR]: (0, project_1.getLoadedEnvFiles)().join(node_path_1.default.delimiter),
|
|
47
|
+
[project_1.INJECTED_KEYS_VAR]: (0, project_1.getInjectedEnvKeys)().join(','),
|
|
48
|
+
};
|
|
39
49
|
console.error(`Unknown command. Falling back2 to: yarn ${args.join(' ')}`);
|
|
40
|
-
(0, test_1.executeCommandsIfWorkspaceAction)(args, preactions,
|
|
50
|
+
(0, test_1.executeCommandsIfWorkspaceAction)(args, preactions, childEnv);
|
|
41
51
|
const child = (0, node_child_process_1.spawn)('yarn', args, {
|
|
42
52
|
stdio: 'inherit',
|
|
43
53
|
shell: process.platform === 'win32',
|
|
44
|
-
env:
|
|
45
|
-
...process.env,
|
|
46
|
-
...envObj,
|
|
47
|
-
PATH,
|
|
48
|
-
[project_1.ENV_FILES_VAR]: (0, project_1.getLoadedEnvFiles)().join(node_path_1.default.delimiter),
|
|
49
|
-
[project_1.INJECTED_KEYS_VAR]: (0, project_1.getInjectedEnvKeys)().join(','),
|
|
50
|
-
},
|
|
54
|
+
env: childEnv,
|
|
51
55
|
});
|
|
52
|
-
child.on('
|
|
56
|
+
child.on('error', (err) => {
|
|
57
|
+
console.error(`✖ mono: failed to start yarn: ${err.message}`);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
});
|
|
60
|
+
child.on('exit', (code, signal) => {
|
|
53
61
|
(0, shared_1.writeLog)('Child process exited with code:', code);
|
|
54
|
-
process.exitCode = code
|
|
62
|
+
process.exitCode = (0, errors_1.exitCodeFromChild)(code, signal);
|
|
55
63
|
});
|
|
56
64
|
});
|
|
57
|
-
|
|
65
|
+
// The single place where a mono failure becomes an exit code. Command actions are async, so
|
|
66
|
+
// parseAsync is required: with parse() a rejected action is dropped and mono exits 0.
|
|
67
|
+
app_1.program.parseAsync().catch((err) => {
|
|
68
|
+
console.error(`✖ mono: ${err?.message ?? err}`);
|
|
69
|
+
process.exitCode = (0, errors_1.exitCodeOf)(err);
|
|
70
|
+
});
|