@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
|
@@ -3,7 +3,7 @@ import defu$1 from "defu";
|
|
|
3
3
|
import { Show, code, splitProps } from "@alloy-js/core";
|
|
4
4
|
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
5
5
|
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
|
|
6
|
-
import { FunctionDeclaration, InterfaceDeclaration, InterfaceMember,
|
|
6
|
+
import { FunctionDeclaration, InterfaceDeclaration, InterfaceMember, VarDeclaration } from "@alloy-js/typescript";
|
|
7
7
|
import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
|
|
8
8
|
import { TSDoc, TSDocInternal, TSDocLink, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
9
9
|
|
|
@@ -542,407 +542,6 @@ function HyperlinkSupportUtilities() {
|
|
|
542
542
|
];
|
|
543
543
|
}
|
|
544
544
|
/**
|
|
545
|
-
* Generates utilities for detecting terminal color support.
|
|
546
|
-
*/
|
|
547
|
-
function ArgsUtilities() {
|
|
548
|
-
return [
|
|
549
|
-
createComponent(TSDoc, {
|
|
550
|
-
heading: "Retrieves the command-line arguments from Deno or Node.js environments.",
|
|
551
|
-
get children() {
|
|
552
|
-
return [
|
|
553
|
-
createComponent(TSDocRemarks, { children: "This function is only intended for internal use. Please use `useArgs()` instead." }),
|
|
554
|
-
createComponent(Spacing, {}),
|
|
555
|
-
createComponent(TSDocInternal, {}),
|
|
556
|
-
createComponent(Spacing, {}),
|
|
557
|
-
createComponent(TSDocReturns, { children: "An array of command-line arguments from Deno or Node.js environments." })
|
|
558
|
-
];
|
|
559
|
-
}
|
|
560
|
-
}),
|
|
561
|
-
createComponent(FunctionDeclaration, {
|
|
562
|
-
"export": true,
|
|
563
|
-
name: "getArgs",
|
|
564
|
-
returnType: "string[]",
|
|
565
|
-
children: code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`
|
|
566
|
-
}),
|
|
567
|
-
createComponent(Spacing, {}),
|
|
568
|
-
createComponent(TSDoc, {
|
|
569
|
-
heading: "Checks if a specific flag is present in the command-line arguments.",
|
|
570
|
-
get children() {
|
|
571
|
-
return [
|
|
572
|
-
createComponent(TSDocLink, { children: "https://github.com/sindresorhus/has-flag/blob/main/index.js" }),
|
|
573
|
-
createComponent(TSDocParam, {
|
|
574
|
-
name: "flag",
|
|
575
|
-
children: "The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\"."
|
|
576
|
-
}),
|
|
577
|
-
createComponent(TSDocParam, {
|
|
578
|
-
name: "argv",
|
|
579
|
-
children: "The command-line arguments to check against. Defaults to global Deno args or process args."
|
|
580
|
-
}),
|
|
581
|
-
createComponent(TSDocReturns, { children: "True if the flag is present, false otherwise." })
|
|
582
|
-
];
|
|
583
|
-
}
|
|
584
|
-
}),
|
|
585
|
-
createComponent(FunctionDeclaration, {
|
|
586
|
-
"export": true,
|
|
587
|
-
name: "hasFlag",
|
|
588
|
-
parameters: [{
|
|
589
|
-
name: "flag",
|
|
590
|
-
type: "string | string[]"
|
|
591
|
-
}, {
|
|
592
|
-
name: "argv",
|
|
593
|
-
type: "string[]",
|
|
594
|
-
default: "useArgs()"
|
|
595
|
-
}],
|
|
596
|
-
get children() {
|
|
597
|
-
return [
|
|
598
|
-
createComponent(VarDeclaration, {
|
|
599
|
-
"const": true,
|
|
600
|
-
name: "position",
|
|
601
|
-
type: "number",
|
|
602
|
-
initializer: code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {
|
|
603
|
-
const pos = argv.findIndex(arg => (f.startsWith("-") ? "" : (f.length === 1 ? "-" : "--") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? "-" : "--") + f + "="));
|
|
604
|
-
return pos !== -1 ? pos : ret;
|
|
605
|
-
}, -1);`
|
|
606
|
-
}),
|
|
607
|
-
createIntrinsic("hbr", {}),
|
|
608
|
-
code`return position !== -1 && argv.indexOf("--") === -1 || position < argv.indexOf("--");`
|
|
609
|
-
];
|
|
610
|
-
}
|
|
611
|
-
}),
|
|
612
|
-
createComponent(Spacing, {}),
|
|
613
|
-
createComponent(VarDeclaration, {
|
|
614
|
-
"export": true,
|
|
615
|
-
name: "isHelp",
|
|
616
|
-
type: "boolean",
|
|
617
|
-
initializer: code` !isCI && hasFlag(["help", "h", "?"]); `
|
|
618
|
-
})
|
|
619
|
-
];
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Generates the `spawn` function declaration, which is a cross-platform utility for spawning child processes with proper color support and environment variable handling.
|
|
623
|
-
*/
|
|
624
|
-
function SpawnFunctionDeclaration() {
|
|
625
|
-
return [
|
|
626
|
-
createComponent(FunctionDeclaration, {
|
|
627
|
-
async: true,
|
|
628
|
-
name: "resolveCommand",
|
|
629
|
-
parameters: [
|
|
630
|
-
{
|
|
631
|
-
name: "command",
|
|
632
|
-
type: "string"
|
|
633
|
-
},
|
|
634
|
-
{
|
|
635
|
-
name: "options",
|
|
636
|
-
type: "Record<string, any>",
|
|
637
|
-
default: "{}"
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
name: "pathExt",
|
|
641
|
-
type: "string",
|
|
642
|
-
default: "process.env.PATHEXT || [\".EXE\", \".CMD\", \".BAT\", \".COM\"].join(delimiter)"
|
|
643
|
-
}
|
|
644
|
-
],
|
|
645
|
-
children: code`const env = options.env || process.env;
|
|
646
|
-
const cwd = process.cwd();
|
|
647
|
-
if (!!options.cwd && process.chdir !== undefined && !(process.chdir as any).disabled) {
|
|
648
|
-
try {
|
|
649
|
-
process.chdir(options.cwd);
|
|
650
|
-
} catch (err) {
|
|
651
|
-
// Do nothing
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
let resolved;
|
|
656
|
-
try {
|
|
657
|
-
let extensions = [""];
|
|
658
|
-
if (isWindows) {
|
|
659
|
-
extensions = pathExt.split(delimiter).flatMap((item) => [item, item.toLowerCase()]);
|
|
660
|
-
if (command.includes(".") && extensions[0] !== "") {
|
|
661
|
-
extensions.unshift("");
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
for (const envPart of (command.match(new RegExp(\`[\${posix.sep}\${sep === posix.sep ? "" : sep}]\`.replace(/(\\\\)/g, "\\\\$1"))))
|
|
666
|
-
? [...(isWindows ? [process.cwd()] : []), ...(process.env.PATH || "").split(delimiter)]
|
|
667
|
-
: [""]
|
|
668
|
-
) {
|
|
669
|
-
const part = \`\${!(/^".*"$/.test(envPart) ? envPart.slice(1, -1) : envPart) && new RegExp(\`^\\.\${new RegExp(\`[\${posix.sep}\${sep === posix.sep ? "" : sep}]\`.replace(/(\\\\)/g, "\\\\$1")).source}\`).test(command) ? command.slice(0, 2) : ""}\${join(/^".*"$/.test(envPart) ? envPart.slice(1, -1) : envPart, command)}\`;
|
|
670
|
-
for (const extension of extensions) {
|
|
671
|
-
if (isWindows) {
|
|
672
|
-
const filePath = part + extension;
|
|
673
|
-
if ((await stat(filePath)).isFile() && extensions.some((ext) => filePath.substring(filePath.length - ext.length).toLowerCase() === ext.toLowerCase())) {
|
|
674
|
-
resolved = filePath;
|
|
675
|
-
break;
|
|
676
|
-
}
|
|
677
|
-
} else {
|
|
678
|
-
const file = await stat(part + extension);
|
|
679
|
-
if (file.isFile() && (file.mode & 0o111) !== 0) {
|
|
680
|
-
resolved = part + extension;
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
} catch (err) {
|
|
687
|
-
// Do nothing
|
|
688
|
-
} finally {
|
|
689
|
-
if (!!options.cwd && process.chdir !== undefined && !(process.chdir as any).disabled) {
|
|
690
|
-
process.chdir(cwd);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
if (resolved) {
|
|
696
|
-
resolved = resolve(
|
|
697
|
-
options.cwd ? options.cwd : "",
|
|
698
|
-
resolved
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
return resolved; `
|
|
703
|
-
}),
|
|
704
|
-
createComponent(Spacing, {}),
|
|
705
|
-
createComponent(InterfaceDeclaration, {
|
|
706
|
-
name: "SpawnBaseOptions",
|
|
707
|
-
doc: "Options for the `spawn` handler function.",
|
|
708
|
-
get children() {
|
|
709
|
-
return [
|
|
710
|
-
createComponent(InterfaceMember, {
|
|
711
|
-
name: "stdout",
|
|
712
|
-
optional: true,
|
|
713
|
-
type: "(data: string) => void",
|
|
714
|
-
doc: "The writable stream to use for prompt output, defaults to process.stdout"
|
|
715
|
-
}),
|
|
716
|
-
createIntrinsic("hbr", {}),
|
|
717
|
-
createComponent(InterfaceMember, {
|
|
718
|
-
name: "stderr",
|
|
719
|
-
optional: true,
|
|
720
|
-
type: "(data: string) => void",
|
|
721
|
-
doc: "The writable stream to use for prompt error output, defaults to process.stderr"
|
|
722
|
-
}),
|
|
723
|
-
createIntrinsic("hbr", {}),
|
|
724
|
-
createComponent(InterfaceMember, {
|
|
725
|
-
name: "rejectOnError",
|
|
726
|
-
optional: true,
|
|
727
|
-
type: "boolean",
|
|
728
|
-
doc: "Whether to reject the promise on error. Defaults to false."
|
|
729
|
-
}),
|
|
730
|
-
createIntrinsic("hbr", {}),
|
|
731
|
-
createComponent(InterfaceMember, {
|
|
732
|
-
name: "file",
|
|
733
|
-
optional: true,
|
|
734
|
-
type: "string",
|
|
735
|
-
doc: "The file to execute."
|
|
736
|
-
}),
|
|
737
|
-
createIntrinsic("hbr", {}),
|
|
738
|
-
createComponent(InterfaceMember, {
|
|
739
|
-
name: "shell",
|
|
740
|
-
optional: true,
|
|
741
|
-
type: "boolean | string",
|
|
742
|
-
doc: "If true, runs command inside of a shell. Uses '/bin/sh' on UNIX, and process.env.ComSpec on Windows. If a string is provided, it specifies the shell to use."
|
|
743
|
-
}),
|
|
744
|
-
createIntrinsic("hbr", {}),
|
|
745
|
-
createComponent(InterfaceMember, {
|
|
746
|
-
name: "forceShell",
|
|
747
|
-
optional: true,
|
|
748
|
-
type: "boolean",
|
|
749
|
-
doc: "If true, forces the command to run inside of a shell, even if the command is a file."
|
|
750
|
-
})
|
|
751
|
-
];
|
|
752
|
-
}
|
|
753
|
-
}),
|
|
754
|
-
createComponent(Spacing, {}),
|
|
755
|
-
createComponent(TypeDeclaration, {
|
|
756
|
-
"export": true,
|
|
757
|
-
name: "SpawnOptions",
|
|
758
|
-
children: code`SpawnBaseOptions & Parameters<typeof _spawn>[1]`
|
|
759
|
-
}),
|
|
760
|
-
createComponent(Spacing, {}),
|
|
761
|
-
createComponent(TSDoc, {
|
|
762
|
-
heading: "A function to spawn child processes with proper color support and environment variable handling.",
|
|
763
|
-
get children() {
|
|
764
|
-
return [
|
|
765
|
-
createComponent(TSDocParam, {
|
|
766
|
-
name: "command",
|
|
767
|
-
children: `The command to execute.`
|
|
768
|
-
}),
|
|
769
|
-
createComponent(TSDocParam, {
|
|
770
|
-
name: "args",
|
|
771
|
-
children: `The command-line arguments to pass to the command. Defaults to an empty array.`
|
|
772
|
-
}),
|
|
773
|
-
createComponent(TSDocParam, {
|
|
774
|
-
name: "options",
|
|
775
|
-
children: `Additional options for spawning the process, such as the current working directory (\`cwd\`).`
|
|
776
|
-
}),
|
|
777
|
-
createComponent(TSDocReturns, { children: `The result of the spawned process.` })
|
|
778
|
-
];
|
|
779
|
-
}
|
|
780
|
-
}),
|
|
781
|
-
createComponent(FunctionDeclaration, {
|
|
782
|
-
"export": true,
|
|
783
|
-
async: true,
|
|
784
|
-
name: "spawn",
|
|
785
|
-
parameters: [
|
|
786
|
-
{
|
|
787
|
-
name: "command",
|
|
788
|
-
type: "string"
|
|
789
|
-
},
|
|
790
|
-
{
|
|
791
|
-
name: "args",
|
|
792
|
-
type: "string[] | SpawnOptions",
|
|
793
|
-
default: "{} as SpawnOptions"
|
|
794
|
-
},
|
|
795
|
-
{
|
|
796
|
-
name: "options",
|
|
797
|
-
type: "SpawnOptions",
|
|
798
|
-
default: "{} as SpawnOptions"
|
|
799
|
-
}
|
|
800
|
-
],
|
|
801
|
-
children: code`const normalized = {
|
|
802
|
-
command,
|
|
803
|
-
args: [] as string[],
|
|
804
|
-
options: options as SpawnOptions | any,
|
|
805
|
-
file: undefined as string | undefined,
|
|
806
|
-
original: {
|
|
807
|
-
command,
|
|
808
|
-
args,
|
|
809
|
-
},
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
if (args) {
|
|
813
|
-
if (Array.isArray(args)) {
|
|
814
|
-
if (args.length > 0) {
|
|
815
|
-
normalized.args = args.slice(0);
|
|
816
|
-
}
|
|
817
|
-
} else {
|
|
818
|
-
normalized.options = { ...args } as SpawnOptions | any;
|
|
819
|
-
normalized.args = [];
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
if (!normalized.options.shell && isWindows) {
|
|
824
|
-
normalized.file = (await resolveCommand(normalized.command, normalized.options)) || (await resolveCommand(normalized.command, normalized.options, delimiter));
|
|
825
|
-
|
|
826
|
-
let commandFile = normalized.file;
|
|
827
|
-
if (normalized.file) {
|
|
828
|
-
let shebang: string | undefined;
|
|
829
|
-
const buffer = Buffer.alloc(150);
|
|
830
|
-
|
|
831
|
-
try {
|
|
832
|
-
const fd = openSync(normalized.file, "r");
|
|
833
|
-
await promisify(read)(fd, buffer, 0, 150, 0);
|
|
834
|
-
closeSync(fd);
|
|
835
|
-
} catch (err) {
|
|
836
|
-
// Do nothing
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
const matched = buffer.toString().match(/^#!(.*)/);
|
|
840
|
-
if (matched) {
|
|
841
|
-
const [path, argument] = matched[0].replace(/#! ?/, "").split(" ");
|
|
842
|
-
const binary = path.split("/").pop();
|
|
843
|
-
if (binary === "env") {
|
|
844
|
-
shebang = argument;
|
|
845
|
-
} else {
|
|
846
|
-
shebang = argument ? \`\${binary} \${argument}\` : binary;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
if (shebang) {
|
|
851
|
-
normalized.args.unshift(normalized.file);
|
|
852
|
-
normalized.command = shebang;
|
|
853
|
-
|
|
854
|
-
commandFile = await resolveCommand(normalized.command, normalized.options);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
if (commandFile && (normalized.options.forceShell || /\\.(?:com|exe)$/i.test(commandFile))) {
|
|
859
|
-
normalized.command = normalize(normalized.command).replace(/([()\\][%!^"\`<>&|;, *?])/g, "^$1");
|
|
860
|
-
|
|
861
|
-
normalized.args = ["/d", "/s", "/c", \`"\${normalized.command} \${normalized.args.map(arg =>
|
|
862
|
-
\`\${arg}\`.replace(/(?=(\\\\+?)?)\\1"/g, "$1$1\\"").replace(/(?=(\\\\+?)?)\\1$/, "$1$1")
|
|
863
|
-
).map(arg =>
|
|
864
|
-
\`"\${arg}"\`.replace(/([()\\][%!^"\`<>&|;, *?])/g, "^$1")
|
|
865
|
-
).map(arg =>
|
|
866
|
-
/node_modules[\\\\/].bin[\\\\/][^\\\\/]+\\.cmd$/i.test(commandFile) ? arg.replace(/([()\\][%!^"\`<>&|;, *?])/g, "^$1") : arg
|
|
867
|
-
).join(" ")}"\`];
|
|
868
|
-
normalized.command = process.env.comspec || "cmd.exe";
|
|
869
|
-
normalized.options.windowsVerbatimArguments = true;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
let stdout = "";
|
|
874
|
-
let stderr = "";
|
|
875
|
-
|
|
876
|
-
const child = _spawn(normalized.command, normalized.args, {
|
|
877
|
-
cwd: process.cwd(),
|
|
878
|
-
env: {
|
|
879
|
-
...process.env,
|
|
880
|
-
FORCE_COLOR: isColorSupported ? "1" : "0",
|
|
881
|
-
},
|
|
882
|
-
...normalized.options,
|
|
883
|
-
}) as ReturnType<typeof _spawn>;
|
|
884
|
-
|
|
885
|
-
if (isWindows) {
|
|
886
|
-
const emit = child.emit;
|
|
887
|
-
child.emit = (eventName: string | symbol, ...eventArgs: any[]) => {
|
|
888
|
-
if (eventName === "exit") {
|
|
889
|
-
let err: Error | null = null;
|
|
890
|
-
if (eventArgs[0] === 1 && !normalized.file) {
|
|
891
|
-
err = Object.assign(new Error(\`spawn \${normalized.original.command} ENOENT\`), {
|
|
892
|
-
code: "ENOENT",
|
|
893
|
-
errno: "ENOENT",
|
|
894
|
-
syscall: \`spawn \${normalized.original.command}\`,
|
|
895
|
-
path: normalized.original.command,
|
|
896
|
-
spawnargs: normalized.original.args,
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
if (err) {
|
|
901
|
-
return emit.call(child, "error", err);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
return emit.apply(child, [eventName, ...eventArgs]);
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
return new Promise((resolve, reject) => {
|
|
910
|
-
if (normalized.options.stdin !== undefined) {
|
|
911
|
-
child.stdin?.write(normalized.options.stdin);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
child.stdin?.end();
|
|
915
|
-
|
|
916
|
-
child.stdout?.on("data", data => {
|
|
917
|
-
stdout += data;
|
|
918
|
-
if (normalized.options.stdout) {
|
|
919
|
-
normalized.options.stdout(data);
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
child.stderr?.on("data", data => {
|
|
924
|
-
stderr += data;
|
|
925
|
-
if (normalized.options.stderr) {
|
|
926
|
-
normalized.options.stderr(data);
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
if (normalized.options.rejectOnError) {
|
|
931
|
-
child.addListener("error", reject);
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
child.on("close", code => {
|
|
935
|
-
if (code !== 0 && normalized.options.rejectOnError) {
|
|
936
|
-
reject(stderr);
|
|
937
|
-
} else {
|
|
938
|
-
resolve({ stdout, stderr });
|
|
939
|
-
}
|
|
940
|
-
});
|
|
941
|
-
}); `
|
|
942
|
-
})
|
|
943
|
-
];
|
|
944
|
-
}
|
|
945
|
-
/**
|
|
946
545
|
* Generates the `resolveModule` function declaration, which is a utility for resolving file paths across different platforms.
|
|
947
546
|
*/
|
|
948
547
|
function ResolveModuleFunctionDeclaration() {
|
|
@@ -1936,88 +1535,6 @@ function ResolveModuleFunctionDeclaration() {
|
|
|
1936
1535
|
})
|
|
1937
1536
|
];
|
|
1938
1537
|
}
|
|
1939
|
-
function ContextUtilities() {
|
|
1940
|
-
return code`
|
|
1941
|
-
/**
|
|
1942
|
-
* The global Shell Shock - Application context instance.
|
|
1943
|
-
*
|
|
1944
|
-
* @internal
|
|
1945
|
-
*/
|
|
1946
|
-
export let internal_appContext = new AsyncLocalStorage<Map<string, any>>();
|
|
1947
|
-
|
|
1948
|
-
/**
|
|
1949
|
-
* Get the Shell Shock - Application context for the current application.
|
|
1950
|
-
*
|
|
1951
|
-
* @param options - The options to use when getting the context.
|
|
1952
|
-
* @returns The Shell Shock - Application context for the current application or undefined if the context is not available.
|
|
1953
|
-
*/
|
|
1954
|
-
export function useApp(): Map<string, any> | undefined {
|
|
1955
|
-
return internal_appContext.getStore();
|
|
1956
|
-
}
|
|
1957
|
-
|
|
1958
|
-
/**
|
|
1959
|
-
* A utility hook function to get the command-line arguments from the application context.
|
|
1960
|
-
*
|
|
1961
|
-
* @returns An array of command-line arguments from the application context.
|
|
1962
|
-
* @throws If the application context is not available.
|
|
1963
|
-
*/
|
|
1964
|
-
export function useArgs(): string[] {
|
|
1965
|
-
return useApp()?.get("args") ?? getArgs();
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
/**
|
|
1969
|
-
* The context object for the current command execution, containing the command path and segments.
|
|
1970
|
-
*/
|
|
1971
|
-
export interface CommandContext {
|
|
1972
|
-
path: string;
|
|
1973
|
-
segments: string[];
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
/**
|
|
1977
|
-
* The global Shell Shock - Command context instance.
|
|
1978
|
-
*
|
|
1979
|
-
* @internal
|
|
1980
|
-
*/
|
|
1981
|
-
export let internal_commandContext = new AsyncLocalStorage<CommandContext>();
|
|
1982
|
-
|
|
1983
|
-
/**
|
|
1984
|
-
* Get the Shell Shock - Command context for the current application.
|
|
1985
|
-
*
|
|
1986
|
-
* @param options - The options to use when getting the context.
|
|
1987
|
-
* @returns The Shell Shock - Command context for the current application.
|
|
1988
|
-
* @throws If the Shell Shock - Command context is not available.
|
|
1989
|
-
*/
|
|
1990
|
-
export function useCommand(): CommandContext {
|
|
1991
|
-
const result = internal_commandContext.getStore();
|
|
1992
|
-
if (!result) {
|
|
1993
|
-
throw new Error(
|
|
1994
|
-
\`The Shell Shock - Command context is not available. Make sure to call useCommand() within a valid context scope.\`
|
|
1995
|
-
);
|
|
1996
|
-
}
|
|
1997
|
-
return result;
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
/**
|
|
2001
|
-
* A utility hook function to get the individual segments of the current command path.
|
|
2002
|
-
*
|
|
2003
|
-
* @returns An array of command path segments.
|
|
2004
|
-
* @throws If the command context is not available.
|
|
2005
|
-
*/
|
|
2006
|
-
export function useSegments(): string[] {
|
|
2007
|
-
return useCommand().segments;
|
|
2008
|
-
}
|
|
2009
|
-
|
|
2010
|
-
/**
|
|
2011
|
-
* A utility hook function to get the full command path as a string.
|
|
2012
|
-
*
|
|
2013
|
-
* @returns The full command path as a string.
|
|
2014
|
-
* @throws If the command context is not available.
|
|
2015
|
-
*/
|
|
2016
|
-
export function usePath(): string {
|
|
2017
|
-
return useCommand().path;
|
|
2018
|
-
}
|
|
2019
|
-
`;
|
|
2020
|
-
}
|
|
2021
1538
|
/**
|
|
2022
1539
|
* A built-in utilities module for Shell Shock.
|
|
2023
1540
|
*/
|
|
@@ -2052,12 +1569,7 @@ function UtilsBuiltin(props) {
|
|
|
2052
1569
|
"node:fs/promises": ["stat"],
|
|
2053
1570
|
"node:util": ["promisify"],
|
|
2054
1571
|
"node:url": ["fileURLToPath", "pathToFileURL"],
|
|
2055
|
-
"node:module": ["builtinModules"]
|
|
2056
|
-
"node:child_process": [{
|
|
2057
|
-
name: "spawn",
|
|
2058
|
-
alias: "_spawn"
|
|
2059
|
-
}],
|
|
2060
|
-
"node:async_hooks": ["AsyncLocalStorage"]
|
|
1572
|
+
"node:module": ["builtinModules"]
|
|
2061
1573
|
});
|
|
2062
1574
|
},
|
|
2063
1575
|
get builtinImports() {
|
|
@@ -2074,7 +1586,8 @@ function UtilsBuiltin(props) {
|
|
|
2074
1586
|
"isWindows",
|
|
2075
1587
|
"isDevelopment",
|
|
2076
1588
|
"isDebug"
|
|
2077
|
-
]
|
|
1589
|
+
],
|
|
1590
|
+
state: ["hasFlag"]
|
|
2078
1591
|
});
|
|
2079
1592
|
},
|
|
2080
1593
|
get children() {
|
|
@@ -2099,18 +1612,12 @@ function UtilsBuiltin(props) {
|
|
|
2099
1612
|
children: code`return new Promise((resolve) => setTimeout(resolve, durationMs)); `
|
|
2100
1613
|
}),
|
|
2101
1614
|
createComponent(Spacing, {}),
|
|
2102
|
-
createComponent(ContextUtilities, {}),
|
|
2103
|
-
createComponent(Spacing, {}),
|
|
2104
|
-
createComponent(ArgsUtilities, {}),
|
|
2105
|
-
createComponent(Spacing, {}),
|
|
2106
1615
|
createComponent(EnvSupportUtilities, {}),
|
|
2107
1616
|
createComponent(Spacing, {}),
|
|
2108
1617
|
createComponent(HyperlinkSupportUtilities, {}),
|
|
2109
1618
|
createComponent(Spacing, {}),
|
|
2110
1619
|
createComponent(ColorSupportUtilities, {}),
|
|
2111
1620
|
createComponent(Spacing, {}),
|
|
2112
|
-
createComponent(SpawnFunctionDeclaration, {}),
|
|
2113
|
-
createComponent(Spacing, {}),
|
|
2114
1621
|
createComponent(ResolveModuleFunctionDeclaration, {}),
|
|
2115
1622
|
createComponent(Spacing, {}),
|
|
2116
1623
|
createComponent(FindSuggestionsDeclaration, {}),
|
|
@@ -2127,5 +1634,5 @@ function UtilsBuiltin(props) {
|
|
|
2127
1634
|
}
|
|
2128
1635
|
|
|
2129
1636
|
//#endregion
|
|
2130
|
-
export {
|
|
1637
|
+
export { ColorSupportUtilities, EnvSupportUtilities, FindSuggestionsDeclaration, HyperlinkSupportUtilities, ResolveModuleFunctionDeclaration, UtilsBuiltin };
|
|
2131
1638
|
//# sourceMappingURL=utils-builtin.mjs.map
|