lianrouter 2.2.1 → 2.2.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.
Files changed (2) hide show
  1. package/dist/cli.js +91 -2
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -17,7 +17,7 @@ var package_default;
17
17
  var init_package = __esm(() => {
18
18
  package_default = {
19
19
  name: "lianrouter",
20
- version: "2.2.1",
20
+ version: "2.2.2",
21
21
  description: "LianRouter launcher: install, run and control the gateway from one command",
22
22
  type: "module",
23
23
  bin: {
@@ -2820,6 +2820,82 @@ async function runUpdateSequence(deps) {
2820
2820
  }
2821
2821
  }
2822
2822
 
2823
+ // cli/src/update-notice.ts
2824
+ var ARROW = "\u2192";
2825
+ function renderUpdateNotices(input) {
2826
+ const lines = [];
2827
+ const launcher = input.launcher;
2828
+ if (launcher !== undefined && compareVersions(launcher.latest, launcher.current) > 0) {
2829
+ lines.push(`lianrouter: a newer launcher is published (${launcher.current} ${ARROW} ${launcher.latest}). Run: bun add -g lianrouter@latest`);
2830
+ }
2831
+ const gateway = input.gateway;
2832
+ if (gateway !== undefined && compareVersions(gateway.latest, gateway.current) > 0) {
2833
+ lines.push(`lianrouter: a gateway update is available (${gateway.current} ${ARROW} ${gateway.latest}). Run: lianrouter update`);
2834
+ }
2835
+ return lines;
2836
+ }
2837
+
2838
+ // cli/update/npm-source.ts
2839
+ var DEFAULT_REGISTRY_URL = "https://registry.npmjs.org/lianrouter/latest";
2840
+ var REGISTRY_URL = (() => {
2841
+ const override = process.env.LIANROUTER_NPM_REGISTRY;
2842
+ return override !== undefined && override.trim().length > 0 ? override.trim() : DEFAULT_REGISTRY_URL;
2843
+ })();
2844
+ var REQUEST_TIMEOUT_MS2 = 2500;
2845
+ var UPDATE_CHECK_DISABLE_ENV = "LIANROUTER_NO_UPDATE_CHECK";
2846
+ function updateCheckDisabled() {
2847
+ return process.env[UPDATE_CHECK_DISABLE_ENV] === "1";
2848
+ }
2849
+ var VERSION_SHAPE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
2850
+ function isSemverish(value) {
2851
+ return typeof value === "string" && VERSION_SHAPE.test(normalizeVersion(value));
2852
+ }
2853
+ async function checkLauncherVersion(options) {
2854
+ const url = options.registryUrl ?? REGISTRY_URL;
2855
+ const doFetch = options.fetchImpl ?? fetch;
2856
+ const controller = new AbortController;
2857
+ let timer;
2858
+ const deadline = new Promise((_resolve, reject) => {
2859
+ timer = setTimeout(() => {
2860
+ controller.abort();
2861
+ reject(new Error(`registry did not answer within ${REQUEST_TIMEOUT_MS2} ms`));
2862
+ }, REQUEST_TIMEOUT_MS2);
2863
+ });
2864
+ let response;
2865
+ try {
2866
+ response = await Promise.race([
2867
+ doFetch(url, { headers: { Accept: "application/json" }, signal: controller.signal }),
2868
+ deadline
2869
+ ]);
2870
+ } catch (error) {
2871
+ return {
2872
+ status: "unavailable",
2873
+ reason: `registry unreachable: ${error instanceof Error ? error.message : String(error)}`
2874
+ };
2875
+ } finally {
2876
+ clearTimeout(timer);
2877
+ }
2878
+ if (!response.ok) {
2879
+ return { status: "unavailable", reason: `registry returned ${response.status}` };
2880
+ }
2881
+ let payload;
2882
+ try {
2883
+ payload = await response.json();
2884
+ } catch {
2885
+ return { status: "unavailable", reason: "registry returned a non-JSON body" };
2886
+ }
2887
+ if (typeof payload !== "object" || payload === null || !("version" in payload)) {
2888
+ return { status: "unavailable", reason: "registry returned no usable version" };
2889
+ }
2890
+ const published = payload.version;
2891
+ if (!isSemverish(published)) {
2892
+ return { status: "unavailable", reason: "registry returned no usable version" };
2893
+ }
2894
+ const latest = normalizeVersion(published);
2895
+ const current = normalizeVersion(options.currentVersion);
2896
+ return compareVersions(latest, current) > 0 ? { status: "outdated", latest, current } : { status: "current", latest };
2897
+ }
2898
+
2823
2899
  // cli/src/tray-launcher.ts
2824
2900
  init_paths();
2825
2901
  import { existsSync as existsSync3 } from "fs";
@@ -3280,7 +3356,14 @@ ${cause}`);
3280
3356
  return supervisor.status;
3281
3357
  }
3282
3358
  async function runInteractive(supervisor, options, runtime) {
3359
+ const checkDisabled = updateCheckDisabled();
3360
+ const noticesApply = !options.background && !options.headless;
3361
+ const launcherCheck = checkDisabled || !noticesApply ? undefined : checkLauncherVersion({ currentVersion: CLI_VERSION }).catch(() => {
3362
+ return;
3363
+ });
3283
3364
  await ensureStarted(supervisor);
3365
+ const launcher = await launcherCheck;
3366
+ const launcherNotice = launcher?.status === "outdated" ? { launcher: { current: launcher.current, latest: launcher.latest } } : {};
3284
3367
  const session = await openSession(supervisor, runtime, options.host);
3285
3368
  if (options.background) {
3286
3369
  supervisor.detach();
@@ -3291,7 +3374,13 @@ async function runInteractive(supervisor, options, runtime) {
3291
3374
  if (options.headless) {
3292
3375
  return await blockUntilTrayExit(supervisor, session, runtime);
3293
3376
  }
3294
- const update = await readUpdateInfo(runtime.installRoot);
3377
+ const update = checkDisabled ? null : await readUpdateInfo(runtime.installRoot);
3378
+ for (const line of renderUpdateNotices({
3379
+ ...launcherNotice,
3380
+ ...update !== null && update.available ? { gateway: { current: update.current, latest: update.latest } } : {}
3381
+ })) {
3382
+ console.log(line);
3383
+ }
3295
3384
  const action = await promptMenu({
3296
3385
  version: CLI_VERSION,
3297
3386
  port: supervisor.status.port,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lianrouter",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "LianRouter launcher: install, run and control the gateway from one command",
5
5
  "type": "module",
6
6
  "bin": {