main
1"use strict";
2const {
3 __export,
4 __toCommonJS,
5 __async
6} = require('./esblib.cjs');
7
8
9// src/deps.ts
10var deps_exports = {};
11__export(deps_exports, {
12 installDeps: () => installDeps,
13 parseDeps: () => parseDeps
14});
15module.exports = __toCommonJS(deps_exports);
16var import_node_module = require("module");
17var import_index = require("./index.cjs");
18var import_vendor = require("./vendor.cjs");
19function installDeps(dependencies, prefix, registry, installerType = "npm") {
20 return __async(this, null, function* () {
21 const installer = installers[installerType];
22 const packages = Object.entries(dependencies).map(
23 ([name, version]) => `${name}@${version}`
24 );
25 if (packages.length === 0) return;
26 if (!installer) {
27 throw new import_index.Fail(
28 `Unsupported installer type: ${installerType}. Supported types: ${Object.keys(installers).join(", ")}`
29 );
30 }
31 yield (0, import_index.spinner)(
32 `${installerType} i ${packages.join(" ")}`,
33 () => installer({ packages, prefix, registry })
34 );
35 });
36}
37var installers = {
38 npm: (_0) => __async(null, [_0], function* ({ packages, prefix, registry }) {
39 const flags = [
40 "--no-save",
41 "--no-audit",
42 "--no-fund",
43 prefix && `--prefix=${prefix}`,
44 registry && `--registry=${registry}`
45 ].filter(Boolean);
46 yield import_index.$`npm install ${flags} ${packages}`.nothrow();
47 })
48};
49var builtins = new Set(import_node_module.builtinModules);
50var nameRe = new RegExp("^(?<name>(@[a-z\\d-~][\\w-.~]*\\/)?[a-z\\d-~][\\w-.~]*)\\/?.*$", "i");
51var versionRe = new RegExp("^@(?<version>[~^]?(v?[\\dx*]+([-.][\\d*a-z-]+)*))", "i");
52function parseDeps(content) {
53 return (0, import_vendor.depseek)(content + "\n", { comments: true }).reduce((m, { type, value }, i, list) => {
54 if (type === "dep") {
55 const meta = list[i + 1];
56 const name = parsePackageName(value);
57 const version = (meta == null ? void 0 : meta.type) === "comment" && parseVersion(meta == null ? void 0 : meta.value.trim()) || "latest";
58 if (name) m[name] = version;
59 }
60 return m;
61 }, {});
62}
63function parsePackageName(path) {
64 var _a, _b;
65 if (!path) return;
66 const name = (_b = (_a = nameRe.exec(path)) == null ? void 0 : _a.groups) == null ? void 0 : _b.name;
67 if (name && !builtins.has(name)) return name;
68}
69function parseVersion(line) {
70 var _a, _b;
71 return ((_b = (_a = versionRe.exec(line)) == null ? void 0 : _a.groups) == null ? void 0 : _b.version) || "latest";
72}
73/* c8 ignore next 100 */
74// Annotate the CommonJS export names for ESM import in node:
750 && (module.exports = {
76 installDeps,
77 parseDeps
78});