@darkrymit/crunes-cli 0.9.0 → 0.10.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/chunks/add-2OM5KGN5.js +67 -0
- package/dist/chunks/{apply-YY7MIM64.js → apply-GBUQQ4XF.js} +21 -9
- package/dist/chunks/{benchmark-BQNMULOO.js → benchmark-QWGVX3BX.js} +21 -15
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/chunk-3KKRNQQU.js +275 -0
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/{chunk-SNC7AOT7.js → chunk-AL37NFWR.js} +45 -94
- package/dist/chunks/chunk-ARIFLX5E.js +9525 -0
- package/dist/chunks/{chunk-X7PZN73N.js → chunk-E7CZPAM2.js} +1 -1
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/{chunk-MRNZFUXZ.js → chunk-KQMTTEJV.js} +22 -7
- package/dist/chunks/chunk-KX6QEHM5.js +578 -0
- package/dist/chunks/{chunk-VST6HAB6.js → chunk-MTJ2KW3V.js} +2 -0
- package/dist/chunks/chunk-MUWDZJN2.js +71 -0
- package/dist/chunks/{chunk-CY6C6ADU.js → chunk-MVCBPI4J.js} +45 -478
- package/dist/chunks/{chunk-34F4ZURL.js → chunk-NJVPLN5D.js} +29 -12
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/chunk-VSMAZISQ.js +303 -0
- package/dist/chunks/chunk-WE4HDHFU.js +37 -0
- package/dist/chunks/{create-ET6DT5ZE.js → create-2CQZF53Z.js} +5 -2
- package/dist/chunks/{create-LM7U3CJS.js → create-36F6V4WP.js} +99 -6
- package/dist/chunks/{create-TLPM7HJE.js → create-DXW4YYLJ.js} +5 -5
- package/dist/chunks/{disable-TNTEIAKO.js → disable-FB64CSYV.js} +5 -2
- package/dist/chunks/doctor-PVO4JLYN.js +208 -0
- package/dist/chunks/{enable-GUQCB4CU.js → enable-UVXHTKCJ.js} +6 -3
- package/dist/chunks/{init-PJSCFOC6.js → init-GPNC7TR5.js} +5 -2
- package/dist/chunks/{install-4YP7FALO.js → install-3G7U5ZIO.js} +10 -5
- package/dist/chunks/{intro-SA7MWV3Z.js → intro-YI5HUZCF.js} +45 -19
- package/dist/chunks/{list-WKNPZZOV.js → list-J2UCBYAY.js} +9 -6
- package/dist/chunks/list-JB4447YK.js +62 -0
- package/dist/chunks/{list-7R6NASFI.js → list-W4JAYPAA.js} +19 -19
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/{registry-K5DV5NAK.js → registry-IWP7JMNI.js} +1 -1
- package/dist/chunks/{repl-ZB3DIJ4K.js → repl-MWFEZ65P.js} +30 -20
- package/dist/chunks/resolver-URPQMOIV.js +36 -0
- package/dist/chunks/{run-22B65ZWZ.js → run-3VKWSRLO.js} +17 -11
- package/dist/chunks/rune-L5EP645W.js +283 -0
- package/dist/chunks/runner-VPTLUQJE.js +34 -0
- package/dist/chunks/{shell-explain-QLITLHW7.js → shell-explain-LKBBP2BG.js} +5 -2
- package/dist/chunks/trust-LXXYSF6W.js +109 -0
- package/dist/chunks/{uninstall-4WR5IHLC.js → uninstall-J7JUYETA.js} +10 -5
- package/dist/chunks/{update-ACLDK6E6.js → update-ZJRLDCUT.js} +10 -5
- package/dist/chunks/{version-EULYWNXN.js → version-ZULO6CV3.js} +2 -2
- package/dist/cli.js +47 -34
- package/package.json +2 -2
- package/dist/chunks/chunk-G3U4V32O.js +0 -46
- package/dist/chunks/chunk-QYRF3R35.js +0 -154
- package/dist/chunks/chunk-YXCHIMLW.js +0 -75308
- package/dist/chunks/doctor-VXAQYMTR.js +0 -101
- package/dist/chunks/list-OMMZAQ23.js +0 -28
- package/dist/chunks/resolver-QIYYFIDX.js +0 -34
- package/dist/chunks/rune-SYK4N642.js +0 -425
- package/dist/chunks/{delete-5R3WBLVD.js → delete-2EXPFBFC.js} +4 -4
- package/dist/chunks/{delete-U4STA2QZ.js → delete-MJAECXXV.js} +4 -4
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getConfigPath,
|
|
3
|
+
readRawConfig,
|
|
4
|
+
writeRawConfig
|
|
5
|
+
} from "./chunk-E7CZPAM2.js";
|
|
6
|
+
import {
|
|
7
|
+
output
|
|
8
|
+
} from "./chunk-MIKWIFYR.js";
|
|
9
|
+
import "./chunk-CGZL5SSH.js";
|
|
10
|
+
import "./chunk-WCODTMDN.js";
|
|
11
|
+
import {
|
|
12
|
+
runtimeOf
|
|
13
|
+
} from "./chunk-2DNYVKBF.js";
|
|
14
|
+
import "./chunk-3KKRNQQU.js";
|
|
15
|
+
import {
|
|
16
|
+
isPathCommand
|
|
17
|
+
} from "./chunk-UBCAZGLE.js";
|
|
18
|
+
import "./chunk-VP7YLCQP.js";
|
|
19
|
+
import "./chunk-2HM5Q52B.js";
|
|
20
|
+
import {
|
|
21
|
+
getStorePath
|
|
22
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
23
|
+
import "./chunk-55GTJG5I.js";
|
|
24
|
+
import {
|
|
25
|
+
init_require_shim
|
|
26
|
+
} from "./chunk-TPK5AGRA.js";
|
|
27
|
+
|
|
28
|
+
// src/rune/commands/add.js
|
|
29
|
+
init_require_shim();
|
|
30
|
+
import { existsSync } from "node:fs";
|
|
31
|
+
import { join, isAbsolute } from "node:path";
|
|
32
|
+
async function handler({ key, command, argv = [], name, description, configRoot = process.cwd(), global = false }) {
|
|
33
|
+
const configPath = getConfigPath({ configRoot, global });
|
|
34
|
+
const config = readRawConfig(configPath);
|
|
35
|
+
if (!config) {
|
|
36
|
+
output.error(`No config at ${configPath}. Run \`crunes init${global ? " -g" : ""}\` first.`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
if (config.runes?.[key] != null) {
|
|
40
|
+
output.error(`Rune "${key}" already exists in ${configPath}.`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
if (isPathCommand(command)) {
|
|
44
|
+
const base = global ? getStorePath() : configRoot;
|
|
45
|
+
const file = isAbsolute(command) ? command : join(base, command);
|
|
46
|
+
if (!existsSync(file)) {
|
|
47
|
+
output.error(`${command} does not exist (looked for ${file}).`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const run = argv.length > 0 ? { command, argv } : command;
|
|
52
|
+
config.runes = {
|
|
53
|
+
...config.runes ?? {},
|
|
54
|
+
[key]: {
|
|
55
|
+
...name && { name },
|
|
56
|
+
...description && { description },
|
|
57
|
+
run
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
await writeRawConfig(configPath, config);
|
|
61
|
+
const runtime = runtimeOf(command);
|
|
62
|
+
output.success(`Added "${key}" \u2192 ${[command, ...argv].join(" ")} (${runtime === "isolate" ? "isolate" : `${runtime}, native`})`);
|
|
63
|
+
output.info(`Run: crunes run ${key}`);
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
handler
|
|
67
|
+
};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadConfig
|
|
3
|
-
} from "./chunk-QYRF3R35.js";
|
|
4
1
|
import {
|
|
5
2
|
output
|
|
6
3
|
} from "./chunk-MIKWIFYR.js";
|
|
@@ -11,14 +8,23 @@ import {
|
|
|
11
8
|
ye
|
|
12
9
|
} from "./chunk-CGZL5SSH.js";
|
|
13
10
|
import "./chunk-WCODTMDN.js";
|
|
11
|
+
import {
|
|
12
|
+
loadConfig
|
|
13
|
+
} from "./chunk-3KKRNQQU.js";
|
|
14
|
+
import "./chunk-UBCAZGLE.js";
|
|
14
15
|
import {
|
|
15
16
|
loadRegistry,
|
|
16
17
|
resolvePluginKey
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-2Q3KLBE6.js";
|
|
18
|
+
} from "./chunk-MTJ2KW3V.js";
|
|
19
19
|
import {
|
|
20
20
|
loadPluginJson
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-FIAFVIAN.js";
|
|
22
|
+
import "./chunk-VP7YLCQP.js";
|
|
23
|
+
import {
|
|
24
|
+
isolateName
|
|
25
|
+
} from "./chunk-WE4HDHFU.js";
|
|
26
|
+
import "./chunk-2Q3KLBE6.js";
|
|
27
|
+
import "./chunk-55GTJG5I.js";
|
|
22
28
|
import {
|
|
23
29
|
init_require_shim
|
|
24
30
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -99,7 +105,11 @@ async function handler({
|
|
|
99
105
|
process.exit(1);
|
|
100
106
|
}
|
|
101
107
|
const outputKey = key ?? templateName;
|
|
102
|
-
runeRelPath = runeRelPath ?? `.crunes/runes/${outputKey}.js`;
|
|
108
|
+
runeRelPath = runeRelPath ?? `.crunes/runes/${outputKey}.rune.js`;
|
|
109
|
+
if (!/\.rune\.m?js$/i.test(runeRelPath)) {
|
|
110
|
+
output.error(`${runeRelPath}: a sandboxed rune's file must be named *.rune.js \u2014 the name is what runs it in the isolate.`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
103
113
|
const runeAbsPath = path.join(projectRoot, runeRelPath);
|
|
104
114
|
if (!isNonInteractive) ye("crunes template apply");
|
|
105
115
|
try {
|
|
@@ -161,11 +171,13 @@ async function handler({
|
|
|
161
171
|
}
|
|
162
172
|
const resolvedName = name ?? templateMeta.name;
|
|
163
173
|
const resolvedDesc = description ?? templateMeta.description;
|
|
174
|
+
const command = isolateName(runeRelPath);
|
|
175
|
+
const perms = templateMeta.permissions;
|
|
164
176
|
const configEntry = {
|
|
165
|
-
path: runeRelPath,
|
|
166
177
|
...resolvedName && { name: resolvedName },
|
|
167
178
|
...resolvedDesc && { description: resolvedDesc },
|
|
168
|
-
|
|
179
|
+
run: perms?.run ? { command, permissions: perms.run } : command,
|
|
180
|
+
...perms?.repl && { repl: { command, permissions: perms.repl } }
|
|
169
181
|
};
|
|
170
182
|
config.runes = { ...config.runes ?? {}, [outputKey]: configEntry };
|
|
171
183
|
const tmp = configPath + ".tmp";
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
joinBracketTokens,
|
|
3
3
|
parseBracketKey
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
runRune
|
|
7
|
-
} from "./chunk-YXCHIMLW.js";
|
|
8
|
-
import "./chunk-UEUUOAJY.js";
|
|
9
|
-
import "./chunk-4GJMCFR6.js";
|
|
10
|
-
import "./chunk-CY6C6ADU.js";
|
|
11
|
-
import "./chunk-GVMT55GH.js";
|
|
12
|
-
import "./chunk-WJII3LZK.js";
|
|
13
|
-
import "./chunk-G4ZAUHHA.js";
|
|
14
|
-
import {
|
|
15
|
-
loadConfig
|
|
16
|
-
} from "./chunk-QYRF3R35.js";
|
|
4
|
+
} from "./chunk-AL37NFWR.js";
|
|
17
5
|
import {
|
|
18
6
|
output
|
|
19
7
|
} from "./chunk-MIKWIFYR.js";
|
|
@@ -21,9 +9,27 @@ import "./chunk-CGZL5SSH.js";
|
|
|
21
9
|
import {
|
|
22
10
|
source_default
|
|
23
11
|
} from "./chunk-WCODTMDN.js";
|
|
24
|
-
import
|
|
12
|
+
import {
|
|
13
|
+
runRune
|
|
14
|
+
} from "./chunk-VSMAZISQ.js";
|
|
15
|
+
import "./chunk-KX6QEHM5.js";
|
|
16
|
+
import "./chunk-2DNYVKBF.js";
|
|
17
|
+
import "./chunk-MUWDZJN2.js";
|
|
18
|
+
import {
|
|
19
|
+
loadConfig
|
|
20
|
+
} from "./chunk-3KKRNQQU.js";
|
|
21
|
+
import "./chunk-UBCAZGLE.js";
|
|
22
|
+
import "./chunk-MTJ2KW3V.js";
|
|
23
|
+
import "./chunk-FIAFVIAN.js";
|
|
24
|
+
import "./chunk-VP7YLCQP.js";
|
|
25
|
+
import "./chunk-WE4HDHFU.js";
|
|
26
|
+
import "./chunk-MVCBPI4J.js";
|
|
27
|
+
import "./chunk-GVMT55GH.js";
|
|
28
|
+
import "./chunk-2HM5Q52B.js";
|
|
29
|
+
import "./chunk-WJII3LZK.js";
|
|
30
|
+
import "./chunk-G4ZAUHHA.js";
|
|
25
31
|
import "./chunk-2Q3KLBE6.js";
|
|
26
|
-
import "./chunk-
|
|
32
|
+
import "./chunk-55GTJG5I.js";
|
|
27
33
|
import {
|
|
28
34
|
init_require_shim
|
|
29
35
|
} from "./chunk-TPK5AGRA.js";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPathCommand
|
|
3
|
+
} from "./chunk-UBCAZGLE.js";
|
|
4
|
+
import {
|
|
5
|
+
defaultDeps,
|
|
6
|
+
resolveShell
|
|
7
|
+
} from "./chunk-2HM5Q52B.js";
|
|
8
|
+
import {
|
|
9
|
+
init_require_shim
|
|
10
|
+
} from "./chunk-TPK5AGRA.js";
|
|
11
|
+
|
|
12
|
+
// src/rune/native/runtime.js
|
|
13
|
+
init_require_shim();
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
var ISOLATE_FILE = /\.rune\.m?js$/i;
|
|
17
|
+
var RUNTIME_BY_EXTENSION = {
|
|
18
|
+
".js": "node",
|
|
19
|
+
".mjs": "node",
|
|
20
|
+
".cjs": "node",
|
|
21
|
+
".py": "python",
|
|
22
|
+
".sh": "bash",
|
|
23
|
+
".cmd": "cmd",
|
|
24
|
+
".bat": "cmd"
|
|
25
|
+
};
|
|
26
|
+
function runtimeOf(command) {
|
|
27
|
+
if (!isPathCommand(command)) return "program";
|
|
28
|
+
if (ISOLATE_FILE.test(command)) return "isolate";
|
|
29
|
+
return RUNTIME_BY_EXTENSION[path.extname(command).toLowerCase()] ?? "file";
|
|
30
|
+
}
|
|
31
|
+
var InterpreterNotFoundError = class extends Error {
|
|
32
|
+
constructor(runtime, tried, hint) {
|
|
33
|
+
super(`No ${runtime} interpreter found. Tried:
|
|
34
|
+
${tried.join("\n ")}
|
|
35
|
+
${hint}`);
|
|
36
|
+
this.name = "InterpreterNotFoundError";
|
|
37
|
+
this.tried = tried;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var pathFor = (deps) => deps.platform === "win32" ? path.win32 : path.posix;
|
|
41
|
+
function onPath(name, deps = defaultDeps()) {
|
|
42
|
+
const names = deps.platform === "win32" ? [`${name}.exe`, name] : [name];
|
|
43
|
+
for (const dir of deps.pathDirs) {
|
|
44
|
+
for (const n of names) {
|
|
45
|
+
const candidate = pathFor(deps).join(dir, n);
|
|
46
|
+
if (deps.exists(candidate)) return candidate;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function findPython(projectDir, deps = defaultDeps()) {
|
|
52
|
+
const win = deps.platform === "win32";
|
|
53
|
+
const p = pathFor(deps);
|
|
54
|
+
const venvPython = (dir) => win ? p.join(dir, "Scripts", "python.exe") : p.join(dir, "bin", "python");
|
|
55
|
+
const tried = [];
|
|
56
|
+
const attempt = (label, candidate, args = [], missing = "(unset)") => {
|
|
57
|
+
tried.push(candidate ? `${label}: ${candidate}` : `${label}: ${missing}`);
|
|
58
|
+
return candidate && deps.exists(candidate) ? { command: candidate, args } : null;
|
|
59
|
+
};
|
|
60
|
+
const found = attempt("CRUNES_PYTHON", deps.env.CRUNES_PYTHON) ?? attempt("VIRTUAL_ENV", deps.env.VIRTUAL_ENV && venvPython(deps.env.VIRTUAL_ENV)) ?? attempt(".venv", venvPython(p.join(projectDir, ".venv"))) ?? attempt("venv", venvPython(p.join(projectDir, "venv"))) ?? attempt("python3", onPath("python3", deps), [], "(not on PATH)") ?? attempt("python", onPath("python", deps), [], "(not on PATH)") ?? (win ? attempt("py -3", onPath("py", deps), ["-3"], "(not on PATH)") : null);
|
|
61
|
+
if (found) return found;
|
|
62
|
+
throw new InterpreterNotFoundError("Python", tried, "Install Python, or set CRUNES_PYTHON to the interpreter to use.");
|
|
63
|
+
}
|
|
64
|
+
var pythonCache = /* @__PURE__ */ new Map();
|
|
65
|
+
function resolveInterpreter(runtime, projectDir) {
|
|
66
|
+
switch (runtime) {
|
|
67
|
+
case "node":
|
|
68
|
+
return { command: process.execPath, args: [] };
|
|
69
|
+
case "python": {
|
|
70
|
+
if (!pythonCache.has(projectDir)) pythonCache.set(projectDir, findPython(projectDir));
|
|
71
|
+
return pythonCache.get(projectDir);
|
|
72
|
+
}
|
|
73
|
+
case "bash":
|
|
74
|
+
return { command: resolveShell("bash").path, args: [] };
|
|
75
|
+
case "cmd":
|
|
76
|
+
if (process.platform !== "win32") {
|
|
77
|
+
throw new Error("Windows batch scripts (.cmd/.bat) can only run on Windows.");
|
|
78
|
+
}
|
|
79
|
+
return { command: process.env.COMSPEC || "cmd.exe", args: ["/d", "/s", "/c"] };
|
|
80
|
+
default:
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var UTILS_IMPORT = /(?:\bfrom\s*|\bimport\s*\(?\s*)['"]@utils['"]/;
|
|
85
|
+
function assertNotMissedRename(file, runtime, projectDir = null) {
|
|
86
|
+
if (runtime !== "node") return;
|
|
87
|
+
let source;
|
|
88
|
+
try {
|
|
89
|
+
source = readFileSync(file, "utf8");
|
|
90
|
+
} catch {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!UTILS_IMPORT.test(source)) return;
|
|
94
|
+
const shown = projectDir ? path.relative(projectDir, file).replace(/\\/g, "/") : file;
|
|
95
|
+
const renamed = shown.replace(/\.(m?js|cjs)$/i, ".rune.$1");
|
|
96
|
+
throw new Error(
|
|
97
|
+
`${shown} imports @utils but is named as a native Node script.
|
|
98
|
+
A run block runs plain .js files with Node, outside the sandbox. To keep it in the isolate, rename it:
|
|
99
|
+
mv ${shown} ${renamed}
|
|
100
|
+
and point run.command at the new name.`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export {
|
|
105
|
+
runtimeOf,
|
|
106
|
+
onPath,
|
|
107
|
+
resolveInterpreter,
|
|
108
|
+
assertNotMissedRename
|
|
109
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_require_shim
|
|
3
|
+
} from "./chunk-TPK5AGRA.js";
|
|
4
|
+
|
|
5
|
+
// src/rune/api/shell-resolve.js
|
|
6
|
+
init_require_shim();
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
var ShellResolutionError = class extends Error {
|
|
10
|
+
constructor(message, { mode, tried }) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "ShellResolutionError";
|
|
13
|
+
this.mode = mode;
|
|
14
|
+
this.tried = tried;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function isWslLauncher(candidate, env) {
|
|
18
|
+
const systemRoot = (env.SystemRoot ?? "C:\\Windows").replace(/\\/g, "/").toLowerCase();
|
|
19
|
+
const p = String(candidate).replace(/\\/g, "/").toLowerCase();
|
|
20
|
+
return p.startsWith(`${systemRoot}/system32/`);
|
|
21
|
+
}
|
|
22
|
+
function bashCandidates(deps) {
|
|
23
|
+
const { platform, env, pathDirs } = deps;
|
|
24
|
+
if (platform !== "win32") {
|
|
25
|
+
return ["/bin/bash", "/usr/bin/bash", ...pathDirs.map((d) => path.posix.join(d, "bash"))];
|
|
26
|
+
}
|
|
27
|
+
const out = [];
|
|
28
|
+
if (env.ProgramFiles) out.push(path.win32.join(env.ProgramFiles, "Git", "bin", "bash.exe"));
|
|
29
|
+
if (env["ProgramFiles(x86)"]) out.push(path.win32.join(env["ProgramFiles(x86)"], "Git", "bin", "bash.exe"));
|
|
30
|
+
if (env.LOCALAPPDATA) out.push(path.win32.join(env.LOCALAPPDATA, "Programs", "Git", "bin", "bash.exe"));
|
|
31
|
+
for (const dir of pathDirs) {
|
|
32
|
+
const candidate = path.win32.join(dir, "bash.exe");
|
|
33
|
+
if (isWslLauncher(candidate, env)) continue;
|
|
34
|
+
out.push(candidate);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function findBash(deps) {
|
|
39
|
+
const { env, exists } = deps;
|
|
40
|
+
const tried = bashCandidates(deps);
|
|
41
|
+
for (const candidate of tried) {
|
|
42
|
+
if (exists(candidate)) return { path: candidate, tried };
|
|
43
|
+
}
|
|
44
|
+
const override = env.CRUNES_BASH;
|
|
45
|
+
if (override && exists(override) && !isWslLauncher(override, env)) {
|
|
46
|
+
return { path: override, tried: [...tried, override] };
|
|
47
|
+
}
|
|
48
|
+
return { path: null, tried: override ? [...tried, override] : tried };
|
|
49
|
+
}
|
|
50
|
+
function findSh(deps) {
|
|
51
|
+
if (deps.platform === "win32") return null;
|
|
52
|
+
return deps.exists("/bin/sh") ? "/bin/sh" : null;
|
|
53
|
+
}
|
|
54
|
+
function findCmd(deps) {
|
|
55
|
+
if (deps.platform !== "win32") return null;
|
|
56
|
+
return deps.env.ComSpec ?? "C:\\Windows\\System32\\cmd.exe";
|
|
57
|
+
}
|
|
58
|
+
var cached = null;
|
|
59
|
+
function defaultDeps() {
|
|
60
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
61
|
+
return {
|
|
62
|
+
platform: process.platform,
|
|
63
|
+
env: process.env,
|
|
64
|
+
exists: (p) => {
|
|
65
|
+
try {
|
|
66
|
+
return existsSync(p);
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
pathDirs: (process.env.PATH ?? "").split(sep).filter(Boolean)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function resolveShell(mode, deps = null) {
|
|
75
|
+
const d = deps ?? defaultDeps();
|
|
76
|
+
const useCache = deps === null;
|
|
77
|
+
if (mode !== void 0 && mode !== "bash" && mode !== "cmd") {
|
|
78
|
+
throw new ShellResolutionError(`Unknown shell mode: '${mode}'. Expected 'bash', 'cmd', or undefined.`, { mode, tried: [] });
|
|
79
|
+
}
|
|
80
|
+
if (useCache && cached && cached[String(mode)]) return cached[String(mode)];
|
|
81
|
+
let result;
|
|
82
|
+
if (mode === "bash") {
|
|
83
|
+
const { path: bash, tried } = findBash(d);
|
|
84
|
+
if (!bash) {
|
|
85
|
+
throw new ShellResolutionError(
|
|
86
|
+
`shell: 'bash' was requested but no bash was found. Tried:
|
|
87
|
+
${tried.join("\n ")}
|
|
88
|
+
Set CRUNES_BASH to an absolute bash path if it is installed elsewhere.`,
|
|
89
|
+
{ mode, tried }
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
result = { kind: "bash", path: bash };
|
|
93
|
+
} else if (mode === "cmd") {
|
|
94
|
+
const cmd = findCmd(d);
|
|
95
|
+
if (!cmd) {
|
|
96
|
+
throw new ShellResolutionError(`shell: 'cmd' is only available on Windows (platform is '${d.platform}').`, { mode, tried: [] });
|
|
97
|
+
}
|
|
98
|
+
result = { kind: "cmd", path: cmd };
|
|
99
|
+
} else {
|
|
100
|
+
const { path: bash, tried } = findBash(d);
|
|
101
|
+
if (bash) {
|
|
102
|
+
result = { kind: "bash", path: bash };
|
|
103
|
+
} else {
|
|
104
|
+
const sh = findSh(d);
|
|
105
|
+
if (sh) {
|
|
106
|
+
result = { kind: "sh", path: sh };
|
|
107
|
+
} else {
|
|
108
|
+
const cmd = findCmd(d);
|
|
109
|
+
if (!cmd) {
|
|
110
|
+
throw new ShellResolutionError(
|
|
111
|
+
`No usable shell found. Tried bash:
|
|
112
|
+
${tried.join("\n ")}
|
|
113
|
+
then /bin/sh.`,
|
|
114
|
+
{ mode, tried: [...tried, "/bin/sh"] }
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
result = { kind: "cmd", path: cmd };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (useCache) {
|
|
122
|
+
cached ??= {};
|
|
123
|
+
cached[String(mode)] = result;
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
defaultDeps,
|
|
130
|
+
resolveShell
|
|
131
|
+
};
|