Skip to content

Commit 3c8380a

Browse files
committed
fix: remove console logs from the dev server
Long story, but they are not being consumed and we end up with the blocked dev server because it waits until log buffer is freed.
1 parent d6324b3 commit 3c8380a

33 files changed

Lines changed: 511 additions & 400 deletions

cmp/compiler/src/__test-utils__/mocks.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Prevents duplication of test helper functions across test files
44
*/
55

6-
import type { LoaderConfig } from "../types";
7-
import { createLoaderConfig } from "../utils/config-factory";
8-
import { DictionarySchema } from "../translators";
6+
import type { LingoConfig } from "../types";
7+
import { createLingoConfig } from "../utils/config-factory";
8+
import type { DictionarySchema } from "../translators";
99

1010
/**
1111
* Create a mock loader config for testing
@@ -21,11 +21,11 @@ import { DictionarySchema } from "../translators";
2121
* ```
2222
*/
2323
export function createMockConfig(
24-
overrides?: Partial<LoaderConfig>,
25-
): LoaderConfig {
26-
return createLoaderConfig({
24+
overrides?: Partial<LingoConfig>,
25+
): LingoConfig {
26+
return createLingoConfig({
27+
sourceLocale: "en",
2728
sourceRoot: "src",
28-
framework: "vite", // Default to vite (all client components)
2929
targetLocales: ["en", "de"],
3030
...overrides,
3131
});

cmp/compiler/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type {
2-
LoaderConfig,
2+
PartialLingoConfig,
33
MetadataConfig,
44
TranslationConfig,
55
PathConfig,

cmp/compiler/src/plugin/dev-server-loader.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { LoaderConfig } from "../types";
1+
import type { LingoConfig } from "../types";
22
import { logger } from "../utils/logger";
33
import { DEFAULT_TIMEOUTS, withTimeout } from "../utils/timeout";
4-
import { startOrGetTranslationServerHono } from "../translation-server/translation-server-hono";
4+
import { startOrGetTranslationServer } from "../translation-server/translation-server";
5+
import { getCacheDir } from "../utils/path-helpers";
56

6-
let serverPromise: ReturnType<typeof startOrGetTranslationServerHono> | null =
7-
null;
7+
let serverPromise: ReturnType<typeof startOrGetTranslationServer> | null = null;
88

99
export default async function devServerLoader(
1010
this: any,
@@ -14,14 +14,16 @@ export default async function devServerLoader(
1414
if (typeof this.async !== "function") {
1515
throw new Error("This module must be run as a loader");
1616
}
17+
logger.debug("devServerLoader called", this.resourcePath);
1718
const callback = this.async();
1819
const isDev = process.env.NODE_ENV === "development";
1920

20-
const config: LoaderConfig & { cacheDir: string } = this.getOptions();
21+
const config: LingoConfig = this.getOptions();
22+
const startPort = config.dev.serverStartPort;
2123

2224
if (isDev && !serverPromise) {
23-
serverPromise = startOrGetTranslationServerHono({
24-
startPort: 60000,
25+
serverPromise = startOrGetTranslationServer({
26+
startPort,
2527
onError: (err) => {
2628
logger.error("Translation server error:", err);
2729
},
@@ -42,7 +44,9 @@ export default async function devServerLoader(
4244
callback(
4345
null,
4446
source
45-
.replace("__SERVER_URL__", server?.url || "http://127.0.0.1:60000")
46-
.replace("__CACHE_DIR__", config.cacheDir),
47+
// TODO (AleksandrSl 04/12/2025): Should we just error instead of the default?
48+
.replace("__SERVER_URL__", server?.url || `http://127.0.0.1:${startPort}`)
49+
// TODO (AleksandrSl 04/12/2025): Make cacheDir work
50+
.replace("__CACHE_DIR__", getCacheDir(config)),
4751
);
4852
}

cmp/compiler/src/plugin/esbuild.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020

2121
import { lingoUnplugin, type LingoPluginOptions } from "./unplugin";
2222

23-
export function lingoCompilerPlugin(options: Partial<LingoPluginOptions> = {}) {
24-
return lingoUnplugin.esbuild({
25-
...options,
26-
framework: "esbuild",
27-
} as LingoPluginOptions);
23+
export function lingoCompilerPlugin(options: LingoPluginOptions) {
24+
return lingoUnplugin.esbuild(options);
2825
}
2926

3027
export type { LingoPluginOptions };

cmp/compiler/src/plugin/next.ts

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,14 @@ import {
66
getCacheDir,
77
getCachePath,
88
getConfigPath,
9-
getDevConfigPath,
109
} from "../utils/path-helpers";
11-
import { createLoaderConfig } from "../utils/config-factory";
10+
import { createLingoConfig } from "../utils/config-factory";
1211
import { logger } from "../utils/logger";
1312
import { startTranslationServer } from "../translation-server";
14-
import { CookieConfig, LoaderConfig } from "../types";
15-
import { TurbopackOptions } from "next/dist/server/config-shared";
16-
17-
export type LingoNextPluginOptions = {
18-
/**
19-
* File patterns to skip during transformation
20-
* @default [/node_modules/, /\.spec\./, /\.test\./]
21-
*/
22-
skipPatterns?: RegExp[];
23-
24-
/**
25-
* Cookie configuration for locale persistence
26-
* Shared between client-side LocaleSwitcher and server-side locale resolver
27-
* @default { name: 'locale', maxAge: 31536000 }
28-
*/
29-
cookieConfig?: CookieConfig;
30-
} & Pick<
31-
LoaderConfig,
32-
| "dev"
33-
| "prompt"
34-
| "models"
35-
| "useDirective"
36-
| "targetLocales"
37-
| "sourceLocale"
38-
| "lingoDir"
39-
| "sourceRoot"
40-
>;
13+
import type { PartialLingoConfig } from "../types";
14+
import type { TurbopackOptions } from "next/dist/server/config-shared";
15+
16+
export type LingoNextPluginOptions = PartialLingoConfig;
4117

4218
/**
4319
* Check if Next.js supports stable turbopack config (Next.js 16+)
@@ -93,10 +69,7 @@ function buildLingoConfig(
9369
userNextConfig: NextConfig,
9470
lingoOptions: LingoNextPluginOptions,
9571
): NextConfig {
96-
const lingoConfig = createLoaderConfig({
97-
...lingoOptions,
98-
framework: "next",
99-
});
72+
const lingoConfig = createLingoConfig(lingoOptions);
10073

10174
// Prepare Turbopack loader configuration
10275
const loaderConfig = {
@@ -106,7 +79,6 @@ function buildLingoConfig(
10679
lingoDir: lingoConfig.lingoDir,
10780
sourceLocale: lingoConfig.sourceLocale,
10881
useDirective: lingoConfig.useDirective,
109-
framework: lingoConfig.framework,
11082
},
11183
};
11284

@@ -118,15 +90,14 @@ function buildLingoConfig(
11890
}),
11991
// TODO (AleksandrSl 02/12/2025): We can also inject default resolvers for locale based on the framework
12092
{
121-
pattern: "**/dev-config.ts",
93+
pattern: "**/dev-config.mjs",
12294
config: {
12395
loaders: [
12496
{
12597
loader: "@lingo.dev/_compiler/dev-server-loader",
12698
options: {
12799
sourceRoot: lingoConfig.sourceRoot,
128100
lingoDir: lingoConfig.lingoDir,
129-
cacheDir: getCacheDir(lingoConfig),
130101
dev: lingoConfig.dev,
131102
sourceLocale: lingoConfig.sourceLocale,
132103
},
@@ -140,7 +111,6 @@ function buildLingoConfig(
140111
const mergedResolveAlias = {
141112
...existingResolveAlias,
142113
"@lingo.dev/_compiler/config": getConfigPath(lingoConfig),
143-
"@lingo.dev/_compiler/dev-config": getDevConfigPath(lingoConfig),
144114
};
145115

146116
// Build Turbopack config (handles Next.js 16+ vs <16)
@@ -191,7 +161,7 @@ function buildLingoConfig(
191161
| undefined;
192162
try {
193163
translationServer = await startTranslationServer({
194-
startPort: 60000,
164+
startPort: lingoConfig.dev?.serverStartPort,
195165
onError: (err) => {
196166
logger.error("Translation server error:", err);
197167
},
@@ -267,7 +237,6 @@ function buildLingoConfig(
267237
sourceLocale: lingoConfig.sourceLocale,
268238
useDirective: lingoConfig.useDirective,
269239
skipPatterns: lingoConfig.skipPatterns,
270-
framework: lingoConfig.framework,
271240
},
272241
},
273242
],

cmp/compiler/src/plugin/rollup.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919

2020
import { lingoUnplugin, type LingoPluginOptions } from "./unplugin";
2121

22-
export function lingoCompilerPlugin(options: Partial<LingoPluginOptions> = {}) {
23-
return lingoUnplugin.rollup({
24-
...options,
25-
framework: "rollup",
26-
} as LingoPluginOptions);
22+
export function lingoCompilerPlugin(options: LingoPluginOptions) {
23+
return lingoUnplugin.rollup(options);
2724
}
2825

2926
export type { LingoPluginOptions };

cmp/compiler/src/plugin/transform/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as parser from "@babel/parser";
22
import traverseDefault from "@babel/traverse";
33
import generateDefault from "@babel/generator";
44
import path from "path";
5-
import { LoaderConfig, MetadataSchema, TranslationEntry } from "../../types";
6-
import { createBabelVisitors, VisitorsSharedState } from "./visitors";
5+
import type { LingoConfig, TranslationEntry } from "../../types";
6+
import { createBabelVisitors, type VisitorsSharedState } from "./visitors";
77
import { logger } from "../../utils/logger";
88

99
// Handle ESM/CJS interop - these packages may export differently
@@ -36,7 +36,7 @@ export interface BabelTransformOptions {
3636
/**
3737
* Loader configuration
3838
*/
39-
config: LoaderConfig;
39+
config: LingoConfig;
4040
}
4141

4242
/**
@@ -107,7 +107,7 @@ export function transformComponent({
107107
*/
108108
export function shouldTransformFile(
109109
filePath: string,
110-
config: LoaderConfig,
110+
config: LingoConfig,
111111
): boolean {
112112
// Only transform .tsx and .jsx files
113113
if (!filePath.match(/\.(tsx|jsx)$/)) {

0 commit comments

Comments
 (0)