@liangmi/mo 0.0.5
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/LICENSE +21 -0
- package/README.md +156 -0
- package/bin/mo-inner.mjs +3 -0
- package/bin/mo.mjs +3 -0
- package/config_schema.json +68 -0
- package/dist/mo-inner.mjs +86 -0
- package/dist/mo.mjs +5363 -0
- package/dist/runner-BDAeQY-R.mjs +1750 -0
- package/package.json +67 -0
- package/scripts/install.ts +63 -0
- package/scripts/uninstall.ts +34 -0
|
@@ -0,0 +1,1750 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import os, { homedir } from "node:os";
|
|
4
|
+
import path, { delimiter, dirname, normalize, resolve } from "node:path";
|
|
5
|
+
import { parse } from "jsonc-parser";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { cwd } from "node:process";
|
|
8
|
+
import { PassThrough } from "node:stream";
|
|
9
|
+
import c from "node:readline";
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
22
|
+
get: ((k) => from[k]).bind(null, key),
|
|
23
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
value: mod,
|
|
30
|
+
enumerable: true
|
|
31
|
+
}) : target, mod));
|
|
32
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
|
|
35
|
+
function toArr(any) {
|
|
36
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
37
|
+
}
|
|
38
|
+
function toVal(out, key, val, opts) {
|
|
39
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
40
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
41
|
+
}
|
|
42
|
+
function lib_default(args, opts) {
|
|
43
|
+
args = args || [];
|
|
44
|
+
opts = opts || {};
|
|
45
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
46
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
47
|
+
const alibi = opts.alias !== void 0;
|
|
48
|
+
const strict = opts.unknown !== void 0;
|
|
49
|
+
const defaults = opts.default !== void 0;
|
|
50
|
+
opts.alias = opts.alias || {};
|
|
51
|
+
opts.string = toArr(opts.string);
|
|
52
|
+
opts.boolean = toArr(opts.boolean);
|
|
53
|
+
if (alibi) for (k in opts.alias) {
|
|
54
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
55
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
56
|
+
}
|
|
57
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
58
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
59
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
60
|
+
}
|
|
61
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
62
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
63
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
64
|
+
}
|
|
65
|
+
if (defaults) for (k in opts.default) {
|
|
66
|
+
name = typeof opts.default[k];
|
|
67
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
68
|
+
if (opts[name] !== void 0) {
|
|
69
|
+
opts[name].push(k);
|
|
70
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
74
|
+
for (i = 0; i < len; i++) {
|
|
75
|
+
arg = args[i];
|
|
76
|
+
if (arg === "--") {
|
|
77
|
+
out._ = out._.concat(args.slice(++i));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
81
|
+
if (j === 0) out._.push(arg);
|
|
82
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
83
|
+
name = arg.substring(j + 3);
|
|
84
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
85
|
+
out[name] = false;
|
|
86
|
+
} else {
|
|
87
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
88
|
+
name = arg.substring(j, idx);
|
|
89
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
90
|
+
arr = j === 2 ? [name] : name;
|
|
91
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
92
|
+
name = arr[idx];
|
|
93
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
94
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (defaults) {
|
|
99
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
100
|
+
}
|
|
101
|
+
if (alibi) for (k in out) {
|
|
102
|
+
arr = opts.alias[k] || [];
|
|
103
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function removeBrackets(v) {
|
|
108
|
+
return v.replace(/[<[].+/, "").trim();
|
|
109
|
+
}
|
|
110
|
+
function findAllBrackets(v) {
|
|
111
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
112
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
113
|
+
const res = [];
|
|
114
|
+
const parse = (match) => {
|
|
115
|
+
let variadic = false;
|
|
116
|
+
let value = match[1];
|
|
117
|
+
if (value.startsWith("...")) {
|
|
118
|
+
value = value.slice(3);
|
|
119
|
+
variadic = true;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
required: match[0].startsWith("<"),
|
|
123
|
+
value,
|
|
124
|
+
variadic
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
let angledMatch;
|
|
128
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
129
|
+
let squareMatch;
|
|
130
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
131
|
+
return res;
|
|
132
|
+
}
|
|
133
|
+
function getMriOptions(options) {
|
|
134
|
+
const result = {
|
|
135
|
+
alias: {},
|
|
136
|
+
boolean: []
|
|
137
|
+
};
|
|
138
|
+
for (const [index, option] of options.entries()) {
|
|
139
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
140
|
+
if (option.isBoolean) if (option.negated) {
|
|
141
|
+
if (!options.some((o, i) => {
|
|
142
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
143
|
+
})) result.boolean.push(option.names[0]);
|
|
144
|
+
} else result.boolean.push(option.names[0]);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function findLongest(arr) {
|
|
149
|
+
return arr.sort((a, b) => {
|
|
150
|
+
return a.length > b.length ? -1 : 1;
|
|
151
|
+
})[0];
|
|
152
|
+
}
|
|
153
|
+
function padRight(str, length) {
|
|
154
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
155
|
+
}
|
|
156
|
+
function camelcase(input) {
|
|
157
|
+
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
158
|
+
return p1 + p2.toUpperCase();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function setDotProp(obj, keys, val) {
|
|
162
|
+
let current = obj;
|
|
163
|
+
for (let i = 0; i < keys.length; i++) {
|
|
164
|
+
const key = keys[i];
|
|
165
|
+
if (i === keys.length - 1) {
|
|
166
|
+
current[key] = val;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (current[key] == null) {
|
|
170
|
+
const nextKeyIsArrayIndex = +keys[i + 1] > -1;
|
|
171
|
+
current[key] = nextKeyIsArrayIndex ? [] : {};
|
|
172
|
+
}
|
|
173
|
+
current = current[key];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function setByType(obj, transforms) {
|
|
177
|
+
for (const key of Object.keys(transforms)) {
|
|
178
|
+
const transform = transforms[key];
|
|
179
|
+
if (transform.shouldTransform) {
|
|
180
|
+
obj[key] = [obj[key]].flat();
|
|
181
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getFileName(input) {
|
|
186
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
187
|
+
return m ? m[1] : "";
|
|
188
|
+
}
|
|
189
|
+
function camelcaseOptionName(name) {
|
|
190
|
+
return name.split(".").map((v, i) => {
|
|
191
|
+
return i === 0 ? camelcase(v) : v;
|
|
192
|
+
}).join(".");
|
|
193
|
+
}
|
|
194
|
+
var CACError = class extends Error {
|
|
195
|
+
constructor(message) {
|
|
196
|
+
super(message);
|
|
197
|
+
this.name = "CACError";
|
|
198
|
+
if (typeof Error.captureStackTrace !== "function") this.stack = new Error(message).stack;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var Option = class {
|
|
202
|
+
rawName;
|
|
203
|
+
description;
|
|
204
|
+
/** Option name */
|
|
205
|
+
name;
|
|
206
|
+
/** Option name and aliases */
|
|
207
|
+
names;
|
|
208
|
+
isBoolean;
|
|
209
|
+
required;
|
|
210
|
+
config;
|
|
211
|
+
negated;
|
|
212
|
+
constructor(rawName, description, config) {
|
|
213
|
+
this.rawName = rawName;
|
|
214
|
+
this.description = description;
|
|
215
|
+
this.config = Object.assign({}, config);
|
|
216
|
+
rawName = rawName.replaceAll(".*", "");
|
|
217
|
+
this.negated = false;
|
|
218
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
219
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
220
|
+
if (name.startsWith("no-")) {
|
|
221
|
+
this.negated = true;
|
|
222
|
+
name = name.replace(/^no-/, "");
|
|
223
|
+
}
|
|
224
|
+
return camelcaseOptionName(name);
|
|
225
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
226
|
+
this.name = this.names.at(-1);
|
|
227
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
|
228
|
+
if (rawName.includes("<")) this.required = true;
|
|
229
|
+
else if (rawName.includes("[")) this.required = false;
|
|
230
|
+
else this.isBoolean = true;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
let runtimeProcessArgs;
|
|
234
|
+
let runtimeInfo;
|
|
235
|
+
if (typeof process !== "undefined") {
|
|
236
|
+
let runtimeName;
|
|
237
|
+
if (typeof Deno !== "undefined" && typeof Deno.version?.deno === "string") runtimeName = "deno";
|
|
238
|
+
else if (typeof Bun !== "undefined" && typeof Bun.version === "string") runtimeName = "bun";
|
|
239
|
+
else runtimeName = "node";
|
|
240
|
+
runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
241
|
+
runtimeProcessArgs = process.argv;
|
|
242
|
+
} else if (typeof navigator === "undefined") runtimeInfo = `unknown`;
|
|
243
|
+
else runtimeInfo = `${navigator.platform} ${navigator.userAgent}`;
|
|
244
|
+
var Command = class {
|
|
245
|
+
rawName;
|
|
246
|
+
description;
|
|
247
|
+
config;
|
|
248
|
+
cli;
|
|
249
|
+
options;
|
|
250
|
+
aliasNames;
|
|
251
|
+
name;
|
|
252
|
+
args;
|
|
253
|
+
commandAction;
|
|
254
|
+
usageText;
|
|
255
|
+
versionNumber;
|
|
256
|
+
examples;
|
|
257
|
+
helpCallback;
|
|
258
|
+
globalCommand;
|
|
259
|
+
constructor(rawName, description, config = {}, cli) {
|
|
260
|
+
this.rawName = rawName;
|
|
261
|
+
this.description = description;
|
|
262
|
+
this.config = config;
|
|
263
|
+
this.cli = cli;
|
|
264
|
+
this.options = [];
|
|
265
|
+
this.aliasNames = [];
|
|
266
|
+
this.name = removeBrackets(rawName);
|
|
267
|
+
this.args = findAllBrackets(rawName);
|
|
268
|
+
this.examples = [];
|
|
269
|
+
}
|
|
270
|
+
usage(text) {
|
|
271
|
+
this.usageText = text;
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
allowUnknownOptions() {
|
|
275
|
+
this.config.allowUnknownOptions = true;
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
ignoreOptionDefaultValue() {
|
|
279
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
version(version, customFlags = "-v, --version") {
|
|
283
|
+
this.versionNumber = version;
|
|
284
|
+
this.option(customFlags, "Display version number");
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
example(example) {
|
|
288
|
+
this.examples.push(example);
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Add a option for this command
|
|
293
|
+
* @param rawName Raw option name(s)
|
|
294
|
+
* @param description Option description
|
|
295
|
+
* @param config Option config
|
|
296
|
+
*/
|
|
297
|
+
option(rawName, description, config) {
|
|
298
|
+
const option = new Option(rawName, description, config);
|
|
299
|
+
this.options.push(option);
|
|
300
|
+
return this;
|
|
301
|
+
}
|
|
302
|
+
alias(name) {
|
|
303
|
+
this.aliasNames.push(name);
|
|
304
|
+
return this;
|
|
305
|
+
}
|
|
306
|
+
action(callback) {
|
|
307
|
+
this.commandAction = callback;
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Check if a command name is matched by this command
|
|
312
|
+
* @param name Command name
|
|
313
|
+
*/
|
|
314
|
+
isMatched(name) {
|
|
315
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
316
|
+
}
|
|
317
|
+
get isDefaultCommand() {
|
|
318
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
319
|
+
}
|
|
320
|
+
get isGlobalCommand() {
|
|
321
|
+
return this instanceof GlobalCommand;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Check if an option is registered in this command
|
|
325
|
+
* @param name Option name
|
|
326
|
+
*/
|
|
327
|
+
hasOption(name) {
|
|
328
|
+
name = name.split(".")[0];
|
|
329
|
+
return this.options.find((option) => {
|
|
330
|
+
return option.names.includes(name);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
outputHelp() {
|
|
334
|
+
const { name, commands } = this.cli;
|
|
335
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
336
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
337
|
+
sections.push({
|
|
338
|
+
title: "Usage",
|
|
339
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
340
|
+
});
|
|
341
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
342
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
343
|
+
sections.push({
|
|
344
|
+
title: "Commands",
|
|
345
|
+
body: commands.map((command) => {
|
|
346
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
347
|
+
}).join("\n")
|
|
348
|
+
}, {
|
|
349
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
350
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
354
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
355
|
+
if (options.length > 0) {
|
|
356
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
357
|
+
sections.push({
|
|
358
|
+
title: "Options",
|
|
359
|
+
body: options.map((option) => {
|
|
360
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
361
|
+
}).join("\n")
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (this.examples.length > 0) sections.push({
|
|
365
|
+
title: "Examples",
|
|
366
|
+
body: this.examples.map((example) => {
|
|
367
|
+
if (typeof example === "function") return example(name);
|
|
368
|
+
return example;
|
|
369
|
+
}).join("\n")
|
|
370
|
+
});
|
|
371
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
372
|
+
console.info(sections.map((section) => {
|
|
373
|
+
return section.title ? `${section.title}:\n${section.body}` : section.body;
|
|
374
|
+
}).join("\n\n"));
|
|
375
|
+
}
|
|
376
|
+
outputVersion() {
|
|
377
|
+
const { name } = this.cli;
|
|
378
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
379
|
+
if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
|
|
380
|
+
}
|
|
381
|
+
checkRequiredArgs() {
|
|
382
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
383
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Check if the parsed options contain any unknown options
|
|
387
|
+
*
|
|
388
|
+
* Exit and output error when true
|
|
389
|
+
*/
|
|
390
|
+
checkUnknownOptions() {
|
|
391
|
+
const { options, globalCommand } = this.cli;
|
|
392
|
+
if (!this.config.allowUnknownOptions) {
|
|
393
|
+
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Check if the required string-type options exist
|
|
398
|
+
*/
|
|
399
|
+
checkOptionValue() {
|
|
400
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
401
|
+
const options = [...globalCommand.options, ...this.options];
|
|
402
|
+
for (const option of options) {
|
|
403
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
404
|
+
if (option.required) {
|
|
405
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
406
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Check if the number of args is more than expected
|
|
412
|
+
*/
|
|
413
|
+
checkUnusedArgs() {
|
|
414
|
+
const maximumArgsCount = this.args.some((arg) => arg.variadic) ? Infinity : this.args.length;
|
|
415
|
+
if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg) => `\`${arg}\``).join(", ")}`);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
var GlobalCommand = class extends Command {
|
|
419
|
+
constructor(cli) {
|
|
420
|
+
super("@@global@@", "", {}, cli);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var CAC = class extends EventTarget {
|
|
424
|
+
/** The program name to display in help and version message */
|
|
425
|
+
name;
|
|
426
|
+
commands;
|
|
427
|
+
globalCommand;
|
|
428
|
+
matchedCommand;
|
|
429
|
+
matchedCommandName;
|
|
430
|
+
/**
|
|
431
|
+
* Raw CLI arguments
|
|
432
|
+
*/
|
|
433
|
+
rawArgs;
|
|
434
|
+
/**
|
|
435
|
+
* Parsed CLI arguments
|
|
436
|
+
*/
|
|
437
|
+
args;
|
|
438
|
+
/**
|
|
439
|
+
* Parsed CLI options, camelCased
|
|
440
|
+
*/
|
|
441
|
+
options;
|
|
442
|
+
showHelpOnExit;
|
|
443
|
+
showVersionOnExit;
|
|
444
|
+
/**
|
|
445
|
+
* @param name The program name to display in help and version message
|
|
446
|
+
*/
|
|
447
|
+
constructor(name = "") {
|
|
448
|
+
super();
|
|
449
|
+
this.name = name;
|
|
450
|
+
this.commands = [];
|
|
451
|
+
this.rawArgs = [];
|
|
452
|
+
this.args = [];
|
|
453
|
+
this.options = {};
|
|
454
|
+
this.globalCommand = new GlobalCommand(this);
|
|
455
|
+
this.globalCommand.usage("<command> [options]");
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Add a global usage text.
|
|
459
|
+
*
|
|
460
|
+
* This is not used by sub-commands.
|
|
461
|
+
*/
|
|
462
|
+
usage(text) {
|
|
463
|
+
this.globalCommand.usage(text);
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Add a sub-command
|
|
468
|
+
*/
|
|
469
|
+
command(rawName, description, config) {
|
|
470
|
+
const command = new Command(rawName, description || "", config, this);
|
|
471
|
+
command.globalCommand = this.globalCommand;
|
|
472
|
+
this.commands.push(command);
|
|
473
|
+
return command;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Add a global CLI option.
|
|
477
|
+
*
|
|
478
|
+
* Which is also applied to sub-commands.
|
|
479
|
+
*/
|
|
480
|
+
option(rawName, description, config) {
|
|
481
|
+
this.globalCommand.option(rawName, description, config);
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Show help message when `-h, --help` flags appear.
|
|
486
|
+
*
|
|
487
|
+
*/
|
|
488
|
+
help(callback) {
|
|
489
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
490
|
+
this.globalCommand.helpCallback = callback;
|
|
491
|
+
this.showHelpOnExit = true;
|
|
492
|
+
return this;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Show version number when `-v, --version` flags appear.
|
|
496
|
+
*
|
|
497
|
+
*/
|
|
498
|
+
version(version, customFlags = "-v, --version") {
|
|
499
|
+
this.globalCommand.version(version, customFlags);
|
|
500
|
+
this.showVersionOnExit = true;
|
|
501
|
+
return this;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Add a global example.
|
|
505
|
+
*
|
|
506
|
+
* This example added here will not be used by sub-commands.
|
|
507
|
+
*/
|
|
508
|
+
example(example) {
|
|
509
|
+
this.globalCommand.example(example);
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Output the corresponding help message
|
|
514
|
+
* When a sub-command is matched, output the help message for the command
|
|
515
|
+
* Otherwise output the global one.
|
|
516
|
+
*
|
|
517
|
+
*/
|
|
518
|
+
outputHelp() {
|
|
519
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
520
|
+
else this.globalCommand.outputHelp();
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Output the version number.
|
|
524
|
+
*
|
|
525
|
+
*/
|
|
526
|
+
outputVersion() {
|
|
527
|
+
this.globalCommand.outputVersion();
|
|
528
|
+
}
|
|
529
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
530
|
+
this.args = args;
|
|
531
|
+
this.options = options;
|
|
532
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
533
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
534
|
+
return this;
|
|
535
|
+
}
|
|
536
|
+
unsetMatchedCommand() {
|
|
537
|
+
this.matchedCommand = void 0;
|
|
538
|
+
this.matchedCommandName = void 0;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Parse argv
|
|
542
|
+
*/
|
|
543
|
+
parse(argv, { run = true } = {}) {
|
|
544
|
+
if (!argv) {
|
|
545
|
+
if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
|
|
546
|
+
argv = runtimeProcessArgs;
|
|
547
|
+
}
|
|
548
|
+
this.rawArgs = argv;
|
|
549
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
550
|
+
let shouldParse = true;
|
|
551
|
+
for (const command of this.commands) {
|
|
552
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
553
|
+
const commandName = parsed.args[0];
|
|
554
|
+
if (command.isMatched(commandName)) {
|
|
555
|
+
shouldParse = false;
|
|
556
|
+
const parsedInfo = {
|
|
557
|
+
...parsed,
|
|
558
|
+
args: parsed.args.slice(1)
|
|
559
|
+
};
|
|
560
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
561
|
+
this.dispatchEvent(new CustomEvent(`command:${commandName}`, { detail: command }));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (shouldParse) {
|
|
565
|
+
for (const command of this.commands) if (command.isDefaultCommand) {
|
|
566
|
+
shouldParse = false;
|
|
567
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
568
|
+
this.setParsedInfo(parsed, command);
|
|
569
|
+
this.dispatchEvent(new CustomEvent("command:!", { detail: command }));
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (shouldParse) {
|
|
573
|
+
const parsed = this.mri(argv.slice(2));
|
|
574
|
+
this.setParsedInfo(parsed);
|
|
575
|
+
}
|
|
576
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
577
|
+
this.outputHelp();
|
|
578
|
+
run = false;
|
|
579
|
+
this.unsetMatchedCommand();
|
|
580
|
+
}
|
|
581
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
582
|
+
this.outputVersion();
|
|
583
|
+
run = false;
|
|
584
|
+
this.unsetMatchedCommand();
|
|
585
|
+
}
|
|
586
|
+
const parsedArgv = {
|
|
587
|
+
args: this.args,
|
|
588
|
+
options: this.options
|
|
589
|
+
};
|
|
590
|
+
if (run) this.runMatchedCommand();
|
|
591
|
+
if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] }));
|
|
592
|
+
return parsedArgv;
|
|
593
|
+
}
|
|
594
|
+
mri(argv, command) {
|
|
595
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
596
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
597
|
+
let argsAfterDoubleDashes = [];
|
|
598
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
599
|
+
if (doubleDashesIndex !== -1) {
|
|
600
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
601
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
602
|
+
}
|
|
603
|
+
let parsed = lib_default(argv, mriOptions);
|
|
604
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
605
|
+
return {
|
|
606
|
+
...res,
|
|
607
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
608
|
+
};
|
|
609
|
+
}, { _: [] });
|
|
610
|
+
const args = parsed._;
|
|
611
|
+
const options = { "--": argsAfterDoubleDashes };
|
|
612
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
613
|
+
const transforms = Object.create(null);
|
|
614
|
+
for (const cliOption of cliOptions) {
|
|
615
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
616
|
+
if (Array.isArray(cliOption.config.type) && transforms[cliOption.name] === void 0) {
|
|
617
|
+
transforms[cliOption.name] = Object.create(null);
|
|
618
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
619
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
623
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
624
|
+
setByType(options, transforms);
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
args,
|
|
628
|
+
options
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
runMatchedCommand() {
|
|
632
|
+
const { args, options, matchedCommand: command } = this;
|
|
633
|
+
if (!command || !command.commandAction) return;
|
|
634
|
+
command.checkUnknownOptions();
|
|
635
|
+
command.checkOptionValue();
|
|
636
|
+
command.checkRequiredArgs();
|
|
637
|
+
command.checkUnusedArgs();
|
|
638
|
+
const actionArgs = [];
|
|
639
|
+
command.args.forEach((arg, index) => {
|
|
640
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
641
|
+
else actionArgs.push(args[index]);
|
|
642
|
+
});
|
|
643
|
+
actionArgs.push(options);
|
|
644
|
+
return command.commandAction.apply(this, actionArgs);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
/**
|
|
648
|
+
* @param name The program name to display in help and version message
|
|
649
|
+
*/
|
|
650
|
+
const cac = (name = "") => new CAC(name);
|
|
651
|
+
//#endregion
|
|
652
|
+
//#region node_modules/.pnpm/untildify@6.0.0/node_modules/untildify/index.js
|
|
653
|
+
let homeDirectory;
|
|
654
|
+
let currentUser;
|
|
655
|
+
function untildify(pathWithTilde) {
|
|
656
|
+
if (typeof pathWithTilde !== "string") throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
|
|
657
|
+
if (homeDirectory === void 0) homeDirectory = os.homedir();
|
|
658
|
+
if (homeDirectory && /^~(?=$|\/|\\)/.test(pathWithTilde)) return pathWithTilde.replace(/^~/, homeDirectory);
|
|
659
|
+
const userMatch = pathWithTilde.match(/^~([^/\\]+)(.*)/);
|
|
660
|
+
if (userMatch) {
|
|
661
|
+
if (currentUser === void 0) currentUser = os.userInfo().username;
|
|
662
|
+
if (currentUser) {
|
|
663
|
+
const username = userMatch[1];
|
|
664
|
+
const rest = userMatch[2];
|
|
665
|
+
if (username === currentUser) return homeDirectory + rest;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return pathWithTilde;
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/utils/alias.ts
|
|
672
|
+
const aliasCommands = [
|
|
673
|
+
"clone",
|
|
674
|
+
"list",
|
|
675
|
+
"cd"
|
|
676
|
+
];
|
|
677
|
+
const legacyAliasCommands = ["mo", ...aliasCommands];
|
|
678
|
+
const defaultAliases = {
|
|
679
|
+
clone: "k",
|
|
680
|
+
list: "li",
|
|
681
|
+
cd: "i"
|
|
682
|
+
};
|
|
683
|
+
const aliasNameRegex = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
684
|
+
function parseAliasInput(input, onInvalid) {
|
|
685
|
+
const trimmed = input.trim();
|
|
686
|
+
if (!trimmed) return [];
|
|
687
|
+
const parsed = /* @__PURE__ */ new Set();
|
|
688
|
+
for (const alias of trimmed.split(",")) {
|
|
689
|
+
const value = alias.trim();
|
|
690
|
+
if (!value) continue;
|
|
691
|
+
if (!isValidAliasName(value)) {
|
|
692
|
+
if (onInvalid) onInvalid(value);
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
parsed.add(value);
|
|
696
|
+
}
|
|
697
|
+
return [...parsed];
|
|
698
|
+
}
|
|
699
|
+
function buildAliasLines(aliases, toAliasLine) {
|
|
700
|
+
const lines = [];
|
|
701
|
+
const used = /* @__PURE__ */ new Set();
|
|
702
|
+
for (const command of aliasCommands) {
|
|
703
|
+
const target = getAliasTarget(command);
|
|
704
|
+
const names = aliases[command];
|
|
705
|
+
if (!names?.length) continue;
|
|
706
|
+
for (const aliasName of names) {
|
|
707
|
+
if (!isValidAliasName(aliasName) || used.has(aliasName)) continue;
|
|
708
|
+
used.add(aliasName);
|
|
709
|
+
lines.push(toAliasLine(aliasName, target));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return lines;
|
|
713
|
+
}
|
|
714
|
+
function getAliasPromptLabel(command) {
|
|
715
|
+
return `mo ${command}`;
|
|
716
|
+
}
|
|
717
|
+
function isAliasCommand(value) {
|
|
718
|
+
return aliasCommands.includes(value);
|
|
719
|
+
}
|
|
720
|
+
function isLegacyAliasCommand(value) {
|
|
721
|
+
return legacyAliasCommands.includes(value);
|
|
722
|
+
}
|
|
723
|
+
function isValidAliasName(value) {
|
|
724
|
+
return aliasNameRegex.test(value);
|
|
725
|
+
}
|
|
726
|
+
function getAliasTarget(command) {
|
|
727
|
+
return `mo ${command}`;
|
|
728
|
+
}
|
|
729
|
+
//#endregion
|
|
730
|
+
//#region node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
731
|
+
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
732
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
733
|
+
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
734
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
735
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
736
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
737
|
+
};
|
|
738
|
+
let replaceClose = (string, close, replace, index) => {
|
|
739
|
+
let result = "", cursor = 0;
|
|
740
|
+
do {
|
|
741
|
+
result += string.substring(cursor, index) + replace;
|
|
742
|
+
cursor = index + close.length;
|
|
743
|
+
index = string.indexOf(close, cursor);
|
|
744
|
+
} while (~index);
|
|
745
|
+
return result + string.substring(cursor);
|
|
746
|
+
};
|
|
747
|
+
let createColors = (enabled = isColorSupported) => {
|
|
748
|
+
let f = enabled ? formatter : () => String;
|
|
749
|
+
return {
|
|
750
|
+
isColorSupported: enabled,
|
|
751
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
752
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
753
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
754
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
755
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
756
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
757
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
758
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
759
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
760
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
761
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
762
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
763
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
764
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
765
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
766
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
767
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
768
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
769
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
770
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
771
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
772
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
773
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
774
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
775
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
776
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
777
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
778
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
779
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
780
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
781
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
782
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
783
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
784
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
785
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
786
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
787
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
788
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
789
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
790
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
791
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
792
|
+
};
|
|
793
|
+
};
|
|
794
|
+
module.exports = createColors();
|
|
795
|
+
module.exports.createColors = createColors;
|
|
796
|
+
}));
|
|
797
|
+
//#endregion
|
|
798
|
+
//#region src/utils/format.ts
|
|
799
|
+
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
800
|
+
function toTildePath(fullPath) {
|
|
801
|
+
const home = os.homedir();
|
|
802
|
+
if (fullPath.startsWith(home)) return "~" + fullPath.slice(home.length);
|
|
803
|
+
return fullPath;
|
|
804
|
+
}
|
|
805
|
+
const icons = {
|
|
806
|
+
success: import_picocolors.default.green("✓"),
|
|
807
|
+
error: import_picocolors.default.red("✗"),
|
|
808
|
+
warning: import_picocolors.default.yellow("⚠")
|
|
809
|
+
};
|
|
810
|
+
const spinnerFrames = [
|
|
811
|
+
"⠋",
|
|
812
|
+
"⠙",
|
|
813
|
+
"⠹",
|
|
814
|
+
"⠸",
|
|
815
|
+
"⠼",
|
|
816
|
+
"⠴",
|
|
817
|
+
"⠦",
|
|
818
|
+
"⠧",
|
|
819
|
+
"⠇",
|
|
820
|
+
"⠏"
|
|
821
|
+
];
|
|
822
|
+
function startSpinner(message) {
|
|
823
|
+
let frameIndex = 0;
|
|
824
|
+
return {
|
|
825
|
+
interval: setInterval(() => {
|
|
826
|
+
const frame = import_picocolors.default.cyan(spinnerFrames[frameIndex]);
|
|
827
|
+
process.stdout.write(`\r${frame} ${message}`);
|
|
828
|
+
frameIndex = (frameIndex + 1) % spinnerFrames.length;
|
|
829
|
+
}, 80),
|
|
830
|
+
message
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
function stopSpinner(spinner) {
|
|
834
|
+
clearInterval(spinner.interval);
|
|
835
|
+
process.stdout.write("\r" + " ".repeat(spinner.message.length + 2) + "\r");
|
|
836
|
+
}
|
|
837
|
+
function success(message) {
|
|
838
|
+
console.log(`${icons.success} ${import_picocolors.default.green(message)}`);
|
|
839
|
+
}
|
|
840
|
+
//#endregion
|
|
841
|
+
//#region src/utils/error.ts
|
|
842
|
+
/**
|
|
843
|
+
* Prints an error message to stderr and exits the process.
|
|
844
|
+
*
|
|
845
|
+
* - Uses an ERROR prefix with background color and X icon
|
|
846
|
+
* - Returns `never` because it calls `process.exit()`.
|
|
847
|
+
*/
|
|
848
|
+
function error(message, exitCode = 1) {
|
|
849
|
+
console.error(import_picocolors.default.red(`${icons.error} ${message}`));
|
|
850
|
+
process.exit(exitCode);
|
|
851
|
+
}
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/utils/config.ts
|
|
854
|
+
const supportedShells = [
|
|
855
|
+
"zsh",
|
|
856
|
+
"bash",
|
|
857
|
+
"fish"
|
|
858
|
+
];
|
|
859
|
+
function getDefaultConfigPath() {
|
|
860
|
+
return path.join(homedir(), ".config", "morc.json");
|
|
861
|
+
}
|
|
862
|
+
function loadConfig() {
|
|
863
|
+
const configFilePath = getDefaultConfigPath();
|
|
864
|
+
if (!existsSync(configFilePath)) error(`Couldn't find config file at ${configFilePath}`);
|
|
865
|
+
return parseConfig(readFileSync(configFilePath, "utf8").trim(), configFilePath);
|
|
866
|
+
}
|
|
867
|
+
function parseConfig(jsonc, configFilePath) {
|
|
868
|
+
const invalidConfigError = (message) => error(`Invalid config: ${message} at ${configFilePath}`);
|
|
869
|
+
if (!jsonc) invalidConfigError("Empty file found");
|
|
870
|
+
const config = parse(jsonc, void 0, { allowTrailingComma: true });
|
|
871
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) invalidConfigError("Config must be an object");
|
|
872
|
+
const shells = parseShells(config.shells, invalidConfigError);
|
|
873
|
+
const alias = parseAliasConfig(config.alias, invalidConfigError);
|
|
874
|
+
const root = config.root;
|
|
875
|
+
if (typeof root !== "string" || !root) invalidConfigError("\"root\" must be a non-empty string");
|
|
876
|
+
const rootPath = path.resolve(path.dirname(configFilePath), untildify(root));
|
|
877
|
+
if (!existsSync(rootPath)) invalidConfigError(`"root" directory does not exist`);
|
|
878
|
+
if (!statSync(rootPath).isDirectory()) invalidConfigError(`"root" path is not a directory`);
|
|
879
|
+
return {
|
|
880
|
+
root: rootPath,
|
|
881
|
+
...config.editor ? { editor: String(config.editor) } : {},
|
|
882
|
+
shells,
|
|
883
|
+
...alias ? { alias } : {}
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function parseShells(value, invalidConfigError) {
|
|
887
|
+
if (value == null) invalidConfigError("\"shells\" must be provided with at least one shell");
|
|
888
|
+
if (!Array.isArray(value)) invalidConfigError("\"shells\" must be an array");
|
|
889
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
890
|
+
for (const shell of value) {
|
|
891
|
+
if (typeof shell !== "string") invalidConfigError("\"shells\" must contain strings only");
|
|
892
|
+
const normalizedShell = shell.trim().toLowerCase();
|
|
893
|
+
if (!normalizedShell) continue;
|
|
894
|
+
if (!supportedShells.includes(normalizedShell)) invalidConfigError(`"shells" contains unsupported shell "${shell}". Supported: ${supportedShells.join(", ")}`);
|
|
895
|
+
normalized.add(normalizedShell);
|
|
896
|
+
}
|
|
897
|
+
if (!normalized.size) invalidConfigError("\"shells\" must contain at least one shell");
|
|
898
|
+
return [...normalized];
|
|
899
|
+
}
|
|
900
|
+
function parseAliasConfig(value, invalidConfigError) {
|
|
901
|
+
if (value == null) return;
|
|
902
|
+
if (typeof value !== "object" || Array.isArray(value)) invalidConfigError("\"alias\" must be an object");
|
|
903
|
+
const alias = value;
|
|
904
|
+
const parsed = {};
|
|
905
|
+
for (const [command, aliases] of Object.entries(alias)) {
|
|
906
|
+
if (!isLegacyAliasCommand(command)) invalidConfigError(`"alias" contains unsupported command "${command}". Supported: ${aliasCommands.join(", ")}`);
|
|
907
|
+
if (!Array.isArray(aliases)) invalidConfigError(`"alias.${command}" must be an array`);
|
|
908
|
+
const normalized = normalizeAliasValues(aliases.map((aliasName) => {
|
|
909
|
+
if (typeof aliasName !== "string") invalidConfigError(`"alias.${command}" must contain strings only`);
|
|
910
|
+
return aliasName.trim();
|
|
911
|
+
}), command, invalidConfigError);
|
|
912
|
+
if (command === "mo") continue;
|
|
913
|
+
if (normalized.length > 0 && isAliasCommand(command)) parsed[command] = normalized;
|
|
914
|
+
}
|
|
915
|
+
return Object.keys(parsed).length > 0 ? parsed : void 0;
|
|
916
|
+
}
|
|
917
|
+
function normalizeAliasValues(aliases, command, invalidConfigError) {
|
|
918
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
919
|
+
for (const aliasName of aliases) {
|
|
920
|
+
if (!aliasName) continue;
|
|
921
|
+
if (!isValidAliasName(aliasName)) invalidConfigError(`"alias.${command}" contains invalid alias "${aliasName}". Alias must match [A-Za-z_][A-Za-z0-9_-]*`);
|
|
922
|
+
normalized.add(aliasName);
|
|
923
|
+
}
|
|
924
|
+
return [...normalized];
|
|
925
|
+
}
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region node_modules/.pnpm/tinyexec@1.0.4/node_modules/tinyexec/dist/main.mjs
|
|
928
|
+
var l = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports);
|
|
929
|
+
var u = /* @__PURE__ */ createRequire(import.meta.url);
|
|
930
|
+
const d = /^path$/i;
|
|
931
|
+
const f = {
|
|
932
|
+
key: "PATH",
|
|
933
|
+
value: ""
|
|
934
|
+
};
|
|
935
|
+
function p(e) {
|
|
936
|
+
for (const t in e) {
|
|
937
|
+
if (!Object.prototype.hasOwnProperty.call(e, t) || !d.test(t)) continue;
|
|
938
|
+
const n = e[t];
|
|
939
|
+
if (!n) return f;
|
|
940
|
+
return {
|
|
941
|
+
key: t,
|
|
942
|
+
value: n
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
return f;
|
|
946
|
+
}
|
|
947
|
+
function m(e, t) {
|
|
948
|
+
const i = t.value.split(delimiter);
|
|
949
|
+
const o = [];
|
|
950
|
+
let s = e;
|
|
951
|
+
let c;
|
|
952
|
+
do {
|
|
953
|
+
o.push(resolve(s, "node_modules", ".bin"));
|
|
954
|
+
c = s;
|
|
955
|
+
s = dirname(s);
|
|
956
|
+
} while (s !== c);
|
|
957
|
+
const l = o.concat(i).join(delimiter);
|
|
958
|
+
return {
|
|
959
|
+
key: t.key,
|
|
960
|
+
value: l
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
function h(e, t) {
|
|
964
|
+
const n = {
|
|
965
|
+
...process.env,
|
|
966
|
+
...t
|
|
967
|
+
};
|
|
968
|
+
const r = m(e, p(n));
|
|
969
|
+
n[r.key] = r.value;
|
|
970
|
+
return n;
|
|
971
|
+
}
|
|
972
|
+
const g$1 = (e) => {
|
|
973
|
+
let t = e.length;
|
|
974
|
+
const n = new PassThrough();
|
|
975
|
+
const r = () => {
|
|
976
|
+
if (--t === 0) n.emit("end");
|
|
977
|
+
};
|
|
978
|
+
for (const t of e) {
|
|
979
|
+
t.pipe(n, { end: false });
|
|
980
|
+
t.on("end", r);
|
|
981
|
+
}
|
|
982
|
+
return n;
|
|
983
|
+
};
|
|
984
|
+
var _$1 = /* @__PURE__ */ l(((e, t) => {
|
|
985
|
+
t.exports = a;
|
|
986
|
+
a.sync = o;
|
|
987
|
+
var n = u("fs");
|
|
988
|
+
function r(e, t) {
|
|
989
|
+
var n = t.pathExt !== void 0 ? t.pathExt : process.env.PATHEXT;
|
|
990
|
+
if (!n) return true;
|
|
991
|
+
n = n.split(";");
|
|
992
|
+
if (n.indexOf("") !== -1) return true;
|
|
993
|
+
for (var r = 0; r < n.length; r++) {
|
|
994
|
+
var i = n[r].toLowerCase();
|
|
995
|
+
if (i && e.substr(-i.length).toLowerCase() === i) return true;
|
|
996
|
+
}
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
function i(e, t, n) {
|
|
1000
|
+
if (!e.isSymbolicLink() && !e.isFile()) return false;
|
|
1001
|
+
return r(t, n);
|
|
1002
|
+
}
|
|
1003
|
+
function a(e, t, r) {
|
|
1004
|
+
n.stat(e, function(n, a) {
|
|
1005
|
+
r(n, n ? false : i(a, e, t));
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
function o(e, t) {
|
|
1009
|
+
return i(n.statSync(e), e, t);
|
|
1010
|
+
}
|
|
1011
|
+
}));
|
|
1012
|
+
var v = /* @__PURE__ */ l(((e, t) => {
|
|
1013
|
+
t.exports = r;
|
|
1014
|
+
r.sync = i;
|
|
1015
|
+
var n = u("fs");
|
|
1016
|
+
function r(e, t, r) {
|
|
1017
|
+
n.stat(e, function(e, n) {
|
|
1018
|
+
r(e, e ? false : a(n, t));
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
function i(e, t) {
|
|
1022
|
+
return a(n.statSync(e), t);
|
|
1023
|
+
}
|
|
1024
|
+
function a(e, t) {
|
|
1025
|
+
return e.isFile() && o(e, t);
|
|
1026
|
+
}
|
|
1027
|
+
function o(e, t) {
|
|
1028
|
+
var n = e.mode;
|
|
1029
|
+
var r = e.uid;
|
|
1030
|
+
var i = e.gid;
|
|
1031
|
+
var a = t.uid !== void 0 ? t.uid : process.getuid && process.getuid();
|
|
1032
|
+
var o = t.gid !== void 0 ? t.gid : process.getgid && process.getgid();
|
|
1033
|
+
var s = parseInt("100", 8);
|
|
1034
|
+
var c = parseInt("010", 8);
|
|
1035
|
+
var l = parseInt("001", 8);
|
|
1036
|
+
var u = s | c;
|
|
1037
|
+
return n & l || n & c && i === o || n & s && r === a || n & u && a === 0;
|
|
1038
|
+
}
|
|
1039
|
+
}));
|
|
1040
|
+
var y = /* @__PURE__ */ l(((e, t) => {
|
|
1041
|
+
u("fs");
|
|
1042
|
+
var n;
|
|
1043
|
+
if (process.platform === "win32" || global.TESTING_WINDOWS) n = _$1();
|
|
1044
|
+
else n = v();
|
|
1045
|
+
t.exports = r;
|
|
1046
|
+
r.sync = i;
|
|
1047
|
+
function r(e, t, i) {
|
|
1048
|
+
if (typeof t === "function") {
|
|
1049
|
+
i = t;
|
|
1050
|
+
t = {};
|
|
1051
|
+
}
|
|
1052
|
+
if (!i) {
|
|
1053
|
+
if (typeof Promise !== "function") throw new TypeError("callback not provided");
|
|
1054
|
+
return new Promise(function(n, i) {
|
|
1055
|
+
r(e, t || {}, function(e, t) {
|
|
1056
|
+
if (e) i(e);
|
|
1057
|
+
else n(t);
|
|
1058
|
+
});
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
n(e, t || {}, function(e, n) {
|
|
1062
|
+
if (e) {
|
|
1063
|
+
if (e.code === "EACCES" || t && t.ignoreErrors) {
|
|
1064
|
+
e = null;
|
|
1065
|
+
n = false;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
i(e, n);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
function i(e, t) {
|
|
1072
|
+
try {
|
|
1073
|
+
return n.sync(e, t || {});
|
|
1074
|
+
} catch (e) {
|
|
1075
|
+
if (t && t.ignoreErrors || e.code === "EACCES") return false;
|
|
1076
|
+
else throw e;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}));
|
|
1080
|
+
var b = /* @__PURE__ */ l(((e, t) => {
|
|
1081
|
+
const n = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
1082
|
+
const r = u("path");
|
|
1083
|
+
const i = n ? ";" : ":";
|
|
1084
|
+
const a = y();
|
|
1085
|
+
const o = (e) => Object.assign(/* @__PURE__ */ new Error(`not found: ${e}`), { code: "ENOENT" });
|
|
1086
|
+
const s = (e, t) => {
|
|
1087
|
+
const r = t.colon || i;
|
|
1088
|
+
const a = e.match(/\//) || n && e.match(/\\/) ? [""] : [...n ? [process.cwd()] : [], ...(t.path || process.env.PATH || "").split(r)];
|
|
1089
|
+
const o = n ? t.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
|
|
1090
|
+
const s = n ? o.split(r) : [""];
|
|
1091
|
+
if (n) {
|
|
1092
|
+
if (e.indexOf(".") !== -1 && s[0] !== "") s.unshift("");
|
|
1093
|
+
}
|
|
1094
|
+
return {
|
|
1095
|
+
pathEnv: a,
|
|
1096
|
+
pathExt: s,
|
|
1097
|
+
pathExtExe: o
|
|
1098
|
+
};
|
|
1099
|
+
};
|
|
1100
|
+
const c = (e, t, n) => {
|
|
1101
|
+
if (typeof t === "function") {
|
|
1102
|
+
n = t;
|
|
1103
|
+
t = {};
|
|
1104
|
+
}
|
|
1105
|
+
if (!t) t = {};
|
|
1106
|
+
const { pathEnv: i, pathExt: c, pathExtExe: l } = s(e, t);
|
|
1107
|
+
const u = [];
|
|
1108
|
+
const d = (n) => new Promise((a, s) => {
|
|
1109
|
+
if (n === i.length) return t.all && u.length ? a(u) : s(o(e));
|
|
1110
|
+
const c = i[n];
|
|
1111
|
+
const l = /^".*"$/.test(c) ? c.slice(1, -1) : c;
|
|
1112
|
+
const d = r.join(l, e);
|
|
1113
|
+
a(f(!l && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d, n, 0));
|
|
1114
|
+
});
|
|
1115
|
+
const f = (e, n, r) => new Promise((i, o) => {
|
|
1116
|
+
if (r === c.length) return i(d(n + 1));
|
|
1117
|
+
const s = c[r];
|
|
1118
|
+
a(e + s, { pathExt: l }, (a, o) => {
|
|
1119
|
+
if (!a && o) if (t.all) u.push(e + s);
|
|
1120
|
+
else return i(e + s);
|
|
1121
|
+
return i(f(e, n, r + 1));
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
return n ? d(0).then((e) => n(null, e), n) : d(0);
|
|
1125
|
+
};
|
|
1126
|
+
const l = (e, t) => {
|
|
1127
|
+
t = t || {};
|
|
1128
|
+
const { pathEnv: n, pathExt: i, pathExtExe: c } = s(e, t);
|
|
1129
|
+
const l = [];
|
|
1130
|
+
for (let o = 0; o < n.length; o++) {
|
|
1131
|
+
const s = n[o];
|
|
1132
|
+
const u = /^".*"$/.test(s) ? s.slice(1, -1) : s;
|
|
1133
|
+
const d = r.join(u, e);
|
|
1134
|
+
const f = !u && /^\.[\\\/]/.test(e) ? e.slice(0, 2) + d : d;
|
|
1135
|
+
for (let e = 0; e < i.length; e++) {
|
|
1136
|
+
const n = f + i[e];
|
|
1137
|
+
try {
|
|
1138
|
+
if (a.sync(n, { pathExt: c })) if (t.all) l.push(n);
|
|
1139
|
+
else return n;
|
|
1140
|
+
} catch (e) {}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (t.all && l.length) return l;
|
|
1144
|
+
if (t.nothrow) return null;
|
|
1145
|
+
throw o(e);
|
|
1146
|
+
};
|
|
1147
|
+
t.exports = c;
|
|
1148
|
+
c.sync = l;
|
|
1149
|
+
}));
|
|
1150
|
+
var x = /* @__PURE__ */ l(((e, t) => {
|
|
1151
|
+
const n = (e = {}) => {
|
|
1152
|
+
const t = e.env || process.env;
|
|
1153
|
+
if ((e.platform || process.platform) !== "win32") return "PATH";
|
|
1154
|
+
return Object.keys(t).reverse().find((e) => e.toUpperCase() === "PATH") || "Path";
|
|
1155
|
+
};
|
|
1156
|
+
t.exports = n;
|
|
1157
|
+
t.exports.default = n;
|
|
1158
|
+
}));
|
|
1159
|
+
var S = /* @__PURE__ */ l(((e, t) => {
|
|
1160
|
+
const n = u("path");
|
|
1161
|
+
const r = b();
|
|
1162
|
+
const i = x();
|
|
1163
|
+
function a(e, t) {
|
|
1164
|
+
const a = e.options.env || process.env;
|
|
1165
|
+
const o = process.cwd();
|
|
1166
|
+
const s = e.options.cwd != null;
|
|
1167
|
+
const c = s && process.chdir !== void 0 && !process.chdir.disabled;
|
|
1168
|
+
if (c) try {
|
|
1169
|
+
process.chdir(e.options.cwd);
|
|
1170
|
+
} catch (e) {}
|
|
1171
|
+
let l;
|
|
1172
|
+
try {
|
|
1173
|
+
l = r.sync(e.command, {
|
|
1174
|
+
path: a[i({ env: a })],
|
|
1175
|
+
pathExt: t ? n.delimiter : void 0
|
|
1176
|
+
});
|
|
1177
|
+
} catch (e) {} finally {
|
|
1178
|
+
if (c) process.chdir(o);
|
|
1179
|
+
}
|
|
1180
|
+
if (l) l = n.resolve(s ? e.options.cwd : "", l);
|
|
1181
|
+
return l;
|
|
1182
|
+
}
|
|
1183
|
+
function o(e) {
|
|
1184
|
+
return a(e) || a(e, true);
|
|
1185
|
+
}
|
|
1186
|
+
t.exports = o;
|
|
1187
|
+
}));
|
|
1188
|
+
var C = /* @__PURE__ */ l(((e, t) => {
|
|
1189
|
+
const n = /([()\][%!^"`<>&|;, *?])/g;
|
|
1190
|
+
function r(e) {
|
|
1191
|
+
e = e.replace(n, "^$1");
|
|
1192
|
+
return e;
|
|
1193
|
+
}
|
|
1194
|
+
function i(e, t) {
|
|
1195
|
+
e = `${e}`;
|
|
1196
|
+
e = e.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
|
|
1197
|
+
e = e.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
1198
|
+
e = `"${e}"`;
|
|
1199
|
+
e = e.replace(n, "^$1");
|
|
1200
|
+
if (t) e = e.replace(n, "^$1");
|
|
1201
|
+
return e;
|
|
1202
|
+
}
|
|
1203
|
+
t.exports.command = r;
|
|
1204
|
+
t.exports.argument = i;
|
|
1205
|
+
}));
|
|
1206
|
+
var w = /* @__PURE__ */ l(((e, t) => {
|
|
1207
|
+
t.exports = /^#!(.*)/;
|
|
1208
|
+
}));
|
|
1209
|
+
var T = /* @__PURE__ */ l(((e, t) => {
|
|
1210
|
+
const n = w();
|
|
1211
|
+
t.exports = (e = "") => {
|
|
1212
|
+
const t = e.match(n);
|
|
1213
|
+
if (!t) return null;
|
|
1214
|
+
const [r, i] = t[0].replace(/#! ?/, "").split(" ");
|
|
1215
|
+
const a = r.split("/").pop();
|
|
1216
|
+
if (a === "env") return i;
|
|
1217
|
+
return i ? `${a} ${i}` : a;
|
|
1218
|
+
};
|
|
1219
|
+
}));
|
|
1220
|
+
var E = /* @__PURE__ */ l(((e, t) => {
|
|
1221
|
+
const n = u("fs");
|
|
1222
|
+
const r = T();
|
|
1223
|
+
function i(e) {
|
|
1224
|
+
const t = 150;
|
|
1225
|
+
const i = Buffer.alloc(t);
|
|
1226
|
+
let a;
|
|
1227
|
+
try {
|
|
1228
|
+
a = n.openSync(e, "r");
|
|
1229
|
+
n.readSync(a, i, 0, t, 0);
|
|
1230
|
+
n.closeSync(a);
|
|
1231
|
+
} catch (e) {}
|
|
1232
|
+
return r(i.toString());
|
|
1233
|
+
}
|
|
1234
|
+
t.exports = i;
|
|
1235
|
+
}));
|
|
1236
|
+
var D = /* @__PURE__ */ l(((e, t) => {
|
|
1237
|
+
const n = u("path");
|
|
1238
|
+
const r = S();
|
|
1239
|
+
const i = C();
|
|
1240
|
+
const a = E();
|
|
1241
|
+
const o = process.platform === "win32";
|
|
1242
|
+
const s = /\.(?:com|exe)$/i;
|
|
1243
|
+
const c = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
1244
|
+
function l(e) {
|
|
1245
|
+
e.file = r(e);
|
|
1246
|
+
const t = e.file && a(e.file);
|
|
1247
|
+
if (t) {
|
|
1248
|
+
e.args.unshift(e.file);
|
|
1249
|
+
e.command = t;
|
|
1250
|
+
return r(e);
|
|
1251
|
+
}
|
|
1252
|
+
return e.file;
|
|
1253
|
+
}
|
|
1254
|
+
function d(e) {
|
|
1255
|
+
if (!o) return e;
|
|
1256
|
+
const t = l(e);
|
|
1257
|
+
const r = !s.test(t);
|
|
1258
|
+
if (e.options.forceShell || r) {
|
|
1259
|
+
const r = c.test(t);
|
|
1260
|
+
e.command = n.normalize(e.command);
|
|
1261
|
+
e.command = i.command(e.command);
|
|
1262
|
+
e.args = e.args.map((e) => i.argument(e, r));
|
|
1263
|
+
e.args = [
|
|
1264
|
+
"/d",
|
|
1265
|
+
"/s",
|
|
1266
|
+
"/c",
|
|
1267
|
+
`"${[e.command].concat(e.args).join(" ")}"`
|
|
1268
|
+
];
|
|
1269
|
+
e.command = process.env.comspec || "cmd.exe";
|
|
1270
|
+
e.options.windowsVerbatimArguments = true;
|
|
1271
|
+
}
|
|
1272
|
+
return e;
|
|
1273
|
+
}
|
|
1274
|
+
function f(e, t, n) {
|
|
1275
|
+
if (t && !Array.isArray(t)) {
|
|
1276
|
+
n = t;
|
|
1277
|
+
t = null;
|
|
1278
|
+
}
|
|
1279
|
+
t = t ? t.slice(0) : [];
|
|
1280
|
+
n = Object.assign({}, n);
|
|
1281
|
+
const r = {
|
|
1282
|
+
command: e,
|
|
1283
|
+
args: t,
|
|
1284
|
+
options: n,
|
|
1285
|
+
file: void 0,
|
|
1286
|
+
original: {
|
|
1287
|
+
command: e,
|
|
1288
|
+
args: t
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
return n.shell ? r : d(r);
|
|
1292
|
+
}
|
|
1293
|
+
t.exports = f;
|
|
1294
|
+
}));
|
|
1295
|
+
var O = /* @__PURE__ */ l(((e, t) => {
|
|
1296
|
+
const n = process.platform === "win32";
|
|
1297
|
+
function r(e, t) {
|
|
1298
|
+
return Object.assign(/* @__PURE__ */ new Error(`${t} ${e.command} ENOENT`), {
|
|
1299
|
+
code: "ENOENT",
|
|
1300
|
+
errno: "ENOENT",
|
|
1301
|
+
syscall: `${t} ${e.command}`,
|
|
1302
|
+
path: e.command,
|
|
1303
|
+
spawnargs: e.args
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
function i(e, t) {
|
|
1307
|
+
if (!n) return;
|
|
1308
|
+
const r = e.emit;
|
|
1309
|
+
e.emit = function(n, i) {
|
|
1310
|
+
if (n === "exit") {
|
|
1311
|
+
const n = a(i, t);
|
|
1312
|
+
if (n) return r.call(e, "error", n);
|
|
1313
|
+
}
|
|
1314
|
+
return r.apply(e, arguments);
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
function a(e, t) {
|
|
1318
|
+
if (n && e === 1 && !t.file) return r(t.original, "spawn");
|
|
1319
|
+
return null;
|
|
1320
|
+
}
|
|
1321
|
+
function o(e, t) {
|
|
1322
|
+
if (n && e === 1 && !t.file) return r(t.original, "spawnSync");
|
|
1323
|
+
return null;
|
|
1324
|
+
}
|
|
1325
|
+
t.exports = {
|
|
1326
|
+
hookChildProcess: i,
|
|
1327
|
+
verifyENOENT: a,
|
|
1328
|
+
verifyENOENTSync: o,
|
|
1329
|
+
notFoundError: r
|
|
1330
|
+
};
|
|
1331
|
+
}));
|
|
1332
|
+
var A = (/* @__PURE__ */ l(((e, t) => {
|
|
1333
|
+
const n = u("child_process");
|
|
1334
|
+
const r = D();
|
|
1335
|
+
const i = O();
|
|
1336
|
+
function a(e, t, a) {
|
|
1337
|
+
const o = r(e, t, a);
|
|
1338
|
+
const s = n.spawn(o.command, o.args, o.options);
|
|
1339
|
+
i.hookChildProcess(s, o);
|
|
1340
|
+
return s;
|
|
1341
|
+
}
|
|
1342
|
+
function o(e, t, a) {
|
|
1343
|
+
const o = r(e, t, a);
|
|
1344
|
+
const s = n.spawnSync(o.command, o.args, o.options);
|
|
1345
|
+
s.error = s.error || i.verifyENOENTSync(s.status, o);
|
|
1346
|
+
return s;
|
|
1347
|
+
}
|
|
1348
|
+
t.exports = a;
|
|
1349
|
+
t.exports.spawn = a;
|
|
1350
|
+
t.exports.sync = o;
|
|
1351
|
+
t.exports._parse = r;
|
|
1352
|
+
t.exports._enoent = i;
|
|
1353
|
+
})))();
|
|
1354
|
+
var j = class extends Error {
|
|
1355
|
+
result;
|
|
1356
|
+
output;
|
|
1357
|
+
get exitCode() {
|
|
1358
|
+
if (this.result.exitCode !== null) return this.result.exitCode;
|
|
1359
|
+
}
|
|
1360
|
+
constructor(e, t) {
|
|
1361
|
+
super(`Process exited with non-zero status (${e.exitCode})`);
|
|
1362
|
+
this.result = e;
|
|
1363
|
+
this.output = t;
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
const M = {
|
|
1367
|
+
timeout: void 0,
|
|
1368
|
+
persist: false
|
|
1369
|
+
};
|
|
1370
|
+
const N = { windowsHide: true };
|
|
1371
|
+
function P(e, t) {
|
|
1372
|
+
return {
|
|
1373
|
+
command: normalize(e),
|
|
1374
|
+
args: t ?? []
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
function F(e) {
|
|
1378
|
+
const t = new AbortController();
|
|
1379
|
+
for (const n of e) {
|
|
1380
|
+
if (n.aborted) {
|
|
1381
|
+
t.abort();
|
|
1382
|
+
return n;
|
|
1383
|
+
}
|
|
1384
|
+
const e = () => {
|
|
1385
|
+
t.abort(n.reason);
|
|
1386
|
+
};
|
|
1387
|
+
n.addEventListener("abort", e, { signal: t.signal });
|
|
1388
|
+
}
|
|
1389
|
+
return t.signal;
|
|
1390
|
+
}
|
|
1391
|
+
async function I(e) {
|
|
1392
|
+
let t = "";
|
|
1393
|
+
for await (const n of e) t += n.toString();
|
|
1394
|
+
return t;
|
|
1395
|
+
}
|
|
1396
|
+
var L = class {
|
|
1397
|
+
_process;
|
|
1398
|
+
_aborted = false;
|
|
1399
|
+
_options;
|
|
1400
|
+
_command;
|
|
1401
|
+
_args;
|
|
1402
|
+
_resolveClose;
|
|
1403
|
+
_processClosed;
|
|
1404
|
+
_thrownError;
|
|
1405
|
+
get process() {
|
|
1406
|
+
return this._process;
|
|
1407
|
+
}
|
|
1408
|
+
get pid() {
|
|
1409
|
+
return this._process?.pid;
|
|
1410
|
+
}
|
|
1411
|
+
get exitCode() {
|
|
1412
|
+
if (this._process && this._process.exitCode !== null) return this._process.exitCode;
|
|
1413
|
+
}
|
|
1414
|
+
constructor(e, t, n) {
|
|
1415
|
+
this._options = {
|
|
1416
|
+
...M,
|
|
1417
|
+
...n
|
|
1418
|
+
};
|
|
1419
|
+
this._command = e;
|
|
1420
|
+
this._args = t ?? [];
|
|
1421
|
+
this._processClosed = new Promise((e) => {
|
|
1422
|
+
this._resolveClose = e;
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
kill(e) {
|
|
1426
|
+
return this._process?.kill(e) === true;
|
|
1427
|
+
}
|
|
1428
|
+
get aborted() {
|
|
1429
|
+
return this._aborted;
|
|
1430
|
+
}
|
|
1431
|
+
get killed() {
|
|
1432
|
+
return this._process?.killed === true;
|
|
1433
|
+
}
|
|
1434
|
+
pipe(e, t, n) {
|
|
1435
|
+
return z(e, t, {
|
|
1436
|
+
...n,
|
|
1437
|
+
stdin: this
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
async *[Symbol.asyncIterator]() {
|
|
1441
|
+
const e = this._process;
|
|
1442
|
+
if (!e) return;
|
|
1443
|
+
const t = [];
|
|
1444
|
+
if (this._streamErr) t.push(this._streamErr);
|
|
1445
|
+
if (this._streamOut) t.push(this._streamOut);
|
|
1446
|
+
const n = g$1(t);
|
|
1447
|
+
const r = c.createInterface({ input: n });
|
|
1448
|
+
for await (const e of r) yield e.toString();
|
|
1449
|
+
await this._processClosed;
|
|
1450
|
+
e.removeAllListeners();
|
|
1451
|
+
if (this._thrownError) throw this._thrownError;
|
|
1452
|
+
if (this._options?.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new j(this);
|
|
1453
|
+
}
|
|
1454
|
+
async _waitForOutput() {
|
|
1455
|
+
const e = this._process;
|
|
1456
|
+
if (!e) throw new Error("No process was started");
|
|
1457
|
+
const [t, n] = await Promise.all([this._streamOut ? I(this._streamOut) : "", this._streamErr ? I(this._streamErr) : ""]);
|
|
1458
|
+
await this._processClosed;
|
|
1459
|
+
if (this._options?.stdin) await this._options.stdin;
|
|
1460
|
+
e.removeAllListeners();
|
|
1461
|
+
if (this._thrownError) throw this._thrownError;
|
|
1462
|
+
const r = {
|
|
1463
|
+
stderr: n,
|
|
1464
|
+
stdout: t,
|
|
1465
|
+
exitCode: this.exitCode
|
|
1466
|
+
};
|
|
1467
|
+
if (this._options.throwOnError && this.exitCode !== 0 && this.exitCode !== void 0) throw new j(this, r);
|
|
1468
|
+
return r;
|
|
1469
|
+
}
|
|
1470
|
+
then(e, t) {
|
|
1471
|
+
return this._waitForOutput().then(e, t);
|
|
1472
|
+
}
|
|
1473
|
+
_streamOut;
|
|
1474
|
+
_streamErr;
|
|
1475
|
+
spawn() {
|
|
1476
|
+
const e = cwd();
|
|
1477
|
+
const n = this._options;
|
|
1478
|
+
const r = {
|
|
1479
|
+
...N,
|
|
1480
|
+
...n.nodeOptions
|
|
1481
|
+
};
|
|
1482
|
+
const i = [];
|
|
1483
|
+
this._resetState();
|
|
1484
|
+
if (n.timeout !== void 0) i.push(AbortSignal.timeout(n.timeout));
|
|
1485
|
+
if (n.signal !== void 0) i.push(n.signal);
|
|
1486
|
+
if (n.persist === true) r.detached = true;
|
|
1487
|
+
if (i.length > 0) r.signal = F(i);
|
|
1488
|
+
r.env = h(e, r.env);
|
|
1489
|
+
const { command: a, args: s } = P(this._command, this._args);
|
|
1490
|
+
const c = (0, A._parse)(a, s, r);
|
|
1491
|
+
const l = spawn(c.command, c.args, c.options);
|
|
1492
|
+
if (l.stderr) this._streamErr = l.stderr;
|
|
1493
|
+
if (l.stdout) this._streamOut = l.stdout;
|
|
1494
|
+
this._process = l;
|
|
1495
|
+
l.once("error", this._onError);
|
|
1496
|
+
l.once("close", this._onClose);
|
|
1497
|
+
if (n.stdin !== void 0 && l.stdin && n.stdin.process) {
|
|
1498
|
+
const { stdout: e } = n.stdin.process;
|
|
1499
|
+
if (e) e.pipe(l.stdin);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
_resetState() {
|
|
1503
|
+
this._aborted = false;
|
|
1504
|
+
this._processClosed = new Promise((e) => {
|
|
1505
|
+
this._resolveClose = e;
|
|
1506
|
+
});
|
|
1507
|
+
this._thrownError = void 0;
|
|
1508
|
+
}
|
|
1509
|
+
_onError = (e) => {
|
|
1510
|
+
if (e.name === "AbortError" && (!(e.cause instanceof Error) || e.cause.name !== "TimeoutError")) {
|
|
1511
|
+
this._aborted = true;
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
this._thrownError = e;
|
|
1515
|
+
};
|
|
1516
|
+
_onClose = () => {
|
|
1517
|
+
if (this._resolveClose) this._resolveClose();
|
|
1518
|
+
};
|
|
1519
|
+
};
|
|
1520
|
+
const R = (e, t, n) => {
|
|
1521
|
+
const r = new L(e, t, n);
|
|
1522
|
+
r.spawn();
|
|
1523
|
+
return r;
|
|
1524
|
+
};
|
|
1525
|
+
const z = R;
|
|
1526
|
+
//#endregion
|
|
1527
|
+
//#region node_modules/.pnpm/isexe@4.0.0/node_modules/isexe/dist/commonjs/index.min.js
|
|
1528
|
+
var require_index_min = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1529
|
+
var a = (t, e) => () => (e || t((e = { exports: {} }).exports, e), e.exports);
|
|
1530
|
+
var _ = a((i) => {
|
|
1531
|
+
"use strict";
|
|
1532
|
+
Object.defineProperty(i, "__esModule", { value: !0 });
|
|
1533
|
+
i.sync = i.isexe = void 0;
|
|
1534
|
+
var M = __require("node:fs"), x = __require("node:fs/promises"), q = async (t, e = {}) => {
|
|
1535
|
+
let { ignoreErrors: r = !1 } = e;
|
|
1536
|
+
try {
|
|
1537
|
+
return d(await (0, x.stat)(t), e);
|
|
1538
|
+
} catch (s) {
|
|
1539
|
+
let n = s;
|
|
1540
|
+
if (r || n.code === "EACCES") return !1;
|
|
1541
|
+
throw n;
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
i.isexe = q;
|
|
1545
|
+
var m = (t, e = {}) => {
|
|
1546
|
+
let { ignoreErrors: r = !1 } = e;
|
|
1547
|
+
try {
|
|
1548
|
+
return d((0, M.statSync)(t), e);
|
|
1549
|
+
} catch (s) {
|
|
1550
|
+
let n = s;
|
|
1551
|
+
if (r || n.code === "EACCES") return !1;
|
|
1552
|
+
throw n;
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
i.sync = m;
|
|
1556
|
+
var d = (t, e) => t.isFile() && A(t, e), A = (t, e) => {
|
|
1557
|
+
let r = e.uid ?? process.getuid?.(), s = e.groups ?? process.getgroups?.() ?? [], n = e.gid ?? process.getgid?.() ?? s[0];
|
|
1558
|
+
if (r === void 0 || n === void 0) throw new Error("cannot get uid or gid");
|
|
1559
|
+
let u = new Set([n, ...s]), c = t.mode, S = t.uid, P = t.gid, f = parseInt("100", 8), l = parseInt("010", 8), j = parseInt("001", 8), C = f | l;
|
|
1560
|
+
return !!(c & j || c & l && u.has(P) || c & f && S === r || c & C && r === 0);
|
|
1561
|
+
};
|
|
1562
|
+
});
|
|
1563
|
+
var g = a((o) => {
|
|
1564
|
+
"use strict";
|
|
1565
|
+
Object.defineProperty(o, "__esModule", { value: !0 });
|
|
1566
|
+
o.sync = o.isexe = void 0;
|
|
1567
|
+
var T = __require("node:fs"), I = __require("node:fs/promises"), D = __require("node:path"), F = async (t, e = {}) => {
|
|
1568
|
+
let { ignoreErrors: r = !1 } = e;
|
|
1569
|
+
try {
|
|
1570
|
+
return y(await (0, I.stat)(t), t, e);
|
|
1571
|
+
} catch (s) {
|
|
1572
|
+
let n = s;
|
|
1573
|
+
if (r || n.code === "EACCES") return !1;
|
|
1574
|
+
throw n;
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
o.isexe = F;
|
|
1578
|
+
var L = (t, e = {}) => {
|
|
1579
|
+
let { ignoreErrors: r = !1 } = e;
|
|
1580
|
+
try {
|
|
1581
|
+
return y((0, T.statSync)(t), t, e);
|
|
1582
|
+
} catch (s) {
|
|
1583
|
+
let n = s;
|
|
1584
|
+
if (r || n.code === "EACCES") return !1;
|
|
1585
|
+
throw n;
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
o.sync = L;
|
|
1589
|
+
var B = (t, e) => {
|
|
1590
|
+
let { pathExt: r = process.env.PATHEXT || "" } = e, s = r.split(D.delimiter);
|
|
1591
|
+
if (s.indexOf("") !== -1) return !0;
|
|
1592
|
+
for (let n of s) {
|
|
1593
|
+
let u = n.toLowerCase(), c = t.substring(t.length - u.length).toLowerCase();
|
|
1594
|
+
if (u && c === u) return !0;
|
|
1595
|
+
}
|
|
1596
|
+
return !1;
|
|
1597
|
+
}, y = (t, e, r) => t.isFile() && B(e, r);
|
|
1598
|
+
});
|
|
1599
|
+
var p = a((h) => {
|
|
1600
|
+
"use strict";
|
|
1601
|
+
Object.defineProperty(h, "__esModule", { value: !0 });
|
|
1602
|
+
});
|
|
1603
|
+
var v = exports && exports.__createBinding || (Object.create ? (function(t, e, r, s) {
|
|
1604
|
+
s === void 0 && (s = r);
|
|
1605
|
+
var n = Object.getOwnPropertyDescriptor(e, r);
|
|
1606
|
+
(!n || ("get" in n ? !e.__esModule : n.writable || n.configurable)) && (n = {
|
|
1607
|
+
enumerable: !0,
|
|
1608
|
+
get: function() {
|
|
1609
|
+
return e[r];
|
|
1610
|
+
}
|
|
1611
|
+
}), Object.defineProperty(t, s, n);
|
|
1612
|
+
}) : (function(t, e, r, s) {
|
|
1613
|
+
s === void 0 && (s = r), t[s] = e[r];
|
|
1614
|
+
})), G = exports && exports.__setModuleDefault || (Object.create ? (function(t, e) {
|
|
1615
|
+
Object.defineProperty(t, "default", {
|
|
1616
|
+
enumerable: !0,
|
|
1617
|
+
value: e
|
|
1618
|
+
});
|
|
1619
|
+
}) : function(t, e) {
|
|
1620
|
+
t.default = e;
|
|
1621
|
+
}), w = exports && exports.__importStar || (function() {
|
|
1622
|
+
var t = function(e) {
|
|
1623
|
+
return t = Object.getOwnPropertyNames || function(r) {
|
|
1624
|
+
var s = [];
|
|
1625
|
+
for (var n in r) Object.prototype.hasOwnProperty.call(r, n) && (s[s.length] = n);
|
|
1626
|
+
return s;
|
|
1627
|
+
}, t(e);
|
|
1628
|
+
};
|
|
1629
|
+
return function(e) {
|
|
1630
|
+
if (e && e.__esModule) return e;
|
|
1631
|
+
var r = {};
|
|
1632
|
+
if (e != null) for (var s = t(e), n = 0; n < s.length; n++) s[n] !== "default" && v(r, e, s[n]);
|
|
1633
|
+
return G(r, e), r;
|
|
1634
|
+
};
|
|
1635
|
+
})(), X = exports && exports.__exportStar || function(t, e) {
|
|
1636
|
+
for (var r in t) r !== "default" && !Object.prototype.hasOwnProperty.call(e, r) && v(e, t, r);
|
|
1637
|
+
};
|
|
1638
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
1639
|
+
exports.sync = exports.isexe = exports.posix = exports.win32 = void 0;
|
|
1640
|
+
var E = w(_());
|
|
1641
|
+
exports.posix = E;
|
|
1642
|
+
var O = w(g());
|
|
1643
|
+
exports.win32 = O;
|
|
1644
|
+
X(p(), exports);
|
|
1645
|
+
var b = (process.env._ISEXE_TEST_PLATFORM_ || process.platform) === "win32" ? O : E;
|
|
1646
|
+
exports.isexe = b.isexe;
|
|
1647
|
+
exports.sync = b.sync;
|
|
1648
|
+
}));
|
|
1649
|
+
//#endregion
|
|
1650
|
+
//#region src/utils/commands.ts
|
|
1651
|
+
var import_lib = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1652
|
+
const { isexe, sync: isexeSync } = require_index_min();
|
|
1653
|
+
const { join, delimiter: delimiter$1, sep, posix } = __require("path");
|
|
1654
|
+
const isWindows = process.platform === "win32";
|
|
1655
|
+
/* istanbul ignore next */
|
|
1656
|
+
const rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? "" : sep}]`.replace(/(\\)/g, "\\$1"));
|
|
1657
|
+
const rRel = new RegExp(`^\\.${rSlash.source}`);
|
|
1658
|
+
const getNotFoundError = (cmd) => Object.assign(/* @__PURE__ */ new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
1659
|
+
const getPathInfo = (cmd, { path: optPath = process.env.PATH, pathExt: optPathExt = process.env.PATHEXT, delimiter: optDelimiter = delimiter$1 }) => {
|
|
1660
|
+
const pathEnv = cmd.match(rSlash) ? [""] : [...isWindows ? [process.cwd()] : [], ...(optPath || "").split(optDelimiter)];
|
|
1661
|
+
if (isWindows) {
|
|
1662
|
+
const pathExtExe = optPathExt || [
|
|
1663
|
+
".EXE",
|
|
1664
|
+
".CMD",
|
|
1665
|
+
".BAT",
|
|
1666
|
+
".COM"
|
|
1667
|
+
].join(optDelimiter);
|
|
1668
|
+
const pathExt = pathExtExe.split(optDelimiter).flatMap((item) => [item, item.toLowerCase()]);
|
|
1669
|
+
if (cmd.includes(".") && pathExt[0] !== "") pathExt.unshift("");
|
|
1670
|
+
return {
|
|
1671
|
+
pathEnv,
|
|
1672
|
+
pathExt,
|
|
1673
|
+
pathExtExe
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
return {
|
|
1677
|
+
pathEnv,
|
|
1678
|
+
pathExt: [""]
|
|
1679
|
+
};
|
|
1680
|
+
};
|
|
1681
|
+
const getPathPart = (raw, cmd) => {
|
|
1682
|
+
const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
|
|
1683
|
+
return (!pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : "") + join(pathPart, cmd);
|
|
1684
|
+
};
|
|
1685
|
+
const which = async (cmd, opt = {}) => {
|
|
1686
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
1687
|
+
const found = [];
|
|
1688
|
+
for (const envPart of pathEnv) {
|
|
1689
|
+
const p = getPathPart(envPart, cmd);
|
|
1690
|
+
for (const ext of pathExt) {
|
|
1691
|
+
const withExt = p + ext;
|
|
1692
|
+
if (await isexe(withExt, {
|
|
1693
|
+
pathExt: pathExtExe,
|
|
1694
|
+
ignoreErrors: true
|
|
1695
|
+
})) {
|
|
1696
|
+
if (!opt.all) return withExt;
|
|
1697
|
+
found.push(withExt);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
if (opt.all && found.length) return found;
|
|
1702
|
+
if (opt.nothrow) return null;
|
|
1703
|
+
throw getNotFoundError(cmd);
|
|
1704
|
+
};
|
|
1705
|
+
const whichSync = (cmd, opt = {}) => {
|
|
1706
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
1707
|
+
const found = [];
|
|
1708
|
+
for (const pathEnvPart of pathEnv) {
|
|
1709
|
+
const p = getPathPart(pathEnvPart, cmd);
|
|
1710
|
+
for (const ext of pathExt) {
|
|
1711
|
+
const withExt = p + ext;
|
|
1712
|
+
if (isexeSync(withExt, {
|
|
1713
|
+
pathExt: pathExtExe,
|
|
1714
|
+
ignoreErrors: true
|
|
1715
|
+
})) {
|
|
1716
|
+
if (!opt.all) return withExt;
|
|
1717
|
+
found.push(withExt);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
if (opt.all && found.length) return found;
|
|
1722
|
+
if (opt.nothrow) return null;
|
|
1723
|
+
throw getNotFoundError(cmd);
|
|
1724
|
+
};
|
|
1725
|
+
module.exports = which;
|
|
1726
|
+
which.sync = whichSync;
|
|
1727
|
+
})))(), 1);
|
|
1728
|
+
const runCommand = async (command, args) => {
|
|
1729
|
+
return { exitCode: (await R(command, args, { throwOnError: false })).exitCode ?? 1 };
|
|
1730
|
+
};
|
|
1731
|
+
const ensureToolReady = async (command, panic = true) => {
|
|
1732
|
+
try {
|
|
1733
|
+
if (await (0, import_lib.default)(command, { nothrow: true })) return true;
|
|
1734
|
+
} catch {}
|
|
1735
|
+
if (panic) error(`Required tool "${command}" is unavailable.`, 69);
|
|
1736
|
+
return false;
|
|
1737
|
+
};
|
|
1738
|
+
const innerBinName = "mo-inner";
|
|
1739
|
+
async function preventRunning() {
|
|
1740
|
+
if (process.platform === "win32") error("Windows is not supported. mo currently supports macOS and Linux only.", 69);
|
|
1741
|
+
try {
|
|
1742
|
+
const hasInner = await ensureToolReady(innerBinName, false);
|
|
1743
|
+
const hasUser = await ensureToolReady("mo", false);
|
|
1744
|
+
if (!hasInner || !hasUser) throw new Error();
|
|
1745
|
+
} catch {
|
|
1746
|
+
error("Local installation is not supported. Please install mo globally.", 78);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
//#endregion
|
|
1750
|
+
export { __commonJSMin as C, cac as S, __toESM as T, buildAliasLines as _, R as a, parseAliasInput as b, supportedShells as c, startSpinner as d, stopSpinner as f, aliasCommands as g, require_picocolors as h, runCommand as i, error as l, toTildePath as m, preventRunning as n, getDefaultConfigPath as o, success as p, ensureToolReady as r, loadConfig as s, innerBinName as t, icons as u, defaultAliases as v, __require as w, untildify as x, getAliasPromptLabel as y };
|