UNPKG

vlt

Version:
188 lines (186 loc) 5.1 kB
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 { vlxDelete, vlxInfo, vlxInstall, vlxList } from "./chunk-N47CDNRA.js"; import { stdout } from "./chunk-KNHO4BUR.js"; import "./chunk-BQNTW6JU.js"; import { ViewClass } from "./chunk-YESBS37V.js"; import "./chunk-J25GTXK2.js"; import "./chunk-3VS4XBYN.js"; import "./chunk-GGPZGJ5H.js"; import "./chunk-OTLTOVZN.js"; import { RollbackRemove } from "./chunk-QALMFIGC.js"; import "./chunk-6RYZ5N3C.js"; import { commandUsage } from "./chunk-L3E552CT.js"; import "./chunk-GTAUGWLW.js"; import "./chunk-U5J4TCIV.js"; import "./chunk-KPA4XNCN.js"; import "./chunk-VYJVN3B6.js"; import "./chunk-B4MAUXR2.js"; import "./chunk-W7RMFRDJ.js"; import "./chunk-O57KIW5U.js"; import "./chunk-JBBINXAZ.js"; import "./chunk-OAYCZMD4.js"; import "./chunk-QOAKZNUG.js"; import "./chunk-BA67AKYJ.js"; import { error } from "./chunk-KVH5ECIG.js"; import "./chunk-AECDW3EJ.js"; // ../../src/cli-sdk/src/commands/exec-cache.ts import { basename } from "node:path"; var view; var ExecCacheView = class extends ViewClass { constructor(options, conf) { super(options, conf); view = this; } stdout(...args) { stdout(...args); } }; var views = { human: ExecCacheView }; var usageDef = { command: "exec-cache", usage: "<command> [flags]", description: "Work with vlt exec-cache folders", subcommands: { ls: { usage: "", description: `Show previously installed packages used for \`vlt exec\`. Key provided can be either the package name, or the full key.` }, delete: { usage: "[<key>...]", description: `Delete previously installed packages used for \`vlt exec\`. If no keys are provided, then all entries will be deleted.` }, info: { usage: "<key>", description: `Show extended information about a given \`vlt exec\` installation.` }, install: { usage: "<spec>...", description: `Install the specified package(s) in the \`vlt exec\` central cache location. Metadata info about each installation will be printed.` } }, examples: { ls: { description: `Show all the keys for the installations in the \`vlt exec\` cache.` }, "delete typescript": { description: `Delete all versions of typescript installed for vlt exec` }, "info typescript-695bf962": { description: `Show extended info about a specific version of typescript` } } }; var usage = () => commandUsage(usageDef); var command = async (conf) => { const [sub, ...args] = conf.positionals; switch (sub) { case "ls": return ls(conf, args, view); case "info": return info(conf, args, view); case "install": return install(conf, args, view); case "delete": return deleteEntries(conf, args, view); default: { throw error("Unrecognized exec-cache command", { code: "EUSAGE", found: sub, validOptions: Object.keys(usageDef.subcommands) }); } } }; var install = async (conf, keys, view2) => { if (!keys.length) { throw error("Must supply a package spec to install", { code: "EUSAGE" }); } const allowScripts = conf.get("allow-scripts") ? String(conf.get("allow-scripts")) : ":not(*)"; return Promise.all( keys.map(async (key) => { const info2 = await vlxInstall(key, { ...conf.options, query: void 0, allowScripts }); view2?.stdout(info2); return info2.path; }) ); }; var ls = async (_conf, args, view2) => { const results = []; for await (const path of vlxList()) { const key = basename(path); if (args.length && !args.some((a) => key.includes(a))) continue; results.push(key); view2?.stdout(key); } return results; }; var info = async (conf, keys, view2) => { const allowScripts = conf.get("allow-scripts") ? String(conf.get("allow-scripts")) : ":not(*)"; const results = []; for await (const key of keys.length ? keys : vlxList()) { const info2 = vlxInfo(key, { ...conf.options, query: void 0, allowScripts }); results.push(info2); view2?.stdout(info2); } return results; }; var deleteEntries = async (conf, keys, view2) => { const allowScripts = conf.get("allow-scripts") ? String(conf.get("allow-scripts")) : ":not(*)"; const remover = new RollbackRemove(); const removed = (await vlxDelete(keys, remover, { ...conf.options, query: void 0, allowScripts })).map((path) => { view2?.stdout(`- ${basename(path)}`); return path; }); remover.confirm(); return removed; }; export { ExecCacheView, command, usage, views }; //# sourceMappingURL=exec-cache-KMUFTNIQ.js.map