UNPKG

vlt

Version:
244 lines (239 loc) 7.72 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 { Query } from "./chunk-4HCFIDH4.js"; import { require_lz_string, startGUI } from "./chunk-CFFI3WEV.js"; import { SecurityArchive } from "./chunk-G6XZXH3U.js"; import "./chunk-WJN6TZTJ.js"; import "./chunk-3SZCEJ7Q.js"; import "./chunk-M34JYYXI.js"; import { GraphModifier, actual, asNode, humanReadableOutput, jsonOutput, mermaidOutput } from "./chunk-HFPRNHS6.js"; import "./chunk-SDAHMDDM.js"; import "./chunk-XZF5GYDF.js"; import "./chunk-FRVD5QAW.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 "./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 { error } from "./chunk-RV3EHS4P.js"; import { __toESM } from "./chunk-AECDW3EJ.js"; // ../../src/cli-sdk/src/commands/query.ts var import_lz_string = __toESM(require_lz_string(), 1); var usage = () => commandUsage({ command: "query", usage: [ "", "<query> --view=<human | json | mermaid | gui>", "<query> --expect-results=<comparison string>", "--target=<query> --view=<human | json | mermaid | gui>" ], description: `List installed dependencies matching the provided query. The vlt Dependency Selector Syntax is a CSS-like query language that allows you to filter installed dependencies using a variety of metadata in the form of CSS-like attributes, pseudo selectors & combinators. The --scope and --target options accepts DSS query selectors to filter packages. Using --scope, you can specify which packages to treat as the top-level items in the output graph. The --target option can be used as an alternative to positional arguments, it allows you to filter what dependencies to include in the output. Using both options allows you to render subgraphs of the dependency graph. Defaults to listing all dependencies of the project root and workspaces.`, examples: { [`'#foo'`]: { description: 'Query dependencies declared as "foo"' }, [`'*:workspace > *:peer'`]: { description: "Query all peer dependencies of workspaces" }, [`':project > *:attr(scripts, [build])'`]: { description: 'Query all direct project dependencies with a "build" script' }, [`'[name^="@vltpkg"]'`]: { description: 'Query packages with names starting with "@vltpkg"' }, [`'*:license(copyleft) --expect-results=0'`]: { description: "Errors if a copyleft licensed package is found" }, '--scope=":root > #dependency-name"': { description: "Defines a direct dependency as the output top-level scope" }, [`'--target="*"'`]: { description: "Query all dependencies using the target option" }, [`'--target=":workspace > *:peer"'`]: { description: "Query all peer dependencies of workspaces using target option" } }, options: { "expect-results": { value: "[number | string]", description: 'Sets an expected number of resulting items. Errors if the number of resulting items does not match the set value. Accepts a specific numeric value or a string value starting with either ">", "<", ">=" or "<=" followed by a numeric value to be compared.' }, scope: { value: "<query>", description: "Query selector to select top-level packages using the DSS query language syntax." }, target: { value: "<query>", description: "Query selector to filter packages using DSS syntax." }, view: { value: "[human | json | mermaid | gui]", description: "Output format. Defaults to human-readable or json if no tty." } } }); var validateExpectedResult = (conf, edges) => { const expectResults = conf.values["expect-results"]; if (expectResults?.startsWith(">=")) { return edges.length >= parseInt(expectResults.slice(2).trim(), 10); } else if (expectResults?.startsWith("<=")) { return edges.length <= parseInt(expectResults.slice(2).trim(), 10); } else if (expectResults?.startsWith(">")) { return edges.length > parseInt(expectResults.slice(1).trim(), 10); } else if (expectResults?.startsWith("<")) { return edges.length < parseInt(expectResults.slice(1).trim(), 10); } else if (expectResults) { return edges.length === parseInt(expectResults.trim(), 10); } return true; }; var views = { json: jsonOutput, mermaid: mermaidOutput, human: humanReadableOutput, gui: async ({ queryString }, _, conf) => { await startGUI( conf, `/explore/${import_lz_string.default.compressToEncodedURIComponent(queryString)}/overview` ); } }; var command = async (conf) => { const modifiers = GraphModifier.maybeLoad(conf.options); const monorepo = conf.options.monorepo; const mainManifest = conf.options.packageJson.read( conf.options.projectRoot ); const graph = actual.load({ ...conf.options, mainManifest, modifiers, monorepo, loadManifests: true }); const defaultQueryString = "*"; const positionalQueryString = conf.positionals[0]; const targetQueryString = conf.get("target"); const queryString = targetQueryString || positionalQueryString; const securityArchive = await SecurityArchive.start({ graph, specOptions: conf.options }); const query = new Query({ graph, specOptions: conf.options, securityArchive }); const importers = /* @__PURE__ */ new Set(); const scopeIDs = []; const scopeQueryString = conf.get("scope"); let scopeNodes; if (scopeQueryString) { const scopeQuery = new Query({ graph, specOptions: conf.options, securityArchive }); const { nodes: nodes2 } = await scopeQuery.search(scopeQueryString, { signal: new AbortController().signal }); scopeNodes = nodes2; } if (scopeQueryString && scopeNodes) { for (const queryNode of scopeNodes) { importers.add(asNode(queryNode)); } } else { if (monorepo) { for (const workspace of monorepo.filter(conf.values)) { const w = graph.nodes.get(workspace.id); if (w) { importers.add(w); scopeIDs.push(workspace.id); } } } if (importers.size === 0) { for (const importer of graph.importers) { importers.add(importer); } } } const { edges, nodes } = await query.search( queryString || defaultQueryString, { signal: new AbortController().signal, scopeIDs: scopeIDs.length > 0 ? scopeIDs : void 0 } ); if (!validateExpectedResult(conf, edges)) { throw error("Unexpected number of items", { found: edges.length, wanted: conf.values["expect-results"] }); } return { importers, edges, nodes, highlightSelection: !!(targetQueryString || positionalQueryString), queryString: queryString || defaultQueryString }; }; export { command, usage, views }; //# sourceMappingURL=query-I2MTDLVQ.js.map