@yabasha/gex 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -4
- package/dist/cli-bun.mjs +916 -0
- package/dist/cli-bun.mjs.map +1 -0
- package/dist/cli-node.cjs +766 -0
- package/dist/cli-node.cjs.map +1 -0
- package/dist/cli-node.mjs +734 -0
- package/dist/cli-node.mjs.map +1 -0
- package/dist/cli.cjs +359 -302
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +356 -300
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +18 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/cli-bun.mjs
ADDED
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/runtimes/bun/commands.ts
|
|
10
|
+
import path7 from "path";
|
|
11
|
+
import { readFile as readFile6 } from "fs/promises";
|
|
12
|
+
import { Command } from "commander";
|
|
13
|
+
|
|
14
|
+
// src/shared/cli/install.ts
|
|
15
|
+
var INSTALL_COMMANDS = {
|
|
16
|
+
npm: {
|
|
17
|
+
global: ["i", "-g"],
|
|
18
|
+
local: ["i"],
|
|
19
|
+
dev: ["i", "-D"]
|
|
20
|
+
},
|
|
21
|
+
bun: {
|
|
22
|
+
global: ["add", "-g"],
|
|
23
|
+
local: ["add"],
|
|
24
|
+
dev: ["add", "-d"]
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var MAX_BUFFER = 10 * 1024 * 1024;
|
|
28
|
+
function formatSpec(pkg) {
|
|
29
|
+
return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
|
|
30
|
+
}
|
|
31
|
+
async function getExecFileAsync() {
|
|
32
|
+
const { execFile } = await import("child_process");
|
|
33
|
+
const { promisify: promisify3 } = await import("util");
|
|
34
|
+
return promisify3(execFile);
|
|
35
|
+
}
|
|
36
|
+
async function installFromReport(report, options) {
|
|
37
|
+
const opts = typeof options === "string" ? { cwd: options } : options;
|
|
38
|
+
const { cwd, packageManager = "npm" } = opts;
|
|
39
|
+
const globalPkgs = report.global_packages.map(formatSpec).filter(Boolean);
|
|
40
|
+
const localPkgs = report.local_dependencies.map(formatSpec).filter(Boolean);
|
|
41
|
+
const devPkgs = report.local_dev_dependencies.map(formatSpec).filter(Boolean);
|
|
42
|
+
if (globalPkgs.length === 0 && localPkgs.length === 0 && devPkgs.length === 0) {
|
|
43
|
+
console.log("No packages to install from report.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const execFileAsync = await getExecFileAsync();
|
|
47
|
+
const cmd = INSTALL_COMMANDS[packageManager];
|
|
48
|
+
const binary = packageManager === "bun" ? "bun" : "npm";
|
|
49
|
+
if (globalPkgs.length > 0) {
|
|
50
|
+
console.log(`Installing global: ${globalPkgs.join(" ")}`);
|
|
51
|
+
await execFileAsync(binary, [...cmd.global, ...globalPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
52
|
+
}
|
|
53
|
+
if (localPkgs.length > 0) {
|
|
54
|
+
console.log(`Installing local deps: ${localPkgs.join(" ")}`);
|
|
55
|
+
await execFileAsync(binary, [...cmd.local, ...localPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
56
|
+
}
|
|
57
|
+
if (devPkgs.length > 0) {
|
|
58
|
+
console.log(`Installing local devDeps: ${devPkgs.join(" ")}`);
|
|
59
|
+
await execFileAsync(binary, [...cmd.dev, ...devPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function printFromReport(report) {
|
|
63
|
+
const lines = [];
|
|
64
|
+
if (report.global_packages.length > 0) {
|
|
65
|
+
lines.push("Global Packages:");
|
|
66
|
+
for (const p of report.global_packages) {
|
|
67
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (report.local_dependencies.length > 0) {
|
|
71
|
+
if (lines.length) lines.push("");
|
|
72
|
+
lines.push("Local Dependencies:");
|
|
73
|
+
for (const p of report.local_dependencies) {
|
|
74
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (report.local_dev_dependencies.length > 0) {
|
|
78
|
+
if (lines.length) lines.push("");
|
|
79
|
+
lines.push("Local Dev Dependencies:");
|
|
80
|
+
for (const p of report.local_dev_dependencies) {
|
|
81
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (lines.length === 0) {
|
|
85
|
+
lines.push("(no packages found in report)");
|
|
86
|
+
}
|
|
87
|
+
console.log(lines.join("\n"));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/shared/cli/output.ts
|
|
91
|
+
import path from "path";
|
|
92
|
+
|
|
93
|
+
// src/shared/report/json.ts
|
|
94
|
+
function renderJson(report) {
|
|
95
|
+
const r = {
|
|
96
|
+
...report,
|
|
97
|
+
global_packages: [...report.global_packages].sort((a, b) => a.name.localeCompare(b.name)),
|
|
98
|
+
local_dependencies: [...report.local_dependencies].sort((a, b) => a.name.localeCompare(b.name)),
|
|
99
|
+
local_dev_dependencies: [...report.local_dev_dependencies].sort(
|
|
100
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
101
|
+
)
|
|
102
|
+
};
|
|
103
|
+
return JSON.stringify(r, null, 2);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/shared/report/md.ts
|
|
107
|
+
function table(headers, rows) {
|
|
108
|
+
const header = `| ${headers.join(" | ")} |`;
|
|
109
|
+
const sep = `| ${headers.map(() => "---").join(" | ")} |`;
|
|
110
|
+
const body = rows.map((r) => `| ${r.join(" | ")} |`).join("\n");
|
|
111
|
+
return [header, sep, body].filter(Boolean).join("\n");
|
|
112
|
+
}
|
|
113
|
+
function renderMarkdown(report) {
|
|
114
|
+
const lines = [];
|
|
115
|
+
lines.push("# GEX Report");
|
|
116
|
+
lines.push("");
|
|
117
|
+
if (report.project_name || report.project_version || report.project_description || report.project_homepage || report.project_bugs) {
|
|
118
|
+
lines.push("## Project Metadata");
|
|
119
|
+
if (report.project_name) lines.push(`- Name: ${report.project_name}`);
|
|
120
|
+
if (report.project_version) lines.push(`- Version: ${report.project_version}`);
|
|
121
|
+
if (report.project_description)
|
|
122
|
+
lines.push(`- Description: ${report.project_description}`);
|
|
123
|
+
if (report.project_homepage)
|
|
124
|
+
lines.push(`- Homepage: ${report.project_homepage}`);
|
|
125
|
+
if (report.project_bugs) lines.push(`- Bugs: ${report.project_bugs}`);
|
|
126
|
+
lines.push("");
|
|
127
|
+
}
|
|
128
|
+
if (report.global_packages.length > 0) {
|
|
129
|
+
lines.push("## Global Packages");
|
|
130
|
+
const rows = report.global_packages.map((p) => [p.name, p.version || "", p.resolved_path || ""]);
|
|
131
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
132
|
+
lines.push("");
|
|
133
|
+
}
|
|
134
|
+
if (report.local_dependencies.length > 0) {
|
|
135
|
+
lines.push("## Local Dependencies");
|
|
136
|
+
const rows = report.local_dependencies.map((p) => [
|
|
137
|
+
p.name,
|
|
138
|
+
p.version || "",
|
|
139
|
+
p.resolved_path || ""
|
|
140
|
+
]);
|
|
141
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
142
|
+
lines.push("");
|
|
143
|
+
}
|
|
144
|
+
if (report.local_dev_dependencies.length > 0) {
|
|
145
|
+
lines.push("## Local Dev Dependencies");
|
|
146
|
+
const rows = report.local_dev_dependencies.map((p) => [
|
|
147
|
+
p.name,
|
|
148
|
+
p.version || "",
|
|
149
|
+
p.resolved_path || ""
|
|
150
|
+
]);
|
|
151
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
152
|
+
lines.push("");
|
|
153
|
+
}
|
|
154
|
+
lines.push("---");
|
|
155
|
+
lines.push("_Generated by GEX_");
|
|
156
|
+
return lines.join("\n");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/shared/cli/output.ts
|
|
160
|
+
async function outputReport(report, format, outFile, markdownExtras) {
|
|
161
|
+
const content = format === "json" ? renderJson(report) : renderMarkdown({ ...report, ...markdownExtras || {} });
|
|
162
|
+
if (outFile) {
|
|
163
|
+
const outDir = path.dirname(outFile);
|
|
164
|
+
const { mkdir, writeFile } = await import("fs/promises");
|
|
165
|
+
await mkdir(outDir, { recursive: true });
|
|
166
|
+
await writeFile(outFile, content, "utf8");
|
|
167
|
+
console.log(`Wrote report to ${outFile}`);
|
|
168
|
+
} else {
|
|
169
|
+
console.log(content);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/shared/cli/parser.ts
|
|
174
|
+
import { readFile } from "fs/promises";
|
|
175
|
+
import path2 from "path";
|
|
176
|
+
function isMarkdownReportFile(filePath) {
|
|
177
|
+
const ext = path2.extname(filePath).toLowerCase();
|
|
178
|
+
return ext === ".md" || ext === ".markdown";
|
|
179
|
+
}
|
|
180
|
+
function parseMarkdownPackagesTable(lines, startIndex) {
|
|
181
|
+
const rows = [];
|
|
182
|
+
if (!lines[startIndex] || !lines[startIndex].trim().startsWith("|")) return rows;
|
|
183
|
+
let i = startIndex + 2;
|
|
184
|
+
while (i < lines.length && lines[i].trim().startsWith("|")) {
|
|
185
|
+
const cols = lines[i].split("|").map((c) => c.trim()).filter((_, idx, arr) => !(idx === 0 || idx === arr.length - 1));
|
|
186
|
+
const [name = "", version = "", resolved_path = ""] = cols;
|
|
187
|
+
if (name) rows.push({ name, version, resolved_path });
|
|
188
|
+
i++;
|
|
189
|
+
}
|
|
190
|
+
return rows;
|
|
191
|
+
}
|
|
192
|
+
function parseMarkdownReport(md) {
|
|
193
|
+
const lines = md.split(/\r?\n/);
|
|
194
|
+
const findSection = (title) => lines.findIndex((l) => l.trim().toLowerCase() === `## ${title}`.toLowerCase());
|
|
195
|
+
const parseSection = (idx) => {
|
|
196
|
+
if (idx < 0) return [];
|
|
197
|
+
let i = idx + 1;
|
|
198
|
+
while (i < lines.length && !lines[i].trim().startsWith("|")) i++;
|
|
199
|
+
return parseMarkdownPackagesTable(lines, i);
|
|
200
|
+
};
|
|
201
|
+
const global_packages = parseSection(findSection("Global Packages"));
|
|
202
|
+
const local_dependencies = parseSection(findSection("Local Dependencies"));
|
|
203
|
+
const local_dev_dependencies = parseSection(findSection("Local Dev Dependencies"));
|
|
204
|
+
const report = {
|
|
205
|
+
report_version: "1.0",
|
|
206
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
207
|
+
tool_version: "unknown",
|
|
208
|
+
global_packages,
|
|
209
|
+
local_dependencies,
|
|
210
|
+
local_dev_dependencies
|
|
211
|
+
};
|
|
212
|
+
return report;
|
|
213
|
+
}
|
|
214
|
+
async function loadReportFromFile(reportPath) {
|
|
215
|
+
const raw = await readFile(reportPath, "utf8");
|
|
216
|
+
if (isMarkdownReportFile(reportPath) || raw.startsWith("# GEX Report")) {
|
|
217
|
+
return parseMarkdownReport(raw);
|
|
218
|
+
}
|
|
219
|
+
return JSON.parse(raw);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/shared/npm-cli.ts
|
|
223
|
+
import { promisify } from "util";
|
|
224
|
+
async function getExecFileAsync2() {
|
|
225
|
+
const { execFile } = await import("child_process");
|
|
226
|
+
return promisify(execFile);
|
|
227
|
+
}
|
|
228
|
+
function formatNpmError(error, commandLabel) {
|
|
229
|
+
const stderr = typeof error?.stderr === "string" ? error.stderr.trim() : "";
|
|
230
|
+
const message = stderr || error?.message || `${commandLabel} failed`;
|
|
231
|
+
return new Error(`${commandLabel} failed: ${message}`);
|
|
232
|
+
}
|
|
233
|
+
async function npmViewVersion(packageName) {
|
|
234
|
+
try {
|
|
235
|
+
const execFileAsync = await getExecFileAsync2();
|
|
236
|
+
const { stdout } = await execFileAsync("npm", ["view", packageName, "version", "--json"], {
|
|
237
|
+
maxBuffer: 5 * 1024 * 1024
|
|
238
|
+
});
|
|
239
|
+
const parsed = JSON.parse(stdout);
|
|
240
|
+
if (typeof parsed === "string") return parsed;
|
|
241
|
+
if (Array.isArray(parsed)) return parsed[parsed.length - 1] ?? "";
|
|
242
|
+
return "";
|
|
243
|
+
} catch (error) {
|
|
244
|
+
throw formatNpmError(error, `npm view ${packageName}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/shared/cli/loader.ts
|
|
249
|
+
var frames = ["-", "\\", "|", "/"];
|
|
250
|
+
function createLoader(message) {
|
|
251
|
+
if (!process.stdout.isTTY) {
|
|
252
|
+
console.log(`${message}...`);
|
|
253
|
+
return {
|
|
254
|
+
stop(finalMessage) {
|
|
255
|
+
if (finalMessage) console.log(finalMessage);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
let index = 0;
|
|
260
|
+
const interval = setInterval(() => {
|
|
261
|
+
const frame = frames[index % frames.length];
|
|
262
|
+
index += 1;
|
|
263
|
+
process.stdout.write(`\r${message} ${frame}`);
|
|
264
|
+
}, 80);
|
|
265
|
+
return {
|
|
266
|
+
stop(finalMessage) {
|
|
267
|
+
clearInterval(interval);
|
|
268
|
+
process.stdout.write("\r");
|
|
269
|
+
if (finalMessage) {
|
|
270
|
+
console.log(finalMessage);
|
|
271
|
+
} else {
|
|
272
|
+
process.stdout.write("\x1B[2K");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/shared/cli/outdated.ts
|
|
279
|
+
function normalizeUpdateSelection(value) {
|
|
280
|
+
if (value === void 0) {
|
|
281
|
+
return { shouldUpdate: false, updateAll: false, packages: [] };
|
|
282
|
+
}
|
|
283
|
+
if (value === true) {
|
|
284
|
+
return { shouldUpdate: true, updateAll: true, packages: [] };
|
|
285
|
+
}
|
|
286
|
+
const packages = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
|
|
287
|
+
const normalized = packages.flatMap((entry) => String(entry).split(",").map((part) => part.trim())).filter(Boolean);
|
|
288
|
+
return {
|
|
289
|
+
shouldUpdate: true,
|
|
290
|
+
updateAll: false,
|
|
291
|
+
packages: normalized
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function formatOutdatedTable(entries) {
|
|
295
|
+
const headers = ["Name", "Current", "Wanted", "Latest", "Type"];
|
|
296
|
+
const rows = entries.map((entry) => [
|
|
297
|
+
entry.name,
|
|
298
|
+
entry.current || "-",
|
|
299
|
+
entry.wanted || "-",
|
|
300
|
+
entry.latest || "-",
|
|
301
|
+
entry.type || "-"
|
|
302
|
+
]);
|
|
303
|
+
const widths = headers.map(
|
|
304
|
+
(header, index) => Math.max(header.length, ...rows.map((row) => row[index].length))
|
|
305
|
+
);
|
|
306
|
+
const formatRow = (columns) => columns.map((col, idx) => col.padEnd(widths[idx], " ")).join(" ");
|
|
307
|
+
const lines = [formatRow(headers), formatRow(widths.map((w) => "-".repeat(w)))];
|
|
308
|
+
for (const row of rows) {
|
|
309
|
+
lines.push(formatRow(row));
|
|
310
|
+
}
|
|
311
|
+
return lines.join("\n");
|
|
312
|
+
}
|
|
313
|
+
async function handleOutdatedWorkflow(opts) {
|
|
314
|
+
if (!opts.checkOutdated && !opts.selection.shouldUpdate) {
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
let fetchLoader;
|
|
318
|
+
if (opts.checkOutdated || opts.selection.shouldUpdate) {
|
|
319
|
+
fetchLoader = createLoader("Checking for outdated packages");
|
|
320
|
+
}
|
|
321
|
+
const outdated = await opts.fetchOutdated();
|
|
322
|
+
fetchLoader?.stop("Finished checking outdated packages.");
|
|
323
|
+
if (opts.checkOutdated) {
|
|
324
|
+
if (outdated.length === 0) {
|
|
325
|
+
console.log(`All ${opts.contextLabel} packages are up to date.`);
|
|
326
|
+
} else {
|
|
327
|
+
console.log(formatOutdatedTable(outdated));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (opts.selection.shouldUpdate && opts.updateRunner) {
|
|
331
|
+
const packagesToUpdate = opts.selection.updateAll ? outdated.map((entry) => entry.name) : opts.selection.packages;
|
|
332
|
+
if (!packagesToUpdate || packagesToUpdate.length === 0) {
|
|
333
|
+
if (opts.selection.updateAll) {
|
|
334
|
+
console.log("No outdated packages to update.");
|
|
335
|
+
} else {
|
|
336
|
+
console.log("No packages were specified for updating.");
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
const updateLoader = createLoader("Updating packages");
|
|
340
|
+
await opts.updateRunner(packagesToUpdate);
|
|
341
|
+
updateLoader.stop("Finished updating packages.");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (opts.checkOutdated || opts.selection.shouldUpdate) {
|
|
345
|
+
if (!opts.outFile) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
async function resolveOutdatedWithNpmView(packages) {
|
|
352
|
+
const results = [];
|
|
353
|
+
for (const pkg of packages) {
|
|
354
|
+
try {
|
|
355
|
+
const latest = await npmViewVersion(pkg.name);
|
|
356
|
+
if (latest && pkg.current && latest !== pkg.current) {
|
|
357
|
+
results.push({
|
|
358
|
+
name: pkg.name,
|
|
359
|
+
current: pkg.current,
|
|
360
|
+
wanted: pkg.declared || latest,
|
|
361
|
+
latest,
|
|
362
|
+
type: pkg.type
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return results;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/shared/cli/utils.ts
|
|
373
|
+
import { existsSync } from "fs";
|
|
374
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
375
|
+
import path3 from "path";
|
|
376
|
+
import { fileURLToPath } from "url";
|
|
377
|
+
function getPkgJsonPath() {
|
|
378
|
+
let startDir;
|
|
379
|
+
try {
|
|
380
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
381
|
+
startDir = path3.dirname(__filename);
|
|
382
|
+
} catch {
|
|
383
|
+
startDir = typeof __dirname !== "undefined" ? __dirname : process.cwd();
|
|
384
|
+
}
|
|
385
|
+
return findPackageJson(startDir);
|
|
386
|
+
}
|
|
387
|
+
function findPackageJson(startDir) {
|
|
388
|
+
let current = startDir;
|
|
389
|
+
const maxDepth = 6;
|
|
390
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
391
|
+
const candidate = path3.resolve(current, "package.json");
|
|
392
|
+
if (existsSync(candidate)) {
|
|
393
|
+
return candidate;
|
|
394
|
+
}
|
|
395
|
+
const parent = path3.dirname(current);
|
|
396
|
+
if (parent === current) break;
|
|
397
|
+
current = parent;
|
|
398
|
+
}
|
|
399
|
+
return path3.resolve(process.cwd(), "package.json");
|
|
400
|
+
}
|
|
401
|
+
async function getToolVersion() {
|
|
402
|
+
try {
|
|
403
|
+
const pkgPath = getPkgJsonPath();
|
|
404
|
+
const raw = await readFile2(pkgPath, "utf8");
|
|
405
|
+
const pkg = JSON.parse(raw);
|
|
406
|
+
return pkg.version || "0.0.0";
|
|
407
|
+
} catch {
|
|
408
|
+
return "0.0.0";
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
var ASCII_BANNER = String.raw`
|
|
412
|
+
________ __
|
|
413
|
+
/ _____/ ____ _____/ |_ ____ ____
|
|
414
|
+
/ \ ___ / _ \ / _ \ __\/ __ \ / \
|
|
415
|
+
\ \_\ ( <_> | <_> ) | \ ___/| | \
|
|
416
|
+
\______ /\____/ \____/|__| \___ >___| /
|
|
417
|
+
\/ \/ \/
|
|
418
|
+
GEX
|
|
419
|
+
`;
|
|
420
|
+
|
|
421
|
+
// src/runtimes/bun/report.ts
|
|
422
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
423
|
+
import path6 from "path";
|
|
424
|
+
|
|
425
|
+
// src/shared/transform.ts
|
|
426
|
+
import path4 from "path";
|
|
427
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
428
|
+
function toPkgArray(obj) {
|
|
429
|
+
if (!obj) return [];
|
|
430
|
+
return Object.keys(obj).map((name) => ({ name, node: obj[name] })).filter((p) => p && p.node);
|
|
431
|
+
}
|
|
432
|
+
async function buildReportFromNpmTree(tree, opts) {
|
|
433
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
434
|
+
const report = {
|
|
435
|
+
report_version: "1.0",
|
|
436
|
+
timestamp,
|
|
437
|
+
tool_version: opts.toolVersion,
|
|
438
|
+
global_packages: [],
|
|
439
|
+
local_dependencies: [],
|
|
440
|
+
local_dev_dependencies: []
|
|
441
|
+
};
|
|
442
|
+
if (opts.context === "local") {
|
|
443
|
+
let pkgMeta = null;
|
|
444
|
+
try {
|
|
445
|
+
const pkgJsonPath = path4.join(opts.cwd || process.cwd(), "package.json");
|
|
446
|
+
const raw = await readFile3(pkgJsonPath, "utf8");
|
|
447
|
+
pkgMeta = JSON.parse(raw);
|
|
448
|
+
} catch {
|
|
449
|
+
}
|
|
450
|
+
if (pkgMeta?.name) report.project_name = pkgMeta.name;
|
|
451
|
+
if (pkgMeta?.version) report.project_version = pkgMeta.version;
|
|
452
|
+
const depsObj = tree?.dependencies;
|
|
453
|
+
const devDepsObj = tree?.devDependencies;
|
|
454
|
+
const prodItems = toPkgArray(depsObj);
|
|
455
|
+
const treeDevItems = toPkgArray(devDepsObj);
|
|
456
|
+
if (treeDevItems.length > 0) {
|
|
457
|
+
for (const { name, node } of treeDevItems) {
|
|
458
|
+
const version = node && node.version || "";
|
|
459
|
+
const resolvedPath = node && node.path || path4.join(opts.cwd || process.cwd(), "node_modules", name);
|
|
460
|
+
report.local_dev_dependencies.push({ name, version, resolved_path: resolvedPath });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const devKeys = treeDevItems.length > 0 ? new Set(treeDevItems.map((entry) => entry.name)) : new Set(Object.keys(pkgMeta?.devDependencies || {}));
|
|
464
|
+
for (const { name, node } of prodItems) {
|
|
465
|
+
const version = node && node.version || "";
|
|
466
|
+
const resolvedPath = node && node.path || path4.join(opts.cwd || process.cwd(), "node_modules", name);
|
|
467
|
+
const pkg = { name, version, resolved_path: resolvedPath };
|
|
468
|
+
if (!treeDevItems.length && devKeys.has(name)) {
|
|
469
|
+
report.local_dev_dependencies.push(pkg);
|
|
470
|
+
} else {
|
|
471
|
+
report.local_dependencies.push(pkg);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
report.local_dependencies.sort((a, b) => a.name.localeCompare(b.name));
|
|
475
|
+
report.local_dev_dependencies.sort((a, b) => a.name.localeCompare(b.name));
|
|
476
|
+
} else if (opts.context === "global") {
|
|
477
|
+
const depsObj = tree?.dependencies;
|
|
478
|
+
const items = toPkgArray(depsObj);
|
|
479
|
+
for (const { name, node } of items) {
|
|
480
|
+
const version = node && node.version || "";
|
|
481
|
+
const resolvedPath = node && node.path || path4.join(opts.globalRoot || "", name);
|
|
482
|
+
const pkg = { name, version, resolved_path: resolvedPath };
|
|
483
|
+
report.global_packages.push(pkg);
|
|
484
|
+
}
|
|
485
|
+
report.global_packages.sort((a, b) => a.name.localeCompare(b.name));
|
|
486
|
+
}
|
|
487
|
+
if (opts.includeTree) {
|
|
488
|
+
report.tree = tree;
|
|
489
|
+
}
|
|
490
|
+
return report;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/runtimes/bun/package-manager.ts
|
|
494
|
+
import path5 from "path";
|
|
495
|
+
import { constants as fsConstants } from "fs";
|
|
496
|
+
import { access, readFile as readFile4, readdir, stat } from "fs/promises";
|
|
497
|
+
import { promisify as promisify2 } from "util";
|
|
498
|
+
var IGNORED_ENTRIES = /* @__PURE__ */ new Set([".bin"]);
|
|
499
|
+
async function bunPmLs(options = {}) {
|
|
500
|
+
if (options.global) {
|
|
501
|
+
const root = await bunPmRootGlobal();
|
|
502
|
+
const manifest2 = await readJson(path5.join(path5.dirname(root), "package.json"));
|
|
503
|
+
const selections2 = buildSelections(manifest2, { includeDev: false });
|
|
504
|
+
const dependencies2 = selections2.prod.size > 0 ? await collectPackagesForNames(root, mapSelections(selections2.prod)) : await collectPackagesFromNodeModules(root);
|
|
505
|
+
return { dependencies: dependencies2, node_modules_path: root };
|
|
506
|
+
}
|
|
507
|
+
const cwd = options.cwd || process.cwd();
|
|
508
|
+
const nodeModulesPath = await bunPmRootLocal(cwd);
|
|
509
|
+
const manifest = await readJson(path5.join(cwd, "package.json"));
|
|
510
|
+
const includeDev = !options.omitDev;
|
|
511
|
+
const selections = buildSelections(manifest, { includeDev });
|
|
512
|
+
const dependencies = selections.prod.size > 0 ? await collectPackagesForNames(nodeModulesPath, mapSelections(selections.prod)) : await collectPackagesFromNodeModules(nodeModulesPath);
|
|
513
|
+
let devDependencies;
|
|
514
|
+
if (includeDev) {
|
|
515
|
+
if (selections.dev.size > 0) {
|
|
516
|
+
devDependencies = await collectPackagesForNames(
|
|
517
|
+
nodeModulesPath,
|
|
518
|
+
mapSelections(selections.dev)
|
|
519
|
+
);
|
|
520
|
+
} else {
|
|
521
|
+
devDependencies = {};
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return { dependencies, devDependencies, node_modules_path: nodeModulesPath };
|
|
525
|
+
}
|
|
526
|
+
async function bunPmRootGlobal() {
|
|
527
|
+
if (process.env.GEX_BUN_GLOBAL_ROOT) {
|
|
528
|
+
return process.env.GEX_BUN_GLOBAL_ROOT;
|
|
529
|
+
}
|
|
530
|
+
const candidates = getGlobalRootCandidates();
|
|
531
|
+
for (const candidate of candidates) {
|
|
532
|
+
if (candidate && await pathExists(candidate)) {
|
|
533
|
+
return candidate;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return candidates.find((c) => Boolean(c)) || path5.join(process.env.HOME || process.cwd(), ".bun", "install", "global", "node_modules");
|
|
537
|
+
}
|
|
538
|
+
async function bunPmRootLocal(cwd = process.cwd()) {
|
|
539
|
+
if (process.env.GEX_BUN_LOCAL_ROOT) {
|
|
540
|
+
return process.env.GEX_BUN_LOCAL_ROOT;
|
|
541
|
+
}
|
|
542
|
+
return path5.join(cwd, "node_modules");
|
|
543
|
+
}
|
|
544
|
+
async function bunUpdate(options) {
|
|
545
|
+
const execFileAsync = await getExecFileAsync3();
|
|
546
|
+
const packages = options.packages && options.packages.length > 0 ? options.packages : [];
|
|
547
|
+
if (options.global) {
|
|
548
|
+
const targets = packages.length > 0 ? packages : [];
|
|
549
|
+
const list = targets.length > 0 ? targets : [];
|
|
550
|
+
const cmdPackages = list.map((name) => `${name}@latest`);
|
|
551
|
+
try {
|
|
552
|
+
await execFileAsync("bun", ["add", "-g", ...cmdPackages], {
|
|
553
|
+
cwd: options.cwd,
|
|
554
|
+
maxBuffer: 10 * 1024 * 1024
|
|
555
|
+
});
|
|
556
|
+
} catch (error) {
|
|
557
|
+
const stderr = typeof error?.stderr === "string" ? error.stderr.trim() : "";
|
|
558
|
+
throw new Error(`bun add -g failed: ${stderr || error?.message || "unknown error"}`);
|
|
559
|
+
}
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const args = ["update"];
|
|
563
|
+
if (packages.length > 0) args.push(...packages);
|
|
564
|
+
try {
|
|
565
|
+
await execFileAsync("bun", args, {
|
|
566
|
+
cwd: options.cwd,
|
|
567
|
+
maxBuffer: 10 * 1024 * 1024
|
|
568
|
+
});
|
|
569
|
+
} catch (error) {
|
|
570
|
+
const stderr = typeof error?.stderr === "string" ? error.stderr.trim() : "";
|
|
571
|
+
throw new Error(`bun update failed: ${stderr || error?.message || "unknown error"}`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
async function collectPackagesForNames(nodeModulesPath, packages) {
|
|
575
|
+
const result = {};
|
|
576
|
+
await Promise.all(
|
|
577
|
+
packages.map(async ({ name, declared }) => {
|
|
578
|
+
const pkgDir = packageDir(nodeModulesPath, name);
|
|
579
|
+
const manifest = await readJson(path5.join(pkgDir, "package.json"));
|
|
580
|
+
const pkgName = typeof manifest?.name === "string" ? manifest.name : name;
|
|
581
|
+
const version = typeof manifest?.version === "string" ? manifest.version : declared || "";
|
|
582
|
+
result[pkgName] = { version, path: pkgDir };
|
|
583
|
+
})
|
|
584
|
+
);
|
|
585
|
+
return result;
|
|
586
|
+
}
|
|
587
|
+
async function collectPackagesFromNodeModules(root) {
|
|
588
|
+
const result = {};
|
|
589
|
+
const entries = await safeReadDir(root);
|
|
590
|
+
for (const entry of entries) {
|
|
591
|
+
if (!entry || !entry.name || entry.name.startsWith(".") || IGNORED_ENTRIES.has(entry.name)) {
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
const entryPath = path5.join(root, entry.name);
|
|
595
|
+
if (!await isDir(entry, entryPath)) continue;
|
|
596
|
+
if (entry.name.startsWith("@")) {
|
|
597
|
+
const scopedEntries = await safeReadDir(entryPath);
|
|
598
|
+
for (const scopedEntry of scopedEntries) {
|
|
599
|
+
if (!scopedEntry || !scopedEntry.name || scopedEntry.name.startsWith(".")) continue;
|
|
600
|
+
const scopedPath = path5.join(entryPath, scopedEntry.name);
|
|
601
|
+
if (!await isDir(scopedEntry, scopedPath)) continue;
|
|
602
|
+
const manifest = await readJson(path5.join(scopedPath, "package.json"));
|
|
603
|
+
const pkgName = typeof manifest?.name === "string" ? manifest.name : `${entry.name}/${scopedEntry.name}`;
|
|
604
|
+
const version = typeof manifest?.version === "string" ? manifest.version : "";
|
|
605
|
+
result[pkgName] = { version, path: scopedPath };
|
|
606
|
+
}
|
|
607
|
+
} else {
|
|
608
|
+
const manifest = await readJson(path5.join(entryPath, "package.json"));
|
|
609
|
+
const pkgName = typeof manifest?.name === "string" ? manifest.name : entry.name;
|
|
610
|
+
const version = typeof manifest?.version === "string" ? manifest.version : "";
|
|
611
|
+
result[pkgName] = { version, path: entryPath };
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return result;
|
|
615
|
+
}
|
|
616
|
+
async function readJson(file) {
|
|
617
|
+
try {
|
|
618
|
+
const raw = await readFile4(file, "utf8");
|
|
619
|
+
return JSON.parse(raw);
|
|
620
|
+
} catch {
|
|
621
|
+
return null;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function packageDir(root, packageName) {
|
|
625
|
+
const segments = packageName.startsWith("@") ? packageName.split("/") : [packageName];
|
|
626
|
+
return path5.join(root, ...segments);
|
|
627
|
+
}
|
|
628
|
+
function buildSelections(manifest, { includeDev }) {
|
|
629
|
+
const prod = /* @__PURE__ */ new Map();
|
|
630
|
+
const dev = /* @__PURE__ */ new Map();
|
|
631
|
+
const addAll = (target, record) => {
|
|
632
|
+
if (!record) return;
|
|
633
|
+
for (const [name, range] of Object.entries(record)) {
|
|
634
|
+
if (!target.has(name)) {
|
|
635
|
+
target.set(name, range);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
addAll(prod, manifest?.dependencies);
|
|
640
|
+
addAll(prod, manifest?.optionalDependencies);
|
|
641
|
+
if (includeDev) addAll(dev, manifest?.devDependencies);
|
|
642
|
+
return { prod, dev };
|
|
643
|
+
}
|
|
644
|
+
function mapSelections(map) {
|
|
645
|
+
return Array.from(map.entries()).map(([name, declared]) => ({ name, declared }));
|
|
646
|
+
}
|
|
647
|
+
async function safeReadDir(dir) {
|
|
648
|
+
try {
|
|
649
|
+
return await readdir(dir, { withFileTypes: true });
|
|
650
|
+
} catch {
|
|
651
|
+
return [];
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
async function isDir(entry, fullPath) {
|
|
655
|
+
if (entry.isDirectory()) return true;
|
|
656
|
+
if (entry.isSymbolicLink()) {
|
|
657
|
+
try {
|
|
658
|
+
const stats = await stat(fullPath);
|
|
659
|
+
return stats.isDirectory();
|
|
660
|
+
} catch {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
async function pathExists(target) {
|
|
667
|
+
try {
|
|
668
|
+
await access(target, fsConstants.R_OK);
|
|
669
|
+
return true;
|
|
670
|
+
} catch {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function getGlobalRootCandidates() {
|
|
675
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
676
|
+
const bunInstall = process.env.BUN_INSTALL || (process.env.HOME ? path5.join(process.env.HOME, ".bun") : void 0);
|
|
677
|
+
const maybeAdd = (value) => {
|
|
678
|
+
if (value) candidates.add(value);
|
|
679
|
+
};
|
|
680
|
+
if (bunInstall) {
|
|
681
|
+
maybeAdd(path5.join(bunInstall, "install", "global", "node_modules"));
|
|
682
|
+
maybeAdd(path5.join(bunInstall, "global", "node_modules"));
|
|
683
|
+
}
|
|
684
|
+
if (process.env.XDG_DATA_HOME) {
|
|
685
|
+
maybeAdd(path5.join(process.env.XDG_DATA_HOME, "bun", "install", "global", "node_modules"));
|
|
686
|
+
}
|
|
687
|
+
maybeAdd("/usr/local/share/bun/global/node_modules");
|
|
688
|
+
maybeAdd("/opt/homebrew/var/bun/install/global/node_modules");
|
|
689
|
+
return Array.from(candidates);
|
|
690
|
+
}
|
|
691
|
+
async function getExecFileAsync3() {
|
|
692
|
+
const { execFile } = await import("child_process");
|
|
693
|
+
return promisify2(execFile);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// src/runtimes/bun/report.ts
|
|
697
|
+
async function produceReport(ctx, options) {
|
|
698
|
+
const toolVersion = await getToolVersion();
|
|
699
|
+
const cwd = options.cwd || process.cwd();
|
|
700
|
+
const tree = await bunPmLs({
|
|
701
|
+
global: ctx === "global",
|
|
702
|
+
omitDev: ctx === "local" ? Boolean(options.omitDev) : false,
|
|
703
|
+
cwd
|
|
704
|
+
});
|
|
705
|
+
const nodeModulesPath = tree?.node_modules_path;
|
|
706
|
+
let project_description;
|
|
707
|
+
let project_homepage;
|
|
708
|
+
let project_bugs;
|
|
709
|
+
if (ctx === "local") {
|
|
710
|
+
try {
|
|
711
|
+
const pkgRaw = await readFile5(path6.join(cwd, "package.json"), "utf8");
|
|
712
|
+
const pkg = JSON.parse(pkgRaw);
|
|
713
|
+
project_description = pkg.description;
|
|
714
|
+
project_homepage = pkg.homepage;
|
|
715
|
+
if (typeof pkg.bugs === "string") project_bugs = pkg.bugs;
|
|
716
|
+
else if (pkg.bugs && typeof pkg.bugs.url === "string") project_bugs = pkg.bugs.url;
|
|
717
|
+
} catch {
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
const resolvedRoot = nodeModulesPath ? nodeModulesPath : ctx === "global" ? await bunPmRootGlobal().catch(() => void 0) : await bunPmRootLocal(cwd).catch(() => `${cwd}/node_modules`);
|
|
721
|
+
const report = await buildReportFromNpmTree(tree, {
|
|
722
|
+
context: ctx,
|
|
723
|
+
includeTree: Boolean(options.fullTree),
|
|
724
|
+
omitDev: Boolean(options.omitDev),
|
|
725
|
+
cwd,
|
|
726
|
+
toolVersion,
|
|
727
|
+
globalRoot: resolvedRoot
|
|
728
|
+
});
|
|
729
|
+
const markdownExtras = { project_description, project_homepage, project_bugs };
|
|
730
|
+
return { report, markdownExtras };
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/runtimes/bun/commands.ts
|
|
734
|
+
function addCommonOptions(cmd, { allowOmitDev }) {
|
|
735
|
+
cmd.option(
|
|
736
|
+
"-f, --output-format <format>",
|
|
737
|
+
"Output format: md or json",
|
|
738
|
+
(val) => val === "md" ? "md" : "json",
|
|
739
|
+
"json"
|
|
740
|
+
).option("-o, --out-file <path>", "Write report to file").option("--full-tree", "Include full bun pm ls tree (when available)", false).option("-c, --check-outdated", "List outdated packages instead of printing the report", false).option(
|
|
741
|
+
"-u, --update-outdated [packages...]",
|
|
742
|
+
"Update outdated packages (omit package names to update every package)"
|
|
743
|
+
);
|
|
744
|
+
if (allowOmitDev) {
|
|
745
|
+
cmd.option("--omit-dev", "Exclude devDependencies (local only)", false);
|
|
746
|
+
}
|
|
747
|
+
return cmd;
|
|
748
|
+
}
|
|
749
|
+
function createLocalCommand(program) {
|
|
750
|
+
const localCmd = program.command("local", { isDefault: true }).description("Generate a report for the current Bun project's dependencies");
|
|
751
|
+
addCommonOptions(localCmd, { allowOmitDev: true });
|
|
752
|
+
localCmd.action(async (opts) => {
|
|
753
|
+
const outputFormat = opts.outputFormat ?? "json";
|
|
754
|
+
const outFile = opts.outFile;
|
|
755
|
+
const fullTree = Boolean(opts.fullTree);
|
|
756
|
+
const omitDev = Boolean(opts.omitDev);
|
|
757
|
+
const cwd = process.cwd();
|
|
758
|
+
const selection = normalizeUpdateSelection(opts.updateOutdated);
|
|
759
|
+
const proceed = await handleOutdatedWorkflow({
|
|
760
|
+
checkOutdated: Boolean(opts.checkOutdated),
|
|
761
|
+
selection,
|
|
762
|
+
contextLabel: "local",
|
|
763
|
+
outFile,
|
|
764
|
+
fetchOutdated: async () => {
|
|
765
|
+
const tree = await bunPmLs({ cwd, omitDev });
|
|
766
|
+
const manifest = await readPackageManifest(cwd);
|
|
767
|
+
const declared = {
|
|
768
|
+
...manifest?.dependencies || {},
|
|
769
|
+
...manifest?.optionalDependencies || {},
|
|
770
|
+
...manifest?.devDependencies || {}
|
|
771
|
+
};
|
|
772
|
+
const packages = Object.entries(tree.dependencies).map(([name, node]) => ({
|
|
773
|
+
name,
|
|
774
|
+
current: node.version,
|
|
775
|
+
declared: declared[name],
|
|
776
|
+
type: "prod"
|
|
777
|
+
}));
|
|
778
|
+
if (tree.devDependencies) {
|
|
779
|
+
for (const [name, node] of Object.entries(tree.devDependencies)) {
|
|
780
|
+
packages.push({
|
|
781
|
+
name,
|
|
782
|
+
current: node.version,
|
|
783
|
+
declared: declared[name],
|
|
784
|
+
type: "dev"
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return resolveOutdatedWithNpmView(packages);
|
|
789
|
+
},
|
|
790
|
+
updateRunner: selection.shouldUpdate ? async (packages) => {
|
|
791
|
+
await bunUpdate({ cwd, packages });
|
|
792
|
+
} : void 0
|
|
793
|
+
});
|
|
794
|
+
if (!proceed) return;
|
|
795
|
+
const finalOutFile = outFile;
|
|
796
|
+
const { report, markdownExtras } = await produceReport("local", {
|
|
797
|
+
outputFormat,
|
|
798
|
+
outFile: finalOutFile,
|
|
799
|
+
fullTree,
|
|
800
|
+
omitDev
|
|
801
|
+
});
|
|
802
|
+
await outputReport(report, outputFormat, finalOutFile, markdownExtras);
|
|
803
|
+
});
|
|
804
|
+
return localCmd;
|
|
805
|
+
}
|
|
806
|
+
function createGlobalCommand(program) {
|
|
807
|
+
const globalCmd = program.command("global").description("Generate a report of globally installed Bun packages");
|
|
808
|
+
addCommonOptions(globalCmd, { allowOmitDev: false });
|
|
809
|
+
globalCmd.action(async (opts) => {
|
|
810
|
+
const outputFormat = opts.outputFormat ?? "json";
|
|
811
|
+
const outFile = opts.outFile;
|
|
812
|
+
const fullTree = Boolean(opts.fullTree);
|
|
813
|
+
const cwd = process.cwd();
|
|
814
|
+
const selection = normalizeUpdateSelection(opts.updateOutdated);
|
|
815
|
+
const proceed = await handleOutdatedWorkflow({
|
|
816
|
+
checkOutdated: Boolean(opts.checkOutdated),
|
|
817
|
+
selection,
|
|
818
|
+
contextLabel: "global",
|
|
819
|
+
outFile,
|
|
820
|
+
fetchOutdated: async () => {
|
|
821
|
+
const tree = await bunPmLs({ global: true });
|
|
822
|
+
const packages = Object.entries(tree.dependencies).map(([name, node]) => ({
|
|
823
|
+
name,
|
|
824
|
+
current: node.version,
|
|
825
|
+
type: "global"
|
|
826
|
+
}));
|
|
827
|
+
return resolveOutdatedWithNpmView(packages);
|
|
828
|
+
},
|
|
829
|
+
updateRunner: selection.shouldUpdate ? async (packages) => {
|
|
830
|
+
await bunUpdate({ cwd, global: true, packages });
|
|
831
|
+
} : void 0
|
|
832
|
+
});
|
|
833
|
+
if (!proceed) return;
|
|
834
|
+
const finalOutFile = outFile;
|
|
835
|
+
const { report, markdownExtras } = await produceReport("global", {
|
|
836
|
+
outputFormat,
|
|
837
|
+
outFile: finalOutFile,
|
|
838
|
+
fullTree
|
|
839
|
+
});
|
|
840
|
+
await outputReport(report, outputFormat, finalOutFile, markdownExtras);
|
|
841
|
+
});
|
|
842
|
+
return globalCmd;
|
|
843
|
+
}
|
|
844
|
+
function createReadCommand(program) {
|
|
845
|
+
const readCmd = program.command("read").description(
|
|
846
|
+
"Read a previously generated report (JSON or Markdown) and either print package names or install them"
|
|
847
|
+
).argument("[report]", "Path to report file (JSON or Markdown)", "bun-report.json").option("-r, --report <path>", "Path to report file (JSON or Markdown)").option("-p, --print", "Print package names/versions from the report (default)", false).option("-i, --install", "Install packages from the report using Bun", false);
|
|
848
|
+
readCmd.action(async (reportArg, opts) => {
|
|
849
|
+
const chosen = opts.report || reportArg || "bun-report.json";
|
|
850
|
+
const reportPath = path7.resolve(process.cwd(), chosen);
|
|
851
|
+
try {
|
|
852
|
+
const parsed = await loadReportFromFile(reportPath);
|
|
853
|
+
const doInstall = Boolean(opts.install);
|
|
854
|
+
const doPrint = Boolean(opts.print) || !doInstall;
|
|
855
|
+
if (doPrint) {
|
|
856
|
+
printFromReport(parsed);
|
|
857
|
+
}
|
|
858
|
+
if (doInstall) {
|
|
859
|
+
await installFromReport(parsed, { cwd: process.cwd(), packageManager: "bun" });
|
|
860
|
+
}
|
|
861
|
+
} catch (err) {
|
|
862
|
+
const isMd = isMarkdownReportFile(reportPath);
|
|
863
|
+
const hint = isMd ? "Try generating a JSON report with: gex-bun global -f json -o global.json, then: gex-bun read global.json" : "Specify a report path with: gex-bun read <path-to-report.json>";
|
|
864
|
+
console.error(`Failed to read report at ${reportPath}: ${err?.message || err}`);
|
|
865
|
+
console.error(hint);
|
|
866
|
+
process.exitCode = 1;
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
return readCmd;
|
|
870
|
+
}
|
|
871
|
+
async function createProgram() {
|
|
872
|
+
const program = new Command().name("gex-bun").description("GEX: Dependency auditing and documentation for Bun (local and global).").version(await getToolVersion());
|
|
873
|
+
program.addHelpText("beforeAll", `
|
|
874
|
+
${ASCII_BANNER}`);
|
|
875
|
+
createLocalCommand(program);
|
|
876
|
+
createGlobalCommand(program);
|
|
877
|
+
createReadCommand(program);
|
|
878
|
+
return program;
|
|
879
|
+
}
|
|
880
|
+
async function readPackageManifest(cwd) {
|
|
881
|
+
try {
|
|
882
|
+
const raw = await readFile6(path7.join(cwd, "package.json"), "utf8");
|
|
883
|
+
return JSON.parse(raw);
|
|
884
|
+
} catch {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// src/runtimes/bun/cli.ts
|
|
890
|
+
async function run(argv = process.argv) {
|
|
891
|
+
const program = await createProgram();
|
|
892
|
+
await program.parseAsync(argv);
|
|
893
|
+
}
|
|
894
|
+
var isMainModule = (() => {
|
|
895
|
+
try {
|
|
896
|
+
if (typeof __require !== "undefined" && typeof module !== "undefined") {
|
|
897
|
+
return __require.main === module;
|
|
898
|
+
}
|
|
899
|
+
if (typeof import.meta !== "undefined") {
|
|
900
|
+
return import.meta.url === `file://${process.argv[1]}`;
|
|
901
|
+
}
|
|
902
|
+
return false;
|
|
903
|
+
} catch {
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
})();
|
|
907
|
+
if (isMainModule) {
|
|
908
|
+
run().catch((error) => {
|
|
909
|
+
console.error("Bun CLI error:", error);
|
|
910
|
+
process.exitCode = 1;
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
export {
|
|
914
|
+
run
|
|
915
|
+
};
|
|
916
|
+
//# sourceMappingURL=cli-bun.mjs.map
|