stop-wasting-tokens 2.0.1 → 2.0.2

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/cli.mjs CHANGED
@@ -9,7 +9,7 @@ import process16, { env, cwd, hrtime, execPath, execArgv, platform as platform$1
9
9
  import os, { type, constants, homedir } from 'os';
10
10
  import fs4, { readFile, mkdir, writeFile, stat, rename, unlink, readdir, realpath, lstat, open as open$1, constants as constants$1 } from 'fs/promises';
11
11
  import { promisify, debuglog, callbackify, parseArgs, aborted, inspect, stripVTControlCharacters } from 'util';
12
- import childProcess, { execFile, spawn, execSync, spawnSync, ChildProcess } from 'child_process';
12
+ import childProcess, { execFile, spawnSync, spawn, execSync, ChildProcess } from 'child_process';
13
13
  import { Buffer as Buffer$1 } from 'buffer';
14
14
  import { createServer } from 'net';
15
15
  import { randomBytes } from 'crypto';
@@ -31188,6 +31188,11 @@ function parseSwtArgv(argv) {
31188
31188
  strict: { type: "boolean", default: false },
31189
31189
  registry: { type: "string" },
31190
31190
  "no-cache": { type: "boolean", default: false },
31191
+ // swt update: --check skips the auto-apply (just print, like the
31192
+ // pre-2.0.2 behavior). Default behavior is now to actually run
31193
+ // the upgrade via the user's package manager.
31194
+ check: { type: "boolean", default: false },
31195
+ "no-marketplace": { type: "boolean", default: false },
31191
31196
  port: { type: "string" },
31192
31197
  host: { type: "string" },
31193
31198
  "unsafe-public": { type: "boolean", default: false },
@@ -35868,7 +35873,7 @@ async function pickPort(opts) {
35868
35873
 
35869
35874
  // packages/cli/src/commands/version.ts
35870
35875
  init_esm_shims();
35871
- var CURRENT_VERSION = "2.0.1" ;
35876
+ var CURRENT_VERSION = "2.0.2" ;
35872
35877
  function versionHandler(version = CURRENT_VERSION) {
35873
35878
  return (_parsed, io) => {
35874
35879
  io.stdout.write(`swt ${version}
@@ -48108,20 +48113,60 @@ async function queryLatestVersion(packageName, current, opts = {}) {
48108
48113
  }
48109
48114
 
48110
48115
  // packages/cli/src/commands/update.ts
48111
- var PACKAGE_NAME = "@swt-labs/cli";
48116
+ var PACKAGE_NAME = "stop-wasting-tokens";
48117
+ var PACKAGE_MANAGERS = [
48118
+ ["npm", ["install", "-g"]],
48119
+ ["pnpm", ["add", "-g"]],
48120
+ ["bun", ["add", "-g"]]
48121
+ ];
48112
48122
  var UPGRADE_COMMANDS = [
48113
- "npm install -g @swt-labs/cli@latest",
48114
- "pnpm add -g @swt-labs/cli@latest",
48115
- "bun add -g @swt-labs/cli@latest"
48123
+ `npm install -g ${PACKAGE_NAME}@latest`,
48124
+ `pnpm add -g ${PACKAGE_NAME}@latest`,
48125
+ `bun add -g ${PACKAGE_NAME}@latest`
48116
48126
  ];
48127
+ var defaultSpawnSync = (cmd, args, options) => spawnSync(cmd, [...args], options);
48128
+ function applyUpdate(io, spawnFn) {
48129
+ const triedMissing = [];
48130
+ for (const [bin, baseArgs] of PACKAGE_MANAGERS) {
48131
+ const args = [...baseArgs, `${PACKAGE_NAME}@latest`];
48132
+ io.stdout.write(`
48133
+ \u25C6 Running: ${bin} ${args.join(" ")}
48134
+ `);
48135
+ const result = spawnFn(bin, args, { stdio: "inherit" });
48136
+ if (result.error) {
48137
+ const code = result.error.code ?? "";
48138
+ if (code === "ENOENT") {
48139
+ triedMissing.push(bin);
48140
+ io.stdout.write(` ${bin} not found \u2014 trying next package manager...
48141
+ `);
48142
+ continue;
48143
+ }
48144
+ return { ok: false, reason: `${bin}: ${result.error.message}` };
48145
+ }
48146
+ if (result.status === 0) {
48147
+ return { ok: true, manager: bin };
48148
+ }
48149
+ return {
48150
+ ok: false,
48151
+ reason: `${bin} exited with code ${result.status ?? -1}${result.signal !== null ? ` (signal ${result.signal})` : ""}`
48152
+ };
48153
+ }
48154
+ return {
48155
+ ok: false,
48156
+ reason: `no package manager found on PATH (tried: ${triedMissing.join(", ")})`
48157
+ };
48158
+ }
48117
48159
  function updateHandler(opts = {}) {
48118
48160
  return async (parsed, io) => {
48119
48161
  const json = parsed.flags.json === true;
48120
48162
  const strict = parsed.flags.strict === true;
48163
+ const checkOnly = parsed.flags.check === true;
48121
48164
  const noCache = parsed.flags["no-cache"] === true;
48122
48165
  const noMarketplace = parsed.flags["no-marketplace"] === true;
48123
48166
  const registryFlag = parsed.flags.registry;
48124
48167
  const registry = typeof registryFlag === "string" ? registryFlag : void 0;
48168
+ const spawnFn = opts.spawnSync ?? defaultSpawnSync;
48169
+ const shouldApply = !json && !checkOnly;
48125
48170
  const queryOpts = {
48126
48171
  ...registry !== void 0 ? { registry } : {},
48127
48172
  noCache,
@@ -48192,12 +48237,40 @@ function updateHandler(opts = {}) {
48192
48237
  case "outdated":
48193
48238
  io.stdout.write(
48194
48239
  `\u2191 Update available: v${result.current} \u2192 v${result.latest}
48195
-
48196
- Upgrade with one of:
48197
48240
  `
48198
48241
  );
48199
- for (const cmd of UPGRADE_COMMANDS) {
48200
- io.stdout.write(` ${cmd}
48242
+ if (shouldApply) {
48243
+ const apply = applyUpdate(io, spawnFn);
48244
+ if (apply.ok) {
48245
+ io.stdout.write(
48246
+ `
48247
+ \u2713 Upgraded to v${result.latest} via ${apply.manager}.
48248
+ Restart any running 'swt' processes to pick up the new bin.
48249
+ `
48250
+ );
48251
+ } else {
48252
+ io.stderr.write(`
48253
+ \u2717 Upgrade failed: ${apply.reason}
48254
+
48255
+ `);
48256
+ io.stderr.write(`Run one of these manually:
48257
+ `);
48258
+ for (const cmd of UPGRADE_COMMANDS) {
48259
+ io.stderr.write(` ${cmd}
48260
+ `);
48261
+ }
48262
+ return EXIT.USAGE_ERROR;
48263
+ }
48264
+ } else {
48265
+ io.stdout.write(`
48266
+ Upgrade with one of:
48267
+ `);
48268
+ for (const cmd of UPGRADE_COMMANDS) {
48269
+ io.stdout.write(` ${cmd}
48270
+ `);
48271
+ }
48272
+ io.stdout.write(`
48273
+ (Or run \`swt update\` without --check to apply automatically.)
48201
48274
  `);
48202
48275
  }
48203
48276
  break;