@lingo.dev/_compiler 0.5.2 → 0.5.4
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/{chunk-42EM6MWM.cjs → chunk-PO4OCL2U.cjs} +15 -7
- package/build/{chunk-XCIXY6J2.mjs → chunk-ZXNG22MO.mjs} +14 -6
- package/build/index.cjs +116 -29
- package/build/index.d.cts +77 -0
- package/build/index.d.ts +77 -0
- package/build/index.mjs +93 -6
- package/build/lingo-turbopack-loader.cjs +3 -3
- package/build/lingo-turbopack-loader.mjs +1 -1
- package/package.json +4 -2
|
@@ -53,7 +53,8 @@ var defaultParams = {
|
|
|
53
53
|
rsc: false,
|
|
54
54
|
useDirective: false,
|
|
55
55
|
debug: false,
|
|
56
|
-
models: {}
|
|
56
|
+
models: {},
|
|
57
|
+
prompt: null
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
// src/_const.ts
|
|
@@ -1927,7 +1928,7 @@ var shots_default = [
|
|
|
1927
1928
|
// src/lib/lcp/api/index.ts
|
|
1928
1929
|
|
|
1929
1930
|
var LCPAPI = class {
|
|
1930
|
-
static async translate(models, sourceDictionary, sourceLocale, targetLocale) {
|
|
1931
|
+
static async translate(models, sourceDictionary, sourceLocale, targetLocale, prompt) {
|
|
1931
1932
|
const timeLabel = `LCPAPI.translate: ${targetLocale}`;
|
|
1932
1933
|
console.time(timeLabel);
|
|
1933
1934
|
const chunks = this._chunkDictionary(sourceDictionary);
|
|
@@ -1937,7 +1938,8 @@ var LCPAPI = class {
|
|
|
1937
1938
|
models,
|
|
1938
1939
|
chunk,
|
|
1939
1940
|
sourceLocale,
|
|
1940
|
-
targetLocale
|
|
1941
|
+
targetLocale,
|
|
1942
|
+
prompt
|
|
1941
1943
|
);
|
|
1942
1944
|
translatedChunks.push(translatedChunk);
|
|
1943
1945
|
}
|
|
@@ -2026,7 +2028,7 @@ var LCPAPI = class {
|
|
|
2026
2028
|
apiKey
|
|
2027
2029
|
});
|
|
2028
2030
|
}
|
|
2029
|
-
static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale) {
|
|
2031
|
+
static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale, prompt) {
|
|
2030
2032
|
if (models === "lingo.dev") {
|
|
2031
2033
|
try {
|
|
2032
2034
|
const lingoDotDevEngine = this._createLingoDotDevEngine();
|
|
@@ -2087,7 +2089,11 @@ var LCPAPI = class {
|
|
|
2087
2089
|
messages: [
|
|
2088
2090
|
{
|
|
2089
2091
|
role: "system",
|
|
2090
|
-
content: prompt_default({
|
|
2092
|
+
content: prompt_default({
|
|
2093
|
+
sourceLocale,
|
|
2094
|
+
targetLocale,
|
|
2095
|
+
prompt: _nullishCoalesce(prompt, () => ( void 0))
|
|
2096
|
+
})
|
|
2091
2097
|
},
|
|
2092
2098
|
...shots_default.flatMap((shotsTuple) => [
|
|
2093
2099
|
{
|
|
@@ -2390,7 +2396,8 @@ var LCPServer = (_class = class {
|
|
|
2390
2396
|
params.models,
|
|
2391
2397
|
uncachedSourceDictionary,
|
|
2392
2398
|
params.sourceLocale,
|
|
2393
|
-
params.targetLocale
|
|
2399
|
+
params.targetLocale,
|
|
2400
|
+
params.prompt
|
|
2394
2401
|
);
|
|
2395
2402
|
targetDictionary = this._mergeDictionaries(newTranslations, cache);
|
|
2396
2403
|
targetDictionary = {
|
|
@@ -2703,4 +2710,5 @@ function transformComponent(options) {
|
|
|
2703
2710
|
|
|
2704
2711
|
|
|
2705
2712
|
|
|
2706
|
-
|
|
2713
|
+
|
|
2714
|
+
exports.__require = __require; exports.defaultParams = defaultParams; exports.LCP_DICTIONARY_FILE_NAME = LCP_DICTIONARY_FILE_NAME; exports.LCPCache = LCPCache; exports.getInvalidLocales = getInvalidLocales; exports.getRc = getRc; exports.getGroqKeyFromRc = getGroqKeyFromRc; exports.getGroqKeyFromEnv = getGroqKeyFromEnv; exports.getLingoDotDevKeyFromEnv = getLingoDotDevKeyFromEnv; exports.getLingoDotDevKeyFromRc = getLingoDotDevKeyFromRc; exports.getGoogleKeyFromRc = getGoogleKeyFromRc; exports.getGoogleKeyFromEnv = getGoogleKeyFromEnv; exports.getMistralKeyFromRc = getMistralKeyFromRc; exports.getMistralKeyFromEnv = getMistralKeyFromEnv; exports.isRunningInCIOrDocker = isRunningInCIOrDocker; exports.providerDetails = providerDetails; exports.loadDictionary = loadDictionary; exports.transformComponent = transformComponent;
|
|
@@ -53,7 +53,8 @@ var defaultParams = {
|
|
|
53
53
|
rsc: false,
|
|
54
54
|
useDirective: false,
|
|
55
55
|
debug: false,
|
|
56
|
-
models: {}
|
|
56
|
+
models: {},
|
|
57
|
+
prompt: null
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
// src/_const.ts
|
|
@@ -1927,7 +1928,7 @@ var shots_default = [
|
|
|
1927
1928
|
// src/lib/lcp/api/index.ts
|
|
1928
1929
|
import dedent2 from "dedent";
|
|
1929
1930
|
var LCPAPI = class {
|
|
1930
|
-
static async translate(models, sourceDictionary, sourceLocale, targetLocale) {
|
|
1931
|
+
static async translate(models, sourceDictionary, sourceLocale, targetLocale, prompt) {
|
|
1931
1932
|
const timeLabel = `LCPAPI.translate: ${targetLocale}`;
|
|
1932
1933
|
console.time(timeLabel);
|
|
1933
1934
|
const chunks = this._chunkDictionary(sourceDictionary);
|
|
@@ -1937,7 +1938,8 @@ var LCPAPI = class {
|
|
|
1937
1938
|
models,
|
|
1938
1939
|
chunk,
|
|
1939
1940
|
sourceLocale,
|
|
1940
|
-
targetLocale
|
|
1941
|
+
targetLocale,
|
|
1942
|
+
prompt
|
|
1941
1943
|
);
|
|
1942
1944
|
translatedChunks.push(translatedChunk);
|
|
1943
1945
|
}
|
|
@@ -2026,7 +2028,7 @@ var LCPAPI = class {
|
|
|
2026
2028
|
apiKey
|
|
2027
2029
|
});
|
|
2028
2030
|
}
|
|
2029
|
-
static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale) {
|
|
2031
|
+
static async _translateChunk(models, sourceDictionary, sourceLocale, targetLocale, prompt) {
|
|
2030
2032
|
if (models === "lingo.dev") {
|
|
2031
2033
|
try {
|
|
2032
2034
|
const lingoDotDevEngine = this._createLingoDotDevEngine();
|
|
@@ -2087,7 +2089,11 @@ var LCPAPI = class {
|
|
|
2087
2089
|
messages: [
|
|
2088
2090
|
{
|
|
2089
2091
|
role: "system",
|
|
2090
|
-
content: prompt_default({
|
|
2092
|
+
content: prompt_default({
|
|
2093
|
+
sourceLocale,
|
|
2094
|
+
targetLocale,
|
|
2095
|
+
prompt: prompt ?? void 0
|
|
2096
|
+
})
|
|
2091
2097
|
},
|
|
2092
2098
|
...shots_default.flatMap((shotsTuple) => [
|
|
2093
2099
|
{
|
|
@@ -2390,7 +2396,8 @@ var LCPServer = class {
|
|
|
2390
2396
|
params.models,
|
|
2391
2397
|
uncachedSourceDictionary,
|
|
2392
2398
|
params.sourceLocale,
|
|
2393
|
-
params.targetLocale
|
|
2399
|
+
params.targetLocale,
|
|
2400
|
+
params.prompt
|
|
2394
2401
|
);
|
|
2395
2402
|
targetDictionary = this._mergeDictionaries(newTranslations, cache);
|
|
2396
2403
|
targetDictionary = {
|
|
@@ -2691,6 +2698,7 @@ export {
|
|
|
2691
2698
|
LCP_DICTIONARY_FILE_NAME,
|
|
2692
2699
|
LCPCache,
|
|
2693
2700
|
getInvalidLocales,
|
|
2701
|
+
getRc,
|
|
2694
2702
|
getGroqKeyFromRc,
|
|
2695
2703
|
getGroqKeyFromEnv,
|
|
2696
2704
|
getLingoDotDevKeyFromEnv,
|
package/build/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
var _chunkPO4OCL2Ucjs = require('./chunk-PO4OCL2U.cjs');
|
|
20
21
|
|
|
21
22
|
// src/index.ts
|
|
22
23
|
var _unplugin = require('unplugin');
|
|
@@ -24,7 +25,7 @@ var _unplugin = require('unplugin');
|
|
|
24
25
|
// package.json
|
|
25
26
|
var package_default = {
|
|
26
27
|
name: "@lingo.dev/_compiler",
|
|
27
|
-
version: "0.5.
|
|
28
|
+
version: "0.5.4",
|
|
28
29
|
description: "Lingo.dev Compiler",
|
|
29
30
|
private: false,
|
|
30
31
|
publishConfig: {
|
|
@@ -81,7 +82,9 @@ var package_default = {
|
|
|
81
82
|
prettier: "^3.4.2",
|
|
82
83
|
unplugin: "^2.1.2",
|
|
83
84
|
vitest: "^2.1.4",
|
|
84
|
-
zod: "^3.24.1"
|
|
85
|
+
zod: "^3.24.1",
|
|
86
|
+
"posthog-node": "^4.17.0",
|
|
87
|
+
"node-machine-id": "^1.1.12"
|
|
85
88
|
},
|
|
86
89
|
packageManager: "pnpm@9.12.3"
|
|
87
90
|
};
|
|
@@ -89,35 +92,109 @@ var package_default = {
|
|
|
89
92
|
// src/index.ts
|
|
90
93
|
var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash);
|
|
91
94
|
var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
|
|
95
|
+
|
|
96
|
+
// src/utils/observability.ts
|
|
97
|
+
var _nodemachineid = require('node-machine-id');
|
|
98
|
+
async function trackEvent(event, properties) {
|
|
99
|
+
if (process.env.DO_NOT_TRACK) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const actualId = await getActualId();
|
|
104
|
+
const { PostHog } = await Promise.resolve().then(() => _interopRequireWildcard(require("posthog-node")));
|
|
105
|
+
const posthog = new PostHog(
|
|
106
|
+
"phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
|
|
107
|
+
{
|
|
108
|
+
host: "https://eu.i.posthog.com",
|
|
109
|
+
flushAt: 1,
|
|
110
|
+
flushInterval: 0
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
await posthog.capture({
|
|
114
|
+
distinctId: actualId,
|
|
115
|
+
event,
|
|
116
|
+
properties: {
|
|
117
|
+
...properties,
|
|
118
|
+
isByokMode: _optionalChain([properties, 'optionalAccess', _2 => _2.models]) !== "lingo.dev",
|
|
119
|
+
meta: {
|
|
120
|
+
version: process.env.npm_package_version,
|
|
121
|
+
isCi: process.env.CI === "true"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
await posthog.shutdown();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (process.env.DEBUG) {
|
|
128
|
+
console.error(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function getActualId() {
|
|
133
|
+
const rc = _chunkPO4OCL2Ucjs.getRc.call(void 0, );
|
|
134
|
+
const apiKey = process.env.LINGODOTDEV_API_KEY || _optionalChain([rc, 'optionalAccess', _3 => _3.auth, 'optionalAccess', _4 => _4.apiKey]);
|
|
135
|
+
const apiUrl = process.env.LINGODOTDEV_API_URL || _optionalChain([rc, 'optionalAccess', _5 => _5.auth, 'optionalAccess', _6 => _6.apiUrl]) || "https://engine.lingo.dev";
|
|
136
|
+
if (apiKey) {
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch(`${apiUrl}/whoami`, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Bearer ${apiKey}`,
|
|
142
|
+
ContentType: "application/json"
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (res.ok) {
|
|
146
|
+
const payload = await res.json();
|
|
147
|
+
if (_optionalChain([payload, 'optionalAccess', _7 => _7.email])) {
|
|
148
|
+
return payload.email;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (err) {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const id = await _nodemachineid.machineId.call(void 0, );
|
|
155
|
+
return `device-${id}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/index.ts
|
|
92
159
|
var keyCheckers = {
|
|
93
160
|
groq: {
|
|
94
|
-
checkEnv:
|
|
95
|
-
checkRc:
|
|
161
|
+
checkEnv: _chunkPO4OCL2Ucjs.getGroqKeyFromEnv,
|
|
162
|
+
checkRc: _chunkPO4OCL2Ucjs.getGroqKeyFromRc
|
|
96
163
|
},
|
|
97
164
|
google: {
|
|
98
|
-
checkEnv:
|
|
99
|
-
checkRc:
|
|
165
|
+
checkEnv: _chunkPO4OCL2Ucjs.getGoogleKeyFromEnv,
|
|
166
|
+
checkRc: _chunkPO4OCL2Ucjs.getGoogleKeyFromRc
|
|
100
167
|
},
|
|
101
168
|
mistral: {
|
|
102
|
-
checkEnv:
|
|
103
|
-
checkRc:
|
|
169
|
+
checkEnv: _chunkPO4OCL2Ucjs.getMistralKeyFromEnv,
|
|
170
|
+
checkRc: _chunkPO4OCL2Ucjs.getMistralKeyFromRc
|
|
104
171
|
},
|
|
105
172
|
"lingo.dev": {
|
|
106
|
-
checkEnv:
|
|
107
|
-
checkRc:
|
|
173
|
+
checkEnv: _chunkPO4OCL2Ucjs.getLingoDotDevKeyFromEnv,
|
|
174
|
+
checkRc: _chunkPO4OCL2Ucjs.getLingoDotDevKeyFromRc
|
|
108
175
|
}
|
|
109
176
|
};
|
|
177
|
+
var alreadySentBuildEvent = { value: false };
|
|
178
|
+
function sendBuildEvent(framework, config, isDev) {
|
|
179
|
+
if (alreadySentBuildEvent.value) return;
|
|
180
|
+
alreadySentBuildEvent.value = true;
|
|
181
|
+
trackEvent("compiler.build.start", {
|
|
182
|
+
framework,
|
|
183
|
+
configuration: config,
|
|
184
|
+
isDevMode: isDev
|
|
185
|
+
});
|
|
186
|
+
}
|
|
110
187
|
var unplugin = _unplugin.createUnplugin.call(void 0,
|
|
111
188
|
(_params, _meta) => {
|
|
112
189
|
console.log("\u2139\uFE0F Starting Lingo.dev compiler...");
|
|
113
|
-
const params = _lodash2.default.defaults(_params,
|
|
114
|
-
if (!
|
|
190
|
+
const params = _lodash2.default.defaults(_params, _chunkPO4OCL2Ucjs.defaultParams);
|
|
191
|
+
if (!_chunkPO4OCL2Ucjs.isRunningInCIOrDocker.call(void 0, )) {
|
|
115
192
|
if (params.models === "lingo.dev") {
|
|
116
193
|
validateLLMKeyDetails(["lingo.dev"]);
|
|
117
194
|
} else {
|
|
118
195
|
const configuredProviders = getConfiguredProviders(params.models);
|
|
119
196
|
validateLLMKeyDetails(configuredProviders);
|
|
120
|
-
const invalidLocales =
|
|
197
|
+
const invalidLocales = _chunkPO4OCL2Ucjs.getInvalidLocales.call(void 0,
|
|
121
198
|
params.models,
|
|
122
199
|
params.sourceLocale,
|
|
123
200
|
params.targetLocales
|
|
@@ -140,16 +217,17 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
|
|
|
140
217
|
}
|
|
141
218
|
}
|
|
142
219
|
}
|
|
143
|
-
|
|
220
|
+
_chunkPO4OCL2Ucjs.LCPCache.ensureDictionaryFile({
|
|
144
221
|
sourceRoot: params.sourceRoot,
|
|
145
222
|
lingoDir: params.lingoDir
|
|
146
223
|
});
|
|
147
224
|
const isDev = "dev" in _meta ? !!_meta.dev : process.env.NODE_ENV !== "production";
|
|
225
|
+
sendBuildEvent("unplugin", params, isDev);
|
|
148
226
|
return {
|
|
149
227
|
name: package_default.name,
|
|
150
|
-
loadInclude: (id) => !!id.match(
|
|
228
|
+
loadInclude: (id) => !!id.match(_chunkPO4OCL2Ucjs.LCP_DICTIONARY_FILE_NAME),
|
|
151
229
|
async load(id) {
|
|
152
|
-
const dictionary = await
|
|
230
|
+
const dictionary = await _chunkPO4OCL2Ucjs.loadDictionary.call(void 0, {
|
|
153
231
|
resourcePath: id,
|
|
154
232
|
resourceQuery: "",
|
|
155
233
|
params: {
|
|
@@ -165,7 +243,6 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
|
|
|
165
243
|
if (!dictionary) {
|
|
166
244
|
return null;
|
|
167
245
|
}
|
|
168
|
-
console.log(JSON.stringify(dictionary, null, 2));
|
|
169
246
|
return {
|
|
170
247
|
code: `export default ${JSON.stringify(dictionary, null, 2)}`
|
|
171
248
|
};
|
|
@@ -174,7 +251,7 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
|
|
|
174
251
|
enforce: "pre",
|
|
175
252
|
transform(code, id) {
|
|
176
253
|
try {
|
|
177
|
-
const result =
|
|
254
|
+
const result = _chunkPO4OCL2Ucjs.transformComponent.call(void 0, {
|
|
178
255
|
code,
|
|
179
256
|
params,
|
|
180
257
|
resourcePath: id,
|
|
@@ -194,7 +271,7 @@ var src_default = {
|
|
|
194
271
|
next: (compilerParams) => (nextConfig = {}) => {
|
|
195
272
|
const mergedParams = _lodash2.default.merge(
|
|
196
273
|
{},
|
|
197
|
-
|
|
274
|
+
_chunkPO4OCL2Ucjs.defaultParams,
|
|
198
275
|
{
|
|
199
276
|
rsc: true,
|
|
200
277
|
turbopack: {
|
|
@@ -204,13 +281,15 @@ var src_default = {
|
|
|
204
281
|
},
|
|
205
282
|
compilerParams
|
|
206
283
|
);
|
|
284
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
285
|
+
sendBuildEvent("Next.js", mergedParams, isDev);
|
|
207
286
|
let turbopackEnabled;
|
|
208
|
-
if (_optionalChain([mergedParams, 'access',
|
|
287
|
+
if (_optionalChain([mergedParams, 'access', _8 => _8.turbopack, 'optionalAccess', _9 => _9.enabled]) === "auto") {
|
|
209
288
|
turbopackEnabled = process.env.TURBOPACK === "1" || process.env.TURBOPACK === "true";
|
|
210
289
|
} else {
|
|
211
|
-
turbopackEnabled = _optionalChain([mergedParams, 'access',
|
|
290
|
+
turbopackEnabled = _optionalChain([mergedParams, 'access', _10 => _10.turbopack, 'optionalAccess', _11 => _11.enabled]) === true;
|
|
212
291
|
}
|
|
213
|
-
const supportLegacyTurbo = _optionalChain([mergedParams, 'access',
|
|
292
|
+
const supportLegacyTurbo = _optionalChain([mergedParams, 'access', _12 => _12.turbopack, 'optionalAccess', _13 => _13.useLegacyTurbo]) === true;
|
|
214
293
|
const hasWebpackConfig = typeof nextConfig.webpack === "function";
|
|
215
294
|
const hasTurbopackConfig = typeof nextConfig.turbopack === "function";
|
|
216
295
|
if (hasWebpackConfig && turbopackEnabled) {
|
|
@@ -243,7 +322,7 @@ var src_default = {
|
|
|
243
322
|
turbopackConfigPath.rules ??= {};
|
|
244
323
|
const rules = turbopackConfigPath.rules;
|
|
245
324
|
const lingoGlob = `**/*.{ts,tsx,js,jsx}`;
|
|
246
|
-
const lingoLoaderPath =
|
|
325
|
+
const lingoLoaderPath = _chunkPO4OCL2Ucjs.__require.resolve("./lingo-turbopack-loader");
|
|
247
326
|
rules[lingoGlob] = {
|
|
248
327
|
loaders: [
|
|
249
328
|
{
|
|
@@ -256,15 +335,23 @@ var src_default = {
|
|
|
256
335
|
return nextConfig;
|
|
257
336
|
},
|
|
258
337
|
vite: (compilerParams) => (config) => {
|
|
259
|
-
|
|
260
|
-
|
|
338
|
+
const mergedParams = _lodash2.default.merge(
|
|
339
|
+
{},
|
|
340
|
+
_chunkPO4OCL2Ucjs.defaultParams,
|
|
341
|
+
{ rsc: false },
|
|
342
|
+
compilerParams
|
|
261
343
|
);
|
|
344
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
345
|
+
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")]);
|
|
346
|
+
const framework = isReactRouter ? "React Router" : "Vite";
|
|
347
|
+
sendBuildEvent(framework, mergedParams, isDev);
|
|
348
|
+
config.plugins.unshift(unplugin.vite(mergedParams));
|
|
262
349
|
return config;
|
|
263
350
|
}
|
|
264
351
|
};
|
|
265
352
|
function getConfiguredProviders(models) {
|
|
266
353
|
return _lodash2.default.chain(Object.values(models)).map((modelString) => modelString.split(":")[0]).filter(Boolean).uniq().filter(
|
|
267
|
-
(providerId) =>
|
|
354
|
+
(providerId) => _chunkPO4OCL2Ucjs.providerDetails.hasOwnProperty(providerId) && keyCheckers.hasOwnProperty(providerId)
|
|
268
355
|
).value();
|
|
269
356
|
}
|
|
270
357
|
function validateLLMKeyDetails(configuredProviders) {
|
|
@@ -275,7 +362,7 @@ function validateLLMKeyDetails(configuredProviders) {
|
|
|
275
362
|
const missingProviders = [];
|
|
276
363
|
const foundProviders = [];
|
|
277
364
|
for (const providerId of configuredProviders) {
|
|
278
|
-
const details =
|
|
365
|
+
const details = _chunkPO4OCL2Ucjs.providerDetails[providerId];
|
|
279
366
|
const checkers = keyCheckers[providerId];
|
|
280
367
|
if (!details || !checkers) continue;
|
|
281
368
|
const foundInEnv = !!checkers.checkEnv();
|
package/build/index.d.cts
CHANGED
|
@@ -1,14 +1,91 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring Lingo.dev Compiler.
|
|
5
|
+
*/
|
|
3
6
|
type CompilerParams = {
|
|
7
|
+
/**
|
|
8
|
+
* The locale to translate from.
|
|
9
|
+
*
|
|
10
|
+
* This must match one of the following formats:
|
|
11
|
+
*
|
|
12
|
+
* - [ISO 639-1 language code](https://en.wikipedia.org/wiki/ISO_639-1) (e.g., `"en"`)
|
|
13
|
+
* - [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (e.g., `"en-US"`)
|
|
14
|
+
*
|
|
15
|
+
* @default "en"
|
|
16
|
+
*/
|
|
4
17
|
sourceLocale: string;
|
|
18
|
+
/**
|
|
19
|
+
* The locale(s) to translate to.
|
|
20
|
+
*
|
|
21
|
+
* Each locale must match one of the following formats:
|
|
22
|
+
*
|
|
23
|
+
* - [ISO 639-1 language code](https://en.wikipedia.org/wiki/ISO_639-1) (e.g., `"en"`)
|
|
24
|
+
* - [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (e.g., `"en-US"`)
|
|
25
|
+
*
|
|
26
|
+
* @default ["es"]
|
|
27
|
+
*/
|
|
5
28
|
targetLocales: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The name of the directory where translation files will be stored, relative to `sourceRoot`.
|
|
31
|
+
*
|
|
32
|
+
* @default "lingo"
|
|
33
|
+
*/
|
|
6
34
|
lingoDir: string;
|
|
35
|
+
/**
|
|
36
|
+
* The directory of the source code that will be translated, relative to the current working directory.
|
|
37
|
+
*
|
|
38
|
+
* @default "src"
|
|
39
|
+
*/
|
|
7
40
|
sourceRoot: string;
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, the compiler will generate code for React Server Components (RSC).
|
|
43
|
+
*
|
|
44
|
+
* When using Vite, this value is always `false`.
|
|
45
|
+
*
|
|
46
|
+
* When using Next.js, this value is always `true`.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
8
50
|
rsc: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If `true`, the compiler will only localize files that use the `"use i18n";` directive.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
9
56
|
useDirective: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* If `true`, the compiler will log additional information to the console.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
10
62
|
debug: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The model(s) to use for translation.
|
|
65
|
+
*
|
|
66
|
+
* If set to `"lingo.dev"`, the compiler will use Lingo.dev Engine.
|
|
67
|
+
*
|
|
68
|
+
* If set to an object, the compiler will use the model(s) specified in the object:
|
|
69
|
+
*
|
|
70
|
+
* - The key is a string that represents the source and target locales, separated by a colon (e.g., `"en:es"`).
|
|
71
|
+
* - The value is a string that represents the LLM provider and model, separated by a colon (e.g., `"google:gemini-2.0-flash"`).
|
|
72
|
+
*
|
|
73
|
+
* You can use `*` as a wildcard to match any locale.
|
|
74
|
+
*
|
|
75
|
+
* If a model is not specified, an error will be thrown.
|
|
76
|
+
*
|
|
77
|
+
* @default {}
|
|
78
|
+
*/
|
|
11
79
|
models: "lingo.dev" | Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* Custom system prompt for the translation engine. If set, this prompt will override the default system prompt defined in Compiler.
|
|
82
|
+
* Only works with custom models, not with Lingo.dev Engine.
|
|
83
|
+
*
|
|
84
|
+
* Example: "You are a helpful assistant that translates {SOURCE_LOCALE} to {TARGET_LOCALE}."
|
|
85
|
+
*
|
|
86
|
+
* @default null
|
|
87
|
+
*/
|
|
88
|
+
prompt?: string | null;
|
|
12
89
|
};
|
|
13
90
|
declare const defaultParams: CompilerParams;
|
|
14
91
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,14 +1,91 @@
|
|
|
1
1
|
import { NextConfig } from 'next';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Options for configuring Lingo.dev Compiler.
|
|
5
|
+
*/
|
|
3
6
|
type CompilerParams = {
|
|
7
|
+
/**
|
|
8
|
+
* The locale to translate from.
|
|
9
|
+
*
|
|
10
|
+
* This must match one of the following formats:
|
|
11
|
+
*
|
|
12
|
+
* - [ISO 639-1 language code](https://en.wikipedia.org/wiki/ISO_639-1) (e.g., `"en"`)
|
|
13
|
+
* - [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (e.g., `"en-US"`)
|
|
14
|
+
*
|
|
15
|
+
* @default "en"
|
|
16
|
+
*/
|
|
4
17
|
sourceLocale: string;
|
|
18
|
+
/**
|
|
19
|
+
* The locale(s) to translate to.
|
|
20
|
+
*
|
|
21
|
+
* Each locale must match one of the following formats:
|
|
22
|
+
*
|
|
23
|
+
* - [ISO 639-1 language code](https://en.wikipedia.org/wiki/ISO_639-1) (e.g., `"en"`)
|
|
24
|
+
* - [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (e.g., `"en-US"`)
|
|
25
|
+
*
|
|
26
|
+
* @default ["es"]
|
|
27
|
+
*/
|
|
5
28
|
targetLocales: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The name of the directory where translation files will be stored, relative to `sourceRoot`.
|
|
31
|
+
*
|
|
32
|
+
* @default "lingo"
|
|
33
|
+
*/
|
|
6
34
|
lingoDir: string;
|
|
35
|
+
/**
|
|
36
|
+
* The directory of the source code that will be translated, relative to the current working directory.
|
|
37
|
+
*
|
|
38
|
+
* @default "src"
|
|
39
|
+
*/
|
|
7
40
|
sourceRoot: string;
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, the compiler will generate code for React Server Components (RSC).
|
|
43
|
+
*
|
|
44
|
+
* When using Vite, this value is always `false`.
|
|
45
|
+
*
|
|
46
|
+
* When using Next.js, this value is always `true`.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
8
50
|
rsc: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If `true`, the compiler will only localize files that use the `"use i18n";` directive.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
9
56
|
useDirective: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* If `true`, the compiler will log additional information to the console.
|
|
59
|
+
*
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
10
62
|
debug: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The model(s) to use for translation.
|
|
65
|
+
*
|
|
66
|
+
* If set to `"lingo.dev"`, the compiler will use Lingo.dev Engine.
|
|
67
|
+
*
|
|
68
|
+
* If set to an object, the compiler will use the model(s) specified in the object:
|
|
69
|
+
*
|
|
70
|
+
* - The key is a string that represents the source and target locales, separated by a colon (e.g., `"en:es"`).
|
|
71
|
+
* - The value is a string that represents the LLM provider and model, separated by a colon (e.g., `"google:gemini-2.0-flash"`).
|
|
72
|
+
*
|
|
73
|
+
* You can use `*` as a wildcard to match any locale.
|
|
74
|
+
*
|
|
75
|
+
* If a model is not specified, an error will be thrown.
|
|
76
|
+
*
|
|
77
|
+
* @default {}
|
|
78
|
+
*/
|
|
11
79
|
models: "lingo.dev" | Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* Custom system prompt for the translation engine. If set, this prompt will override the default system prompt defined in Compiler.
|
|
82
|
+
* Only works with custom models, not with Lingo.dev Engine.
|
|
83
|
+
*
|
|
84
|
+
* Example: "You are a helpful assistant that translates {SOURCE_LOCALE} to {TARGET_LOCALE}."
|
|
85
|
+
*
|
|
86
|
+
* @default null
|
|
87
|
+
*/
|
|
88
|
+
prompt?: string | null;
|
|
12
89
|
};
|
|
13
90
|
declare const defaultParams: CompilerParams;
|
|
14
91
|
|
package/build/index.mjs
CHANGED
|
@@ -12,11 +12,12 @@ import {
|
|
|
12
12
|
getLingoDotDevKeyFromRc,
|
|
13
13
|
getMistralKeyFromEnv,
|
|
14
14
|
getMistralKeyFromRc,
|
|
15
|
+
getRc,
|
|
15
16
|
isRunningInCIOrDocker,
|
|
16
17
|
loadDictionary,
|
|
17
18
|
providerDetails,
|
|
18
19
|
transformComponent
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-ZXNG22MO.mjs";
|
|
20
21
|
|
|
21
22
|
// src/index.ts
|
|
22
23
|
import { createUnplugin } from "unplugin";
|
|
@@ -24,7 +25,7 @@ import { createUnplugin } from "unplugin";
|
|
|
24
25
|
// package.json
|
|
25
26
|
var package_default = {
|
|
26
27
|
name: "@lingo.dev/_compiler",
|
|
27
|
-
version: "0.5.
|
|
28
|
+
version: "0.5.4",
|
|
28
29
|
description: "Lingo.dev Compiler",
|
|
29
30
|
private: false,
|
|
30
31
|
publishConfig: {
|
|
@@ -81,7 +82,9 @@ var package_default = {
|
|
|
81
82
|
prettier: "^3.4.2",
|
|
82
83
|
unplugin: "^2.1.2",
|
|
83
84
|
vitest: "^2.1.4",
|
|
84
|
-
zod: "^3.24.1"
|
|
85
|
+
zod: "^3.24.1",
|
|
86
|
+
"posthog-node": "^4.17.0",
|
|
87
|
+
"node-machine-id": "^1.1.12"
|
|
85
88
|
},
|
|
86
89
|
packageManager: "pnpm@9.12.3"
|
|
87
90
|
};
|
|
@@ -89,6 +92,70 @@ var package_default = {
|
|
|
89
92
|
// src/index.ts
|
|
90
93
|
import _ from "lodash";
|
|
91
94
|
import dedent from "dedent";
|
|
95
|
+
|
|
96
|
+
// src/utils/observability.ts
|
|
97
|
+
import { machineId } from "node-machine-id";
|
|
98
|
+
async function trackEvent(event, properties) {
|
|
99
|
+
if (process.env.DO_NOT_TRACK) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const actualId = await getActualId();
|
|
104
|
+
const { PostHog } = await import("posthog-node");
|
|
105
|
+
const posthog = new PostHog(
|
|
106
|
+
"phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
|
|
107
|
+
{
|
|
108
|
+
host: "https://eu.i.posthog.com",
|
|
109
|
+
flushAt: 1,
|
|
110
|
+
flushInterval: 0
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
await posthog.capture({
|
|
114
|
+
distinctId: actualId,
|
|
115
|
+
event,
|
|
116
|
+
properties: {
|
|
117
|
+
...properties,
|
|
118
|
+
isByokMode: properties?.models !== "lingo.dev",
|
|
119
|
+
meta: {
|
|
120
|
+
version: process.env.npm_package_version,
|
|
121
|
+
isCi: process.env.CI === "true"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
await posthog.shutdown();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
if (process.env.DEBUG) {
|
|
128
|
+
console.error(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function getActualId() {
|
|
133
|
+
const rc = getRc();
|
|
134
|
+
const apiKey = process.env.LINGODOTDEV_API_KEY || rc?.auth?.apiKey;
|
|
135
|
+
const apiUrl = process.env.LINGODOTDEV_API_URL || rc?.auth?.apiUrl || "https://engine.lingo.dev";
|
|
136
|
+
if (apiKey) {
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch(`${apiUrl}/whoami`, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Bearer ${apiKey}`,
|
|
142
|
+
ContentType: "application/json"
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (res.ok) {
|
|
146
|
+
const payload = await res.json();
|
|
147
|
+
if (payload?.email) {
|
|
148
|
+
return payload.email;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch (err) {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const id = await machineId();
|
|
155
|
+
return `device-${id}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/index.ts
|
|
92
159
|
var keyCheckers = {
|
|
93
160
|
groq: {
|
|
94
161
|
checkEnv: getGroqKeyFromEnv,
|
|
@@ -107,6 +174,16 @@ var keyCheckers = {
|
|
|
107
174
|
checkRc: getLingoDotDevKeyFromRc
|
|
108
175
|
}
|
|
109
176
|
};
|
|
177
|
+
var alreadySentBuildEvent = { value: false };
|
|
178
|
+
function sendBuildEvent(framework, config, isDev) {
|
|
179
|
+
if (alreadySentBuildEvent.value) return;
|
|
180
|
+
alreadySentBuildEvent.value = true;
|
|
181
|
+
trackEvent("compiler.build.start", {
|
|
182
|
+
framework,
|
|
183
|
+
configuration: config,
|
|
184
|
+
isDevMode: isDev
|
|
185
|
+
});
|
|
186
|
+
}
|
|
110
187
|
var unplugin = createUnplugin(
|
|
111
188
|
(_params, _meta) => {
|
|
112
189
|
console.log("\u2139\uFE0F Starting Lingo.dev compiler...");
|
|
@@ -145,6 +222,7 @@ var unplugin = createUnplugin(
|
|
|
145
222
|
lingoDir: params.lingoDir
|
|
146
223
|
});
|
|
147
224
|
const isDev = "dev" in _meta ? !!_meta.dev : process.env.NODE_ENV !== "production";
|
|
225
|
+
sendBuildEvent("unplugin", params, isDev);
|
|
148
226
|
return {
|
|
149
227
|
name: package_default.name,
|
|
150
228
|
loadInclude: (id) => !!id.match(LCP_DICTIONARY_FILE_NAME),
|
|
@@ -165,7 +243,6 @@ var unplugin = createUnplugin(
|
|
|
165
243
|
if (!dictionary) {
|
|
166
244
|
return null;
|
|
167
245
|
}
|
|
168
|
-
console.log(JSON.stringify(dictionary, null, 2));
|
|
169
246
|
return {
|
|
170
247
|
code: `export default ${JSON.stringify(dictionary, null, 2)}`
|
|
171
248
|
};
|
|
@@ -204,6 +281,8 @@ var src_default = {
|
|
|
204
281
|
},
|
|
205
282
|
compilerParams
|
|
206
283
|
);
|
|
284
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
285
|
+
sendBuildEvent("Next.js", mergedParams, isDev);
|
|
207
286
|
let turbopackEnabled;
|
|
208
287
|
if (mergedParams.turbopack?.enabled === "auto") {
|
|
209
288
|
turbopackEnabled = process.env.TURBOPACK === "1" || process.env.TURBOPACK === "true";
|
|
@@ -256,9 +335,17 @@ var src_default = {
|
|
|
256
335
|
return nextConfig;
|
|
257
336
|
},
|
|
258
337
|
vite: (compilerParams) => (config) => {
|
|
259
|
-
|
|
260
|
-
|
|
338
|
+
const mergedParams = _.merge(
|
|
339
|
+
{},
|
|
340
|
+
defaultParams,
|
|
341
|
+
{ rsc: false },
|
|
342
|
+
compilerParams
|
|
261
343
|
);
|
|
344
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
345
|
+
const isReactRouter = config.plugins?.flat()?.some((plugin) => plugin.name === "react-router");
|
|
346
|
+
const framework = isReactRouter ? "React Router" : "Vite";
|
|
347
|
+
sendBuildEvent(framework, mergedParams, isDev);
|
|
348
|
+
config.plugins.unshift(unplugin.vite(mergedParams));
|
|
262
349
|
return config;
|
|
263
350
|
}
|
|
264
351
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkPO4OCL2Ucjs = require('./chunk-PO4OCL2U.cjs');
|
|
5
5
|
|
|
6
6
|
// src/lingo-turbopack-loader.ts
|
|
7
7
|
async function lingo_turbopack_loader_default(source) {
|
|
@@ -9,7 +9,7 @@ async function lingo_turbopack_loader_default(source) {
|
|
|
9
9
|
const params = this.getOptions();
|
|
10
10
|
const isDev = process.env.NODE_ENV !== "production";
|
|
11
11
|
try {
|
|
12
|
-
const dictionary = await
|
|
12
|
+
const dictionary = await _chunkPO4OCL2Ucjs.loadDictionary.call(void 0, {
|
|
13
13
|
resourcePath: this.resourcePath,
|
|
14
14
|
resourceQuery: this.resourceQuery,
|
|
15
15
|
params,
|
|
@@ -21,7 +21,7 @@ async function lingo_turbopack_loader_default(source) {
|
|
|
21
21
|
const code = `export default ${JSON.stringify(dictionary, null, 2)};`;
|
|
22
22
|
return callback(null, code);
|
|
23
23
|
}
|
|
24
|
-
const result =
|
|
24
|
+
const result = _chunkPO4OCL2Ucjs.transformComponent.call(void 0, {
|
|
25
25
|
code: source,
|
|
26
26
|
params,
|
|
27
27
|
resourcePath: this.resourcePath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingo.dev/_compiler",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Lingo.dev Compiler",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -50,7 +50,9 @@
|
|
|
50
50
|
"unplugin": "^2.1.2",
|
|
51
51
|
"vitest": "^2.1.4",
|
|
52
52
|
"zod": "^3.24.1",
|
|
53
|
-
"
|
|
53
|
+
"posthog-node": "^4.17.0",
|
|
54
|
+
"node-machine-id": "^1.1.12",
|
|
55
|
+
"@lingo.dev/_sdk": "0.9.6"
|
|
54
56
|
},
|
|
55
57
|
"scripts": {
|
|
56
58
|
"dev": "tsup --watch",
|