@shell-shock/core 0.15.2 → 0.16.1
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.
- package/dist/api.cjs +10 -7
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +11 -8
- package/dist/api.mjs.map +1 -1
- package/dist/components/helpers.cjs +1 -1
- package/dist/components/helpers.cjs.map +1 -1
- package/dist/components/helpers.mjs +1 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +8 -4
- package/dist/components/index.d.cts +4 -2
- package/dist/components/index.d.mts +4 -2
- package/dist/components/index.mjs +4 -2
- package/dist/components/options-parser-logic.cjs +68 -48
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +68 -48
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/spawn-builtin.cjs +656 -0
- package/dist/components/spawn-builtin.cjs.map +1 -0
- package/dist/components/spawn-builtin.d.cts +12 -0
- package/dist/components/spawn-builtin.d.cts.map +1 -0
- package/dist/components/spawn-builtin.d.mts +12 -0
- package/dist/components/spawn-builtin.d.mts.map +1 -0
- package/dist/components/spawn-builtin.mjs +653 -0
- package/dist/components/spawn-builtin.mjs.map +1 -0
- package/dist/components/state-builtin.cjs +553 -0
- package/dist/components/state-builtin.cjs.map +1 -0
- package/dist/components/state-builtin.d.cts +18 -0
- package/dist/components/state-builtin.d.cts.map +1 -0
- package/dist/components/state-builtin.d.mts +18 -0
- package/dist/components/state-builtin.d.mts.map +1 -0
- package/dist/components/state-builtin.mjs +547 -0
- package/dist/components/state-builtin.mjs.map +1 -0
- package/dist/components/utils-builtin.cjs +3 -499
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts +1 -10
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +1 -10
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +5 -498
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/options.cjs +9 -9
- package/dist/contexts/options.cjs.map +1 -1
- package/dist/contexts/options.d.cts +2 -2
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts +2 -2
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +9 -9
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/index.cjs +2 -10
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +1 -7
- package/dist/plugin.cjs +11 -26
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +10 -24
- package/dist/plugin.mjs.map +1 -1
- package/dist/types/config.cjs +3 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.cts +1 -1
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +1 -1
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +3 -1
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/env.cjs +2 -1
- package/dist/types/env.cjs.map +1 -1
- package/dist/types/env.d.cts +15 -0
- package/dist/types/env.d.cts.map +1 -1
- package/dist/types/env.d.mts +15 -0
- package/dist/types/env.d.mts.map +1 -1
- package/dist/types/env.mjs +2 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +1 -2
- package/package.json +50 -36
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/types/runtime.cjs +0 -13
- package/dist/types/runtime.cjs.map +0 -1
- package/dist/types/runtime.d.cts +0 -14
- package/dist/types/runtime.d.cts.map +0 -1
- package/dist/types/runtime.d.mts +0 -14
- package/dist/types/runtime.d.mts.map +0 -1
- package/dist/types/runtime.mjs +0 -11
- package/dist/types/runtime.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-builtin.mjs","names":[],"sources":["../../src/components/spawn-builtin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\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/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, Show, splitProps } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n InterfaceDeclaration,\n InterfaceMember,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { ReflectionKind } from \"@powerlines/deepkit/vendor/type\";\n\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport type { BuiltinFileProps } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport { BuiltinFile } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport {\n TSDoc,\n TSDocDefaultValue,\n TSDocParam,\n TSDocReturns\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport defu from \"defu\";\n\nexport interface SpawnBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * A built-in module for handling child process spawning in Shell Shock.\n */\nexport function SpawnBuiltin(props: SpawnBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"spawn\"\n description=\"A module to handle spawning child processes.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:path\": [\"basename\", \"extname\", \"dirname\", \"join\"],\n \"node:fs\": [\"existsSync\"],\n \"node:child_process\": [{ name: \"spawn\", alias: \"_spawn\" }],\n \"node:stream\": [{ name: \"Stream\", default: true, type: true }]\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n env: [\"isWindows\"]\n })}>\n <FunctionDeclaration\n name=\"resolveCommandEnv\"\n parameters={[\n {\n name: \"params\",\n type: \"{ argv: string[]; env?: NodeJS.ProcessEnv; baseEnv?: NodeJS.ProcessEnv; }\"\n }\n ]}\n returnType=\"NodeJS.ProcessEnv\">\n {code`const baseEnv = params.baseEnv ?? process.env;\nconst argv = params.argv;\nconst shouldSuppressNpmFund = (() => {\n const cmd = basename(argv[0] ?? \"\");\n if (cmd === \"npm\" || cmd === \"npm.cmd\" || cmd === \"npm.exe\") {\n return true;\n }\n if (cmd === \"node\" || cmd === \"node.exe\") {\n const script = argv[1] ?? \"\";\n\n return script.includes(\"npm-cli.js\");\n }\n return false;\n})();\n\nconst mergedEnv = params.env ? { ...baseEnv, ...params.env } : { ...baseEnv };\nconst resolvedEnv = Object.fromEntries(\n Object.entries(mergedEnv)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [key, String(value)])\n);\nif (shouldSuppressNpmFund) {\n resolvedEnv.NPM_CONFIG_FUND ??= \"false\";\n resolvedEnv.npm_config_fund ??= \"false\";\n}\nreturn resolvedEnv;`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"isWindowsBatchCommand\"\n parameters={[{ name: \"resolvedCommand\", type: \"string\" }]}\n returnType=\"boolean\">\n {code`if (!isWindows) {\n return false;\n}\nconst ext = extname(resolvedCommand).toLowerCase();\n\nreturn ext === \".cmd\" || ext === \".bat\";`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"escapeForCmdExe\"\n parameters={[{ name: \"arg\", type: \"string\" }]}\n returnType=\"string\">\n {code`if (/[&|<>^%\\\\\\\\r\\\\\\\\n]/.test(arg)) {\n throw new Error(\n \\`Unsafe Windows cmd.exe argument detected: \\${JSON.stringify(arg)}. \\` +\n \"Pass an explicit shell-wrapper argv at the call site instead.\"\n );\n}\nif (!arg.includes(\" \") && !arg.includes('\"')) {\n return arg;\n}\nreturn \\`\"\\${arg.replace(/\"/g, '\"\"')}\"\\`;`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"buildCmdExeCommandLine\"\n parameters={[\n { name: \"resolvedCommand\", type: \"string\" },\n { name: \"args\", type: \"string[]\" }\n ]}\n returnType=\"string\">\n {code`return [escapeForCmdExe(resolvedCommand), ...args.map(escapeForCmdExe)].join(\n \" \"\n);`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"resolveNpmArgvForWindows\"\n doc=\"On Windows, Node 18.20.2+ (CVE-2024-27980) rejects spawning .cmd/.bat directly without shell, causing EINVAL. Resolve npm/npx to node + cli script so we spawn node.exe instead of npm.cmd.\"\n parameters={[{ name: \"argv\", type: \"string[]\" }]}\n returnType=\"string[] | null\">\n {code`if (!isWindows || argv.length === 0) {\n return null;\n}\nconst base = basename(argv[0] ?? \"\")\n .toLowerCase()\n .replace(/\\.(?:cmd|exe|bat)$/, \"\");\nconst cliName =\n base === \"npx\" ? \"npx-cli.js\" : base === \"npm\" ? \"npm-cli.js\" : null;\nif (!cliName) {\n return null;\n}\nconst nodeDir = dirname(process.execPath);\nconst cliPath = join(nodeDir, \"node_modules\", \"npm\", \"bin\", cliName);\nif (!existsSync(cliPath)) {\n const command = argv[0] ?? \"\";\n const ext = extname(command).toLowerCase();\n const shimmedCommand = ext ? command : \\`\\${command}.cmd\\`;\n\n return [shimmedCommand, ...argv.slice(1)];\n}\nreturn [process.execPath, cliPath, ...argv.slice(1)];`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"resolveCommand\"\n doc=\"Resolves a command for Windows compatibility. On Windows, non-.exe commands (like pnpm, yarn) are resolved to .cmd; npm/npx are handled by resolveNpmArgvForWindows to avoid spawn EINVAL (no direct .cmd).\"\n parameters={[{ name: \"command\", type: \"string\" }]}\n returnType=\"string\">\n {code`if (!isWindows) {\n return command;\n}\nconst base = basename(command).toLowerCase();\nif (extname(base)) {\n return command;\n}\nif ([\"pnpm\", \"yarn\"].includes(base)) {\n return \\`\\${command}.cmd\\`;\n}\nreturn command;`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"resolveCommandStdio\"\n parameters={[\n {\n name: \"params\",\n type: \"{ hasInput: boolean; preferInherit: boolean; }\"\n }\n ]}\n returnType='[\"pipe\" | \"inherit\" | \"ignore\", \"pipe\", \"pipe\"]'>\n {code`const stdin = params.hasInput\n ? \"pipe\"\n : params.preferInherit\n ? \"inherit\"\n : \"pipe\";\n\nreturn [stdin, \"pipe\", \"pipe\"];`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"resolveChildProcessInvocation\"\n parameters={[\n {\n name: \"params\",\n type: \"{ argv: string[]; windowsVerbatimArguments?: boolean; }\"\n }\n ]}\n returnType=\"{ args: string[]; command: string; usesWindowsExitCodeShim: boolean; windowsHide: true; windowsVerbatimArguments?: boolean; }\">\n {code`const finalArgv =\n isWindows\n ? (resolveNpmArgvForWindows(params.argv) ?? params.argv)\n : params.argv;\nconst resolvedCommand =\n finalArgv !== params.argv\n ? (finalArgv[0] ?? \"\")\n : resolveCommand(params.argv[0] ?? \"\");\nconst useCmdWrapper = isWindowsBatchCommand(resolvedCommand);\n\nreturn {\n command: useCmdWrapper\n ? (process.env.ComSpec ?? \"cmd.exe\")\n : resolvedCommand,\n args: useCmdWrapper\n ? [\n \"/d\",\n \"/s\",\n \"/c\",\n buildCmdExeCommandLine(resolvedCommand, finalArgv.slice(1))\n ]\n : finalArgv.slice(1),\n usesWindowsExitCodeShim:\n isWindows &&\n (useCmdWrapper || finalArgv !== params.argv),\n windowsHide: true,\n windowsVerbatimArguments: useCmdWrapper\n ? true\n : params.windowsVerbatimArguments\n};`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"resolveProcessExitCode\"\n parameters={[\n {\n name: \"params\",\n type: \"{ explicitCode: number | null | undefined; childExitCode: number | null | undefined; resolvedSignal: NodeJS.Signals | null; usesWindowsExitCodeShim: boolean; timedOut: boolean; noOutputTimedOut: boolean; killIssuedByTimeout: boolean; }\"\n }\n ]}\n returnType=\"number | null\">\n {code`return (\n params.explicitCode ??\n params.childExitCode ??\n (params.usesWindowsExitCodeShim &&\n params.resolvedSignal == null &&\n !params.timedOut &&\n !params.noOutputTimedOut &&\n !params.killIssuedByTimeout\n ? 0\n : null)\n);`}\n </FunctionDeclaration>\n <Spacing />\n <FunctionDeclaration\n name=\"shouldSpawnWithShell\"\n parameters={[\n {\n name: \"params\",\n type: \"{ resolvedCommand: string; platform: NodeJS.Platform; }\"\n }\n ]}\n returnType=\"boolean\">\n {code`// SECURITY: never enable \\`shell\\` for argv-based execution.\n// \\`shell\\` routes through cmd.exe on Windows, which turns untrusted argv values\n// (like chat prompts passed as CLI args) into command-injection primitives.\n// If you need a shell, use an explicit shell-wrapper argv (e.g. \\`cmd.exe /c ...\\`)\n// and validate/escape at the call site.\nvoid params;\nreturn false;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"The result of a spawn operation.\" />\n <InterfaceDeclaration export name=\"SpawnResult\">\n <TSDoc heading=\"The PID of the spawned child process, if available.\" />\n <InterfaceMember name=\"pid\" optional type=\"number\" />\n <Spacing />\n <TSDoc heading=\"The standard output produced by the child process.\" />\n <InterfaceMember name=\"stdout\" type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The standard error produced by the child process.\" />\n <InterfaceMember name=\"stderr\" type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The exit code of the child process, if available.\" />\n <InterfaceMember name=\"code\" type=\"number | null\" />\n <Spacing />\n <TSDoc heading=\"The signal that caused the child process to terminate, if it was killed by a signal.\" />\n <InterfaceMember name=\"signal\" type=\"NodeJS.Signals | null\" />\n <Spacing />\n <TSDoc heading=\"Whether the child process was killed.\" />\n <InterfaceMember name=\"killed\" type=\"boolean\" />\n <Spacing />\n <TSDoc heading=\"The reason for the child process termination.\" />\n <InterfaceMember\n name=\"termination\"\n type={code`\"exit\" | \"timeout\" | \"no-output-timeout\" | \"signal\"`}\n />\n <Spacing />\n <TSDoc heading=\"Whether the child process timed out due to no output.\" />\n <InterfaceMember name=\"noOutputTimedOut\" optional type=\"boolean\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"Options for spawning a child process.\" />\n <InterfaceDeclaration export name=\"SpawnOptions\">\n <TSDoc heading=\"The timeout in milliseconds for the spawn operation. If the process runs longer than this, it will be killed and the spawn promise will reject. This can also be provided as a number directly to the spawn function for convenience. Providing \\`-1\\` will disable the timeout.\">\n <TSDocDefaultValue\n type={ReflectionKind.number}\n defaultValue=\"300000\"\n />\n </TSDoc>\n <InterfaceMember name=\"timeoutMs\" type=\"number\" />\n <Spacing />\n <TSDoc heading=\"The current working directory of the child process.\" />\n <InterfaceMember name=\"cwd\" optional type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The input to be passed to the child process.\" />\n <InterfaceMember name=\"input\" optional type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The environment variables for the child process.\" />\n <InterfaceMember name=\"env\" optional type=\"NodeJS.ProcessEnv\" />\n <Spacing />\n <TSDoc heading=\"Whether to pass arguments to the child process verbatim on Windows.\" />\n <InterfaceMember\n name=\"windowsVerbatimArguments\"\n optional\n type=\"boolean\"\n />\n <Spacing />\n <TSDoc heading=\"The timeout in milliseconds for the child process to produce output on stdout or stderr. If the process produces no output for this duration, it will be killed and the spawn promise will reject with a no-output-timeout termination reason.\" />\n <InterfaceMember name=\"noOutputTimeoutMs\" optional type=\"number\" />\n </InterfaceDeclaration>\n <Spacing />\n <VarDeclaration\n const\n name=\"WINDOWS_CLOSE_STATE_SETTLE_TIMEOUT_MS\"\n initializer={code`250`}\n />\n <Spacing />\n <VarDeclaration\n const\n name=\"WINDOWS_CLOSE_STATE_POLL_MS\"\n initializer={code`10`}\n />\n <Spacing />\n <TSDoc heading=\"Spawns a child process with the given arguments and options, returning a promise that resolves with the result of the spawn operation.\">\n <TSDocParam name=\"argv\">\n {\"The command and its arguments to spawn.\"}\n </TSDocParam>\n <TSDocParam name=\"optionsOrTimeoutMs\">\n {`The options for spawning the command, or a number representing the timeout in milliseconds. This allows for a convenient shorthand when only a timeout is needed. Providing \\`-1\\` will disable the timeout. If no options or timeout are provided, a default timeout of 5 minutes will be used.`}\n </TSDocParam>\n <TSDocReturns>\n {\n \"A promise that resolves with the result of the spawn operation, including stdout, stderr, exit code, signal, and termination reason.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"spawn\"\n parameters={[\n { name: \"argv\", type: \"string[]\" },\n {\n name: \"optionsOrTimeoutMs\",\n type: \"number | SpawnOptions\",\n default: \"300000\"\n }\n ]}\n returnType=\"Promise<SpawnResult>\">\n {code`const options: SpawnOptions =\n typeof optionsOrTimeoutMs === \"number\"\n ? { timeoutMs: optionsOrTimeoutMs }\n : optionsOrTimeoutMs;\nconst { timeoutMs, cwd, input, env, noOutputTimeoutMs } = options;\nconst hasInput = input !== undefined;\nconst resolvedEnv = resolveCommandEnv({ argv, env });\nconst stdio = resolveCommandStdio({ hasInput, preferInherit: true });\nconst invocation = resolveChildProcessInvocation({\n argv,\n windowsVerbatimArguments: options.windowsVerbatimArguments\n});\n\nconst child = _spawn(invocation.command, invocation.args, {\n stdio,\n cwd,\n env: resolvedEnv,\n windowsHide: invocation.windowsHide,\n windowsVerbatimArguments: invocation.windowsVerbatimArguments,\n ...(shouldSpawnWithShell({\n resolvedCommand: invocation.command,\n platform: process.platform\n })\n ? { shell: true }\n : {})\n});\n\nreturn new Promise((resolve, reject) => {\n let stdout = \"\";\n let stderr = \"\";\n let settled = false;\n let timedOut = false;\n let noOutputTimedOut = false;\n let killIssuedByTimeout = false;\n let childExitState: {\n code: number | null;\n signal: NodeJS.Signals | null;\n } | null = null;\n let closeFallbackTimer: NodeJS.Timeout | null = null;\n let noOutputTimer: NodeJS.Timeout | null = null;\n const shouldTrackOutputTimeout =\n typeof noOutputTimeoutMs === \"number\" &&\n Number.isFinite(noOutputTimeoutMs) &&\n noOutputTimeoutMs > 0;\n\n const clearNoOutputTimer = () => {\n if (!noOutputTimer) {\n return;\n }\n clearTimeout(noOutputTimer);\n noOutputTimer = null;\n };\n\n const clearCloseFallbackTimer = () => {\n if (!closeFallbackTimer) {\n return;\n }\n clearTimeout(closeFallbackTimer);\n closeFallbackTimer = null;\n };\n\n const killChild = () => {\n if (settled || typeof child?.kill !== \"function\") {\n return;\n }\n killIssuedByTimeout = true;\n child.kill(\"SIGKILL\");\n };\n\n const armNoOutputTimer = () => {\n if (!shouldTrackOutputTimeout || settled) {\n return;\n }\n clearNoOutputTimer();\n noOutputTimer = setTimeout(() => {\n if (settled) {\n return;\n }\n noOutputTimedOut = true;\n killChild();\n }, Math.floor(noOutputTimeoutMs));\n };\n\n const timer = setTimeout(() => {\n timedOut = true;\n killChild();\n }, timeoutMs >= 0 ? timeoutMs : Number.POSITIVE_INFINITY);\n armNoOutputTimer();\n\n if (hasInput && child.stdin) {\n child.stdin.write(input ?? \"\");\n child.stdin.end();\n }\n\n child.stdout?.on(\"data\", (d: Stream) => {\n stdout += d.toString();\n armNoOutputTimer();\n });\n child.stderr?.on(\"data\", (d: Stream) => {\n stderr += d.toString();\n armNoOutputTimer();\n });\n child.on(\"error\", err => {\n if (settled) {\n return;\n }\n settled = true;\n clearTimeout(timer);\n clearNoOutputTimer();\n clearCloseFallbackTimer();\n reject(err);\n });\n child.on(\"exit\", (code, signal) => {\n childExitState = { code, signal };\n if (settled || closeFallbackTimer) {\n return;\n }\n closeFallbackTimer = setTimeout(() => {\n if (settled) {\n return;\n }\n child.stdout?.destroy();\n child.stderr?.destroy();\n }, 250);\n });\n const resolveFromClose = (\n code: number | null,\n signal: NodeJS.Signals | null\n ) => {\n if (settled) {\n return;\n }\n settled = true;\n clearTimeout(timer);\n clearNoOutputTimer();\n clearCloseFallbackTimer();\n const resolvedSignal =\n childExitState?.signal ?? signal ?? child.signalCode ?? null;\n const resolvedCode = resolveProcessExitCode({\n explicitCode: childExitState?.code ?? code,\n childExitCode: child.exitCode,\n resolvedSignal,\n usesWindowsExitCodeShim: invocation.usesWindowsExitCodeShim,\n timedOut,\n noOutputTimedOut,\n killIssuedByTimeout\n });\n const termination = noOutputTimedOut\n ? \"no-output-timeout\"\n : timedOut\n ? \"timeout\"\n : resolvedSignal != null\n ? \"signal\"\n : \"exit\";\n const normalizedCode =\n termination === \"timeout\" || termination === \"no-output-timeout\"\n ? resolvedCode === 0\n ? 124\n : resolvedCode\n : resolvedCode;\n resolve({\n pid: child.pid ?? undefined,\n stdout,\n stderr,\n code: normalizedCode,\n signal: resolvedSignal,\n killed: child.killed,\n termination,\n noOutputTimedOut\n });\n };\n child.on(\"close\", (code, signal) => {\n if (\n !isWindows ||\n childExitState != null ||\n code != null ||\n signal != null ||\n child.exitCode != null ||\n child.signalCode != null\n ) {\n resolveFromClose(code, signal);\n return;\n }\n\n const startedAt = Date.now();\n const waitForExitState = () => {\n if (settled) {\n return;\n }\n if (\n childExitState != null ||\n child.exitCode != null ||\n child.signalCode != null\n ) {\n resolveFromClose(code, signal);\n return;\n }\n if (Date.now() - startedAt >= WINDOWS_CLOSE_STATE_SETTLE_TIMEOUT_MS) {\n resolveFromClose(code, signal);\n return;\n }\n setTimeout(waitForExitState, WINDOWS_CLOSE_STATE_POLL_MS);\n };\n waitForExitState();\n });\n});`}\n </FunctionDeclaration>\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;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A,CAAA;IAAA,gBAAQ,qBAAgC;KACxC,UAAY;KACZ,OAAA;KACJ,MAAA;KACA,YAAA,CAAA;;MAEI,MAAQ;MACP,EAAA;MACF,MAAA;MACE,MAAA;MACL,SAAa;MACb,CAAA;KACI,YAAA;KACF,UAAA,IAAiB"}
|
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
4
|
+
const require_contexts_options = require('../contexts/options.cjs');
|
|
5
|
+
require('../plugin-utils/index.cjs');
|
|
6
|
+
const require_components_options_parser_logic = require('./options-parser-logic.cjs');
|
|
7
|
+
let _alloy_js_core_jsx_runtime = require("@alloy-js/core/jsx-runtime");
|
|
8
|
+
let defu = require("defu");
|
|
9
|
+
defu = require_runtime.__toESM(defu);
|
|
10
|
+
let _alloy_js_core = require("@alloy-js/core");
|
|
11
|
+
let _powerlines_plugin_alloy_core_components_spacing = require("@powerlines/plugin-alloy/core/components/spacing");
|
|
12
|
+
let _powerlines_plugin_alloy_core_contexts_context = require("@powerlines/plugin-alloy/core/contexts/context");
|
|
13
|
+
let _alloy_js_typescript = require("@alloy-js/typescript");
|
|
14
|
+
let _powerlines_plugin_alloy_typescript_components_builtin_file = require("@powerlines/plugin-alloy/typescript/components/builtin-file");
|
|
15
|
+
let _powerlines_plugin_alloy_typescript_components_tsdoc = require("@powerlines/plugin-alloy/typescript/components/tsdoc");
|
|
16
|
+
|
|
17
|
+
//#region src/components/state-builtin.tsx
|
|
18
|
+
function GlobalTypeDefinitions() {
|
|
19
|
+
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
20
|
+
const options = (0, _alloy_js_core.computed)(() => require_contexts_options.computedOptions(context.options));
|
|
21
|
+
return [
|
|
22
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
23
|
+
return `An object representing the global options available for every command in the ${require_context_helpers.getAppTitle(context, true)} command-line application.`;
|
|
24
|
+
} }),
|
|
25
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
26
|
+
"export": true,
|
|
27
|
+
name: "GlobalOptions",
|
|
28
|
+
get children() {
|
|
29
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.For, {
|
|
30
|
+
get each() {
|
|
31
|
+
return Object.values(options.value);
|
|
32
|
+
},
|
|
33
|
+
hardline: true,
|
|
34
|
+
children: (option) => (0, _alloy_js_core_jsx_runtime.createComponent)(require_components_options_parser_logic.OptionsMember, { option })
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
38
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
39
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The context object for the current command execution, containing the command path and segments." }),
|
|
40
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
41
|
+
"export": true,
|
|
42
|
+
name: "CommandContext",
|
|
43
|
+
typeParameters: [{
|
|
44
|
+
name: "THandler",
|
|
45
|
+
extends: "(...params: any[]) => any",
|
|
46
|
+
default: "(...params: any[]) => any"
|
|
47
|
+
}],
|
|
48
|
+
get children() {
|
|
49
|
+
return [
|
|
50
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
51
|
+
return `The full command path as a string. For example, if the user runs \`${require_context_helpers.getAppBin(context)} foo bar\`, this would be \`foo bar\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`;
|
|
52
|
+
} }),
|
|
53
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
54
|
+
name: "path",
|
|
55
|
+
type: "string"
|
|
56
|
+
}),
|
|
57
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
58
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
59
|
+
return `An array of command path segments. For example, if the user runs \`${require_context_helpers.getAppBin(context)} foo bar\`, this would be \`["foo", "bar"]\`. This is useful for commands that need to know their individual path segments, such as for dynamic routing or for commands that have behavior based on specific segments in the command hierarchy.`;
|
|
60
|
+
} }),
|
|
61
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
62
|
+
name: "segments",
|
|
63
|
+
type: "string[]"
|
|
64
|
+
}),
|
|
65
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
66
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: `The parameters for the current command's handler function.` }),
|
|
67
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
68
|
+
name: "params",
|
|
69
|
+
type: "Parameters<THandler>"
|
|
70
|
+
})
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
75
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.TypeDeclaration, {
|
|
76
|
+
"export": true,
|
|
77
|
+
name: "GlobalContextStatus",
|
|
78
|
+
children: _alloy_js_core.code`"initializing" | "preparing" | "executing" | "completed"`
|
|
79
|
+
}),
|
|
80
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
81
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
82
|
+
return `The state object for the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
83
|
+
} }),
|
|
84
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
85
|
+
"export": true,
|
|
86
|
+
name: "GlobalContextState",
|
|
87
|
+
get children() {
|
|
88
|
+
return [
|
|
89
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The unique identifier for the current execution context." }),
|
|
90
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
91
|
+
name: "executionId",
|
|
92
|
+
type: "string"
|
|
93
|
+
}),
|
|
94
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
95
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The status of the current execution context." }),
|
|
96
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
97
|
+
name: "status",
|
|
98
|
+
type: "GlobalContextStatus"
|
|
99
|
+
}),
|
|
100
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
101
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "Indicates whether the current execution context has encountered an error." }),
|
|
102
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
103
|
+
name: "isError",
|
|
104
|
+
type: "boolean"
|
|
105
|
+
}),
|
|
106
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
107
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "A map containing arbitrary data associated with the current execution context." }),
|
|
108
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
109
|
+
name: "meta",
|
|
110
|
+
type: "Map<string, unknown>"
|
|
111
|
+
})
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
116
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { get heading() {
|
|
117
|
+
return `The context object for the ${require_context_helpers.getAppTitle(context)} application.`;
|
|
118
|
+
} }),
|
|
119
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceDeclaration, {
|
|
120
|
+
"export": true,
|
|
121
|
+
name: "GlobalContext",
|
|
122
|
+
get children() {
|
|
123
|
+
return [
|
|
124
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The global options shared across all commands in the application." }),
|
|
125
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
126
|
+
name: "options",
|
|
127
|
+
type: "GlobalOptions"
|
|
128
|
+
}),
|
|
129
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
130
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The raw command-line arguments passed to the application." }),
|
|
131
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
132
|
+
name: "inputArgs",
|
|
133
|
+
type: "string[]"
|
|
134
|
+
}),
|
|
135
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
136
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, { heading: "The state of the current execution context." }),
|
|
137
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
138
|
+
name: "state",
|
|
139
|
+
type: "GlobalContextState"
|
|
140
|
+
})
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Generates utilities for detecting terminal color support.
|
|
148
|
+
*/
|
|
149
|
+
function ArgsUtilities() {
|
|
150
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
151
|
+
heading: "Retrieves the command-line arguments from Deno or Node.js environments.",
|
|
152
|
+
get children() {
|
|
153
|
+
return [
|
|
154
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `This function is only intended for internal use. Please use \`useArgs()\` instead.` }),
|
|
155
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
156
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocInternal, {}),
|
|
157
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
158
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `An array of command-line arguments from Deno or Node.js environments.` })
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
162
|
+
name: "getInputArgs",
|
|
163
|
+
returnType: "string[]",
|
|
164
|
+
children: _alloy_js_core.code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
|
|
165
|
+
})];
|
|
166
|
+
}
|
|
167
|
+
function ContextUtilities() {
|
|
168
|
+
const context = (0, _powerlines_plugin_alloy_core_contexts_context.usePowerlines)();
|
|
169
|
+
return [
|
|
170
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
171
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
172
|
+
get heading() {
|
|
173
|
+
return `The global ${require_context_helpers.getAppTitle(context)} application context store instance.`;
|
|
174
|
+
},
|
|
175
|
+
get children() {
|
|
176
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocInternal, {});
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
180
|
+
"export": true,
|
|
181
|
+
"const": true,
|
|
182
|
+
name: "unstable_globalStore",
|
|
183
|
+
children: _alloy_js_core.code` new AsyncLocalStorage<GlobalContext>({ name: "globalStore" }); `
|
|
184
|
+
}),
|
|
185
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
186
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
187
|
+
get heading() {
|
|
188
|
+
return `Get the ${require_context_helpers.getAppTitle(context)} application context for the current application.`;
|
|
189
|
+
},
|
|
190
|
+
get children() {
|
|
191
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
192
|
+
name: "options",
|
|
193
|
+
children: `The options to use when getting the context. This can include parameters for how to handle missing contexts, such as whether to throw an error or return undefined. By default, if the context is not available, this function will return undefined.`
|
|
194
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { get children() {
|
|
195
|
+
return `The ${require_context_helpers.getAppTitle(context)} application context for the current application or undefined if the context is not available.`;
|
|
196
|
+
} })];
|
|
197
|
+
}
|
|
198
|
+
}),
|
|
199
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
200
|
+
"export": true,
|
|
201
|
+
name: "useGlobal",
|
|
202
|
+
returnType: "GlobalContext",
|
|
203
|
+
children: _alloy_js_core.code`return unstable_globalStore.getStore() as GlobalContext;`
|
|
204
|
+
}),
|
|
205
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
206
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
207
|
+
get heading() {
|
|
208
|
+
return `A utility hook function to get the command-line arguments from the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
209
|
+
},
|
|
210
|
+
get children() {
|
|
211
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "An array of command-line arguments from the application context." });
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
215
|
+
"export": true,
|
|
216
|
+
name: "useArgs",
|
|
217
|
+
returnType: "string[]",
|
|
218
|
+
children: _alloy_js_core.code`return useGlobal()?.inputArgs ?? getInputArgs();`
|
|
219
|
+
}),
|
|
220
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
221
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
222
|
+
get heading() {
|
|
223
|
+
return `A utility hook function to get the state of the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
224
|
+
},
|
|
225
|
+
get children() {
|
|
226
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "The state of the application context." });
|
|
227
|
+
}
|
|
228
|
+
}),
|
|
229
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
230
|
+
"export": true,
|
|
231
|
+
name: "useState",
|
|
232
|
+
returnType: "GlobalContextState",
|
|
233
|
+
children: _alloy_js_core.code`return useGlobal()?.state;`
|
|
234
|
+
}),
|
|
235
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
236
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
237
|
+
get heading() {
|
|
238
|
+
return `A utility function to update the state of the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
239
|
+
},
|
|
240
|
+
get children() {
|
|
241
|
+
return [
|
|
242
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: `This function will throw an error if the global context is not available, so it should only be used within a valid context scope, such as within a command handler or within the \`withGlobal()\` function.` }),
|
|
243
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
244
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
245
|
+
name: "update",
|
|
246
|
+
children: `The new state or a function that receives the previous state and returns the new state. This allows for both direct state updates and functional updates based on the previous state.`
|
|
247
|
+
})
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
}),
|
|
251
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
252
|
+
"export": true,
|
|
253
|
+
name: "setState",
|
|
254
|
+
parameters: [{
|
|
255
|
+
name: "update",
|
|
256
|
+
type: "Partial<GlobalContextState> | ((prev: GlobalContextState) => GlobalContextState)"
|
|
257
|
+
}],
|
|
258
|
+
get children() {
|
|
259
|
+
return _alloy_js_core.code`const prev = useGlobal()?.state;
|
|
260
|
+
if (!prev) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
\`The ${require_context_helpers.getAppTitle(context)} application context is not available. Make sure to call setState() within a valid context scope.\`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
useGlobal().state = typeof update === "function" ? update(prev) : { ...prev, ...update }; `;
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
269
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
270
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
271
|
+
get heading() {
|
|
272
|
+
return `A utility hook function to get the execution ID of the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
273
|
+
},
|
|
274
|
+
get children() {
|
|
275
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "The execution ID of the application context." });
|
|
276
|
+
}
|
|
277
|
+
}),
|
|
278
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
279
|
+
"export": true,
|
|
280
|
+
name: "useExecutionId",
|
|
281
|
+
returnType: "string",
|
|
282
|
+
children: _alloy_js_core.code`return useState().executionId;`
|
|
283
|
+
}),
|
|
284
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
285
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
286
|
+
get heading() {
|
|
287
|
+
return `A utility hook function to get the metadata of the ${require_context_helpers.getAppTitle(context)} application context.`;
|
|
288
|
+
},
|
|
289
|
+
get children() {
|
|
290
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "The metadata of the application context." });
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
294
|
+
"export": true,
|
|
295
|
+
name: "useMeta",
|
|
296
|
+
returnType: "Map<string, unknown>",
|
|
297
|
+
children: _alloy_js_core.code`return useState().meta;`
|
|
298
|
+
}),
|
|
299
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
300
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
301
|
+
get heading() {
|
|
302
|
+
return `A utility hook function to get the current status of the ${require_context_helpers.getAppTitle(context)} application.`;
|
|
303
|
+
},
|
|
304
|
+
get children() {
|
|
305
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "The current status of the application." });
|
|
306
|
+
}
|
|
307
|
+
}),
|
|
308
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
309
|
+
"export": true,
|
|
310
|
+
name: "useStatus",
|
|
311
|
+
returnType: "GlobalContextStatus",
|
|
312
|
+
children: _alloy_js_core.code`return useState().status;`
|
|
313
|
+
}),
|
|
314
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
315
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
316
|
+
get heading() {
|
|
317
|
+
return `The global ${require_context_helpers.getAppTitle(context)} - command context store instance.`;
|
|
318
|
+
},
|
|
319
|
+
get children() {
|
|
320
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocInternal, {});
|
|
321
|
+
}
|
|
322
|
+
}),
|
|
323
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
324
|
+
"export": true,
|
|
325
|
+
name: "unstable_commandStore",
|
|
326
|
+
children: _alloy_js_core.code`new AsyncLocalStorage<CommandContext>({ name: "commandStore" });`
|
|
327
|
+
}),
|
|
328
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
329
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
330
|
+
get heading() {
|
|
331
|
+
return `Get the ${require_context_helpers.getAppTitle(context)} - command context for the current application.`;
|
|
332
|
+
},
|
|
333
|
+
get children() {
|
|
334
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { get children() {
|
|
335
|
+
return `The ${require_context_helpers.getAppTitle(context)} - command context for the current application.`;
|
|
336
|
+
} });
|
|
337
|
+
}
|
|
338
|
+
}),
|
|
339
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
340
|
+
"export": true,
|
|
341
|
+
name: "useCommand",
|
|
342
|
+
returnType: "CommandContext",
|
|
343
|
+
get children() {
|
|
344
|
+
return _alloy_js_core.code`const result = unstable_commandStore.getStore();
|
|
345
|
+
if (!result) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
\`The ${require_context_helpers.getAppTitle(context)} - command context is not available. Make sure to call useCommand() within a valid context scope.\`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
return result;`;
|
|
351
|
+
}
|
|
352
|
+
}),
|
|
353
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
354
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
355
|
+
heading: "A utility hook function to get the individual segments of the current command path.",
|
|
356
|
+
get children() {
|
|
357
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "An array of command path segments." });
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
360
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
361
|
+
"export": true,
|
|
362
|
+
name: "useSegments",
|
|
363
|
+
returnType: "string[]",
|
|
364
|
+
children: _alloy_js_core.code`return useCommand().segments;`
|
|
365
|
+
}),
|
|
366
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
367
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
368
|
+
heading: "A utility hook function to get the full command path as a string.",
|
|
369
|
+
get children() {
|
|
370
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { get children() {
|
|
371
|
+
return `The full command path as a string. For example, if the user runs \`${require_context_helpers.getAppBin(context)} foo bar\`, this would return \`"foo bar"\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`;
|
|
372
|
+
} });
|
|
373
|
+
}
|
|
374
|
+
}),
|
|
375
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
376
|
+
"export": true,
|
|
377
|
+
name: "usePath",
|
|
378
|
+
returnType: "string",
|
|
379
|
+
children: _alloy_js_core.code`return useCommand().path;`
|
|
380
|
+
}),
|
|
381
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
382
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
383
|
+
heading: "Checks if a specific flag is present in the command-line arguments.",
|
|
384
|
+
get children() {
|
|
385
|
+
return [
|
|
386
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
|
|
387
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
388
|
+
name: "flag",
|
|
389
|
+
children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
|
|
390
|
+
}),
|
|
391
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
392
|
+
name: "argv",
|
|
393
|
+
children: "The command-line arguments to check against. Defaults to global Deno args or process args."
|
|
394
|
+
}),
|
|
395
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "True if the flag is present, false otherwise." })
|
|
396
|
+
];
|
|
397
|
+
}
|
|
398
|
+
}),
|
|
399
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
400
|
+
"export": true,
|
|
401
|
+
name: "hasFlag",
|
|
402
|
+
parameters: [{
|
|
403
|
+
name: "flag",
|
|
404
|
+
type: "string | string[]"
|
|
405
|
+
}, {
|
|
406
|
+
name: "argv",
|
|
407
|
+
type: "string[]",
|
|
408
|
+
default: "useArgs()"
|
|
409
|
+
}],
|
|
410
|
+
get children() {
|
|
411
|
+
return [
|
|
412
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
|
|
413
|
+
"const": true,
|
|
414
|
+
name: "position",
|
|
415
|
+
type: "number",
|
|
416
|
+
initializer: _alloy_js_core.code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
|
|
417
|
+
const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
|
|
418
|
+
return pos !== -1 ? pos : ret;
|
|
419
|
+
}, -1);`
|
|
420
|
+
}),
|
|
421
|
+
(0, _alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
422
|
+
_alloy_js_core.code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
|
|
423
|
+
];
|
|
424
|
+
}
|
|
425
|
+
}),
|
|
426
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
427
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
428
|
+
heading: "A utility function to determine if the help flag is present or if the command is in an error state during preparation.",
|
|
429
|
+
get children() {
|
|
430
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `True if the help flag is present or if the command is in an error state during preparation, false otherwise. This can be used to conditionally display help text or to alter command behavior when the user is likely seeking help.` });
|
|
431
|
+
}
|
|
432
|
+
}),
|
|
433
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
434
|
+
"export": true,
|
|
435
|
+
name: "isHelp",
|
|
436
|
+
returnType: "boolean",
|
|
437
|
+
children: _alloy_js_core.code`return !isCI && (hasFlag(["help", "h", "?"]) || (useStatus() === "preparing" && useState().isError)); `
|
|
438
|
+
}),
|
|
439
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
440
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
441
|
+
get heading() {
|
|
442
|
+
return `A utility function to wrap the ${require_context_helpers.getAppTitle(context)} application within the global context scope.`;
|
|
443
|
+
},
|
|
444
|
+
get children() {
|
|
445
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
446
|
+
name: "handler",
|
|
447
|
+
children: `The callback function to run within the global context scope. This function will receive the global context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`
|
|
448
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `The result of the callback function, which can be a value or a promise that resolves to a value.` })];
|
|
449
|
+
}
|
|
450
|
+
}),
|
|
451
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
452
|
+
"export": true,
|
|
453
|
+
async: true,
|
|
454
|
+
name: "withGlobal",
|
|
455
|
+
parameters: [{
|
|
456
|
+
name: "handler",
|
|
457
|
+
type: "() => any"
|
|
458
|
+
}],
|
|
459
|
+
returnType: "Promise<void>",
|
|
460
|
+
children: _alloy_js_core.code`
|
|
461
|
+
return unstable_globalStore.run({ options: {} as unknown as GlobalOptions, inputArgs: getInputArgs(), state: { executionId: randomUUID(), status: "initializing", isError: false, meta: new Map() } as GlobalContextState }, handler);`
|
|
462
|
+
}),
|
|
463
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
464
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
465
|
+
get heading() {
|
|
466
|
+
return `A utility function to wrap a ${require_context_helpers.getAppTitle(context)} application command handler within the command context scope.`;
|
|
467
|
+
},
|
|
468
|
+
get children() {
|
|
469
|
+
return [(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
470
|
+
name: "handler",
|
|
471
|
+
children: `The callback function to run within the command context scope. This function will receive the command context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`
|
|
472
|
+
}), (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `The result of the callback function, which can be a value or a promise that resolves to a value.` })];
|
|
473
|
+
}
|
|
474
|
+
}),
|
|
475
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
476
|
+
"export": true,
|
|
477
|
+
async: true,
|
|
478
|
+
name: "withCommand",
|
|
479
|
+
typeParameters: [{
|
|
480
|
+
name: "THandler",
|
|
481
|
+
extends: "(...params: any[]) => any",
|
|
482
|
+
default: "(...params: any[]) => any"
|
|
483
|
+
}],
|
|
484
|
+
parameters: [
|
|
485
|
+
{
|
|
486
|
+
name: "path",
|
|
487
|
+
type: "string"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
name: "segments",
|
|
491
|
+
type: "string[]"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
name: "params",
|
|
495
|
+
type: "Parameters<THandler>"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
name: "handler",
|
|
499
|
+
type: "THandler"
|
|
500
|
+
}
|
|
501
|
+
],
|
|
502
|
+
returnType: "Promise<{ error: string | Error | null }>",
|
|
503
|
+
children: _alloy_js_core.code`setState({ status: "preparing", isError: false });
|
|
504
|
+
|
|
505
|
+
const ctx = { path, segments, params } as CommandContext<THandler>;
|
|
506
|
+
const result = await Promise.resolve(unstable_commandStore.run(ctx, Reflect.apply(ctx, handler, params)));
|
|
507
|
+
if (result instanceof Error || (typeof result === "object" && ((result as { error: unknown }).error instanceof Error || typeof (result as { error: unknown }).error === "string"))) {
|
|
508
|
+
setState({ status: "completed", isError: true });
|
|
509
|
+
return { error: result instanceof Error ? result : (result as { error: Error | string }).error };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
setState({ status: "completed", isError: false });
|
|
513
|
+
return { error: null }; `
|
|
514
|
+
})
|
|
515
|
+
];
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* A built-in module for handling application state utilities in Shell Shock.
|
|
519
|
+
*/
|
|
520
|
+
function StateBuiltin(props) {
|
|
521
|
+
const [{ children }, rest] = (0, _alloy_js_core.splitProps)(props, ["children"]);
|
|
522
|
+
return (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_builtin_file.BuiltinFile, (0, _alloy_js_core_jsx_runtime.mergeProps)({
|
|
523
|
+
id: "state",
|
|
524
|
+
description: "A module that provides context hooks and utilities for accessing the application state."
|
|
525
|
+
}, rest, {
|
|
526
|
+
get imports() {
|
|
527
|
+
return (0, defu.default)(rest.imports ?? {}, { "node:async_hooks": ["AsyncLocalStorage"] });
|
|
528
|
+
},
|
|
529
|
+
get children() {
|
|
530
|
+
return [
|
|
531
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(GlobalTypeDefinitions, {}),
|
|
532
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
533
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(ArgsUtilities, {}),
|
|
534
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
535
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(ContextUtilities, {}),
|
|
536
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
537
|
+
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
538
|
+
get when() {
|
|
539
|
+
return Boolean(children);
|
|
540
|
+
},
|
|
541
|
+
children
|
|
542
|
+
})
|
|
543
|
+
];
|
|
544
|
+
}
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
//#endregion
|
|
549
|
+
exports.ArgsUtilities = ArgsUtilities;
|
|
550
|
+
exports.ContextUtilities = ContextUtilities;
|
|
551
|
+
exports.GlobalTypeDefinitions = GlobalTypeDefinitions;
|
|
552
|
+
exports.StateBuiltin = StateBuiltin;
|
|
553
|
+
//# sourceMappingURL=state-builtin.cjs.map
|