@lingo.dev/_compiler 0.8.6 → 0.8.8

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/index.cjs CHANGED
@@ -27,7 +27,7 @@ var _unplugin = require('unplugin');
27
27
  // package.json
28
28
  var package_default = {
29
29
  name: "@lingo.dev/_compiler",
30
- version: "0.8.6",
30
+ version: "0.8.8",
31
31
  description: "Lingo.dev Compiler",
32
32
  private: false,
33
33
  repository: {
@@ -72,7 +72,7 @@ var package_default = {
72
72
  "@types/lodash": "4.17.21",
73
73
  "@types/object-hash": "3.0.6",
74
74
  "@types/react": "19.2.7",
75
- next: "15.2.6",
75
+ next: "15.3.8",
76
76
  tsup: "8.5.1",
77
77
  typescript: "5.9.3",
78
78
  vitest: "4.0.13"
@@ -112,12 +112,82 @@ var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
112
112
 
113
113
  // src/utils/observability.ts
114
114
  var _nodemachineid = require('node-machine-id'); var machineIdLib = _interopRequireWildcard(_nodemachineid);
115
+
116
+ // src/utils/repository-id.ts
117
+ var _child_process = require('child_process');
118
+ var cachedGitRepoId = void 0;
119
+ function getRepositoryId() {
120
+ const ciRepoId = getCIRepositoryId();
121
+ if (ciRepoId) return ciRepoId;
122
+ const gitRepoId = getGitRepositoryId();
123
+ if (gitRepoId) return gitRepoId;
124
+ return null;
125
+ }
126
+ function getCIRepositoryId() {
127
+ if (process.env.GITHUB_REPOSITORY) {
128
+ return `github:${process.env.GITHUB_REPOSITORY}`;
129
+ }
130
+ if (process.env.CI_PROJECT_PATH) {
131
+ return `gitlab:${process.env.CI_PROJECT_PATH}`;
132
+ }
133
+ if (process.env.BITBUCKET_REPO_FULL_NAME) {
134
+ return `bitbucket:${process.env.BITBUCKET_REPO_FULL_NAME}`;
135
+ }
136
+ return null;
137
+ }
138
+ function getGitRepositoryId() {
139
+ if (cachedGitRepoId !== void 0) {
140
+ return cachedGitRepoId;
141
+ }
142
+ try {
143
+ const remoteUrl = _child_process.execSync.call(void 0, "git config --get remote.origin.url", {
144
+ encoding: "utf8",
145
+ stdio: ["pipe", "pipe", "ignore"]
146
+ }).trim();
147
+ if (!remoteUrl) {
148
+ cachedGitRepoId = null;
149
+ return null;
150
+ }
151
+ cachedGitRepoId = parseGitUrl(remoteUrl);
152
+ return cachedGitRepoId;
153
+ } catch (e) {
154
+ cachedGitRepoId = null;
155
+ return null;
156
+ }
157
+ }
158
+ function parseGitUrl(url) {
159
+ const cleanUrl = url.replace(/\.git$/, "");
160
+ let platform = null;
161
+ if (cleanUrl.includes("github.com")) {
162
+ platform = "github";
163
+ } else if (cleanUrl.includes("gitlab.com")) {
164
+ platform = "gitlab";
165
+ } else if (cleanUrl.includes("bitbucket.org")) {
166
+ platform = "bitbucket";
167
+ }
168
+ const sshMatch = cleanUrl.match(/[@:]([^:/@]+\/[^:/@]+)$/);
169
+ const httpsMatch = cleanUrl.match(/\/([^/]+\/[^/]+)$/);
170
+ const repoPath = _optionalChain([sshMatch, 'optionalAccess', _2 => _2[1]]) || _optionalChain([httpsMatch, 'optionalAccess', _3 => _3[1]]);
171
+ if (!repoPath) return null;
172
+ if (platform) {
173
+ return `${platform}:${repoPath}`;
174
+ }
175
+ return `git:${repoPath}`;
176
+ }
177
+
178
+ // src/utils/observability.ts
179
+ var TRACKING_VERSION = "2.0";
115
180
  async function trackEvent(event, properties) {
116
- if (process.env.DO_NOT_TRACK) {
181
+ if (process.env.DO_NOT_TRACK === "1") {
117
182
  return;
118
183
  }
119
184
  try {
120
- const actualId = await getActualId();
185
+ const identityInfo = await getDistinctId();
186
+ if (process.env.DEBUG === "true") {
187
+ console.log(
188
+ `[Tracking] Event: ${event}, ID: ${identityInfo.distinct_id}, Source: ${identityInfo.distinct_id_source}`
189
+ );
190
+ }
121
191
  const { PostHog } = await Promise.resolve().then(() => _interopRequireWildcard(require("posthog-node")));
122
192
  const posthog = new PostHog(
123
193
  "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
@@ -128,11 +198,14 @@ async function trackEvent(event, properties) {
128
198
  }
129
199
  );
130
200
  await posthog.capture({
131
- distinctId: actualId,
201
+ distinctId: identityInfo.distinct_id,
132
202
  event,
133
203
  properties: {
134
204
  ...properties,
135
- isByokMode: _optionalChain([properties, 'optionalAccess', _2 => _2.models]) !== "lingo.dev",
205
+ isByokMode: _optionalChain([properties, 'optionalAccess', _4 => _4.models]) !== "lingo.dev",
206
+ tracking_version: TRACKING_VERSION,
207
+ distinct_id_source: identityInfo.distinct_id_source,
208
+ project_id: identityInfo.project_id,
136
209
  meta: {
137
210
  version: process.env.npm_package_version,
138
211
  isCi: process.env.CI === "true"
@@ -141,35 +214,65 @@ async function trackEvent(event, properties) {
141
214
  });
142
215
  await posthog.shutdown();
143
216
  } catch (error) {
144
- if (process.env.DEBUG) {
145
- console.error(error);
217
+ if (process.env.DEBUG === "true") {
218
+ console.error("[Tracking] Error:", error);
146
219
  }
147
220
  }
148
221
  }
149
- async function getActualId() {
222
+ async function getDistinctId() {
223
+ const email = await tryGetEmail();
224
+ if (email) {
225
+ const projectId = getRepositoryId();
226
+ return {
227
+ distinct_id: email,
228
+ distinct_id_source: "email",
229
+ project_id: projectId
230
+ };
231
+ }
232
+ const repoId = getRepositoryId();
233
+ if (repoId) {
234
+ return {
235
+ distinct_id: repoId,
236
+ distinct_id_source: "git_repo",
237
+ project_id: repoId
238
+ };
239
+ }
240
+ const deviceId = `device-${await machineIdLib.machineId()}`;
241
+ if (process.env.DEBUG === "true") {
242
+ console.warn(
243
+ "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking."
244
+ );
245
+ }
246
+ return {
247
+ distinct_id: deviceId,
248
+ distinct_id_source: "device",
249
+ project_id: null
250
+ };
251
+ }
252
+ async function tryGetEmail() {
150
253
  const rc = _chunkAKV7BRP5cjs.getRc.call(void 0, );
151
- const apiKey = process.env.LINGODOTDEV_API_KEY || _optionalChain([rc, 'optionalAccess', _3 => _3.auth, 'optionalAccess', _4 => _4.apiKey]);
152
- const apiUrl = process.env.LINGODOTDEV_API_URL || _optionalChain([rc, 'optionalAccess', _5 => _5.auth, 'optionalAccess', _6 => _6.apiUrl]) || "https://engine.lingo.dev";
153
- if (apiKey) {
154
- try {
155
- const res = await fetch(`${apiUrl}/whoami`, {
156
- method: "POST",
157
- headers: {
158
- Authorization: `Bearer ${apiKey}`,
159
- ContentType: "application/json"
160
- }
161
- });
162
- if (res.ok) {
163
- const payload = await res.json();
164
- if (_optionalChain([payload, 'optionalAccess', _7 => _7.email])) {
165
- return payload.email;
166
- }
254
+ const apiKey = process.env.LINGODOTDEV_API_KEY || _optionalChain([rc, 'optionalAccess', _5 => _5.auth, 'optionalAccess', _6 => _6.apiKey]);
255
+ const apiUrl = process.env.LINGODOTDEV_API_URL || _optionalChain([rc, 'optionalAccess', _7 => _7.auth, 'optionalAccess', _8 => _8.apiUrl]) || "https://engine.lingo.dev";
256
+ if (!apiKey) {
257
+ return null;
258
+ }
259
+ try {
260
+ const res = await fetch(`${apiUrl}/whoami`, {
261
+ method: "POST",
262
+ headers: {
263
+ Authorization: `Bearer ${apiKey}`,
264
+ ContentType: "application/json"
265
+ }
266
+ });
267
+ if (res.ok) {
268
+ const payload = await res.json();
269
+ if (_optionalChain([payload, 'optionalAccess', _9 => _9.email])) {
270
+ return payload.email;
167
271
  }
168
- } catch (err) {
169
272
  }
273
+ } catch (err) {
170
274
  }
171
- const id = await machineIdLib.machineId();
172
- return `device-${id}`;
275
+ return null;
173
276
  }
174
277
 
175
278
  // src/index.ts
@@ -319,12 +422,12 @@ var index_default = {
319
422
  const isDev = process.env.NODE_ENV !== "production";
320
423
  sendBuildEvent("Next.js", mergedParams, isDev);
321
424
  let turbopackEnabled;
322
- if (_optionalChain([mergedParams, 'access', _8 => _8.turbopack, 'optionalAccess', _9 => _9.enabled]) === "auto") {
425
+ if (_optionalChain([mergedParams, 'access', _10 => _10.turbopack, 'optionalAccess', _11 => _11.enabled]) === "auto") {
323
426
  turbopackEnabled = process.env.TURBOPACK === "1" || process.env.TURBOPACK === "true";
324
427
  } else {
325
- turbopackEnabled = _optionalChain([mergedParams, 'access', _10 => _10.turbopack, 'optionalAccess', _11 => _11.enabled]) === true;
428
+ turbopackEnabled = _optionalChain([mergedParams, 'access', _12 => _12.turbopack, 'optionalAccess', _13 => _13.enabled]) === true;
326
429
  }
327
- const supportLegacyTurbo = _optionalChain([mergedParams, 'access', _12 => _12.turbopack, 'optionalAccess', _13 => _13.useLegacyTurbo]) === true;
430
+ const supportLegacyTurbo = _optionalChain([mergedParams, 'access', _14 => _14.turbopack, 'optionalAccess', _15 => _15.useLegacyTurbo]) === true;
328
431
  const hasWebpackConfig = typeof nextConfig.webpack === "function";
329
432
  const hasTurbopackConfig = typeof nextConfig.turbopack === "function";
330
433
  if (hasWebpackConfig && turbopackEnabled) {
@@ -422,7 +525,7 @@ var index_default = {
422
525
  compilerParams
423
526
  );
424
527
  const isDev = process.env.NODE_ENV !== "production";
425
- const isReactRouter = _optionalChain([config, 'access', _14 => _14.plugins, 'optionalAccess', _15 => _15.flat, 'call', _16 => _16(), 'optionalAccess', _17 => _17.some, 'call', _18 => _18((plugin) => plugin.name === "react-router")]);
528
+ const isReactRouter = _optionalChain([config, 'access', _16 => _16.plugins, 'optionalAccess', _17 => _17.flat, 'call', _18 => _18(), 'optionalAccess', _19 => _19.some, 'call', _20 => _20((plugin) => plugin.name === "react-router")]);
426
529
  const framework = isReactRouter ? "React Router" : "Vite";
427
530
  sendBuildEvent(framework, mergedParams, isDev);
428
531
  config.plugins.unshift(unplugin.vite(mergedParams));
package/build/index.mjs CHANGED
@@ -27,7 +27,7 @@ import { createUnplugin } from "unplugin";
27
27
  // package.json
28
28
  var package_default = {
29
29
  name: "@lingo.dev/_compiler",
30
- version: "0.8.6",
30
+ version: "0.8.8",
31
31
  description: "Lingo.dev Compiler",
32
32
  private: false,
33
33
  repository: {
@@ -72,7 +72,7 @@ var package_default = {
72
72
  "@types/lodash": "4.17.21",
73
73
  "@types/object-hash": "3.0.6",
74
74
  "@types/react": "19.2.7",
75
- next: "15.2.6",
75
+ next: "15.3.8",
76
76
  tsup: "8.5.1",
77
77
  typescript: "5.9.3",
78
78
  vitest: "4.0.13"
@@ -112,12 +112,82 @@ import dedent from "dedent";
112
112
 
113
113
  // src/utils/observability.ts
114
114
  import * as machineIdLib from "node-machine-id";
115
+
116
+ // src/utils/repository-id.ts
117
+ import { execSync } from "child_process";
118
+ var cachedGitRepoId = void 0;
119
+ function getRepositoryId() {
120
+ const ciRepoId = getCIRepositoryId();
121
+ if (ciRepoId) return ciRepoId;
122
+ const gitRepoId = getGitRepositoryId();
123
+ if (gitRepoId) return gitRepoId;
124
+ return null;
125
+ }
126
+ function getCIRepositoryId() {
127
+ if (process.env.GITHUB_REPOSITORY) {
128
+ return `github:${process.env.GITHUB_REPOSITORY}`;
129
+ }
130
+ if (process.env.CI_PROJECT_PATH) {
131
+ return `gitlab:${process.env.CI_PROJECT_PATH}`;
132
+ }
133
+ if (process.env.BITBUCKET_REPO_FULL_NAME) {
134
+ return `bitbucket:${process.env.BITBUCKET_REPO_FULL_NAME}`;
135
+ }
136
+ return null;
137
+ }
138
+ function getGitRepositoryId() {
139
+ if (cachedGitRepoId !== void 0) {
140
+ return cachedGitRepoId;
141
+ }
142
+ try {
143
+ const remoteUrl = execSync("git config --get remote.origin.url", {
144
+ encoding: "utf8",
145
+ stdio: ["pipe", "pipe", "ignore"]
146
+ }).trim();
147
+ if (!remoteUrl) {
148
+ cachedGitRepoId = null;
149
+ return null;
150
+ }
151
+ cachedGitRepoId = parseGitUrl(remoteUrl);
152
+ return cachedGitRepoId;
153
+ } catch {
154
+ cachedGitRepoId = null;
155
+ return null;
156
+ }
157
+ }
158
+ function parseGitUrl(url) {
159
+ const cleanUrl = url.replace(/\.git$/, "");
160
+ let platform = null;
161
+ if (cleanUrl.includes("github.com")) {
162
+ platform = "github";
163
+ } else if (cleanUrl.includes("gitlab.com")) {
164
+ platform = "gitlab";
165
+ } else if (cleanUrl.includes("bitbucket.org")) {
166
+ platform = "bitbucket";
167
+ }
168
+ const sshMatch = cleanUrl.match(/[@:]([^:/@]+\/[^:/@]+)$/);
169
+ const httpsMatch = cleanUrl.match(/\/([^/]+\/[^/]+)$/);
170
+ const repoPath = sshMatch?.[1] || httpsMatch?.[1];
171
+ if (!repoPath) return null;
172
+ if (platform) {
173
+ return `${platform}:${repoPath}`;
174
+ }
175
+ return `git:${repoPath}`;
176
+ }
177
+
178
+ // src/utils/observability.ts
179
+ var TRACKING_VERSION = "2.0";
115
180
  async function trackEvent(event, properties) {
116
- if (process.env.DO_NOT_TRACK) {
181
+ if (process.env.DO_NOT_TRACK === "1") {
117
182
  return;
118
183
  }
119
184
  try {
120
- const actualId = await getActualId();
185
+ const identityInfo = await getDistinctId();
186
+ if (process.env.DEBUG === "true") {
187
+ console.log(
188
+ `[Tracking] Event: ${event}, ID: ${identityInfo.distinct_id}, Source: ${identityInfo.distinct_id_source}`
189
+ );
190
+ }
121
191
  const { PostHog } = await import("posthog-node");
122
192
  const posthog = new PostHog(
123
193
  "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
@@ -128,11 +198,14 @@ async function trackEvent(event, properties) {
128
198
  }
129
199
  );
130
200
  await posthog.capture({
131
- distinctId: actualId,
201
+ distinctId: identityInfo.distinct_id,
132
202
  event,
133
203
  properties: {
134
204
  ...properties,
135
205
  isByokMode: properties?.models !== "lingo.dev",
206
+ tracking_version: TRACKING_VERSION,
207
+ distinct_id_source: identityInfo.distinct_id_source,
208
+ project_id: identityInfo.project_id,
136
209
  meta: {
137
210
  version: process.env.npm_package_version,
138
211
  isCi: process.env.CI === "true"
@@ -141,35 +214,65 @@ async function trackEvent(event, properties) {
141
214
  });
142
215
  await posthog.shutdown();
143
216
  } catch (error) {
144
- if (process.env.DEBUG) {
145
- console.error(error);
217
+ if (process.env.DEBUG === "true") {
218
+ console.error("[Tracking] Error:", error);
146
219
  }
147
220
  }
148
221
  }
149
- async function getActualId() {
222
+ async function getDistinctId() {
223
+ const email = await tryGetEmail();
224
+ if (email) {
225
+ const projectId = getRepositoryId();
226
+ return {
227
+ distinct_id: email,
228
+ distinct_id_source: "email",
229
+ project_id: projectId
230
+ };
231
+ }
232
+ const repoId = getRepositoryId();
233
+ if (repoId) {
234
+ return {
235
+ distinct_id: repoId,
236
+ distinct_id_source: "git_repo",
237
+ project_id: repoId
238
+ };
239
+ }
240
+ const deviceId = `device-${await machineIdLib.machineId()}`;
241
+ if (process.env.DEBUG === "true") {
242
+ console.warn(
243
+ "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking."
244
+ );
245
+ }
246
+ return {
247
+ distinct_id: deviceId,
248
+ distinct_id_source: "device",
249
+ project_id: null
250
+ };
251
+ }
252
+ async function tryGetEmail() {
150
253
  const rc = getRc();
151
254
  const apiKey = process.env.LINGODOTDEV_API_KEY || rc?.auth?.apiKey;
152
255
  const apiUrl = process.env.LINGODOTDEV_API_URL || rc?.auth?.apiUrl || "https://engine.lingo.dev";
153
- if (apiKey) {
154
- try {
155
- const res = await fetch(`${apiUrl}/whoami`, {
156
- method: "POST",
157
- headers: {
158
- Authorization: `Bearer ${apiKey}`,
159
- ContentType: "application/json"
160
- }
161
- });
162
- if (res.ok) {
163
- const payload = await res.json();
164
- if (payload?.email) {
165
- return payload.email;
166
- }
256
+ if (!apiKey) {
257
+ return null;
258
+ }
259
+ try {
260
+ const res = await fetch(`${apiUrl}/whoami`, {
261
+ method: "POST",
262
+ headers: {
263
+ Authorization: `Bearer ${apiKey}`,
264
+ ContentType: "application/json"
265
+ }
266
+ });
267
+ if (res.ok) {
268
+ const payload = await res.json();
269
+ if (payload?.email) {
270
+ return payload.email;
167
271
  }
168
- } catch (err) {
169
272
  }
273
+ } catch (err) {
170
274
  }
171
- const id = await machineIdLib.machineId();
172
- return `device-${id}`;
275
+ return null;
173
276
  }
174
277
 
175
278
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "@types/lodash": "4.17.21",
38
38
  "@types/object-hash": "3.0.6",
39
39
  "@types/react": "19.2.7",
40
- "next": "15.2.6",
40
+ "next": "15.3.8",
41
41
  "tsup": "8.5.1",
42
42
  "typescript": "5.9.3",
43
43
  "vitest": "4.0.13"