@shell-shock/core 0.17.0 → 0.17.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/components/command-validation-logic.cjs +1 -1
- package/dist/components/command-validation-logic.cjs.map +1 -1
- package/dist/components/command-validation-logic.mjs +1 -1
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +38 -39
- package/dist/components/exec-builtin.cjs.map +1 -1
- package/dist/components/exec-builtin.mjs +38 -39
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/options-parser-logic.cjs +14 -6
- package/dist/components/options-parser-logic.cjs.map +1 -1
- package/dist/components/options-parser-logic.d.cts +2 -5
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +2 -5
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +14 -6
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +43 -8
- package/dist/components/state-builtin.cjs.map +1 -1
- package/dist/components/state-builtin.d.cts.map +1 -1
- package/dist/components/state-builtin.d.mts.map +1 -1
- package/dist/components/state-builtin.mjs +44 -9
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +10 -3
- package/dist/components/utils-builtin.cjs.map +1 -1
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +10 -3
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +1 -1
- package/dist/resolver/resolve.cjs.map +1 -1
- package/dist/resolver/resolve.mjs +1 -1
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/env.cjs +1 -1
- package/dist/types/env.cjs.map +1 -1
- package/dist/types/env.d.cts +7 -1
- package/dist/types/env.d.cts.map +1 -1
- package/dist/types/env.d.mts +7 -1
- package/dist/types/env.d.mts.map +1 -1
- package/dist/types/env.mjs +1 -1
- package/dist/types/env.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -95,7 +95,7 @@ function CommandValidationLogic(props) {
|
|
|
95
95
|
get children() {
|
|
96
96
|
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_core.Show, {
|
|
97
97
|
get when() {
|
|
98
|
-
return
|
|
98
|
+
return !option.variadic;
|
|
99
99
|
},
|
|
100
100
|
get fallback() {
|
|
101
101
|
return (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.ElseIfClause, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-validation-logic.cjs","names":[],"sources":["../../src/components/command-validation-logic.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, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { list } from \"@stryke/string-format/list\";\nimport type {\n CommandTree,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n {code`failures.push(\"Missing required ${option.name} option\");`}\n </IfStatement>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n option.name\n } array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === CommandParameterKinds.number}>\n <Show\n when={(option as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n option.name\n } option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n option.name\n } array option\");`}\n </IfStatement>\n </Show>\n </Show>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.choices &&\n option.choices.length > 0\n }>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }\n fallback={\n <ElseIfClause\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.every(value => [${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(value))`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as\n | StringCommandParameter\n | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n }>\n <ElseIfClause\n condition={code`![${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as StringCommandParameter | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <Spacing />\n <For each={command.args} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n <Show\n when={\n (argument.kind === CommandParameterKinds.string ||\n argument.kind === CommandParameterKinds.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n argument.name\n } array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === CommandParameterKinds.number}>\n <Show\n when={(argument as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n argument.name\n } positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n argument.name\n } array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;CAkCA,MAAO,EACL,YACF;;;GAEE,MAAA;GACE,MAAC;GACH,aAAA,mBAAA;GACF,CAAA;kDAAgB,OAAA,EAAA,CAAA;kDAA8B,oBAAA;GAC5C,IAAM,OAAE;;;GAGN,gBAAC;GACD,WAAG,WAAe;oDAAqB,qBAAC;KACtC,IAAI,OAAE;AACL,aAAQ,CAAC,OAAO;;KAEjB,IAAI,WAAC;AACH,aAAK,iDAAmB,kCAAS;OAC/B,IAAI,YAAC;AACH,eAAI,mBAAA,WAAiB,OAAQ,KAAA,SAAA,IAAA,GAAA,KAAA,OAAA,KAAA,MAAA,oDAAA,OAAA,KAAA;;OAE/B,IAAI,WAAW;AACb,eAAO,mBAAI,mCAA0B,OAAA,KAAA;;OAExC,CAAC,kDAAoB,qBAAM;OAC1B,IAAI,OAAE;AACJ,gBAAG,OAAA,SAAA,4CAAA,UAAA,OAAA,SAAA,4CAAA,WAAA,OAAA;;OAEL,IAAI,WAAW;AACb,+DAAwB,mCAAA;SACtB,IAAI,YAAO;AACT,iBAAC,mBAAA,UAAA,OAAA,KAAA,SAAA,IAAA,GAAA,KAAA,OAAA,KAAA,MAAA,oDAAA,OAAA,KAAA,GAAA;;SAEH,IAAI,WAAW;AACb,iBAAI,mBAAO,0DAAiB,OAAA,KAAA;;SAE/B,CAAC;;OAEL,CAAC,CAAC;;KAEN,CAAC;oDAAoB,qBAAM;KAC1B,IAAI,OAAO;AACT,aAAO,OAAK,SAAA,4CAAA;;KAEd,IAAI,WAAQ;AACV,6DAAO,qBAAA;OACL,IAAI,OAAO;AACT,eAAI,OAAS;;OAEf,IA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DAAwB,SAAA,KAAA;;QAEtC,CAAC;;MAEL,CAAC,CAAC;;IAEN,CAAC,kDAAgB,qBAAU;IAC1B,IAAI,OAAO;AACT,YAAO,SAAO,SAAW,4CAAU;;IAErC,IAAI,WAAW;AACb,4DAAoB,qBAAU;MAC5B,IAAI,OAAO;AACT,cAAM,SAAY;;MAEpB,IAAI,WAAI;AACN,8DAAA,kCAAA;QACH,IAAA,YAAA;AACE,gBAAA,mBAAA,mDAAA,SAAA,KAAA,CAAA,mEAAA,SAAA,KAAA,CAAA;;QAEA,IAAM,WAAY;AACpB,gBAAY,mBAAA,yDAAA,SAAA,KAAA;;QAER,CAAA;;MAEH,IAAI,WAAQ;AACV,8DAAe,kCAAA;QACb,IAAI,YAAG;AACL,gBAAA,mBAAW,mDAAA,SAAA,KAAA,CAAA;;QAEb,IAAE,WAAK;AACL,gBAAG,mBAAQ,wDAAwC,SAAA,KAAA;;QAEtD,CAAC;;MAEL,CAAC;;IAEL,CAAC,CAAC;GACJ,CAAC;EAAC"}
|
|
1
|
+
{"version":3,"file":"command-validation-logic.cjs","names":[],"sources":["../../src/components/command-validation-logic.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, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { list } from \"@stryke/string-format/list\";\nimport type {\n CommandTree,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n {code`failures.push(\"Missing required ${option.name} option\");`}\n </IfStatement>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n option.name\n } array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === CommandParameterKinds.number}>\n <Show\n when={(option as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n option.name\n } option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n option.name\n } array option\");`}\n </IfStatement>\n </Show>\n </Show>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.choices &&\n option.choices.length > 0\n }>\n <Show\n when={!option.variadic}\n fallback={\n <ElseIfClause\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.every(value => [${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(value))`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as\n | StringCommandParameter\n | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n }>\n <ElseIfClause\n condition={code`![${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as StringCommandParameter | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <Spacing />\n <For each={command.args} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n <Show\n when={\n (argument.kind === CommandParameterKinds.string ||\n argument.kind === CommandParameterKinds.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n argument.name\n } array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === CommandParameterKinds.number}>\n <Show\n when={(argument as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n argument.name\n } positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n argument.name\n } array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;CAkCA,MAAO,EACL,YACF;;;GAEE,MAAA;GACE,MAAC;GACH,aAAA,mBAAA;GACF,CAAA;kDAAgB,OAAA,EAAA,CAAA;kDAA8B,oBAAA;GAC5C,IAAM,OAAE;;;GAGN,gBAAC;GACD,WAAG,WAAe;oDAAqB,qBAAC;KACtC,IAAI,OAAE;AACL,aAAQ,CAAC,OAAO;;KAEjB,IAAI,WAAC;AACH,aAAK,iDAAmB,kCAAS;OAC/B,IAAI,YAAC;AACH,eAAI,mBAAA,WAAiB,OAAQ,KAAA,SAAA,IAAA,GAAA,KAAA,OAAA,KAAA,MAAA,oDAAA,OAAA,KAAA;;OAE/B,IAAI,WAAW;AACb,eAAO,mBAAI,mCAA0B,OAAA,KAAA;;OAExC,CAAC,kDAAoB,qBAAM;OAC1B,IAAI,OAAE;AACJ,gBAAG,OAAA,SAAA,4CAAA,UAAA,OAAA,SAAA,4CAAA,WAAA,OAAA;;OAEL,IAAI,WAAW;AACb,+DAAwB,mCAAA;SACtB,IAAI,YAAO;AACT,iBAAC,mBAAA,UAAA,OAAA,KAAA,SAAA,IAAA,GAAA,KAAA,OAAA,KAAA,MAAA,oDAAA,OAAA,KAAA,GAAA;;SAEH,IAAI,WAAW;AACb,iBAAI,mBAAO,0DAAiB,O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AA,4CAAA,WAAA,SAAA;;MAEV,IAAI,WAAM;AACR,8DAAwB,mCAAO;QAC7B,IAAI,YAAU;AACZ,gBAAM,mBAAA,mDAAA,SAAA,KAAA,CAAA;;QAER,IAAI,WAAS;AACX,gBAAI,mBAAO,0DAA8B,SAAA,KAAA;;QAE5C,CAAC;;MAEL,CAAC,CAAC;;IAEN,CAAC,kDAAoB,qBAAG;IACvB,IAAI,OAAO;AACT,YAAO,SAAS,SAAC,4CAAA;;IAEnB,IAAI,WAAU;AACZ,4DAAU,qBAAA;MACR,IAAE,OAAA;AACH,cAAA,SAAA;;MAEF,IAAO,WAAE;AACL,8DAAoB,kCAAc;QACpC,IAAS,YAAG;AACV,gBAAA,mBAAA,mDAAA,SAAA,KAAA,CAAA,mEAAA,SAAA,KAAA,CAAA;;QAEG,IAAC,WAAY;AACX,gBAAM,mBAAA,yDAAoC,SAAA,KAAA;;QAE7C,CAAC;;MAEJ,IAAI,WAAC;AACH,8DAAS,kCAAA;QACP,IAAI,YAAU;AACZ,gBAAI,mBAAA,mDAAkB,SAAA,KAAA,CAAA;;QAExB,IAAG,WAAA;AACD,gBAAC,mBAAA,wDAAA,SAAA,KAAA;;QAEJ,CAAC;;MAEL,CAAC;;IAEL,CAAC,CAAC;GACJ,CAAC;EAAC"}
|
|
@@ -93,7 +93,7 @@ function CommandValidationLogic(props) {
|
|
|
93
93
|
get children() {
|
|
94
94
|
return createComponent(Show, {
|
|
95
95
|
get when() {
|
|
96
|
-
return
|
|
96
|
+
return !option.variadic;
|
|
97
97
|
},
|
|
98
98
|
get fallback() {
|
|
99
99
|
return createComponent(ElseIfClause, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-validation-logic.mjs","names":[],"sources":["../../src/components/command-validation-logic.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, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { list } from \"@stryke/string-format/list\";\nimport type {\n CommandTree,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n {code`failures.push(\"Missing required ${option.name} option\");`}\n </IfStatement>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n option.name\n } array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === CommandParameterKinds.number}>\n <Show\n when={(option as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n option.name\n } option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n option.name\n } array option\");`}\n </IfStatement>\n </Show>\n </Show>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.choices &&\n option.choices.length > 0\n }>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }\n fallback={\n <ElseIfClause\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.every(value => [${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(value))`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as\n | StringCommandParameter\n | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n }>\n <ElseIfClause\n condition={code`![${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as StringCommandParameter | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <Spacing />\n <For each={command.args} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n <Show\n when={\n (argument.kind === CommandParameterKinds.string ||\n argument.kind === CommandParameterKinds.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n argument.name\n } array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === CommandParameterKinds.number}>\n <Show\n when={(argument as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n argument.name\n } positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n argument.name\n } array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;CAkCA,MAAO,EACL,YACF;;;GAEE,MAAA;GACE,MAAC;GACH,aAAA,IAAA;GACF,CAAA;EAAM,gBAAU,OAAA,EAAA,CAAA;EAAA,gBAA8B,KAAA;GAC5C,IAAM,OAAE;;;GAGN,gBAAC;GACD,WAAG,WAAe;IAAA,gBAAqB,MAAC;KACtC,IAAI,OAAE;AACL,aAAQ,CAAC,OAAO;;KAEjB,IAAI,WAAC;AACH,aAAK,CAAA,gBAAmB,aAAS;OAC/B,IAAI,YAAC;AACH,eAAI,IAAA,WA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Q;AACV,cAAM,gBAAS,aAAA;QACb,IAAI,YAAG;AACL,gBAAA,IAAW,GAAA,UAAA,SAAA,KAAA,CAAA;;QAEb,IAAE,WAAK;AACL,gBAAG,IAAQ,wDAAwC,SAAA,KAAA;;QAEtD,CAAC;;MAEL,CAAC;;IAEL,CAAC,CAAC;GACJ,CAAC;EAAC"}
|
|
1
|
+
{"version":3,"file":"command-validation-logic.mjs","names":[],"sources":["../../src/components/command-validation-logic.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, For, Show } from \"@alloy-js/core\";\nimport {\n ElseIfClause,\n IfStatement,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { camelCase } from \"@stryke/string-format/camel-case\";\nimport { list } from \"@stryke/string-format/list\";\nimport type {\n CommandTree,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\n\nexport interface CommandValidationLogicProps {\n command: CommandTree;\n}\n\n/**\n * A component that generates command validation logic for required options and arguments.\n */\nexport function CommandValidationLogic(props: CommandValidationLogicProps) {\n const { command } = props;\n\n return (\n <>\n <VarDeclaration name=\"failures\" type=\"string[]\" initializer={code`[];`} />\n <hbr />\n <For each={Object.values(command.options ?? {})} doubleHardline>\n {option => (\n <>\n <Show when={!option.optional}>\n <IfStatement\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }`}>\n {code`failures.push(\"Missing required ${option.name} option\");`}\n </IfStatement>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.variadic\n }>\n <ElseIfClause\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n option.name\n } array option\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={option.kind === CommandParameterKinds.number}>\n <Show\n when={(option as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n } && Number.isNaN(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n option.name\n } option\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n option.name\n } array option\");`}\n </IfStatement>\n </Show>\n </Show>\n <Show\n when={\n (option.kind === CommandParameterKinds.string ||\n option.kind === CommandParameterKinds.number) &&\n option.choices &&\n option.choices.length > 0\n }>\n <Show\n when={!option.variadic}\n fallback={\n <ElseIfClause\n condition={code`!options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }.every(value => [${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(value))`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as\n | StringCommandParameter\n | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n }>\n <ElseIfClause\n condition={code`![${(\n option as StringCommandParameter | NumberCommandParameter\n ).choices\n ?.map(choice =>\n option.kind === CommandParameterKinds.string\n ? `\"${choice}\"`\n : choice\n )\n .join(\", \")}].includes(options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n })`}>\n {code`failures.push(\\`Invalid value provided for the ${\n option.name\n } option - valid values include: ${list(\n (\n option as StringCommandParameter | NumberCommandParameter\n )?.choices?.map(choice => String(choice)) ?? []\n )}; provided: \\${options${\n option.name.includes(\"?\")\n ? `[\"${option.name}\"]`\n : `.${camelCase(option.name)}`\n }}\\`);`}\n </ElseIfClause>\n </Show>\n </Show>\n </>\n )}\n </For>\n <Spacing />\n <For each={command.args} doubleHardline>\n {argument => (\n <>\n <Show when={!argument.optional}>\n <IfStatement condition={code`!${camelCase(argument.name)}`}>\n {code`failures.push(\"Missing required \\\\\"${\n argument.name\n }\\\\\" positional argument\");`}\n </IfStatement>\n <Show\n when={\n (argument.kind === CommandParameterKinds.string ||\n argument.kind === CommandParameterKinds.number) &&\n argument.variadic\n }>\n <ElseIfClause\n condition={code`${camelCase(argument.name)}.length === 0`}>\n {code`failures.push(\"No values were provided to the required ${\n argument.name\n } array positional argument\");`}\n </ElseIfClause>\n </Show>\n </Show>\n <Show when={argument.kind === CommandParameterKinds.number}>\n <Show\n when={(argument as NumberCommandParameter).variadic}\n fallback={\n <IfStatement\n condition={code`${camelCase(\n argument.name\n )} && Number.isNaN(${camelCase(argument.name)})`}>\n {code`failures.push(\"Invalid numeric value provided for the ${\n argument.name\n } positional argument\");`}\n </IfStatement>\n }>\n <IfStatement\n condition={code`${camelCase(argument.name)}.some(value => Number.isNaN(value))`}>\n {code`failures.push(\"Invalid numeric value provided in the ${\n argument.name\n } array positional argument\");`}\n </IfStatement>\n </Show>\n </Show>\n </>\n )}\n </For>\n </>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,SAAS,SAAC,sBAAA;;IAEnB,IAAI,WAAU;AACZ,YAAM,gBAAI,MAAA;MACR,IAAE,OAAA;AACH,cAAA,SAAA;;MAEF,IAAO,WAAE;AACL,cAAM,gBAAc,aAAc;QACpC,IAAS,YAAG;AACV,gBAAA,IAAA,GAAA,UAAA,SAAA,KAAA,CAAA,mBAAA,UAAA,SAAA,KAAA,CAAA;;QAEG,IAAC,WAAY;AACX,gBAAM,IAAA,yDAAoC,SAAA,KAAA;;QAE7C,CAAC;;MAEJ,IAAI,WAAC;AACH,cAAI,gBAAK,aAAA;QACP,IAAI,YAAU;AACZ,gBAAI,IAAA,GAAS,UAAS,SAAA,KAAA,CAAA;;QAExB,IAAG,WAAA;AACD,gBAAC,IAAA,wDAAA,SAAA,KAAA;;QAEJ,CAAC;;MAEL,CAAC;;IAEL,CAAC,CAAC;GACJ,CAAC;EAAC"}
|
|
@@ -41,7 +41,14 @@ function ExecBuiltin(props) {
|
|
|
41
41
|
});
|
|
42
42
|
},
|
|
43
43
|
get builtinImports() {
|
|
44
|
-
return (0, defu.default)(rest.builtinImports ?? {}, { env: [
|
|
44
|
+
return (0, defu.default)(rest.builtinImports ?? {}, { env: [
|
|
45
|
+
"isWindows",
|
|
46
|
+
"env",
|
|
47
|
+
{
|
|
48
|
+
name: "Env",
|
|
49
|
+
type: true
|
|
50
|
+
}
|
|
51
|
+
] });
|
|
45
52
|
},
|
|
46
53
|
get children() {
|
|
47
54
|
return [
|
|
@@ -49,11 +56,10 @@ function ExecBuiltin(props) {
|
|
|
49
56
|
name: "resolveCommandEnv",
|
|
50
57
|
parameters: [{
|
|
51
58
|
name: "params",
|
|
52
|
-
type: "{ argv: string[]; env?: NodeJS.ProcessEnv;
|
|
59
|
+
type: "{ argv: string[]; env?: NodeJS.ProcessEnv; }"
|
|
53
60
|
}],
|
|
54
61
|
returnType: "NodeJS.ProcessEnv",
|
|
55
|
-
children: _alloy_js_core.code`const
|
|
56
|
-
const argv = params.argv;
|
|
62
|
+
children: _alloy_js_core.code`const argv = params.argv;
|
|
57
63
|
const shouldSuppressNpmFund = (() => {
|
|
58
64
|
const cmd = basename(argv[0] ?? "");
|
|
59
65
|
if (cmd === "npm" || cmd === "npm.cmd" || cmd === "npm.exe") {
|
|
@@ -67,17 +73,19 @@ const shouldSuppressNpmFund = (() => {
|
|
|
67
73
|
return false;
|
|
68
74
|
})();
|
|
69
75
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
const result = Object.fromEntries(
|
|
77
|
+
Object.entries({
|
|
78
|
+
...env,
|
|
79
|
+
...(params.env ?? {})
|
|
80
|
+
})
|
|
81
|
+
.filter(([, value]) => value !== undefined)
|
|
82
|
+
.map(([key, value]) => [key, String(value)])
|
|
75
83
|
);
|
|
76
84
|
if (shouldSuppressNpmFund) {
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
result.NPM_CONFIG_FUND ??= "false";
|
|
86
|
+
result.npm_config_fund ??= "false";
|
|
79
87
|
}
|
|
80
|
-
return
|
|
88
|
+
return result; `
|
|
81
89
|
}),
|
|
82
90
|
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
83
91
|
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
|
|
@@ -311,6 +319,7 @@ return false;`
|
|
|
311
319
|
}),
|
|
312
320
|
(0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.InterfaceMember, {
|
|
313
321
|
name: "timeoutMs",
|
|
322
|
+
optional: true,
|
|
314
323
|
type: "number"
|
|
315
324
|
}),
|
|
316
325
|
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
@@ -397,43 +406,40 @@ return false;`
|
|
|
397
406
|
typeof optionsOrTimeoutMs === "number"
|
|
398
407
|
? { timeoutMs: optionsOrTimeoutMs }
|
|
399
408
|
: optionsOrTimeoutMs;
|
|
400
|
-
const { timeoutMs, cwd, input,
|
|
401
|
-
const hasInput = input !== undefined;
|
|
402
|
-
const resolvedEnv = resolveCommandEnv({ argv, env });
|
|
403
|
-
const stdio = resolveCommandStdio({ hasInput, preferInherit: true });
|
|
409
|
+
const { timeoutMs = 300000, cwd, input, noOutputTimeoutMs } = options;
|
|
404
410
|
|
|
405
|
-
const
|
|
411
|
+
const resolvedArgv =
|
|
406
412
|
isWindows
|
|
407
413
|
? (resolveNpmArgvForWindows(argv) ?? argv)
|
|
408
414
|
: argv;
|
|
409
415
|
const resolvedCommand =
|
|
410
|
-
|
|
411
|
-
? (
|
|
416
|
+
resolvedArgv !== argv
|
|
417
|
+
? (resolvedArgv[0] ?? "")
|
|
412
418
|
: resolveCommand(argv[0] ?? "");
|
|
413
419
|
const useCmdWrapper = isWindowsBatchCommand(resolvedCommand);
|
|
414
420
|
|
|
415
421
|
const child = _spawn(
|
|
416
422
|
useCmdWrapper
|
|
417
|
-
? (
|
|
423
|
+
? (env.COMSPEC ?? "cmd.exe")
|
|
418
424
|
: resolvedCommand,
|
|
419
425
|
useCmdWrapper
|
|
420
426
|
? [
|
|
421
427
|
"/d",
|
|
422
428
|
"/s",
|
|
423
429
|
"/c",
|
|
424
|
-
buildCmdExeCommandLine(resolvedCommand,
|
|
430
|
+
buildCmdExeCommandLine(resolvedCommand, resolvedArgv.slice(1))
|
|
425
431
|
]
|
|
426
|
-
:
|
|
427
|
-
stdio,
|
|
432
|
+
: resolvedArgv.slice(1), {
|
|
433
|
+
stdio: resolveCommandStdio({ hasInput: input !== undefined, preferInherit: true }),
|
|
428
434
|
cwd,
|
|
429
|
-
env:
|
|
435
|
+
env: resolveCommandEnv({ argv, env: options.env }),
|
|
430
436
|
windowsHide: true,
|
|
431
437
|
windowsVerbatimArguments: useCmdWrapper
|
|
432
438
|
? true
|
|
433
439
|
: options.windowsVerbatimArguments,
|
|
434
440
|
...(shouldSpawnWithShell({
|
|
435
441
|
resolvedCommand: useCmdWrapper
|
|
436
|
-
? (
|
|
442
|
+
? (env.COMSPEC ?? "cmd.exe")
|
|
437
443
|
: resolvedCommand,
|
|
438
444
|
platform: process.platform
|
|
439
445
|
})
|
|
@@ -503,7 +509,7 @@ return new Promise((resolve, reject) => {
|
|
|
503
509
|
}, timeoutMs >= 0 ? timeoutMs : Number.POSITIVE_INFINITY);
|
|
504
510
|
armNoOutputTimer();
|
|
505
511
|
|
|
506
|
-
if (
|
|
512
|
+
if (input !== undefined && child.stdin) {
|
|
507
513
|
child.stdin.write(input ?? "");
|
|
508
514
|
child.stdin.end();
|
|
509
515
|
}
|
|
@@ -556,7 +562,7 @@ return new Promise((resolve, reject) => {
|
|
|
556
562
|
explicitCode: childExitState?.code ?? code,
|
|
557
563
|
childExitCode: child.exitCode,
|
|
558
564
|
resolvedSignal,
|
|
559
|
-
usesWindowsExitCodeShim: isWindows && (useCmdWrapper ||
|
|
565
|
+
usesWindowsExitCodeShim: isWindows && (useCmdWrapper || resolvedArgv !== argv),
|
|
560
566
|
timedOut,
|
|
561
567
|
noOutputTimedOut,
|
|
562
568
|
killIssuedByTimeout
|
|
@@ -686,23 +692,16 @@ return new Promise((resolve, reject) => {
|
|
|
686
692
|
}, {
|
|
687
693
|
name: "options",
|
|
688
694
|
type: "SpawnOptions",
|
|
689
|
-
|
|
695
|
+
default: "{}"
|
|
690
696
|
}],
|
|
691
697
|
returnType: "string",
|
|
692
698
|
children: _alloy_js_core.code`return execFileSync(argv.length > 0 ? argv[0] : "", argv.slice(1), {
|
|
693
699
|
encoding: "utf8",
|
|
694
700
|
stdio: ["ignore", "pipe", "ignore"],
|
|
695
|
-
timeout: options
|
|
696
|
-
env:
|
|
697
|
-
cwd: options
|
|
698
|
-
windowsHide: true
|
|
699
|
-
windowsVerbatimArguments: options?.windowsVerbatimArguments,
|
|
700
|
-
...(shouldSpawnWithShell({
|
|
701
|
-
resolvedCommand: argv[0] ?? "",
|
|
702
|
-
platform: process.platform
|
|
703
|
-
})
|
|
704
|
-
? { shell: true }
|
|
705
|
-
: {})
|
|
701
|
+
timeout: options.timeoutMs ?? 300000,
|
|
702
|
+
env: resolveCommandEnv({ argv, env: options.env }),
|
|
703
|
+
cwd: options.cwd || process.cwd(),
|
|
704
|
+
windowsHide: true
|
|
706
705
|
}).trim(); `
|
|
707
706
|
}),
|
|
708
707
|
(0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec-builtin.cjs","names":[],"sources":["../../src/components/exec-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 ExecBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * A built-in module for handling command execution in Shell Shock.\n */\nexport function ExecBuiltin(props: ExecBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"exec\"\n description=\"A module to handle command execution in a Shell Shock application.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:path\": [\"basename\", \"extname\", \"dirname\", \"join\"],\n \"node:fs\": [\"existsSync\"],\n \"node:child_process\": [\n { name: \"spawn\", alias: \"_spawn\" },\n \"execFileSync\"\n ],\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=\"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 });\n\nconst finalArgv =\n isWindows\n ? (resolveNpmArgvForWindows(argv) ?? argv)\n : argv;\nconst resolvedCommand =\n finalArgv !== argv\n ? (finalArgv[0] ?? \"\")\n : resolveCommand(argv[0] ?? \"\");\nconst useCmdWrapper = isWindowsBatchCommand(resolvedCommand);\n\nconst child = _spawn(\n useCmdWrapper\n ? (process.env.ComSpec ?? \"cmd.exe\")\n : resolvedCommand,\n useCmdWrapper\n ? [\n \"/d\",\n \"/s\",\n \"/c\",\n buildCmdExeCommandLine(resolvedCommand, finalArgv.slice(1))\n ]\n : finalArgv.slice(1), {\n stdio,\n cwd,\n env: resolvedEnv,\n windowsHide: true,\n windowsVerbatimArguments: useCmdWrapper\n ? true\n : options.windowsVerbatimArguments,\n ...(shouldSpawnWithShell({\n resolvedCommand: useCmdWrapper\n ? (process.env.ComSpec ?? \"cmd.exe\")\n : resolvedCommand,\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: isWindows && (useCmdWrapper || finalArgv !== argv),\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 <TSDoc heading=\"A helper function that executes a command and returns its stdout.\">\n <TSDocParam name=\"argv\">\n {`The command and its arguments to spawn. This is passed directly to the spawn function. Remember that on Windows, commands like \\`npm\\` or \\`pnpm\\` will be resolved to their .cmd shims, so you can just pass \\`npm\\` without worrying about the extension.`}\n </TSDocParam>\n <TSDocParam name=\"optionsOrTimeoutMs\">\n {`The options for spawning the command, or a number representing the timeout in milliseconds. This is passed directly to the spawn function. 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 if the command exits with code 0, or rejects with an error if the command exits with a non-zero code or if there is a problem spawning the process.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"exec\"\n parameters={[\n { name: \"argv\", type: \"string[]\" },\n {\n name: \"optionsOrTimeoutMs\",\n type: \"number | SpawnOptions\",\n default: \"300000\"\n }\n ]}\n returnType=\"Promise<string>\">\n {code`const spawnResult = await spawn(argv, optionsOrTimeoutMs);\n if (spawnResult.code !== 0) {\n throw Object.assign(new Error(\n \\`Command \"\\${argv.join(\" \")}\" exited with code \\${spawnResult.code} and signal \\${spawnResult.signal}\\`\n ), spawnResult);\n }\n\n return spawnResult.stdout.trim(); `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A helper function that executes a command synchronously and returns its stdout. This is a thin wrapper around \\`child_process.execFileSync\\` with some added Windows compatibility handling.\">\n <TSDocParam name=\"argv\">\n {`The command and its arguments to spawn. This is passed directly to \\`execFileSync\\` after Windows-specific resolution. Remember that on Windows, commands like \\`npm\\` or \\`pnpm\\` will be resolved to their .cmd shims, so you can just pass \\`npm\\` without worrying about the extension.`}\n </TSDocParam>\n <TSDocParam name=\"options\">\n {`The options for spawning the command. This is passed directly to \\`execFileSync\\` after some processing. The timeout option is supported, but note that it will throw an error if the process runs longer than the specified timeout. If no options are provided, a default timeout of 5 minutes will be used.`}\n </TSDocParam>\n <TSDocReturns>\n {\n \"The standard output produced by the command if it exits with code 0. If the command exits with a non-zero code or if there is a problem spawning the process, an error will be thrown.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"execSync\"\n parameters={[\n { name: \"argv\", type: \"string[]\" },\n { name: \"options\", type: \"SpawnOptions\", optional: true }\n ]}\n returnType=\"string\">\n {code`return execFileSync(argv.length > 0 ? argv[0] : \"\", argv.slice(1), {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n timeout: options?.timeoutMs ?? 300000,\n env: options?.env ? resolveCommandEnv({ argv, env: options.env }) : process.env,\n cwd: options?.cwd,\n windowsHide: true,\n windowsVerbatimArguments: options?.windowsVerbatimArguments,\n ...(shouldSpawnWithShell({\n resolvedCommand: argv[0] ?? \"\",\n platform: process.platform\n })\n ? { shell: true }\n : {})\n }).trim(); `}\n </FunctionDeclaration>\n <Spacing />\n\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAE,YAAiB,OAAA;CACjB,MAAA,CAAA,EACA,YACA,uCAAkB,OAAO,CAAK,WAAW,CAAC;AAC5C,wDAAuB,oHAAA;;EAEvB,aAAiB;EACf,EAAA,MAAA;EACC,IAAK,UAAE;AACP,4BAAA,KAAA,WAAA,EAAA,EAAA;;;;;;;IAED,WAAA,CAAA,aAAA;IACG,sBAAoB,CAAA;KACvB,MAAA;KACK,OAAS;KACP,EAAE,eAAY;;KAEd,MAAA;KACJ,SAAA;KACK,MAAI;KACR,CAAA;IACC,CAAC;;EAEJ,IAAI,iBAAe;AACjB,4BAAY,KAAG,kBAAY,EAAA,EAAA,EACzB,KAAK,CAAC,YAAA,EACP,CAAC;;EAEJ,IAAI,WAAC;AACH,UAAO;oDAAmB,0CAAmB;KAC3C,MAAA;KACF,YAAc,CAAC;MACb,MAAO;MACN,MAAA;MACF,CAAA;KACC,YAAM;KACN,UAAU,mBAAE;;;;;;;;;;;;;;;;;;;;;;;;;;KA0Bf,CAAG;oDAAoB,0DAAK,EAAM,CAAC;oDAAO,0CAAA;KAC9C,MAAA;KACG,YAAA,CAAA;MACF,MAAY;MACZ,MAAY;MACd,CAAA;KACO,YAAa;KACZ,UAAA,mBAAA;;;;;;KAMD,CAAC;oDAAoB,0DAAE,EAAA,CAAA;oDAAA,0CAAA;KACtB,MAAM;KACd,YAAA,CAAA;MACU,MAAE;;MAEL,CAAG;KACF,YAAA;KACD,UAAS,mBAAA;;;;;;;;;;KAUhB,CAAA;oDAAA,0DAAA,EAAA,CAAA;oDAAA,0CAAA;KACQ,MAAC;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmOZ,CAAC;oDAAE,0DAAA,EAAA,CAAA;oDAAA,4DAAA;KACF,SAAS;KACT,IAAI,WAAO;AACT,aAAE;uDAAgB,iEAAA;QAClB,MAAA;QACD,UAAA;QACD,CAAA;uDAAoB,iEAAQ;QAC3B,MAAK;QACF,UAAE;QACH,CAAC;uDAAoB,mEAAS,EAC7B,UAAI,sNACL,CAAC;OAAC;;;;KAGL,UAAS;KACT,OAAA;KACD,MAAO;KACP,YAAa,CAAC;MACZ,MAAA;MACC,MAAM;MACP,EAAC;MACD,MAAA;MACC,MAAM;MACN,SAAA;MACD,CAAA;KACD,YAAE;KACF,UAAS,mBAAA;;;;;;;;KAQV,CAAC;oDAAkB,0DAAO,EAAM,CAAC;oDAAI,4DAAA;KACpC,SAAS;KACT,IAAC,WAAA;AACD,aAAA;uDAAmB,iEAAA;QAClB,MAAK;QACJ,UAAW;QACX,CAAA;uDAAmB,iEAAe;QAClC,MAAQ;QACR,UAAY;QACZ,CAAA;uDAAiB,mEAAA,EACjB,UAAY,0LACZ,CAAA;OAAA;;KAEH,CAAC;oDAAoB,0CAAc;KAClC,UAAI;KACJ,MAAG;KACH,YAAQ,CAAK;MACX,MAAM;MACN,MAAM;MACR,EAAA;MACD,MAAS;;MAET,UAAW;MACZ,CAAA;KACH,YAAA;KACH,UAAA,mBAAA"}
|
|
1
|
+
{"version":3,"file":"exec-builtin.cjs","names":[],"sources":["../../src/components/exec-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 ExecBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * A built-in module for handling command execution in Shell Shock.\n */\nexport function ExecBuiltin(props: ExecBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"exec\"\n description=\"A module to handle command execution in a Shell Shock application.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:path\": [\"basename\", \"extname\", \"dirname\", \"join\"],\n \"node:fs\": [\"existsSync\"],\n \"node:child_process\": [\n { name: \"spawn\", alias: \"_spawn\" },\n \"execFileSync\"\n ],\n \"node:stream\": [{ name: \"Stream\", default: true, type: true }]\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n env: [\"isWindows\", \"env\", { name: \"Env\", type: true }]\n })}>\n <FunctionDeclaration\n name=\"resolveCommandEnv\"\n parameters={[\n {\n name: \"params\",\n type: \"{ argv: string[]; env?: NodeJS.ProcessEnv; }\"\n }\n ]}\n returnType=\"NodeJS.ProcessEnv\">\n {code`const 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 result = Object.fromEntries(\n Object.entries({\n ...env,\n ...(params.env ?? {})\n})\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [key, String(value)])\n);\nif (shouldSuppressNpmFund) {\n result.NPM_CONFIG_FUND ??= \"false\";\n result.npm_config_fund ??= \"false\";\n}\nreturn result; `}\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=\"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\" optional 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 = 300000, cwd, input, noOutputTimeoutMs } = options;\n\nconst resolvedArgv =\n isWindows\n ? (resolveNpmArgvForWindows(argv) ?? argv)\n : argv;\nconst resolvedCommand =\n resolvedArgv !== argv\n ? (resolvedArgv[0] ?? \"\")\n : resolveCommand(argv[0] ?? \"\");\nconst useCmdWrapper = isWindowsBatchCommand(resolvedCommand);\n\nconst child = _spawn(\n useCmdWrapper\n ? (env.COMSPEC ?? \"cmd.exe\")\n : resolvedCommand,\n useCmdWrapper\n ? [\n \"/d\",\n \"/s\",\n \"/c\",\n buildCmdExeCommandLine(resolvedCommand, resolvedArgv.slice(1))\n ]\n : resolvedArgv.slice(1), {\n stdio: resolveCommandStdio({ hasInput: input !== undefined, preferInherit: true }),\n cwd,\n env: resolveCommandEnv({ argv, env: options.env }),\n windowsHide: true,\n windowsVerbatimArguments: useCmdWrapper\n ? true\n : options.windowsVerbatimArguments,\n ...(shouldSpawnWithShell({\n resolvedCommand: useCmdWrapper\n ? (env.COMSPEC ?? \"cmd.exe\")\n : resolvedCommand,\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 (input !== undefined && 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: isWindows && (useCmdWrapper || resolvedArgv !== argv),\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 <TSDoc heading=\"A helper function that executes a command and returns its stdout.\">\n <TSDocParam name=\"argv\">\n {`The command and its arguments to spawn. This is passed directly to the spawn function. Remember that on Windows, commands like \\`npm\\` or \\`pnpm\\` will be resolved to their .cmd shims, so you can just pass \\`npm\\` without worrying about the extension.`}\n </TSDocParam>\n <TSDocParam name=\"optionsOrTimeoutMs\">\n {`The options for spawning the command, or a number representing the timeout in milliseconds. This is passed directly to the spawn function. 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 if the command exits with code 0, or rejects with an error if the command exits with a non-zero code or if there is a problem spawning the process.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"exec\"\n parameters={[\n { name: \"argv\", type: \"string[]\" },\n {\n name: \"optionsOrTimeoutMs\",\n type: \"number | SpawnOptions\",\n default: \"300000\"\n }\n ]}\n returnType=\"Promise<string>\">\n {code`const spawnResult = await spawn(argv, optionsOrTimeoutMs);\n if (spawnResult.code !== 0) {\n throw Object.assign(new Error(\n \\`Command \"\\${argv.join(\" \")}\" exited with code \\${spawnResult.code} and signal \\${spawnResult.signal}\\`\n ), spawnResult);\n }\n\n return spawnResult.stdout.trim(); `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A helper function that executes a command synchronously and returns its stdout. This is a thin wrapper around \\`child_process.execFileSync\\` with some added Windows compatibility handling.\">\n <TSDocParam name=\"argv\">\n {`The command and its arguments to spawn. This is passed directly to \\`execFileSync\\` after Windows-specific resolution. Remember that on Windows, commands like \\`npm\\` or \\`pnpm\\` will be resolved to their .cmd shims, so you can just pass \\`npm\\` without worrying about the extension.`}\n </TSDocParam>\n <TSDocParam name=\"options\">\n {`The options for spawning the command. This is passed directly to \\`execFileSync\\` after some processing. The timeout option is supported, but note that it will throw an error if the process runs longer than the specified timeout. If no options are provided, a default timeout of 5 minutes will be used.`}\n </TSDocParam>\n <TSDocReturns>\n {\n \"The standard output produced by the command if it exits with code 0. If the command exits with a non-zero code or if there is a problem spawning the process, an error will be thrown.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"execSync\"\n parameters={[\n { name: \"argv\", type: \"string[]\" },\n { name: \"options\", type: \"SpawnOptions\", default: \"{}\" }\n ]}\n returnType=\"string\">\n {code`return execFileSync(argv.length > 0 ? argv[0] : \"\", argv.slice(1), {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n timeout: options.timeoutMs ?? 300000,\n env: resolveCommandEnv({ argv, env: options.env }),\n cwd: options.cwd || process.cwd(),\n windowsHide: true\n }).trim(); `}\n </FunctionDeclaration>\n <Spacing />\n\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgCA,SAAE,YAAiB,OAAA;CACjB,MAAA,CAAA,EACA,YACA,uCAAkB,OAAO,CAAK,WAAW,CAAC;AAC5C,wDAAuB,oHAAA;;EAEvB,aAAiB;EACf,EAAA,MAAA;EACC,IAAK,UAAE;AACP,4BAAA,KAAA,WAAA,EAAA,EAAA;;;;;;;IAED,WAAA,CAAA,aAAA;IACG,sBAAoB,CAAA;KACvB,MAAA;KACK,OAAS;KACP,EAAE,eAAY;;KAEd,MAAA;KACJ,SAAA;KACK,MAAI;KACR,CAAA;IACC,CAAC;;EAEJ,IAAI,iBAAe;AACjB,4BAAY,KAAG,kBAAY,EAAA,EAAA,EACzB,KAAK;IAAC;IAAa;IAAG;KACpB,MAAM;KACN,MAAC;KACF;IAAA,EACF,CAAC;;EAEJ,IAAE,WAAA;AACA,UAAO;oDAAmB,0CAAqB;KAC7C,MAAC;KACF,YAAA,CAAA;MACC,MAAM;MACN,MAAA;MACC,CA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