@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
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/runtimes/node/cli.ts
|
|
32
|
+
var cli_exports = {};
|
|
33
|
+
__export(cli_exports, {
|
|
34
|
+
run: () => run
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(cli_exports);
|
|
37
|
+
|
|
38
|
+
// src/runtimes/node/commands.ts
|
|
39
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
40
|
+
var import_commander = require("commander");
|
|
41
|
+
|
|
42
|
+
// src/shared/cli/install.ts
|
|
43
|
+
var INSTALL_COMMANDS = {
|
|
44
|
+
npm: {
|
|
45
|
+
global: ["i", "-g"],
|
|
46
|
+
local: ["i"],
|
|
47
|
+
dev: ["i", "-D"]
|
|
48
|
+
},
|
|
49
|
+
bun: {
|
|
50
|
+
global: ["add", "-g"],
|
|
51
|
+
local: ["add"],
|
|
52
|
+
dev: ["add", "-d"]
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var MAX_BUFFER = 10 * 1024 * 1024;
|
|
56
|
+
function formatSpec(pkg) {
|
|
57
|
+
return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
|
|
58
|
+
}
|
|
59
|
+
async function getExecFileAsync() {
|
|
60
|
+
const { execFile } = await import("child_process");
|
|
61
|
+
const { promisify: promisify2 } = await import("util");
|
|
62
|
+
return promisify2(execFile);
|
|
63
|
+
}
|
|
64
|
+
async function installFromReport(report, options) {
|
|
65
|
+
const opts = typeof options === "string" ? { cwd: options } : options;
|
|
66
|
+
const { cwd, packageManager = "npm" } = opts;
|
|
67
|
+
const globalPkgs = report.global_packages.map(formatSpec).filter(Boolean);
|
|
68
|
+
const localPkgs = report.local_dependencies.map(formatSpec).filter(Boolean);
|
|
69
|
+
const devPkgs = report.local_dev_dependencies.map(formatSpec).filter(Boolean);
|
|
70
|
+
if (globalPkgs.length === 0 && localPkgs.length === 0 && devPkgs.length === 0) {
|
|
71
|
+
console.log("No packages to install from report.");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const execFileAsync = await getExecFileAsync();
|
|
75
|
+
const cmd = INSTALL_COMMANDS[packageManager];
|
|
76
|
+
const binary = packageManager === "bun" ? "bun" : "npm";
|
|
77
|
+
if (globalPkgs.length > 0) {
|
|
78
|
+
console.log(`Installing global: ${globalPkgs.join(" ")}`);
|
|
79
|
+
await execFileAsync(binary, [...cmd.global, ...globalPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
80
|
+
}
|
|
81
|
+
if (localPkgs.length > 0) {
|
|
82
|
+
console.log(`Installing local deps: ${localPkgs.join(" ")}`);
|
|
83
|
+
await execFileAsync(binary, [...cmd.local, ...localPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
84
|
+
}
|
|
85
|
+
if (devPkgs.length > 0) {
|
|
86
|
+
console.log(`Installing local devDeps: ${devPkgs.join(" ")}`);
|
|
87
|
+
await execFileAsync(binary, [...cmd.dev, ...devPkgs], { cwd, maxBuffer: MAX_BUFFER });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function printFromReport(report) {
|
|
91
|
+
const lines = [];
|
|
92
|
+
if (report.global_packages.length > 0) {
|
|
93
|
+
lines.push("Global Packages:");
|
|
94
|
+
for (const p of report.global_packages) {
|
|
95
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (report.local_dependencies.length > 0) {
|
|
99
|
+
if (lines.length) lines.push("");
|
|
100
|
+
lines.push("Local Dependencies:");
|
|
101
|
+
for (const p of report.local_dependencies) {
|
|
102
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (report.local_dev_dependencies.length > 0) {
|
|
106
|
+
if (lines.length) lines.push("");
|
|
107
|
+
lines.push("Local Dev Dependencies:");
|
|
108
|
+
for (const p of report.local_dev_dependencies) {
|
|
109
|
+
lines.push(`- ${p.name}@${p.version}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (lines.length === 0) {
|
|
113
|
+
lines.push("(no packages found in report)");
|
|
114
|
+
}
|
|
115
|
+
console.log(lines.join("\n"));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/shared/cli/output.ts
|
|
119
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
120
|
+
|
|
121
|
+
// src/shared/report/json.ts
|
|
122
|
+
function renderJson(report) {
|
|
123
|
+
const r = {
|
|
124
|
+
...report,
|
|
125
|
+
global_packages: [...report.global_packages].sort((a, b) => a.name.localeCompare(b.name)),
|
|
126
|
+
local_dependencies: [...report.local_dependencies].sort((a, b) => a.name.localeCompare(b.name)),
|
|
127
|
+
local_dev_dependencies: [...report.local_dev_dependencies].sort(
|
|
128
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
129
|
+
)
|
|
130
|
+
};
|
|
131
|
+
return JSON.stringify(r, null, 2);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/shared/report/md.ts
|
|
135
|
+
function table(headers, rows) {
|
|
136
|
+
const header = `| ${headers.join(" | ")} |`;
|
|
137
|
+
const sep = `| ${headers.map(() => "---").join(" | ")} |`;
|
|
138
|
+
const body = rows.map((r) => `| ${r.join(" | ")} |`).join("\n");
|
|
139
|
+
return [header, sep, body].filter(Boolean).join("\n");
|
|
140
|
+
}
|
|
141
|
+
function renderMarkdown(report) {
|
|
142
|
+
const lines = [];
|
|
143
|
+
lines.push("# GEX Report");
|
|
144
|
+
lines.push("");
|
|
145
|
+
if (report.project_name || report.project_version || report.project_description || report.project_homepage || report.project_bugs) {
|
|
146
|
+
lines.push("## Project Metadata");
|
|
147
|
+
if (report.project_name) lines.push(`- Name: ${report.project_name}`);
|
|
148
|
+
if (report.project_version) lines.push(`- Version: ${report.project_version}`);
|
|
149
|
+
if (report.project_description)
|
|
150
|
+
lines.push(`- Description: ${report.project_description}`);
|
|
151
|
+
if (report.project_homepage)
|
|
152
|
+
lines.push(`- Homepage: ${report.project_homepage}`);
|
|
153
|
+
if (report.project_bugs) lines.push(`- Bugs: ${report.project_bugs}`);
|
|
154
|
+
lines.push("");
|
|
155
|
+
}
|
|
156
|
+
if (report.global_packages.length > 0) {
|
|
157
|
+
lines.push("## Global Packages");
|
|
158
|
+
const rows = report.global_packages.map((p) => [p.name, p.version || "", p.resolved_path || ""]);
|
|
159
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
160
|
+
lines.push("");
|
|
161
|
+
}
|
|
162
|
+
if (report.local_dependencies.length > 0) {
|
|
163
|
+
lines.push("## Local Dependencies");
|
|
164
|
+
const rows = report.local_dependencies.map((p) => [
|
|
165
|
+
p.name,
|
|
166
|
+
p.version || "",
|
|
167
|
+
p.resolved_path || ""
|
|
168
|
+
]);
|
|
169
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
170
|
+
lines.push("");
|
|
171
|
+
}
|
|
172
|
+
if (report.local_dev_dependencies.length > 0) {
|
|
173
|
+
lines.push("## Local Dev Dependencies");
|
|
174
|
+
const rows = report.local_dev_dependencies.map((p) => [
|
|
175
|
+
p.name,
|
|
176
|
+
p.version || "",
|
|
177
|
+
p.resolved_path || ""
|
|
178
|
+
]);
|
|
179
|
+
lines.push(table(["Name", "Version", "Path"], rows));
|
|
180
|
+
lines.push("");
|
|
181
|
+
}
|
|
182
|
+
lines.push("---");
|
|
183
|
+
lines.push("_Generated by GEX_");
|
|
184
|
+
return lines.join("\n");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/shared/cli/output.ts
|
|
188
|
+
async function outputReport(report, format, outFile, markdownExtras) {
|
|
189
|
+
const content = format === "json" ? renderJson(report) : renderMarkdown({ ...report, ...markdownExtras || {} });
|
|
190
|
+
if (outFile) {
|
|
191
|
+
const outDir = import_node_path.default.dirname(outFile);
|
|
192
|
+
const { mkdir, writeFile } = await import("fs/promises");
|
|
193
|
+
await mkdir(outDir, { recursive: true });
|
|
194
|
+
await writeFile(outFile, content, "utf8");
|
|
195
|
+
console.log(`Wrote report to ${outFile}`);
|
|
196
|
+
} else {
|
|
197
|
+
console.log(content);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/shared/cli/parser.ts
|
|
202
|
+
var import_promises = require("fs/promises");
|
|
203
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
204
|
+
function isMarkdownReportFile(filePath) {
|
|
205
|
+
const ext = import_node_path2.default.extname(filePath).toLowerCase();
|
|
206
|
+
return ext === ".md" || ext === ".markdown";
|
|
207
|
+
}
|
|
208
|
+
function parseMarkdownPackagesTable(lines, startIndex) {
|
|
209
|
+
const rows = [];
|
|
210
|
+
if (!lines[startIndex] || !lines[startIndex].trim().startsWith("|")) return rows;
|
|
211
|
+
let i = startIndex + 2;
|
|
212
|
+
while (i < lines.length && lines[i].trim().startsWith("|")) {
|
|
213
|
+
const cols = lines[i].split("|").map((c) => c.trim()).filter((_, idx, arr) => !(idx === 0 || idx === arr.length - 1));
|
|
214
|
+
const [name = "", version = "", resolved_path = ""] = cols;
|
|
215
|
+
if (name) rows.push({ name, version, resolved_path });
|
|
216
|
+
i++;
|
|
217
|
+
}
|
|
218
|
+
return rows;
|
|
219
|
+
}
|
|
220
|
+
function parseMarkdownReport(md) {
|
|
221
|
+
const lines = md.split(/\r?\n/);
|
|
222
|
+
const findSection = (title) => lines.findIndex((l) => l.trim().toLowerCase() === `## ${title}`.toLowerCase());
|
|
223
|
+
const parseSection = (idx) => {
|
|
224
|
+
if (idx < 0) return [];
|
|
225
|
+
let i = idx + 1;
|
|
226
|
+
while (i < lines.length && !lines[i].trim().startsWith("|")) i++;
|
|
227
|
+
return parseMarkdownPackagesTable(lines, i);
|
|
228
|
+
};
|
|
229
|
+
const global_packages = parseSection(findSection("Global Packages"));
|
|
230
|
+
const local_dependencies = parseSection(findSection("Local Dependencies"));
|
|
231
|
+
const local_dev_dependencies = parseSection(findSection("Local Dev Dependencies"));
|
|
232
|
+
const report = {
|
|
233
|
+
report_version: "1.0",
|
|
234
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
235
|
+
tool_version: "unknown",
|
|
236
|
+
global_packages,
|
|
237
|
+
local_dependencies,
|
|
238
|
+
local_dev_dependencies
|
|
239
|
+
};
|
|
240
|
+
return report;
|
|
241
|
+
}
|
|
242
|
+
async function loadReportFromFile(reportPath) {
|
|
243
|
+
const raw = await (0, import_promises.readFile)(reportPath, "utf8");
|
|
244
|
+
if (isMarkdownReportFile(reportPath) || raw.startsWith("# GEX Report")) {
|
|
245
|
+
return parseMarkdownReport(raw);
|
|
246
|
+
}
|
|
247
|
+
return JSON.parse(raw);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/shared/npm-cli.ts
|
|
251
|
+
var import_node_util = require("util");
|
|
252
|
+
async function getExecFileAsync2() {
|
|
253
|
+
const { execFile } = await import("child_process");
|
|
254
|
+
return (0, import_node_util.promisify)(execFile);
|
|
255
|
+
}
|
|
256
|
+
async function npmOutdated(options = {}) {
|
|
257
|
+
const args = ["outdated", "--json"];
|
|
258
|
+
if (options.global) args.push("--global");
|
|
259
|
+
try {
|
|
260
|
+
const execFileAsync = await getExecFileAsync2();
|
|
261
|
+
const { stdout } = await execFileAsync("npm", args, {
|
|
262
|
+
cwd: options.cwd,
|
|
263
|
+
maxBuffer: 10 * 1024 * 1024
|
|
264
|
+
});
|
|
265
|
+
return normalizeOutdated(stdout);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
const stdout = typeof error?.stdout === "string" ? error.stdout : "";
|
|
268
|
+
if (stdout.trim()) {
|
|
269
|
+
return normalizeOutdated(stdout);
|
|
270
|
+
}
|
|
271
|
+
throw formatNpmError(error, "npm outdated");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function npmUpdate(options) {
|
|
275
|
+
const args = ["update"];
|
|
276
|
+
if (options.global) args.push("-g");
|
|
277
|
+
if (options.packages && options.packages.length > 0) args.push(...options.packages);
|
|
278
|
+
try {
|
|
279
|
+
const execFileAsync = await getExecFileAsync2();
|
|
280
|
+
await execFileAsync("npm", args, {
|
|
281
|
+
cwd: options.cwd,
|
|
282
|
+
maxBuffer: 10 * 1024 * 1024
|
|
283
|
+
});
|
|
284
|
+
} catch (error) {
|
|
285
|
+
throw formatNpmError(error, "npm update");
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function normalizeOutdated(stdout) {
|
|
289
|
+
if (!stdout.trim()) return [];
|
|
290
|
+
let data;
|
|
291
|
+
try {
|
|
292
|
+
data = JSON.parse(stdout);
|
|
293
|
+
} catch {
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
if (!data) return [];
|
|
297
|
+
return Object.entries(data).map(([name, info]) => ({
|
|
298
|
+
name,
|
|
299
|
+
current: info?.current ? String(info.current) : "",
|
|
300
|
+
wanted: info?.wanted ? String(info.wanted) : "",
|
|
301
|
+
latest: info?.latest ? String(info.latest) : "",
|
|
302
|
+
type: info?.type ? String(info.type) : void 0
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
function formatNpmError(error, commandLabel) {
|
|
306
|
+
const stderr = typeof error?.stderr === "string" ? error.stderr.trim() : "";
|
|
307
|
+
const message = stderr || error?.message || `${commandLabel} failed`;
|
|
308
|
+
return new Error(`${commandLabel} failed: ${message}`);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/shared/cli/loader.ts
|
|
312
|
+
var frames = ["-", "\\", "|", "/"];
|
|
313
|
+
function createLoader(message) {
|
|
314
|
+
if (!process.stdout.isTTY) {
|
|
315
|
+
console.log(`${message}...`);
|
|
316
|
+
return {
|
|
317
|
+
stop(finalMessage) {
|
|
318
|
+
if (finalMessage) console.log(finalMessage);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
let index = 0;
|
|
323
|
+
const interval = setInterval(() => {
|
|
324
|
+
const frame = frames[index % frames.length];
|
|
325
|
+
index += 1;
|
|
326
|
+
process.stdout.write(`\r${message} ${frame}`);
|
|
327
|
+
}, 80);
|
|
328
|
+
return {
|
|
329
|
+
stop(finalMessage) {
|
|
330
|
+
clearInterval(interval);
|
|
331
|
+
process.stdout.write("\r");
|
|
332
|
+
if (finalMessage) {
|
|
333
|
+
console.log(finalMessage);
|
|
334
|
+
} else {
|
|
335
|
+
process.stdout.write("\x1B[2K");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/shared/cli/outdated.ts
|
|
342
|
+
function normalizeUpdateSelection(value) {
|
|
343
|
+
if (value === void 0) {
|
|
344
|
+
return { shouldUpdate: false, updateAll: false, packages: [] };
|
|
345
|
+
}
|
|
346
|
+
if (value === true) {
|
|
347
|
+
return { shouldUpdate: true, updateAll: true, packages: [] };
|
|
348
|
+
}
|
|
349
|
+
const packages = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
|
|
350
|
+
const normalized = packages.flatMap((entry) => String(entry).split(",").map((part) => part.trim())).filter(Boolean);
|
|
351
|
+
return {
|
|
352
|
+
shouldUpdate: true,
|
|
353
|
+
updateAll: false,
|
|
354
|
+
packages: normalized
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function formatOutdatedTable(entries) {
|
|
358
|
+
const headers = ["Name", "Current", "Wanted", "Latest", "Type"];
|
|
359
|
+
const rows = entries.map((entry) => [
|
|
360
|
+
entry.name,
|
|
361
|
+
entry.current || "-",
|
|
362
|
+
entry.wanted || "-",
|
|
363
|
+
entry.latest || "-",
|
|
364
|
+
entry.type || "-"
|
|
365
|
+
]);
|
|
366
|
+
const widths = headers.map(
|
|
367
|
+
(header, index) => Math.max(header.length, ...rows.map((row) => row[index].length))
|
|
368
|
+
);
|
|
369
|
+
const formatRow = (columns) => columns.map((col, idx) => col.padEnd(widths[idx], " ")).join(" ");
|
|
370
|
+
const lines = [formatRow(headers), formatRow(widths.map((w) => "-".repeat(w)))];
|
|
371
|
+
for (const row of rows) {
|
|
372
|
+
lines.push(formatRow(row));
|
|
373
|
+
}
|
|
374
|
+
return lines.join("\n");
|
|
375
|
+
}
|
|
376
|
+
async function handleOutdatedWorkflow(opts) {
|
|
377
|
+
if (!opts.checkOutdated && !opts.selection.shouldUpdate) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
let fetchLoader;
|
|
381
|
+
if (opts.checkOutdated || opts.selection.shouldUpdate) {
|
|
382
|
+
fetchLoader = createLoader("Checking for outdated packages");
|
|
383
|
+
}
|
|
384
|
+
const outdated = await opts.fetchOutdated();
|
|
385
|
+
fetchLoader?.stop("Finished checking outdated packages.");
|
|
386
|
+
if (opts.checkOutdated) {
|
|
387
|
+
if (outdated.length === 0) {
|
|
388
|
+
console.log(`All ${opts.contextLabel} packages are up to date.`);
|
|
389
|
+
} else {
|
|
390
|
+
console.log(formatOutdatedTable(outdated));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (opts.selection.shouldUpdate && opts.updateRunner) {
|
|
394
|
+
const packagesToUpdate = opts.selection.updateAll ? outdated.map((entry) => entry.name) : opts.selection.packages;
|
|
395
|
+
if (!packagesToUpdate || packagesToUpdate.length === 0) {
|
|
396
|
+
if (opts.selection.updateAll) {
|
|
397
|
+
console.log("No outdated packages to update.");
|
|
398
|
+
} else {
|
|
399
|
+
console.log("No packages were specified for updating.");
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
const updateLoader = createLoader("Updating packages");
|
|
403
|
+
await opts.updateRunner(packagesToUpdate);
|
|
404
|
+
updateLoader.stop("Finished updating packages.");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (opts.checkOutdated || opts.selection.shouldUpdate) {
|
|
408
|
+
if (!opts.outFile) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// src/shared/cli/utils.ts
|
|
416
|
+
var import_node_fs = require("fs");
|
|
417
|
+
var import_promises2 = require("fs/promises");
|
|
418
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
419
|
+
var import_node_url = require("url");
|
|
420
|
+
var import_meta = {};
|
|
421
|
+
function getPkgJsonPath() {
|
|
422
|
+
let startDir;
|
|
423
|
+
try {
|
|
424
|
+
const __filename = (0, import_node_url.fileURLToPath)(import_meta.url);
|
|
425
|
+
startDir = import_node_path3.default.dirname(__filename);
|
|
426
|
+
} catch {
|
|
427
|
+
startDir = typeof __dirname !== "undefined" ? __dirname : process.cwd();
|
|
428
|
+
}
|
|
429
|
+
return findPackageJson(startDir);
|
|
430
|
+
}
|
|
431
|
+
function findPackageJson(startDir) {
|
|
432
|
+
let current = startDir;
|
|
433
|
+
const maxDepth = 6;
|
|
434
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
435
|
+
const candidate = import_node_path3.default.resolve(current, "package.json");
|
|
436
|
+
if ((0, import_node_fs.existsSync)(candidate)) {
|
|
437
|
+
return candidate;
|
|
438
|
+
}
|
|
439
|
+
const parent = import_node_path3.default.dirname(current);
|
|
440
|
+
if (parent === current) break;
|
|
441
|
+
current = parent;
|
|
442
|
+
}
|
|
443
|
+
return import_node_path3.default.resolve(process.cwd(), "package.json");
|
|
444
|
+
}
|
|
445
|
+
async function getToolVersion() {
|
|
446
|
+
try {
|
|
447
|
+
const pkgPath = getPkgJsonPath();
|
|
448
|
+
const raw = await (0, import_promises2.readFile)(pkgPath, "utf8");
|
|
449
|
+
const pkg = JSON.parse(raw);
|
|
450
|
+
return pkg.version || "0.0.0";
|
|
451
|
+
} catch {
|
|
452
|
+
return "0.0.0";
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
var ASCII_BANNER = String.raw`
|
|
456
|
+
________ __
|
|
457
|
+
/ _____/ ____ _____/ |_ ____ ____
|
|
458
|
+
/ \ ___ / _ \ / _ \ __\/ __ \ / \
|
|
459
|
+
\ \_\ ( <_> | <_> ) | \ ___/| | \
|
|
460
|
+
\______ /\____/ \____/|__| \___ >___| /
|
|
461
|
+
\/ \/ \/
|
|
462
|
+
GEX
|
|
463
|
+
`;
|
|
464
|
+
|
|
465
|
+
// src/runtimes/node/report.ts
|
|
466
|
+
var import_promises4 = require("fs/promises");
|
|
467
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
468
|
+
|
|
469
|
+
// src/shared/transform.ts
|
|
470
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
471
|
+
var import_promises3 = require("fs/promises");
|
|
472
|
+
function toPkgArray(obj) {
|
|
473
|
+
if (!obj) return [];
|
|
474
|
+
return Object.keys(obj).map((name) => ({ name, node: obj[name] })).filter((p) => p && p.node);
|
|
475
|
+
}
|
|
476
|
+
async function buildReportFromNpmTree(tree, opts) {
|
|
477
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
478
|
+
const report = {
|
|
479
|
+
report_version: "1.0",
|
|
480
|
+
timestamp,
|
|
481
|
+
tool_version: opts.toolVersion,
|
|
482
|
+
global_packages: [],
|
|
483
|
+
local_dependencies: [],
|
|
484
|
+
local_dev_dependencies: []
|
|
485
|
+
};
|
|
486
|
+
if (opts.context === "local") {
|
|
487
|
+
let pkgMeta = null;
|
|
488
|
+
try {
|
|
489
|
+
const pkgJsonPath = import_node_path4.default.join(opts.cwd || process.cwd(), "package.json");
|
|
490
|
+
const raw = await (0, import_promises3.readFile)(pkgJsonPath, "utf8");
|
|
491
|
+
pkgMeta = JSON.parse(raw);
|
|
492
|
+
} catch {
|
|
493
|
+
}
|
|
494
|
+
if (pkgMeta?.name) report.project_name = pkgMeta.name;
|
|
495
|
+
if (pkgMeta?.version) report.project_version = pkgMeta.version;
|
|
496
|
+
const depsObj = tree?.dependencies;
|
|
497
|
+
const devDepsObj = tree?.devDependencies;
|
|
498
|
+
const prodItems = toPkgArray(depsObj);
|
|
499
|
+
const treeDevItems = toPkgArray(devDepsObj);
|
|
500
|
+
if (treeDevItems.length > 0) {
|
|
501
|
+
for (const { name, node } of treeDevItems) {
|
|
502
|
+
const version = node && node.version || "";
|
|
503
|
+
const resolvedPath = node && node.path || import_node_path4.default.join(opts.cwd || process.cwd(), "node_modules", name);
|
|
504
|
+
report.local_dev_dependencies.push({ name, version, resolved_path: resolvedPath });
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
const devKeys = treeDevItems.length > 0 ? new Set(treeDevItems.map((entry) => entry.name)) : new Set(Object.keys(pkgMeta?.devDependencies || {}));
|
|
508
|
+
for (const { name, node } of prodItems) {
|
|
509
|
+
const version = node && node.version || "";
|
|
510
|
+
const resolvedPath = node && node.path || import_node_path4.default.join(opts.cwd || process.cwd(), "node_modules", name);
|
|
511
|
+
const pkg = { name, version, resolved_path: resolvedPath };
|
|
512
|
+
if (!treeDevItems.length && devKeys.has(name)) {
|
|
513
|
+
report.local_dev_dependencies.push(pkg);
|
|
514
|
+
} else {
|
|
515
|
+
report.local_dependencies.push(pkg);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
report.local_dependencies.sort((a, b) => a.name.localeCompare(b.name));
|
|
519
|
+
report.local_dev_dependencies.sort((a, b) => a.name.localeCompare(b.name));
|
|
520
|
+
} else if (opts.context === "global") {
|
|
521
|
+
const depsObj = tree?.dependencies;
|
|
522
|
+
const items = toPkgArray(depsObj);
|
|
523
|
+
for (const { name, node } of items) {
|
|
524
|
+
const version = node && node.version || "";
|
|
525
|
+
const resolvedPath = node && node.path || import_node_path4.default.join(opts.globalRoot || "", name);
|
|
526
|
+
const pkg = { name, version, resolved_path: resolvedPath };
|
|
527
|
+
report.global_packages.push(pkg);
|
|
528
|
+
}
|
|
529
|
+
report.global_packages.sort((a, b) => a.name.localeCompare(b.name));
|
|
530
|
+
}
|
|
531
|
+
if (opts.includeTree) {
|
|
532
|
+
report.tree = tree;
|
|
533
|
+
}
|
|
534
|
+
return report;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// src/runtimes/node/package-manager.ts
|
|
538
|
+
async function getExecFileAsync3() {
|
|
539
|
+
const { execFile } = await import("child_process");
|
|
540
|
+
const { promisify: promisify2 } = await import("util");
|
|
541
|
+
return promisify2(execFile);
|
|
542
|
+
}
|
|
543
|
+
async function npmLs(options = {}) {
|
|
544
|
+
const args = ["ls", "--json"];
|
|
545
|
+
if (options.global) args.push("--global");
|
|
546
|
+
if (options.omitDev) args.push("--omit=dev");
|
|
547
|
+
if (options.depth0) args.push("--depth=0");
|
|
548
|
+
try {
|
|
549
|
+
const execFileAsync = await getExecFileAsync3();
|
|
550
|
+
const { stdout } = await execFileAsync("npm", args, {
|
|
551
|
+
cwd: options.cwd,
|
|
552
|
+
maxBuffer: 10 * 1024 * 1024
|
|
553
|
+
});
|
|
554
|
+
if (stdout && stdout.trim()) return JSON.parse(stdout);
|
|
555
|
+
return {};
|
|
556
|
+
} catch (err) {
|
|
557
|
+
const stdout = err?.stdout;
|
|
558
|
+
if (typeof stdout === "string" && stdout.trim()) {
|
|
559
|
+
try {
|
|
560
|
+
return JSON.parse(stdout);
|
|
561
|
+
} catch (parseErr) {
|
|
562
|
+
if (process.env.DEBUG?.includes("gex")) {
|
|
563
|
+
console.warn("npm ls stdout parse failed:", parseErr);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
const stderr = err?.stderr;
|
|
568
|
+
const msg = typeof stderr === "string" && stderr.trim() || err?.message || "npm ls failed";
|
|
569
|
+
throw new Error(`npm ls failed: ${msg}`);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
async function npmRootGlobal() {
|
|
573
|
+
try {
|
|
574
|
+
const execFileAsync = await getExecFileAsync3();
|
|
575
|
+
const { stdout } = await execFileAsync("npm", ["root", "-g"]);
|
|
576
|
+
return stdout.trim();
|
|
577
|
+
} catch (err) {
|
|
578
|
+
const stderr = err?.stderr;
|
|
579
|
+
const msg = typeof stderr === "string" && stderr.trim() || err?.message || "npm root -g failed";
|
|
580
|
+
throw new Error(`npm root -g failed: ${msg}`);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/runtimes/node/report.ts
|
|
585
|
+
async function produceReport(ctx, options) {
|
|
586
|
+
const toolVersion = await getToolVersion();
|
|
587
|
+
const depth0 = !options.fullTree;
|
|
588
|
+
const cwd = options.cwd || process.cwd();
|
|
589
|
+
const tree = await npmLs({
|
|
590
|
+
global: ctx === "global",
|
|
591
|
+
omitDev: ctx === "local" ? Boolean(options.omitDev) : false,
|
|
592
|
+
depth0,
|
|
593
|
+
cwd
|
|
594
|
+
});
|
|
595
|
+
let project_description;
|
|
596
|
+
let project_homepage;
|
|
597
|
+
let project_bugs;
|
|
598
|
+
if (ctx === "local") {
|
|
599
|
+
try {
|
|
600
|
+
const pkgRaw = await (0, import_promises4.readFile)(import_node_path5.default.join(cwd, "package.json"), "utf8");
|
|
601
|
+
const pkg = JSON.parse(pkgRaw);
|
|
602
|
+
project_description = pkg.description;
|
|
603
|
+
project_homepage = pkg.homepage;
|
|
604
|
+
if (typeof pkg.bugs === "string") project_bugs = pkg.bugs;
|
|
605
|
+
else if (pkg.bugs && typeof pkg.bugs.url === "string") project_bugs = pkg.bugs.url;
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const globalRoot = ctx === "global" ? await npmRootGlobal().catch(() => void 0) : void 0;
|
|
610
|
+
const report = await buildReportFromNpmTree(tree, {
|
|
611
|
+
context: ctx,
|
|
612
|
+
includeTree: Boolean(options.fullTree),
|
|
613
|
+
omitDev: Boolean(options.omitDev),
|
|
614
|
+
cwd,
|
|
615
|
+
toolVersion,
|
|
616
|
+
globalRoot
|
|
617
|
+
});
|
|
618
|
+
const markdownExtras = { project_description, project_homepage, project_bugs };
|
|
619
|
+
return { report, markdownExtras };
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/runtimes/node/commands.ts
|
|
623
|
+
function addCommonOptions(cmd, { allowOmitDev }) {
|
|
624
|
+
cmd.option(
|
|
625
|
+
"-f, --output-format <format>",
|
|
626
|
+
"Output format: md or json",
|
|
627
|
+
(val) => val === "md" ? "md" : "json",
|
|
628
|
+
"json"
|
|
629
|
+
).option("-o, --out-file <path>", "Write report to file").option("--full-tree", "Include full npm ls tree (omit depth=0 default)", false).option("-c, --check-outdated", "List outdated packages instead of printing the report", false).option(
|
|
630
|
+
"-u, --update-outdated [packages...]",
|
|
631
|
+
"Update outdated packages (omit package names to update every package)"
|
|
632
|
+
);
|
|
633
|
+
if (allowOmitDev) {
|
|
634
|
+
cmd.option("--omit-dev", "Exclude devDependencies (local only)", false);
|
|
635
|
+
}
|
|
636
|
+
return cmd;
|
|
637
|
+
}
|
|
638
|
+
function createLocalCommand(program) {
|
|
639
|
+
const localCmd = program.command("local", { isDefault: true }).description("Generate a report for the current project's dependencies");
|
|
640
|
+
addCommonOptions(localCmd, { allowOmitDev: true });
|
|
641
|
+
localCmd.action(async (opts) => {
|
|
642
|
+
const outputFormat = opts.outputFormat ?? "json";
|
|
643
|
+
const outFile = opts.outFile;
|
|
644
|
+
const fullTree = Boolean(opts.fullTree);
|
|
645
|
+
const omitDev = Boolean(opts.omitDev);
|
|
646
|
+
const cwd = process.cwd();
|
|
647
|
+
const selection = normalizeUpdateSelection(opts.updateOutdated);
|
|
648
|
+
const proceed = await handleOutdatedWorkflow({
|
|
649
|
+
checkOutdated: Boolean(opts.checkOutdated),
|
|
650
|
+
selection,
|
|
651
|
+
contextLabel: "local",
|
|
652
|
+
outFile,
|
|
653
|
+
fetchOutdated: () => npmOutdated({ cwd }),
|
|
654
|
+
updateRunner: selection.shouldUpdate ? async (packages) => {
|
|
655
|
+
await npmUpdate({ cwd, packages });
|
|
656
|
+
} : void 0
|
|
657
|
+
});
|
|
658
|
+
if (!proceed) return;
|
|
659
|
+
const finalOutFile = outFile;
|
|
660
|
+
const { report, markdownExtras } = await produceReport("local", {
|
|
661
|
+
outputFormat,
|
|
662
|
+
outFile: finalOutFile,
|
|
663
|
+
fullTree,
|
|
664
|
+
omitDev
|
|
665
|
+
});
|
|
666
|
+
await outputReport(report, outputFormat, finalOutFile, markdownExtras);
|
|
667
|
+
});
|
|
668
|
+
return localCmd;
|
|
669
|
+
}
|
|
670
|
+
function createGlobalCommand(program) {
|
|
671
|
+
const globalCmd = program.command("global").description("Generate a report of globally installed packages");
|
|
672
|
+
addCommonOptions(globalCmd, { allowOmitDev: false });
|
|
673
|
+
globalCmd.action(async (opts) => {
|
|
674
|
+
const outputFormat = opts.outputFormat ?? "json";
|
|
675
|
+
const outFile = opts.outFile;
|
|
676
|
+
const fullTree = Boolean(opts.fullTree);
|
|
677
|
+
const cwd = process.cwd();
|
|
678
|
+
const selection = normalizeUpdateSelection(opts.updateOutdated);
|
|
679
|
+
const proceed = await handleOutdatedWorkflow({
|
|
680
|
+
checkOutdated: Boolean(opts.checkOutdated),
|
|
681
|
+
selection,
|
|
682
|
+
contextLabel: "global",
|
|
683
|
+
outFile,
|
|
684
|
+
fetchOutdated: () => npmOutdated({ cwd, global: true }),
|
|
685
|
+
updateRunner: selection.shouldUpdate ? async (packages) => {
|
|
686
|
+
await npmUpdate({ cwd, global: true, packages });
|
|
687
|
+
} : void 0
|
|
688
|
+
});
|
|
689
|
+
if (!proceed) return;
|
|
690
|
+
const finalOutFile = outFile;
|
|
691
|
+
const { report, markdownExtras } = await produceReport("global", {
|
|
692
|
+
outputFormat,
|
|
693
|
+
outFile: finalOutFile,
|
|
694
|
+
fullTree
|
|
695
|
+
});
|
|
696
|
+
await outputReport(report, outputFormat, finalOutFile, markdownExtras);
|
|
697
|
+
});
|
|
698
|
+
return globalCmd;
|
|
699
|
+
}
|
|
700
|
+
function createReadCommand(program) {
|
|
701
|
+
const readCmd = program.command("read").description(
|
|
702
|
+
"Read a previously generated report (JSON or Markdown) and either print package names or install them"
|
|
703
|
+
).argument("[report]", "Path to report file (JSON or Markdown)", "gex-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", false);
|
|
704
|
+
readCmd.action(async (reportArg, opts) => {
|
|
705
|
+
const chosen = opts.report || reportArg || "gex-report.json";
|
|
706
|
+
const reportPath = import_node_path6.default.resolve(process.cwd(), chosen);
|
|
707
|
+
try {
|
|
708
|
+
const parsed = await loadReportFromFile(reportPath);
|
|
709
|
+
const doInstall = Boolean(opts.install);
|
|
710
|
+
const doPrint = Boolean(opts.print) || !doInstall;
|
|
711
|
+
if (doPrint) {
|
|
712
|
+
printFromReport(parsed);
|
|
713
|
+
}
|
|
714
|
+
if (doInstall) {
|
|
715
|
+
await installFromReport(parsed, { cwd: process.cwd(), packageManager: "npm" });
|
|
716
|
+
}
|
|
717
|
+
} catch (err) {
|
|
718
|
+
const isMd = isMarkdownReportFile(reportPath);
|
|
719
|
+
const hint = isMd ? "Try generating a JSON report with: gex global -f json -o global.json, then: gex read global.json" : "Specify a report path with: gex read <path-to-report.json>";
|
|
720
|
+
console.error(`Failed to read report at ${reportPath}: ${err?.message || err}`);
|
|
721
|
+
console.error(hint);
|
|
722
|
+
process.exitCode = 1;
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
return readCmd;
|
|
726
|
+
}
|
|
727
|
+
async function createProgram() {
|
|
728
|
+
const program = new import_commander.Command().name("gex").description("GEX: Dependency auditing and documentation for Node.js (local and global).").version(await getToolVersion());
|
|
729
|
+
program.addHelpText("beforeAll", `
|
|
730
|
+
${ASCII_BANNER}`);
|
|
731
|
+
createLocalCommand(program);
|
|
732
|
+
createGlobalCommand(program);
|
|
733
|
+
createReadCommand(program);
|
|
734
|
+
return program;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/runtimes/node/cli.ts
|
|
738
|
+
var import_meta2 = {};
|
|
739
|
+
async function run(argv = process.argv) {
|
|
740
|
+
const program = await createProgram();
|
|
741
|
+
await program.parseAsync(argv);
|
|
742
|
+
}
|
|
743
|
+
var isMainModule = (() => {
|
|
744
|
+
try {
|
|
745
|
+
if (typeof require !== "undefined" && typeof module !== "undefined") {
|
|
746
|
+
return require.main === module;
|
|
747
|
+
}
|
|
748
|
+
if (typeof import_meta2 !== "undefined") {
|
|
749
|
+
return import_meta2.url === `file://${process.argv[1]}`;
|
|
750
|
+
}
|
|
751
|
+
return false;
|
|
752
|
+
} catch {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
})();
|
|
756
|
+
if (isMainModule) {
|
|
757
|
+
run().catch((error) => {
|
|
758
|
+
console.error("CLI error:", error);
|
|
759
|
+
process.exitCode = 1;
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
763
|
+
0 && (module.exports = {
|
|
764
|
+
run
|
|
765
|
+
});
|
|
766
|
+
//# sourceMappingURL=cli-node.cjs.map
|