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