@powerlines/engine 0.44.1 → 0.44.3

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 (38) hide show
  1. package/dist/_internal/worker.cjs +34 -5
  2. package/dist/_internal/worker.mjs +35 -6
  3. package/dist/_internal/worker.mjs.map +1 -1
  4. package/dist/api.cjs +4 -4
  5. package/dist/api.mjs +4 -4
  6. package/dist/{base-context-DkGTyGX0.cjs → base-context-CAA1druQ.cjs} +34 -1
  7. package/dist/{base-context-Dv5OTHxZ.mjs → base-context-fOM4ZWUo.mjs} +39 -6
  8. package/dist/base-context-fOM4ZWUo.mjs.map +1 -0
  9. package/dist/context/index.cjs +3 -3
  10. package/dist/context/index.d.cts.map +1 -1
  11. package/dist/context/index.d.mts.map +1 -1
  12. package/dist/context/index.mjs +3 -3
  13. package/dist/{engine-context-CytME-Ht.mjs → engine-context-BWGxMU_n.mjs} +2 -2
  14. package/dist/{engine-context-CytME-Ht.mjs.map → engine-context-BWGxMU_n.mjs.map} +1 -1
  15. package/dist/{engine-context-CDSR7PHF.cjs → engine-context-CUPubmrM.cjs} +1 -1
  16. package/dist/{execution-context-B-CVP76S.cjs → execution-context-BoJhCK0d.cjs} +9 -9
  17. package/dist/{execution-context-F7RyGqff.mjs → execution-context-CFJst4Fz.mjs} +10 -10
  18. package/dist/{execution-context-F7RyGqff.mjs.map → execution-context-CFJst4Fz.mjs.map} +1 -1
  19. package/dist/index.cjs +107 -41
  20. package/dist/index.d.cts +8 -0
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +8 -0
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +107 -41
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/storage/index.cjs +1 -1
  27. package/dist/storage/index.mjs +1 -1
  28. package/dist/{tsconfig-Cstsoprg.mjs → tsconfig-CI6bla4E.mjs} +2 -2
  29. package/dist/{tsconfig-Cstsoprg.mjs.map → tsconfig-CI6bla4E.mjs.map} +1 -1
  30. package/dist/{tsconfig-DeyWQC2N.cjs → tsconfig-QMSxSwBD.cjs} +1 -1
  31. package/dist/typescript/index.cjs +1 -1
  32. package/dist/typescript/index.mjs +1 -1
  33. package/dist/{virtual-CUgOdyIa.mjs → virtual-CYGZHTDd.mjs} +5 -5
  34. package/dist/virtual-CYGZHTDd.mjs.map +1 -0
  35. package/dist/{virtual-1hYa9zCy.cjs → virtual-Ct3ZqPeN.cjs} +2 -2
  36. package/package.json +3 -3
  37. package/dist/base-context-Dv5OTHxZ.mjs.map +0 -1
  38. package/dist/virtual-CUgOdyIa.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["Worker","#worker","JestWorker","#worker","Worker","#context"],"sources":["../src/_internal/ipc/helpers.ts","../src/_internal/helpers/worker.ts","../src/index.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 { LogMeta } from \"@powerlines/core\";\nimport { toArray } from \"@stryke/convert/to-array\";\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 { Serializable } from \"node:worker_threads\";\nimport {\n IpcMessage,\n UpdateCommandMessagePayload,\n UpdateHookMessagePayload,\n UpdatePluginMessagePayload,\n WriteLogMessagePayload\n} from \"./messages\";\n\nexport function parseIpcMessage(data: Serializable): IpcMessage | undefined {\n let message: Record<string, any> | undefined;\n if (isSetObject(data)) {\n message = data;\n } else if (isString(data)) {\n try {\n const parsed = JSON.parse(data);\n if (isSetObject(parsed)) {\n message = parsed;\n }\n } catch {\n // Do nothing\n }\n }\n\n if (\n message &&\n isSetString(message.id) &&\n isSetString(message.type) &&\n isSetString(message.executionId) &&\n Number.isInteger(message.executionIndex) &&\n !Number.isNaN(message.timestamp)\n ) {\n return message as IpcMessage;\n }\n\n return undefined;\n}\n\nexport function parseWriteLogMessagePayload(\n data?: Record<string, any>\n): WriteLogMessagePayload {\n if (\n isSetObject(data) &&\n isSetString(data.type) &&\n isSetString(data.category) &&\n isSetString(data.logId) &&\n isSetString(data.message)\n ) {\n return {\n ...(data as LogMeta),\n message: toArray(data.message).filter(Boolean)\n };\n }\n\n throw new Error('Invalid \"write-log\" message payload.');\n}\n\nexport function parseUpdateCommandMessagePayload(\n data?: Record<string, any>\n): UpdateCommandMessagePayload {\n if (isSetString(data?.command)) {\n return {\n command: data.command\n };\n }\n\n throw new Error('Invalid \"update-command\" message payload.');\n}\n\nexport function parseUpdateHookMessagePayload(\n data?: Record<string, any>\n): UpdateHookMessagePayload {\n if (\n isSetString(data?.hook) &&\n [\"pre\", \"post\", \"normal\"].includes(data.order)\n ) {\n return {\n hook: data.hook,\n order: data.order\n };\n }\n\n throw new Error('Invalid \"update-hook\" message payload.');\n}\n\nexport function parseUpdatePluginMessagePayload(\n data?: Record<string, any>\n): UpdatePluginMessagePayload {\n if (isSetString(data?.plugin)) {\n return {\n plugin: data.plugin\n };\n }\n\n throw new Error('Invalid \"update-plugin\" message payload.');\n}\n","/* -------------------------------------------------------------------\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 { Logger } from \"@powerlines/core\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport { formatDuration } from \"date-fns/formatDuration\";\nimport { Worker as JestWorker } from \"jest-worker\";\nimport type { ChildProcess } from \"node:child_process\";\nimport { cpus } from \"node:os\";\nimport { Transform } from \"node:stream\";\nimport { parseArgs } from \"node:util\";\nimport {\n parseIpcMessage,\n parseUpdateCommandMessagePayload,\n parseUpdateHookMessagePayload,\n parseUpdatePluginMessagePayload,\n parseWriteLogMessagePayload\n} from \"../ipc/helpers\";\nimport {\n IpcMessage,\n IpcMessageType,\n UpdateCommandIpcMessage,\n UpdateHookIpcMessage,\n UpdatePluginIpcMessage,\n WriteLogIpcMessage\n} from \"../ipc/messages\";\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\n/**\n * Node.js CLI flags that are not allowed in NODE_OPTIONS and must be\n * passed as direct CLI arguments via execArgv.\n * This set is the difference between all Node.js CLI flags and the ones **not**\n * allowed in NODE_OPTIONS, as listed in the Node.js documentation:\n * https://nodejs.org/api/cli.html#node_optionsoptions\n *\n * It is not exhaustive since not all options make sense for Powerlines (e.g. --test)\n */\nconst EXEC_ARGV_ONLY_OPTIONS = new Set([\n \"experimental-network-inspection\",\n \"experimental-storage-inspection\",\n \"experimental-worker-inspection\",\n \"experimental-inspector-network-resource\"\n]);\n\nfunction formatArg(\n key: string,\n value: string | boolean | undefined\n): string | null {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${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 return null;\n}\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nconst tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[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 (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++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 return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`. Options that are not allowed in\n * NODE_OPTIONS are returned separately as execArgv.\n *\n * @param args - The arguments to be stringified.\n * @returns An object with `nodeOptions` string and `execArgv` array.\n */\nfunction formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): { nodeOptions: string; execArgv: string[] } {\n const nodeOptionsParts: string[] = [];\n const execArgv: string[] = [];\n\n for (const [key, value] of Object.entries(args)) {\n const formatted = formatArg(key, value);\n if (formatted === null) continue;\n\n if (EXEC_ARGV_ONLY_OPTIONS.has(key)) {\n execArgv.push(formatted);\n } else {\n nodeOptionsParts.push(formatted);\n }\n }\n\n return { nodeOptions: nodeOptionsParts.join(\" \"), execArgv };\n}\n\nexport type NodeOptions = Record<string, string | boolean | undefined>;\n\nconst parseNodeArgs = (args: string[]): NodeOptions => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\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 values && isString(values[orphan.name])) {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\nfunction getParsedNodeOptions(): Record<string, string | boolean | undefined> {\n const args = [...process.execArgv, ...getNodeOptionsArgs()];\n if (args.length === 0) return {};\n\n return parseNodeArgs(args);\n}\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 type WorkerOptions = ConstructorParameters<typeof JestWorker>[1] & {\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 * True if `--max-old-space-size` should not be forwarded to the worker.\n */\n isolatedMemory?: boolean;\n\n /**\n * The maximum time in milliseconds a worker can run before being terminated. Defaults to `0` (no timeout).\n */\n timeout?: number;\n\n /**\n * A callback function that is called when the worker is active.\n */\n onActivity?: () => void;\n\n /**\n * A callback function that is called when the worker activity is aborted.\n */\n onActivityAbort?: () => void;\n\n /**\n * A callback function that is called when the worker is restarted.\n */\n onRestart?: (method: string, args: any[], attempts: number) => void;\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 exposedMethods: ReadonlyArray<string>;\n\n /**\n * Whether to use worker threads instead of child processes for the worker implementation. This is an experimental feature and may not be suitable for all use cases. Defaults to `false`.\n */\n enableWorkerThreads?: boolean;\n\n /**\n * A custom log function that can be used to log messages from the worker. This can be useful for debugging and monitoring the worker's activity. The function should accept a string message as its argument.\n */\n logger: Logger;\n\n /**\n * A callback function that is called when the worker sends a log message.\n */\n onWriteLog?: (payload: WriteLogIpcMessage) => MaybePromise<void>;\n\n /**\n * A callback function that is called when the worker sends an update command message.\n */\n onUpdateCommand?: (payload: UpdateCommandIpcMessage) => MaybePromise<void>;\n\n /**\n * A callback function that is called when the worker sends an update hook message.\n */\n onUpdateHook?: (payload: UpdateHookIpcMessage) => MaybePromise<void>;\n\n /**\n * A callback function that is called when the worker sends an update plugin message.\n */\n onUpdatePlugin?: (payload: UpdatePluginIpcMessage) => MaybePromise<void>;\n};\n\nexport class Worker {\n #worker: JestWorker | undefined;\n\n /**\n * Create a new worker instance.\n *\n * @param workerPath - The path to the worker file.\n * @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.\n */\n public constructor(\n protected workerPath: string,\n protected options: WorkerOptions\n ) {\n const {\n timeout,\n onRestart,\n debuggerPortOffset = -1,\n enableSourceMaps = false,\n isolatedMemory = false,\n logger,\n ...rest\n } = this.options;\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 const nodeOptions = getParsedNodeOptions();\n const originalOptions = { ...nodeOptions };\n delete nodeOptions.inspect;\n delete nodeOptions[\"inspect-brk\"];\n delete nodeOptions.inspect_brk;\n if (debuggerPortOffset !== -1) {\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:\n debuggerAddress.port === 0\n ? 0\n : debuggerAddress.port + 1 + debuggerPortOffset\n };\n nodeOptions[nodeDebugType] = formatDebugAddress(address);\n }\n }\n\n if (enableSourceMaps) {\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 { nodeOptions: formattedNodeOptions, execArgv } =\n formatNodeOptions(nodeOptions);\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 static 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 if (this.options.onActivity) {\n this.options.onActivity();\n }\n\n hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);\n };\n\n const createWorker = () => {\n const workerEnv: NodeJS.ProcessEnv = {\n ...process.env,\n ...((rest.forkOptions?.env ?? {}) as any),\n POWERLINES_WORKER: \"true\",\n NODE_OPTIONS: formattedNodeOptions\n };\n\n if (workerEnv.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 !workerEnv.NO_COLOR &&\n !workerEnv.CI &&\n workerEnv.TERM !== \"dumb\" &&\n (process.stdout.isTTY || process.stderr?.isTTY);\n\n if (supportsColors) {\n workerEnv.FORCE_COLOR = \"1\";\n }\n }\n\n this.#worker = new JestWorker(workerPath, {\n maxRetries: 0,\n numWorkers: cpus().length ?? 3,\n ...rest,\n forkOptions: {\n ...rest.forkOptions,\n execArgv: [...execArgv, ...(rest.forkOptions?.execArgv ?? [])],\n env: workerEnv\n }\n });\n restartPromise = new Promise(resolve => {\n resolveRestartPromise = resolve;\n });\n\n /**\n * Jest Worker has two worker types, ChildProcessWorker (uses child_process) and NodeThreadWorker (uses worker_threads)\n * Powerlines uses ChildProcessWorker by default, but it can be switched to NodeThreadWorker with an experimental flag\n *\n * We only want to handle ChildProcessWorker's orphan process issue, so we access the private property \"_child\":\n * https://github.com/facebook/jest/blob/b38d7d345a81d97d1dc3b68b8458b1837fbf19be/packages/jest-worker/src/workers/ChildProcessWorker.ts\n *\n * But this property is not available in NodeThreadWorker, so we need to check if we are using ChildProcessWorker\n */\n if (!rest.enableWorkerThreads) {\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 if ((code || (signal && signal !== \"SIGINT\")) && this.#worker) {\n logger.error(\n `Worker exited with code: ${code} and signal: ${signal}`\n );\n\n // if a child process doesn't exit gracefully, we want to bubble up the exit code to the parent process\n process.exit(code ?? 1);\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 if (\n isSetObject(data) &&\n (data as IpcMessage).type === IpcMessageType.ACTIVITY\n ) {\n onActivity();\n } else {\n const message = parseIpcMessage(data);\n if (message) {\n logger.trace(\n `Received IPC message from worker: ${JSON.stringify(message)}`\n );\n\n switch (message.type) {\n case IpcMessageType.WRITE_LOG:\n if (options.onWriteLog) {\n void Promise.resolve(\n options.onWriteLog({\n ...message,\n type: IpcMessageType.WRITE_LOG,\n payload: parseWriteLogMessagePayload(message.payload)\n })\n );\n }\n break;\n\n case IpcMessageType.UPDATE_COMMAND:\n if (options.onUpdateCommand) {\n void Promise.resolve(\n options.onUpdateCommand({\n ...message,\n type: IpcMessageType.UPDATE_COMMAND,\n payload: parseUpdateCommandMessagePayload(\n message.payload\n )\n })\n );\n }\n break;\n\n case IpcMessageType.UPDATE_HOOK:\n if (options.onUpdateHook) {\n void Promise.resolve(\n options.onUpdateHook({\n ...message,\n type: IpcMessageType.UPDATE_HOOK,\n payload: parseUpdateHookMessagePayload(\n message.payload\n )\n })\n );\n }\n break;\n\n case IpcMessageType.UPDATE_PLUGIN:\n if (options.onUpdatePlugin) {\n void Promise.resolve(\n options.onUpdatePlugin({\n ...message,\n type: IpcMessageType.UPDATE_PLUGIN,\n payload: parseUpdatePluginMessagePayload(\n message.payload\n )\n })\n );\n }\n break;\n\n case IpcMessageType.ACTIVITY:\n case undefined:\n default: {\n break;\n }\n }\n }\n }\n });\n }\n }\n\n let aborted = false;\n const onActivityAbort = () => {\n if (!aborted) {\n this.options.onActivityAbort?.();\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 rest.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 if (onRestart) {\n onRestart(method, args, ++attempts);\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 public async end(): ReturnType<JestWorker[\"end\"]> {\n const worker = this.#worker;\n if (!worker) {\n throw new Error(\"Farm is ended, no more calls can be done to it\");\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","/* -------------------------------------------------------------------\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 type {\n BuildInlineConfig,\n CleanInlineConfig,\n DeployInlineConfig,\n DocsInlineConfig,\n Engine,\n EngineContext,\n EngineOptions,\n ExecutionWorkerProcess,\n LintInlineConfig,\n NewInlineConfig,\n PrepareInlineConfig,\n TestInlineConfig,\n TypesInlineConfig\n} from \"@powerlines/core\";\nimport { POWERLINES_API_FUNCTIONS } from \"@powerlines/core/constants\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { PartialKeys } from \"@stryke/types/base\";\nimport { Worker } from \"./_internal/helpers/worker\";\nimport { PowerlinesEngineContext } from \"./context/engine-context\";\n\n/**\n * The Powerlines Engine class\n *\n * @remarks\n * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.\n *\n * @public\n */\nexport class PowerlinesEngine implements Engine, AsyncDisposable {\n /**\n * The Powerlines context\n */\n #context: EngineContext;\n\n /**\n * The worker pool for managing child threads\n */\n #worker!: ExecutionWorkerProcess;\n\n /**\n * Create a new Powerlines Engine instance\n *\n * @param options - The options to initialize the context with\n * @returns A new instance of the Powerlines Engine\n */\n public static async fromOptions(\n options: EngineOptions\n ): Promise<PowerlinesEngine> {\n const api = new PowerlinesEngine(\n await PowerlinesEngineContext.fromOptions(options)\n );\n\n const packagePath = await resolvePackage(\"@powerlines/engine\");\n if (!packagePath) {\n throw new Error(\n \"Could not resolve `@powerlines/engine` package location.\"\n );\n }\n\n api.#worker = new Worker(joinPaths(packagePath, \"./_internal/worker.mjs\"), {\n enableSourceMaps: options.mode === \"development\",\n exposedMethods: POWERLINES_API_FUNCTIONS,\n logger: api.context.extendLogger({ category: \"ipc\" })\n }) as unknown as ExecutionWorkerProcess;\n\n return api;\n }\n\n /**\n * The Powerlines context\n */\n public get context(): EngineContext {\n return this.#context;\n }\n\n /**\n * Create a new Powerlines Engine instance\n *\n * @param context - The Powerlines context\n */\n protected constructor(context: EngineContext) {\n this.#context = context;\n }\n\n /**\n * Generate the Powerlines typescript declaration file\n *\n * @remarks\n * 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.\n *\n * @param inlineConfig - The inline configuration for the types command\n */\n public async types(\n inlineConfig: PartialKeys<\n Omit<TypesInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"types\"\n }\n ) {\n const timer = this.context.timer(\"Types\");\n this.context.info(\n \" 🏗️ Generating typescript declarations for the Powerlines project\"\n );\n\n this.context.debug(\n \" Aggregating configuration options for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"types\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.types({\n options: execution.options,\n config: inlineConfig as TypesInlineConfig\n })\n )\n );\n\n this.context.debug(\n \"✔ Powerlines types generation has completed successfully\"\n );\n timer();\n }\n\n /**\n * Prepare the Powerlines API\n *\n * @remarks\n * This method will prepare the Powerlines API for use, initializing any necessary resources.\n *\n * @param inlineConfig - The inline configuration for the prepare command\n */\n public async prepare(\n inlineConfig:\n | PartialKeys<Omit<PrepareInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<TypesInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<NewInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<CleanInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<LintInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<DocsInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<DeployInlineConfig, \"configFile\">, \"command\"> = {\n command: \"prepare\"\n }\n ) {\n const timer = this.context.timer(\"Prepare\");\n this.context.info(\" 🏗️ Preparing the Powerlines project\");\n\n this.context.debug(\n \"Aggregating configuration options for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"prepare\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.prepare({\n options: execution.options,\n config: inlineConfig as PrepareInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines preparation has completed successfully\");\n timer();\n }\n\n /**\n * Create a new Powerlines project\n *\n * @remarks\n * This method will create a new Powerlines project in the current directory.\n *\n * @param inlineConfig - The inline configuration for the new command\n * @returns A promise that resolves when the project has been created\n */\n public async new(inlineConfig: PartialKeys<NewInlineConfig, \"command\">) {\n const timer = this.context.timer(\"New\");\n this.context.info(\" 🆕 Creating a new Powerlines project\");\n\n inlineConfig.command ??= \"new\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.new({\n options: execution.options,\n config: inlineConfig as NewInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines new command completed successfully\");\n timer();\n }\n\n /**\n * Clean any previously prepared artifacts\n *\n * @remarks\n * This method will remove the previous Powerlines artifacts from the project.\n *\n * @param inlineConfig - The inline configuration for the clean command\n * @returns A promise that resolves when the clean command has completed\n */\n public async clean(\n inlineConfig:\n | PartialKeys<Omit<CleanInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<PrepareInlineConfig, \"configFile\">, \"command\"> = {\n command: \"clean\"\n }\n ) {\n const timer = this.context.timer(\"Clean\");\n this.context.info(\" 🧹 Cleaning the previous Powerlines artifacts\");\n\n inlineConfig.command ??= \"clean\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.clean({\n options: execution.options,\n config: inlineConfig as CleanInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines cleaning completed successfully\");\n timer();\n }\n\n /**\n * Lint the project\n *\n * @param inlineConfig - The inline configuration for the lint command\n * @returns A promise that resolves when the lint command has completed\n */\n public async lint(\n inlineConfig:\n | PartialKeys<Omit<LintInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\"> = {\n command: \"lint\"\n }\n ) {\n const timer = this.context.timer(\"Lint\");\n this.context.info(\" 📝 Linting the Powerlines project\");\n\n inlineConfig.command ??= \"lint\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.lint({\n options: execution.options,\n config: inlineConfig as LintInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines linting completed successfully\");\n timer();\n }\n\n /**\n * Test the project\n *\n * @remarks\n * This method will run the tests for the Powerlines project.\n *\n * @param inlineConfig - The inline configuration for the test command\n * @returns A promise that resolves when the test command has completed\n */\n public async test(\n inlineConfig:\n | PartialKeys<Omit<TestInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\"> = {\n command: \"test\"\n }\n ) {\n const timer = this.context.timer(\"Test\");\n this.context.info(\" 🧪 Running tests for the Powerlines project\");\n\n inlineConfig.command ??= \"test\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.test({\n options: execution.options,\n config: inlineConfig as TestInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines testing completed successfully\");\n timer();\n }\n\n /**\n * Build the project\n *\n * @remarks\n * This method will build the Powerlines project, generating the necessary artifacts.\n *\n * @param inlineConfig - The inline configuration for the build command\n * @returns A promise that resolves when the build command has completed\n */\n public async build(\n inlineConfig: PartialKeys<\n Omit<BuildInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"build\"\n }\n ) {\n const timer = this.context.timer(\"Build\");\n this.context.info(\" 📦 Building the Powerlines project\");\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.build({\n options: execution.options,\n config: inlineConfig as BuildInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines build completed successfully\");\n timer();\n }\n\n /**\n * Prepare the documentation for the project\n *\n * @param inlineConfig - The inline configuration for the docs command\n * @returns A promise that resolves when the documentation generation has completed\n */\n public async docs(\n inlineConfig: PartialKeys<\n Omit<DocsInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"docs\"\n }\n ) {\n const timer = this.context.timer(\"Docs\");\n this.context.info(\n \" 📓 Generating documentation for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"docs\";\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.docs({\n options: execution.options,\n config: inlineConfig as DocsInlineConfig\n })\n )\n );\n\n this.context.debug(\n \"✔ Powerlines documentation generation completed successfully\"\n );\n timer();\n }\n\n /**\n * Deploy the project source code\n *\n * @remarks\n * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.\n *\n * @param inlineConfig - The inline configuration for the deploy command\n */\n public async deploy(\n inlineConfig: PartialKeys<\n Omit<DeployInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"deploy\"\n }\n ) {\n const timer = this.context.timer(\"Deploy\");\n this.context.info(\" 🚀 Deploying the Powerlines project\");\n\n inlineConfig.command ??= \"deploy\";\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.deploy({\n options: execution.options,\n config: inlineConfig as DeployInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines deploy completed successfully\");\n timer();\n }\n\n /**\n * Finalization/cleanup processing for the Powerlines API\n *\n * @remarks\n * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.\n *\n * @returns A promise that resolves when the finalization process has completed\n */\n public async finalize() {\n const timer = this.context.timer(\"Finalization\");\n this.context.info(\" 🏁 Powerlines finalization processes started\");\n\n this.#worker.close();\n\n this.context.debug(\"✔ Powerlines finalization completed successfully\");\n timer();\n }\n\n async [Symbol.asyncDispose]() {\n return this.finalize();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAAgB,MAA4C;CAC1E,IAAI;AACJ,KAAI,YAAY,KAAK,CACnB,WAAU;UACD,SAAS,KAAK,CACvB,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,MAAI,YAAY,OAAO,CACrB,WAAU;SAEN;AAKV,KACE,WACA,YAAY,QAAQ,GAAG,IACvB,YAAY,QAAQ,KAAK,IACzB,YAAY,QAAQ,YAAY,IAChC,OAAO,UAAU,QAAQ,eAAe,IACxC,CAAC,OAAO,MAAM,QAAQ,UAAU,CAEhC,QAAO;;AAMX,SAAgB,4BACd,MACwB;AACxB,KACE,YAAY,KAAK,IACjB,YAAY,KAAK,KAAK,IACtB,YAAY,KAAK,SAAS,IAC1B,YAAY,KAAK,MAAM,IACvB,YAAY,KAAK,QAAQ,CAEzB,QAAO;EACL,GAAI;EACJ,SAAS,QAAQ,KAAK,QAAQ,CAAC,OAAO,QAAQ;EAC/C;AAGH,OAAM,IAAI,MAAM,yCAAuC;;AAGzD,SAAgB,iCACd,MAC6B;AAC7B,KAAI,YAAY,MAAM,QAAQ,CAC5B,QAAO,EACL,SAAS,KAAK,SACf;AAGH,OAAM,IAAI,MAAM,8CAA4C;;AAG9D,SAAgB,8BACd,MAC0B;AAC1B,KACE,YAAY,MAAM,KAAK,IACvB;EAAC;EAAO;EAAQ;EAAS,CAAC,SAAS,KAAK,MAAM,CAE9C,QAAO;EACL,MAAM,KAAK;EACX,OAAO,KAAK;EACb;AAGH,OAAM,IAAI,MAAM,2CAAyC;;AA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KAAK,QAAQ,MAAM,OAAO;AACxC,OAAK,QAAQ,KACX,0DACD;AAED,eAAa,YAAY;AAEzB,QAAM,QAAQ,IACZ,MAAKE,QAAS,WAAW,IAAI,OAAM,cACjC,MAAKF,OAAQ,KAAK;GAChB,SAAS,UAAU;GACnB,QAAQ;GACT,CAAC,CACH,CACF;AAED,OAAK,QAAQ,MACX,+DACD;AACD,SAAO;;;;;;;;;;CAWT,MAAa,OACX,eAGI,EACF,SAAS,UACV,EACD;EACA,MAAM,QAAQ,KAAK,QAAQ,MAAM,SAAS;AAC1C,OAAK,QAAQ,KAAK,uCAAuC;AAEzD,eAAa,YAAY;AAEzB,QAAM,QAAQ,IACZ,MAAKE,QAAS,WAAW,IAAI,OAAM,cACjC,MAAKF,OAAQ,OAAO;GAClB,SAAS,UAAU;GACnB,QAAQ;GACT,CAAC,CACH,CACF;AAED,OAAK,QAAQ,MAAM,6CAA6C;AAChE,SAAO;;;;;;;;;;CAWT,MAAa,WAAW;EACtB,MAAM,QAAQ,KAAK,QAAQ,MAAM,eAAe;AAChD,OAAK,QAAQ,KAAK,gDAAgD;AAElE,QAAKA,OAAQ,OAAO;AAEpB,OAAK,QAAQ,MAAM,mDAAmD;AACtE,SAAO;;CAGT,OAAO,OAAO,gBAAgB;AAC5B,SAAO,KAAK,UAAU"}
1
+ {"version":3,"file":"index.mjs","names":["Worker","#worker","JestWorker","#worker","Worker","#context"],"sources":["../src/_internal/ipc/parse.ts","../src/_internal/helpers/worker.ts","../src/index.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 { LogMeta } from \"@powerlines/core\";\nimport { toArray } from \"@stryke/convert/to-array\";\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 { Serializable } from \"node:worker_threads\";\nimport {\n IpcMessage,\n UpdateCommandMessagePayload,\n UpdateHookMessagePayload,\n UpdatePluginMessagePayload,\n WriteLogMessagePayload\n} from \"./messages\";\n\nexport function parseIpcMessage(data: Serializable): IpcMessage | undefined {\n let message: Record<string, any> | undefined;\n if (isSetObject(data)) {\n message = data;\n } else if (isString(data)) {\n try {\n const parsed = JSON.parse(data);\n if (isSetObject(parsed)) {\n message = parsed;\n }\n } catch {\n // Do nothing\n }\n }\n\n if (\n message &&\n isSetString(message.id) &&\n isSetString(message.type) &&\n isSetString(message.executionId) &&\n Number.isInteger(message.executionIndex) &&\n !Number.isNaN(message.timestamp)\n ) {\n return message as IpcMessage;\n }\n\n return undefined;\n}\n\nexport function parseWriteLogMessagePayload(\n data?: Record<string, any>\n): WriteLogMessagePayload {\n if (\n isSetObject(data) &&\n isSetObject(data.meta) &&\n isSetString((data.meta as LogMeta).type) &&\n (isSetString(data.message) || Array.isArray(data.message))\n ) {\n return {\n ...data,\n meta: data.meta as Omit<\n LogMeta,\n \"executionId\" | \"executionIndex\" | \"environment\" | \"timestamp\"\n >,\n message: toArray(data.message).filter(Boolean)\n };\n }\n\n throw new Error(\n `Invalid \"write-log\" message payload: ${JSON.stringify(data)}`\n );\n}\n\nexport function parseUpdateCommandMessagePayload(\n data?: Record<string, any>\n): UpdateCommandMessagePayload {\n if (isSetString(data?.command)) {\n return {\n command: data.command\n };\n }\n\n throw new Error(\n `Invalid \"update-command\" message payload: ${JSON.stringify(data)}`\n );\n}\n\nexport function parseUpdateHookMessagePayload(\n data?: Record<string, any>\n): UpdateHookMessagePayload {\n if (\n isSetString(data?.hook) &&\n [\"pre\", \"post\", \"normal\"].includes(data.order)\n ) {\n return {\n hook: data.hook,\n order: data.order\n };\n }\n\n throw new Error(\n `Invalid \"update-hook\" message payload: ${JSON.stringify(data)}`\n );\n}\n\nexport function parseUpdatePluginMessagePayload(\n data?: Record<string, any>\n): UpdatePluginMessagePayload {\n if (isSetString(data?.plugin)) {\n return {\n plugin: data.plugin\n };\n }\n\n throw new Error(\n `Invalid \"update-plugin\" message payload: ${JSON.stringify(data)}`\n );\n}\n","/* -------------------------------------------------------------------\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 { Logger } from \"@powerlines/core\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport { formatDuration } from \"date-fns/formatDuration\";\nimport { Worker as JestWorker } from \"jest-worker\";\nimport type { ChildProcess } from \"node:child_process\";\nimport { cpus } from \"node:os\";\nimport { Transform } from \"node:stream\";\nimport { parseArgs } from \"node:util\";\nimport { IpcMessage, IpcMessageType } from \"../ipc/messages\";\nimport { parseIpcMessage } from \"../ipc/parse\";\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\n/**\n * Node.js CLI flags that are not allowed in NODE_OPTIONS and must be\n * passed as direct CLI arguments via execArgv.\n * This set is the difference between all Node.js CLI flags and the ones **not**\n * allowed in NODE_OPTIONS, as listed in the Node.js documentation:\n * https://nodejs.org/api/cli.html#node_optionsoptions\n *\n * It is not exhaustive since not all options make sense for Powerlines (e.g. --test)\n */\nconst EXEC_ARGV_ONLY_OPTIONS = new Set([\n \"experimental-network-inspection\",\n \"experimental-storage-inspection\",\n \"experimental-worker-inspection\",\n \"experimental-inspector-network-resource\"\n]);\n\nfunction formatArg(\n key: string,\n value: string | boolean | undefined\n): string | null {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${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 return null;\n}\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nconst tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[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 (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++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 return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`. Options that are not allowed in\n * NODE_OPTIONS are returned separately as execArgv.\n *\n * @param args - The arguments to be stringified.\n * @returns An object with `nodeOptions` string and `execArgv` array.\n */\nfunction formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): { nodeOptions: string; execArgv: string[] } {\n const nodeOptionsParts: string[] = [];\n const execArgv: string[] = [];\n\n for (const [key, value] of Object.entries(args)) {\n const formatted = formatArg(key, value);\n if (formatted === null) continue;\n\n if (EXEC_ARGV_ONLY_OPTIONS.has(key)) {\n execArgv.push(formatted);\n } else {\n nodeOptionsParts.push(formatted);\n }\n }\n\n return { nodeOptions: nodeOptionsParts.join(\" \"), execArgv };\n}\n\nexport type NodeOptions = Record<string, string | boolean | undefined>;\n\nconst parseNodeArgs = (args: string[]): NodeOptions => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\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 values && isString(values[orphan.name])) {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\nfunction getParsedNodeOptions(): Record<string, string | boolean | undefined> {\n const args = [...process.execArgv, ...getNodeOptionsArgs()];\n if (args.length === 0) return {};\n\n return parseNodeArgs(args);\n}\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 type WorkerOptions = ConstructorParameters<typeof JestWorker>[1] & {\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 * True if `--max-old-space-size` should not be forwarded to the worker.\n */\n isolatedMemory?: boolean;\n\n /**\n * The maximum time in milliseconds a worker can run before being terminated. Defaults to `0` (no timeout).\n */\n timeout?: number;\n\n /**\n * A callback function that is called when the worker is active.\n */\n onActivity?: () => void;\n\n /**\n * A callback function that is called when the worker activity is aborted.\n */\n onActivityAbort?: () => void;\n\n /**\n * A callback function that is called when the worker is restarted.\n */\n onRestart?: (method: string, args: any[], attempts: number) => void;\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 exposedMethods: ReadonlyArray<string>;\n\n /**\n * Whether to use worker threads instead of child processes for the worker implementation. This is an experimental feature and may not be suitable for all use cases. Defaults to `false`.\n */\n enableWorkerThreads?: boolean;\n\n /**\n * A custom log function that can be used to log messages from the worker. This can be useful for debugging and monitoring the worker's activity. The function should accept a string message as its argument.\n */\n logger: Logger;\n\n /**\n * A callback function that is called when the worker sends a log message. This can be used to handle log messages from the worker and integrate them with the parent process's logging system. The function should accept a `WriteLogIpcMessage` object as its argument, which contains the log message and associated metadata.\n */\n onIpcMessage?: (message: IpcMessage) => MaybePromise<void>;\n};\n\nexport class Worker {\n #worker: JestWorker | undefined;\n\n /**\n * Create a new worker instance.\n *\n * @param workerPath - The path to the worker file.\n * @param options - The options for the worker, including exposed methods, timeout, and hooks for activity and restart.\n */\n public constructor(\n protected workerPath: string,\n protected options: WorkerOptions\n ) {\n const {\n timeout,\n onRestart,\n debuggerPortOffset = -1,\n enableSourceMaps = false,\n isolatedMemory = false,\n logger,\n ...rest\n } = this.options;\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 const nodeOptions = getParsedNodeOptions();\n const originalOptions = { ...nodeOptions };\n delete nodeOptions.inspect;\n delete nodeOptions[\"inspect-brk\"];\n delete nodeOptions.inspect_brk;\n if (debuggerPortOffset !== -1) {\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:\n debuggerAddress.port === 0\n ? 0\n : debuggerAddress.port + 1 + debuggerPortOffset\n };\n nodeOptions[nodeDebugType] = formatDebugAddress(address);\n }\n }\n\n if (enableSourceMaps) {\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 { nodeOptions: formattedNodeOptions, execArgv } =\n formatNodeOptions(nodeOptions);\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 static 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 if (this.options.onActivity) {\n this.options.onActivity();\n }\n\n hangingTimer = activeTasks > 0 && setTimeout(onHanging, timeout);\n };\n\n const createWorker = () => {\n const workerEnv: NodeJS.ProcessEnv = {\n ...process.env,\n ...((rest.forkOptions?.env ?? {}) as any),\n POWERLINES_WORKER: \"true\",\n NODE_OPTIONS: formattedNodeOptions\n };\n\n if (workerEnv.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 !workerEnv.NO_COLOR &&\n !workerEnv.CI &&\n workerEnv.TERM !== \"dumb\" &&\n (process.stdout.isTTY || process.stderr?.isTTY);\n\n if (supportsColors) {\n workerEnv.FORCE_COLOR = \"1\";\n }\n }\n\n this.#worker = new JestWorker(workerPath, {\n maxRetries: 0,\n numWorkers: cpus().length ?? 3,\n ...rest,\n forkOptions: {\n ...rest.forkOptions,\n execArgv: [...execArgv, ...(rest.forkOptions?.execArgv ?? [])],\n env: workerEnv\n }\n });\n restartPromise = new Promise(resolve => {\n resolveRestartPromise = resolve;\n });\n\n /**\n * Jest Worker has two worker types, ChildProcessWorker (uses child_process) and NodeThreadWorker (uses worker_threads)\n * Powerlines uses ChildProcessWorker by default, but it can be switched to NodeThreadWorker with an experimental flag\n *\n * We only want to handle ChildProcessWorker's orphan process issue, so we access the private property \"_child\":\n * https://github.com/facebook/jest/blob/b38d7d345a81d97d1dc3b68b8458b1837fbf19be/packages/jest-worker/src/workers/ChildProcessWorker.ts\n *\n * But this property is not available in NodeThreadWorker, so we need to check if we are using ChildProcessWorker\n */\n if (!rest.enableWorkerThreads) {\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 if ((code || (signal && signal !== \"SIGINT\")) && this.#worker) {\n logger.error(\n `Worker exited with code: ${code} and signal: ${signal}`\n );\n\n // if a child process doesn't exit gracefully, we want to bubble up the exit code to the parent process\n process.exit(code ?? 1);\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 if (\n isSetObject(data) &&\n (data as IpcMessage).type === IpcMessageType.ACTIVITY\n ) {\n onActivity();\n } else {\n const message = parseIpcMessage(data);\n if (message) {\n logger.trace(\n `Received IPC message from worker: ${JSON.stringify(message)}`\n );\n\n void Promise.resolve(this.options.onIpcMessage?.(message));\n }\n }\n });\n }\n }\n\n let aborted = false;\n const onActivityAbort = () => {\n if (!aborted) {\n this.options.onActivityAbort?.();\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 rest.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 if (onRestart) {\n onRestart(method, args, ++attempts);\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 public async end(): ReturnType<JestWorker[\"end\"]> {\n const worker = this.#worker;\n if (!worker) {\n throw new Error(\"Farm is ended, no more calls can be done to it\");\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","/* -------------------------------------------------------------------\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 type {\n BuildInlineConfig,\n CleanInlineConfig,\n DeployInlineConfig,\n DocsInlineConfig,\n Engine,\n EngineContext,\n EngineOptions,\n ExecutionWorkerProcess,\n LintInlineConfig,\n NewInlineConfig,\n PrepareInlineConfig,\n TestInlineConfig,\n TypesInlineConfig\n} from \"@powerlines/core\";\nimport { POWERLINES_API_FUNCTIONS } from \"@powerlines/core/constants\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { PartialKeys } from \"@stryke/types/base\";\nimport { Worker } from \"./_internal/helpers/worker\";\nimport {\n IpcMessage,\n IpcMessageType,\n UpdateCommandIpcMessage,\n UpdateHookIpcMessage,\n UpdatePluginIpcMessage,\n WriteLogIpcMessage\n} from \"./_internal/ipc/messages\";\nimport {\n parseUpdateCommandMessagePayload,\n parseUpdateHookMessagePayload,\n parseUpdatePluginMessagePayload,\n parseWriteLogMessagePayload\n} from \"./_internal/ipc/parse\";\nimport { PowerlinesEngineContext } from \"./context/engine-context\";\n\n/**\n * The Powerlines Engine class\n *\n * @remarks\n * This class is responsible for managing the Powerlines project lifecycle, including initialization, building, and finalization.\n *\n * @public\n */\nexport class PowerlinesEngine implements Engine, AsyncDisposable {\n /**\n * The Powerlines context\n */\n #context: EngineContext;\n\n /**\n * The worker pool for managing child threads\n */\n #worker!: ExecutionWorkerProcess;\n\n /**\n * Create a new Powerlines Engine instance\n *\n * @param options - The options to initialize the context with\n * @returns A new instance of the Powerlines Engine\n */\n public static async fromOptions(\n options: EngineOptions\n ): Promise<PowerlinesEngine> {\n const api = new PowerlinesEngine(\n await PowerlinesEngineContext.fromOptions(options)\n );\n\n const packagePath = await resolvePackage(\"@powerlines/engine\");\n if (!packagePath) {\n throw new Error(\n \"Could not resolve `@powerlines/engine` package location.\"\n );\n }\n\n api.#worker = new Worker(joinPaths(packagePath, \"./_internal/worker.mjs\"), {\n onIpcMessage: api.handleIpcMessage.bind(api),\n enableSourceMaps: options.mode === \"development\",\n exposedMethods: POWERLINES_API_FUNCTIONS,\n logger: api.context.extendLogger({ category: \"ipc\" })\n }) as unknown as ExecutionWorkerProcess;\n\n return api;\n }\n\n /**\n * The Powerlines context\n */\n public get context(): EngineContext {\n return this.#context;\n }\n\n /**\n * Create a new Powerlines Engine instance\n *\n * @param context - The Powerlines context\n */\n protected constructor(context: EngineContext) {\n this.#context = context;\n }\n\n /**\n * Generate the Powerlines typescript declaration file\n *\n * @remarks\n * 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.\n *\n * @param inlineConfig - The inline configuration for the types command\n */\n public async types(\n inlineConfig: PartialKeys<\n Omit<TypesInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"types\"\n }\n ) {\n const timer = this.context.timer(\"Types\");\n this.context.info(\n \" 🏗️ Generating typescript declarations for the Powerlines project\"\n );\n\n this.context.debug(\n \" Aggregating configuration options for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"types\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.types({\n options: execution.options,\n config: inlineConfig as TypesInlineConfig\n })\n )\n );\n\n this.context.debug(\n \"✔ Powerlines types generation has completed successfully\"\n );\n timer();\n }\n\n /**\n * Prepare the Powerlines API\n *\n * @remarks\n * This method will prepare the Powerlines API for use, initializing any necessary resources.\n *\n * @param inlineConfig - The inline configuration for the prepare command\n */\n public async prepare(\n inlineConfig:\n | PartialKeys<Omit<PrepareInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<TypesInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<NewInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<CleanInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<LintInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<DocsInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<DeployInlineConfig, \"configFile\">, \"command\"> = {\n command: \"prepare\"\n }\n ) {\n const timer = this.context.timer(\"Prepare\");\n this.context.info(\" 🏗️ Preparing the Powerlines project\");\n\n this.context.debug(\n \"Aggregating configuration options for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"prepare\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.prepare({\n options: execution.options,\n config: inlineConfig as PrepareInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines preparation has completed successfully\");\n timer();\n }\n\n /**\n * Create a new Powerlines project\n *\n * @remarks\n * This method will create a new Powerlines project in the current directory.\n *\n * @param inlineConfig - The inline configuration for the new command\n * @returns A promise that resolves when the project has been created\n */\n public async new(inlineConfig: PartialKeys<NewInlineConfig, \"command\">) {\n const timer = this.context.timer(\"New\");\n this.context.info(\" 🆕 Creating a new Powerlines project\");\n\n inlineConfig.command ??= \"new\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.new({\n options: execution.options,\n config: inlineConfig as NewInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines new command completed successfully\");\n timer();\n }\n\n /**\n * Clean any previously prepared artifacts\n *\n * @remarks\n * This method will remove the previous Powerlines artifacts from the project.\n *\n * @param inlineConfig - The inline configuration for the clean command\n * @returns A promise that resolves when the clean command has completed\n */\n public async clean(\n inlineConfig:\n | PartialKeys<Omit<CleanInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<PrepareInlineConfig, \"configFile\">, \"command\"> = {\n command: \"clean\"\n }\n ) {\n const timer = this.context.timer(\"Clean\");\n this.context.info(\" 🧹 Cleaning the previous Powerlines artifacts\");\n\n inlineConfig.command ??= \"clean\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.clean({\n options: execution.options,\n config: inlineConfig as CleanInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines cleaning completed successfully\");\n timer();\n }\n\n /**\n * Lint the project\n *\n * @param inlineConfig - The inline configuration for the lint command\n * @returns A promise that resolves when the lint command has completed\n */\n public async lint(\n inlineConfig:\n | PartialKeys<Omit<LintInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\"> = {\n command: \"lint\"\n }\n ) {\n const timer = this.context.timer(\"Lint\");\n this.context.info(\" 📝 Linting the Powerlines project\");\n\n inlineConfig.command ??= \"lint\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.lint({\n options: execution.options,\n config: inlineConfig as LintInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines linting completed successfully\");\n timer();\n }\n\n /**\n * Test the project\n *\n * @remarks\n * This method will run the tests for the Powerlines project.\n *\n * @param inlineConfig - The inline configuration for the test command\n * @returns A promise that resolves when the test command has completed\n */\n public async test(\n inlineConfig:\n | PartialKeys<Omit<TestInlineConfig, \"configFile\">, \"command\">\n | PartialKeys<Omit<BuildInlineConfig, \"configFile\">, \"command\"> = {\n command: \"test\"\n }\n ) {\n const timer = this.context.timer(\"Test\");\n this.context.info(\" 🧪 Running tests for the Powerlines project\");\n\n inlineConfig.command ??= \"test\";\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.test({\n options: execution.options,\n config: inlineConfig as TestInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines testing completed successfully\");\n timer();\n }\n\n /**\n * Build the project\n *\n * @remarks\n * This method will build the Powerlines project, generating the necessary artifacts.\n *\n * @param inlineConfig - The inline configuration for the build command\n * @returns A promise that resolves when the build command has completed\n */\n public async build(\n inlineConfig: PartialKeys<\n Omit<BuildInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"build\"\n }\n ) {\n const timer = this.context.timer(\"Build\");\n this.context.info(\" 📦 Building the Powerlines project\");\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.build({\n options: execution.options,\n config: inlineConfig as BuildInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines build completed successfully\");\n timer();\n }\n\n /**\n * Prepare the documentation for the project\n *\n * @param inlineConfig - The inline configuration for the docs command\n * @returns A promise that resolves when the documentation generation has completed\n */\n public async docs(\n inlineConfig: PartialKeys<\n Omit<DocsInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"docs\"\n }\n ) {\n const timer = this.context.timer(\"Docs\");\n this.context.info(\n \" 📓 Generating documentation for the Powerlines project\"\n );\n\n inlineConfig.command ??= \"docs\";\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.docs({\n options: execution.options,\n config: inlineConfig as DocsInlineConfig\n })\n )\n );\n\n this.context.debug(\n \"✔ Powerlines documentation generation completed successfully\"\n );\n timer();\n }\n\n /**\n * Deploy the project source code\n *\n * @remarks\n * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.\n *\n * @param inlineConfig - The inline configuration for the deploy command\n */\n public async deploy(\n inlineConfig: PartialKeys<\n Omit<DeployInlineConfig, \"configFile\">,\n \"command\"\n > = {\n command: \"deploy\"\n }\n ) {\n const timer = this.context.timer(\"Deploy\");\n this.context.info(\" 🚀 Deploying the Powerlines project\");\n\n inlineConfig.command ??= \"deploy\";\n\n await Promise.all(\n this.#context.executions.map(async execution =>\n this.#worker.deploy({\n options: execution.options,\n config: inlineConfig as DeployInlineConfig\n })\n )\n );\n\n this.context.debug(\"✔ Powerlines deploy completed successfully\");\n timer();\n }\n\n /**\n * Finalization/cleanup processing for the Powerlines API\n *\n * @remarks\n * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.\n *\n * @returns A promise that resolves when the finalization process has completed\n */\n public async finalize() {\n const timer = this.context.timer(\"Finalization\");\n this.context.info(\" 🏁 Powerlines finalization processes started\");\n\n this.#worker.close();\n\n this.context.debug(\"✔ Powerlines finalization completed successfully\");\n timer();\n }\n\n /**\n * Asynchronous disposal method for the Powerlines Engine, which will call the finalize method to perform any necessary cleanup when the engine is disposed of.\n */\n public async [Symbol.asyncDispose]() {\n return this.finalize();\n }\n\n private async handleIpcMessage(message: IpcMessage) {\n switch (message.type) {\n case IpcMessageType.WRITE_LOG:\n this.context.logger.debug({\n meta: {\n category: \"ipc\",\n executionId: message.executionId,\n executionIndex: message.executionIndex,\n environment: message.environment\n },\n message: 'Received a \"write-log\" IPC message from worker'\n });\n\n await this.handleWriteLog({\n ...message,\n type: IpcMessageType.WRITE_LOG,\n payload: parseWriteLogMessagePayload(message.payload)\n });\n\n break;\n\n case IpcMessageType.UPDATE_COMMAND:\n this.context.logger.debug({\n meta: {\n category: \"ipc\",\n executionId: message.executionId,\n executionIndex: message.executionIndex,\n environment: message.environment\n },\n message: 'Received an \"update-command\" IPC message from worker'\n });\n\n await this.handleUpdateCommand({\n ...message,\n type: IpcMessageType.UPDATE_COMMAND,\n payload: parseUpdateCommandMessagePayload(message.payload)\n });\n\n break;\n\n case IpcMessageType.UPDATE_HOOK:\n this.context.logger.debug({\n meta: {\n category: \"ipc\",\n executionId: message.executionId,\n executionIndex: message.executionIndex,\n environment: message.environment\n },\n message: 'Received an \"update-hook\" IPC message from worker'\n });\n\n await this.handleUpdateHook({\n ...message,\n type: IpcMessageType.UPDATE_HOOK,\n payload: parseUpdateHookMessagePayload(message.payload)\n });\n\n break;\n\n case IpcMessageType.UPDATE_PLUGIN:\n this.context.logger.debug({\n meta: {\n category: \"ipc\",\n executionId: message.executionId,\n executionIndex: message.executionIndex,\n environment: message.environment\n },\n message: 'Received an \"update-plugin\" IPC message from worker'\n });\n\n await this.handleUpdatePlugin({\n ...message,\n type: IpcMessageType.UPDATE_PLUGIN,\n payload: parseUpdatePluginMessagePayload(message.payload)\n });\n\n break;\n\n case IpcMessageType.ACTIVITY:\n case undefined:\n default: {\n break;\n }\n }\n }\n\n private async handleWriteLog(message: WriteLogIpcMessage) {\n const { payload } = message;\n\n this.context.logger.log(payload.meta.type, {\n message: toArray(payload.message).filter(Boolean).join(\"\\n\"),\n meta: {\n category: payload.meta.category,\n logId: payload.meta.logId,\n name: payload.meta.name,\n executionId: message.executionId,\n executionIndex: message.executionIndex,\n command: payload.meta.command,\n hook: payload.meta.hook,\n environment: message.environment,\n plugin: payload.meta.plugin,\n source: payload.meta.source,\n timestamp: message.timestamp\n }\n });\n }\n\n private async handleUpdatePlugin(_: UpdatePluginIpcMessage) {}\n\n private async handleUpdateHook(_: UpdateHookIpcMessage) {}\n\n private async handleUpdateCommand(_: UpdateCommandIpcMessage) {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAgB,gBAAgB,MAA4C;CAC1E,IAAI;AACJ,KAAI,YAAY,KAAK,CACnB,WAAU;UACD,SAAS,KAAK,CACvB,KAAI;EACF,MAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,MAAI,YAAY,OAAO,CACrB,WAAU;SAEN;AAKV,KACE,WACA,YAAY,QAAQ,GAAG,IACvB,YAAY,QAAQ,KAAK,IACzB,YAAY,QAAQ,YAAY,IAChC,OAAO,UAAU,QAAQ,eAAe,IACxC,CAAC,OAAO,MAAM,QAAQ,UAAU,CAEhC,QAAO;;AAMX,SAAgB,4BACd,MACwB;AACxB,KACE,YAAY,KAAK,IACjB,YAAY,KAAK,KAAK,IACtB,YAAa,KAAK,KAAiB,KAAK,KACvC,YAAY,KAAK,QAAQ,IAAI,MAAM,QAAQ,KAAK,QAAQ,EAEzD,QAAO;EACL,GAAG;EACH,MAAM,KAAK;EAIX,SAAS,QAAQ,KAAK,QAAQ,CAAC,OAAO,QAAQ;EAC/C;AAGH,OAAM,IAAI,MACR,wCAAwC,KAAK,UAAU,KAAK,GAC7D;;AAGH,SAAgB,iCACd,MAC6B;AAC7B,KAAI,YAAY,MAAM,QAAQ,CAC5B,QAAO,EACL,SAAS,KAAK,SACf;AAGH,O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U;MACV,aAAa,QAAQ;MACrB,gBAAgB,QAAQ;MACxB,aAAa,QAAQ;MACtB;KACD,SAAS;KACV,CAAC;AAEF,UAAM,KAAK,iBAAiB;KAC1B,GAAG;KACH;KACA,SAAS,8BAA8B,QAAQ,QAAQ;KACxD,CAAC;AAEF;GAEF;AACE,SAAK,QAAQ,OAAO,MAAM;KACxB,MAAM;MACJ,UAAU;MACV,aAAa,QAAQ;MACrB,gBAAgB,QAAQ;MACxB,aAAa,QAAQ;MACtB;KACD,SAAS;KACV,CAAC;AAEF,UAAM,KAAK,mBAAmB;KAC5B,GAAG;KACH;KACA,SAAS,gCAAgC,QAAQ,QAAQ;KAC1D,CAAC;AAEF;GAEF;GACA,KAAK;GACL,QACE;;;CAKN,MAAc,eAAe,SAA6B;EACxD,MAAM,EAAE,YAAY;AAEpB,OAAK,QAAQ,OAAO,IAAI,QAAQ,KAAK,MAAM;GACzC,SAAS,QAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK;GAC5D,MAAM;IACJ,UAAU,QAAQ,KAAK;IACvB,OAAO,QAAQ,KAAK;IACpB,MAAM,QAAQ,KAAK;IACnB,aAAa,QAAQ;IACrB,gBAAgB,QAAQ;IACxB,SAAS,QAAQ,KAAK;IACtB,MAAM,QAAQ,KAAK;IACnB,aAAa,QAAQ;IACrB,QAAQ,QAAQ,KAAK;IACrB,QAAQ,QAAQ,KAAK;IACrB,WAAW,QAAQ;IACpB;GACF,CAAC;;CAGJ,MAAc,mBAAmB,GAA2B;CAE5D,MAAc,iBAAiB,GAAyB;CAExD,MAAc,oBAAoB,GAA4B"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_virtual = require('../virtual-1hYa9zCy.cjs');
2
+ const require_virtual = require('../virtual-Ct3ZqPeN.cjs');
3
3
 
4
4
  exports.BaseStorageAdapter = require_virtual.BaseStorageAdapter;
5
5
  exports.FileSystemStorageAdapter = require_virtual.FileSystemStorageAdapter;
@@ -1,3 +1,3 @@
1
- import { a as isFileError, i as ignoreNotfound, n as FileSystemStorageAdapter, o as BaseStorageAdapter, r as ignoreExists, t as VirtualStorageAdapter } from "../virtual-CUgOdyIa.mjs";
1
+ import { a as isFileError, i as ignoreNotfound, n as FileSystemStorageAdapter, o as BaseStorageAdapter, r as ignoreExists, t as VirtualStorageAdapter } from "../virtual-CYGZHTDd.mjs";
2
2
 
3
3
  export { BaseStorageAdapter, FileSystemStorageAdapter, VirtualStorageAdapter, ignoreExists, ignoreNotfound, isFileError };
@@ -1,7 +1,7 @@
1
+ import { appendPath } from "@stryke/path/append";
1
2
  import defu from "defu";
2
3
  import { joinPaths } from "@stryke/path/join-paths";
3
4
  import { existsSync } from "@stryke/fs/exists";
4
- import { appendPath } from "@stryke/path/append";
5
5
  import { readJsonFileSync } from "@stryke/fs/json";
6
6
  import ts from "typescript";
7
7
 
@@ -152,4 +152,4 @@ ${parsedCommandLine.errors.map((error) => `- ${(error.category !== void 0 && err
152
152
 
153
153
  //#endregion
154
154
  export { isIncludeMatchFound as a, getTsconfigFilePath as i, findMatch as n, isMatchFound as o, getParsedTypeScriptConfig as r, tryTsconfigFilePath as s, findIncludeMatch as t };
155
- //# sourceMappingURL=tsconfig-Cstsoprg.mjs.map
155
+ //# sourceMappingURL=tsconfig-CI6bla4E.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tsconfig-Cstsoprg.mjs","names":[],"sources":["../src/typescript/tsconfig.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 type { ParsedTypeScriptConfig, TSConfig } from \"@powerlines/core\";\nimport { existsSync } from \"@stryke/fs/exists\";\nimport { readJsonFileSync } from \"@stryke/fs/json\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { FilterPattern } from \"@stryke/types/file\";\nimport { TsConfigJson } from \"@stryke/types/tsconfig\";\nimport defu from \"defu\";\nimport ts from \"typescript\";\n\n/**\n * Get the path to the tsconfig.json file.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @returns The absolute path to the tsconfig.json file.\n * @throws If the tsconfig.json file does not exist.\n */\nexport function getTsconfigFilePath(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig?: string\n): string {\n let tsconfigFilePath: string | undefined;\n if (tsconfig) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n tsconfig\n );\n } else {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.app.json\"\n );\n if (!tsconfigFilePath) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.lib.json\"\n );\n if (!tsconfigFilePath) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.json\"\n );\n }\n }\n }\n\n if (!tsconfigFilePath) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file for the project at ${\n projectRoot\n }.`\n );\n }\n\n return tsconfigFilePath;\n}\n\n/**\n * Get the path to the tsconfig.json file.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @returns The absolute path to the tsconfig.json file.\n * @throws If the tsconfig.json file does not exist.\n */\nexport function tryTsconfigFilePath(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig: string\n): string | undefined {\n let tsconfigFilePath = tsconfig;\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = appendPath(tsconfig, projectRoot);\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = appendPath(\n tsconfig,\n appendPath(projectRoot, workspaceRoot)\n );\n if (!existsSync(tsconfigFilePath)) {\n return undefined;\n }\n }\n }\n\n return tsconfigFilePath;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[],\n extensions: string[] = [\".ts\", \".tsx\", \".d.ts\"]\n): string | RegExp | null | undefined {\n return types.find(\n type =>\n tsconfigType?.toString().toLowerCase() ===\n type?.toString().toLowerCase() ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}` ||\n `./${tsconfigType?.toString().toLowerCase()}` ===\n type?.toString().toLowerCase() ||\n extensions.some(\n ext =>\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n type?.toString().toLowerCase() ||\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n `./${type?.toString().toLowerCase()}` ||\n `${type?.toString().toLowerCase()}${ext}` ===\n `./${tsconfigType?.toString().toLowerCase()}` ||\n tsconfigType?.toString().toLowerCase() ===\n `${type?.toString().toLowerCase()}${ext}` ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}${ext}` ||\n type?.toString().toLowerCase() ===\n `./${tsconfigType?.toString().toLowerCase()}${ext}`\n )\n );\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findIncludeMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): string | RegExp | null | undefined {\n return findMatch(tsconfigType, types, [\n \".ts\",\n \".tsx\",\n \".d.ts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n \".mts\",\n \".cts\",\n \"/*.ts\",\n \"/*.tsx\",\n \"/*.d.ts\",\n \"/*.js\",\n \"/*.jsx\",\n \"/*.mjs\",\n \"/*.cjs\",\n \"/*.mts\",\n \"/*.cts\",\n \"/**/*.ts\",\n \"/**/*.tsx\",\n \"/**/*.d.ts\",\n \"/**/*.js\",\n \"/**/*.jsx\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.mts\",\n \"/**/*.cts\"\n ]);\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isMatchFound(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): boolean {\n return findMatch(tsconfigType, types) !== undefined;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isIncludeMatchFound(\n tsconfigType: FilterPattern,\n types: FilterPattern[]\n): boolean {\n return (\n findIncludeMatch(\n tsconfigType as string | RegExp | null,\n types as (string | RegExp | null)[]\n ) !== undefined\n );\n}\n\n/**\n * Get the parsed TypeScript configuration.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @param tsconfigRaw - The raw tsconfig.json content.\n * @param originalTsconfigJson - The original tsconfig.json content.\n * @param host - The TypeScript parse config host.\n * @returns The resolved TypeScript configuration.\n */\nexport function getParsedTypeScriptConfig(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig?: string,\n tsconfigRaw: TSConfig = {},\n originalTsconfigJson?: TSConfig,\n host: ts.ParseConfigHost = ts.sys\n): ParsedTypeScriptConfig {\n const tsconfigFilePath = getTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n tsconfig\n );\n const tsconfigJson = readJsonFileSync<TSConfig>(tsconfigFilePath);\n if (!tsconfigJson) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file at ${joinPaths(\n projectRoot,\n tsconfig ?? \"tsconfig.json\"\n )}`\n );\n }\n\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n defu(tsconfigRaw ?? {}, tsconfigJson),\n host,\n appendPath(projectRoot, workspaceRoot)\n );\n if (parsedCommandLine.errors.length > 0) {\n const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:\n${parsedCommandLine.errors\n .map(\n error =>\n `- ${\n (error.category !== undefined && error.code\n ? `[${error.category}-${error.code}]: `\n : \"\") + error.messageText.toString()\n }`\n )\n .join(\"\\n\")}\n `;\n\n throw new Error(errorMessage);\n }\n\n return {\n ...parsedCommandLine,\n originalTsconfigJson: (originalTsconfigJson ??\n tsconfigJson) as TsConfigJson,\n tsconfigJson,\n tsconfigFilePath\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,SAAgB,oBACd,eACA,aACA,UACQ;CACR,IAAI;AACJ,KAAI,SACF,oBAAmB,oBACjB,eACA,aACA,SACD;MACI;AACL,qBAAmB,oBACjB,eACA,aACA,oBACD;AACD,MAAI,CAAC,kBAAkB;AACrB,sBAAmB,oBACjB,eACA,aACA,oBACD;AACD,OAAI,CAAC,iBACH,oBAAmB,oBACjB,eACA,aACA,gBACD;;;AAKP,KAAI,CAAC,iBACH,OAAM,IAAI,MACR,2EACE,YACD,GACF;AAGH,QAAO;;;;;;;;;;;AAYT,SAAgB,oBACd,eACA,aACA,UACoB;CACpB,IAAI,mBAAmB;AACvB,KAAI,CAAC,WAAW,iBAAiB,EAAE;AACjC,qBAAmB,WAAW,UAAU,YAAY;AACpD,MAAI,CAAC,WAAW,iBAAi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K;;;;;;;;;;;;;AAeV,SAAgB,0BACd,eACA,aACA,UACA,cAAwB,EAAE,EAC1B,sBACA,OAA2B,GAAG,KACN;CACxB,MAAM,mBAAmB,oBACvB,eACA,aACA,SACD;CACD,MAAM,eAAe,iBAA2B,iBAAiB;AACjE,KAAI,CAAC,aACH,OAAM,IAAI,MACR,2DAA2D,UACzD,aACA,YAAY,gBACb,GACF;CAGH,MAAM,oBAAoB,GAAG,2BAC3B,KAAK,eAAe,EAAE,EAAE,aAAa,EACrC,MACA,WAAW,aAAa,cAAc,CACvC;AACD,KAAI,kBAAkB,OAAO,SAAS,GAAG;EACvC,MAAM,eAAe;EACvB,kBAAkB,OACjB,KACC,UACE,MACG,MAAM,aAAa,UAAa,MAAM,OACnC,IAAI,MAAM,SAAS,GAAG,MAAM,KAAK,OACjC,MAAM,MAAM,YAAY,UAAU,GAE3C,CACA,KAAK,KAAK,CAAC;;AAGV,QAAM,IAAI,MAAM,aAAa;;AAG/B,QAAO;EACL,GAAG;EACH,sBAAuB,wBACrB;EACF;EACA;EACD"}
1
+ {"version":3,"file":"tsconfig-CI6bla4E.mjs","names":[],"sources":["../src/typescript/tsconfig.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 type { ParsedTypeScriptConfig, TSConfig } from \"@powerlines/core\";\nimport { existsSync } from \"@stryke/fs/exists\";\nimport { readJsonFileSync } from \"@stryke/fs/json\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { FilterPattern } from \"@stryke/types/file\";\nimport { TsConfigJson } from \"@stryke/types/tsconfig\";\nimport defu from \"defu\";\nimport ts from \"typescript\";\n\n/**\n * Get the path to the tsconfig.json file.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @returns The absolute path to the tsconfig.json file.\n * @throws If the tsconfig.json file does not exist.\n */\nexport function getTsconfigFilePath(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig?: string\n): string {\n let tsconfigFilePath: string | undefined;\n if (tsconfig) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n tsconfig\n );\n } else {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.app.json\"\n );\n if (!tsconfigFilePath) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.lib.json\"\n );\n if (!tsconfigFilePath) {\n tsconfigFilePath = tryTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n \"tsconfig.json\"\n );\n }\n }\n }\n\n if (!tsconfigFilePath) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file for the project at ${\n projectRoot\n }.`\n );\n }\n\n return tsconfigFilePath;\n}\n\n/**\n * Get the path to the tsconfig.json file.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @returns The absolute path to the tsconfig.json file.\n * @throws If the tsconfig.json file does not exist.\n */\nexport function tryTsconfigFilePath(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig: string\n): string | undefined {\n let tsconfigFilePath = tsconfig;\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = appendPath(tsconfig, projectRoot);\n if (!existsSync(tsconfigFilePath)) {\n tsconfigFilePath = appendPath(\n tsconfig,\n appendPath(projectRoot, workspaceRoot)\n );\n if (!existsSync(tsconfigFilePath)) {\n return undefined;\n }\n }\n }\n\n return tsconfigFilePath;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[],\n extensions: string[] = [\".ts\", \".tsx\", \".d.ts\"]\n): string | RegExp | null | undefined {\n return types.find(\n type =>\n tsconfigType?.toString().toLowerCase() ===\n type?.toString().toLowerCase() ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}` ||\n `./${tsconfigType?.toString().toLowerCase()}` ===\n type?.toString().toLowerCase() ||\n extensions.some(\n ext =>\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n type?.toString().toLowerCase() ||\n `${tsconfigType?.toString().toLowerCase()}${ext}` ===\n `./${type?.toString().toLowerCase()}` ||\n `${type?.toString().toLowerCase()}${ext}` ===\n `./${tsconfigType?.toString().toLowerCase()}` ||\n tsconfigType?.toString().toLowerCase() ===\n `${type?.toString().toLowerCase()}${ext}` ||\n tsconfigType?.toString().toLowerCase() ===\n `./${type?.toString().toLowerCase()}${ext}` ||\n type?.toString().toLowerCase() ===\n `./${tsconfigType?.toString().toLowerCase()}${ext}`\n )\n );\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function findIncludeMatch(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): string | RegExp | null | undefined {\n return findMatch(tsconfigType, types, [\n \".ts\",\n \".tsx\",\n \".d.ts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n \".mts\",\n \".cts\",\n \"/*.ts\",\n \"/*.tsx\",\n \"/*.d.ts\",\n \"/*.js\",\n \"/*.jsx\",\n \"/*.mjs\",\n \"/*.cjs\",\n \"/*.mts\",\n \"/*.cts\",\n \"/**/*.ts\",\n \"/**/*.tsx\",\n \"/**/*.d.ts\",\n \"/**/*.js\",\n \"/**/*.jsx\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.mts\",\n \"/**/*.cts\"\n ]);\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isMatchFound(\n tsconfigType: string | RegExp | null,\n types: (string | RegExp | null)[]\n): boolean {\n return findMatch(tsconfigType, types) !== undefined;\n}\n\n/**\n * Check if the TypeScript configuration type matches any of the provided types.\n *\n * @param tsconfigType - The type from the TypeScript configuration.\n * @param types - An array of type names to check against.\n * @returns True if the TypeScript configuration type matches any of the provided types, false otherwise.\n */\nexport function isIncludeMatchFound(\n tsconfigType: FilterPattern,\n types: FilterPattern[]\n): boolean {\n return (\n findIncludeMatch(\n tsconfigType as string | RegExp | null,\n types as (string | RegExp | null)[]\n ) !== undefined\n );\n}\n\n/**\n * Get the parsed TypeScript configuration.\n *\n * @param workspaceRoot - The root directory of the workspace.\n * @param projectRoot - The root directory of the project.\n * @param tsconfig - The path to the tsconfig.json file.\n * @param tsconfigRaw - The raw tsconfig.json content.\n * @param originalTsconfigJson - The original tsconfig.json content.\n * @param host - The TypeScript parse config host.\n * @returns The resolved TypeScript configuration.\n */\nexport function getParsedTypeScriptConfig(\n workspaceRoot: string,\n projectRoot: string,\n tsconfig?: string,\n tsconfigRaw: TSConfig = {},\n originalTsconfigJson?: TSConfig,\n host: ts.ParseConfigHost = ts.sys\n): ParsedTypeScriptConfig {\n const tsconfigFilePath = getTsconfigFilePath(\n workspaceRoot,\n projectRoot,\n tsconfig\n );\n const tsconfigJson = readJsonFileSync<TSConfig>(tsconfigFilePath);\n if (!tsconfigJson) {\n throw new Error(\n `Cannot find the \\`tsconfig.json\\` configuration file at ${joinPaths(\n projectRoot,\n tsconfig ?? \"tsconfig.json\"\n )}`\n );\n }\n\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n defu(tsconfigRaw ?? {}, tsconfigJson),\n host,\n appendPath(projectRoot, workspaceRoot)\n );\n if (parsedCommandLine.errors.length > 0) {\n const errorMessage = `Cannot parse the TypeScript compiler options. Please investigate the following issues:\n${parsedCommandLine.errors\n .map(\n error =>\n `- ${\n (error.category !== undefined && error.code\n ? `[${error.category}-${error.code}]: `\n : \"\") + error.messageText.toString()\n }`\n )\n .join(\"\\n\")}\n `;\n\n throw new Error(errorMessage);\n }\n\n return {\n ...parsedCommandLine,\n originalTsconfigJson: (originalTsconfigJson ??\n tsconfigJson) as TsConfigJson,\n tsconfigJson,\n tsconfigFilePath\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,SAAgB,oBACd,eACA,aACA,UACQ;CACR,IAAI;AACJ,KAAI,SACF,oBAAmB,oBACjB,eACA,aACA,SACD;MACI;AACL,qBAAmB,oBACjB,eACA,aACA,oBACD;AACD,MAAI,CAAC,kBAAkB;AACrB,sBAAmB,oBACjB,eACA,aACA,oBACD;AACD,OAAI,CAAC,iBACH,oBAAmB,oBACjB,eACA,aACA,gBACD;;;AAKP,KAAI,CAAC,iBACH,OAAM,IAAI,MACR,2EACE,YACD,GACF;AAGH,QAAO;;;;;;;;;;;AAYT,SAAgB,oBACd,eACA,aACA,UACoB;CACpB,IAAI,mBAAmB;AACvB,KAAI,CAAC,WAAW,iBAAiB,EAAE;AACjC,qBAAmB,WAAW,UAAU,YAAY;AACpD,MAAI,CAAC,WAAW,iBAAiB,EAAE;AACjC,sBAAmB,WACjB,UACA,WAAW,aAAa,cAAc,CACvC;AACD,OAAI,CAAC,WAAW,iBAAiB,CAC/B;;;AAKN,QAAO;;;;;;;;;AAUT,SAAgB,UACd,cACA,OACA,aAAuB;CAAC;CAAO;CAAQ;CAAQ,EACX;AACpC,QAAO,MAA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AI,MACR,2DAA2D,UACzD,aACA,YAAY,gBACb,GACF;CAGH,MAAM,oBAAoB,GAAG,2BAC3B,KAAK,eAAe,EAAE,EAAE,aAAa,EACrC,MACA,WAAW,aAAa,cAAc,CACvC;AACD,KAAI,kBAAkB,OAAO,SAAS,GAAG;EACvC,MAAM,eAAe;EACvB,kBAAkB,OACjB,KACC,UACE,MACG,MAAM,aAAa,UAAa,MAAM,OACnC,IAAI,MAAM,SAAS,GAAG,MAAM,KAAK,OACjC,MAAM,MAAM,YAAY,UAAU,GAE3C,CACA,KAAK,KAAK,CAAC;;AAGV,QAAM,IAAI,MAAM,aAAa;;AAG/B,QAAO;EACL,GAAG;EACH,sBAAuB,wBACrB;EACF;EACA;EACD"}
@@ -1,9 +1,9 @@
1
1
  const require_chunk = require('./chunk-C0xms8kb.cjs');
2
+ let _stryke_path_append = require("@stryke/path/append");
2
3
  let defu = require("defu");
3
4
  defu = require_chunk.__toESM(defu, 1);
4
5
  let _stryke_path_join_paths = require("@stryke/path/join-paths");
5
6
  let _stryke_fs_exists = require("@stryke/fs/exists");
6
- let _stryke_path_append = require("@stryke/path/append");
7
7
  let _stryke_fs_json = require("@stryke/fs/json");
8
8
  let typescript = require("typescript");
9
9
  typescript = require_chunk.__toESM(typescript, 1);
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_tsconfig = require('../tsconfig-DeyWQC2N.cjs');
2
+ const require_tsconfig = require('../tsconfig-QMSxSwBD.cjs');
3
3
  const require_ts_morph = require('../ts-morph-BaLPVAdB.cjs');
4
4
 
5
5
  exports.VirtualFileSystemHost = require_ts_morph.VirtualFileSystemHost;
@@ -1,4 +1,4 @@
1
- import { a as isIncludeMatchFound, i as getTsconfigFilePath, n as findMatch, o as isMatchFound, r as getParsedTypeScriptConfig, s as tryTsconfigFilePath, t as findIncludeMatch } from "../tsconfig-Cstsoprg.mjs";
1
+ import { a as isIncludeMatchFound, i as getTsconfigFilePath, n as findMatch, o as isMatchFound, r as getParsedTypeScriptConfig, s as tryTsconfigFilePath, t as findIncludeMatch } from "../tsconfig-CI6bla4E.mjs";
2
2
  import { n as createProgram, t as VirtualFileSystemHost } from "../ts-morph-D0CaA37w.mjs";
3
3
 
4
4
  export { VirtualFileSystemHost, createProgram, findIncludeMatch, findMatch, getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound, isMatchFound, tryTsconfigFilePath };
@@ -1,17 +1,17 @@
1
1
  import { joinPaths } from "@stryke/path/join";
2
2
  import { isSetString } from "@stryke/type-checks/is-set-string";
3
+ import { appendPath } from "@stryke/path/append";
4
+ import { unlinkSync } from "node:fs";
3
5
  import { getFileHeaderWarningText } from "@powerlines/core/lib/utilities/file-header";
4
- import { exists, existsSync } from "@stryke/fs/exists";
6
+ import { exists, existsSync as existsSync$1 } from "@stryke/fs/exists";
5
7
  import { createDirectory, createDirectorySync } from "@stryke/fs/helpers";
6
8
  import { listFiles, listFilesSync } from "@stryke/fs/list-files";
7
- import { appendPath } from "@stryke/path/append";
8
9
  import { isParentPath } from "@stryke/path/is-parent-path";
9
10
  import { isError } from "@stryke/type-checks/is-error";
10
11
  import { correctPath } from "@stryke/path/correct-path";
11
12
  import { isDirectory, isFile } from "@stryke/fs/is-file";
12
13
  import { readFile, readFileSync } from "@stryke/fs/read-file";
13
14
  import { writeFile, writeFileSync } from "@stryke/fs/write-file";
14
- import { unlinkSync } from "node:fs";
15
15
  import { unlink } from "node:fs/promises";
16
16
  import { resolve } from "node:path";
17
17
 
@@ -285,7 +285,7 @@ var FileSystemStorageAdapter = class extends BaseStorageAdapter {
285
285
  * @returns Returns `true` if the key exists, otherwise `false`.
286
286
  */
287
287
  existsSync(key) {
288
- return existsSync(this.resolve(key));
288
+ return existsSync$1(this.resolve(key));
289
289
  }
290
290
  /**
291
291
  * Asynchronously checks if a key exists in the storage.
@@ -510,4 +510,4 @@ var VirtualStorageAdapter = class extends BaseStorageAdapter {
510
510
 
511
511
  //#endregion
512
512
  export { isFileError as a, ignoreNotfound as i, FileSystemStorageAdapter as n, BaseStorageAdapter as o, ignoreExists as r, VirtualStorageAdapter as t };
513
- //# sourceMappingURL=virtual-CUgOdyIa.mjs.map
513
+ //# sourceMappingURL=virtual-CYGZHTDd.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-CYGZHTDd.mjs","names":["#isDisposed","existsSync"],"sources":["../src/storage/base.ts","../src/storage/helpers.ts","../src/storage/file-system.ts","../src/storage/virtual.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 type { Context, StorageAdapter, StoragePreset } from \"@powerlines/core\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { correctPath } from \"@stryke/path/correct-path\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport { resolve } from \"node:path\";\n\nexport interface StorageAdapterOptions {\n base: string;\n isReadOnly?: boolean;\n ignore?: string | string[];\n}\n\n/**\n * Abstract base class for storage adapters, providing a template for storage operations.\n */\nexport abstract class BaseStorageAdapter<\n TOptions extends StorageAdapterOptions = StorageAdapterOptions\n> implements StorageAdapter {\n /**\n * Indicates whether the storage adapter has been disposed.\n */\n #isDisposed = false;\n\n /**\n * A name identifying the storage adapter type.\n */\n public abstract name: string;\n\n /**\n * Configuration options for the storage adapter.\n */\n public options: TOptions;\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public readonly preset?: StoragePreset | null = null;\n\n /**\n * Constructor for the BaseStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(\n protected context: Context,\n options: TOptions = { base: \"/\" } as TOptions\n ) {\n this.options = options;\n this.options.base = resolve(options.base);\n this.options.isReadOnly = !!options.isReadOnly;\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public abstract existsSync(key: string): boolean;\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public async exists(key: string): Promise<boolean> {\n return this.existsSync(key);\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public abstract getSync(key: string): string | null;\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public async get(key: string): Promise<string | null> {\n return this.getSync(key);\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public abstract setSync(key: string, value: string): void;\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) {\n this.setSync(key, value);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param _ - The path of the directory to create.\n */\n public mkdirSync(_: string) {}\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public async mkdir(dirPath: string): Promise<void> {\n return Promise.resolve(this.mkdirSync(dirPath));\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public abstract removeSync(key: string): void;\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n this.removeSync(key);\n }\n }\n\n /**\n * Synchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n */\n public clearSync(base?: string) {\n if (!this.isReadOnly && this.overwrite) {\n const keys = this.listSync(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n keys.map(key =>\n this.removeSync(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n );\n }\n }\n\n /**\n * Asynchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n * @returns A promise that resolves when the operation is complete.\n */\n public async clear(base?: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n const keys = await this.list(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n await Promise.all(\n keys.map(async key =>\n this.remove(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n )\n );\n }\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public abstract listSync(base?: string): string[];\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public async list(base?: string): Promise<string[]> {\n return this.listSync(base);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param _ - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public isDirectorySync(_: string): boolean {\n return false;\n }\n\n /**\n * Checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a directory, otherwise `false`.\n */\n public async isDirectory(key: string) {\n return Promise.resolve(this.isDirectorySync(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public isFileSync(key: string): boolean {\n return this.existsSync(key) && !this.isDirectorySync(key);\n }\n\n /**\n * Checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a file, otherwise `false`.\n */\n public async isFile(key: string) {\n return Promise.resolve(this.isFileSync(key));\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n public dispose(): MaybePromise<void> {\n return Promise.resolve();\n }\n\n /**\n * Async dispose method to clean up resources.\n *\n * @returns A promise that resolves when disposal is complete.\n */\n public async [Symbol.asyncDispose]() {\n return this._dispose();\n }\n\n /**\n * Determines if the storage adapter is read-only based on the provided options.\n *\n * @returns `true` if the storage adapter is read-only, otherwise `false`.\n */\n protected get isReadOnly() {\n return !!this.options.isReadOnly;\n }\n\n /**\n * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.\n *\n * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.\n */\n protected get overwrite() {\n return !this.isReadOnly && this.context.config.output.overwrite !== false;\n }\n\n /**\n * Resolves a given key to its full path within the storage adapter.\n *\n * @param key - The key to resolve.\n * @returns The resolved full path for the key.\n */\n protected resolve(key?: string) {\n if (!key) {\n return this.options.base;\n }\n\n if (/\\.\\.:|\\.\\.$/.test(key)) {\n throw new Error(\n `[${this.name}]: Invalid key: ${JSON.stringify(key)} provided to storage adapter.`\n );\n }\n\n return appendPath(correctPath(key).replace(/:/g, \"/\"), this.options.base);\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n protected async _dispose(): Promise<void> {\n if (!this.#isDisposed) {\n await Promise.resolve(this.dispose());\n this.#isDisposed = true;\n }\n }\n}\n","/* -------------------------------------------------------------------\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 { isError } from \"@stryke/type-checks/is-error\";\n\n/**\n * Checks if an error is a file system error.\n *\n * @param err - The error to check.\n * @returns `true` if the error is a file system error, otherwise `false`.\n */\nexport function isFileError(err: any) {\n return isError(err) && \"code\" in err && err.code;\n}\n\n/**\n * Ignores file not found errors.\n *\n * @param err - The error to check.\n * @returns `null` if the error is a file not found error, otherwise returns the error.\n */\nexport function ignoreNotfound(err: any) {\n return (\n isFileError(err) &&\n (err.code === \"ENOENT\" || err.code === \"EISDIR\" ? null : err)\n );\n}\n\n/**\n * Ignores file exists errors.\n *\n * @param err - The error to check.\n * @returns `null` if the error is a file exists error, otherwise returns the error.\n */\nexport function ignoreExists(err: any) {\n return isFileError(err) && err.code === \"EEXIST\" ? null : err;\n}\n","/* -------------------------------------------------------------------\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 type { Context } from \"@powerlines/core\";\nimport { getFileHeaderWarningText } from \"@powerlines/core/lib/utilities/file-header\";\nimport { exists, existsSync } from \"@stryke/fs/exists\";\nimport { createDirectory, createDirectorySync } from \"@stryke/fs/helpers\";\nimport { isDirectory, isFile } from \"@stryke/fs/is-file\";\nimport { listFiles, listFilesSync } from \"@stryke/fs/list-files\";\nimport { readFile, readFileSync } from \"@stryke/fs/read-file\";\nimport { writeFile, writeFileSync } from \"@stryke/fs/write-file\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { unlinkSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport { BaseStorageAdapter, StorageAdapterOptions } from \"./base\";\nimport { ignoreNotfound } from \"./helpers\";\n\nexport type SetSyncOptions = Parameters<typeof writeFileSync>[2];\nexport type SetOptions = Parameters<typeof writeFile>[2];\n\n/**\n * File system storage adapter implementation.\n */\nexport class FileSystemStorageAdapter extends BaseStorageAdapter {\n /**\n * A name identifying the storage adapter type.\n */\n public name = \"file-system\";\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public override readonly preset = \"fs\";\n\n /**\n * Constructor for the FileSystemStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(context: Context, options?: StorageAdapterOptions) {\n super(context, options);\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public existsSync(key: string): boolean {\n return existsSync(this.resolve(key));\n }\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public override async exists(key: string): Promise<boolean> {\n return exists(this.resolve(key));\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public getSync(key: string): string | null {\n return readFileSync(this.resolve(key));\n }\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public override async get(key: string): Promise<string | null> {\n return readFile(this.resolve(key));\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public setSync(key: string, value: string) {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = this.getSync(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(true, this.context.config.framework)\n )\n ) {\n return writeFileSync(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(true, this.context.config.framework),\n getFileHeaderWarningText(false, this.context.config.framework)\n )\n );\n }\n } else {\n return writeFileSync(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public override async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = await this.get(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(true, this.context.config.framework)\n )\n ) {\n return writeFile(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(true, this.context.config.framework),\n getFileHeaderWarningText(false, this.context.config.framework)\n )\n );\n }\n } else {\n return writeFile(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public removeSync(key: string) {\n if (!this.isReadOnly && this.overwrite) {\n try {\n return unlinkSync(this.resolve(key));\n } catch (err) {\n return ignoreNotfound(err);\n }\n }\n }\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public override async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n return unlink(this.resolve(key)).catch(ignoreNotfound);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override mkdirSync(dirPath: string) {\n createDirectorySync(this.resolve(dirPath));\n }\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override async mkdir(dirPath: string): Promise<void> {\n await createDirectory(this.resolve(dirPath));\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public listSync(base?: string): string[] {\n try {\n return listFilesSync(this.resolve(base), {\n ignore: this.options.ignore\n });\n } catch (err) {\n return ignoreNotfound(err) ?? [];\n }\n }\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public override async list(base?: string): Promise<string[]> {\n return listFiles(this.resolve(base), {\n ignore: this.options.ignore\n })\n .catch(ignoreNotfound)\n .then(r => r || []);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public override isDirectorySync(key: string): boolean {\n return isDirectory(this.resolve(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public override isFileSync(key: string): boolean {\n return isFile(this.resolve(key));\n }\n}\n","/* -------------------------------------------------------------------\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 type { Context } from \"@powerlines/core\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { BaseStorageAdapter, StorageAdapterOptions } from \"./base\";\n\n/**\n * Virtual/in-memory storage adapter implementation.\n */\nexport class VirtualStorageAdapter extends BaseStorageAdapter {\n /**\n * A name identifying the storage adapter type.\n */\n public name = \"virtual\";\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public override readonly preset = \"virtual\";\n\n /**\n * In-memory data storage.\n */\n protected data = new Map<string, any>();\n\n /**\n * Constructor for the VirtualStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(context: Context, options?: StorageAdapterOptions) {\n super(context, options);\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public existsSync(key: string): boolean {\n return this.data.has(this.resolve(key));\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public getSync(key: string): string | null {\n return this.data.get(this.resolve(key)) ?? null;\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public setSync(key: string, value: string) {\n if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) {\n this.data.set(this.resolve(key), value);\n }\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public removeSync(key: string) {\n if (!this.isReadOnly && this.overwrite) {\n this.data.delete(this.resolve(key));\n }\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public listSync(base?: string): string[] {\n return [\n ...this.data\n .keys()\n .filter(key => (!base ? true : isParentPath(key, this.resolve(base))))\n ];\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n public override async dispose(): Promise<void> {\n return this.clear();\n }\n\n /**\n * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.\n *\n * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.\n */\n protected override get overwrite() {\n return !this.isReadOnly;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA,IAAsB,qBAAtB,MAE4B;;;;CAI1B,cAAc;;;;CAUd,AAAO;;;;;;;CAQP,AAAgB,SAAgC;;;;;;;CAQhD,AAAO,YACL,AAAU,SACV,UAAoB,EAAE,MAAM,KAAK,EACjC;EAF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,IAAa,wBAAb,cAA2C,mBAAmB;;;;CAI5D,AAAO,OAAO;;;;;;;CAQd,AAAyB,SAAS;;;;CAKlC,AAAU,uBAAO,IAAI,KAAkB;;;;;;;CAQvC,AAAO,YAAY,SAAkB,SAAiC;AACpE,QAAM,SAAS,QAAQ;;;;;;;;CASzB,AAAO,WAAW,KAAsB;AACtC,SAAO,KAAK,KAAK,IAAI,KAAK,QAAQ,IAAI,CAAC;;;;;;;;CASzC,AAAO,QAAQ,KAA4B;AACzC,SAAO,KAAK,KAAK,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI;;;;;;;;CAS7C,AAAO,QAAQ,KAAa,OAAe;AACzC,MAAI,CAAC,KAAK,eAAe,CAAC,KAAK,WAAW,IAAI,IAAI,KAAK,WACrD,MAAK,KAAK,IAAI,KAAK,QAAQ,IAAI,EAAE,MAAM;;;;;;;CAS3C,AAAO,WAAW,KAAa;AAC7B,MAAI,CAAC,KAAK,cAAc,KAAK,UAC3B,MAAK,KAAK,OAAO,KAAK,QAAQ,IAAI,CAAC;;;;;;;;CAUvC,AAAO,SAAS,MAAyB;AACvC,SAAO,CACL,GAAG,KAAK,KACL,MAAM,CACN,QAAO,QAAQ,CAAC,OAAO,OAAO,aAAa,KAAK,KAAK,QAAQ,KAAK,CAAC,CAAE,CACzE;;;;;;;CAQH,MAAsB,UAAyB;AAC7C,SAAO,KAAK,OAAO;;;;;;;CAQrB,IAAuB,YAAY;AACjC,SAAO,CAAC,KAAK"}
@@ -1,18 +1,18 @@
1
1
  const require_chunk = require('./chunk-C0xms8kb.cjs');
2
2
  let _stryke_path_join = require("@stryke/path/join");
3
3
  let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
4
+ let _stryke_path_append = require("@stryke/path/append");
5
+ let node_fs = require("node:fs");
4
6
  let _powerlines_core_lib_utilities_file_header = require("@powerlines/core/lib/utilities/file-header");
5
7
  let _stryke_fs_exists = require("@stryke/fs/exists");
6
8
  let _stryke_fs_helpers = require("@stryke/fs/helpers");
7
9
  let _stryke_fs_list_files = require("@stryke/fs/list-files");
8
- let _stryke_path_append = require("@stryke/path/append");
9
10
  let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
10
11
  let _stryke_type_checks_is_error = require("@stryke/type-checks/is-error");
11
12
  let _stryke_path_correct_path = require("@stryke/path/correct-path");
12
13
  let _stryke_fs_is_file = require("@stryke/fs/is-file");
13
14
  let _stryke_fs_read_file = require("@stryke/fs/read-file");
14
15
  let _stryke_fs_write_file = require("@stryke/fs/write-file");
15
- let node_fs = require("node:fs");
16
16
  let node_fs_promises = require("node:fs/promises");
17
17
  let node_path = require("node:path");
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/engine",
3
- "version": "0.44.1",
3
+ "version": "0.44.3",
4
4
  "private": false,
5
5
  "description": "An internal package containing the core engine modules for Powerlines.",
6
6
  "homepage": "https://stormsoftware.com",
@@ -137,7 +137,7 @@
137
137
  "@cacheable/memory": "^2.0.8",
138
138
  "@donedeal0/superdiff": "^3.2.0",
139
139
  "@jridgewell/sourcemap-codec": "^1.5.5",
140
- "@powerlines/core": "^0.44.1",
140
+ "@powerlines/core": "^0.44.3",
141
141
  "@storm-software/config": "^1.137.32",
142
142
  "@storm-software/config-tools": "^1.189.78",
143
143
  "@stryke/async": "^0.1.0",
@@ -180,5 +180,5 @@
180
180
  "typescript": "^6.0.3",
181
181
  "undici-types": "^7.25.0"
182
182
  },
183
- "gitHead": "e246dfd00453dc44868dac37f1b6cefb369c6e48"
183
+ "gitHead": "032f30368bbc27e44768f2027691354a4f2719a4"
184
184
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-context-Dv5OTHxZ.mjs","names":["#timestamp","createLogger"],"sources":["../src/_internal/helpers/resolver.ts","../src/context/base-context.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 type { ResolvedConfig, Resolver } from \"@powerlines/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { JitiOptions, createJiti } from \"jiti\";\n\nexport type CreateResolverOptions = Omit<\n JitiOptions,\n \"fsCache\" | \"moduleCache\" | \"interopDefault\"\n> &\n Pick<ResolvedConfig, \"mode\" | \"logLevel\" | \"skipCache\"> & {\n workspaceRoot: string;\n root: string;\n cacheDir: string;\n };\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nfunction resolveOptions(options: CreateResolverOptions): JitiOptions {\n return defu(options, {\n interopDefault: true,\n fsCache:\n options.mode !== \"development\"\n ? joinPaths(options.cacheDir, \"jiti\")\n : false,\n moduleCache: options.mode !== \"development\"\n });\n}\n\n/**\n * Create a Jiti resolver for the given workspace and project root.\n *\n * @param options - The options for creating the resolver.\n * @returns A Jiti instance configured for the specified workspace and project root.\n */\nexport function createResolver(options: CreateResolverOptions): Resolver {\n const baseResolver = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n ) as Resolver;\n baseResolver.plugin = createJiti(\n joinPaths(options.workspaceRoot, options.root),\n resolveOptions(options)\n );\n\n return baseResolver;\n}\n","/* -------------------------------------------------------------------\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 type {\n BaseContext,\n EngineOptions,\n Logger,\n LoggerMessage,\n LoggerOptions,\n LogLevelResolvedConfig,\n LogMessage,\n ParsedUserConfig,\n ResolvedEngineOptions,\n Resolver\n} from \"@powerlines/core\";\nimport { loadUserConfigFile } from \"@powerlines/core/lib/config\";\nimport { resolveLogLevel } from \"@powerlines/core/plugin-utils\";\nimport {\n createLogger,\n extendLogger\n} from \"@powerlines/core/plugin-utils/logging\";\nimport { EnvPaths, getEnvPaths } from \"@stryke/env/get-env-paths\";\nimport { resolvePackage } from \"@stryke/fs/resolve\";\nimport { StormJSON } from \"@stryke/json/storm-json\";\nimport { isEqual } from \"@stryke/path/is-equal\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport chalk from \"chalk\";\nimport { formatDistanceToNowStrict } from \"date-fns/formatDistanceToNowStrict\";\nimport defu from \"defu\";\nimport { createResolver } from \"../_internal/helpers/resolver\";\n\nexport class PowerlinesBaseContext implements BaseContext {\n #timestamp: number = Date.now();\n\n /**\n * The path to the Powerlines package\n */\n public powerlinesPath!: string;\n\n /**\n * The module resolver for the project\n */\n public resolver!: Resolver;\n\n /**\n * The options provided to the Powerlines process\n */\n public options!: ResolvedEngineOptions;\n\n /**\n * The input options used to initialize the context, which may be used when cloning the context to ensure the same configuration is applied to the new context\n */\n public inputOptions: Partial<EngineOptions> = {};\n\n /**\n * The parsed configuration file for the project\n */\n public configFile!: ParsedUserConfig;\n\n /**\n * The logger instance for the context, which can be used to create log messages with consistent formatting and metadata. This logger is extended by plugin contexts to include additional metadata such as the plugin name and category, which can be used to filter and format log messages in a more granular way.\n */\n public get logger(): Logger {\n return this.createLogger({ ...this.configFile.config, ...this.options });\n }\n\n /**\n * A timestamp representing when the context was initialized\n */\n public get timestamp(): number {\n return this.#timestamp;\n }\n\n public get logLevel(): LogLevelResolvedConfig {\n return resolveLogLevel(this.options.logLevel, this.options.mode);\n }\n\n /**\n * The environment paths for the project\n */\n public get envPaths(): EnvPaths {\n return getEnvPaths({\n orgId: this.options.organization,\n appId: this.options.framework || \"powerlines\",\n workspaceRoot: this.options.cwd\n });\n }\n\n /**\n * Creates a clone of the current context with the same configuration and workspace settings. This can be useful for running multiple builds in parallel or for creating isolated contexts for different parts of the build process.\n *\n * @remarks\n * The cloned context will have the same configuration and workspace settings as the original context, but will have a different build ID, release ID, and timestamp. The virtual file system and caches will also be separate between the original and cloned contexts.\n *\n * @returns A promise that resolves to the cloned context.\n */\n public async clone(): Promise<BaseContext> {\n const clone = new PowerlinesBaseContext();\n await clone.init(this.options);\n\n return clone;\n }\n\n /**\n * A logging function for fatal messages\n *\n * @param message - The message to log.\n */\n public fatal(message: string | LogMessage) {\n this.logger.error(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for error messages\n *\n * @param message - The message to log.\n */\n public error(message: string | LogMessage) {\n this.logger.error(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for warning messages\n *\n * @param message - The message to log.\n */\n public warn(message: string | LogMessage) {\n this.logger.warn(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for informational messages\n *\n * @param message - The message to log.\n */\n public info(message: string | LogMessage) {\n this.logger.info(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for debug messages\n *\n * @param message - The message to log.\n */\n public debug(message: string | LogMessage) {\n this.logger.debug(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A logging function for trace messages\n *\n * @param message - The message to log.\n */\n public trace(message: string | LogMessage) {\n this.logger.trace(\n isString(message) ? message : StormJSON.stringify(message)\n );\n }\n\n /**\n * A function to create a timer for measuring the duration of asynchronous operations\n *\n * @example\n * ```ts\n * const stopTimer = context.timer(\"Your Async Operation\");\n * await performAsyncOperation();\n * stopTimer(); // \"Your Async Operation completed in 123.45 milliseconds\"\n * ```\n *\n * @param name - The name of the timer.\n * @returns A function that, when called, stops the timer and logs the duration.\n */\n public timer(name: string): () => void {\n const startDate = Date.now();\n const startDuration = performance.now();\n\n return () => {\n const duration = performance.now() - startDuration;\n this.logger.info({\n meta: {\n category: \"performance\"\n },\n message: `${chalk.bold.cyanBright(name)} completed in ${chalk.bold.cyanBright(\n duration < 1000\n ? `${duration.toFixed(2)} milliseconds`\n : formatDistanceToNowStrict(startDate)\n )}`\n });\n };\n }\n\n /**\n * Create a new logger instance\n *\n * @param options - The configuration options to use for the logger instance, which can be used to customize the appearance and behavior of the log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance.\n * @returns A logger client instance that can be used to generate log messages with consistent formatting and metadata.\n */\n public createLogger(\n options: LoggerOptions,\n callback?: (message: string | LoggerMessage) => void\n ): Logger {\n return createLogger(\n this.options.name || this.options.framework || \"powerlines\",\n options,\n callback\n );\n }\n\n /**\n * Extend the base logger with additional configuration options\n *\n * @param options - The configuration options to extend the base logger with, which can be used to add additional metadata or customize the appearance of log messages generated by the logger. This is typically the name of the plugin or module that is creating the logger instance, as well as any additional metadata such as the plugin category or environment.\n * @returns A new logger client instance that extends the base logger with the provided configuration options.\n */\n public extendLogger(options: LoggerOptions): Logger {\n return extendLogger(this.logger, options);\n }\n\n /**\n * Initialize the context with the provided configuration options\n *\n * @remarks\n * This method will set up the resolver and load the user configuration file based on the provided options. It is called during the construction of the context and can also be called when cloning the context to ensure that the new context has the same configuration and resolver setup.\n *\n * @param options - The configuration options to initialize the context with\n */\n protected async init(options: Partial<EngineOptions> = {}) {\n this.inputOptions = { ...options };\n\n if (!this.powerlinesPath) {\n const powerlinesPath = await resolvePackage(\"powerlines\");\n if (!powerlinesPath) {\n throw new Error(\"Could not resolve `powerlines` package location.\");\n }\n this.powerlinesPath = powerlinesPath;\n }\n\n const cwd = options.cwd || this.options?.cwd || process.cwd();\n const root = replacePath(\n (options.root || this.options?.root) &&\n (options.root || this.options.root).replace(/^\\.\\/?/, \"\") &&\n !isEqual(options.root || this.options.root, cwd)\n ? options.root || this.options.root\n : \".\",\n cwd\n );\n\n this.options = defu(\n {\n root,\n cwd,\n mode: options.mode,\n logLevel: options.logLevel,\n framework: options.framework,\n organization: options.organization,\n configFile: options.configFile\n },\n this.options ?? {},\n {\n mode: \"production\",\n framework: \"powerlines\"\n }\n ) as ResolvedEngineOptions;\n\n this.resolver = createResolver({\n workspaceRoot: cwd,\n root,\n cacheDir: this.envPaths.cache,\n mode: this.options.mode,\n logLevel: this.logLevel\n });\n\n this.configFile = await loadUserConfigFile(this.options, this.resolver);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,eAAe,SAA6C;AACnE,QAAO,KAAK,SAAS;EACnB,gBAAgB;EAChB,SACE,QAAQ,SAAS,gBACb,UAAU,QAAQ,UAAU,OAAO,GACnC;EACN,aAAa,QAAQ,SAAS;EAC/B,CAAC;;;;;;;;AASJ,SAAgB,eAAe,SAA0C;CACvE,MAAM,eAAe,WACnB,UAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AACD,cAAa,SAAS,WACpB,UAAU,QAAQ,eAAe,QAAQ,KAAK,EAC9C,eAAe,QAAQ,CACxB;AAED,QAAO;;;;;ACnBT,IAAa,wBAAb,MAAa,sBAA6C;CACxD,aAAqB,KAAK,KAAK;;;;CAK/B,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO;;;;CAKP,AAAO,eAAuC,EAAE;;;;CAKhD,AAAO;;;;CAKP,IAAW,SAAiB;AAC1B,SAAO,KAAK,aAAa;GAAE,GAAG,KAAK,WAAW;GAAQ,GAAG,KAAK;GAAS,CAAC;;;;;CAM1E,IAAW,YAAoB;AAC7B,SAAO,MAAKA;;CAGd,IAAW,WAAmC;AAC5C,SAAO,gBAAgB,KAAK,QAAQ,UAAU,KAAK,QAAQ,KAAK;;;;;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