lingo.dev 0.117.15 → 0.117.17

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
@@ -5477,23 +5477,25 @@ function createPoDataLoader(params) {
5477
5477
  const contextKey = _12.keys(sectionPo.translations)[0];
5478
5478
  const entries = sectionPo.translations[contextKey];
5479
5479
  const msgid = Object.keys(entries).find((key) => entries[key].msgid);
5480
+ const currentSection = currentSections.find((cs) => {
5481
+ const csPo = gettextParser.po.parse(cs);
5482
+ const csContextKey = _12.keys(csPo.translations)[0];
5483
+ const csEntries = csPo.translations[csContextKey];
5484
+ const csMsgid = Object.keys(csEntries).find(
5485
+ (key) => csEntries[key].msgid
5486
+ );
5487
+ return csMsgid === msgid;
5488
+ });
5480
5489
  if (!msgid) {
5481
- const currentSection = currentSections.find((cs) => {
5482
- const csPo = gettextParser.po.parse(cs);
5483
- const csContextKey = _12.keys(csPo.translations)[0];
5484
- const csEntries = csPo.translations[csContextKey];
5485
- const csMsgid = Object.keys(csEntries).find(
5486
- (key) => csEntries[key].msgid
5487
- );
5488
- return csMsgid === msgid;
5489
- });
5490
5490
  if (currentSection) {
5491
5491
  return currentSection;
5492
5492
  }
5493
5493
  return section;
5494
5494
  }
5495
5495
  if (data[msgid]) {
5496
+ const headers = currentSection ? gettextParser.po.parse(currentSection).headers : sectionPo.headers;
5496
5497
  const updatedPo = _12.merge({}, sectionPo, {
5498
+ headers,
5497
5499
  translations: {
5498
5500
  [contextKey]: {
5499
5501
  [msgid]: {
@@ -10796,27 +10798,128 @@ function withExponentialBackoff(fn, maxAttempts = 3, baseDelay = 1e3) {
10796
10798
  // src/cli/utils/observability.ts
10797
10799
  import pkg from "node-machine-id";
10798
10800
  import https from "https";
10801
+
10802
+ // src/cli/utils/repository-id.ts
10803
+ import { execSync } from "child_process";
10804
+ var cachedGitRepoId = void 0;
10805
+ function getRepositoryId() {
10806
+ const ciRepoId = getCIRepositoryId();
10807
+ if (ciRepoId) return ciRepoId;
10808
+ const gitRepoId = getGitRepositoryId();
10809
+ if (gitRepoId) return gitRepoId;
10810
+ return null;
10811
+ }
10812
+ function getCIRepositoryId() {
10813
+ if (process.env.GITHUB_REPOSITORY) {
10814
+ return `github:${process.env.GITHUB_REPOSITORY}`;
10815
+ }
10816
+ if (process.env.CI_PROJECT_PATH) {
10817
+ return `gitlab:${process.env.CI_PROJECT_PATH}`;
10818
+ }
10819
+ if (process.env.BITBUCKET_REPO_FULL_NAME) {
10820
+ return `bitbucket:${process.env.BITBUCKET_REPO_FULL_NAME}`;
10821
+ }
10822
+ return null;
10823
+ }
10824
+ function getGitRepositoryId() {
10825
+ if (cachedGitRepoId !== void 0) {
10826
+ return cachedGitRepoId;
10827
+ }
10828
+ try {
10829
+ const remoteUrl = execSync("git config --get remote.origin.url", {
10830
+ encoding: "utf8",
10831
+ stdio: ["pipe", "pipe", "ignore"]
10832
+ }).trim();
10833
+ if (!remoteUrl) {
10834
+ cachedGitRepoId = null;
10835
+ return null;
10836
+ }
10837
+ cachedGitRepoId = parseGitUrl(remoteUrl);
10838
+ return cachedGitRepoId;
10839
+ } catch {
10840
+ cachedGitRepoId = null;
10841
+ return null;
10842
+ }
10843
+ }
10844
+ function parseGitUrl(url) {
10845
+ const cleanUrl = url.replace(/\.git$/, "");
10846
+ let platform = null;
10847
+ if (cleanUrl.includes("github.com")) {
10848
+ platform = "github";
10849
+ } else if (cleanUrl.includes("gitlab.com")) {
10850
+ platform = "gitlab";
10851
+ } else if (cleanUrl.includes("bitbucket.org")) {
10852
+ platform = "bitbucket";
10853
+ }
10854
+ const sshMatch = cleanUrl.match(/[@:]([^:/@]+\/[^:/@]+)$/);
10855
+ const httpsMatch = cleanUrl.match(/\/([^/]+\/[^/]+)$/);
10856
+ const repoPath = sshMatch?.[1] || httpsMatch?.[1];
10857
+ if (!repoPath) return null;
10858
+ if (platform) {
10859
+ return `${platform}:${repoPath}`;
10860
+ }
10861
+ return `git:${repoPath}`;
10862
+ }
10863
+
10864
+ // src/cli/utils/observability.ts
10799
10865
  var { machineIdSync } = pkg;
10800
10866
  var POSTHOG_API_KEY = "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk";
10801
10867
  var POSTHOG_HOST = "eu.i.posthog.com";
10802
10868
  var POSTHOG_PATH = "/i/v0/e/";
10803
10869
  var REQUEST_TIMEOUT_MS = 1e3;
10870
+ var TRACKING_VERSION = "2.0";
10871
+ function determineDistinctId(providedId) {
10872
+ if (providedId) {
10873
+ const projectId = getRepositoryId();
10874
+ return {
10875
+ distinct_id: providedId,
10876
+ distinct_id_source: "email",
10877
+ project_id: projectId
10878
+ };
10879
+ }
10880
+ const repoId = getRepositoryId();
10881
+ if (repoId) {
10882
+ return {
10883
+ distinct_id: repoId,
10884
+ distinct_id_source: "git_repo",
10885
+ project_id: repoId
10886
+ };
10887
+ }
10888
+ const deviceId = `device-${machineIdSync()}`;
10889
+ if (process.env.DEBUG === "true") {
10890
+ console.warn(
10891
+ "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking."
10892
+ );
10893
+ }
10894
+ return {
10895
+ distinct_id: deviceId,
10896
+ distinct_id_source: "device",
10897
+ project_id: null
10898
+ };
10899
+ }
10804
10900
  function trackEvent(distinctId, event, properties) {
10805
10901
  if (process.env.DO_NOT_TRACK === "1") {
10806
10902
  return;
10807
10903
  }
10808
10904
  setImmediate(() => {
10809
10905
  try {
10810
- const actualId = distinctId || `device-${machineIdSync()}`;
10906
+ const identityInfo = determineDistinctId(distinctId);
10907
+ if (process.env.DEBUG === "true") {
10908
+ console.log(
10909
+ `[Tracking] Event: ${event}, ID: ${identityInfo.distinct_id}, Source: ${identityInfo.distinct_id_source}`
10910
+ );
10911
+ }
10811
10912
  const eventData = {
10812
10913
  api_key: POSTHOG_API_KEY,
10813
10914
  event,
10814
- distinct_id: actualId,
10915
+ distinct_id: identityInfo.distinct_id,
10815
10916
  properties: {
10816
10917
  ...properties,
10817
10918
  $lib: "lingo.dev-cli",
10818
10919
  $lib_version: process.env.npm_package_version || "unknown",
10819
- // Essential debugging context only
10920
+ tracking_version: TRACKING_VERSION,
10921
+ distinct_id_source: identityInfo.distinct_id_source,
10922
+ project_id: identityInfo.project_id,
10820
10923
  node_version: process.version,
10821
10924
  is_ci: !!process.env.CI,
10822
10925
  debug_enabled: process.env.DEBUG === "true"
@@ -11026,7 +11129,7 @@ var i18n_default = new Command14().command("i18n").description(
11026
11129
  try {
11027
11130
  flags = parseFlags(options);
11028
11131
  } catch (parseError) {
11029
- await trackEvent("unknown", "cmd.i18n.error", {
11132
+ await trackEvent(null, "cmd.i18n.error", {
11030
11133
  errorType: "validation_error",
11031
11134
  errorName: parseError.name || "ValidationError",
11032
11135
  errorMessage: parseError.message || "Invalid command line options",
@@ -11426,7 +11529,7 @@ var i18n_default = new Command14().command("i18n").description(
11426
11529
  });
11427
11530
  } else {
11428
11531
  ora.warn("Localization completed with errors.");
11429
- await trackEvent(authId || "unknown", "cmd.i18n.error", {
11532
+ await trackEvent(authId, "cmd.i18n.error", {
11430
11533
  flags,
11431
11534
  ...aggregateErrorAnalytics(
11432
11535
  errorDetails,
@@ -11452,7 +11555,7 @@ var i18n_default = new Command14().command("i18n").description(
11452
11555
  bucket: error.bucket
11453
11556
  };
11454
11557
  }
11455
- await trackEvent(authId || "unknown", "cmd.i18n.error", {
11558
+ await trackEvent(authId, "cmd.i18n.error", {
11456
11559
  flags,
11457
11560
  errorType,
11458
11561
  errorName: error.name || "Error",
@@ -11972,10 +12075,10 @@ import { Command as Command19 } from "interactive-commander";
11972
12075
  import createOra from "ora";
11973
12076
 
11974
12077
  // src/cli/cmd/ci/flows/pull-request.ts
11975
- import { execSync as execSync2 } from "child_process";
12078
+ import { execSync as execSync3 } from "child_process";
11976
12079
 
11977
12080
  // src/cli/cmd/ci/flows/in-branch.ts
11978
- import { execSync } from "child_process";
12081
+ import { execSync as execSync2 } from "child_process";
11979
12082
  import path18 from "path";
11980
12083
 
11981
12084
  // src/cli/cmd/ci/flows/_base.ts
@@ -13208,7 +13311,7 @@ var run_default = new Command18().command("run").description("Run localization p
13208
13311
  flags: ctx.flags
13209
13312
  });
13210
13313
  } catch (error) {
13211
- await trackEvent(authId || "unknown", "cmd.run.error", {});
13314
+ await trackEvent(authId, "cmd.run.error", {});
13212
13315
  if (args.sound) {
13213
13316
  await playSound("failure");
13214
13317
  }
@@ -13228,15 +13331,15 @@ var InBranchFlow = class extends IntegrationFlow {
13228
13331
  this.ora.start("Running Lingo.dev");
13229
13332
  await this.runLingoDotDev(options.parallel);
13230
13333
  this.ora.succeed("Done running Lingo.dev");
13231
- execSync(`rm -f i18n.cache`, { stdio: "inherit" });
13334
+ execSync2(`rm -f i18n.cache`, { stdio: "inherit" });
13232
13335
  this.ora.start("Checking for changes");
13233
13336
  const hasChanges = this.checkCommitableChanges();
13234
13337
  this.ora.succeed(hasChanges ? "Changes detected" : "No changes detected");
13235
13338
  if (hasChanges) {
13236
13339
  this.ora.start("Committing changes");
13237
- execSync(`git add .`, { stdio: "inherit" });
13238
- execSync(`git status --porcelain`, { stdio: "inherit" });
13239
- execSync(
13340
+ execSync2(`git add .`, { stdio: "inherit" });
13341
+ execSync2(`git status --porcelain`, { stdio: "inherit" });
13342
+ execSync2(
13240
13343
  `git commit -m ${escapeShellArg(
13241
13344
  this.platformKit.config.commitMessage
13242
13345
  )} --no-verify`,
@@ -13247,7 +13350,7 @@ var InBranchFlow = class extends IntegrationFlow {
13247
13350
  this.ora.succeed("Changes committed");
13248
13351
  this.ora.start("Pushing changes to remote");
13249
13352
  const currentBranch = this.i18nBranchName ?? this.platformKit.platformConfig.baseBranchName;
13250
- execSync(
13353
+ execSync2(
13251
13354
  `git push origin ${currentBranch} ${options.force ? "--force" : ""}`,
13252
13355
  {
13253
13356
  stdio: "inherit"
@@ -13258,7 +13361,7 @@ var InBranchFlow = class extends IntegrationFlow {
13258
13361
  return hasChanges;
13259
13362
  }
13260
13363
  checkCommitableChanges() {
13261
- return execSync('git status --porcelain || echo "has_changes"', {
13364
+ return execSync2('git status --porcelain || echo "has_changes"', {
13262
13365
  encoding: "utf8"
13263
13366
  }).length > 0;
13264
13367
  }
@@ -13283,17 +13386,17 @@ var InBranchFlow = class extends IntegrationFlow {
13283
13386
  const { baseBranchName } = this.platformKit.platformConfig;
13284
13387
  const gitConfig = getGitConfig(this.platformKit);
13285
13388
  this.ora.info(`Current working directory:`);
13286
- execSync(`pwd`, { stdio: "inherit" });
13287
- execSync(`ls -la`, { stdio: "inherit" });
13288
- execSync(`git config --global safe.directory ${process.cwd()}`);
13289
- execSync(`git config user.name "${gitConfig.userName}"`);
13290
- execSync(`git config user.email "${gitConfig.userEmail}"`);
13389
+ execSync2(`pwd`, { stdio: "inherit" });
13390
+ execSync2(`ls -la`, { stdio: "inherit" });
13391
+ execSync2(`git config --global safe.directory ${process.cwd()}`);
13392
+ execSync2(`git config user.name "${gitConfig.userName}"`);
13393
+ execSync2(`git config user.email "${gitConfig.userEmail}"`);
13291
13394
  this.platformKit?.gitConfig();
13292
- execSync(`git fetch origin ${baseBranchName}`, { stdio: "inherit" });
13293
- execSync(`git checkout ${baseBranchName} --`, { stdio: "inherit" });
13395
+ execSync2(`git fetch origin ${baseBranchName}`, { stdio: "inherit" });
13396
+ execSync2(`git checkout ${baseBranchName} --`, { stdio: "inherit" });
13294
13397
  if (!processOwnCommits) {
13295
13398
  const currentAuthor = `${gitConfig.userName} <${gitConfig.userEmail}>`;
13296
- const authorOfLastCommit = execSync(
13399
+ const authorOfLastCommit = execSync2(
13297
13400
  `git log -1 --pretty=format:'%an <%ae>'`
13298
13401
  ).toString();
13299
13402
  if (authorOfLastCommit === currentAuthor) {
@@ -13397,18 +13500,18 @@ var PullRequestFlow = class extends InBranchFlow {
13397
13500
  return prNumber;
13398
13501
  }
13399
13502
  checkoutI18nBranch(i18nBranchName) {
13400
- execSync2(`git fetch origin ${i18nBranchName}`, { stdio: "inherit" });
13401
- execSync2(`git checkout -b ${i18nBranchName}`, {
13503
+ execSync3(`git fetch origin ${i18nBranchName}`, { stdio: "inherit" });
13504
+ execSync3(`git checkout -b ${i18nBranchName}`, {
13402
13505
  stdio: "inherit"
13403
13506
  });
13404
13507
  }
13405
13508
  createI18nBranch(i18nBranchName) {
13406
13509
  try {
13407
- execSync2(
13510
+ execSync3(
13408
13511
  `git fetch origin ${this.platformKit.platformConfig.baseBranchName}`,
13409
13512
  { stdio: "inherit" }
13410
13513
  );
13411
- execSync2(
13514
+ execSync3(
13412
13515
  `git checkout -b ${i18nBranchName} origin/${this.platformKit.platformConfig.baseBranchName}`,
13413
13516
  {
13414
13517
  stdio: "inherit"
@@ -13433,7 +13536,7 @@ var PullRequestFlow = class extends InBranchFlow {
13433
13536
  this.ora.start(
13434
13537
  `Fetching latest changes from ${this.platformKit.platformConfig.baseBranchName}`
13435
13538
  );
13436
- execSync2(
13539
+ execSync3(
13437
13540
  `git fetch origin ${this.platformKit.platformConfig.baseBranchName}`,
13438
13541
  { stdio: "inherit" }
13439
13542
  );
@@ -13442,7 +13545,7 @@ var PullRequestFlow = class extends InBranchFlow {
13442
13545
  );
13443
13546
  try {
13444
13547
  this.ora.start("Attempting to rebase branch");
13445
- execSync2(
13548
+ execSync3(
13446
13549
  `git rebase origin/${this.platformKit.platformConfig.baseBranchName}`,
13447
13550
  { stdio: "inherit" }
13448
13551
  );
@@ -13450,12 +13553,12 @@ var PullRequestFlow = class extends InBranchFlow {
13450
13553
  } catch (error) {
13451
13554
  this.ora.warn("Rebase failed, falling back to alternative sync method");
13452
13555
  this.ora.start("Aborting failed rebase");
13453
- execSync2("git rebase --abort", { stdio: "inherit" });
13556
+ execSync3("git rebase --abort", { stdio: "inherit" });
13454
13557
  this.ora.succeed("Aborted failed rebase");
13455
13558
  this.ora.start(
13456
13559
  `Resetting to ${this.platformKit.platformConfig.baseBranchName}`
13457
13560
  );
13458
- execSync2(
13561
+ execSync3(
13459
13562
  `git reset --hard origin/${this.platformKit.platformConfig.baseBranchName}`,
13460
13563
  { stdio: "inherit" }
13461
13564
  );
@@ -13464,15 +13567,15 @@ var PullRequestFlow = class extends InBranchFlow {
13464
13567
  );
13465
13568
  this.ora.start("Restoring target files");
13466
13569
  const targetFiles = ["i18n.lock"];
13467
- const targetFileNames = execSync2(
13570
+ const targetFileNames = execSync3(
13468
13571
  `npx lingo.dev@latest show files --target ${this.platformKit.platformConfig.baseBranchName}`,
13469
13572
  { encoding: "utf8" }
13470
13573
  ).split("\n").filter(Boolean);
13471
13574
  targetFiles.push(...targetFileNames);
13472
- execSync2(`git fetch origin ${this.i18nBranchName}`, { stdio: "inherit" });
13575
+ execSync3(`git fetch origin ${this.i18nBranchName}`, { stdio: "inherit" });
13473
13576
  for (const file of targetFiles) {
13474
13577
  try {
13475
- execSync2(`git checkout FETCH_HEAD -- ${file}`, { stdio: "inherit" });
13578
+ execSync3(`git checkout FETCH_HEAD -- ${file}`, { stdio: "inherit" });
13476
13579
  } catch (error2) {
13477
13580
  this.ora.warn(`Skipping non-existent file: ${file}`);
13478
13581
  continue;
@@ -13483,8 +13586,8 @@ var PullRequestFlow = class extends InBranchFlow {
13483
13586
  this.ora.start("Checking for changes to commit");
13484
13587
  const hasChanges = this.checkCommitableChanges();
13485
13588
  if (hasChanges) {
13486
- execSync2("git add .", { stdio: "inherit" });
13487
- execSync2(
13589
+ execSync3("git add .", { stdio: "inherit" });
13590
+ execSync3(
13488
13591
  `git commit -m "chore: sync with ${this.platformKit.platformConfig.baseBranchName}" --no-verify`,
13489
13592
  {
13490
13593
  stdio: "inherit"
@@ -13516,18 +13619,18 @@ Hey team,
13516
13619
  };
13517
13620
 
13518
13621
  // src/cli/cmd/ci/platforms/bitbucket.ts
13519
- import { execSync as execSync4 } from "child_process";
13622
+ import { execSync as execSync5 } from "child_process";
13520
13623
  import bbLib from "bitbucket";
13521
13624
  import Z8 from "zod";
13522
13625
 
13523
13626
  // src/cli/cmd/ci/platforms/_base.ts
13524
- import { execSync as execSync3 } from "child_process";
13627
+ import { execSync as execSync4 } from "child_process";
13525
13628
  import Z7 from "zod";
13526
13629
  var defaultMessage = "feat: update translations via @lingodotdev";
13527
13630
  var PlatformKit = class {
13528
13631
  gitConfig(token, repoUrl) {
13529
13632
  if (token && repoUrl) {
13530
- execSync3(`git remote set-url origin ${repoUrl}`, {
13633
+ execSync4(`git remote set-url origin ${repoUrl}`, {
13531
13634
  stdio: "inherit"
13532
13635
  });
13533
13636
  }
@@ -13631,10 +13734,10 @@ var BitbucketPlatformKit = class extends PlatformKit {
13631
13734
  });
13632
13735
  }
13633
13736
  async gitConfig() {
13634
- execSync4("git config --unset http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy", {
13737
+ execSync5("git config --unset http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy", {
13635
13738
  stdio: "inherit"
13636
13739
  });
13637
- execSync4(
13740
+ execSync5(
13638
13741
  "git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://host.docker.internal:29418/",
13639
13742
  {
13640
13743
  stdio: "inherit"
@@ -14063,7 +14166,7 @@ var status_default = new Command20().command("status").description("Show the sta
14063
14166
  ora.start("Validating localization configuration...");
14064
14167
  validateParams2(i18nConfig, flags);
14065
14168
  ora.succeed("Localization configuration is valid");
14066
- trackEvent(authId || "status", "cmd.status.start", {
14169
+ trackEvent(authId, "cmd.status.start", {
14067
14170
  i18nConfig,
14068
14171
  flags
14069
14172
  });
@@ -14450,7 +14553,7 @@ var status_default = new Command20().command("status").description("Show the sta
14450
14553
  `\u2022 Try 'lingo.dev@latest i18n --locale ${targetLocales[0]}' to process just one language`
14451
14554
  );
14452
14555
  }
14453
- trackEvent(authId || "status", "cmd.status.success", {
14556
+ trackEvent(authId, "cmd.status.success", {
14454
14557
  i18nConfig,
14455
14558
  flags,
14456
14559
  totalSourceKeyCount,
@@ -14461,7 +14564,7 @@ var status_default = new Command20().command("status").description("Show the sta
14461
14564
  exitGracefully();
14462
14565
  } catch (error) {
14463
14566
  ora.fail(error.message);
14464
- trackEvent(authId || "status", "cmd.status.error", {
14567
+ trackEvent(authId, "cmd.status.error", {
14465
14568
  flags,
14466
14569
  error: error.message,
14467
14570
  authenticated: !!authId
@@ -14603,7 +14706,7 @@ async function renderHero2() {
14603
14706
  // package.json
14604
14707
  var package_default = {
14605
14708
  name: "lingo.dev",
14606
- version: "0.117.15",
14709
+ version: "0.117.17",
14607
14710
  description: "Lingo.dev CLI",
14608
14711
  private: false,
14609
14712
  repository: {