lingo.dev 0.125.0 → 0.125.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.cjs CHANGED
@@ -14,7 +14,7 @@ var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
14
14
 
15
15
  // src/cli/utils/settings.ts
16
16
  var _os = require('os'); var _os2 = _interopRequireDefault(_os);
17
- var _path = require('path'); var path15 = _interopRequireWildcard(_path); var path16 = _interopRequireWildcard(_path);
17
+ var _path = require('path'); var path15 = _interopRequireWildcard(_path); var path17 = _interopRequireWildcard(_path);
18
18
  var _zod = require('zod'); var _zod2 = _interopRequireDefault(_zod);
19
19
  var _fs = require('fs'); var fs13 = _interopRequireWildcard(_fs);
20
20
  var _ini = require('ini'); var _ini2 = _interopRequireDefault(_ini);
@@ -10998,44 +10998,41 @@ function withExponentialBackoff(fn, maxAttempts = 3, baseDelay = 1e3) {
10998
10998
  var _nodemachineid = require('node-machine-id'); var _nodemachineid2 = _interopRequireDefault(_nodemachineid);
10999
10999
  var _https = require('https'); var _https2 = _interopRequireDefault(_https);
11000
11000
 
11001
- // src/cli/utils/repository-id.ts
11001
+ // src/cli/utils/org-id.ts
11002
11002
  var _child_process = require('child_process'); var cp = _interopRequireWildcard(_child_process);
11003
- var _crypto = require('crypto');
11004
- var cachedGitRepoId = void 0;
11005
- function hashProjectName(fullPath) {
11003
+ var cachedGitOrgId = void 0;
11004
+ function extractOrg(fullPath) {
11006
11005
  const parts = fullPath.split("/");
11007
- if (parts.length !== 2) {
11008
- return _crypto.createHash.call(void 0, "sha256").update(fullPath).digest("hex").slice(0, 8);
11009
- }
11010
- const [org, project] = parts;
11011
- const hashedProject = _crypto.createHash.call(void 0, "sha256").update(project).digest("hex").slice(0, 8);
11012
- return `${org}/${hashedProject}`;
11013
- }
11014
- function getRepositoryId() {
11015
- const ciRepoId = getCIRepositoryId();
11016
- if (ciRepoId) return ciRepoId;
11017
- const gitRepoId = getGitRepositoryId();
11018
- if (gitRepoId) return gitRepoId;
11006
+ if (parts.length < 1) {
11007
+ return null;
11008
+ }
11009
+ return parts[0];
11010
+ }
11011
+ function getOrgId() {
11012
+ const ciOrgId = getCIOrgId();
11013
+ if (ciOrgId) return ciOrgId;
11014
+ const gitOrgId = getGitOrgId();
11015
+ if (gitOrgId) return gitOrgId;
11019
11016
  return null;
11020
11017
  }
11021
- function getCIRepositoryId() {
11018
+ function getCIOrgId() {
11022
11019
  if (process.env.GITHUB_REPOSITORY) {
11023
- const hashed = hashProjectName(process.env.GITHUB_REPOSITORY);
11024
- return `github:${hashed}`;
11020
+ const org = extractOrg(process.env.GITHUB_REPOSITORY);
11021
+ if (org) return `github:${org}`;
11025
11022
  }
11026
11023
  if (process.env.CI_PROJECT_PATH) {
11027
- const hashed = hashProjectName(process.env.CI_PROJECT_PATH);
11028
- return `gitlab:${hashed}`;
11024
+ const org = extractOrg(process.env.CI_PROJECT_PATH);
11025
+ if (org) return `gitlab:${org}`;
11029
11026
  }
11030
11027
  if (process.env.BITBUCKET_REPO_FULL_NAME) {
11031
- const hashed = hashProjectName(process.env.BITBUCKET_REPO_FULL_NAME);
11032
- return `bitbucket:${hashed}`;
11028
+ const org = extractOrg(process.env.BITBUCKET_REPO_FULL_NAME);
11029
+ if (org) return `bitbucket:${org}`;
11033
11030
  }
11034
11031
  return null;
11035
11032
  }
11036
- function getGitRepositoryId() {
11037
- if (cachedGitRepoId !== void 0) {
11038
- return cachedGitRepoId;
11033
+ function getGitOrgId() {
11034
+ if (cachedGitOrgId !== void 0) {
11035
+ return cachedGitOrgId;
11039
11036
  }
11040
11037
  try {
11041
11038
  const remoteUrl = _child_process.execSync.call(void 0, "git config --get remote.origin.url", {
@@ -11043,13 +11040,13 @@ function getGitRepositoryId() {
11043
11040
  stdio: ["pipe", "pipe", "ignore"]
11044
11041
  }).trim();
11045
11042
  if (!remoteUrl) {
11046
- cachedGitRepoId = null;
11043
+ cachedGitOrgId = null;
11047
11044
  return null;
11048
11045
  }
11049
- cachedGitRepoId = parseGitUrl(remoteUrl);
11050
- return cachedGitRepoId;
11046
+ cachedGitOrgId = parseGitUrl(remoteUrl);
11047
+ return cachedGitOrgId;
11051
11048
  } catch (e3) {
11052
- cachedGitRepoId = null;
11049
+ cachedGitOrgId = null;
11053
11050
  return null;
11054
11051
  }
11055
11052
  }
@@ -11067,11 +11064,12 @@ function parseGitUrl(url) {
11067
11064
  const httpsMatch = cleanUrl.match(/\/([^/]+\/[^/]+)$/);
11068
11065
  const repoPath = _optionalChain([sshMatch, 'optionalAccess', _349 => _349[1]]) || _optionalChain([httpsMatch, 'optionalAccess', _350 => _350[1]]);
11069
11066
  if (!repoPath) return null;
11070
- const hashedPath = hashProjectName(repoPath);
11067
+ const org = extractOrg(repoPath);
11068
+ if (!org) return null;
11071
11069
  if (platform) {
11072
- return `${platform}:${hashedPath}`;
11070
+ return `${platform}:${org}`;
11073
11071
  }
11074
- return `git:${hashedPath}`;
11072
+ return `git:${org}`;
11075
11073
  }
11076
11074
 
11077
11075
  // src/cli/utils/observability.ts
@@ -11082,20 +11080,19 @@ var POSTHOG_PATH = "/i/v0/e/";
11082
11080
  var REQUEST_TIMEOUT_MS = 3e3;
11083
11081
  var TRACKING_VERSION = "2.0";
11084
11082
  function determineDistinctId(email) {
11083
+ const orgId = getOrgId();
11085
11084
  if (email) {
11086
- const projectId = getRepositoryId();
11087
11085
  return {
11088
11086
  distinct_id: email,
11089
11087
  distinct_id_source: "email",
11090
- project_id: projectId
11088
+ org_id: orgId
11091
11089
  };
11092
11090
  }
11093
- const repoId = getRepositoryId();
11094
- if (repoId) {
11091
+ if (orgId) {
11095
11092
  return {
11096
- distinct_id: repoId,
11097
- distinct_id_source: "git_repo",
11098
- project_id: repoId
11093
+ distinct_id: orgId,
11094
+ distinct_id_source: "git_org",
11095
+ org_id: orgId
11099
11096
  };
11100
11097
  }
11101
11098
  const deviceId = `device-${machineIdSync()}`;
@@ -11107,7 +11104,7 @@ function determineDistinctId(email) {
11107
11104
  return {
11108
11105
  distinct_id: deviceId,
11109
11106
  distinct_id_source: "device",
11110
- project_id: null
11107
+ org_id: null
11111
11108
  };
11112
11109
  }
11113
11110
  function trackEvent(email, event, properties) {
@@ -11132,7 +11129,7 @@ function trackEvent(email, event, properties) {
11132
11129
  $lib_version: process.env.npm_package_version || "unknown",
11133
11130
  tracking_version: TRACKING_VERSION,
11134
11131
  distinct_id_source: identityInfo.distinct_id_source,
11135
- project_id: identityInfo.project_id,
11132
+ org_id: identityInfo.org_id,
11136
11133
  node_version: process.version,
11137
11134
  is_ci: !!process.env.CI,
11138
11135
  debug_enabled: process.env.DEBUG === "true"
@@ -11203,6 +11200,134 @@ function checkIfFileExists(filePath) {
11203
11200
  // src/cli/utils/delta.ts
11204
11201
 
11205
11202
 
11203
+
11204
+ // src/cli/utils/lockfile.ts
11205
+
11206
+
11207
+
11208
+
11209
+
11210
+
11211
+ function createLockfileHelper() {
11212
+ return {
11213
+ isLockfileExists: () => {
11214
+ const lockfilePath = _getLockfilePath();
11215
+ return fs13.default.existsSync(lockfilePath);
11216
+ },
11217
+ registerSourceData: (pathPattern, sourceData) => {
11218
+ const lockfile = _loadLockfile();
11219
+ const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
11220
+ const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
11221
+ lockfile.checksums[sectionKey] = sectionChecksums;
11222
+ _saveLockfile(lockfile);
11223
+ },
11224
+ registerPartialSourceData: (pathPattern, partialSourceData) => {
11225
+ const lockfile = _loadLockfile();
11226
+ const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
11227
+ const sectionChecksums = _lodash2.default.mapValues(
11228
+ partialSourceData,
11229
+ (value) => _objecthash.MD5.call(void 0, value)
11230
+ );
11231
+ lockfile.checksums[sectionKey] = _lodash2.default.merge(
11232
+ {},
11233
+ _nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})),
11234
+ sectionChecksums
11235
+ );
11236
+ _saveLockfile(lockfile);
11237
+ },
11238
+ extractUpdatedData: (pathPattern, sourceData) => {
11239
+ const lockfile = _loadLockfile();
11240
+ const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
11241
+ const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
11242
+ const savedChecksums = lockfile.checksums[sectionKey] || {};
11243
+ const updatedData = _lodash2.default.pickBy(
11244
+ sourceData,
11245
+ (value, key) => savedChecksums[key] !== currentChecksums[key]
11246
+ );
11247
+ return updatedData;
11248
+ }
11249
+ };
11250
+ function _loadLockfile() {
11251
+ const lockfilePath = _getLockfilePath();
11252
+ if (!fs13.default.existsSync(lockfilePath)) {
11253
+ return LockfileSchema.parse({});
11254
+ }
11255
+ const content = fs13.default.readFileSync(lockfilePath, "utf-8");
11256
+ const { deduplicatedContent, duplicatesRemoved } = deduplicateLockfileYaml(content);
11257
+ if (duplicatesRemoved > 0) {
11258
+ fs13.default.writeFileSync(lockfilePath, deduplicatedContent);
11259
+ console.log(
11260
+ `Removed ${duplicatesRemoved} duplicate ${duplicatesRemoved === 1 ? "entry" : "entries"} from i18n.lock`
11261
+ );
11262
+ }
11263
+ const parsed = LockfileSchema.parse(_yaml2.default.parse(deduplicatedContent));
11264
+ return parsed;
11265
+ }
11266
+ function _saveLockfile(lockfile) {
11267
+ const lockfilePath = _getLockfilePath();
11268
+ const content = _yaml2.default.stringify(lockfile);
11269
+ fs13.default.writeFileSync(lockfilePath, content);
11270
+ }
11271
+ function _getLockfilePath() {
11272
+ return path15.default.join(process.cwd(), "i18n.lock");
11273
+ }
11274
+ }
11275
+ var LockfileSchema = _zod2.default.object({
11276
+ version: _zod2.default.literal(1).prefault(1),
11277
+ checksums: _zod2.default.record(
11278
+ _zod2.default.string(),
11279
+ // localizable files' keys
11280
+ _zod2.default.record(
11281
+ // checksums hashmap
11282
+ _zod2.default.string(),
11283
+ // key
11284
+ _zod2.default.string()
11285
+ // checksum of the key's value in the source locale
11286
+ ).prefault({})
11287
+ ).prefault({})
11288
+ });
11289
+ function deduplicateLockfileYaml(yamlContent) {
11290
+ const doc = _yaml2.default.parseDocument(yamlContent);
11291
+ let duplicatesRemoved = 0;
11292
+ if (doc.contents && _yaml2.default.isMap(doc.contents)) {
11293
+ const checksums = doc.contents.get("checksums");
11294
+ if (checksums && _yaml2.default.isMap(checksums)) {
11295
+ for (const pathItem of checksums.items) {
11296
+ if (_yaml2.default.isMap(pathItem.value)) {
11297
+ const keyPositions = /* @__PURE__ */ new Map();
11298
+ for (let i = 0; i < pathItem.value.items.length; i++) {
11299
+ const translationItem = pathItem.value.items[i];
11300
+ const key = String(_yaml2.default.isScalar(translationItem.key) ? translationItem.key.value : translationItem.key);
11301
+ if (!keyPositions.has(key)) {
11302
+ keyPositions.set(key, []);
11303
+ }
11304
+ keyPositions.get(key).push(i);
11305
+ }
11306
+ const indicesToRemove = [];
11307
+ for (const positions of keyPositions.values()) {
11308
+ if (positions.length > 1) {
11309
+ indicesToRemove.push(...positions.slice(0, -1));
11310
+ duplicatesRemoved += positions.length - 1;
11311
+ }
11312
+ }
11313
+ indicesToRemove.sort((a, b) => b - a);
11314
+ for (const index of indicesToRemove) {
11315
+ pathItem.value.items.splice(index, 1);
11316
+ }
11317
+ }
11318
+ }
11319
+ }
11320
+ }
11321
+ const cleanedData = doc.toJSON();
11322
+ const cleanDoc = new _yaml2.default.Document(cleanedData);
11323
+ const deduplicatedContent = cleanDoc.toString();
11324
+ return {
11325
+ deduplicatedContent,
11326
+ duplicatesRemoved
11327
+ };
11328
+ }
11329
+
11330
+ // src/cli/utils/delta.ts
11206
11331
  var LockSchema = _zod2.default.object({
11207
11332
  version: _zod2.default.literal(1).prefault(1),
11208
11333
  checksums: _zod2.default.record(
@@ -11218,7 +11343,7 @@ var LockSchema = _zod2.default.object({
11218
11343
  ).prefault({})
11219
11344
  });
11220
11345
  function createDeltaProcessor(fileKey) {
11221
- const lockfilePath = path16.join(process.cwd(), "i18n.lock");
11346
+ const lockfilePath = path17.join(process.cwd(), "i18n.lock");
11222
11347
  return {
11223
11348
  async checkIfLockExists() {
11224
11349
  return checkIfFileExists(lockfilePath);
@@ -11267,12 +11392,21 @@ function createDeltaProcessor(fileKey) {
11267
11392
  },
11268
11393
  async loadLock() {
11269
11394
  const lockfileContent = tryReadFile(lockfilePath, null);
11270
- const lockfileYaml = lockfileContent ? _yaml2.default.parse(lockfileContent) : null;
11271
- const lockfileData = lockfileYaml ? LockSchema.parse(lockfileYaml) : {
11272
- version: 1,
11273
- checksums: {}
11274
- };
11275
- return lockfileData;
11395
+ if (!lockfileContent) {
11396
+ return {
11397
+ version: 1,
11398
+ checksums: {}
11399
+ };
11400
+ }
11401
+ const { deduplicatedContent, duplicatesRemoved } = deduplicateLockfileYaml(lockfileContent);
11402
+ if (duplicatesRemoved > 0) {
11403
+ writeFile(lockfilePath, deduplicatedContent);
11404
+ console.log(
11405
+ `Removed ${duplicatesRemoved} duplicate ${duplicatesRemoved === 1 ? "entry" : "entries"} from i18n.lock`
11406
+ );
11407
+ }
11408
+ const parsed = LockSchema.parse(_yaml2.default.parse(deduplicatedContent));
11409
+ return parsed;
11276
11410
  },
11277
11411
  async saveLock(lockData) {
11278
11412
  const lockfileYaml = _yaml2.default.stringify(lockData);
@@ -11281,12 +11415,14 @@ function createDeltaProcessor(fileKey) {
11281
11415
  async loadChecksums() {
11282
11416
  const id = md5(fileKey);
11283
11417
  const lockfileData = await this.loadLock();
11284
- return lockfileData.checksums[id] || {};
11418
+ const checksums = lockfileData.checksums;
11419
+ return checksums[id] || {};
11285
11420
  },
11286
11421
  async saveChecksums(checksums) {
11287
11422
  const id = md5(fileKey);
11288
11423
  const lockfileData = await this.loadLock();
11289
- lockfileData.checksums[id] = checksums;
11424
+ const lockChecksums = lockfileData.checksums;
11425
+ lockChecksums[id] = checksums;
11290
11426
  await this.saveLock(lockfileData);
11291
11427
  },
11292
11428
  async createChecksums(sourceData) {
@@ -11974,87 +12110,6 @@ Editing value for: ${_chalk2.default.cyan(key)}`);
11974
12110
 
11975
12111
 
11976
12112
 
11977
- // src/cli/utils/lockfile.ts
11978
-
11979
-
11980
-
11981
-
11982
-
11983
-
11984
- function createLockfileHelper() {
11985
- return {
11986
- isLockfileExists: () => {
11987
- const lockfilePath = _getLockfilePath();
11988
- return fs13.default.existsSync(lockfilePath);
11989
- },
11990
- registerSourceData: (pathPattern, sourceData) => {
11991
- const lockfile = _loadLockfile();
11992
- const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
11993
- const sectionChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
11994
- lockfile.checksums[sectionKey] = sectionChecksums;
11995
- _saveLockfile(lockfile);
11996
- },
11997
- registerPartialSourceData: (pathPattern, partialSourceData) => {
11998
- const lockfile = _loadLockfile();
11999
- const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
12000
- const sectionChecksums = _lodash2.default.mapValues(
12001
- partialSourceData,
12002
- (value) => _objecthash.MD5.call(void 0, value)
12003
- );
12004
- lockfile.checksums[sectionKey] = _lodash2.default.merge(
12005
- {},
12006
- _nullishCoalesce(lockfile.checksums[sectionKey], () => ( {})),
12007
- sectionChecksums
12008
- );
12009
- _saveLockfile(lockfile);
12010
- },
12011
- extractUpdatedData: (pathPattern, sourceData) => {
12012
- const lockfile = _loadLockfile();
12013
- const sectionKey = _objecthash.MD5.call(void 0, pathPattern);
12014
- const currentChecksums = _lodash2.default.mapValues(sourceData, (value) => _objecthash.MD5.call(void 0, value));
12015
- const savedChecksums = lockfile.checksums[sectionKey] || {};
12016
- const updatedData = _lodash2.default.pickBy(
12017
- sourceData,
12018
- (value, key) => savedChecksums[key] !== currentChecksums[key]
12019
- );
12020
- return updatedData;
12021
- }
12022
- };
12023
- function _loadLockfile() {
12024
- const lockfilePath = _getLockfilePath();
12025
- if (!fs13.default.existsSync(lockfilePath)) {
12026
- return LockfileSchema.parse({});
12027
- }
12028
- const content = fs13.default.readFileSync(lockfilePath, "utf-8");
12029
- const result = LockfileSchema.parse(_yaml2.default.parse(content));
12030
- return result;
12031
- }
12032
- function _saveLockfile(lockfile) {
12033
- const lockfilePath = _getLockfilePath();
12034
- const content = _yaml2.default.stringify(lockfile);
12035
- fs13.default.writeFileSync(lockfilePath, content);
12036
- }
12037
- function _getLockfilePath() {
12038
- return path15.default.join(process.cwd(), "i18n.lock");
12039
- }
12040
- }
12041
- var LockfileSchema = _zod2.default.object({
12042
- version: _zod2.default.literal(1).prefault(1),
12043
- checksums: _zod2.default.record(
12044
- _zod2.default.string(),
12045
- // localizable files' keys
12046
- _zod2.default.record(
12047
- // checksums hashmap
12048
- _zod2.default.string(),
12049
- // key
12050
- _zod2.default.string()
12051
- // checksum of the key's value in the source locale
12052
- ).prefault({})
12053
- ).prefault({})
12054
- });
12055
-
12056
- // src/cli/cmd/lockfile.ts
12057
-
12058
12113
  var lockfile_default = new (0, _interactivecommander.Command)().command("lockfile").description(
12059
12114
  "Generate or refresh i18n.lock based on the current source locale content"
12060
12115
  ).helpOption("-h, --help", "Show help").option(
@@ -15195,7 +15250,7 @@ async function renderHero2() {
15195
15250
  // package.json
15196
15251
  var package_default = {
15197
15252
  name: "lingo.dev",
15198
- version: "0.125.0",
15253
+ version: "0.125.2",
15199
15254
  description: "Lingo.dev CLI",
15200
15255
  private: false,
15201
15256
  repository: {