@lingo.dev/_compiler 0.8.5 → 0.8.7

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,11 +27,17 @@ var _unplugin = require('unplugin');
27
27
  // package.json
28
28
  var package_default = {
29
29
  name: "@lingo.dev/_compiler",
30
- version: "0.8.5",
30
+ version: "0.8.7",
31
31
  description: "Lingo.dev Compiler",
32
32
  private: false,
33
+ repository: {
34
+ type: "git",
35
+ url: "https://github.com/lingodotdev/lingo.dev.git",
36
+ directory: "packages/compiler"
37
+ },
33
38
  publishConfig: {
34
- access: "public"
39
+ access: "public",
40
+ provenance: true
35
41
  },
36
42
  sideEffects: false,
37
43
  type: "module",
@@ -106,12 +112,82 @@ var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
106
112
 
107
113
  // src/utils/observability.ts
108
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";
109
180
  async function trackEvent(event, properties) {
110
- if (process.env.DO_NOT_TRACK) {
181
+ if (process.env.DO_NOT_TRACK === "1") {
111
182
  return;
112
183
  }
113
184
  try {
114
- 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
+ }
115
191
  const { PostHog } = await Promise.resolve().then(() => _interopRequireWildcard(require("posthog-node")));
116
192
  const posthog = new PostHog(
117
193
  "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
@@ -122,11 +198,14 @@ async function trackEvent(event, properties) {
122
198
  }
123
199
  );
124
200
  await posthog.capture({
125
- distinctId: actualId,
201
+ distinctId: identityInfo.distinct_id,
126
202
  event,
127
203
  properties: {
128
204
  ...properties,
129
- 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,
130
209
  meta: {
131
210
  version: process.env.npm_package_version,
132
211
  isCi: process.env.CI === "true"
@@ -135,35 +214,65 @@ async function trackEvent(event, properties) {
135
214
  });
136
215
  await posthog.shutdown();
137
216
  } catch (error) {
138
- if (process.env.DEBUG) {
139
- console.error(error);
217
+ if (process.env.DEBUG === "true") {
218
+ console.error("[Tracking] Error:", error);
140
219
  }
141
220
  }
142
221
  }
143
- 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() {
144
253
  const rc = _chunkAKV7BRP5cjs.getRc.call(void 0, );
145
- const apiKey = process.env.LINGODOTDEV_API_KEY || _optionalChain([rc, 'optionalAccess', _3 => _3.auth, 'optionalAccess', _4 => _4.apiKey]);
146
- const apiUrl = process.env.LINGODOTDEV_API_URL || _optionalChain([rc, 'optionalAccess', _5 => _5.auth, 'optionalAccess', _6 => _6.apiUrl]) || "https://engine.lingo.dev";
147
- if (apiKey) {
148
- try {
149
- const res = await fetch(`${apiUrl}/whoami`, {
150
- method: "POST",
151
- headers: {
152
- Authorization: `Bearer ${apiKey}`,
153
- ContentType: "application/json"
154
- }
155
- });
156
- if (res.ok) {
157
- const payload = await res.json();
158
- if (_optionalChain([payload, 'optionalAccess', _7 => _7.email])) {
159
- return payload.email;
160
- }
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;
161
271
  }
162
- } catch (err) {
163
272
  }
273
+ } catch (err) {
164
274
  }
165
- const id = await machineIdLib.machineId();
166
- return `device-${id}`;
275
+ return null;
167
276
  }
168
277
 
169
278
  // src/index.ts
@@ -313,12 +422,12 @@ var index_default = {
313
422
  const isDev = process.env.NODE_ENV !== "production";
314
423
  sendBuildEvent("Next.js", mergedParams, isDev);
315
424
  let turbopackEnabled;
316
- 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") {
317
426
  turbopackEnabled = process.env.TURBOPACK === "1" || process.env.TURBOPACK === "true";
318
427
  } else {
319
- 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;
320
429
  }
321
- 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;
322
431
  const hasWebpackConfig = typeof nextConfig.webpack === "function";
323
432
  const hasTurbopackConfig = typeof nextConfig.turbopack === "function";
324
433
  if (hasWebpackConfig && turbopackEnabled) {
@@ -416,7 +525,7 @@ var index_default = {
416
525
  compilerParams
417
526
  );
418
527
  const isDev = process.env.NODE_ENV !== "production";
419
- 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")]);
420
529
  const framework = isReactRouter ? "React Router" : "Vite";
421
530
  sendBuildEvent(framework, mergedParams, isDev);
422
531
  config.plugins.unshift(unplugin.vite(mergedParams));
package/build/index.mjs CHANGED
@@ -27,11 +27,17 @@ import { createUnplugin } from "unplugin";
27
27
  // package.json
28
28
  var package_default = {
29
29
  name: "@lingo.dev/_compiler",
30
- version: "0.8.5",
30
+ version: "0.8.7",
31
31
  description: "Lingo.dev Compiler",
32
32
  private: false,
33
+ repository: {
34
+ type: "git",
35
+ url: "https://github.com/lingodotdev/lingo.dev.git",
36
+ directory: "packages/compiler"
37
+ },
33
38
  publishConfig: {
34
- access: "public"
39
+ access: "public",
40
+ provenance: true
35
41
  },
36
42
  sideEffects: false,
37
43
  type: "module",
@@ -106,12 +112,82 @@ import dedent from "dedent";
106
112
 
107
113
  // src/utils/observability.ts
108
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";
109
180
  async function trackEvent(event, properties) {
110
- if (process.env.DO_NOT_TRACK) {
181
+ if (process.env.DO_NOT_TRACK === "1") {
111
182
  return;
112
183
  }
113
184
  try {
114
- 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
+ }
115
191
  const { PostHog } = await import("posthog-node");
116
192
  const posthog = new PostHog(
117
193
  "phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
@@ -122,11 +198,14 @@ async function trackEvent(event, properties) {
122
198
  }
123
199
  );
124
200
  await posthog.capture({
125
- distinctId: actualId,
201
+ distinctId: identityInfo.distinct_id,
126
202
  event,
127
203
  properties: {
128
204
  ...properties,
129
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,
130
209
  meta: {
131
210
  version: process.env.npm_package_version,
132
211
  isCi: process.env.CI === "true"
@@ -135,35 +214,65 @@ async function trackEvent(event, properties) {
135
214
  });
136
215
  await posthog.shutdown();
137
216
  } catch (error) {
138
- if (process.env.DEBUG) {
139
- console.error(error);
217
+ if (process.env.DEBUG === "true") {
218
+ console.error("[Tracking] Error:", error);
140
219
  }
141
220
  }
142
221
  }
143
- 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() {
144
253
  const rc = getRc();
145
254
  const apiKey = process.env.LINGODOTDEV_API_KEY || rc?.auth?.apiKey;
146
255
  const apiUrl = process.env.LINGODOTDEV_API_URL || rc?.auth?.apiUrl || "https://engine.lingo.dev";
147
- if (apiKey) {
148
- try {
149
- const res = await fetch(`${apiUrl}/whoami`, {
150
- method: "POST",
151
- headers: {
152
- Authorization: `Bearer ${apiKey}`,
153
- ContentType: "application/json"
154
- }
155
- });
156
- if (res.ok) {
157
- const payload = await res.json();
158
- if (payload?.email) {
159
- return payload.email;
160
- }
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;
161
271
  }
162
- } catch (err) {
163
272
  }
273
+ } catch (err) {
164
274
  }
165
- const id = await machineIdLib.machineId();
166
- return `device-${id}`;
275
+ return null;
167
276
  }
168
277
 
169
278
  // src/index.ts
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/lingodotdev/lingo.dev.git",
9
+ "directory": "packages/compiler"
10
+ },
6
11
  "publishConfig": {
7
- "access": "public"
12
+ "access": "public",
13
+ "provenance": true
8
14
  },
9
15
  "sideEffects": false,
10
16
  "type": "module",
@@ -59,8 +65,8 @@
59
65
  "posthog-node": "5.14.0",
60
66
  "unplugin": "2.3.11",
61
67
  "zod": "3.25.76",
62
- "@lingo.dev/_sdk": "0.13.3",
63
- "@lingo.dev/_spec": "0.44.3"
68
+ "@lingo.dev/_sdk": "0.13.4",
69
+ "@lingo.dev/_spec": "0.44.4"
64
70
  },
65
71
  "scripts": {
66
72
  "dev": "tsup --watch",