vlt
Version:
The vlt CLI
203 lines (201 loc) • 5.9 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout as _vlt_setTimeout,clearTimeout as _vlt_clearTimeout,setImmediate as _vlt_setImmediate,clearImmediate as _vlt_clearImmediate,setInterval as _vlt_setInterval,clearInterval as _vlt_clearInterval} from "node:timers";
globalThis.setTimeout = _vlt_setTimeout;
globalThis.clearTimeout = _vlt_clearTimeout;
globalThis.setImmediate = _vlt_setImmediate;
globalThis.clearImmediate = _vlt_clearImmediate;
globalThis.setInterval = _vlt_setInterval;
globalThis.clearInterval = _vlt_clearInterval;
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
require_lib
} from "./chunk-KUJV76HM.js";
import {
createHostContextsMap
} from "./chunk-6K6533KS.js";
import "./chunk-IN6BBUSG.js";
import {
Query,
SecurityArchive,
actual
} from "./chunk-V52UM37T.js";
import "./chunk-6F6VOBW3.js";
import "./chunk-QEOLSUUZ.js";
import {
commandUsage
} from "./chunk-32II74H6.js";
import "./chunk-C3WXW4MY.js";
import {
PackageInfoClient
} from "./chunk-JG56ZRZC.js";
import {
urlOpen
} from "./chunk-X4GYYGTU.js";
import "./chunk-CGWKWA24.js";
import {
Spec2 as Spec
} from "./chunk-MBW6A3RQ.js";
import "./chunk-YD3KKYTM.js";
import "./chunk-XGSKO6BL.js";
import "./chunk-RXFAZHP7.js";
import "./chunk-TW6XJ6XF.js";
import "./chunk-4LVU5YJD.js";
import "./chunk-TG2CR2PD.js";
import "./chunk-REP7WICP.js";
import "./chunk-XN35SAI7.js";
import "./chunk-52JFXOJH.js";
import {
error
} from "./chunk-CHD5BAMM.js";
import {
__toESM
} from "./chunk-C5WO664N.js";
// ../../src/cli-sdk/src/commands/bugs.ts
var import_hosted_git_info = __toESM(require_lib(), 1);
var { fromUrl: hostedGitInfoFromUrl } = import_hosted_git_info.default;
var usage = () => commandUsage({
command: "bugs",
usage: ["[<spec>]", "[--target=<query>]"],
description: `Open bug tracker for a package in a web browser.
Reads bug tracker information from package.json or fetches
manifest data for the specified package.`,
options: {
target: {
value: "<query>",
description: "Query selector to filter packages using DSS syntax."
}
},
examples: {
"": {
description: "Open bugs for the current package (reads local package.json)"
},
"abbrev@2.0.0": {
description: "Open bugs for a specific package version"
},
'--target=":root > *"': {
description: "List bug tracker URLs for all direct dependencies"
}
}
});
var views = {
human: (r) => {
if (Array.isArray(r)) {
let msg = "Multiple package bug trackers found:\n";
msg += r.map((item) => `\u2022 ${item.name}: ${item.url}`).join("\n");
return msg;
}
return "";
},
json: (r) => r
};
var getUrlFromManifest = (manifest) => {
const { name, bugs, repository } = manifest;
if (!name) {
throw error("No package name found");
}
let url;
if (bugs) {
if (typeof bugs === "string") {
url = bugs;
} else if (typeof bugs === "object") {
if ("url" in bugs && bugs.url) {
url = bugs.url;
} else if ("email" in bugs && bugs.email) {
url = `mailto:${bugs.email}`;
}
}
}
if (!url && repository) {
const repoUrl = typeof repository === "string" ? repository : typeof repository === "object" && "url" in repository ? repository.url : (
/* c8 ignore next */
void 0
);
if (repoUrl) {
const info = hostedGitInfoFromUrl(repoUrl.replace(/^git\+/, ""));
if (info?.bugs && typeof info.bugs === "function") {
url = info.bugs();
}
}
}
if (!url) {
url = `https://vlt.io/explore/npm/${name}/overview`;
}
return url;
};
var command = async (conf) => {
const { projectRoot, packageJson } = conf.options;
const targetOption = conf.get("target");
if (targetOption) {
const mainManifest = packageJson.maybeRead(projectRoot);
if (!mainManifest) {
throw error("No package.json found in project root", {
path: projectRoot
});
}
const graph = actual.load({
...conf.options,
mainManifest,
monorepo: conf.options.monorepo,
loadManifests: true
});
const securityArchive = Query.hasSecuritySelectors(targetOption) ? await SecurityArchive.start({
nodes: [...graph.nodes.values()]
}) : void 0;
const hostContexts = await createHostContextsMap(conf);
const query = new Query({
nodes: new Set(graph.nodes.values()),
edges: graph.edges,
importers: graph.importers,
securityArchive,
hostContexts
});
const { nodes } = await query.search(targetOption, {
signal: new AbortController().signal
});
const results = [];
for (const node of nodes) {
if (!node.manifest) continue;
const url2 = getUrlFromManifest(node.manifest);
results.push({
url: url2,
name: node.name ?? "(unknown)"
});
}
if (results.length === 0) {
throw error("No packages found matching target query", {
found: targetOption
});
}
if (results.length === 1) {
const result = results[0];
if (!result) {
throw error("Unexpected empty result");
}
await urlOpen(result.url);
return result;
}
return results;
}
const specArg = conf.positionals[0];
const manifest = conf.positionals.length === 0 ? packageJson.read(projectRoot) : specArg ? await new PackageInfoClient(conf.options).manifest(
Spec.parseArgs(specArg, conf.options)
) : (
/* c8 ignore next */
packageJson.read(projectRoot)
);
const url = getUrlFromManifest(manifest);
const { name } = manifest;
if (!name) {
throw error("No package name found");
}
await urlOpen(url);
return { url, name };
};
export {
command,
usage,
views
};
//# sourceMappingURL=bugs-NNKBOKH3.js.map