@powerlines/engine 0.47.4 → 0.49.2
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/api/build.cjs +66 -0
- package/dist/api/build.d.cts +14 -0
- package/dist/api/build.d.cts.map +1 -0
- package/dist/api/build.d.mts +14 -0
- package/dist/api/build.d.mts.map +1 -0
- package/dist/api/build.mjs +64 -0
- package/dist/api/build.mjs.map +1 -0
- package/dist/api/clean.cjs +28 -0
- package/dist/api/clean.d.cts +14 -0
- package/dist/api/clean.d.cts.map +1 -0
- package/dist/api/clean.d.mts +14 -0
- package/dist/api/clean.d.mts.map +1 -0
- package/dist/api/clean.mjs +28 -0
- package/dist/api/clean.mjs.map +1 -0
- package/dist/api/create.cjs +59 -0
- package/dist/api/create.d.cts +14 -0
- package/dist/api/create.d.cts.map +1 -0
- package/dist/api/create.d.mts +14 -0
- package/dist/api/create.d.mts.map +1 -0
- package/dist/api/create.mjs +57 -0
- package/dist/api/create.mjs.map +1 -0
- package/dist/api/deploy.cjs +24 -0
- package/dist/api/deploy.d.cts +17 -0
- package/dist/api/deploy.d.cts.map +1 -0
- package/dist/api/deploy.d.mts +17 -0
- package/dist/api/deploy.d.mts.map +1 -0
- package/dist/api/deploy.mjs +24 -0
- package/dist/api/deploy.mjs.map +1 -0
- package/dist/api/docs.cjs +24 -0
- package/dist/api/docs.d.cts +17 -0
- package/dist/api/docs.d.cts.map +1 -0
- package/dist/api/docs.d.mts +17 -0
- package/dist/api/docs.d.mts.map +1 -0
- package/dist/api/docs.mjs +24 -0
- package/dist/api/docs.mjs.map +1 -0
- package/dist/api/lint.cjs +27 -0
- package/dist/api/lint.d.cts +17 -0
- package/dist/api/lint.d.cts.map +1 -0
- package/dist/api/lint.d.mts +17 -0
- package/dist/api/lint.d.mts.map +1 -0
- package/dist/api/lint.mjs +27 -0
- package/dist/api/lint.mjs.map +1 -0
- package/dist/api/prepare.cjs +68 -0
- package/dist/api/prepare.d.cts +14 -0
- package/dist/api/prepare.d.cts.map +1 -0
- package/dist/api/prepare.d.mts +14 -0
- package/dist/api/prepare.d.mts.map +1 -0
- package/dist/api/prepare.mjs +68 -0
- package/dist/api/prepare.mjs.map +1 -0
- package/dist/api/test.cjs +27 -0
- package/dist/api/test.d.cts +17 -0
- package/dist/api/test.d.cts.map +1 -0
- package/dist/api/test.d.mts +17 -0
- package/dist/api/test.d.mts.map +1 -0
- package/dist/api/test.mjs +27 -0
- package/dist/api/test.mjs.map +1 -0
- package/dist/api/types.cjs +70 -0
- package/dist/api/types.d.cts +17 -0
- package/dist/api/types.d.cts.map +1 -0
- package/dist/api/types.d.mts +17 -0
- package/dist/api/types.d.mts.map +1 -0
- package/dist/api/types.mjs +70 -0
- package/dist/api/types.mjs.map +1 -0
- package/dist/api-BgyEi2hF.d.mts +138 -0
- package/dist/api-BgyEi2hF.d.mts.map +1 -0
- package/dist/api-DcHfCjQK.d.cts +138 -0
- package/dist/api-DcHfCjQK.d.cts.map +1 -0
- package/dist/api.cjs +39 -1268
- package/dist/api.d.cts +11 -300
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +11 -300
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +31 -1264
- package/dist/api.mjs.map +1 -1
- package/dist/config-ByLyzMI0.d.mts +204 -0
- package/dist/config-ByLyzMI0.d.mts.map +1 -0
- package/dist/config-DKEmqMrh.d.cts +204 -0
- package/dist/config-DKEmqMrh.d.cts.map +1 -0
- package/dist/context/engine-context.cjs +177 -0
- package/dist/context/engine-context.d.cts +2 -0
- package/dist/context/engine-context.d.mts +2 -0
- package/dist/context/engine-context.mjs +175 -0
- package/dist/context/engine-context.mjs.map +1 -0
- package/dist/context/index.cjs +2 -9
- package/dist/context/index.d.cts +2 -150
- package/dist/context/index.d.mts +2 -150
- package/dist/context/index.mjs +2 -4
- package/dist/context-D0_a0kRO.d.cts +149 -0
- package/dist/context-D0_a0kRO.d.cts.map +1 -0
- package/dist/context-DcXV6_GL.d.mts +149 -0
- package/dist/context-DcXV6_GL.d.mts.map +1 -0
- package/dist/engine-Dz6BvkFY.cjs +590 -0
- package/dist/engine-context-B8K6Jtkk.d.cts +53 -0
- package/dist/engine-context-B8K6Jtkk.d.cts.map +1 -0
- package/dist/engine-context-DKlA5Pgu.d.mts +53 -0
- package/dist/engine-context-DKlA5Pgu.d.mts.map +1 -0
- package/dist/engine-q6YKXXcB.mjs +571 -0
- package/dist/engine-q6YKXXcB.mjs.map +1 -0
- package/dist/engine.cjs +6 -0
- package/dist/engine.d.cts +143 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.mts +143 -0
- package/dist/engine.d.mts.map +1 -0
- package/dist/engine.mjs +3 -0
- package/dist/helpers/create-execution-host.cjs +57 -0
- package/dist/helpers/create-execution-host.d.cts +20 -0
- package/dist/helpers/create-execution-host.d.cts.map +1 -0
- package/dist/helpers/create-execution-host.d.mts +20 -0
- package/dist/helpers/create-execution-host.d.mts.map +1 -0
- package/dist/helpers/create-execution-host.mjs +57 -0
- package/dist/helpers/create-execution-host.mjs.map +1 -0
- package/dist/helpers/finalize.cjs +26 -0
- package/dist/helpers/finalize.d.cts +12 -0
- package/dist/helpers/finalize.d.cts.map +1 -0
- package/dist/helpers/finalize.d.mts +12 -0
- package/dist/helpers/finalize.d.mts.map +1 -0
- package/dist/helpers/finalize.mjs +26 -0
- package/dist/helpers/finalize.mjs.map +1 -0
- package/dist/helpers/index.cjs +12 -0
- package/dist/helpers/index.d.cts +5 -0
- package/dist/helpers/index.d.mts +5 -0
- package/dist/helpers/index.mjs +6 -0
- package/dist/helpers/rpc.cjs +139 -0
- package/dist/helpers/rpc.d.cts +7 -0
- package/dist/helpers/rpc.d.cts.map +1 -0
- package/dist/helpers/rpc.d.mts +7 -0
- package/dist/helpers/rpc.d.mts.map +1 -0
- package/dist/helpers/rpc.mjs +139 -0
- package/dist/helpers/rpc.mjs.map +1 -0
- package/dist/helpers/stream.cjs +119 -0
- package/dist/helpers/stream.d.cts +45 -0
- package/dist/helpers/stream.d.cts.map +1 -0
- package/dist/helpers/stream.d.mts +45 -0
- package/dist/helpers/stream.d.mts.map +1 -0
- package/dist/helpers/stream.mjs +117 -0
- package/dist/helpers/stream.mjs.map +1 -0
- package/dist/index-BVVgDSdq.d.cts +1 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.cjs +8 -748
- package/dist/index.d.cts +6 -140
- package/dist/index.d.mts +6 -140
- package/dist/index.mjs +4 -747
- package/package.json +102 -132
- package/dist/_internal/worker.cjs +0 -5192
- package/dist/_internal/worker.d.cts +0 -46
- package/dist/_internal/worker.d.cts.map +0 -1
- package/dist/_internal/worker.d.mts +0 -46
- package/dist/_internal/worker.d.mts.map +0 -1
- package/dist/_internal/worker.mjs +0 -5153
- package/dist/_internal/worker.mjs.map +0 -1
- package/dist/base-context-DLemGRbd.cjs +0 -322
- package/dist/base-context-DUha4Lz-.mjs +0 -315
- package/dist/base-context-DUha4Lz-.mjs.map +0 -1
- package/dist/context/index.d.cts.map +0 -1
- package/dist/context/index.d.mts.map +0 -1
- package/dist/engine-context-BfFiKN53.mjs +0 -86
- package/dist/engine-context-BfFiKN53.mjs.map +0 -1
- package/dist/engine-context-D0y88i_J.cjs +0 -91
- package/dist/execution-context-CE5H90Um.mjs +0 -2845
- package/dist/execution-context-CE5H90Um.mjs.map +0 -1
- package/dist/execution-context-CnyaM3Ul.cjs +0 -2889
- package/dist/execution-context-NyDjVZ6T.d.cts +0 -647
- package/dist/execution-context-NyDjVZ6T.d.cts.map +0 -1
- package/dist/execution-context-YrjFeD9k.d.mts +0 -647
- package/dist/execution-context-YrjFeD9k.d.mts.map +0 -1
- package/dist/fs-CeEdzPKE.cjs +0 -262
- package/dist/fs-Dcle8lUp.mjs +0 -226
- package/dist/fs-Dcle8lUp.mjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/rpc/client.cjs +0 -74
- package/dist/rpc/client.d.cts +0 -31
- package/dist/rpc/client.d.cts.map +0 -1
- package/dist/rpc/client.d.mts +0 -31
- package/dist/rpc/client.d.mts.map +0 -1
- package/dist/rpc/client.mjs +0 -71
- package/dist/rpc/client.mjs.map +0 -1
- package/dist/rpc/serialization.cjs +0 -82
- package/dist/rpc/serialization.d.cts +0 -46
- package/dist/rpc/serialization.d.cts.map +0 -1
- package/dist/rpc/serialization.d.mts +0 -46
- package/dist/rpc/serialization.d.mts.map +0 -1
- package/dist/rpc/serialization.mjs +0 -76
- package/dist/rpc/serialization.mjs.map +0 -1
- package/dist/rpc/server.cjs +0 -69
- package/dist/rpc/server.d.cts +0 -29
- package/dist/rpc/server.d.cts.map +0 -1
- package/dist/rpc/server.d.mts +0 -29
- package/dist/rpc/server.d.mts.map +0 -1
- package/dist/rpc/server.mjs +0 -66
- package/dist/rpc/server.mjs.map +0 -1
- package/dist/rpc/types.cjs +0 -0
- package/dist/rpc/types.d.cts +0 -70
- package/dist/rpc/types.d.cts.map +0 -1
- package/dist/rpc/types.d.mts +0 -70
- package/dist/rpc/types.d.mts.map +0 -1
- package/dist/rpc/types.mjs +0 -1
- package/dist/schemas.cjs +0 -9
- package/dist/schemas.d.cts +0 -127
- package/dist/schemas.d.cts.map +0 -1
- package/dist/schemas.d.mts +0 -127
- package/dist/schemas.d.mts.map +0 -1
- package/dist/schemas.mjs +0 -3
- package/dist/storage/base.cjs +0 -216
- package/dist/storage/base.d.cts +0 -199
- package/dist/storage/base.d.cts.map +0 -1
- package/dist/storage/base.d.mts +0 -199
- package/dist/storage/base.d.mts.map +0 -1
- package/dist/storage/base.mjs +0 -215
- package/dist/storage/base.mjs.map +0 -1
- package/dist/storage/file-system.cjs +0 -180
- package/dist/storage/file-system.d.cts +0 -127
- package/dist/storage/file-system.d.cts.map +0 -1
- package/dist/storage/file-system.d.mts +0 -127
- package/dist/storage/file-system.d.mts.map +0 -1
- package/dist/storage/file-system.mjs +0 -179
- package/dist/storage/file-system.mjs.map +0 -1
- package/dist/storage/helpers.cjs +0 -37
- package/dist/storage/helpers.d.cts +0 -25
- package/dist/storage/helpers.d.cts.map +0 -1
- package/dist/storage/helpers.d.mts +0 -25
- package/dist/storage/helpers.d.mts.map +0 -1
- package/dist/storage/helpers.mjs +0 -34
- package/dist/storage/helpers.mjs.map +0 -1
- package/dist/storage/index.cjs +0 -12
- package/dist/storage/index.d.cts +0 -5
- package/dist/storage/index.d.mts +0 -5
- package/dist/storage/index.mjs +0 -6
- package/dist/storage/virtual.cjs +0 -98
- package/dist/storage/virtual.d.cts +0 -80
- package/dist/storage/virtual.d.cts.map +0 -1
- package/dist/storage/virtual.d.mts +0 -80
- package/dist/storage/virtual.d.mts.map +0 -1
- package/dist/storage/virtual.mjs +0 -97
- package/dist/storage/virtual.mjs.map +0 -1
- package/dist/ts-morph-BbM83PT9.cjs +0 -114
- package/dist/ts-morph-C6YBNc46.mjs +0 -102
- package/dist/ts-morph-C6YBNc46.mjs.map +0 -1
- package/dist/tsconfig-DeKMGasE.cjs +0 -198
- package/dist/tsconfig-HzJsMUrr.mjs +0 -155
- package/dist/tsconfig-HzJsMUrr.mjs.map +0 -1
- package/dist/typescript/index.cjs +0 -13
- package/dist/typescript/index.d.cts +0 -106
- package/dist/typescript/index.d.cts.map +0 -1
- package/dist/typescript/index.d.mts +0 -106
- package/dist/typescript/index.d.mts.map +0 -1
- package/dist/typescript/index.mjs +0 -4
- /package/dist/{chunk-C0xms8kb.cjs → chunk-C_NdSu1c.cjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,748 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { isSet } from "@stryke/type-checks/is-set";
|
|
5
|
-
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
6
|
-
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
7
|
-
import { isString } from "@stryke/type-checks/is-string";
|
|
8
|
-
import { POWERLINES_API_FUNCTIONS } from "@powerlines/core/constants";
|
|
9
|
-
import { joinPaths } from "@stryke/path/join";
|
|
10
|
-
import { Worker } from "jest-worker";
|
|
11
|
-
import { formatDuration } from "date-fns/formatDuration";
|
|
12
|
-
import { Transform } from "node:stream";
|
|
13
|
-
import { parseArgs } from "node:util";
|
|
1
|
+
import { n as createContext, r as createEngine, t as PowerlinesEngine } from "./engine-q6YKXXcB.mjs";
|
|
2
|
+
import { PowerlinesEngineContext } from "./context/engine-context.mjs";
|
|
3
|
+
import "./context/index.mjs";
|
|
14
4
|
|
|
15
|
-
|
|
16
|
-
function parseIpcMessage(data) {
|
|
17
|
-
let message;
|
|
18
|
-
if (isSetObject(data)) message = data;
|
|
19
|
-
else if (isString(data)) try {
|
|
20
|
-
const parsed = JSON.parse(data);
|
|
21
|
-
if (isSetObject(parsed)) message = parsed;
|
|
22
|
-
} catch {}
|
|
23
|
-
if (message && isSetString(message.id) && isSetString(message.type) && isSetString(message.executionId) && Number.isInteger(message.executionIndex) && !Number.isNaN(message.timestamp)) return message;
|
|
24
|
-
}
|
|
25
|
-
function parseWriteLogMessagePayload(data) {
|
|
26
|
-
if (isSetObject(data) && isSetObject(data.meta) && isSetString(data.meta.type) && (isSetString(data.message) || Array.isArray(data.message))) return {
|
|
27
|
-
...data,
|
|
28
|
-
meta: data.meta,
|
|
29
|
-
message: toArray(data.message).filter(Boolean)
|
|
30
|
-
};
|
|
31
|
-
throw new Error(`Invalid "write-log" message payload: ${JSON.stringify(data)}`);
|
|
32
|
-
}
|
|
33
|
-
function parseUpdateCommandMessagePayload(data) {
|
|
34
|
-
if (isSetString(data?.command)) return { command: data.command };
|
|
35
|
-
throw new Error(`Invalid "update-command" message payload: ${JSON.stringify(data)}`);
|
|
36
|
-
}
|
|
37
|
-
function parseUpdateHookMessagePayload(data) {
|
|
38
|
-
if (isSetString(data?.hook) && [
|
|
39
|
-
"pre",
|
|
40
|
-
"post",
|
|
41
|
-
"normal"
|
|
42
|
-
].includes(data.order)) return {
|
|
43
|
-
hook: data.hook,
|
|
44
|
-
order: data.order
|
|
45
|
-
};
|
|
46
|
-
throw new Error(`Invalid "update-hook" message payload: ${JSON.stringify(data)}`);
|
|
47
|
-
}
|
|
48
|
-
function parseUpdatePluginMessagePayload(data) {
|
|
49
|
-
if (isSetString(data?.plugin)) return { plugin: data.plugin };
|
|
50
|
-
throw new Error(`Invalid "update-plugin" message payload: ${JSON.stringify(data)}`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/_internal/helpers/worker.ts
|
|
55
|
-
const RESTARTED = Symbol("powerlines-worker:restarted");
|
|
56
|
-
/**
|
|
57
|
-
* Formats the debug address into a string.
|
|
58
|
-
*/
|
|
59
|
-
const formatDebugAddress = ({ host, port }) => {
|
|
60
|
-
return host ? `${host}:${port}` : `${port}`;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Node.js CLI flags that are not allowed in NODE_OPTIONS and must be
|
|
64
|
-
* passed as direct CLI arguments via execArgv.
|
|
65
|
-
* This set is the difference between all Node.js CLI flags and the ones **not**
|
|
66
|
-
* allowed in NODE_OPTIONS, as listed in the Node.js documentation:
|
|
67
|
-
* https://nodejs.org/api/cli.html#node_optionsoptions
|
|
68
|
-
*
|
|
69
|
-
* It is not exhaustive since not all options make sense for Powerlines (e.g. --test)
|
|
70
|
-
*/
|
|
71
|
-
const EXEC_ARGV_ONLY_OPTIONS = new Set([
|
|
72
|
-
"experimental-network-inspection",
|
|
73
|
-
"experimental-storage-inspection",
|
|
74
|
-
"experimental-worker-inspection",
|
|
75
|
-
"experimental-inspector-network-resource"
|
|
76
|
-
]);
|
|
77
|
-
function formatArg(key, value) {
|
|
78
|
-
if (value === true) return `--${key}`;
|
|
79
|
-
if (value) return `--${key}=${value.includes(" ") && !value.startsWith("\"") ? JSON.stringify(value) : value}`;
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Tokenizes the arguments string into an array of strings, supporting quoted
|
|
84
|
-
* values and escaped characters.
|
|
85
|
-
* Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401
|
|
86
|
-
*
|
|
87
|
-
* @param input - The arguments string to be tokenized.
|
|
88
|
-
* @returns An array of strings with the tokenized arguments.
|
|
89
|
-
*/
|
|
90
|
-
const tokenizeArgs = (input) => {
|
|
91
|
-
const args = [];
|
|
92
|
-
let isInString = false;
|
|
93
|
-
let willStartNewArg = true;
|
|
94
|
-
for (let i = 0; i < input.length; i++) {
|
|
95
|
-
let char = input[i];
|
|
96
|
-
if (char) {
|
|
97
|
-
if (char === "\\" && isInString) {
|
|
98
|
-
if (input.length === i + 1) throw new Error("Invalid escape character at the end.");
|
|
99
|
-
char = input[++i];
|
|
100
|
-
if (!char) continue;
|
|
101
|
-
} else if (char === " " && !isInString) {
|
|
102
|
-
willStartNewArg = true;
|
|
103
|
-
continue;
|
|
104
|
-
} else if (char === "\"") {
|
|
105
|
-
isInString = !isInString;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
if (willStartNewArg) {
|
|
109
|
-
args.push(char);
|
|
110
|
-
willStartNewArg = false;
|
|
111
|
-
} else args[args.length - 1] += char;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (isInString) throw new Error("Unterminated string");
|
|
115
|
-
return args;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Get the node options from the environment variable `NODE_OPTIONS` and returns
|
|
119
|
-
* them as an array of strings.
|
|
120
|
-
*
|
|
121
|
-
* @returns An array of strings with the node options.
|
|
122
|
-
*/
|
|
123
|
-
const getNodeOptionsArgs = () => {
|
|
124
|
-
if (!process.env.NODE_OPTIONS) return [];
|
|
125
|
-
return tokenizeArgs(process.env.NODE_OPTIONS);
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Stringify the arguments to be used in a command line. It will ignore any
|
|
129
|
-
* argument that has a value of `undefined`. Options that are not allowed in
|
|
130
|
-
* NODE_OPTIONS are returned separately as execArgv.
|
|
131
|
-
*
|
|
132
|
-
* @param args - The arguments to be stringified.
|
|
133
|
-
* @returns An object with `nodeOptions` string and `execArgv` array.
|
|
134
|
-
*/
|
|
135
|
-
function formatNodeOptions(args) {
|
|
136
|
-
const nodeOptionsParts = [];
|
|
137
|
-
const execArgv = [];
|
|
138
|
-
for (const [key, value] of Object.entries(args)) {
|
|
139
|
-
const formatted = formatArg(key, value);
|
|
140
|
-
if (formatted === null) continue;
|
|
141
|
-
if (EXEC_ARGV_ONLY_OPTIONS.has(key)) execArgv.push(formatted);
|
|
142
|
-
else nodeOptionsParts.push(formatted);
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
nodeOptions: nodeOptionsParts.join(" "),
|
|
146
|
-
execArgv
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
const parseNodeArgs = (args) => {
|
|
150
|
-
const { values, tokens } = parseArgs({
|
|
151
|
-
args,
|
|
152
|
-
strict: false,
|
|
153
|
-
tokens: true
|
|
154
|
-
});
|
|
155
|
-
let orphan = null;
|
|
156
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
157
|
-
const token = tokens[i];
|
|
158
|
-
if (!token) continue;
|
|
159
|
-
if (token.kind === "option-terminator") break;
|
|
160
|
-
if (token.kind === "option") {
|
|
161
|
-
orphan = !isSet(token.value) ? token : null;
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (token.kind !== "positional") {
|
|
165
|
-
orphan = null;
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
if (!orphan) continue;
|
|
169
|
-
if (orphan.name in values && isString(values[orphan.name])) values[orphan.name] += ` ${token.value}`;
|
|
170
|
-
else values[orphan.name] = token.value;
|
|
171
|
-
}
|
|
172
|
-
return values;
|
|
173
|
-
};
|
|
174
|
-
function getParsedNodeOptions() {
|
|
175
|
-
const args = [...process.execArgv, ...getNodeOptionsArgs()];
|
|
176
|
-
if (args.length === 0) return {};
|
|
177
|
-
return parseNodeArgs(args);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Get's the debug address from the `NODE_OPTIONS` environment variable. If the
|
|
181
|
-
* address is not found, it returns the default host (`undefined`) and port
|
|
182
|
-
* (`9229`).
|
|
183
|
-
*
|
|
184
|
-
* @returns An object with the host and port of the debug address.
|
|
185
|
-
*/
|
|
186
|
-
const getParsedDebugAddress = (address) => {
|
|
187
|
-
if (!address || !isString(address)) return {
|
|
188
|
-
host: void 0,
|
|
189
|
-
port: 9229
|
|
190
|
-
};
|
|
191
|
-
if (address.includes(":")) {
|
|
192
|
-
const [host, port] = address.split(":");
|
|
193
|
-
if (!host || !port) throw new Error(`Invalid debug address: ${address}`);
|
|
194
|
-
return {
|
|
195
|
-
host,
|
|
196
|
-
port: Number.parseInt(port, 10)
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
host: void 0,
|
|
201
|
-
port: Number.parseInt(address, 10)
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* Get the debug type from the `NODE_OPTIONS` environment variable.
|
|
206
|
-
*/
|
|
207
|
-
function getNodeDebugType(nodeOptions) {
|
|
208
|
-
if (nodeOptions.inspect) return "inspect";
|
|
209
|
-
if (nodeOptions["inspect-brk"] || nodeOptions.inspect_brk) return "inspect-brk";
|
|
210
|
-
}
|
|
211
|
-
const cleanupWorkers = (worker) => {
|
|
212
|
-
for (const curWorker of worker._workerPool?._workers || []) curWorker._child?.kill("SIGINT");
|
|
213
|
-
};
|
|
214
|
-
var Worker$1 = class {
|
|
215
|
-
#worker;
|
|
216
|
-
/**
|
|
217
|
-
* Create a new worker instance.
|
|
218
|
-
*
|
|
219
|
-
* @param workerPath - The path to the worker file.
|
|
220
|
-
* @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.
|
|
221
|
-
*/
|
|
222
|
-
constructor(workerPath, options) {
|
|
223
|
-
this.workerPath = workerPath;
|
|
224
|
-
this.options = options;
|
|
225
|
-
const { timeout = 9e5, onRestart, debuggerPortOffset = -1, enableSourceMaps = false, isolatedMemory = false, enableWorkerThreads = false, logger, ...rest } = this.options;
|
|
226
|
-
let restartPromise;
|
|
227
|
-
let resolveRestartPromise;
|
|
228
|
-
let activeTasks = 0;
|
|
229
|
-
this.#worker = void 0;
|
|
230
|
-
process.on("exit", () => {
|
|
231
|
-
this.close();
|
|
232
|
-
});
|
|
233
|
-
const nodeOptions = getParsedNodeOptions();
|
|
234
|
-
const originalOptions = { ...nodeOptions };
|
|
235
|
-
delete nodeOptions.inspect;
|
|
236
|
-
delete nodeOptions["inspect-brk"];
|
|
237
|
-
delete nodeOptions.inspect_brk;
|
|
238
|
-
if (debuggerPortOffset !== -1) {
|
|
239
|
-
const nodeDebugType = getNodeDebugType(originalOptions);
|
|
240
|
-
if (nodeDebugType) {
|
|
241
|
-
const debuggerAddress = getParsedDebugAddress(originalOptions[nodeDebugType]);
|
|
242
|
-
nodeOptions[nodeDebugType] = formatDebugAddress({
|
|
243
|
-
host: debuggerAddress.host,
|
|
244
|
-
port: debuggerAddress.port === 0 ? 0 : debuggerAddress.port + 1 + debuggerPortOffset
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
if (enableSourceMaps) nodeOptions["enable-source-maps"] = true;
|
|
249
|
-
if (isolatedMemory) {
|
|
250
|
-
delete nodeOptions["max-old-space-size"];
|
|
251
|
-
delete nodeOptions.max_old_space_size;
|
|
252
|
-
}
|
|
253
|
-
const { nodeOptions: formattedNodeOptions, execArgv } = formatNodeOptions(nodeOptions);
|
|
254
|
-
const onHanging = () => {
|
|
255
|
-
const worker = this.#worker;
|
|
256
|
-
if (!worker) return;
|
|
257
|
-
const resolve = resolveRestartPromise;
|
|
258
|
-
createWorker();
|
|
259
|
-
logger.warn(`Sending SIGTERM signal to static worker due to timeout${timeout ? ` of ${formatDuration({ seconds: timeout / 1e3 })}` : ""}. Subsequent errors may be a result of the worker exiting.`);
|
|
260
|
-
worker.end().then(() => {
|
|
261
|
-
resolve(RESTARTED);
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
let hangingTimer = false;
|
|
265
|
-
const onActivity = () => {
|
|
266
|
-
if (hangingTimer) clearTimeout(hangingTimer);
|
|
267
|
-
if (this.options.onActivity) this.options.onActivity();
|
|
268
|
-
hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);
|
|
269
|
-
};
|
|
270
|
-
const createWorker = () => {
|
|
271
|
-
const workerEnv = {
|
|
272
|
-
...process.env,
|
|
273
|
-
...rest.forkOptions?.env ?? {},
|
|
274
|
-
NODE_OPTIONS: formattedNodeOptions,
|
|
275
|
-
POWERLINES_EXECUTION_THREAD_TYPE: enableWorkerThreads ? "worker-thread" : "child-process"
|
|
276
|
-
};
|
|
277
|
-
if (workerEnv.FORCE_COLOR === void 0) {
|
|
278
|
-
if (!workerEnv.NO_COLOR && !workerEnv.CI && workerEnv.TERM !== "dumb" && (process.stdout.isTTY || process.stderr?.isTTY)) workerEnv.FORCE_COLOR = "1";
|
|
279
|
-
}
|
|
280
|
-
this.#worker = new Worker(workerPath, {
|
|
281
|
-
maxRetries: 0,
|
|
282
|
-
computeWorkerKey: (_, ...args) => {
|
|
283
|
-
let executionId = "default";
|
|
284
|
-
let executionIndex = 0;
|
|
285
|
-
if (args.length > 0 && isSetObject(args[0])) {
|
|
286
|
-
const arg = args[0];
|
|
287
|
-
if (isSetObject(arg.options)) {
|
|
288
|
-
executionIndex = arg.options.executionIndex ?? 0;
|
|
289
|
-
executionId = arg.options.executionId || "default";
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return `${executionId}-${executionIndex}`;
|
|
293
|
-
},
|
|
294
|
-
...rest,
|
|
295
|
-
enableWorkerThreads,
|
|
296
|
-
forkOptions: {
|
|
297
|
-
...rest.forkOptions,
|
|
298
|
-
silent: true,
|
|
299
|
-
execArgv: [...execArgv, ...rest.forkOptions?.execArgv ?? []],
|
|
300
|
-
env: workerEnv
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
restartPromise = new Promise((resolve) => {
|
|
304
|
-
resolveRestartPromise = resolve;
|
|
305
|
-
});
|
|
306
|
-
/**
|
|
307
|
-
* Jest Worker has two worker types, ChildProcessWorker (uses child_process) and NodeThreadWorker (uses worker_threads)
|
|
308
|
-
* Powerlines uses ChildProcessWorker by default, but it can be switched to NodeThreadWorker with an experimental flag
|
|
309
|
-
*
|
|
310
|
-
* We only want to handle ChildProcessWorker's orphan process issue, so we access the private property "_child":
|
|
311
|
-
* https://github.com/facebook/jest/blob/b38d7d345a81d97d1dc3b68b8458b1837fbf19be/packages/jest-worker/src/workers/ChildProcessWorker.ts
|
|
312
|
-
*
|
|
313
|
-
* But this property is not available in NodeThreadWorker, so we need to check if we are using ChildProcessWorker
|
|
314
|
-
*/
|
|
315
|
-
if (!enableWorkerThreads) for (const worker of this.#worker._workerPool?._workers || []) {
|
|
316
|
-
worker._child?.on("exit", (code, signal) => {
|
|
317
|
-
if ((code || signal && signal !== "SIGINT") && this.#worker) {
|
|
318
|
-
logger.error(`Worker exited with code: ${code} and signal: ${signal}`);
|
|
319
|
-
process.exit(code ?? 1);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
worker._child?.on("message", (data) => {
|
|
323
|
-
if (isSetObject(data) && data.type === "activity") onActivity();
|
|
324
|
-
else {
|
|
325
|
-
const message = parseIpcMessage(data);
|
|
326
|
-
if (message) {
|
|
327
|
-
logger.trace(`Received IPC message from worker: ${JSON.stringify(message)}`);
|
|
328
|
-
Promise.resolve(this.options.onIpcMessage?.(message));
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
let aborted = false;
|
|
334
|
-
const onActivityAbort = () => {
|
|
335
|
-
if (!aborted) {
|
|
336
|
-
this.options.onActivityAbort?.();
|
|
337
|
-
aborted = true;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const abortActivityStreamOnLog = new Transform({ transform(_chunk, _encoding, callback) {
|
|
341
|
-
onActivityAbort();
|
|
342
|
-
callback();
|
|
343
|
-
} });
|
|
344
|
-
this.#worker.getStdout().pipe(abortActivityStreamOnLog);
|
|
345
|
-
this.#worker.getStderr().pipe(abortActivityStreamOnLog);
|
|
346
|
-
this.#worker.getStdout().pipe(process.stdout);
|
|
347
|
-
this.#worker.getStderr().pipe(process.stderr);
|
|
348
|
-
};
|
|
349
|
-
createWorker();
|
|
350
|
-
for (const method of rest.exposedMethods) {
|
|
351
|
-
if (method.startsWith("_")) continue;
|
|
352
|
-
this[method] = timeout ? async (...args) => {
|
|
353
|
-
activeTasks++;
|
|
354
|
-
try {
|
|
355
|
-
let attempts = 0;
|
|
356
|
-
for (;;) {
|
|
357
|
-
onActivity();
|
|
358
|
-
const result = await Promise.race([this.#worker[method](args.length > 0 && args[0] ? args[0] : {}), restartPromise]);
|
|
359
|
-
if (result !== RESTARTED) return result;
|
|
360
|
-
if (onRestart) onRestart(method, args, ++attempts);
|
|
361
|
-
}
|
|
362
|
-
} finally {
|
|
363
|
-
activeTasks--;
|
|
364
|
-
onActivity();
|
|
365
|
-
}
|
|
366
|
-
} : this.#worker[method].bind(this.#worker);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
async end() {
|
|
370
|
-
const worker = this.#worker;
|
|
371
|
-
if (!worker) throw new Error("Farm is ended, no more calls can be done to it");
|
|
372
|
-
cleanupWorkers(worker);
|
|
373
|
-
this.#worker = void 0;
|
|
374
|
-
return worker.end();
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Quietly end the worker if it exists
|
|
378
|
-
*/
|
|
379
|
-
close() {
|
|
380
|
-
if (this.#worker) {
|
|
381
|
-
cleanupWorkers(this.#worker);
|
|
382
|
-
this.#worker.end();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
//#endregion
|
|
388
|
-
//#region src/index.ts
|
|
389
|
-
/**
|
|
390
|
-
* The Powerlines Engine class
|
|
391
|
-
*
|
|
392
|
-
* @remarks
|
|
393
|
-
* This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
|
|
394
|
-
*
|
|
395
|
-
* @public
|
|
396
|
-
*/
|
|
397
|
-
var PowerlinesEngine = class PowerlinesEngine {
|
|
398
|
-
/**
|
|
399
|
-
* The Powerlines context
|
|
400
|
-
*/
|
|
401
|
-
#context;
|
|
402
|
-
/**
|
|
403
|
-
* The worker pool for managing child threads
|
|
404
|
-
*/
|
|
405
|
-
#worker;
|
|
406
|
-
/**
|
|
407
|
-
* Create a new Powerlines Engine instance
|
|
408
|
-
*
|
|
409
|
-
* @param options - The options to initialize the context with
|
|
410
|
-
* @param initialConfig - The initial configuration for the context, which can be used to provide additional context or override certain configuration values during initialization. This is particularly useful when initializing the context from a CLI command, where the CLI flags can be passed as part of the initial configuration to ensure they are properly merged with the configuration file and made available to plugins during their setup and execution.
|
|
411
|
-
* @returns A new instance of the Powerlines Engine
|
|
412
|
-
*/
|
|
413
|
-
static async from(options, initialConfig = {}) {
|
|
414
|
-
const api = new PowerlinesEngine(await PowerlinesEngineContext.fromInitialConfig(options, initialConfig));
|
|
415
|
-
const packagePath = await resolvePackage("@powerlines/engine");
|
|
416
|
-
if (!packagePath) throw new Error("Could not resolve `@powerlines/engine` package location.");
|
|
417
|
-
api.#worker = new Worker$1(joinPaths(packagePath, "./_internal/worker.mjs"), {
|
|
418
|
-
onIpcMessage: api.handleIpcMessage.bind(api),
|
|
419
|
-
enableSourceMaps: options.mode === "development",
|
|
420
|
-
exposedMethods: POWERLINES_API_FUNCTIONS,
|
|
421
|
-
logger: api.context.extendLogger({ category: "ipc" })
|
|
422
|
-
});
|
|
423
|
-
return api;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* The Powerlines context
|
|
427
|
-
*/
|
|
428
|
-
get context() {
|
|
429
|
-
return this.#context;
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Generate the Powerlines typescript declaration file
|
|
433
|
-
*
|
|
434
|
-
* @remarks
|
|
435
|
-
* This method will only generate the typescript declaration file for the Powerlines project. It is generally recommended to run the full `prepare` command, which will run this method as part of its process.
|
|
436
|
-
*
|
|
437
|
-
* @param inlineConfig - The inline configuration for the types command
|
|
438
|
-
*/
|
|
439
|
-
async types(inlineConfig = { command: "types" }) {
|
|
440
|
-
const timer = this.context.timer("Types");
|
|
441
|
-
this.context.info("🏗️ Generating typescript declarations for the Powerlines project");
|
|
442
|
-
this.context.debug(" Aggregating configuration options for the Powerlines project");
|
|
443
|
-
inlineConfig.command ??= "types";
|
|
444
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.types({
|
|
445
|
-
options: execution.options,
|
|
446
|
-
initialConfig: this.#context.initialConfig,
|
|
447
|
-
inlineConfig
|
|
448
|
-
})));
|
|
449
|
-
this.context.debug("✔ Powerlines types generation has completed successfully");
|
|
450
|
-
timer();
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Prepare the Powerlines API
|
|
454
|
-
*
|
|
455
|
-
* @remarks
|
|
456
|
-
* This method will prepare the Powerlines API for use, initializing any necessary resources.
|
|
457
|
-
*
|
|
458
|
-
* @param inlineConfig - The inline configuration for the prepare command
|
|
459
|
-
*/
|
|
460
|
-
async prepare(inlineConfig = { command: "prepare" }) {
|
|
461
|
-
const timer = this.context.timer("Prepare");
|
|
462
|
-
this.context.info("🏗️ Preparing the Powerlines project");
|
|
463
|
-
this.context.debug("Aggregating configuration options for the Powerlines project");
|
|
464
|
-
inlineConfig.command ??= "prepare";
|
|
465
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.prepare({
|
|
466
|
-
options: execution.options,
|
|
467
|
-
initialConfig: this.#context.initialConfig,
|
|
468
|
-
inlineConfig
|
|
469
|
-
})));
|
|
470
|
-
this.context.debug("✔ Powerlines preparation has completed successfully");
|
|
471
|
-
timer();
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Create a new Powerlines project
|
|
475
|
-
*
|
|
476
|
-
* @remarks
|
|
477
|
-
* This method will create a new Powerlines project in the current directory.
|
|
478
|
-
*
|
|
479
|
-
* @param inlineConfig - The inline configuration for the new command
|
|
480
|
-
* @returns A promise that resolves when the project has been created
|
|
481
|
-
*/
|
|
482
|
-
async new(inlineConfig) {
|
|
483
|
-
const timer = this.context.timer("New");
|
|
484
|
-
this.context.info("🆕 Creating a new Powerlines project");
|
|
485
|
-
inlineConfig.command ??= "new";
|
|
486
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.new({
|
|
487
|
-
options: execution.options,
|
|
488
|
-
initialConfig: this.#context.initialConfig,
|
|
489
|
-
inlineConfig
|
|
490
|
-
})));
|
|
491
|
-
this.context.debug("✔ Powerlines new command completed successfully");
|
|
492
|
-
timer();
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Clean any previously prepared artifacts
|
|
496
|
-
*
|
|
497
|
-
* @remarks
|
|
498
|
-
* This method will remove the previous Powerlines artifacts from the project.
|
|
499
|
-
*
|
|
500
|
-
* @param inlineConfig - The inline configuration for the clean command
|
|
501
|
-
* @returns A promise that resolves when the clean command has completed
|
|
502
|
-
*/
|
|
503
|
-
async clean(inlineConfig = { command: "clean" }) {
|
|
504
|
-
const timer = this.context.timer("Clean");
|
|
505
|
-
this.context.info("🧹 Cleaning the previous Powerlines artifacts");
|
|
506
|
-
inlineConfig.command ??= "clean";
|
|
507
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.clean({
|
|
508
|
-
options: execution.options,
|
|
509
|
-
initialConfig: this.#context.initialConfig,
|
|
510
|
-
inlineConfig
|
|
511
|
-
})));
|
|
512
|
-
this.context.debug("✔ Powerlines cleaning completed successfully");
|
|
513
|
-
timer();
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Lint the project
|
|
517
|
-
*
|
|
518
|
-
* @param inlineConfig - The inline configuration for the lint command
|
|
519
|
-
* @returns A promise that resolves when the lint command has completed
|
|
520
|
-
*/
|
|
521
|
-
async lint(inlineConfig = { command: "lint" }) {
|
|
522
|
-
const timer = this.context.timer("Lint");
|
|
523
|
-
this.context.info("📝 Linting the Powerlines project");
|
|
524
|
-
inlineConfig.command ??= "lint";
|
|
525
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.lint({
|
|
526
|
-
options: execution.options,
|
|
527
|
-
initialConfig: this.#context.initialConfig,
|
|
528
|
-
inlineConfig
|
|
529
|
-
})));
|
|
530
|
-
this.context.debug("✔ Powerlines linting completed successfully");
|
|
531
|
-
timer();
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Test the project
|
|
535
|
-
*
|
|
536
|
-
* @remarks
|
|
537
|
-
* This method will run the tests for the Powerlines project.
|
|
538
|
-
*
|
|
539
|
-
* @param inlineConfig - The inline configuration for the test command
|
|
540
|
-
* @returns A promise that resolves when the test command has completed
|
|
541
|
-
*/
|
|
542
|
-
async test(inlineConfig = { command: "test" }) {
|
|
543
|
-
const timer = this.context.timer("Test");
|
|
544
|
-
this.context.info("🧪 Running tests for the Powerlines project");
|
|
545
|
-
inlineConfig.command ??= "test";
|
|
546
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.test({
|
|
547
|
-
options: execution.options,
|
|
548
|
-
initialConfig: this.#context.initialConfig,
|
|
549
|
-
inlineConfig
|
|
550
|
-
})));
|
|
551
|
-
this.context.debug("✔ Powerlines testing completed successfully");
|
|
552
|
-
timer();
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Build the project
|
|
556
|
-
*
|
|
557
|
-
* @remarks
|
|
558
|
-
* This method will build the Powerlines project, generating the necessary artifacts.
|
|
559
|
-
*
|
|
560
|
-
* @param inlineConfig - The inline configuration for the build command
|
|
561
|
-
* @returns A promise that resolves when the build command has completed
|
|
562
|
-
*/
|
|
563
|
-
async build(inlineConfig = { command: "build" }) {
|
|
564
|
-
const timer = this.context.timer("Build");
|
|
565
|
-
this.context.info("📦 Building the Powerlines project");
|
|
566
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.build({
|
|
567
|
-
options: execution.options,
|
|
568
|
-
initialConfig: this.#context.initialConfig,
|
|
569
|
-
inlineConfig
|
|
570
|
-
})));
|
|
571
|
-
this.context.debug("✔ Powerlines build completed successfully");
|
|
572
|
-
timer();
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* Prepare the documentation for the project
|
|
576
|
-
*
|
|
577
|
-
* @param inlineConfig - The inline configuration for the docs command
|
|
578
|
-
* @returns A promise that resolves when the documentation generation has completed
|
|
579
|
-
*/
|
|
580
|
-
async docs(inlineConfig = { command: "docs" }) {
|
|
581
|
-
const timer = this.context.timer("Docs");
|
|
582
|
-
this.context.info("📓 Generating documentation for the Powerlines project");
|
|
583
|
-
inlineConfig.command ??= "docs";
|
|
584
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.docs({
|
|
585
|
-
options: execution.options,
|
|
586
|
-
initialConfig: this.#context.initialConfig,
|
|
587
|
-
inlineConfig
|
|
588
|
-
})));
|
|
589
|
-
this.context.debug("✔ Powerlines documentation generation completed successfully");
|
|
590
|
-
timer();
|
|
591
|
-
}
|
|
592
|
-
/**
|
|
593
|
-
* Deploy the project source code
|
|
594
|
-
*
|
|
595
|
-
* @remarks
|
|
596
|
-
* This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
|
|
597
|
-
*
|
|
598
|
-
* @param inlineConfig - The inline configuration for the deploy command
|
|
599
|
-
*/
|
|
600
|
-
async deploy(inlineConfig = { command: "deploy" }) {
|
|
601
|
-
const timer = this.context.timer("Deploy");
|
|
602
|
-
this.context.info("🚀 Deploying the Powerlines project");
|
|
603
|
-
inlineConfig.command ??= "deploy";
|
|
604
|
-
await Promise.all(this.#context.executions.map(async (execution) => this.#worker.deploy({
|
|
605
|
-
options: execution.options,
|
|
606
|
-
initialConfig: this.#context.initialConfig,
|
|
607
|
-
inlineConfig
|
|
608
|
-
})));
|
|
609
|
-
this.context.debug("✔ Powerlines deploy completed successfully");
|
|
610
|
-
timer();
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Finalization/cleanup processing for the Powerlines API
|
|
614
|
-
*
|
|
615
|
-
* @remarks
|
|
616
|
-
* This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
|
|
617
|
-
*
|
|
618
|
-
* @returns A promise that resolves when the finalization process has completed
|
|
619
|
-
*/
|
|
620
|
-
async finalize() {
|
|
621
|
-
const timer = this.context.timer("Finalization");
|
|
622
|
-
this.context.info("🏁 Powerlines finalization processes started");
|
|
623
|
-
this.#worker.close();
|
|
624
|
-
this.context.debug("✔ Powerlines finalization completed successfully");
|
|
625
|
-
timer();
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Asynchronous disposal method for the Powerlines Engine, which will call the finalize method to perform any necessary cleanup when the engine is disposed of.
|
|
629
|
-
*/
|
|
630
|
-
async [Symbol.asyncDispose]() {
|
|
631
|
-
return this.finalize();
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Create a new Powerlines Engine instance
|
|
635
|
-
*
|
|
636
|
-
* @param context - The Powerlines context
|
|
637
|
-
*/
|
|
638
|
-
constructor(context) {
|
|
639
|
-
this.#context = context;
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Handle incoming IPC messages from the worker processes, routing them to the appropriate handlers based on the message type.
|
|
643
|
-
*
|
|
644
|
-
* @param message - The IPC message received from a worker process
|
|
645
|
-
*/
|
|
646
|
-
async handleIpcMessage(message) {
|
|
647
|
-
switch (message.type) {
|
|
648
|
-
case "write-log": {
|
|
649
|
-
const payload = parseWriteLogMessagePayload(message.payload);
|
|
650
|
-
this.context.logger.debug({
|
|
651
|
-
meta: {
|
|
652
|
-
category: "ipc",
|
|
653
|
-
executionId: message.executionId,
|
|
654
|
-
executionIndex: message.executionIndex,
|
|
655
|
-
environment: message.environment
|
|
656
|
-
},
|
|
657
|
-
message: `Received a "write-log" IPC message from worker:
|
|
658
|
-
Type: ${payload.meta.type}
|
|
659
|
-
Message: ${toArray(payload.message).filter(Boolean).join("\n")}`
|
|
660
|
-
});
|
|
661
|
-
await this.handleWriteLog({
|
|
662
|
-
...message,
|
|
663
|
-
type: "write-log",
|
|
664
|
-
payload
|
|
665
|
-
});
|
|
666
|
-
break;
|
|
667
|
-
}
|
|
668
|
-
case "update-command":
|
|
669
|
-
this.context.logger.debug({
|
|
670
|
-
meta: {
|
|
671
|
-
category: "ipc",
|
|
672
|
-
executionId: message.executionId,
|
|
673
|
-
executionIndex: message.executionIndex,
|
|
674
|
-
environment: message.environment
|
|
675
|
-
},
|
|
676
|
-
message: `Received an "update-command" IPC message from worker: \n${JSON.stringify(message, null, 2)}`
|
|
677
|
-
});
|
|
678
|
-
await this.handleUpdateCommand({
|
|
679
|
-
...message,
|
|
680
|
-
type: "update-command",
|
|
681
|
-
payload: parseUpdateCommandMessagePayload(message.payload)
|
|
682
|
-
});
|
|
683
|
-
break;
|
|
684
|
-
case "update-hook":
|
|
685
|
-
this.context.logger.debug({
|
|
686
|
-
meta: {
|
|
687
|
-
category: "ipc",
|
|
688
|
-
executionId: message.executionId,
|
|
689
|
-
executionIndex: message.executionIndex,
|
|
690
|
-
environment: message.environment
|
|
691
|
-
},
|
|
692
|
-
message: `Received an "update-hook" IPC message from worker: \n${JSON.stringify(message, null, 2)}`
|
|
693
|
-
});
|
|
694
|
-
await this.handleUpdateHook({
|
|
695
|
-
...message,
|
|
696
|
-
type: "update-hook",
|
|
697
|
-
payload: parseUpdateHookMessagePayload(message.payload)
|
|
698
|
-
});
|
|
699
|
-
break;
|
|
700
|
-
case "update-plugin":
|
|
701
|
-
this.context.logger.debug({
|
|
702
|
-
meta: {
|
|
703
|
-
category: "ipc",
|
|
704
|
-
executionId: message.executionId,
|
|
705
|
-
executionIndex: message.executionIndex,
|
|
706
|
-
environment: message.environment
|
|
707
|
-
},
|
|
708
|
-
message: `Received an "update-plugin" IPC message from worker: \n${JSON.stringify(message, null, 2)}`
|
|
709
|
-
});
|
|
710
|
-
await this.handleUpdatePlugin({
|
|
711
|
-
...message,
|
|
712
|
-
type: "update-plugin",
|
|
713
|
-
payload: parseUpdatePluginMessagePayload(message.payload)
|
|
714
|
-
});
|
|
715
|
-
break;
|
|
716
|
-
case "activity":
|
|
717
|
-
case void 0:
|
|
718
|
-
default: break;
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
async handleWriteLog(message) {
|
|
722
|
-
const { payload } = message;
|
|
723
|
-
this.context.logger.log(payload.meta.type, {
|
|
724
|
-
message: toArray(payload.message).filter(Boolean).join("\n"),
|
|
725
|
-
meta: {
|
|
726
|
-
category: payload.meta.category,
|
|
727
|
-
logId: payload.meta.logId,
|
|
728
|
-
name: payload.meta.name,
|
|
729
|
-
executionId: message.executionId,
|
|
730
|
-
executionIndex: message.executionIndex,
|
|
731
|
-
command: payload.meta.command,
|
|
732
|
-
hook: payload.meta.hook,
|
|
733
|
-
environment: message.environment,
|
|
734
|
-
plugin: payload.meta.plugin,
|
|
735
|
-
source: payload.meta.source,
|
|
736
|
-
timestamp: message.timestamp,
|
|
737
|
-
$$ipc: true
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
async handleUpdatePlugin(_) {}
|
|
742
|
-
async handleUpdateHook(_) {}
|
|
743
|
-
async handleUpdateCommand(_) {}
|
|
744
|
-
};
|
|
745
|
-
|
|
746
|
-
//#endregion
|
|
747
|
-
export { PowerlinesEngine };
|
|
748
|
-
//# sourceMappingURL=index.mjs.map
|
|
5
|
+
export { PowerlinesEngine, PowerlinesEngineContext, createContext, createEngine };
|