justmux 0.2.0 → 0.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 CHANGED
@@ -11,7 +11,9 @@ jm
11
11
  justmux
12
12
  ```
13
13
 
14
- Run the same npm install command to update to the latest release.
14
+ Run `jm update` (or `justmux update`) to check npm and update a global
15
+ installation directly, or `jm update --check` to check without installing. You
16
+ can also re-run the `npm install` command above.
15
17
 
16
18
  Global installations also check npm at most once a day when launched
17
19
  interactively without a command, including `--fullscreen` and `--inline`. A newer version opens
package/bin/justmux.cjs CHANGED
@@ -3,7 +3,10 @@
3
3
 
4
4
  async function main() {
5
5
  const args = process.argv.slice(2);
6
- const result = await require('../lib/update.cjs').maybeUpdate(args);
6
+ const updater = require('../lib/update.cjs');
7
+ const result = updater.isUpdateCommand(args)
8
+ ? await updater.runUpdate(args.slice(1))
9
+ : await updater.maybeUpdate(args);
7
10
  if (result.action === 'exit') {
8
11
  process.exitCode = result.code;
9
12
  return;
package/lib/launcher.cjs CHANGED
@@ -75,10 +75,14 @@ function run(args, options = {}) {
75
75
  );
76
76
  }
77
77
  const executable = resolveExecutable(manifest, { platform: runtime.platform, arch: runtime.arch });
78
+ const entry = typeof runtime.argv?.[1] === 'string' ? path.basename(runtime.argv[1]).toLowerCase() : '';
79
+ const env = entry === 'justmux' || entry === 'jm'
80
+ ? { ...runtime.env, JUSTMUX_INVOKED_AS: entry }
81
+ : runtime.env;
78
82
  try {
79
83
  // Replace Node rather than supervising tmux: signals, stdio and the PID
80
84
  // belong directly to the Rust application, then to tmux after attach.
81
- return runtime.execve(executable, [executable, ...args], runtime.env);
85
+ return runtime.execve(executable, [executable, ...args], env);
82
86
  } catch (error) {
83
87
  throw new Error(`Cannot execute the JustMux native binary: ${error.message}`, { cause: error });
84
88
  }
package/lib/update.cjs CHANGED
@@ -68,9 +68,10 @@ function defaultCachePath(runtime = process) {
68
68
  return path.join(home, runtime.platform === 'darwin' ? 'Library/Caches' : '.cache', 'justmux', 'update.json');
69
69
  }
70
70
 
71
- async function fetchLatest(name, { fetchImpl = globalThis.fetch, timeoutMs = 3000 } = {}) {
71
+ async function fetchLatest(name, { fetchImpl = globalThis.fetch, timeoutMs = 3000, maxTimeoutMs = 3000 } = {}) {
72
72
  if (!PACKAGE.test(name ?? '') || typeof fetchImpl !== 'function') throw new Error('Invalid update request');
73
- const timeout = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, 3000) : 3000;
73
+ const cap = Number.isFinite(maxTimeoutMs) && maxTimeoutMs > 0 ? maxTimeoutMs : 3000;
74
+ const timeout = Number.isFinite(timeoutMs) && timeoutMs > 0 ? Math.min(timeoutMs, cap) : cap;
74
75
  const controller = new AbortController();
75
76
  let timer;
76
77
  const deadline = new Promise((_, reject) => {
@@ -196,7 +197,7 @@ async function maybeUpdate(args, options = {}) {
196
197
  result = await (options.install ?? nativeInstall)('npm', installArgs, { stdio: 'inherit', shell: false });
197
198
  } catch { result = { status: 1 }; }
198
199
  if (result?.status === 0 && !result.signal) {
199
- runtime.stdout.write('JustMux updated. Run jm again to start the new version.\n');
200
+ runtime.stdout.write('JustMux updated. Run jm (or justmux) again to start the new version.\n');
200
201
  return { action: 'exit', code: 0 };
201
202
  }
202
203
  runtime.stdout.write(`JustMux update failed. Continuing with the installed version.\nTo retry: npm ${installArgs.map(quote).join(' ')}\n`);
@@ -204,4 +205,158 @@ async function maybeUpdate(args, options = {}) {
204
205
  } catch { return CONTINUE; }
205
206
  }
206
207
 
207
- module.exports = { maybeUpdate, compareVersions, detectGlobalPrefix, defaultCachePath, fetchLatest, updatePrompt };
208
+ function isUpdateCommand(args) {
209
+ return Array.isArray(args) && (args[0] === 'update' || args[0] === 'upgrade');
210
+ }
211
+
212
+ function readDismissedVersion(fs, cachePath) {
213
+ try {
214
+ const cache = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
215
+ if (typeof cache?.dismissedVersion === 'string') {
216
+ versionParts(cache.dismissedVersion);
217
+ return cache.dismissedVersion;
218
+ }
219
+ } catch { /* Ignore invalid or missing cache state. */ }
220
+ return undefined;
221
+ }
222
+
223
+ function writeUpdateCache(fs, cachePath, entry) {
224
+ try {
225
+ fs.mkdirSync(path.dirname(cachePath), { recursive: true });
226
+ fs.writeFileSync(cachePath, `${JSON.stringify(entry)}\n`, { mode: 0o600 });
227
+ } catch { /* A read-only cache must not fail an explicit update. */ }
228
+ }
229
+
230
+ const UPDATE_USAGE = [
231
+ 'Usage: jm update [--check]',
232
+ '',
233
+ 'Check npm for a newer JustMux release and update the global installation.',
234
+ 'Aliases: jm upgrade, justmux update, justmux upgrade',
235
+ '',
236
+ 'Options:',
237
+ ' --check Only check whether a newer release is available',
238
+ ' -h, --help Print help',
239
+ '',
240
+ ].join('\n');
241
+
242
+ /** Explicit `jm update` / `justmux update` workflow bypassing passive opt-outs and cache. */
243
+ async function runUpdate(restArgs = [], options = {}) {
244
+ const runtime = options.runtime ?? process;
245
+ const out = runtime.stdout ?? process.stdout;
246
+ const err = runtime.stderr ?? runtime.stdout ?? process.stderr;
247
+ let checkOnly = false;
248
+ for (const arg of Array.isArray(restArgs) ? restArgs : []) {
249
+ if (arg === '-h' || arg === '--help') {
250
+ out.write(UPDATE_USAGE);
251
+ return { action: 'exit', code: 0 };
252
+ }
253
+ if (arg === '--check') {
254
+ checkOnly = true;
255
+ continue;
256
+ }
257
+ err.write(`justmux: unexpected argument '${arg}' for 'update' (try 'jm update --help')\n`);
258
+ return { action: 'exit', code: 2 };
259
+ }
260
+
261
+ const fs = options.fs ?? nativeFs;
262
+ const packageRoot = options.packageRoot ?? path.resolve(__dirname, '..');
263
+ let manifest;
264
+ try {
265
+ manifest = options.manifest ?? JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
266
+ if (!PACKAGE.test(manifest?.name ?? '')) throw new Error('Invalid package name');
267
+ versionParts(manifest.version);
268
+ } catch (error) {
269
+ err.write(`justmux: invalid package metadata (${error.message}).\n`);
270
+ return { action: 'exit', code: 1 };
271
+ }
272
+
273
+ const supported = (runtime.platform === 'darwin' && runtime.arch === 'arm64')
274
+ || (runtime.platform === 'linux' && runtime.arch === 'x64');
275
+ if (!checkOnly && !supported) {
276
+ err.write(
277
+ `justmux: unsupported platform ${runtime.platform}/${runtime.arch}. JustMux supports macOS arm64 and Linux x64.\n`
278
+ + `Run: npm install -g ${manifest.name}@latest\n`,
279
+ );
280
+ return { action: 'exit', code: 1 };
281
+ }
282
+
283
+ const prefix = detectGlobalPrefix(packageRoot, manifest.name, fs);
284
+ if (!prefix && !checkOnly) {
285
+ err.write(
286
+ 'justmux: cannot self-update a non-global installation (such as npx, local node_modules, or npm link).\n'
287
+ + `Run: npm install -g ${manifest.name}@latest\n`,
288
+ );
289
+ return { action: 'exit', code: 1 };
290
+ }
291
+
292
+ let latest;
293
+ try {
294
+ latest = await fetchLatest(manifest.name, {
295
+ ...options,
296
+ timeoutMs: options.timeoutMs ?? 10000,
297
+ maxTimeoutMs: options.maxTimeoutMs ?? 15000,
298
+ });
299
+ } catch (error) {
300
+ err.write(
301
+ `justmux: failed to check npm for updates (${error.message}).\n`
302
+ + `To update manually: npm install -g ${manifest.name}@latest\n`,
303
+ );
304
+ return { action: 'exit', code: 1 };
305
+ }
306
+
307
+ if (!versionParts(manifest.version).prerelease.length && versionParts(latest).prerelease.length) {
308
+ out.write(`JustMux ${manifest.version} is already up to date.\n`);
309
+ return { action: 'exit', code: 0 };
310
+ }
311
+
312
+ const cachePath = options.cachePath ?? defaultCachePath(runtime);
313
+ const now = (options.now ?? Date.now)();
314
+ const validNow = Number.isFinite(now) && now >= 0;
315
+ const refreshCache = (dismissedVersion) => {
316
+ if (validNow) {
317
+ writeUpdateCache(fs, cachePath, { version: latest, time: now, ...(dismissedVersion && { dismissedVersion }) });
318
+ }
319
+ };
320
+
321
+ if (compareVersions(latest, manifest.version) <= 0) {
322
+ refreshCache(readDismissedVersion(fs, cachePath));
323
+ out.write(`JustMux ${manifest.version} is already up to date.\n`);
324
+ return { action: 'exit', code: 0 };
325
+ }
326
+
327
+ if (checkOnly) {
328
+ refreshCache(readDismissedVersion(fs, cachePath));
329
+ out.write(
330
+ `JustMux update available: ${manifest.version} -> ${latest}\n`
331
+ + "Run 'jm update' (or 'justmux update') to install.\n",
332
+ );
333
+ return { action: 'exit', code: 0 };
334
+ }
335
+
336
+ out.write(`Updating JustMux ${manifest.version} -> ${latest}...\n`);
337
+ const installArgs = ['install', '--global', '--prefix', prefix, `${manifest.name}@${latest}`, '--include=optional'];
338
+ let result;
339
+ try {
340
+ result = await (options.install ?? nativeInstall)('npm', installArgs, { stdio: 'inherit', shell: false });
341
+ } catch {
342
+ result = { status: 1 };
343
+ }
344
+ if (result?.status === 0 && !result.signal) {
345
+ refreshCache(undefined);
346
+ out.write(`JustMux updated to ${latest}. Run jm (or justmux) again to start the new version.\n`);
347
+ return { action: 'exit', code: 0 };
348
+ }
349
+ err.write(`JustMux update failed.\nTo retry: npm ${installArgs.map(quote).join(' ')}\n`);
350
+ return { action: 'exit', code: result?.status || 1 };
351
+ }
352
+
353
+ module.exports = {
354
+ maybeUpdate,
355
+ isUpdateCommand,
356
+ runUpdate,
357
+ compareVersions,
358
+ detectGlobalPrefix,
359
+ defaultCachePath,
360
+ fetchLatest,
361
+ updatePrompt,
362
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "justmux",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A modern slash-command interface for tmux. Just tmux. Just simpler.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "LICENSE"
32
32
  ],
33
33
  "optionalDependencies": {
34
- "justmux-darwin-arm64": "0.2.0",
35
- "justmux-linux-x64": "0.2.0"
34
+ "justmux-darwin-arm64": "0.3.0",
35
+ "justmux-linux-x64": "0.3.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public",