@fluid-app/fluid-cli 0.1.770 → 0.1.772

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
@@ -182,6 +182,34 @@ in the process list.
182
182
 
183
183
  ## Updates
184
184
 
185
+ `fluid version` lists the CLI and every plugin it loaded, with each one's
186
+ installed version, npm's latest, and the command that updates it. A newer
187
+ command, option or config key may need a newer CLI or plugin, so run it when
188
+ one is missing. `fluid version --json` prints the same for agents:
189
+
190
+ ```json
191
+ {
192
+ "packages": [
193
+ {
194
+ "name": "@fluid-app/fluid-cli",
195
+ "installed": "0.1.700",
196
+ "latest": "0.1.762",
197
+ "update": {
198
+ "command": "npm install -g @fluid-app/fluid-cli",
199
+ "directory": null
200
+ }
201
+ }
202
+ ]
203
+ }
204
+ ```
205
+
206
+ `update.directory` names the project to run the command in, for a copy a
207
+ project installed; the text report says "in that project" and leaves the
208
+ folder to `--json`. A copy Mist bundles has `"update": { "app": "Mist" }`, and
209
+ one no command can update, such as a plugin an npx run loaded, has `null`.
210
+
211
+ `fluid --version` still prints only the CLI's own version.
212
+
185
213
  Once a day an interactive run starts a detached background check of npm for
186
214
  a newer `@fluid-app/fluid-cli`, and a newer `@fluid-app/fluid-cli-member-site`
187
215
  (the Sites plugin); no command waits on it. When the last check found one, a
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-CuN5vh0j.mjs";
2
+ import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-Df5DNHUo.mjs";
3
3
  import { A as isClientProfile, C as readStoredConfig, D as getConfigDir, E as isStrictConfig, S as readConfig, T as writeConfig, _ as primeClientProfile, c as sessionFacts, j as isIdentityProfile, l as signInWithBrowser, n as describeIdentityError, o as primeIdentityProfile, p as clientAccessToken, r as identityToken, t as endUnusedSessions, u as signOutIdentity, w as updateConfig, y as resolveIdentityUrl } from "../profiles-5slwyRzI.mjs";
4
4
  import { createRequire } from "node:module";
5
- import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
5
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { Argument, Command, Option } from "commander";
8
- import { dirname, isAbsolute, join, relative, sep } from "node:path";
8
+ import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
9
9
  import { createHash, randomBytes, randomUUID } from "node:crypto";
10
10
  import { tmpdir } from "node:os";
11
11
  import { text } from "node:stream/consumers";
@@ -42,7 +42,7 @@ function missingPluginHint(program, args, enabledPlugins) {
42
42
  * fluid commands — list every installed command, or print the catalog as
43
43
  * JSON for agents and documentation generators.
44
44
  */
45
- const { version: version$1 } = createRequire(import.meta.url)("../../package.json");
45
+ const { version: version$2 } = createRequire(import.meta.url)("../../package.json");
46
46
  function usage(entry) {
47
47
  const args = entry.arguments.map((arg) => {
48
48
  const name = arg.variadic ? `${arg.name}...` : arg.name;
@@ -74,7 +74,7 @@ const commandsCommand = new Command("commands").description("List installed comm
74
74
  if (opts.json) {
75
75
  process.stdout.write(JSON.stringify({
76
76
  cli: root.name(),
77
- version: version$1,
77
+ version: version$2,
78
78
  commands: entries
79
79
  }, null, 2) + "\n");
80
80
  return;
@@ -1821,31 +1821,6 @@ const switchCommand = new Command("switch").description("Switch between companie
1821
1821
  await (identity ? performIdentitySwitch(identity, selected, activeBaseUrl) : performSwitch(token, selected, activeBaseUrl));
1822
1822
  });
1823
1823
  //#endregion
1824
- //#region src/auth/identity/prime.ts
1825
- /**
1826
- * Restores an identity-mode profile's session before a command runs, so the
1827
- * synchronous `getAuthToken()` that plugins call finds a current access
1828
- * token in memory. Legacy profiles and literal tokens are left alone: no
1829
- * credential store is touched and no request is made for them.
1830
- */
1831
- /**
1832
- * Primes the credential a command with these options would use. A session
1833
- * that cannot be restored is reported on stderr, and the command runs on as
1834
- * it would with no stored credential.
1835
- */
1836
- async function primeCommandCredential(options) {
1837
- if (typeof options.token === "string" && options.token) return;
1838
- const source = resolveCredentialSource(typeof options.profile === "string" && options.profile ? options.profile : void 0);
1839
- if (source?.kind !== "profile") return;
1840
- const { profile } = source;
1841
- try {
1842
- if (isIdentityProfile(profile)) await primeIdentityProfile(profile);
1843
- else if (isClientProfile(profile)) await primeClientProfile(profile);
1844
- } catch (error) {
1845
- process.stderr.write(`${chalk.yellow(describeIdentityError(error))}\n`);
1846
- }
1847
- }
1848
- //#endregion
1849
1824
  //#region src/plugins/discovery.ts
1850
1825
  /**
1851
1826
  * Auto-discover @fluid-app CLI plugins.
@@ -2402,21 +2377,23 @@ function loadedPackage(source, pkg) {
2402
2377
  }
2403
2378
  }
2404
2379
  /**
2380
+ * How `pkg`, installed under `root`, was installed, read from its own path
2381
+ * as the CLI's is: globally, by an npx run, or in a project, updated with
2382
+ * that project's package manager.
2383
+ */
2384
+ function packageInstallKind(root, pkg) {
2385
+ return detectInstallKind(join(root, "node_modules", pkg, "package.json"));
2386
+ }
2387
+ /**
2405
2388
  * The Sites plugin's update, for the copy this run loaded, when npm has a
2406
- * newer one. A copy in a project other than the CLI's own install is updated
2407
- * with that project's package manager. An npx run fetches its packages each
2408
- * time, so it has none.
2389
+ * newer one. An npx run fetches its packages each time, so it has none.
2409
2390
  */
2410
2391
  function sitesPluginUpdate(options, latest) {
2411
2392
  if (!latest) return null;
2412
2393
  const plugin = options.loadedPlugins?.().find((loaded) => loaded.name === SITES_PLUGIN_NAME);
2413
2394
  const installed = plugin && loadedPackage(plugin.source, "@fluid-app/fluid-cli-member-site");
2414
2395
  if (!installed || !isNewer(installed.version, latest)) return null;
2415
- const install = installed.root === installRoot(options.entryPath) ? detectInstallKind(options.entryPath) : {
2416
- kind: "local",
2417
- manager: projectManager(installed.root, existsSync),
2418
- projectDir: installed.root
2419
- };
2396
+ const install = packageInstallKind(installed.root, SITES_PLUGIN_NAME);
2420
2397
  if (install.kind === "npx") return null;
2421
2398
  return {
2422
2399
  name: "the Sites plugin (fluid sites)",
@@ -2543,7 +2520,8 @@ function startUpdateCheck(options) {
2543
2520
  const now = options.now ?? /* @__PURE__ */ new Date();
2544
2521
  const cache = readUpdateCache(options.configDir);
2545
2522
  if (cache?.latest || cache?.sitesPluginLatest) (options.onExit ?? ((listener) => process.once("exit", listener)))(() => {
2546
- if (audience === "agent" && (options.quiet?.() || existsSync(join(options.configDir, agentNoticeClaim(now))))) return;
2523
+ if (options.quiet?.(audience)) return;
2524
+ if (audience === "agent" && existsSync(join(options.configDir, agentNoticeClaim(now)))) return;
2547
2525
  const updates = pendingUpdates(options, cache);
2548
2526
  if (updates.length === 0) return;
2549
2527
  if (audience === "person") process.stderr.write(personNotice(updates));
@@ -2557,6 +2535,144 @@ function startUpdateCheck(options) {
2557
2535
  })) (options.refresh ?? spawnRefresh)(options.entryPath);
2558
2536
  }
2559
2537
  //#endregion
2538
+ //#region src/commands/version.ts
2539
+ /**
2540
+ * `fluid version`: the CLI's and each loaded plugin's version, npm's latest,
2541
+ * and the command that updates each. A person or a coding agent runs it to
2542
+ * learn whether a missing command, option or config key needs an update.
2543
+ */
2544
+ const { version: version$1 } = createRequire(import.meta.url)("../../package.json");
2545
+ /**
2546
+ * The packages Mist ships: under its app's resources, in
2547
+ * `app.asar.unpacked/node_modules/@fluid-app/`. Its app is a
2548
+ * `Fluid Mist.app` bundle on macOS, wherever it was moved; its Windows
2549
+ * installer puts it in `%LOCALAPPDATA%\mist-desktop\app-<version>`, and
2550
+ * its Linux packages in `/usr/lib/mist-desktop`.
2551
+ */
2552
+ const MIST_PACKAGES = new RegExp("(?:" + [
2553
+ String.raw`[\\/]Fluid Mist\.app[\\/]Contents[\\/]Resources`,
2554
+ String.raw`^[a-z]:[\\/]Users[\\/][^\\/]+[\\/]AppData[\\/]Local[\\/]mist-desktop[\\/]app-[^\\/]+[\\/]resources`,
2555
+ String.raw`^/usr/lib/mist-desktop/resources`
2556
+ ].join("|") + ")" + String.raw`[\\/]app\.asar\.unpacked[\\/]node_modules[\\/]@fluid-app[\\/]`, "i");
2557
+ /**
2558
+ * Whether the package at `path` is a copy Mist ships, which updates with
2559
+ * Mist. Mist also runs other CLIs, such as a project's own, through
2560
+ * Electron, so its path decides, not how it runs.
2561
+ */
2562
+ function isMistBundled(path) {
2563
+ return MIST_PACKAGES.test(path);
2564
+ }
2565
+ /**
2566
+ * Whether the install root `root` is an Electron app's unpacked resources:
2567
+ * an `app.asar.unpacked` folder beside the app's `app.asar` archive, which
2568
+ * Electron always writes together. No package manager command updates a
2569
+ * copy there, whichever app it came with; a project folder that is only
2570
+ * named so has no archive beside it.
2571
+ */
2572
+ function isAppResources(root) {
2573
+ if (basename(root).toLowerCase() !== "app.asar.unpacked") return false;
2574
+ try {
2575
+ return statSync(join(dirname(root), "app.asar")).isFile();
2576
+ } catch {
2577
+ return false;
2578
+ }
2579
+ }
2580
+ /**
2581
+ * How to update `name`, installed under `root` (null for a workspace
2582
+ * build). A copy Mist ships updates with Mist. No command updates a copy
2583
+ * inside another app's resources, or a plugin in an npx run's cache, as an
2584
+ * npx run fetches only the CLI afresh.
2585
+ */
2586
+ function updateFor(name, root) {
2587
+ if (root === null) return null;
2588
+ if (isMistBundled(join(root, "node_modules", name))) return { app: "Mist" };
2589
+ if (isAppResources(root)) return null;
2590
+ const install = packageInstallKind(root, name);
2591
+ if (install.kind === "npx" && name !== "@fluid-app/fluid-cli") return null;
2592
+ return {
2593
+ command: updateCommand(install, name),
2594
+ directory: install.kind === "local" ? install.projectDir : null
2595
+ };
2596
+ }
2597
+ /** The CLI and each plugin, with npm's latest versions asked for at once. */
2598
+ async function versionReport({ entryPath, currentVersion, plugins, fetchImpl = fetch }) {
2599
+ const packages = [{
2600
+ name: PACKAGE_NAME,
2601
+ installed: currentVersion,
2602
+ root: installRoot(entryPath)
2603
+ }, ...plugins.map(({ name, source }) => {
2604
+ const loaded = loadedPackage(source, name);
2605
+ return {
2606
+ name,
2607
+ installed: loaded?.version ?? null,
2608
+ root: loaded?.root ?? null
2609
+ };
2610
+ })];
2611
+ return Promise.all(packages.map(async ({ name, installed, root }) => {
2612
+ const latest = await fetchLatestVersion(fetchImpl, name);
2613
+ return {
2614
+ name,
2615
+ installed,
2616
+ latest,
2617
+ update: latest !== null && installed !== null && isNewer(installed, latest) ? updateFor(name, root) : null
2618
+ };
2619
+ }));
2620
+ }
2621
+ /**
2622
+ * The text report's update. It never prints a project's folder, which a
2623
+ * shell could read as code if the line were pasted into one; `--json` gives
2624
+ * the folder as a field of its own.
2625
+ */
2626
+ function updateText(update) {
2627
+ if ("app" in update) return `update ${update.app}, which brings its own copy`;
2628
+ return update.directory === null ? `run ${update.command}` : `run ${update.command} in that project; fluid version --json shows its folder`;
2629
+ }
2630
+ function statusText({ installed, latest, update }) {
2631
+ if (latest === null) return "latest unknown (not on npm, or npm couldn't be reached)";
2632
+ if (installed === null) return `latest ${latest}`;
2633
+ if (installed === latest || isNewer(latest, installed)) return "up to date";
2634
+ if (!isNewer(installed, latest)) return `latest ${latest}`;
2635
+ return `latest ${latest}: ${update ? updateText(update) : "no command updates this copy"}`;
2636
+ }
2637
+ function formatVersionReport(packages) {
2638
+ const nameWidth = Math.max(...packages.map(({ name }) => name.length));
2639
+ const versionWidth = Math.max(...packages.map(({ installed }) => (installed ?? "?").length));
2640
+ return packages.map((entry) => `${entry.name.padEnd(nameWidth)} ${(entry.installed ?? "?").padEnd(versionWidth)} ${statusText(entry)}`).join("\n");
2641
+ }
2642
+ const versionCommand = new Command("version").description("Show the CLI's and plugins' versions, npm's latest, and how to update").option("--json", "Print the versions as JSON", false).action(async (opts) => {
2643
+ const packages = await versionReport({
2644
+ entryPath: realpathSync(fileURLToPath(import.meta.url)),
2645
+ currentVersion: version$1,
2646
+ plugins: loadedPlugins()
2647
+ });
2648
+ process.stdout.write(opts.json ? JSON.stringify({ packages }, null, 2) + "\n" : formatVersionReport(packages) + "\n");
2649
+ });
2650
+ //#endregion
2651
+ //#region src/auth/identity/prime.ts
2652
+ /**
2653
+ * Restores an identity-mode profile's session before a command runs, so the
2654
+ * synchronous `getAuthToken()` that plugins call finds a current access
2655
+ * token in memory. Legacy profiles and literal tokens are left alone: no
2656
+ * credential store is touched and no request is made for them.
2657
+ */
2658
+ /**
2659
+ * Primes the credential a command with these options would use. A session
2660
+ * that cannot be restored is reported on stderr, and the command runs on as
2661
+ * it would with no stored credential.
2662
+ */
2663
+ async function primeCommandCredential(options) {
2664
+ if (typeof options.token === "string" && options.token) return;
2665
+ const source = resolveCredentialSource(typeof options.profile === "string" && options.profile ? options.profile : void 0);
2666
+ if (source?.kind !== "profile") return;
2667
+ const { profile } = source;
2668
+ try {
2669
+ if (isIdentityProfile(profile)) await primeIdentityProfile(profile);
2670
+ else if (isClientProfile(profile)) await primeClientProfile(profile);
2671
+ } catch (error) {
2672
+ process.stderr.write(`${chalk.yellow(describeIdentityError(error))}\n`);
2673
+ }
2674
+ }
2675
+ //#endregion
2560
2676
  //#region src/bin/fluid.ts
2561
2677
  const { version } = createRequire(import.meta.url)("../../package.json");
2562
2678
  if (process.argv[2] === "__refresh-update-check") {
@@ -2579,6 +2695,7 @@ program.addCommand(whoamiCommand);
2579
2695
  program.addCommand(profilesCommand);
2580
2696
  program.addCommand(switchCommand);
2581
2697
  program.addCommand(commandsCommand);
2698
+ program.addCommand(versionCommand);
2582
2699
  program.addCommand(completionCommand);
2583
2700
  program.addCommand(completeCommand, { hidden: true });
2584
2701
  const selfAuthenticating = new Set([
@@ -2589,14 +2706,18 @@ const selfAuthenticating = new Set([
2589
2706
  profilesCommand,
2590
2707
  switchCommand,
2591
2708
  commandsCommand,
2709
+ versionCommand,
2592
2710
  completionCommand,
2593
2711
  completeCommand
2594
2712
  ].map((command) => command.name()));
2595
2713
  registerInputsHook(program);
2596
- let quietNotice = false;
2714
+ const quietNoticeCommands = new Set([completeCommand, versionCommand]);
2715
+ let quietFor = [];
2597
2716
  program.hook("preAction", async (_program, actionCommand) => {
2598
2717
  const opts = actionCommand.optsWithGlobals();
2599
- quietNotice = actionCommand === completeCommand || opts["json"] === true || opts["format"] === "json";
2718
+ if (quietNoticeCommands.has(actionCommand)) quietFor = ["person", "agent"];
2719
+ else if (opts["json"] === true || opts["format"] === "json") quietFor = ["agent"];
2720
+ else quietFor = [];
2600
2721
  let topLevel = actionCommand;
2601
2722
  while (topLevel.parent && topLevel.parent !== program) topLevel = topLevel.parent;
2602
2723
  if (selfAuthenticating.has(topLevel.name())) return;
@@ -2611,7 +2732,7 @@ if (!inputsModeActive(process.env)) startUpdateCheck({
2611
2732
  entryPath: realpathSync(fileURLToPath(import.meta.url)),
2612
2733
  versions: process.versions,
2613
2734
  loadedPlugins,
2614
- quiet: () => quietNotice
2735
+ quiet: (audience) => quietFor.includes(audience)
2615
2736
  });
2616
2737
  await loadPlugins(program, packageRoot);
2617
2738
  const missingPlugin = missingPluginHint(program, process.argv.slice(2));