vlt
Version:
The vlt CLI
150 lines (141 loc) • 4.86 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
vlxResolve
} from "./chunk-TY5MOWCL.js";
import {
ExecCommand,
views
} from "./chunk-ZSLJZRLN.js";
import "./chunk-4HCFIDH4.js";
import "./chunk-3X64PWHW.js";
import "./chunk-M34JYYXI.js";
import "./chunk-HFPRNHS6.js";
import "./chunk-SDAHMDDM.js";
import {
exec,
execFG
} from "./chunk-XZF5GYDF.js";
import "./chunk-FZMPFIDM.js";
import "./chunk-SLTPNBLH.js";
import "./chunk-D36DAG56.js";
import "./chunk-LEKM5RQR.js";
import "./chunk-YWPMIBJS.js";
import "./chunk-5UBJ3ZBM.js";
import "./chunk-SGEQHKFC.js";
import {
styleTextStdout
} from "./chunk-I5CBBY6I.js";
import {
commandUsage
} from "./chunk-2Y5QRO5N.js";
import "./chunk-VTABR43C.js";
import "./chunk-QAFV2NQX.js";
import "./chunk-VYJVN3B6.js";
import "./chunk-GADRCS54.js";
import "./chunk-GY4L7O2Y.js";
import "./chunk-3HSZY4YW.js";
import "./chunk-6YRWYWZQ.js";
import "./chunk-TJHWNOOA.js";
import "./chunk-L3TCSQZJ.js";
import "./chunk-3RABDTYN.js";
import "./chunk-264UXZEG.js";
import "./chunk-X4RDKJKD.js";
import "./chunk-BNCOU5ZT.js";
import "./chunk-RV3EHS4P.js";
import "./chunk-AECDW3EJ.js";
// ../../src/cli-sdk/src/commands/exec.ts
import { homedir } from "node:os";
import { createInterface } from "node:readline/promises";
var usage = () => commandUsage({
command: "exec",
usage: "[--package=<pkg>] [command...]",
description: `Run a command defined by a package, installing it
if necessary.
If the package specifier is provided explicitly via the
\`--package\` config, then that is what will be used. If
a satisfying instance of the named package exists in the
local \`node_mnodules\` folder, then that will be used.
If \`--package\` is not set, then vlt will attempt to infer
the package to be installed if necessary, in the following
manner:
- If the first argument is an executable found in the
\`node_modules/.bin\` folder (ie, provided by an
installed direct dependency), then that will be used.
The search stops, and nothing will be installed.
- Otherwise, vlt attempts to resolve the first argument
as if it was a \`--package\` option, and then swap it
out with the "default" executable provided by that
package.
The "default" executable provided by a package is:
- If the package provides a single executable string in the
\`bin\` field, then that is the executable to use.
- Otherwise, if there is a \`bin\` with the same name
as the package (or just the portion after the \`/\` in
the case of scoped packages), then that will be used.
If the appropriate excutable cannot be determined, then
an error will be raised.
At no point will \`vlt exec\` change the locally installed
dependencies. Any installs it performs is done in vlt's XDG
data directory.
`,
examples: {
"--package typescript@5 tsc": {
description: "Run tsc provided by typescript version 5"
},
"eslint src/file.js": {
description: "Run the default bin provided by eslint"
},
"eslint@9.24 src/file.js": {
description: "Run the default bin provided by eslint version 9.24"
}
}
});
var HOME = homedir();
var prettyPath = (path) => path.startsWith(HOME) ? `~${path.substring(HOME.length)}` : path;
var promptFn = async (pkgSpec, path, resolution) => {
const response = await createInterface(
process.stdin,
process.stdout
).question(
`About to install: ${styleTextStdout(
["bgWhiteBright", "black", "bold"],
String(pkgSpec)
)}
from: ${styleTextStdout(
["bgWhiteBright", "black", "bold"],
resolution
)}
into: ${styleTextStdout(
["bgWhiteBright", "black", "bold"],
prettyPath(path)
)}
Is this ok? (y) `
);
process.stdin.pause();
return response;
};
var command = async (conf) => {
const arg0 = await vlxResolve(
conf.positionals,
{
...conf.options,
query: void 0
},
promptFn
);
if (arg0) conf.positionals[0] = arg0;
delete conf.options["script-shell"];
return await new ExecCommand(conf, exec, execFG).run();
};
export {
command,
prettyPath,
promptFn,
usage,
views
};
//# sourceMappingURL=exec-7F24KWOD.js.map