lingo.dev 0.111.0 → 0.111.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/build/cli.mjs CHANGED
@@ -7464,21 +7464,25 @@ function withExponentialBackoff(fn, maxAttempts = 3, baseDelay = 1e3) {
7464
7464
  // src/cli/utils/observability.ts
7465
7465
  import pkg from "node-machine-id";
7466
7466
  var { machineIdSync } = pkg;
7467
+ async function createPosthogClient() {
7468
+ const { PostHog } = await import("posthog-node");
7469
+ const posthog = new PostHog(
7470
+ "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
7471
+ {
7472
+ host: "https://eu.i.posthog.com",
7473
+ flushAt: 1,
7474
+ flushInterval: 0
7475
+ }
7476
+ );
7477
+ return posthog;
7478
+ }
7467
7479
  async function trackEvent(distinctId, event, properties) {
7468
7480
  if (process.env.DO_NOT_TRACK) {
7469
7481
  return;
7470
7482
  }
7471
7483
  try {
7472
7484
  const actualId = distinctId || `device-${machineIdSync()}`;
7473
- const { PostHog } = await import("posthog-node");
7474
- const posthog = new PostHog(
7475
- "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
7476
- {
7477
- host: "https://eu.i.posthog.com",
7478
- flushAt: 1,
7479
- flushInterval: 0
7480
- }
7481
- );
7485
+ const posthog = await createPosthogClient();
7482
7486
  await posthog.capture({
7483
7487
  distinctId: actualId,
7484
7488
  event,
@@ -7490,7 +7494,6 @@ async function trackEvent(distinctId, event, properties) {
7490
7494
  }
7491
7495
  }
7492
7496
  });
7493
- await posthog.shutdown();
7494
7497
  } catch (error) {
7495
7498
  if (process.env.DEBUG) {
7496
7499
  console.error(error);
@@ -7689,7 +7692,7 @@ var i18n_default = new Command12().command("i18n").description("Run Localization
7689
7692
  authId = auth.id;
7690
7693
  ora.succeed(`Authenticated as ${auth.email}`);
7691
7694
  }
7692
- trackEvent(authId, "cmd.i18n.start", {
7695
+ await trackEvent(authId, "cmd.i18n.start", {
7693
7696
  i18nConfig,
7694
7697
  flags
7695
7698
  });
@@ -7711,7 +7714,9 @@ var i18n_default = new Command12().command("i18n").description("Run Localization
7711
7714
  ora.fail(
7712
7715
  "No buckets found. All buckets were filtered out by --file option."
7713
7716
  );
7714
- process.exit(1);
7717
+ throw new Error(
7718
+ "No buckets found. All buckets were filtered out by --file option."
7719
+ );
7715
7720
  } else {
7716
7721
  ora.info(`\x1B[36mProcessing only filtered buckets:\x1B[0m`);
7717
7722
  buckets.map((bucket) => {
@@ -7836,7 +7841,9 @@ var i18n_default = new Command12().command("i18n").description("Run Localization
7836
7841
  `Localization data has changed; please update i18n.lock or run without --frozen.`
7837
7842
  );
7838
7843
  ora.fail(` Details: ${message}`);
7839
- process.exit(1);
7844
+ throw new Error(
7845
+ `Localization data has changed; please update i18n.lock or run without --frozen. Details: ${message}`
7846
+ );
7840
7847
  } else {
7841
7848
  ora.succeed("No lockfile updates required.");
7842
7849
  }
@@ -8000,23 +8007,22 @@ var i18n_default = new Command12().command("i18n").description("Run Localization
8000
8007
  console.log();
8001
8008
  if (!hasErrors) {
8002
8009
  ora.succeed("Localization completed.");
8003
- trackEvent(authId, "cmd.i18n.success", {
8010
+ await trackEvent(authId, "cmd.i18n.success", {
8004
8011
  i18nConfig,
8005
8012
  flags
8006
8013
  });
8007
8014
  } else {
8008
8015
  ora.warn("Localization completed with errors.");
8009
- trackEvent(authId || "unknown", "cmd.i18n.error", {
8016
+ await trackEvent(authId || "unknown", "cmd.i18n.error", {
8010
8017
  flags
8011
8018
  });
8012
8019
  }
8013
8020
  } catch (error) {
8014
8021
  ora.fail(error.message);
8015
- trackEvent(authId || "unknown", "cmd.i18n.error", {
8022
+ await trackEvent(authId || "unknown", "cmd.i18n.error", {
8016
8023
  flags,
8017
8024
  error
8018
8025
  });
8019
- process.exit(1);
8020
8026
  }
8021
8027
  });
8022
8028
  function parseFlags(options) {
@@ -9464,7 +9470,7 @@ var run_default = new Command16().command("run").description("Run Lingo.dev loca
9464
9470
  await renderSpacer();
9465
9471
  await setup(ctx);
9466
9472
  authId = await determineAuthId(ctx);
9467
- trackEvent(authId, "cmd.run.start", {
9473
+ await trackEvent(authId, "cmd.run.start", {
9468
9474
  config: ctx.config,
9469
9475
  flags: ctx.flags
9470
9476
  });
@@ -9478,13 +9484,13 @@ var run_default = new Command16().command("run").description("Run Lingo.dev loca
9478
9484
  if (ctx.flags.watch) {
9479
9485
  await watch2(ctx);
9480
9486
  }
9481
- trackEvent(authId, "cmd.run.success", {
9487
+ await trackEvent(authId, "cmd.run.success", {
9482
9488
  config: ctx.config,
9483
9489
  flags: ctx.flags
9484
9490
  });
9485
9491
  } catch (error) {
9486
- trackEvent(authId || "unknown", "cmd.run.error", {});
9487
- process.exit(1);
9492
+ await trackEvent(authId || "unknown", "cmd.run.error", {});
9493
+ throw error;
9488
9494
  }
9489
9495
  });
9490
9496
 
@@ -10221,6 +10227,41 @@ import Z11 from "zod";
10221
10227
  import Ora10 from "ora";
10222
10228
  import chalk14 from "chalk";
10223
10229
  import Table from "cli-table3";
10230
+
10231
+ // src/cli/utils/exit-gracefully.ts
10232
+ var STEP_WAIT_INTERVAL = 250;
10233
+ var MAX_WAIT_INTERVAL = 2e3;
10234
+ function exitGracefully(elapsedMs = 0) {
10235
+ const hasPendingOperations = checkForPendingOperations();
10236
+ if (hasPendingOperations && elapsedMs < MAX_WAIT_INTERVAL) {
10237
+ setTimeout(
10238
+ () => exitGracefully(elapsedMs + STEP_WAIT_INTERVAL),
10239
+ STEP_WAIT_INTERVAL
10240
+ );
10241
+ } else {
10242
+ process.exit(0);
10243
+ }
10244
+ }
10245
+ function checkForPendingOperations() {
10246
+ const activeHandles = process._getActiveHandles?.() || [];
10247
+ const activeRequests = process._getActiveRequests?.() || [];
10248
+ const nonStandardHandles = activeHandles.filter((handle) => {
10249
+ if (handle === process.stdin || handle === process.stdout || handle === process.stderr) {
10250
+ return false;
10251
+ }
10252
+ if (handle && typeof handle === "object" && "hasRef" in handle && !handle.hasRef()) {
10253
+ return false;
10254
+ }
10255
+ return true;
10256
+ });
10257
+ const hasFileWatchers = nonStandardHandles.some(
10258
+ (handle) => handle && typeof handle === "object" && "close" in handle
10259
+ );
10260
+ const hasPendingPromises = activeRequests.length > 0;
10261
+ return nonStandardHandles.length > 0 || hasFileWatchers || hasPendingPromises;
10262
+ }
10263
+
10264
+ // src/cli/cmd/status.ts
10224
10265
  var status_default = new Command18().command("status").description("Show the status of the localization process").helpOption("-h, --help", "Show help").option(
10225
10266
  "--locale <locale>",
10226
10267
  "Locale to process",
@@ -10656,6 +10697,7 @@ var status_default = new Command18().command("status").description("Show the sta
10656
10697
  totalWordsToTranslate,
10657
10698
  authenticated: !!authId
10658
10699
  });
10700
+ exitGracefully();
10659
10701
  } catch (error) {
10660
10702
  ora.fail(error.message);
10661
10703
  trackEvent(authId || "status", "cmd.status.error", {
@@ -10800,7 +10842,7 @@ async function renderHero2() {
10800
10842
  // package.json
10801
10843
  var package_default = {
10802
10844
  name: "lingo.dev",
10803
- version: "0.111.0",
10845
+ version: "0.111.2",
10804
10846
  description: "Lingo.dev CLI",
10805
10847
  private: false,
10806
10848
  publishConfig: {
@@ -10982,7 +11024,7 @@ var package_default = {
10982
11024
  "p-limit": "^6.2.0",
10983
11025
  "php-array-reader": "^2.1.2",
10984
11026
  plist: "^3.1.0",
10985
- "posthog-node": "^5.5.1",
11027
+ "posthog-node": "^5.8.1",
10986
11028
  prettier: "^3.4.2",
10987
11029
  react: "^18.3.1",
10988
11030
  "rehype-stringify": "^10.0.1",