@lingo.dev/_compiler 0.1.11 → 0.1.13

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
@@ -4,7 +4,7 @@ var _unplugin = require('unplugin');
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.1.11",
7
+ version: "0.1.13",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -449,6 +449,9 @@ function getJsxScopes(node) {
449
449
  const result = [];
450
450
  _traverse2.default.call(void 0, node, {
451
451
  JSXElement(path6) {
452
+ if (getJsxElementName(path6) === "LingoProvider") {
453
+ return;
454
+ }
452
455
  const hasNonEmptyTextSiblings = path6.getAllPrevSiblings().concat(path6.getAllNextSiblings()).some(
453
456
  (sibling) => t7.isJSXText(sibling.node) && _optionalChain([sibling, 'access', _16 => _16.node, 'access', _17 => _17.value, 'optionalAccess', _18 => _18.trim, 'call', _19 => _19()]) !== ""
454
457
  );
@@ -624,6 +627,33 @@ var LCP = class _LCP {
624
627
  this.filePath = filePath;
625
628
  this.data = data;
626
629
  }
630
+ static ensureFile(params) {
631
+ const filePath = path.resolve(
632
+ process.cwd(),
633
+ params.sourceRoot,
634
+ params.lingoDir,
635
+ LCP_FILE_NAME
636
+ );
637
+ if (!fs.existsSync(filePath)) {
638
+ const dir = path.dirname(filePath);
639
+ if (!fs.existsSync(dir)) {
640
+ fs.mkdirSync(dir, { recursive: true });
641
+ }
642
+ fs.writeFileSync(filePath, "{}");
643
+ console.log(_dedent2.default`
644
+ \n
645
+ ⚠️ Lingo.dev Compiler detected missing meta.json file in lingo directory.
646
+ Please restart the build / watch command to regenerate all Lingo.dev Compiler files.
647
+ `);
648
+ try {
649
+ fs.rmdirSync(path.resolve(process.cwd(), ".next"), {
650
+ recursive: true
651
+ });
652
+ } catch (error) {
653
+ }
654
+ process.exit(1);
655
+ }
656
+ }
627
657
  static getInstance(params) {
628
658
  const filePath = path.resolve(
629
659
  process.cwd(),
@@ -639,6 +669,9 @@ var LCP = class _LCP {
639
669
  // wait until LCP file stops updating
640
670
  // this ensures all files were transformed before loading / translating dictionaries
641
671
  static async ready(params) {
672
+ if (params.isDev) {
673
+ _LCP.ensureFile(params);
674
+ }
642
675
  const filePath = path.resolve(
643
676
  process.cwd(),
644
677
  params.sourceRoot,
@@ -1234,13 +1267,11 @@ var LCPAPI = class {
1234
1267
  sourceLocale,
1235
1268
  targetLocale
1236
1269
  );
1237
- } catch (e) {
1238
- console.error(`\u26A0\uFE0F Translation for ${targetLocale} failed:`, e);
1239
- return {
1240
- version: 0.1,
1241
- locale: targetLocale,
1242
- files: {}
1243
- };
1270
+ } catch (error) {
1271
+ this._failGroqFailureLocal(
1272
+ targetLocale,
1273
+ error instanceof Error ? error.message : "Unknown error"
1274
+ );
1244
1275
  }
1245
1276
  if (isRunningInCIOrDocker()) {
1246
1277
  const groqFromEnv = getGroqKeyFromEnv();
@@ -1335,6 +1366,50 @@ var LCPAPI = class {
1335
1366
  );
1336
1367
  process.exit(1);
1337
1368
  }
1369
+ static _failGroqFailureLocal(targetLocale, errorMessage) {
1370
+ const isInvalidApiKey = errorMessage.match("Invalid API Key");
1371
+ if (isInvalidApiKey) {
1372
+ console.log(_dedent2.default`
1373
+ \n
1374
+ ⚠️ Lingo.dev Compiler requires a valid Groq API key to translate your application.
1375
+
1376
+ It looks like you set Groq API key but it is not valid. Please check your API key and try again.
1377
+
1378
+ Error details from Groq API: ${errorMessage}
1379
+
1380
+ 👉 You can set the API key in one of the following ways:
1381
+ 1. User-wide: Run npx lingo.dev@latest config set llm.groqApiKey <your-api-key>
1382
+ 2. Project-wide: Add GROQ_API_KEY=<your-api-key> to .env file in every project that uses Lingo.dev Localization Compiler
1383
+ 3. Session-wide: Run export GROQ_API_KEY=<your-api-key> in your terminal before running the compiler to set the API key for the current session
1384
+
1385
+ ⭐️ Also:
1386
+ 1. If you don't yet have a GROQ API key, get one for free at https://groq.com
1387
+ 2. If you want to use a different LLM, raise an issue in our open-source repo: https://lingo.dev/go/gh
1388
+ 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
1389
+
1390
+
1391
+ `);
1392
+ } else {
1393
+ console.log(
1394
+ _dedent2.default`
1395
+ \n
1396
+ ⚠️ Lingo.dev Compiler tried to translate your application to "${targetLocale}" locale via Groq but it failed.
1397
+
1398
+ Error details from Groq API: ${errorMessage}
1399
+
1400
+ This error comes from Groq API, please check their documentation for more details: https://console.groq.com/docs/errors
1401
+
1402
+ ⭐️ Also:
1403
+ 1. Did you set GROQ_API_KEY environment variable?
1404
+ 2. Did you reach any limits of your Groq account?
1405
+ 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
1406
+
1407
+
1408
+ `
1409
+ );
1410
+ }
1411
+ process.exit(1);
1412
+ }
1338
1413
  };
1339
1414
 
1340
1415
  // src/lib/lcp/server.ts
@@ -2339,6 +2414,7 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
2339
2414
  sourceRoot: params.sourceRoot,
2340
2415
  lingoDir: params.lingoDir
2341
2416
  });
2417
+ const isDev = "dev" in _meta ? !!_meta.dev : process.env.NODE_ENV !== "production";
2342
2418
  return {
2343
2419
  name: package_default.name,
2344
2420
  loadInclude: (id) => !!id.match(LCP_DICTIONARY_FILE_NAME),
@@ -2346,7 +2422,8 @@ var unplugin = _unplugin.createUnplugin.call(void 0,
2346
2422
  const moduleInfo = parseParametrizedModuleId(id);
2347
2423
  const lcpParams = {
2348
2424
  sourceRoot: params.sourceRoot,
2349
- lingoDir: params.lingoDir
2425
+ lingoDir: params.lingoDir,
2426
+ isDev
2350
2427
  };
2351
2428
  await LCP.ready(lcpParams);
2352
2429
  const lcp = LCP.getInstance(lcpParams);
package/build/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { createUnplugin } from "unplugin";
4
4
  // package.json
5
5
  var package_default = {
6
6
  name: "@lingo.dev/_compiler",
7
- version: "0.1.11",
7
+ version: "0.1.13",
8
8
  description: "Lingo.dev Compiler",
9
9
  private: false,
10
10
  publishConfig: {
@@ -449,6 +449,9 @@ function getJsxScopes(node) {
449
449
  const result = [];
450
450
  traverse4(node, {
451
451
  JSXElement(path6) {
452
+ if (getJsxElementName(path6) === "LingoProvider") {
453
+ return;
454
+ }
452
455
  const hasNonEmptyTextSiblings = path6.getAllPrevSiblings().concat(path6.getAllNextSiblings()).some(
453
456
  (sibling) => t7.isJSXText(sibling.node) && sibling.node.value?.trim() !== ""
454
457
  );
@@ -624,6 +627,33 @@ var LCP = class _LCP {
624
627
  this.filePath = filePath;
625
628
  this.data = data;
626
629
  }
630
+ static ensureFile(params) {
631
+ const filePath = path.resolve(
632
+ process.cwd(),
633
+ params.sourceRoot,
634
+ params.lingoDir,
635
+ LCP_FILE_NAME
636
+ );
637
+ if (!fs.existsSync(filePath)) {
638
+ const dir = path.dirname(filePath);
639
+ if (!fs.existsSync(dir)) {
640
+ fs.mkdirSync(dir, { recursive: true });
641
+ }
642
+ fs.writeFileSync(filePath, "{}");
643
+ console.log(dedent`
644
+ \n
645
+ ⚠️ Lingo.dev Compiler detected missing meta.json file in lingo directory.
646
+ Please restart the build / watch command to regenerate all Lingo.dev Compiler files.
647
+ `);
648
+ try {
649
+ fs.rmdirSync(path.resolve(process.cwd(), ".next"), {
650
+ recursive: true
651
+ });
652
+ } catch (error) {
653
+ }
654
+ process.exit(1);
655
+ }
656
+ }
627
657
  static getInstance(params) {
628
658
  const filePath = path.resolve(
629
659
  process.cwd(),
@@ -639,6 +669,9 @@ var LCP = class _LCP {
639
669
  // wait until LCP file stops updating
640
670
  // this ensures all files were transformed before loading / translating dictionaries
641
671
  static async ready(params) {
672
+ if (params.isDev) {
673
+ _LCP.ensureFile(params);
674
+ }
642
675
  const filePath = path.resolve(
643
676
  process.cwd(),
644
677
  params.sourceRoot,
@@ -1234,13 +1267,11 @@ var LCPAPI = class {
1234
1267
  sourceLocale,
1235
1268
  targetLocale
1236
1269
  );
1237
- } catch (e) {
1238
- console.error(`\u26A0\uFE0F Translation for ${targetLocale} failed:`, e);
1239
- return {
1240
- version: 0.1,
1241
- locale: targetLocale,
1242
- files: {}
1243
- };
1270
+ } catch (error) {
1271
+ this._failGroqFailureLocal(
1272
+ targetLocale,
1273
+ error instanceof Error ? error.message : "Unknown error"
1274
+ );
1244
1275
  }
1245
1276
  if (isRunningInCIOrDocker()) {
1246
1277
  const groqFromEnv = getGroqKeyFromEnv();
@@ -1335,6 +1366,50 @@ var LCPAPI = class {
1335
1366
  );
1336
1367
  process.exit(1);
1337
1368
  }
1369
+ static _failGroqFailureLocal(targetLocale, errorMessage) {
1370
+ const isInvalidApiKey = errorMessage.match("Invalid API Key");
1371
+ if (isInvalidApiKey) {
1372
+ console.log(dedent2`
1373
+ \n
1374
+ ⚠️ Lingo.dev Compiler requires a valid Groq API key to translate your application.
1375
+
1376
+ It looks like you set Groq API key but it is not valid. Please check your API key and try again.
1377
+
1378
+ Error details from Groq API: ${errorMessage}
1379
+
1380
+ 👉 You can set the API key in one of the following ways:
1381
+ 1. User-wide: Run npx lingo.dev@latest config set llm.groqApiKey <your-api-key>
1382
+ 2. Project-wide: Add GROQ_API_KEY=<your-api-key> to .env file in every project that uses Lingo.dev Localization Compiler
1383
+ 3. Session-wide: Run export GROQ_API_KEY=<your-api-key> in your terminal before running the compiler to set the API key for the current session
1384
+
1385
+ ⭐️ Also:
1386
+ 1. If you don't yet have a GROQ API key, get one for free at https://groq.com
1387
+ 2. If you want to use a different LLM, raise an issue in our open-source repo: https://lingo.dev/go/gh
1388
+ 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
1389
+
1390
+
1391
+ `);
1392
+ } else {
1393
+ console.log(
1394
+ dedent2`
1395
+ \n
1396
+ ⚠️ Lingo.dev Compiler tried to translate your application to "${targetLocale}" locale via Groq but it failed.
1397
+
1398
+ Error details from Groq API: ${errorMessage}
1399
+
1400
+ This error comes from Groq API, please check their documentation for more details: https://console.groq.com/docs/errors
1401
+
1402
+ ⭐️ Also:
1403
+ 1. Did you set GROQ_API_KEY environment variable?
1404
+ 2. Did you reach any limits of your Groq account?
1405
+ 3. If you have questions, feature requests, or would like to contribute, join our Discord: https://lingo.dev/go/discord
1406
+
1407
+
1408
+ `
1409
+ );
1410
+ }
1411
+ process.exit(1);
1412
+ }
1338
1413
  };
1339
1414
 
1340
1415
  // src/lib/lcp/server.ts
@@ -2339,6 +2414,7 @@ var unplugin = createUnplugin(
2339
2414
  sourceRoot: params.sourceRoot,
2340
2415
  lingoDir: params.lingoDir
2341
2416
  });
2417
+ const isDev = "dev" in _meta ? !!_meta.dev : process.env.NODE_ENV !== "production";
2342
2418
  return {
2343
2419
  name: package_default.name,
2344
2420
  loadInclude: (id) => !!id.match(LCP_DICTIONARY_FILE_NAME),
@@ -2346,7 +2422,8 @@ var unplugin = createUnplugin(
2346
2422
  const moduleInfo = parseParametrizedModuleId(id);
2347
2423
  const lcpParams = {
2348
2424
  sourceRoot: params.sourceRoot,
2349
- lingoDir: params.lingoDir
2425
+ lingoDir: params.lingoDir,
2426
+ isDev
2350
2427
  };
2351
2428
  await LCP.ready(lcpParams);
2352
2429
  const lcp = LCP.getInstance(lcpParams);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_compiler",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Lingo.dev Compiler",
5
5
  "private": false,
6
6
  "publishConfig": {