@mono-labs/cli 0.1.288 → 0.1.290
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 +17 -0
- package/dist/lib/commands/build-process/buildBaseEnv.d.ts.map +1 -0
- package/dist/lib/commands/build-process/buildBaseEnv.js +52 -0
- package/dist/lib/commands/build-process/cliFactory.d.ts +2 -0
- 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.map +1 -1
- package/dist/lib/commands/build-process/runMonoCommand.js +32 -13
- 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 +6 -6
- package/dist/lib/commands/build-process/runners/runForeground.d.ts +1 -1
- package/dist/lib/commands/build-process/runners/runForeground.d.ts.map +1 -1
- package/dist/lib/commands/build-process/runners/runForeground.js +5 -6
- 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 +23 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/build-process/buildBaseEnv.ts +75 -0
- package/lib/commands/build-process/cliFactory.ts +20 -19
- package/lib/commands/build-process/runMonoCommand.ts +33 -11
- 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 +9 -6
- package/lib/commands/build-process/runners/runForeground.ts +6 -8
- package/lib/commands/prune/prune.ts +3 -1
- package/lib/index.ts +32 -8
- package/package.json +4 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type BaseEnvResult = {
|
|
2
|
+
/** Environment children start from (real shell vars + this command's env files). */
|
|
3
|
+
baseEnv: NodeJS.ProcessEnv;
|
|
4
|
+
/** Merged values from this command's env files, used to resolve `$KEY` refs. */
|
|
5
|
+
keymap: Record<string, string>;
|
|
6
|
+
/** Absolute paths of the env files considered for this command. */
|
|
7
|
+
files: string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Build the base environment for a mono command, honoring a per-command `envFiles` list.
|
|
11
|
+
*
|
|
12
|
+
* Without `envFiles`, the files loaded at startup are kept as-is. With it, keys injected at
|
|
13
|
+
* startup are stripped and the command's own files are loaded instead (real shell vars still win).
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildBaseEnv(configObject: any, globalConfig?: any): BaseEnvResult;
|
|
16
|
+
export default buildBaseEnv;
|
|
17
|
+
//# sourceMappingURL=buildBaseEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildBaseEnv.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/buildBaseEnv.ts"],"names":[],"mappings":"AAaA,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;CAChB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,GAAG,EAAE,YAAY,GAAE,GAAQ,GAAG,aAAa,CA4CrF;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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.buildBaseEnv = buildBaseEnv;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const project_1 = require("@mono-labs/project");
|
|
9
|
+
const dataLayer_1 = require("./dataLayer");
|
|
10
|
+
/**
|
|
11
|
+
* Build the base environment for a mono command, honoring a per-command `envFiles` list.
|
|
12
|
+
*
|
|
13
|
+
* Without `envFiles`, the files loaded at startup are kept as-is. With it, keys injected at
|
|
14
|
+
* startup are stripped and the command's own files are loaded instead (real shell vars still win).
|
|
15
|
+
*/
|
|
16
|
+
function buildBaseEnv(configObject, globalConfig = {}) {
|
|
17
|
+
const commandFiles = configObject?.envFiles;
|
|
18
|
+
if (commandFiles === undefined) {
|
|
19
|
+
const startupList = globalConfig?.envFiles ?? (0, project_1.envFilesFromEnv)() ?? project_1.DEFAULT_ENV_FILES;
|
|
20
|
+
const files = (0, project_1.getLoadedEnvFiles)();
|
|
21
|
+
const injected = (0, project_1.getInjectedEnvKeys)();
|
|
22
|
+
return {
|
|
23
|
+
baseEnv: {
|
|
24
|
+
...process.env,
|
|
25
|
+
[project_1.ENV_FILES_VAR]: files.join(node_path_1.default.delimiter),
|
|
26
|
+
[project_1.INJECTED_KEYS_VAR]: injected.join(','),
|
|
27
|
+
},
|
|
28
|
+
keymap: (0, project_1.readEnvFiles)(startupList),
|
|
29
|
+
files,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(commandFiles)) {
|
|
33
|
+
throw new Error(`"envFiles" for ${configObject?.name ?? 'command'} must be an array of file paths`);
|
|
34
|
+
}
|
|
35
|
+
const list = commandFiles.map((f) => String((0, dataLayer_1.replaceTokens)(String(f))));
|
|
36
|
+
const keymap = (0, project_1.readEnvFiles)(list);
|
|
37
|
+
const files = (0, project_1.resolveEnvFiles)(list).map((f) => f.path);
|
|
38
|
+
const baseEnv = { ...process.env };
|
|
39
|
+
for (const key of (0, project_1.getInjectedEnvKeys)())
|
|
40
|
+
delete baseEnv[key];
|
|
41
|
+
const injected = [];
|
|
42
|
+
for (const [key, value] of Object.entries(keymap)) {
|
|
43
|
+
if (baseEnv[key] === undefined) {
|
|
44
|
+
baseEnv[key] = value;
|
|
45
|
+
injected.push(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
baseEnv[project_1.ENV_FILES_VAR] = files.join(node_path_1.default.delimiter);
|
|
49
|
+
baseEnv[project_1.INJECTED_KEYS_VAR] = injected.join(',');
|
|
50
|
+
return { baseEnv, keymap, files };
|
|
51
|
+
}
|
|
52
|
+
exports.default = buildBaseEnv;
|
|
@@ -19,6 +19,8 @@ type MonoFileDefinition = {
|
|
|
19
19
|
allowAll?: boolean;
|
|
20
20
|
}>;
|
|
21
21
|
environments?: Record<string, Record<string, unknown>>;
|
|
22
|
+
/** Env files to load for this command, in order (later wins). Defaults to config.json envFiles, then [.env, .env.local]. */
|
|
23
|
+
envFiles?: string[];
|
|
22
24
|
preactions?: string[];
|
|
23
25
|
actions?: string[];
|
|
24
26
|
};
|
|
@@ -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,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runMonoCommand.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/runMonoCommand.ts"],"names":[],"mappings":"AASA,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,CAUlD;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"runMonoCommand.d.ts","sourceRoot":"","sources":["../../../../lib/commands/build-process/runMonoCommand.ts"],"names":[],"mappings":"AASA,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,CAUlD;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFxF;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getAllowAllKeys = getAllowAllKeys;
|
|
7
4
|
exports.runMonoCommand = runMonoCommand;
|
|
@@ -9,8 +6,7 @@ const runForeground_1 = require("./runners/runForeground");
|
|
|
9
6
|
const runBackground_1 = require("./runners/runBackground");
|
|
10
7
|
const processManager_1 = require("./runners/processManager");
|
|
11
8
|
const loadFromRoot_1 = require("../loadFromRoot");
|
|
12
|
-
const
|
|
13
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const buildBaseEnv_1 = require("./buildBaseEnv");
|
|
14
10
|
const dataLayer_1 = require("./dataLayer");
|
|
15
11
|
const shared_1 = require("@mono-labs/shared");
|
|
16
12
|
function getAllowAllKeys(cfg) {
|
|
@@ -33,9 +29,8 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
33
29
|
const devConfig = configObject.environments?.dev ?? {};
|
|
34
30
|
(0, shared_1.writeLog)('configObject:', JSON.stringify(configObject, null, 2));
|
|
35
31
|
(0, dataLayer_1.mergeData)({ ...options });
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
const keymap = (0, readEnv_1.parseEnvFile)(envPath);
|
|
32
|
+
// 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);
|
|
39
34
|
const prodConfig = configObject.environments?.prod ?? {};
|
|
40
35
|
const awsProfile = process.env.CDK_DEPLOY_PROFILE || process.env.AWS_PROFILE || 'default';
|
|
41
36
|
const envObjBase = options.prod ? { ...prodConfig } : { ...devConfig };
|
|
@@ -48,9 +43,9 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
48
43
|
}
|
|
49
44
|
});
|
|
50
45
|
envObjBase.AWS_PROFILE = awsProfile;
|
|
51
|
-
const envKeys = Object.keys(
|
|
46
|
+
const envKeys = Object.keys(baseEnv).filter((k) => k.startsWith('MONO_'));
|
|
52
47
|
const envMapList = config.envMap ?? ['FAILURE'];
|
|
53
|
-
const combinedEnv = { ...
|
|
48
|
+
const combinedEnv = { ...baseEnv, ...envObjBase };
|
|
54
49
|
const envMapVals = {};
|
|
55
50
|
envKeys.forEach((k) => {
|
|
56
51
|
envMapList.forEach((item) => {
|
|
@@ -63,22 +58,46 @@ async function runMonoCommand(configObject, options = {}) {
|
|
|
63
58
|
console.log(`→ Executing mono command: ${configObject.name || 'Unnamed Command'}`);
|
|
64
59
|
console.log(`→ Using AWS profile: ${awsProfile}`);
|
|
65
60
|
console.log(`→ Using environment: ${options.stage ? 'stage' : 'dev'}`);
|
|
61
|
+
console.log(`→ Env files: ${envFiles.length ? envFiles.join(', ') : '(none)'}`);
|
|
66
62
|
console.log('→ Environment variables:', envObj);
|
|
67
63
|
// Run preactions sequentially
|
|
68
64
|
for (const cmd of preactions) {
|
|
69
|
-
await (0, runForeground_1.runForeground)(cmd, envObj);
|
|
65
|
+
await (0, runForeground_1.runForeground)(cmd, envObj, {}, baseEnv);
|
|
70
66
|
}
|
|
71
67
|
if (actions.length === 0)
|
|
72
68
|
return;
|
|
73
69
|
const bg = actions.slice(0, -1);
|
|
74
70
|
const fg = actions[actions.length - 1];
|
|
71
|
+
// A background action that fails while the foreground is still running fails the whole
|
|
72
|
+
// command: the foreground is stopped and mono exits with the background's code. Once the
|
|
73
|
+
// foreground is done, background exits are caused by our own cleanup kill and are ignored.
|
|
74
|
+
let stopping = false;
|
|
75
|
+
let fgChild;
|
|
76
|
+
let failBackground = () => { };
|
|
77
|
+
const backgroundFailed = new Promise((_, reject) => {
|
|
78
|
+
failBackground = reject;
|
|
79
|
+
});
|
|
80
|
+
backgroundFailed.catch(() => { }); // only observed through the race below
|
|
75
81
|
for (const cmd of bg) {
|
|
76
|
-
|
|
82
|
+
(0, runBackground_1.runBackground)(cmd, envObj, 'background', false, baseEnv).catch((err) => {
|
|
83
|
+
if (stopping)
|
|
84
|
+
return;
|
|
85
|
+
console.error(`✖ Background action failed: ${err?.message ?? err}`);
|
|
86
|
+
failBackground(err);
|
|
87
|
+
});
|
|
77
88
|
}
|
|
78
89
|
try {
|
|
79
|
-
await
|
|
90
|
+
await Promise.race([
|
|
91
|
+
(0, runBackground_1.runBackground)(fg, envObj, 'foreground', true, baseEnv, (child) => {
|
|
92
|
+
fgChild = child;
|
|
93
|
+
}),
|
|
94
|
+
backgroundFailed,
|
|
95
|
+
]);
|
|
80
96
|
}
|
|
81
97
|
finally {
|
|
98
|
+
stopping = true;
|
|
99
|
+
if (fgChild)
|
|
100
|
+
(0, processManager_1.killTree)(fgChild);
|
|
82
101
|
(0, processManager_1.killAllBackground)();
|
|
83
102
|
}
|
|
84
103
|
}
|
|
@@ -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) {
|
|
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);
|
|
@@ -25,7 +26,7 @@ function runBackground(cmd, envObj = {}, logName = 'background', attached = fals
|
|
|
25
26
|
const child = (0, child_process_1.spawn)(outCmd, {
|
|
26
27
|
shell: true,
|
|
27
28
|
stdio: attached ? 'inherit' : 'ignore',
|
|
28
|
-
env: { ...
|
|
29
|
+
env: { ...baseEnv, ...expandedEnv },
|
|
29
30
|
detached: !attached && !isWin,
|
|
30
31
|
windowsHide: !attached && isWin,
|
|
31
32
|
});
|
|
@@ -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
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Run a command in the foreground, capturing stdout/stderr. Extracts token patterns
|
|
3
3
|
* of the form {out:field value} and stores them in the shared dataLayer.
|
|
4
4
|
*/
|
|
5
|
-
export declare function runForeground(cmd: string, envObj?: NodeJS.ProcessEnv, _options?: Record<string, unknown
|
|
5
|
+
export declare function runForeground(cmd: string, envObj?: NodeJS.ProcessEnv, _options?: Record<string, unknown>, baseEnv?: NodeJS.ProcessEnv): Promise<string>;
|
|
6
6
|
export default runForeground;
|
|
7
7
|
//# sourceMappingURL=runForeground.d.ts.map
|
|
@@ -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,14 +4,15 @@ 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
|
/**
|
|
10
11
|
* Run a command in the foreground, capturing stdout/stderr. Extracts token patterns
|
|
11
12
|
* of the form {out:field value} and stores them in the shared dataLayer.
|
|
12
13
|
*/
|
|
13
|
-
function runForeground(cmd, envObj = {}, _options = {}) {
|
|
14
|
-
const filteredEnv = (0, filterUnwantedEnvVars_1.filterUnwantedEnvVars)(
|
|
14
|
+
function runForeground(cmd, envObj = {}, _options = {}, baseEnv = process.env) {
|
|
15
|
+
const filteredEnv = (0, filterUnwantedEnvVars_1.filterUnwantedEnvVars)(baseEnv);
|
|
15
16
|
const newEnv = { ...filteredEnv, ...envObj };
|
|
16
17
|
const newCmd = (0, dataLayer_1.replaceTokens)(cmd, newEnv);
|
|
17
18
|
return new Promise((resolve, reject) => {
|
|
@@ -41,11 +42,9 @@ function runForeground(cmd, envObj = {}, _options = {}) {
|
|
|
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":"AAcA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,gCAAgC,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -12,11 +12,13 @@ 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
|
-
(0,
|
|
17
|
+
const { config } = (0, loadFromRoot_1.getMonoConfig)();
|
|
18
|
+
// Global default from .mono/config.json `envFiles`; falls back to MONOLABS_ENV_FILES, then .env + .env.local
|
|
19
|
+
(0, project_1.loadMergedEnv)(config.envFiles);
|
|
17
20
|
const homeBin = node_path_1.default.join(node_os_1.default.homedir(), 'bin');
|
|
18
21
|
const PATH = [homeBin, process.env.PATH].filter(Boolean).join(node_path_1.default.delimiter);
|
|
19
|
-
const { config } = (0, loadFromRoot_1.getMonoConfig)();
|
|
20
22
|
const workspacemap = config.workspace?.packageMaps || {};
|
|
21
23
|
const preactions = config.workspace?.preactions || [];
|
|
22
24
|
const envMapList = config.envMap ?? ['FAILURE'];
|
|
@@ -40,11 +42,26 @@ app_1.program.on('command:*', (operands) => {
|
|
|
40
42
|
const child = (0, node_child_process_1.spawn)('yarn', args, {
|
|
41
43
|
stdio: 'inherit',
|
|
42
44
|
shell: process.platform === 'win32',
|
|
43
|
-
env: {
|
|
45
|
+
env: {
|
|
46
|
+
...process.env,
|
|
47
|
+
...envObj,
|
|
48
|
+
PATH,
|
|
49
|
+
[project_1.ENV_FILES_VAR]: (0, project_1.getLoadedEnvFiles)().join(node_path_1.default.delimiter),
|
|
50
|
+
[project_1.INJECTED_KEYS_VAR]: (0, project_1.getInjectedEnvKeys)().join(','),
|
|
51
|
+
},
|
|
44
52
|
});
|
|
45
|
-
child.on('
|
|
53
|
+
child.on('error', (err) => {
|
|
54
|
+
console.error(`✖ mono: failed to start yarn: ${err.message}`);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
});
|
|
57
|
+
child.on('exit', (code, signal) => {
|
|
46
58
|
(0, shared_1.writeLog)('Child process exited with code:', code);
|
|
47
|
-
process.exitCode = code
|
|
59
|
+
process.exitCode = (0, errors_1.exitCodeFromChild)(code, signal);
|
|
48
60
|
});
|
|
49
61
|
});
|
|
50
|
-
|
|
62
|
+
// The single place where a mono failure becomes an exit code. Command actions are async, so
|
|
63
|
+
// parseAsync is required: with parse() a rejected action is dropped and mono exits 0.
|
|
64
|
+
app_1.program.parseAsync().catch((err) => {
|
|
65
|
+
console.error(`✖ mono: ${err?.message ?? err}`);
|
|
66
|
+
process.exitCode = (0, errors_1.exitCodeOf)(err);
|
|
67
|
+
});
|