Skip to content

Commit 7db90c8

Browse files
authored
feat(compiler): add deprecation warnings for legacy compiler (#1934)
* feat(compiler): add deprecation warnings for legacy compiler * chore: remove deprecated local settings file * docs(compiler): update documentation link format in README
1 parent 0ffe9a0 commit 7db90c8

File tree

7 files changed

+192
-10
lines changed

7 files changed

+192
-10
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@lingo.dev/_compiler": patch
3+
---
4+
5+
Add deprecation warnings throughout legacy compiler
6+
7+
The legacy compiler (`@lingo.dev/_compiler`) now shows deprecation warnings when used.
8+
Users are encouraged to migrate to the new compiler (`@lingo.dev/compiler`).
9+
10+
Changes:
11+
- Added runtime deprecation warnings in `next()`, `vite()`, and the Turbopack loader
12+
- Added `@deprecated` JSDoc tags to all public APIs
13+
- Updated package README with migration guide and examples
14+
- The deprecation warning includes information about new compiler features and migration guide link

packages/cli/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
**Lingo.dev Compiler** is a free, open-source compiler middleware, designed to make any React app multilingual at build time without requiring any changes to the existing React components.
5050

51+
> **Note:** If you're using the legacy compiler (`@lingo.dev/_compiler`), please migrate to `@lingo.dev/compiler`. The legacy compiler is deprecated and will be removed in a future release.
52+
5153
Install once:
5254

5355
```bash

packages/compiler/README.md

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,92 @@
1-
# Lingo.dev Compiler
1+
# Lingo.dev Compiler (Legacy)
22

3-
**Lingo.dev Compiler** is a free, open-source compiler middleware, that makes React apps multilingual at build time without requiring any changes to the existing React components.
3+
> **DEPRECATED:** This package (`@lingo.dev/_compiler`) is deprecated. Please migrate to `@lingo.dev/compiler` (the new compiler).
44
5-
Documentation: https://lingo.dev/compiler
5+
## Migration
6+
7+
Install the new compiler:
8+
9+
```bash
10+
npm install @lingo.dev/compiler
11+
```
12+
13+
Update your configuration:
14+
15+
**Next.js (before):**
16+
```ts
17+
import lingoCompiler from "@lingo.dev/_compiler";
18+
import type { NextConfig } from "next";
19+
20+
const nextConfig: NextConfig = {};
21+
22+
export default lingoCompiler.next({
23+
sourceRoot: "app",
24+
models: "lingo.dev",
25+
})(nextConfig);
26+
```
27+
28+
**Next.js (after):**
29+
```ts
30+
import type { NextConfig } from "next";
31+
import { withLingo } from "@lingo.dev/compiler/next";
32+
33+
const nextConfig: NextConfig = {};
34+
35+
export default async function (): Promise<NextConfig> {
36+
return await withLingo(nextConfig, {
37+
sourceLocale: "en",
38+
targetLocales: ["es", "fr"],
39+
models: "lingo.dev",
40+
});
41+
}
42+
```
43+
44+
**Vite (before):**
45+
```ts
46+
import { defineConfig, type UserConfig } from "vite";
47+
import react from "@vitejs/plugin-react";
48+
import lingoCompiler from "@lingo.dev/_compiler";
49+
50+
const viteConfig: UserConfig = {
51+
plugins: [react()],
52+
};
53+
54+
export default defineConfig(() =>
55+
lingoCompiler.vite({
56+
models: "lingo.dev",
57+
})(viteConfig)
58+
);
59+
```
60+
61+
**Vite (after):**
62+
```ts
63+
import { defineConfig, type UserConfig } from "vite";
64+
import react from "@vitejs/plugin-react";
65+
import { withLingo } from "@lingo.dev/compiler/vite";
66+
67+
const viteConfig: UserConfig = {
68+
plugins: [react()],
69+
};
70+
71+
export default defineConfig(async () =>
72+
await withLingo(viteConfig, {
73+
sourceLocale: "en",
74+
targetLocales: ["es", "fr"],
75+
models: "lingo.dev",
76+
})
77+
);
78+
```
79+
80+
## New Compiler Features
81+
82+
The new compiler (`@lingo.dev/compiler`) offers:
83+
84+
- Advanced virtual module system for better code splitting
85+
- Built-in development translation server
86+
- Pluralization detection with ICU MessageFormat support
87+
- Improved metadata management for better caching
88+
- Thread-safe concurrent build support
89+
90+
## Documentation
91+
92+
Full documentation: [lingo.dev/compiler](https://lingo.dev/compiler)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const DEPRECATION_WARNING = `
2+
⚠️ DEPRECATION WARNING: @lingo.dev/_compiler is deprecated.
3+
Please migrate to @lingo.dev/compiler (the new compiler).
4+
5+
The new compiler offers:
6+
• Advanced virtual module system for better code splitting
7+
• Built-in development translation server
8+
• Pluralization detection with ICU MessageFormat support
9+
• Improved metadata management for better caching
10+
• Thread-safe concurrent build support
11+
12+
Migration guide: https://lingo.dev/compiler
13+
14+
This legacy compiler will be removed in a future release.
15+
`;
16+
17+
let deprecationWarningShown = false;
18+
19+
export function showDeprecationWarning() {
20+
if (deprecationWarningShown) return;
21+
deprecationWarningShown = true;
22+
console.warn(DEPRECATION_WARNING);
23+
}

packages/compiler/src/_loader-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { parseParametrizedModuleId } from "./utils/module-params";
2323

2424
/**
2525
* Loads a dictionary for a specific locale
26+
*
27+
* @deprecated This function is part of the legacy compiler (@lingo.dev/_compiler).
28+
* Please migrate to @lingo.dev/compiler. See https://lingo.dev/compiler
2629
*/
2730
export async function loadDictionary(options: {
2831
resourcePath: string;
@@ -79,6 +82,9 @@ export async function loadDictionary(options: {
7982

8083
/**
8184
* Transforms component code
85+
*
86+
* @deprecated This function is part of the legacy compiler (@lingo.dev/_compiler).
87+
* Please migrate to @lingo.dev/compiler. See https://lingo.dev/compiler
8288
*/
8389
export function transformComponent(options: {
8490
code: string;

packages/compiler/src/index.ts

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./utils/llm-api-key";
2020
import { isRunningInCIOrDocker } from "./utils/env";
2121
import { providerDetails } from "./lib/lcp/api/provider-details";
22+
import { showDeprecationWarning } from "./_deprecation";
2223
import { loadDictionary, transformComponent } from "./_loader-utils";
2324
import trackEvent from "./utils/observability";
2425

@@ -61,6 +62,7 @@ function sendBuildEvent(framework: string, config: any, isDev: boolean) {
6162

6263
const unplugin = createUnplugin<Partial<typeof defaultParams> | undefined>(
6364
(_params, _meta) => {
65+
showDeprecationWarning();
6466
console.log("ℹ️ Starting Lingo.dev compiler...");
6567

6668
const params = _.defaults(_params, defaultParams);
@@ -155,13 +157,32 @@ export default {
155157
/**
156158
* Initializes Lingo.dev Compiler for Next.js (App Router).
157159
*
160+
* @deprecated This legacy compiler is deprecated. Please migrate to `@lingo.dev/compiler`.
161+
* See migration guide at https://lingo.dev/compiler
162+
*
158163
* @param compilerParams - The compiler parameters.
159164
*
160165
* @returns The Next.js configuration.
161166
*
162-
* @example Configuration for Next.js's default template
167+
* @example New compiler usage (recommended):
163168
* ```ts
164-
* import lingoCompiler from "lingo.dev/compiler";
169+
* import type { NextConfig } from "next";
170+
* import { withLingo } from "@lingo.dev/compiler/next";
171+
*
172+
* const nextConfig: NextConfig = {};
173+
*
174+
* export default async function (): Promise<NextConfig> {
175+
* return await withLingo(nextConfig, {
176+
* sourceLocale: "en",
177+
* targetLocales: ["es", "fr"],
178+
* models: "lingo.dev",
179+
* });
180+
* }
181+
* ```
182+
*
183+
* @example Legacy compiler usage (deprecated):
184+
* ```ts
185+
* import lingoCompiler from "@lingo.dev/_compiler";
165186
* import type { NextConfig } from "next";
166187
*
167188
* const nextConfig: NextConfig = {
@@ -184,6 +205,7 @@ export default {
184205
},
185206
) =>
186207
(nextConfig: any = {}): NextConfig => {
208+
showDeprecationWarning();
187209
const mergedParams = _.merge(
188210
{},
189211
defaultParams,
@@ -272,17 +294,38 @@ export default {
272294
/**
273295
* Initializes Lingo.dev Compiler for Vite.
274296
*
297+
* @deprecated This legacy compiler is deprecated. Please migrate to `@lingo.dev/compiler`.
298+
* See migration guide at https://lingo.dev/compiler
299+
*
275300
* @param compilerParams - The compiler parameters.
276301
*
277302
* @returns The Vite configuration.
278303
*
279-
* @example Configuration for Vite's "react-ts" template
304+
* @example New compiler usage (recommended):
305+
* ```ts
306+
* import { defineConfig, type UserConfig } from "vite";
307+
* import react from "@vitejs/plugin-react";
308+
* import { withLingo } from "@lingo.dev/compiler/vite";
309+
*
310+
* const viteConfig: UserConfig = {
311+
* plugins: [react()],
312+
* };
313+
*
314+
* export default defineConfig(async () =>
315+
* await withLingo(viteConfig, {
316+
* sourceLocale: "en",
317+
* targetLocales: ["es", "fr"],
318+
* models: "lingo.dev",
319+
* })
320+
* );
321+
* ```
322+
*
323+
* @example Legacy Vite configuration (deprecated):
280324
* ```ts
281325
* import { defineConfig, type UserConfig } from "vite";
282326
* import react from "@vitejs/plugin-react";
283-
* import lingoCompiler from "lingo.dev/compiler";
327+
* import lingoCompiler from "@lingo.dev/_compiler";
284328
*
285-
* // https://vite.dev/config/
286329
* const viteConfig: UserConfig = {
287330
* plugins: [react()],
288331
* };
@@ -294,11 +337,11 @@ export default {
294337
* );
295338
* ```
296339
*
297-
* @example Configuration for React Router's default template
340+
* @example Legacy React Router configuration (deprecated):
298341
* ```ts
299342
* import { reactRouter } from "@react-router/dev/vite";
300343
* import tailwindcss from "@tailwindcss/vite";
301-
* import lingoCompiler from "lingo.dev/compiler";
344+
* import lingoCompiler from "@lingo.dev/_compiler";
302345
* import { defineConfig, type UserConfig } from "vite";
303346
* import tsconfigPaths from "vite-tsconfig-paths";
304347
*
@@ -315,6 +358,7 @@ export default {
315358
* ```
316359
*/
317360
vite: (compilerParams?: Partial<typeof defaultParams>) => (config: any) => {
361+
showDeprecationWarning();
318362
const mergedParams = _.merge(
319363
{},
320364
defaultParams,

packages/compiler/src/lingo-turbopack-loader.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { showDeprecationWarning } from "./_deprecation";
12
import { loadDictionary, transformComponent } from "./_loader-utils";
23

4+
/**
5+
* @deprecated This loader is part of the legacy compiler. Please migrate to @lingo.dev/compiler.
6+
* See migration guide at https://lingo.dev/compiler
7+
*/
38
// This loader handles component transformations and dictionary generation
49
export default async function (this: any, source: string) {
10+
showDeprecationWarning();
511
const callback = this.async();
612
const params = this.getOptions();
713
const isDev = process.env.NODE_ENV !== "production";

0 commit comments

Comments
 (0)