@powerlines/engine 0.15.19 → 0.15.21

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 (128) hide show
  1. package/dist/api/build.cjs +1 -1
  2. package/dist/api/build.d.mts +2 -2
  3. package/dist/api/build.mjs +1 -1
  4. package/dist/api/build.mjs.map +1 -1
  5. package/dist/api/clean.d.mts +2 -2
  6. package/dist/api/clean.mjs.map +1 -1
  7. package/dist/api/create.d.mts +2 -2
  8. package/dist/api/create.mjs.map +1 -1
  9. package/dist/api/deploy.d.mts +2 -2
  10. package/dist/api/deploy.mjs.map +1 -1
  11. package/dist/api/docs.d.mts +2 -2
  12. package/dist/api/docs.mjs.map +1 -1
  13. package/dist/api/lint.d.mts +2 -2
  14. package/dist/api/lint.mjs.map +1 -1
  15. package/dist/api/prepare.cjs +2 -2
  16. package/dist/api/prepare.d.mts +2 -2
  17. package/dist/api/prepare.mjs +2 -2
  18. package/dist/api/prepare.mjs.map +1 -1
  19. package/dist/api/test.d.mts +2 -2
  20. package/dist/api/test.mjs.map +1 -1
  21. package/dist/api/types.cjs +2 -2
  22. package/dist/api/types.d.mts +2 -2
  23. package/dist/api/types.mjs +2 -2
  24. package/dist/api/types.mjs.map +1 -1
  25. package/dist/{api-Cdw4v0W4.d.mts → api-B2dWvRMM.d.mts} +10 -7
  26. package/dist/api-B2dWvRMM.d.mts.map +1 -0
  27. package/dist/{api-6w4hZL6n.d.cts → api-DgxYwNuZ.d.cts} +8 -5
  28. package/dist/api-DgxYwNuZ.d.cts.map +1 -0
  29. package/dist/{execution-host.cjs → api.cjs} +1 -1
  30. package/dist/{execution-host.d.mts → api.d.cts} +3 -3
  31. package/dist/api.d.cts.map +1 -0
  32. package/dist/{execution-host.d.cts → api.d.mts} +3 -3
  33. package/dist/api.d.mts.map +1 -0
  34. package/dist/{execution-host.mjs → api.mjs} +2 -2
  35. package/dist/api.mjs.map +1 -0
  36. package/dist/{config-BNe23XHx.d.mts → config-C9AD-erz.d.mts} +1 -1
  37. package/dist/config-C9AD-erz.d.mts.map +1 -0
  38. package/dist/config-D6xUniHh.d.cts.map +1 -1
  39. package/dist/context/engine-context.cjs +6 -4
  40. package/dist/context/engine-context.d.cts +1 -1
  41. package/dist/context/engine-context.d.mts +1 -1
  42. package/dist/context/engine-context.mjs +6 -4
  43. package/dist/context/engine-context.mjs.map +1 -1
  44. package/dist/context/index.d.cts +1 -1
  45. package/dist/context/index.d.mts +1 -1
  46. package/dist/{context-DzgsMSWr.d.mts → context-S3XH2DWP.d.mts} +2 -2
  47. package/dist/context-S3XH2DWP.d.mts.map +1 -0
  48. package/dist/context-epL7NPvL.d.cts.map +1 -1
  49. package/dist/engine-Ct0OGdyp.mjs +571 -0
  50. package/dist/engine-Ct0OGdyp.mjs.map +1 -0
  51. package/dist/{engine-context-DEotmVzB.d.mts → engine-context-Cc93ql_I.d.mts} +5 -6
  52. package/dist/engine-context-Cc93ql_I.d.mts.map +1 -0
  53. package/dist/{engine-context-Dw8odBCo.d.cts → engine-context-lrWc13AH.d.cts} +2 -3
  54. package/dist/engine-context-lrWc13AH.d.cts.map +1 -0
  55. package/dist/engine-ntih8wNh.cjs +590 -0
  56. package/dist/engine.cjs +4 -265
  57. package/dist/engine.d.cts +3 -3
  58. package/dist/engine.d.cts.map +1 -1
  59. package/dist/engine.d.mts +5 -5
  60. package/dist/engine.d.mts.map +1 -1
  61. package/dist/engine.mjs +2 -262
  62. package/dist/helpers/create-execution-host.cjs +10 -3
  63. package/dist/helpers/create-execution-host.d.cts +20 -2
  64. package/dist/helpers/create-execution-host.d.cts.map +1 -0
  65. package/dist/helpers/create-execution-host.d.mts +20 -2
  66. package/dist/helpers/create-execution-host.d.mts.map +1 -0
  67. package/dist/helpers/create-execution-host.mjs +10 -3
  68. package/dist/helpers/create-execution-host.mjs.map +1 -1
  69. package/dist/helpers/finalize.d.cts +12 -2
  70. package/dist/helpers/finalize.d.cts.map +1 -0
  71. package/dist/helpers/finalize.d.mts +12 -2
  72. package/dist/helpers/finalize.d.mts.map +1 -0
  73. package/dist/helpers/finalize.mjs.map +1 -1
  74. package/dist/helpers/index.cjs +4 -2
  75. package/dist/helpers/index.d.cts +5 -5
  76. package/dist/helpers/index.d.mts +5 -5
  77. package/dist/helpers/index.mjs +2 -2
  78. package/dist/helpers/rpc.cjs +2 -2
  79. package/dist/helpers/rpc.d.cts +7 -2
  80. package/dist/helpers/rpc.d.cts.map +1 -0
  81. package/dist/helpers/rpc.d.mts +7 -2
  82. package/dist/helpers/rpc.d.mts.map +1 -0
  83. package/dist/helpers/rpc.mjs +2 -2
  84. package/dist/helpers/rpc.mjs.map +1 -1
  85. package/dist/helpers/stream.cjs +120 -0
  86. package/dist/helpers/stream.d.cts +45 -0
  87. package/dist/helpers/stream.d.cts.map +1 -0
  88. package/dist/helpers/stream.d.mts +45 -0
  89. package/dist/helpers/stream.d.mts.map +1 -0
  90. package/dist/helpers/stream.mjs +117 -0
  91. package/dist/helpers/stream.mjs.map +1 -0
  92. package/dist/index.cjs +2 -11
  93. package/dist/index.d.cts +3 -7
  94. package/dist/index.d.mts +5 -9
  95. package/dist/index.mjs +2 -7
  96. package/package.json +10 -12
  97. package/dist/api-6w4hZL6n.d.cts.map +0 -1
  98. package/dist/api-Cdw4v0W4.d.mts.map +0 -1
  99. package/dist/config-BNe23XHx.d.mts.map +0 -1
  100. package/dist/context-DzgsMSWr.d.mts.map +0 -1
  101. package/dist/create-execution-host-CdpuL_YG.d.mts +0 -20
  102. package/dist/create-execution-host-CdpuL_YG.d.mts.map +0 -1
  103. package/dist/create-execution-host-DbOCE5bd.d.cts +0 -20
  104. package/dist/create-execution-host-DbOCE5bd.d.cts.map +0 -1
  105. package/dist/engine-context-DEotmVzB.d.mts.map +0 -1
  106. package/dist/engine-context-Dw8odBCo.d.cts.map +0 -1
  107. package/dist/engine.mjs.map +0 -1
  108. package/dist/execution-host-worker-D7LinO52.d.cts +0 -70
  109. package/dist/execution-host-worker-D7LinO52.d.cts.map +0 -1
  110. package/dist/execution-host-worker-zpQqaW_W.d.mts +0 -70
  111. package/dist/execution-host-worker-zpQqaW_W.d.mts.map +0 -1
  112. package/dist/execution-host.d.cts.map +0 -1
  113. package/dist/execution-host.d.mts.map +0 -1
  114. package/dist/execution-host.mjs.map +0 -1
  115. package/dist/finalize-CW0cO75l.d.cts +0 -12
  116. package/dist/finalize-CW0cO75l.d.cts.map +0 -1
  117. package/dist/finalize-DeSY1r74.d.mts +0 -12
  118. package/dist/finalize-DeSY1r74.d.mts.map +0 -1
  119. package/dist/helpers/execution-host-worker.cjs +0 -327
  120. package/dist/helpers/execution-host-worker.d.cts +0 -2
  121. package/dist/helpers/execution-host-worker.d.mts +0 -2
  122. package/dist/helpers/execution-host-worker.mjs +0 -326
  123. package/dist/helpers/execution-host-worker.mjs.map +0 -1
  124. package/dist/rpc-BsFxzyAK.d.cts +0 -7
  125. package/dist/rpc-BsFxzyAK.d.cts.map +0 -1
  126. package/dist/rpc-xwbFMMNu.d.mts +0 -7
  127. package/dist/rpc-xwbFMMNu.d.mts.map +0 -1
  128. /package/dist/{index-D_TYgLX3.d.cts → index-DDRpa5CJ.d.cts} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution-host-worker.mjs","names":["#worker","JestWorker"],"sources":["../../src/helpers/execution-host-worker.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Mode } from \"@powerlines/core\";\nimport { getDefaultMode } from \"@powerlines/core/lib/config\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { resolve } from \"@stryke/fs/resolve\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { AnyFunction } from \"@stryke/types/base\";\nimport { formatDuration } from \"date-fns/formatDuration\";\nimport { Worker as JestWorker } from \"jest-worker\";\nimport { createJiti } from \"jiti\";\nimport type { ChildProcess } from \"node:child_process\";\nimport { Transform } from \"node:stream\";\nimport { parseArgs } from \"node:util\";\nimport { ExecutionHost, ExecutionHostParams } from \"../types/api\";\nimport { EngineContext } from \"../types/context\";\n\nconst RESTARTED = Symbol(\"powerlines-worker:restarted\");\n\n/**\n * The debug address is in the form of `[host:]port`. The host is optional.\n */\ninterface DebugAddress {\n host?: string;\n port: number;\n}\n\n/**\n * Formats the debug address into a string.\n */\nconst formatDebugAddress = ({ host, port }: DebugAddress): string => {\n return host ? `${host}:${port}` : `${port}`;\n};\n\nexport type NodeOptions = Record<string, string | boolean | undefined>;\n\n/**\n * Get's the debug address from the `NODE_OPTIONS` environment variable. If the\n * address is not found, it returns the default host (`undefined`) and port\n * (`9229`).\n *\n * @returns An object with the host and port of the debug address.\n */\nconst getParsedDebugAddress = (\n address: string | boolean | undefined\n): DebugAddress => {\n if (!address || !isString(address)) {\n return { host: undefined, port: 9229 };\n }\n\n // The address is in the form of `[host:]port`. Let's parse the address.\n if (address.includes(\":\")) {\n const [host, port] = address.split(\":\");\n if (!host || !port) {\n throw new Error(`Invalid debug address: ${address}`);\n }\n\n return { host, port: Number.parseInt(port, 10) };\n }\n\n return { host: undefined, port: Number.parseInt(address, 10) };\n};\n\ntype NodeInspectType = \"inspect\" | \"inspect-brk\" | undefined;\n\n/**\n * Get the debug type from the `NODE_OPTIONS` environment variable.\n */\nfunction getNodeDebugType(nodeOptions: NodeOptions): NodeInspectType {\n if (nodeOptions.inspect) {\n return \"inspect\";\n }\n if (nodeOptions[\"inspect-brk\"] || nodeOptions.inspect_brk) {\n return \"inspect-brk\";\n }\n\n return undefined;\n}\n\nconst cleanupWorkers = (worker: JestWorker) => {\n for (const curWorker of ((worker as any)._workerPool?._workers || []) as {\n _child?: ChildProcess;\n }[]) {\n curWorker._child?.kill(\"SIGINT\");\n }\n};\n\nexport interface ExecutionHostWorkerOptions<\n TExecutionAPI extends ReadonlyArray<string>\n> {\n // /**\n // * `-1` if not inspectable\n // */\n // debuggerPortOffset?: number;\n\n // /**\n // * Whether to enable source maps support in the worker, which can improve the quality of stack traces at the cost of increased memory usage and slower performance. Defaults to `false`.\n // */\n // enableSourceMaps?: boolean;\n\n /**\n * The maximum time in milliseconds a worker can run before being terminated.\n *\n * @defaultValue 900000 (15 minutes)\n */\n timeout?: number;\n\n /**\n * True if `--max-old-space-size` should not be forwarded to the worker.\n */\n isolatedMemory?: boolean;\n\n /**\n * The mode to run the worker in, which can affect how the worker is initialized and how it behaves. This is determined based on the resolved configuration of the engine, and can be used to optimize the worker for different environments (e.g., development, production, etc.).\n */\n mode?: Mode;\n\n /**\n * An optional root to resolve the execution host path from, which can be used to specify a custom root directory for the worker to use when resolving paths and loading configuration files. If this option is not provided, the worker will use the current working directory as the root directory by default.\n */\n root?: string;\n\n /**\n * The context of the {@link @powerlines/engine#Engine | Engine instance}, which can be used to access the engine's state and services within the worker.\n */\n context: EngineContext;\n\n /**\n * An array of method names that the worker exposes. These methods will be available on the Worker instance and can be called to execute tasks in the worker process.\n */\n executionMethods?: TExecutionAPI;\n}\n\nexport class ExecutionHostWorker<TExecutionAPI extends ReadonlyArray<string>> {\n #worker: JestWorker | undefined;\n\n /**\n * Creates a new instance of the ExecutionHostWorker class, which manages a worker process for executing tasks related to the Powerlines Engine. The worker is initialized with the specified options and can be used to run tasks in an isolated environment, with support for automatic restarts and activity monitoring.\n *\n * @param executionHostPath - The path to the Execution Host file.\n * @param options - The options for configuring the worker, including the execution context, exposed methods, timeout, and mode.\n * @returns A promise that resolves to an instance of the ExecutionHostWorker class.\n */\n public static async from<TExecutionAPI extends ReadonlyArray<string>>(\n executionHostPath: string,\n options: ExecutionHostWorkerOptions<TExecutionAPI>\n ) {\n const mode = await getDefaultMode(options.context.cwd);\n\n const resolvedPath = await resolve(executionHostPath, {\n paths: [\n options.context.cwd,\n options.root ? appendPath(options.root, options.context.cwd) : undefined\n ].filter(Boolean) as string[]\n });\n if (!resolvedPath) {\n throw new Error(\n `Could not resolve the provided Execution Host path: \\`${executionHostPath}\\`.`\n );\n }\n\n let exposedMethods = toArray((options.executionMethods ?? []) as string[]);\n if (exposedMethods.length === 0) {\n const jiti = createJiti(import.meta.url);\n const mod: Record<string, AnyFunction> = await jiti.import(\n jiti.esmResolve(resolvedPath)\n );\n if (isFunction(mod)) {\n exposedMethods.push(...exposedMethods, \"default\");\n } else if (isSetObject(mod)) {\n exposedMethods = Object.keys(mod).filter(name => isFunction(mod[name]));\n }\n }\n\n return new ExecutionHostWorker<TExecutionAPI>(\n resolvedPath,\n exposedMethods,\n {\n mode,\n ...options\n }\n ) as unknown as ExecutionHost<TExecutionAPI>;\n }\n\n /**\n * Create a new worker instance.\n *\n * @param executionHostPath - The path to the worker file.\n * @param exposedMethods - An array of method names that the worker exposes.\n * @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.\n */\n public constructor(\n protected executionHostPath: string,\n protected exposedMethods: string[],\n protected options: ExecutionHostWorkerOptions<TExecutionAPI>\n ) {\n const {\n timeout = 900_000,\n isolatedMemory = false,\n mode = \"production\",\n context\n } = this.options;\n\n const logger = context.extendLogger({ category: \"communication\" });\n\n let restartPromise: Promise<typeof RESTARTED>;\n let resolveRestartPromise: (arg: typeof RESTARTED) => void;\n let activeTasks = 0;\n\n this.#worker = undefined;\n\n // ensure we end workers if they weren't before exit\n process.on(\"exit\", () => {\n this.close();\n });\n\n let nodeOptions = {} as {\n [longOption: string]: string | boolean | undefined;\n };\n\n const args: string[] = [...process.execArgv];\n if (process.env.NODE_OPTIONS) {\n let isInString = false;\n let willStartNewArg = true;\n\n const stringifiedNodeOptions = process.env.NODE_OPTIONS.split(\" \").filter(\n part =>\n ((part.startsWith('\"') && part.endsWith('\"')) ||\n (part.startsWith(\"'\") && part.endsWith(\"'\"))) &&\n part\n .replace(/^['\"]|['\"]$/g, \"\")\n .split(\" \")\n .filter(isSetString).length > 0 &&\n part\n .replace(/^['\"]|['\"]$/g, \"\")\n .split(\" \")\n .filter(isSetString)\n .every(p => p.startsWith(\"--\"))\n );\n args.push(\n ...stringifiedNodeOptions.map(part => part.replace(/^['\"]|['\"]$/g, \"\"))\n );\n\n const inputNodeModules = stringifiedNodeOptions.reduce((acc, part) => {\n return acc.replace(part, \"\").trim();\n }, process.env.NODE_OPTIONS);\n for (let i = 0; i < inputNodeModules.length; i++) {\n let char = inputNodeModules[i];\n if (char) {\n // Skip any escaped characters in strings.\n if (char === \"\\\\\" && isInString) {\n // Ensure we don't have an escape character at the end.\n if (inputNodeModules.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = inputNodeModules[++i];\n if (!char) {\n continue;\n }\n }\n // If we find a space outside of a string, we should start a new argument.\n else if (char === \" \" && !isInString) {\n willStartNewArg = true;\n continue;\n }\n\n // If we find a quote, we should toggle the string flag.\n else if (char === '\"') {\n isInString = !isInString;\n continue;\n }\n\n // If we're starting a new argument, we should add it to the array.\n if (willStartNewArg) {\n args.push(char);\n willStartNewArg = false;\n }\n // Otherwise, add it to the last argument.\n else {\n args[args.length - 1] += char;\n }\n }\n }\n\n if (isInString) {\n throw new Error(\"Unterminated string\");\n }\n }\n\n if (args.length > 0) {\n const { values, tokens } = parseArgs({\n args,\n strict: false,\n tokens: true\n });\n nodeOptions = values;\n\n // For the `NODE_OPTIONS`, we support arguments with values without the `=`\n // sign. We need to parse them manually.\n let orphan = null;\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i];\n if (!token) continue;\n\n if (token.kind === \"option-terminator\") {\n break;\n }\n\n // When we encounter an option, if it's value is undefined, we should check\n // to see if the following tokens are positional parameters. If they are,\n // then the option is orphaned, and we can assign it.\n if (token.kind === \"option\") {\n orphan = !isSet(token.value) ? token : null;\n continue;\n }\n\n // If the token isn't a positional one, then we can't assign it to the found\n // orphaned option.\n if (token.kind !== \"positional\") {\n orphan = null;\n continue;\n }\n\n // If we don't have an orphan, then we can skip this token.\n if (!orphan) {\n continue;\n }\n\n // If the token is a positional one, and it has a value, so add it to the\n // values object. If it already exists, append it with a space.\n if (orphan.name in nodeOptions && isString(nodeOptions[orphan.name])) {\n nodeOptions[orphan.name] += ` ${token.value}`;\n } else {\n nodeOptions[orphan.name] = token.value;\n }\n }\n }\n\n const originalOptions = { ...nodeOptions };\n\n delete nodeOptions.inspect;\n delete nodeOptions[\"inspect-brk\"];\n delete nodeOptions.inspect_brk;\n\n if (mode === \"development\") {\n const nodeDebugType = getNodeDebugType(originalOptions);\n if (nodeDebugType) {\n const debuggerAddress = getParsedDebugAddress(\n originalOptions[nodeDebugType]\n );\n const address: DebugAddress = {\n host: debuggerAddress.host,\n // current process runs on `address.port`\n port: debuggerAddress.port === 0 ? 0 : debuggerAddress.port + 1 + 1\n };\n nodeOptions[nodeDebugType] = formatDebugAddress(address);\n }\n\n nodeOptions[\"enable-source-maps\"] = true;\n }\n\n if (isolatedMemory) {\n delete nodeOptions[\"max-old-space-size\"];\n delete nodeOptions.max_old_space_size;\n }\n\n const execArgv: string[] = [];\n const nodeOptionsParts: string[] = [];\n for (const [key, value] of Object.entries(nodeOptions)) {\n let formatted: string | null = null;\n if (value === true) {\n formatted = `--${key}`;\n } else if (value) {\n formatted = `--${key}=${\n // Values with spaces need to be quoted. We use JSON.stringify to\n // also escape any nested quotes.\n value.includes(\" \") && !value.startsWith('\"')\n ? JSON.stringify(value)\n : value\n }`;\n }\n\n if (formatted === null) {\n continue;\n }\n\n if (\n [\n \"experimental-network-inspection\",\n \"experimental-storage-inspection\",\n \"experimental-worker-inspection\",\n \"experimental-inspector-network-resource\"\n ].includes(key)\n ) {\n execArgv.push(formatted);\n } else {\n nodeOptionsParts.push(formatted);\n }\n }\n\n const onHanging = () => {\n const worker = this.#worker;\n if (!worker) {\n return;\n }\n\n const resolve = resolveRestartPromise;\n // eslint-disable-next-line ts/no-use-before-define\n createWorker();\n\n logger.warn(\n `Sending SIGTERM signal to worker due to timeout${\n timeout ? ` of ${formatDuration({ seconds: timeout / 1000 })}` : \"\"\n }. Subsequent errors may be a result of the worker exiting.`\n );\n\n void worker.end().then(() => {\n resolve(RESTARTED);\n });\n };\n\n let hangingTimer: NodeJS.Timeout | false = false;\n\n const onActivity = () => {\n if (hangingTimer) {\n clearTimeout(hangingTimer);\n }\n\n hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);\n };\n\n const createWorker = () => {\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n NODE_ENV: mode,\n NODE_OPTIONS: nodeOptionsParts.join(\" \"),\n POWERLINES_EXECUTION_HOST_WORKER: \"true\"\n };\n\n if (env.FORCE_COLOR === undefined) {\n // Mirror the enablement heuristic from picocolors (see https://github.com/vercel/next.js/blob/6a40da0345939fe4f7b1ae519b296a86dd103432/packages/next/src/lib/picocolors.ts#L21-L24).\n // Picocolors snapshots `process.env`/`stdout.isTTY` at module load time, so when the worker\n // process bootstraps with piped stdio its own check would disable colors. Re-evaluating the\n // same conditions here lets us opt the worker into color output only when the parent would\n // have seen colors, while still respecting explicit opt-outs like NO_COLOR.\n const supportsColors =\n !env.NO_COLOR &&\n !env.CI &&\n env.TERM !== \"dumb\" &&\n (process.stdout.isTTY || process.stderr?.isTTY);\n\n if (supportsColors) {\n env.FORCE_COLOR = \"1\";\n }\n }\n\n this.#worker = new JestWorker(executionHostPath, {\n maxRetries: 0,\n exposedMethods: this.exposedMethods,\n computeWorkerKey: (_, ...args: Array<unknown>) => {\n let executionId = \"default\";\n let configIndex = 0;\n if (args.length > 0 && isSetObject(args[0])) {\n const arg = args[0] as ExecutionHostParams;\n if (isSetObject(arg.options)) {\n configIndex = arg.options.configIndex ?? 0;\n executionId = arg.options.executionId || \"default\";\n }\n }\n\n return `${executionId}-${configIndex}`;\n },\n forkOptions: {\n execArgv,\n env\n }\n });\n\n restartPromise = new Promise(resolve => {\n resolveRestartPromise = resolve;\n });\n\n for (const worker of ((this.#worker as any)._workerPool?._workers ||\n []) as {\n _child?: ChildProcess;\n }[]) {\n worker._child?.on(\"exit\", (code, signal) => {\n logger.debug(\n `Worker process exited with code ${code} and signal ${signal}`\n );\n\n if ((code || (signal && signal !== \"SIGINT\")) && this.#worker) {\n const error = new Error(\n `Execution Host Worker exited unexpectedly with code ${\n code\n } and signal ${signal}`\n );\n logger.error(error);\n\n throw error;\n }\n });\n\n worker._child?.on(\"error\", error => {\n logger.error({\n meta: { category: \"communication\" },\n message: `Worker process emitted an error: ${error.message}`,\n error\n });\n });\n\n // if a child process emits a particular message, we track that as activity\n // so the parent process can keep track of progress\n worker._child?.on(\"message\", data => {\n onActivity();\n\n if (Array.isArray(data) && data.length > 1 && isNumber(data[0])) {\n if (data[0] === 0) {\n logger.trace(\n `Received message from worker: ${JSON.stringify(data.slice(1), null, 2)}`\n );\n } else {\n logger.debug(\n `Received error message from worker: ${JSON.stringify(\n data.slice(1),\n null,\n 2\n )}`\n );\n }\n }\n\n logger.trace(\n `Received message from worker: ${JSON.stringify(data, null, 2)}`\n );\n });\n }\n\n let aborted = false;\n const onActivityAbort = () => {\n if (!aborted) {\n aborted = true;\n }\n };\n\n // Listen to the worker's stdout and stderr, if there's any thing logged, abort the activity first\n const abortActivityStreamOnLog = new Transform({\n transform(_chunk, _encoding, callback) {\n onActivityAbort();\n callback();\n }\n });\n // Stop the activity if there's any output from the worker\n this.#worker.getStdout().pipe(abortActivityStreamOnLog);\n this.#worker.getStderr().pipe(abortActivityStreamOnLog);\n\n // Pipe the worker's stdout and stderr to the parent process\n this.#worker.getStdout().pipe(process.stdout);\n this.#worker.getStderr().pipe(process.stderr);\n };\n createWorker();\n\n for (const method of this.exposedMethods) {\n if (method.startsWith(\"_\")) {\n continue;\n }\n\n (this as any)[method] = timeout\n ? async (...args: any[]) => {\n activeTasks++;\n try {\n let attempts = 0;\n for (;;) {\n onActivity();\n\n const result = await Promise.race([\n // eslint-disable-next-line ts/no-unsafe-call\n (this.#worker as any)[method](\n args.length > 0 && args[0] ? args[0] : {}\n ),\n restartPromise\n ]);\n if (result !== RESTARTED) {\n return result;\n }\n\n logger.warn(\n `Execution Host Worker was restarted while calling method \"${\n method\n }\" (attempt ${attempts++}). Retrying the call...`\n );\n }\n } finally {\n activeTasks--;\n onActivity();\n }\n }\n : // eslint-disable-next-line ts/no-unsafe-call\n (this.#worker as any)[method].bind(this.#worker);\n }\n }\n\n /**\n * Ends the worker process and cleans up any resources associated with it. This method should be called when the worker is no longer needed, to ensure that it is properly terminated and does not continue to consume system resources. If the worker is already terminated or was never initialized, this method will throw an error.\n *\n * @returns A promise that resolves when the worker has been successfully terminated.\n */\n public async end(): ReturnType<JestWorker[\"end\"]> {\n const worker = this.#worker;\n if (!worker) {\n throw new Error(\"Execution Host Worker is not initialized\");\n }\n\n cleanupWorkers(worker);\n this.#worker = undefined;\n return worker.end();\n }\n\n /**\n * Quietly end the worker if it exists\n */\n public close(): void {\n if (this.#worker) {\n cleanupWorkers(this.#worker);\n void this.#worker.end();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuCA,MAAM,YAAY,OAAO,8BAA8B;;;;AAavD,MAAM,sBAAsB,EAAE,MAAM,WAAiC;AACnE,QAAO,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG;;;;;;;;;AAYvC,MAAM,yBACJ,YACiB;AACjB,KAAI,CAAC,WAAW,CAAC,SAAS,QAAQ,CAChC,QAAO;EAAE,MAAM;EAAW,MAAM;EAAM;AAIxC,KAAI,QAAQ,SAAS,IAAI,EAAE;E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AAU,EAC7C,UAAU,QAAQ,WAAW,UAAU;AACrC,qBAAiB;AACjB,cAAU;MAEb,CAAC;AAEF,SAAKA,OAAQ,WAAW,CAAC,KAAK,yBAAyB;AACvD,SAAKA,OAAQ,WAAW,CAAC,KAAK,yBAAyB;AAGvD,SAAKA,OAAQ,WAAW,CAAC,KAAK,QAAQ,OAAO;AAC7C,SAAKA,OAAQ,WAAW,CAAC,KAAK,QAAQ,OAAO;;AAE/C,gBAAc;AAEd,OAAK,MAAM,UAAU,KAAK,gBAAgB;AACxC,OAAI,OAAO,WAAW,IAAI,CACxB;AAGF,GAAC,KAAa,UAAU,UACpB,OAAO,GAAG,SAAgB;AACxB;AACA,QAAI;KACF,IAAI,WAAW;AACf,cAAS;AACP,kBAAY;MAEZ,MAAM,SAAS,MAAM,QAAQ,KAAK,CAE/B,MAAKA,OAAgB,QACpB,KAAK,SAAS,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE,CAC1C,EACD,eACD,CAAC;AACF,UAAI,WAAW,UACb,QAAO;AAGT,aAAO,KACL,6DACE,OACD,aAAa,WAAW,yBAC1B;;cAEK;AACR;AACA,iBAAY;;OAIf,MAAKA,OAAgB,QAAQ,KAAK,MAAKA,OAAQ;;;;;;;;CASxD,MAAa,MAAqC;EAChD,MAAM,SAAS,MAAKA;AACpB,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,2CAA2C;AAG7D,iBAAe,OAAO;AACtB,QAAKA,SAAU;AACf,SAAO,OAAO,KAAK;;;;;CAMrB,AAAO,QAAc;AACnB,MAAI,MAAKA,QAAS;AAChB,kBAAe,MAAKA,OAAQ;AAC5B,GAAK,MAAKA,OAAQ,KAAK"}
@@ -1,7 +0,0 @@
1
- import { i as RpcClientOptions, u as RpcClient } from "./config-D6xUniHh.cjs";
2
-
3
- //#region src/helpers/rpc.d.ts
4
- declare function createRpcClient(options: RpcClientOptions): RpcClient;
5
- //#endregion
6
- export { createRpcClient as t };
7
- //# sourceMappingURL=rpc-BsFxzyAK.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-BsFxzyAK.d.cts","names":[],"sources":["../src/helpers/rpc.ts"],"mappings":";;;iBA0LgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAgB,SAAA"}
@@ -1,7 +0,0 @@
1
- import { i as RpcClientOptions, u as RpcClient } from "./config-BNe23XHx.mjs";
2
-
3
- //#region src/helpers/rpc.d.ts
4
- declare function createRpcClient(options: RpcClientOptions): RpcClient;
5
- //#endregion
6
- export { createRpcClient as t };
7
- //# sourceMappingURL=rpc-xwbFMMNu.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc-xwbFMMNu.d.mts","names":[],"sources":["../src/helpers/rpc.ts"],"mappings":";;;iBA0LgB,eAAA,CAAgB,OAAA,EAAS,gBAAA,GAAgB,SAAA"}