@powerlines/engine 0.15.0 โ†’ 0.15.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.
Files changed (195) hide show
  1. package/dist/api/build.cjs +66 -0
  2. package/dist/api/build.d.cts +14 -0
  3. package/dist/api/build.d.cts.map +1 -0
  4. package/dist/api/build.d.mts +14 -0
  5. package/dist/api/build.d.mts.map +1 -0
  6. package/dist/api/build.mjs +64 -0
  7. package/dist/api/build.mjs.map +1 -0
  8. package/dist/api/clean.cjs +29 -0
  9. package/dist/api/clean.d.cts +14 -0
  10. package/dist/api/clean.d.cts.map +1 -0
  11. package/dist/api/clean.d.mts +14 -0
  12. package/dist/api/clean.d.mts.map +1 -0
  13. package/dist/api/clean.mjs +28 -0
  14. package/dist/api/clean.mjs.map +1 -0
  15. package/dist/api/create.cjs +59 -0
  16. package/dist/api/create.d.cts +14 -0
  17. package/dist/api/create.d.cts.map +1 -0
  18. package/dist/api/create.d.mts +14 -0
  19. package/dist/api/create.d.mts.map +1 -0
  20. package/dist/api/create.mjs +57 -0
  21. package/dist/api/create.mjs.map +1 -0
  22. package/dist/api/deploy.cjs +25 -0
  23. package/dist/api/deploy.d.cts +17 -0
  24. package/dist/api/deploy.d.cts.map +1 -0
  25. package/dist/api/deploy.d.mts +17 -0
  26. package/dist/api/deploy.d.mts.map +1 -0
  27. package/dist/api/deploy.mjs +24 -0
  28. package/dist/api/deploy.mjs.map +1 -0
  29. package/dist/api/docs.cjs +25 -0
  30. package/dist/api/docs.d.cts +17 -0
  31. package/dist/api/docs.d.cts.map +1 -0
  32. package/dist/api/docs.d.mts +17 -0
  33. package/dist/api/docs.d.mts.map +1 -0
  34. package/dist/api/docs.mjs +24 -0
  35. package/dist/api/docs.mjs.map +1 -0
  36. package/dist/api/lint.cjs +28 -0
  37. package/dist/api/lint.d.cts +17 -0
  38. package/dist/api/lint.d.cts.map +1 -0
  39. package/dist/api/lint.d.mts +17 -0
  40. package/dist/api/lint.d.mts.map +1 -0
  41. package/dist/api/lint.mjs +27 -0
  42. package/dist/api/lint.mjs.map +1 -0
  43. package/dist/api/prepare.cjs +69 -0
  44. package/dist/api/prepare.d.cts +14 -0
  45. package/dist/api/prepare.d.cts.map +1 -0
  46. package/dist/api/prepare.d.mts +14 -0
  47. package/dist/api/prepare.d.mts.map +1 -0
  48. package/dist/api/prepare.mjs +68 -0
  49. package/dist/api/prepare.mjs.map +1 -0
  50. package/dist/api/test.cjs +28 -0
  51. package/dist/api/test.d.cts +17 -0
  52. package/dist/api/test.d.cts.map +1 -0
  53. package/dist/api/test.d.mts +17 -0
  54. package/dist/api/test.d.mts.map +1 -0
  55. package/dist/api/test.mjs +27 -0
  56. package/dist/api/test.mjs.map +1 -0
  57. package/dist/api/types.cjs +71 -0
  58. package/dist/api/types.d.cts +17 -0
  59. package/dist/api/types.d.cts.map +1 -0
  60. package/dist/api/types.d.mts +17 -0
  61. package/dist/api/types.d.mts.map +1 -0
  62. package/dist/api/types.mjs +70 -0
  63. package/dist/api/types.mjs.map +1 -0
  64. package/dist/api-6w4hZL6n.d.cts +135 -0
  65. package/dist/api-6w4hZL6n.d.cts.map +1 -0
  66. package/dist/api-Cdw4v0W4.d.mts +135 -0
  67. package/dist/api-Cdw4v0W4.d.mts.map +1 -0
  68. package/dist/config-BNe23XHx.d.mts +204 -0
  69. package/dist/config-BNe23XHx.d.mts.map +1 -0
  70. package/dist/config-D6xUniHh.d.cts +204 -0
  71. package/dist/config-D6xUniHh.d.cts.map +1 -0
  72. package/dist/context/engine-context.cjs +175 -0
  73. package/dist/context/engine-context.d.cts +2 -0
  74. package/dist/context/engine-context.d.mts +2 -0
  75. package/dist/context/engine-context.mjs +173 -0
  76. package/dist/context/engine-context.mjs.map +1 -0
  77. package/dist/context/index.cjs +2 -9
  78. package/dist/context/index.d.cts +2 -660
  79. package/dist/context/index.d.mts +2 -660
  80. package/dist/context/index.mjs +2 -4
  81. package/dist/context-DzgsMSWr.d.mts +149 -0
  82. package/dist/context-DzgsMSWr.d.mts.map +1 -0
  83. package/dist/context-epL7NPvL.d.cts +149 -0
  84. package/dist/context-epL7NPvL.d.cts.map +1 -0
  85. package/dist/engine-context-DEotmVzB.d.mts +54 -0
  86. package/dist/engine-context-DEotmVzB.d.mts.map +1 -0
  87. package/dist/engine-context-Dw8odBCo.d.cts +54 -0
  88. package/dist/engine-context-Dw8odBCo.d.cts.map +1 -0
  89. package/dist/engine.cjs +268 -0
  90. package/dist/engine.d.cts +143 -0
  91. package/dist/engine.d.cts.map +1 -0
  92. package/dist/engine.d.mts +143 -0
  93. package/dist/engine.d.mts.map +1 -0
  94. package/dist/engine.mjs +264 -0
  95. package/dist/engine.mjs.map +1 -0
  96. package/dist/execution-host.cjs +44 -0
  97. package/dist/execution-host.d.cts +14 -0
  98. package/dist/execution-host.d.cts.map +1 -0
  99. package/dist/execution-host.d.mts +14 -0
  100. package/dist/execution-host.d.mts.map +1 -0
  101. package/dist/execution-host.mjs +36 -0
  102. package/dist/execution-host.mjs.map +1 -0
  103. package/dist/helpers/create-execution-host.cjs +51 -0
  104. package/dist/helpers/create-execution-host.d.cts +21 -0
  105. package/dist/helpers/create-execution-host.d.cts.map +1 -0
  106. package/dist/helpers/create-execution-host.d.mts +21 -0
  107. package/dist/helpers/create-execution-host.d.mts.map +1 -0
  108. package/dist/helpers/create-execution-host.mjs +50 -0
  109. package/dist/helpers/create-execution-host.mjs.map +1 -0
  110. package/dist/helpers/execution-host-worker.cjs +308 -0
  111. package/dist/helpers/execution-host-worker.d.cts +68 -0
  112. package/dist/helpers/execution-host-worker.d.cts.map +1 -0
  113. package/dist/helpers/execution-host-worker.d.mts +68 -0
  114. package/dist/helpers/execution-host-worker.d.mts.map +1 -0
  115. package/dist/helpers/execution-host-worker.mjs +307 -0
  116. package/dist/helpers/execution-host-worker.mjs.map +1 -0
  117. package/dist/helpers/finalize.cjs +27 -0
  118. package/dist/helpers/finalize.d.cts +12 -0
  119. package/dist/helpers/finalize.d.cts.map +1 -0
  120. package/dist/helpers/finalize.d.mts +12 -0
  121. package/dist/helpers/finalize.d.mts.map +1 -0
  122. package/dist/helpers/finalize.mjs +26 -0
  123. package/dist/helpers/finalize.mjs.map +1 -0
  124. package/dist/helpers/rpc.cjs +140 -0
  125. package/dist/helpers/rpc.d.cts +7 -0
  126. package/dist/helpers/rpc.d.cts.map +1 -0
  127. package/dist/helpers/rpc.d.mts +7 -0
  128. package/dist/helpers/rpc.d.mts.map +1 -0
  129. package/dist/helpers/rpc.mjs +139 -0
  130. package/dist/helpers/rpc.mjs.map +1 -0
  131. package/dist/index-CNgSR_kt.d.mts +1 -0
  132. package/dist/index-D_TYgLX3.d.cts +1 -0
  133. package/dist/index.cjs +13 -567
  134. package/dist/index.d.cts +9 -126
  135. package/dist/index.d.mts +9 -126
  136. package/dist/index.mjs +7 -567
  137. package/package.json +101 -129
  138. package/dist/_internal/worker.cjs +0 -4843
  139. package/dist/_internal/worker.d.cts +0 -38
  140. package/dist/_internal/worker.d.cts.map +0 -1
  141. package/dist/_internal/worker.d.mts +0 -38
  142. package/dist/_internal/worker.d.mts.map +0 -1
  143. package/dist/_internal/worker.mjs +0 -4804
  144. package/dist/_internal/worker.mjs.map +0 -1
  145. package/dist/api.cjs +0 -1274
  146. package/dist/api.d.cts +0 -265
  147. package/dist/api.d.cts.map +0 -1
  148. package/dist/api.d.mts +0 -265
  149. package/dist/api.d.mts.map +0 -1
  150. package/dist/api.mjs +0 -1270
  151. package/dist/api.mjs.map +0 -1
  152. package/dist/base-context-BUnL_9z8.mjs +0 -241
  153. package/dist/base-context-BUnL_9z8.mjs.map +0 -1
  154. package/dist/base-context-CFvO2N9I.cjs +0 -248
  155. package/dist/context/index.d.cts.map +0 -1
  156. package/dist/context/index.d.mts.map +0 -1
  157. package/dist/engine-context-BuD9AGfd.mjs +0 -41
  158. package/dist/engine-context-BuD9AGfd.mjs.map +0 -1
  159. package/dist/engine-context-NO6enYev.cjs +0 -45
  160. package/dist/execution-context-BgGV4xyW.cjs +0 -2614
  161. package/dist/execution-context-D_CXpe9I.mjs +0 -2570
  162. package/dist/execution-context-D_CXpe9I.mjs.map +0 -1
  163. package/dist/fs-D1nIP45P.mjs +0 -226
  164. package/dist/fs-D1nIP45P.mjs.map +0 -1
  165. package/dist/fs-XogSgMqT.cjs +0 -262
  166. package/dist/index.d.cts.map +0 -1
  167. package/dist/index.d.mts.map +0 -1
  168. package/dist/index.mjs.map +0 -1
  169. package/dist/schemas.cjs +0 -9
  170. package/dist/schemas.d.cts +0 -127
  171. package/dist/schemas.d.cts.map +0 -1
  172. package/dist/schemas.d.mts +0 -127
  173. package/dist/schemas.d.mts.map +0 -1
  174. package/dist/schemas.mjs +0 -3
  175. package/dist/storage/index.cjs +0 -9
  176. package/dist/storage/index.d.cts +0 -419
  177. package/dist/storage/index.d.cts.map +0 -1
  178. package/dist/storage/index.d.mts +0 -419
  179. package/dist/storage/index.d.mts.map +0 -1
  180. package/dist/storage/index.mjs +0 -3
  181. package/dist/ts-morph-BaLPVAdB.cjs +0 -114
  182. package/dist/ts-morph-D0CaA37w.mjs +0 -102
  183. package/dist/ts-morph-D0CaA37w.mjs.map +0 -1
  184. package/dist/tsconfig-Cstsoprg.mjs +0 -155
  185. package/dist/tsconfig-Cstsoprg.mjs.map +0 -1
  186. package/dist/tsconfig-DeyWQC2N.cjs +0 -198
  187. package/dist/typescript/index.cjs +0 -13
  188. package/dist/typescript/index.d.cts +0 -106
  189. package/dist/typescript/index.d.cts.map +0 -1
  190. package/dist/typescript/index.d.mts +0 -106
  191. package/dist/typescript/index.d.mts.map +0 -1
  192. package/dist/typescript/index.mjs +0 -4
  193. package/dist/virtual-BNdKVkRw.cjs +0 -548
  194. package/dist/virtual-gIlTc3Lj.mjs +0 -513
  195. package/dist/virtual-gIlTc3Lj.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,568 +1,8 @@
1
- import { t as PowerlinesEngineContext } from "./engine-context-BuD9AGfd.mjs";
2
- import { POWERLINES_API_FUNCTIONS } from "@powerlines/core/constants";
3
- import { resolvePackage } from "@stryke/fs/resolve";
4
- import { joinPaths } from "@stryke/path/join";
5
- import { LogLevelLabel } from "@storm-software/config-tools/types";
6
- import { isSet } from "@stryke/type-checks/is-set";
7
- import { isString } from "@stryke/type-checks/is-string";
8
- import { Worker } from "jest-worker";
9
- import { Transform } from "node:stream";
10
- import { parseArgs } from "node:util";
1
+ import { PowerlinesEngineContext } from "./context/engine-context.mjs";
2
+ import { PowerlinesEngine, createContext, createEngine } from "./engine.mjs";
3
+ import { createRpcClient } from "./helpers/rpc.mjs";
4
+ import { createExecutionHost } from "./helpers/create-execution-host.mjs";
5
+ import "./context/index.mjs";
6
+ import { finalize } from "./helpers/finalize.mjs";
11
7
 
12
- //#region src/_internal/helpers/worker.ts
13
- const RESTARTED = Symbol("powerlines-worker:restarted");
14
- /**
15
- * Formats the debug address into a string.
16
- */
17
- const formatDebugAddress = ({ host, port }) => {
18
- if (host) return `${host}:${port}`;
19
- return `${port}`;
20
- };
21
- /**
22
- * Node.js CLI flags that are not allowed in NODE_OPTIONS and must be
23
- * passed as direct CLI arguments via execArgv.
24
- * This set is the difference between all Node.js CLI flags and the ones **not**
25
- * allowed in NODE_OPTIONS, as listed in the Node.js documentation:
26
- * https://nodejs.org/api/cli.html#node_optionsoptions
27
- *
28
- * It is not exhaustive since not all options make sense for Powerlines (e.g. --test)
29
- */
30
- const EXEC_ARGV_ONLY_OPTIONS = new Set([
31
- "experimental-network-inspection",
32
- "experimental-storage-inspection",
33
- "experimental-worker-inspection",
34
- "experimental-inspector-network-resource"
35
- ]);
36
- function formatArg(key, value) {
37
- if (value === true) return `--${key}`;
38
- if (value) return `--${key}=${value.includes(" ") && !value.startsWith("\"") ? JSON.stringify(value) : value}`;
39
- return null;
40
- }
41
- /**
42
- * Tokenizes the arguments string into an array of strings, supporting quoted
43
- * values and escaped characters.
44
- * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401
45
- *
46
- * @param input - The arguments string to be tokenized.
47
- * @returns An array of strings with the tokenized arguments.
48
- */
49
- const tokenizeArgs = (input) => {
50
- const args = [];
51
- let isInString = false;
52
- let willStartNewArg = true;
53
- for (let i = 0; i < input.length; i++) {
54
- let char = input[i];
55
- if (char) {
56
- if (char === "\\" && isInString) {
57
- if (input.length === i + 1) throw new Error("Invalid escape character at the end.");
58
- char = input[++i];
59
- if (!char) continue;
60
- } else if (char === " " && !isInString) {
61
- willStartNewArg = true;
62
- continue;
63
- } else if (char === "\"") {
64
- isInString = !isInString;
65
- continue;
66
- }
67
- if (willStartNewArg) {
68
- args.push(char);
69
- willStartNewArg = false;
70
- } else args[args.length - 1] += char;
71
- }
72
- }
73
- if (isInString) throw new Error("Unterminated string");
74
- return args;
75
- };
76
- /**
77
- * Get the node options from the environment variable `NODE_OPTIONS` and returns
78
- * them as an array of strings.
79
- *
80
- * @returns An array of strings with the node options.
81
- */
82
- const getNodeOptionsArgs = () => {
83
- if (!process.env.NODE_OPTIONS) return [];
84
- return tokenizeArgs(process.env.NODE_OPTIONS);
85
- };
86
- /**
87
- * Stringify the arguments to be used in a command line. It will ignore any
88
- * argument that has a value of `undefined`. Options that are not allowed in
89
- * NODE_OPTIONS are returned separately as execArgv.
90
- *
91
- * @param args - The arguments to be stringified.
92
- * @returns An object with `nodeOptions` string and `execArgv` array.
93
- */
94
- function formatNodeOptions(args) {
95
- const nodeOptionsParts = [];
96
- const execArgv = [];
97
- for (const [key, value] of Object.entries(args)) {
98
- const formatted = formatArg(key, value);
99
- if (formatted === null) continue;
100
- if (EXEC_ARGV_ONLY_OPTIONS.has(key)) execArgv.push(formatted);
101
- else nodeOptionsParts.push(formatted);
102
- }
103
- return {
104
- nodeOptions: nodeOptionsParts.join(" "),
105
- execArgv
106
- };
107
- }
108
- const parseNodeArgs = (args) => {
109
- const { values, tokens } = parseArgs({
110
- args,
111
- strict: false,
112
- tokens: true
113
- });
114
- let orphan = null;
115
- for (let i = 0; i < tokens.length; i++) {
116
- const token = tokens[i];
117
- if (!token) continue;
118
- if (token.kind === "option-terminator") break;
119
- if (token.kind === "option") {
120
- orphan = !isSet(token.value) ? token : null;
121
- continue;
122
- }
123
- if (token.kind !== "positional") {
124
- orphan = null;
125
- continue;
126
- }
127
- if (!orphan) continue;
128
- if (orphan.name in values && isString(values[orphan.name])) values[orphan.name] += ` ${token.value}`;
129
- else values[orphan.name] = token.value;
130
- }
131
- return values;
132
- };
133
- function getParsedNodeOptions() {
134
- const args = [...process.execArgv, ...getNodeOptionsArgs()];
135
- if (args.length === 0) return {};
136
- return parseNodeArgs(args);
137
- }
138
- /**
139
- * Get's the debug address from the `NODE_OPTIONS` environment variable. If the
140
- * address is not found, it returns the default host (`undefined`) and port
141
- * (`9229`).
142
- *
143
- * @returns An object with the host and port of the debug address.
144
- */
145
- const getParsedDebugAddress = (address) => {
146
- if (!address || !isString(address)) return {
147
- host: void 0,
148
- port: 9229
149
- };
150
- if (address.includes(":")) {
151
- const [host, port] = address.split(":");
152
- if (!host || !port) throw new Error(`Invalid debug address: ${address}`);
153
- return {
154
- host,
155
- port: Number.parseInt(port, 10)
156
- };
157
- }
158
- return {
159
- host: void 0,
160
- port: Number.parseInt(address, 10)
161
- };
162
- };
163
- /**
164
- * Get the debug type from the `NODE_OPTIONS` environment variable.
165
- */
166
- function getNodeDebugType(nodeOptions) {
167
- if (nodeOptions.inspect) return "inspect";
168
- if (nodeOptions["inspect-brk"] || nodeOptions.inspect_brk) return "inspect-brk";
169
- }
170
- const cleanupWorkers = (worker) => {
171
- for (const curWorker of worker._workerPool?._workers || []) curWorker._child?.kill("SIGINT");
172
- };
173
- var Worker$1 = class {
174
- #worker;
175
- /**
176
- * Create a new worker instance.
177
- *
178
- * @param workerPath - The path to the worker file.
179
- * @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.
180
- */
181
- constructor(workerPath, options) {
182
- this.workerPath = workerPath;
183
- this.options = options;
184
- const { timeout, onRestart, debuggerPortOffset = -1, enableSourceMaps = false, isolatedMemory = false, logger, ...rest } = this.options;
185
- let restartPromise;
186
- let resolveRestartPromise;
187
- let activeTasks = 0;
188
- this.#worker = void 0;
189
- process.on("exit", () => {
190
- this.close();
191
- });
192
- const nodeOptions = getParsedNodeOptions();
193
- const originalOptions = { ...nodeOptions };
194
- delete nodeOptions.inspect;
195
- delete nodeOptions["inspect-brk"];
196
- delete nodeOptions.inspect_brk;
197
- if (debuggerPortOffset !== -1) {
198
- const nodeDebugType = getNodeDebugType(originalOptions);
199
- if (nodeDebugType) {
200
- const debuggerAddress = getParsedDebugAddress(originalOptions[nodeDebugType]);
201
- nodeOptions[nodeDebugType] = formatDebugAddress({
202
- host: debuggerAddress.host,
203
- port: debuggerAddress.port === 0 ? 0 : debuggerAddress.port + 1 + debuggerPortOffset
204
- });
205
- }
206
- }
207
- if (enableSourceMaps) nodeOptions["enable-source-maps"] = true;
208
- if (isolatedMemory) {
209
- delete nodeOptions["max-old-space-size"];
210
- delete nodeOptions.max_old_space_size;
211
- }
212
- const { nodeOptions: formattedNodeOptions, execArgv } = formatNodeOptions(nodeOptions);
213
- const createWorker = () => {
214
- const workerEnv = {
215
- ...process.env,
216
- ...rest.forkOptions?.env ?? {},
217
- POWERLINES_WORKER: "true",
218
- NODE_OPTIONS: formattedNodeOptions
219
- };
220
- if (workerEnv.FORCE_COLOR === void 0) {
221
- if (!workerEnv.NO_COLOR && !workerEnv.CI && workerEnv.TERM !== "dumb" && (process.stdout.isTTY || process.stderr?.isTTY)) workerEnv.FORCE_COLOR = "1";
222
- }
223
- this.#worker = new Worker(workerPath, {
224
- ...rest,
225
- forkOptions: {
226
- ...rest.forkOptions,
227
- execArgv: [...execArgv, ...rest.forkOptions?.execArgv ?? []],
228
- env: workerEnv
229
- },
230
- maxRetries: 0
231
- });
232
- restartPromise = new Promise((resolve) => {
233
- resolveRestartPromise = resolve;
234
- });
235
- /**
236
- * Jest Worker has two worker types, ChildProcessWorker (uses child_process) and NodeThreadWorker (uses worker_threads)
237
- * Powerlines uses ChildProcessWorker by default, but it can be switched to NodeThreadWorker with an experimental flag
238
- *
239
- * We only want to handle ChildProcessWorker's orphan process issue, so we access the private property "_child":
240
- * https://github.com/facebook/jest/blob/b38d7d345a81d97d1dc3b68b8458b1837fbf19be/packages/jest-worker/src/workers/ChildProcessWorker.ts
241
- *
242
- * But this property is not available in NodeThreadWorker, so we need to check if we are using ChildProcessWorker
243
- */
244
- if (!rest.enableWorkerThreads) for (const worker of this.#worker._workerPool?._workers || []) {
245
- worker._child?.on("exit", (code, signal) => {
246
- if ((code || signal && signal !== "SIGINT") && this.#worker) {
247
- logger(LogLevelLabel.ERROR, `Worker exited with code: ${code} and signal: ${signal}`);
248
- process.exit(code ?? 1);
249
- }
250
- });
251
- worker._child?.on("message", ([, data]) => {
252
- if (data && typeof data === "object" && "type" in data && data.type === "activity") onActivity();
253
- });
254
- }
255
- let aborted = false;
256
- const onActivityAbort = () => {
257
- if (!aborted) {
258
- this.options.onActivityAbort?.();
259
- aborted = true;
260
- }
261
- };
262
- const abortActivityStreamOnLog = new Transform({ transform(_chunk, _encoding, callback) {
263
- onActivityAbort();
264
- callback();
265
- } });
266
- this.#worker.getStdout().pipe(abortActivityStreamOnLog);
267
- this.#worker.getStderr().pipe(abortActivityStreamOnLog);
268
- this.#worker.getStdout().pipe(process.stdout);
269
- this.#worker.getStderr().pipe(process.stderr);
270
- };
271
- createWorker();
272
- const onHanging = () => {
273
- const worker = this.#worker;
274
- if (!worker) return;
275
- const resolve = resolveRestartPromise;
276
- createWorker();
277
- logger(LogLevelLabel.WARN, `Sending SIGTERM signal to static worker due to timeout${timeout ? ` of ${timeout / 1e3} seconds` : ""}. Subsequent errors may be a result of the worker exiting.`);
278
- worker.end().then(() => {
279
- resolve(RESTARTED);
280
- });
281
- };
282
- let hangingTimer = false;
283
- const onActivity = () => {
284
- if (hangingTimer) clearTimeout(hangingTimer);
285
- if (this.options.onActivity) this.options.onActivity();
286
- hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);
287
- };
288
- for (const method of rest.exposedMethods) {
289
- if (method.startsWith("_")) continue;
290
- this[method] = timeout ? async (...args) => {
291
- activeTasks++;
292
- try {
293
- let attempts = 0;
294
- for (;;) {
295
- onActivity();
296
- const result = await Promise.race([this.#worker[method](args.length > 0 && args[0] ? args[0] : {}), restartPromise]);
297
- if (result !== RESTARTED) return result;
298
- if (onRestart) onRestart(method, args, ++attempts);
299
- }
300
- } finally {
301
- activeTasks--;
302
- onActivity();
303
- }
304
- } : this.#worker[method].bind(this.#worker);
305
- }
306
- }
307
- async end() {
308
- const worker = this.#worker;
309
- if (!worker) throw new Error("Farm is ended, no more calls can be done to it");
310
- cleanupWorkers(worker);
311
- this.#worker = void 0;
312
- return worker.end();
313
- }
314
- /**
315
- * Quietly end the worker if it exists
316
- */
317
- close() {
318
- if (this.#worker) {
319
- cleanupWorkers(this.#worker);
320
- this.#worker.end();
321
- }
322
- }
323
- };
324
-
325
- //#endregion
326
- //#region src/index.ts
327
- /**
328
- * The Powerlines Engine class
329
- *
330
- * @remarks
331
- * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.
332
- *
333
- * @public
334
- */
335
- var PowerlinesEngine = class PowerlinesEngine {
336
- /**
337
- * The Powerlines context
338
- */
339
- #context;
340
- /**
341
- * The worker pool for managing child threads
342
- */
343
- #worker;
344
- /**
345
- * Create a new Powerlines Engine instance
346
- *
347
- * @param options - The options to initialize the context with
348
- * @returns A new instance of the Powerlines Engine
349
- */
350
- static async fromOptions(options) {
351
- const api = new PowerlinesEngine(await PowerlinesEngineContext.fromOptions(options));
352
- const packagePath = await resolvePackage("@powerlines/engine");
353
- if (!packagePath) throw new Error("Could not resolve `@powerlines/engine` package location.");
354
- api.#worker = new Worker$1(joinPaths(packagePath, "./_internal/worker.mjs"), {
355
- exposedMethods: POWERLINES_API_FUNCTIONS,
356
- logger: api.context.createLog(null)
357
- });
358
- return api;
359
- }
360
- /**
361
- * The Powerlines context
362
- */
363
- get context() {
364
- return this.#context;
365
- }
366
- /**
367
- * Create a new Powerlines Engine instance
368
- *
369
- * @param context - The Powerlines context
370
- */
371
- constructor(context) {
372
- this.#context = context;
373
- }
374
- /**
375
- * Generate the Powerlines typescript declaration file
376
- *
377
- * @remarks
378
- * 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.
379
- *
380
- * @param inlineConfig - The inline configuration for the types command
381
- */
382
- async types(inlineConfig = { command: "types" }) {
383
- const timer = this.context.timer("Types");
384
- this.context.info(" ๐Ÿ—๏ธ Generating typescript declarations for the Powerlines project");
385
- this.context.debug(" Aggregating configuration options for the Powerlines project");
386
- inlineConfig.command ??= "types";
387
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.types({
388
- options,
389
- config: inlineConfig
390
- })));
391
- this.context.debug("โœ” Powerlines types generation has completed successfully");
392
- timer();
393
- }
394
- /**
395
- * Prepare the Powerlines API
396
- *
397
- * @remarks
398
- * This method will prepare the Powerlines API for use, initializing any necessary resources.
399
- *
400
- * @param inlineConfig - The inline configuration for the prepare command
401
- */
402
- async prepare(inlineConfig = { command: "prepare" }) {
403
- const timer = this.context.timer("Prepare");
404
- this.context.info(" ๐Ÿ—๏ธ Preparing the Powerlines project");
405
- this.context.debug("Aggregating configuration options for the Powerlines project");
406
- inlineConfig.command ??= "prepare";
407
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.prepare({
408
- options,
409
- config: inlineConfig
410
- })));
411
- this.context.debug("โœ” Powerlines preparation has completed successfully");
412
- timer();
413
- }
414
- /**
415
- * Create a new Powerlines project
416
- *
417
- * @remarks
418
- * This method will create a new Powerlines project in the current directory.
419
- *
420
- * @param inlineConfig - The inline configuration for the new command
421
- * @returns A promise that resolves when the project has been created
422
- */
423
- async new(inlineConfig) {
424
- const timer = this.context.timer("New");
425
- this.context.info(" ๐Ÿ†• Creating a new Powerlines project");
426
- inlineConfig.command ??= "new";
427
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.new({
428
- options,
429
- config: inlineConfig
430
- })));
431
- this.context.debug("โœ” Powerlines new command completed successfully");
432
- timer();
433
- }
434
- /**
435
- * Clean any previously prepared artifacts
436
- *
437
- * @remarks
438
- * This method will remove the previous Powerlines artifacts from the project.
439
- *
440
- * @param inlineConfig - The inline configuration for the clean command
441
- * @returns A promise that resolves when the clean command has completed
442
- */
443
- async clean(inlineConfig = { command: "clean" }) {
444
- const timer = this.context.timer("Clean");
445
- this.context.info(" ๐Ÿงน Cleaning the previous Powerlines artifacts");
446
- inlineConfig.command ??= "clean";
447
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.clean({
448
- options,
449
- config: inlineConfig
450
- })));
451
- this.context.debug("โœ” Powerlines cleaning completed successfully");
452
- timer();
453
- }
454
- /**
455
- * Lint the project
456
- *
457
- * @param inlineConfig - The inline configuration for the lint command
458
- * @returns A promise that resolves when the lint command has completed
459
- */
460
- async lint(inlineConfig = { command: "lint" }) {
461
- const timer = this.context.timer("Lint");
462
- this.context.info(" ๐Ÿ“ Linting the Powerlines project");
463
- inlineConfig.command ??= "lint";
464
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.lint({
465
- options,
466
- config: inlineConfig
467
- })));
468
- this.context.debug("โœ” Powerlines linting completed successfully");
469
- timer();
470
- }
471
- /**
472
- * Test the project
473
- *
474
- * @remarks
475
- * This method will run the tests for the Powerlines project.
476
- *
477
- * @param inlineConfig - The inline configuration for the test command
478
- * @returns A promise that resolves when the test command has completed
479
- */
480
- async test(inlineConfig = { command: "test" }) {
481
- const timer = this.context.timer("Test");
482
- this.context.info(" ๐Ÿงช Running tests for the Powerlines project");
483
- inlineConfig.command ??= "test";
484
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.test({
485
- options,
486
- config: inlineConfig
487
- })));
488
- this.context.debug("โœ” Powerlines testing completed successfully");
489
- timer();
490
- }
491
- /**
492
- * Build the project
493
- *
494
- * @remarks
495
- * This method will build the Powerlines project, generating the necessary artifacts.
496
- *
497
- * @param inlineConfig - The inline configuration for the build command
498
- * @returns A promise that resolves when the build command has completed
499
- */
500
- async build(inlineConfig = { command: "build" }) {
501
- const timer = this.context.timer("Build");
502
- this.context.info(" ๐Ÿ“ฆ Building the Powerlines project");
503
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.build({
504
- options,
505
- config: inlineConfig
506
- })));
507
- this.context.debug("โœ” Powerlines build completed successfully");
508
- timer();
509
- }
510
- /**
511
- * Prepare the documentation for the project
512
- *
513
- * @param inlineConfig - The inline configuration for the docs command
514
- * @returns A promise that resolves when the documentation generation has completed
515
- */
516
- async docs(inlineConfig = { command: "docs" }) {
517
- const timer = this.context.timer("Docs");
518
- this.context.info(" ๐Ÿ““ Generating documentation for the Powerlines project");
519
- inlineConfig.command ??= "docs";
520
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.docs({
521
- options,
522
- config: inlineConfig
523
- })));
524
- this.context.debug("โœ” Powerlines documentation generation completed successfully");
525
- timer();
526
- }
527
- /**
528
- * Deploy the project source code
529
- *
530
- * @remarks
531
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
532
- *
533
- * @param inlineConfig - The inline configuration for the deploy command
534
- */
535
- async deploy(inlineConfig = { command: "deploy" }) {
536
- const timer = this.context.timer("Deploy");
537
- this.context.info(" ๐Ÿš€ Deploying the Powerlines project");
538
- inlineConfig.command ??= "deploy";
539
- await Promise.all(this.#context.executions.map(async (options) => this.#worker.deploy({
540
- options,
541
- config: inlineConfig
542
- })));
543
- this.context.debug("โœ” Powerlines deploy completed successfully");
544
- timer();
545
- }
546
- /**
547
- * Finalization/cleanup processing for the Powerlines API
548
- *
549
- * @remarks
550
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
551
- *
552
- * @returns A promise that resolves when the finalization process has completed
553
- */
554
- async finalize() {
555
- const timer = this.context.timer("Finalization");
556
- this.context.info(" ๐Ÿ Powerlines finalization processes started");
557
- this.#worker.close();
558
- this.context.debug("โœ” Powerlines finalization completed successfully");
559
- timer();
560
- }
561
- async [Symbol.asyncDispose]() {
562
- return this.finalize();
563
- }
564
- };
565
-
566
- //#endregion
567
- export { PowerlinesEngine };
568
- //# sourceMappingURL=index.mjs.map
8
+ export { PowerlinesEngine, PowerlinesEngineContext, createContext, createEngine, createExecutionHost, createRpcClient, finalize };