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