@profullstack/threatcrush 0.11.5 → 0.11.6

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/dist/index.js CHANGED
@@ -12337,7 +12337,7 @@ var source_default = chalk;
12337
12337
 
12338
12338
  // src/index.ts
12339
12339
  var import_readline = __toESM(require("readline"));
12340
- var import_node_child_process10 = require("child_process");
12340
+ var import_node_child_process11 = require("child_process");
12341
12341
  var import_node_fs31 = require("fs");
12342
12342
  var import_node_path21 = require("path");
12343
12343
  var import_node_os8 = require("os");
@@ -23068,6 +23068,90 @@ async function allowlistCommand(opts) {
23068
23068
 
23069
23069
  // src/index.ts
23070
23070
  init_paths();
23071
+
23072
+ // src/upgrade.ts
23073
+ var import_node_child_process10 = require("child_process");
23074
+ var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
23075
+ var defaultRunner = (cmd) => {
23076
+ try {
23077
+ return (0, import_node_child_process10.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
23078
+ } catch {
23079
+ return null;
23080
+ }
23081
+ };
23082
+ function globalInstallCommand(pm, pkgName, action) {
23083
+ if (action === "remove") {
23084
+ const removals = {
23085
+ npm: `npm uninstall -g ${pkgName}`,
23086
+ pnpm: `pnpm remove -g ${pkgName}`,
23087
+ yarn: `yarn global remove ${pkgName}`,
23088
+ bun: `bun remove -g ${pkgName}`
23089
+ };
23090
+ return removals[pm] ?? removals.npm;
23091
+ }
23092
+ const target = `${pkgName}@latest`;
23093
+ const installs = {
23094
+ npm: `npm i -g ${target}`,
23095
+ pnpm: `pnpm add -g ${target}`,
23096
+ yarn: `yarn global add ${target}`,
23097
+ bun: `bun add -g ${target}`
23098
+ };
23099
+ return installs[pm] ?? installs.npm;
23100
+ }
23101
+ function globalListCommand(pm, pkgName) {
23102
+ const lists = {
23103
+ npm: `npm ls -g --depth=0 ${pkgName}`,
23104
+ pnpm: `pnpm list -g --depth=0 ${pkgName}`,
23105
+ yarn: `yarn global list --pattern ${pkgName}`,
23106
+ bun: `bun pm ls -g`
23107
+ };
23108
+ return lists[pm] ?? lists.npm;
23109
+ }
23110
+ function globalHolders(pkgName, run = defaultRunner) {
23111
+ return PACKAGE_MANAGERS.filter((pm) => {
23112
+ const out = run(globalListCommand(pm, pkgName));
23113
+ return typeof out === "string" && out.includes(pkgName);
23114
+ });
23115
+ }
23116
+ function parseVersionOutput(output) {
23117
+ if (!output) return null;
23118
+ const match = output.match(/\d+\.\d+\.\d+[^\s]*/);
23119
+ return match ? match[0] : null;
23120
+ }
23121
+ function activeCliVersion(bin = "threatcrush", run = defaultRunner) {
23122
+ return parseVersionOutput(run(`${bin} --version`));
23123
+ }
23124
+ function activeCliPath(bin = "threatcrush", run = defaultRunner) {
23125
+ const out = run(`command -v ${bin}`);
23126
+ return out ? out.trim().split("\n")[0] || null : null;
23127
+ }
23128
+ async function latestPublishedVersion(pkgName, timeoutMs = 8e3) {
23129
+ try {
23130
+ const res = await fetch(`https://registry.npmjs.org/${pkgName}/latest`, {
23131
+ signal: AbortSignal.timeout(timeoutMs)
23132
+ });
23133
+ if (!res.ok) return null;
23134
+ const body = await res.json();
23135
+ return body.version ?? null;
23136
+ } catch {
23137
+ return null;
23138
+ }
23139
+ }
23140
+ function shadowedUpdateWarning(latest, active, activePath) {
23141
+ if (!latest || !active || latest === active) return null;
23142
+ return [
23143
+ "\u26A0 The update ran, but PATH still resolves to an older ThreatCrush.",
23144
+ ` Latest published: ${latest}`,
23145
+ ` Running from PATH: ${active} (${activePath || "unknown"})`,
23146
+ "",
23147
+ " Usually a stale shell hash. Try first:",
23148
+ " hash -r # or open a new terminal",
23149
+ " If it persists, that path is a second copy \u2014 remove it:",
23150
+ ` rm ${activePath || "<path>"}`
23151
+ ];
23152
+ }
23153
+
23154
+ // src/index.ts
23071
23155
  var PKG_VERSION2 = "0.1.8";
23072
23156
  try {
23073
23157
  const pkg = JSON.parse((0, import_node_fs31.readFileSync)((0, import_node_path21.join)(__dirname, "..", "package.json"), "utf-8"));
@@ -23089,22 +23173,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
23089
23173
  var INSTALL_CONFIG_PATH = (0, import_node_path21.join)((0, import_node_os8.homedir)(), ".threatcrush", "install.json");
23090
23174
  function detectPackageManager() {
23091
23175
  try {
23092
- const npmGlobal = (0, import_node_child_process10.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
23176
+ const npmGlobal = (0, import_node_child_process11.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
23093
23177
  if (npmGlobal.includes(PKG_NAME)) return "npm";
23094
23178
  } catch {
23095
23179
  }
23096
23180
  try {
23097
- (0, import_node_child_process10.execSync)("pnpm --version", { stdio: "pipe" });
23181
+ (0, import_node_child_process11.execSync)("pnpm --version", { stdio: "pipe" });
23098
23182
  return "pnpm";
23099
23183
  } catch {
23100
23184
  }
23101
23185
  try {
23102
- (0, import_node_child_process10.execSync)("yarn --version", { stdio: "pipe" });
23186
+ (0, import_node_child_process11.execSync)("yarn --version", { stdio: "pipe" });
23103
23187
  return "yarn";
23104
23188
  } catch {
23105
23189
  }
23106
23190
  try {
23107
- (0, import_node_child_process10.execSync)("bun --version", { stdio: "pipe" });
23191
+ (0, import_node_child_process11.execSync)("bun --version", { stdio: "pipe" });
23108
23192
  return "bun";
23109
23193
  } catch {
23110
23194
  }
@@ -23117,40 +23201,9 @@ function readInstallConfig() {
23117
23201
  return {};
23118
23202
  }
23119
23203
  }
23120
- function getGlobalInstallCommand(pm, pkgName, action) {
23121
- const commands = {
23122
- npm: {
23123
- install: `npm i -g ${pkgName}`,
23124
- update: `npm update -g ${pkgName}`,
23125
- remove: `npm uninstall -g ${pkgName}`
23126
- },
23127
- pnpm: {
23128
- install: `pnpm add -g ${pkgName}`,
23129
- update: `pnpm update -g ${pkgName}`,
23130
- remove: `pnpm remove -g ${pkgName}`
23131
- },
23132
- yarn: {
23133
- install: `yarn global add ${pkgName}`,
23134
- update: `yarn global upgrade ${pkgName}`,
23135
- remove: `yarn global remove ${pkgName}`
23136
- },
23137
- bun: {
23138
- install: `bun add -g ${pkgName}`,
23139
- update: `bun update -g ${pkgName}`,
23140
- remove: `bun remove -g ${pkgName}`
23141
- }
23142
- };
23143
- return commands[pm]?.[action] || commands.npm[action];
23144
- }
23145
23204
  function packageLooksInstalled(pm, pkgName) {
23146
23205
  try {
23147
- const listCommands = {
23148
- npm: `npm ls -g ${pkgName} --depth=0`,
23149
- pnpm: `pnpm list -g ${pkgName} --depth=0`,
23150
- yarn: `yarn global list --pattern ${pkgName}`,
23151
- bun: `bun pm ls -g`
23152
- };
23153
- const output = (0, import_node_child_process10.execSync)(listCommands[pm] || listCommands.npm, {
23206
+ const output = (0, import_node_child_process11.execSync)(globalListCommand(pm, pkgName), {
23154
23207
  encoding: "utf-8",
23155
23208
  stdio: ["pipe", "pipe", "pipe"]
23156
23209
  });
@@ -23159,6 +23212,24 @@ function packageLooksInstalled(pm, pkgName) {
23159
23212
  return false;
23160
23213
  }
23161
23214
  }
23215
+ function upgradeCommands(pkgName) {
23216
+ const holders = globalHolders(pkgName);
23217
+ const targets = holders.length > 0 ? holders : [detectPackageManager()];
23218
+ return targets.map((pm) => globalInstallCommand(pm, pkgName, "update"));
23219
+ }
23220
+ async function reportIfStillStale() {
23221
+ const warning = shadowedUpdateWarning(
23222
+ await latestPublishedVersion(PKG_NAME),
23223
+ activeCliVersion(),
23224
+ activeCliPath()
23225
+ );
23226
+ if (!warning) return;
23227
+ console.log(source_default.yellow(` ${warning[0]}`));
23228
+ for (const line of warning.slice(1)) {
23229
+ console.log(source_default.dim(` ${line}`));
23230
+ }
23231
+ console.log();
23232
+ }
23162
23233
  var program2 = new Command();
23163
23234
  program2.name("threatcrush").description(
23164
23235
  `${source_default.green("\u26A1 ThreatCrush")} \u2014 All-in-one security agent
@@ -23310,7 +23381,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
23310
23381
  console.log(source_default.green(` Tailing ${logPath}...
23311
23382
  `));
23312
23383
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
23313
- (0, import_node_child_process10.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
23384
+ (0, import_node_child_process11.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
23314
23385
  });
23315
23386
  program2.command("activate").description("Activate your license key").action(async () => {
23316
23387
  console.log(LOGO2);
@@ -23352,17 +23423,15 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
23352
23423
  if (opts.modules) {
23353
23424
  console.log(LOGO2);
23354
23425
  console.log(source_default.yellow(" Updating modules...\n"));
23355
- const pm2 = detectPackageManager();
23356
- const commands2 = [
23357
- getGlobalInstallCommand(pm2, PKG_NAME, "update")
23358
- ];
23426
+ const commands2 = upgradeCommands(PKG_NAME);
23359
23427
  try {
23360
23428
  for (const cmd of commands2) {
23361
23429
  console.log(source_default.green(` \u2192 ${cmd}
23362
23430
  `));
23363
- (0, import_node_child_process10.execSync)(cmd, { stdio: "inherit" });
23431
+ (0, import_node_child_process11.execSync)(cmd, { stdio: "inherit" });
23364
23432
  }
23365
23433
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
23434
+ await reportIfStillStale();
23366
23435
  } catch (err) {
23367
23436
  console.log(source_default.red("\n \u2717 Module update failed. Try manually:\n"));
23368
23437
  for (const cmd of commands2) {
@@ -23372,18 +23441,19 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
23372
23441
  }
23373
23442
  return;
23374
23443
  }
23375
- const pm = detectPackageManager();
23444
+ const holders = globalHolders(PKG_NAME);
23376
23445
  const installConfig = readInstallConfig();
23377
23446
  const installMode = opts.cli ? "server" : opts.desktop ? "desktop" : installConfig.installMode || "server";
23378
- console.log(source_default.dim(` Detected package manager: ${pm}`));
23379
- console.log(source_default.dim(` Install mode: ${installMode}
23447
+ console.log(source_default.dim(` Detected package manager: ${holders.join(", ") || detectPackageManager()}`));
23448
+ console.log(source_default.dim(` Install mode: ${installMode}`));
23449
+ console.log(source_default.dim(` Current version: ${PKG_VERSION2}
23380
23450
  `));
23381
- const commands = [getGlobalInstallCommand(pm, PKG_NAME, "update")];
23451
+ const commands = upgradeCommands(PKG_NAME);
23382
23452
  try {
23383
23453
  for (const cmd of commands) {
23384
23454
  console.log(source_default.green(` \u2192 ${cmd}
23385
23455
  `));
23386
- (0, import_node_child_process10.execSync)(cmd, { stdio: "inherit" });
23456
+ (0, import_node_child_process11.execSync)(cmd, { stdio: "inherit" });
23387
23457
  }
23388
23458
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
23389
23459
  if (installMode === "desktop") {
@@ -23391,6 +23461,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
23391
23461
  } else {
23392
23462
  console.log(source_default.dim(" Updated bundle: CLI only\n"));
23393
23463
  }
23464
+ await reportIfStillStale();
23394
23465
  } catch (err) {
23395
23466
  console.log(source_default.red("\n \u2717 Update failed. Try manually:\n"));
23396
23467
  for (const cmd of commands) {
@@ -23412,22 +23483,25 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
23412
23483
  console.log(source_default.dim("\n Cancelled.\n"));
23413
23484
  return;
23414
23485
  }
23415
- const pm = detectPackageManager();
23416
23486
  const installConfig = readInstallConfig();
23417
23487
  const installMode = installConfig.installMode || "server";
23418
- const commands = [getGlobalInstallCommand(pm, PKG_NAME, "remove")];
23419
- if (installMode === "desktop" && packageLooksInstalled(pm, DESKTOP_PKG_NAME)) {
23420
- commands.push(getGlobalInstallCommand(pm, DESKTOP_PKG_NAME, "remove"));
23488
+ const holders = globalHolders(PKG_NAME);
23489
+ const pms = holders.length > 0 ? holders : [detectPackageManager()];
23490
+ const commands = pms.map((pm) => globalInstallCommand(pm, PKG_NAME, "remove"));
23491
+ for (const pm of pms) {
23492
+ if (installMode === "desktop" && packageLooksInstalled(pm, DESKTOP_PKG_NAME)) {
23493
+ commands.push(globalInstallCommand(pm, DESKTOP_PKG_NAME, "remove"));
23494
+ }
23421
23495
  }
23422
23496
  console.log(source_default.dim(`
23423
- Detected package manager: ${pm}`));
23497
+ Detected package manager: ${pms.join(", ")}`));
23424
23498
  console.log(source_default.dim(` Install mode: ${installMode}
23425
23499
  `));
23426
23500
  try {
23427
23501
  for (const cmd of commands) {
23428
23502
  console.log(source_default.green(` \u2192 ${cmd}
23429
23503
  `));
23430
- (0, import_node_child_process10.execSync)(cmd, { stdio: "inherit" });
23504
+ (0, import_node_child_process11.execSync)(cmd, { stdio: "inherit" });
23431
23505
  }
23432
23506
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
23433
23507
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));