@persistmemory/cli 0.3.2 → 0.3.3

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/bin.js CHANGED
@@ -1404,7 +1404,7 @@ function shortDate(iso) {
1404
1404
  }
1405
1405
 
1406
1406
  // src/help.ts
1407
- var VERSION = true ? "0.3.2" : versionFromManifest();
1407
+ var VERSION = true ? "0.3.3" : versionFromManifest();
1408
1408
  var PACKAGE = "@persistmemory/cli";
1409
1409
  var HELP = `
1410
1410
  pm \u2014 PersistMemory from your terminal
@@ -2993,6 +2993,9 @@ import { existsSync as existsSync7, rmSync } from "node:fs";
2993
2993
  import { spawnSync } from "node:child_process";
2994
2994
  import { dirname as dirname4, resolve as resolve7 } from "node:path";
2995
2995
  import { fileURLToPath } from "node:url";
2996
+ function installArgs(pkg = PACKAGE) {
2997
+ return ["install", "-g", "--prefer-online", `${pkg}@latest`];
2998
+ }
2996
2999
  async function updateCommand(context) {
2997
3000
  const manager = installer();
2998
3001
  if (!manager) {
@@ -3001,19 +3004,38 @@ async function updateCommand(context) {
3001
3004
  );
3002
3005
  return 1;
3003
3006
  }
3007
+ const before = versionOf(manager);
3004
3008
  context.print(`Installing the newest ${PACKAGE}\u2026`);
3005
- const result = spawnSync(manager, ["install", "-g", `${PACKAGE}@latest`], {
3006
- stdio: "inherit"
3007
- });
3009
+ const result = spawnSync(manager, installArgs(), { stdio: "inherit" });
3008
3010
  if (result.status !== 0) {
3009
3011
  context.error(
3010
- "That did not work. If it failed on permissions, do NOT re-run it with sudo \u2014\npoint npm at a directory you own instead:\n npm config set prefix ~/.npm-global\n export PATH=$HOME/.npm-global/bin:$PATH"
3012
+ 'That did not work.\n\nIf npm said ETARGET or "no matching version", its cached list of versions is\nstale. Clear it and try again:\n npm cache clean --force\n\nIf it failed on permissions, do NOT re-run it with sudo \u2014 point npm at a\ndirectory you own instead:\n npm config set prefix ~/.npm-global\n export PATH=$HOME/.npm-global/bin:$PATH'
3011
3013
  );
3012
3014
  return result.status ?? 1;
3013
3015
  }
3014
- context.print("Done. `pm --version` will show the new one.");
3016
+ const after = versionOf(manager);
3017
+ if (after && before && after === before) {
3018
+ context.print(
3019
+ `npm finished, but ${PACKAGE} is still ${after}. That is usually a second copy
3020
+ earlier on your PATH \u2014 check with: which -a pm`
3021
+ );
3022
+ return 1;
3023
+ }
3024
+ context.print(after ? `Done \u2014 now on ${after}.` : "Done.");
3015
3025
  return 0;
3016
3026
  }
3027
+ function versionOf(manager) {
3028
+ const result = spawnSync(manager, ["ls", "-g", "--depth", "0", "--json", PACKAGE], {
3029
+ encoding: "utf8"
3030
+ });
3031
+ if (result.status !== 0 || !result.stdout) return void 0;
3032
+ try {
3033
+ const parsed = JSON.parse(result.stdout);
3034
+ return parsed.dependencies?.[PACKAGE]?.version;
3035
+ } catch {
3036
+ return void 0;
3037
+ }
3038
+ }
3017
3039
  async function uninstallCommand(context) {
3018
3040
  const manager = installer();
3019
3041
  if (!manager) {