@fluid-app/fluid-cli 0.1.732 → 0.1.733

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
@@ -183,8 +183,11 @@ in the process list.
183
183
  ## Updates
184
184
 
185
185
  Once a day an interactive run starts a detached background check of npm for
186
- a newer `@fluid-app/fluid-cli`; no command waits on it. When the last check
187
- found one, a short notice prints on stderr after the command finishes.
186
+ a newer `@fluid-app/fluid-cli`, and a newer `@fluid-app/fluid-cli-member-site`
187
+ (the Sites plugin); no command waits on it. When the last check found one, a
188
+ short notice prints on stderr after the command finishes. The Sites plugin's
189
+ notice is about the copy the command loaded, and names the command that
190
+ updates that copy.
188
191
  A failed check is retried the next day. It never runs in CI, when output is piped, or for a
189
192
  workspace build. Set `FLUID_NO_UPDATE_CHECK=1` (or `NO_UPDATE_NOTIFIER=1`)
190
193
  to turn it off.
@@ -1,5 +1,5 @@
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-BGEeIspy.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-D9VgFs2r.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-DmgZsxMS.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
@@ -2043,10 +2043,16 @@ function isFluidPlugin(value) {
2043
2043
  const obj = value;
2044
2044
  return typeof obj["name"] === "string" && typeof obj["version"] === "string" && typeof obj["register"] === "function";
2045
2045
  }
2046
+ const loaded = [];
2047
+ /** The plugins the last loadPlugins registered, in the order it did. */
2048
+ function loadedPlugins() {
2049
+ return loaded;
2050
+ }
2046
2051
  /**
2047
2052
  * Discover, import, and register all installed plugins
2048
2053
  */
2049
2054
  async function loadPlugins(program, basePath) {
2055
+ loaded.length = 0;
2050
2056
  const preferInstallation = process.env["FLUID_CLI_PREFER_INSTALLATION_PLUGINS"] === "1";
2051
2057
  const discovered = discoverPlugins(basePath, void 0, {
2052
2058
  preferInstallation,
@@ -2072,6 +2078,10 @@ async function loadPlugins(program, basePath) {
2072
2078
  continue;
2073
2079
  }
2074
2080
  await exported.register(ctx);
2081
+ loaded.push({
2082
+ name,
2083
+ source
2084
+ });
2075
2085
  if (verbose) console.error(chalk.dim(formatPluginLoadLine({
2076
2086
  name: exported.name,
2077
2087
  version: exported.version,
@@ -2092,12 +2102,18 @@ async function loadPlugins(program, basePath) {
2092
2102
  //#endregion
2093
2103
  //#region src/update/notifier.ts
2094
2104
  /**
2095
- * Tell an interactive user, at most once a day, that a newer fluid CLI is
2096
- * on npm. The check never holds a command open: a run prints what the last
2097
- * check found, and a stale cache is refreshed by a detached child process
2098
- * for next time.
2105
+ * Tell an interactive user, at most once a day, that a newer fluid CLI, or a
2106
+ * newer Sites plugin beside it, is on npm. The check never holds a command
2107
+ * open: a run prints what the last check found, and a stale cache is
2108
+ * refreshed by a detached child process for next time.
2099
2109
  */
2100
2110
  const PACKAGE_NAME = "@fluid-app/fluid-cli";
2111
+ /**
2112
+ * The plugin that adds the Sites commands. It ships on its own, so a CLI
2113
+ * that is up to date can still run a Sites plugin too old for a teammate's
2114
+ * site, and its notice is the only hint of that.
2115
+ */
2116
+ const SITES_PLUGIN_NAME = "@fluid-app/fluid-cli-member-site";
2101
2117
  /** The argument the CLI entry point treats as "refresh the cache and exit". */
2102
2118
  const REFRESH_ARG = "__refresh-update-check";
2103
2119
  const FETCH_TIMEOUT_MS = 5e3;
@@ -2188,37 +2204,99 @@ function detectInstallKind(entryPath, exists = existsSync) {
2188
2204
  };
2189
2205
  }
2190
2206
  const PLUGINS_NOTE = "(and any @fluid-app/fluid-cli-* plugins you use)";
2191
- function globalCommand(manager) {
2207
+ function globalCommand(manager, pkg) {
2192
2208
  switch (manager) {
2193
- case "npm": return `npm install -g ${PACKAGE_NAME}`;
2194
- case "pnpm": return `pnpm add -g ${PACKAGE_NAME}@latest`;
2209
+ case "npm": return `npm install -g ${pkg}`;
2210
+ case "pnpm": return `pnpm add -g ${pkg}@latest`;
2195
2211
  case "yarn":
2196
- case "yarn-classic": return `yarn global add ${PACKAGE_NAME}@latest`;
2197
- case "bun": return `bun add -g ${PACKAGE_NAME}@latest`;
2212
+ case "yarn-classic": return `yarn global add ${pkg}@latest`;
2213
+ case "bun": return `bun add -g ${pkg}@latest`;
2198
2214
  }
2199
2215
  }
2200
- function localCommand(manager) {
2216
+ function localCommand(manager, pkg) {
2201
2217
  switch (manager) {
2202
- case "npm": return `npm install ${PACKAGE_NAME}@latest`;
2203
- case "pnpm": return `pnpm update --latest ${PACKAGE_NAME}`;
2204
- case "yarn": return `yarn up ${PACKAGE_NAME}@latest`;
2205
- case "yarn-classic": return `yarn upgrade --latest ${PACKAGE_NAME}`;
2206
- case "bun": return `bun update --latest ${PACKAGE_NAME}`;
2218
+ case "npm": return `npm install ${pkg}@latest`;
2219
+ case "pnpm": return `pnpm update --latest ${pkg}`;
2220
+ case "yarn": return `yarn up ${pkg}@latest`;
2221
+ case "yarn-classic": return `yarn upgrade --latest ${pkg}`;
2222
+ case "bun": return `bun update --latest ${pkg}`;
2207
2223
  }
2208
2224
  }
2209
- function updateInstruction(install) {
2225
+ /**
2226
+ * The command that updates `pkg` for this install. The CLI's own names the
2227
+ * plugins too, unless a plugin's own notice follows it.
2228
+ */
2229
+ function updateInstruction(install, pkg = PACKAGE_NAME, notePlugins = true) {
2230
+ const note = notePlugins ? ` ${PLUGINS_NOTE}` : "";
2210
2231
  switch (install.kind) {
2211
- case "global": return `Run: ${globalCommand(install.manager)} ${PLUGINS_NOTE}\n`;
2212
- case "npx": return `Run: npx ${PACKAGE_NAME}@latest to use the latest version\n`;
2213
- case "local": return `Run in ${install.projectDir}: ${localCommand(install.manager)} ${PLUGINS_NOTE}\n`;
2232
+ case "global": return `Run: ${globalCommand(install.manager, pkg)}${note}\n`;
2233
+ case "npx": return `Run: npx ${pkg}@latest to use the latest version\n`;
2234
+ case "local": return `Run in ${install.projectDir}: ${localCommand(install.manager, pkg)}${note}\n`;
2214
2235
  }
2215
2236
  }
2216
- function updateNotice(current, latest, install = {
2217
- kind: "global",
2218
- manager: "npm"
2219
- }) {
2237
+ const OPT_OUT = `Set FLUID_NO_UPDATE_CHECK=1 to stop these notices.\n`;
2238
+ function cliNoticeBody(current, latest, install, notePlugins = true) {
2220
2239
  if (!isNewer(current, latest)) return null;
2221
- return `\nUpdate available for fluid: ${current} → ${latest}\n` + updateInstruction(install) + `Set FLUID_NO_UPDATE_CHECK=1 to stop these notices.\n`;
2240
+ return `\nUpdate available for fluid: ${current} → ${latest}\n` + updateInstruction(install, PACKAGE_NAME, notePlugins);
2241
+ }
2242
+ /** An npx run fetches its packages each time, so it gets no plugin notice. */
2243
+ function pluginNoticeBody(installed, latest, install) {
2244
+ if (install.kind === "npx") return null;
2245
+ return `\nUpdate available for the Sites plugin (fluid sites): ${installed} → ${latest}\n` + updateInstruction(install, SITES_PLUGIN_NAME, false);
2246
+ }
2247
+ /** The folder before the first `node_modules` in a path: its install's root. */
2248
+ function installRoot(path) {
2249
+ const at = path.replaceAll("\\", "/").indexOf("/node_modules/");
2250
+ return at === -1 ? null : path.slice(0, at);
2251
+ }
2252
+ /**
2253
+ * The version and install root of `pkg` loaded from `source`, read from its
2254
+ * package.json. Null for a workspace build, which no notice is for, or when
2255
+ * the file can't be read.
2256
+ */
2257
+ function loadedPackage(source, pkg) {
2258
+ let path;
2259
+ try {
2260
+ path = fileURLToPath(source);
2261
+ } catch {
2262
+ return null;
2263
+ }
2264
+ const marker = `/node_modules/${pkg}/`;
2265
+ const at = path.replaceAll("\\", "/").lastIndexOf(marker);
2266
+ const root = installRoot(path);
2267
+ if (at === -1 || root === null) return null;
2268
+ try {
2269
+ const { version } = JSON.parse(readFileSync(join(path.slice(0, at + marker.length), "package.json"), "utf8"));
2270
+ return typeof version === "string" ? {
2271
+ version,
2272
+ root
2273
+ } : null;
2274
+ } catch {
2275
+ return null;
2276
+ }
2277
+ }
2278
+ /**
2279
+ * The Sites plugin's notice, for the copy this run loaded, when npm has a
2280
+ * newer one. A copy in a project other than the CLI's own install is updated
2281
+ * with that project's package manager.
2282
+ */
2283
+ function sitesPluginBody(options, latest) {
2284
+ if (!latest) return null;
2285
+ const plugin = options.loadedPlugins?.().find((loaded) => loaded.name === SITES_PLUGIN_NAME);
2286
+ const installed = plugin && loadedPackage(plugin.source, "@fluid-app/fluid-cli-member-site");
2287
+ if (!installed || !isNewer(installed.version, latest)) return null;
2288
+ const install = installed.root === installRoot(options.entryPath) ? detectInstallKind(options.entryPath) : {
2289
+ kind: "local",
2290
+ manager: projectManager(installed.root, existsSync),
2291
+ projectDir: installed.root
2292
+ };
2293
+ return pluginNoticeBody(installed.version, latest, install);
2294
+ }
2295
+ /** Everything the last check found to say, under one opt-out line, or null. */
2296
+ function exitNotice(options, cache) {
2297
+ const pluginBody = sitesPluginBody(options, cache.sitesPluginLatest);
2298
+ const notice = [cache.latest && isNewer(options.currentVersion, cache.latest) ? cliNoticeBody(options.currentVersion, cache.latest, detectInstallKind(options.entryPath), pluginBody === null) : null, pluginBody].filter(Boolean).join("");
2299
+ return notice ? notice + OPT_OUT : null;
2222
2300
  }
2223
2301
  function readUpdateCache(configDir) {
2224
2302
  try {
@@ -2227,7 +2305,8 @@ function readUpdateCache(configDir) {
2227
2305
  const latest = typeof data.latest === "string" ? data.latest : null;
2228
2306
  return {
2229
2307
  checkedAt: data.checkedAt,
2230
- latest
2308
+ latest,
2309
+ ...typeof data.sitesPluginLatest === "string" ? { sitesPluginLatest: data.sitesPluginLatest } : {}
2231
2310
  };
2232
2311
  } catch {
2233
2312
  return null;
@@ -2258,9 +2337,9 @@ function isStale(cache, now) {
2258
2337
  const checkedAt = Date.parse(cache.checkedAt);
2259
2338
  return Number.isNaN(checkedAt) || now.getTime() - checkedAt >= 864e5;
2260
2339
  }
2261
- async function fetchLatestVersion(fetchImpl = fetch) {
2340
+ async function fetchLatestVersion(fetchImpl = fetch, pkg = PACKAGE_NAME) {
2262
2341
  try {
2263
- const response = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
2342
+ const response = await fetchImpl(`https://registry.npmjs.org/${pkg}/latest`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
2264
2343
  if (!response.ok) return null;
2265
2344
  const body = await response.json();
2266
2345
  return typeof body.version === "string" ? body.version : null;
@@ -2269,14 +2348,19 @@ async function fetchLatestVersion(fetchImpl = fetch) {
2269
2348
  }
2270
2349
  }
2271
2350
  /**
2272
- * Ask npm for the latest version and record it. Runs in the detached child;
2273
- * a failure leaves the last known version and the throttle stamp in place.
2351
+ * Ask npm for the latest CLI and Sites plugin and record them. Runs in the
2352
+ * detached child; a failure leaves the last known versions and the throttle
2353
+ * stamp in place.
2274
2354
  */
2275
2355
  async function refreshUpdateCache(configDir, fetchImpl = fetch, now = /* @__PURE__ */ new Date()) {
2276
- const latest = await fetchLatestVersion(fetchImpl);
2277
- if (latest) writeUpdateCache(configDir, {
2356
+ const [latest, sitesPluginLatest] = await Promise.all([fetchLatestVersion(fetchImpl), fetchLatestVersion(fetchImpl, SITES_PLUGIN_NAME)]);
2357
+ if (!latest && !sitesPluginLatest) return;
2358
+ const known = readUpdateCache(configDir);
2359
+ const plugin = sitesPluginLatest ?? known?.sitesPluginLatest;
2360
+ writeUpdateCache(configDir, {
2278
2361
  checkedAt: now.toISOString(),
2279
- latest
2362
+ latest: latest ?? known?.latest ?? null,
2363
+ ...plugin ? { sitesPluginLatest: plugin } : {}
2280
2364
  });
2281
2365
  }
2282
2366
  /** Start `node <entry> __refresh-update-check` detached, so this run never waits on npm. */
@@ -2301,12 +2385,15 @@ function startUpdateCheck(options) {
2301
2385
  if (!shouldCheckForUpdates(options)) return;
2302
2386
  const now = options.now ?? /* @__PURE__ */ new Date();
2303
2387
  const cache = readUpdateCache(options.configDir);
2304
- const notice = cache?.latest ? updateNotice(options.currentVersion, cache.latest, detectInstallKind(options.entryPath)) : null;
2305
- if (notice) (options.onExit ?? ((listener) => process.once("exit", listener)))(() => process.stderr.write(notice));
2388
+ if (cache?.latest || cache?.sitesPluginLatest) (options.onExit ?? ((listener) => process.once("exit", listener)))(() => {
2389
+ const notice = exitNotice(options, cache);
2390
+ if (notice) process.stderr.write(notice);
2391
+ });
2306
2392
  if (!isStale(cache, now)) return;
2307
2393
  if (writeUpdateCache(options.configDir, {
2308
2394
  checkedAt: now.toISOString(),
2309
- latest: cache?.latest ?? null
2395
+ latest: cache?.latest ?? null,
2396
+ ...cache?.sitesPluginLatest ? { sitesPluginLatest: cache.sitesPluginLatest } : {}
2310
2397
  })) (options.refresh ?? spawnRefresh)(options.entryPath);
2311
2398
  }
2312
2399
  //#endregion
@@ -2359,7 +2446,8 @@ if (!inputsModeActive(process.env)) startUpdateCheck({
2359
2446
  stdoutIsTTY: Boolean(process.stdout.isTTY),
2360
2447
  stderrIsTTY: Boolean(process.stderr.isTTY),
2361
2448
  entryPath: realpathSync(fileURLToPath(import.meta.url)),
2362
- versions: process.versions
2449
+ versions: process.versions,
2450
+ loadedPlugins
2363
2451
  });
2364
2452
  await loadPlugins(program, packageRoot);
2365
2453
  const missingPlugin = missingPluginHint(program, process.argv.slice(2));