{"version":3,"file":"deps.mjs","names":[],"sources":["../../src/commands/deps.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport consola from \"consola\";\nimport { sharedArgs, resolvePURL, withErrorHandling } from \"./shared.ts\";\n\nexport default defineCommand({\n  meta: {\n    name: \"deps\",\n    description: \"List package dependencies\",\n  },\n  args: {\n    ...sharedArgs,\n    purl: {\n      type: \"positional\",\n      description: \"Package PURL with version (e.g. pkg:npm/lodash@4.17.21, cargo/serde@1.0)\",\n      required: true,\n    },\n  },\n  async run({ args }) {\n    await withErrorHandling(async () => {\n      const [reg, name, version] = await resolvePURL(args.purl, !args[\"no-cache\"]);\n\n      if (!version) {\n        // Try to resolve latest version\n        const pkg = await reg.fetchPackage(name);\n        if (!pkg.latestVersion) {\n          consola.error(\n            \"PURL must include a version for dependency lookup, and no latest version found.\",\n          );\n          consola.info(\"Example: pkg:npm/lodash@4.17.21\");\n          process.exit(1);\n        }\n        if (!args.json) {\n          consola.info(`No version specified, using latest: ${pkg.latestVersion}`);\n        }\n        const deps = await reg.fetchDependencies(name, pkg.latestVersion);\n        outputDeps(name, pkg.latestVersion, deps, args.json);\n        return;\n      }\n\n      const deps = await reg.fetchDependencies(name, version);\n      outputDeps(name, version, deps, args.json);\n    });\n  },\n});\n\nimport type { Dependency } from \"../core/types.ts\";\n\nfunction outputDeps(\n  name: string,\n  version: string,\n  deps: readonly Dependency[],\n  json: boolean,\n): void {\n  if (json) {\n    console.log(JSON.stringify(deps, null, 2));\n    return;\n  }\n\n  consola.log(\"\");\n  consola.log(\n    `  \\x1B[1m${name}@${version}\\x1B[0m — ${deps.length} dependenc${deps.length === 1 ? \"y\" : \"ies\"}`,\n  );\n  consola.log(\"\");\n\n  const byScope = groupByScope(deps);\n\n  const scopeColors: Record<string, string> = {\n    runtime: \"\\x1B[32m\",\n    development: \"\\x1B[33m\",\n    build: \"\\x1B[35m\",\n    test: \"\\x1B[36m\",\n    optional: \"\\x1B[90m\",\n  };\n\n  for (const [scope, scopeDeps] of byScope) {\n    const color = scopeColors[scope] ?? \"\\x1B[0m\";\n    consola.log(`  ${color}${scope}\\x1B[0m (${scopeDeps.length})`);\n    for (const dep of scopeDeps) {\n      const opt = dep.optional ? \" \\x1B[90m(optional)\\x1B[0m\" : \"\";\n      consola.log(`    ${dep.name} \\x1B[90m${dep.requirements}\\x1B[0m${opt}`);\n    }\n    consola.log(\"\");\n  }\n}\n\nfunction groupByScope(deps: readonly Dependency[]): Map<string, Dependency[]> {\n  const byScope = new Map<string, Dependency[]>();\n\n  for (const dep of deps) {\n    const scope = dep.scope || \"runtime\";\n    const scopeDeps = byScope.get(scope) ?? [];\n    scopeDeps.push(dep);\n    byScope.set(scope, scopeDeps);\n  }\n\n  return byScope;\n}\n"],"mappings":";;;;;;;;AAIA,IAAA,eAAe,cAAc;CAC3B,MAAM;EACJ,MAAM;EACN,aAAa;EACd;CACD,MAAM;EACJ,GAAG;EACH,MAAM;GACJ,MAAM;GACN,aAAa;GACb,UAAU;;EAEb;CACD,MAAM,IAAI,EAAE,QAAQ;AAClB,QAAM,kBAAkB,YAAY;GAClC,MAAM,CAAC,KAAK,MAAM,WAAW,MAAM,YAAY,KAAK,MAAM,CAAC,KAAK,YAAY;AAE5E,OAAI,CAAC,SAAS;IAEZ,MAAM,MAAM,MAAM,IAAI,aAAa,KAAK;AACxC,QAAI,CAAC,IAAI,eAAe;AACtB,aAAQ,MACN,kFACD;AACD,aAAQ,KAAK,kCAAkC;AAC/C,aAAQ,KAAK,EAAE;;AAEjB,QAAI,CAAC,KAAK,KACR,SAAQ,KAAK,uCAAuC,IAAI,gBAAgB;IAE1E,MAAM,OAAO,MAAM,IAAI,kBAAkB,MAAM,IAAI,cAAc;AACjE,eAAW,MAAM,IAAI,eAAe,MAAM,KAAK,KAAK;AACpD;;AAIF,cAAW,MAAM,SADJ,MAAM,IAAI,kBAAkB,MAAM,QAAQ,EACvB,KAAK,KAAK;IAC1C;;CAEL,CAAC;AAIF,SAAS,WACP,MACA,SACA,MAC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