Skip to content

Commit f0fd562

Browse files
committed
fix: vite for external builds
1 parent d36df83 commit f0fd562

File tree

7 files changed

+524
-175
lines changed

7 files changed

+524
-175
lines changed

cmp/compiler/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"@types/react": "^18.3.26",
140140
"@types/react-dom": "^19.2.3",
141141
"@types/ws": "^8.18.1",
142-
"next": "^16.0.3",
142+
"next": "^16.1.0",
143143
"tsdown": "^0.16.5",
144144
"tsx": "^4.19.2",
145145
"typescript": "^5.9.3",
@@ -171,8 +171,8 @@
171171
},
172172
"peerDependencies": {
173173
"next": "^15.0.0 || ^16.0.4",
174-
"react": "^18.0.0 || ^19.0.0",
175-
"react-dom": "^18.0.0 || ^19.0.0"
174+
"react": "^19.0.0",
175+
"react-dom": " ^19.0.0"
176176
},
177177
"peerDependenciesMeta": {
178178
"next": {

cmp/compiler/playwright.config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,4 @@ export default defineConfig({
4242
use: { ...devices["Desktop Chrome"] },
4343
},
4444
],
45-
46-
/* Run your local dev server before starting the tests */
47-
// webServer: {
48-
// command: 'npm run start',
49-
// url: 'http://localhost:3000',
50-
// reuseExistingServer: !process.env.CI,
51-
// },
5245
});

cmp/compiler/tests/helpers/locale-switcher.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Page } from "@playwright/test";
1+
import { expect, Page } from "@playwright/test";
22

33
export function getLocaleSwitcher(page: Page) {
44
return page.getByTestId("lingo-locale-switcher").first();
@@ -19,6 +19,7 @@ export async function switchLocale(
1919
// Wait for the locale change to complete
2020
// This waits for any network requests to finish (e.g., translation file loading)
2121
await page.waitForLoadState("networkidle", { timeout: 10000 });
22+
expect(await getLanguageFromHtml(page)).toBe(targetLocale);
2223
}
2324

2425
/**
@@ -28,3 +29,11 @@ export async function getCurrentLocale(page: Page): Promise<string> {
2829
const select = getLocaleSwitcher(page);
2930
return await select.inputValue();
3031
}
32+
33+
/**
34+
* Get the language from the HTML lang attribute
35+
*/
36+
export async function getLanguageFromHtml(page: Page): Promise<string | null> {
37+
const html = page.locator("html");
38+
return await html.getAttribute("lang");
39+
}

cmp/compiler/tests/helpers/setup-fixture.ts

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path";
44
import { exec, spawn, ChildProcess } from "child_process";
55
import { promisify } from "util";
66
import { verifyFixtureIntegrity } from "./fixture-integrity.js";
7+
import * as os from "node:os";
78

89
const execAsync = promisify(exec);
910

@@ -72,21 +73,6 @@ function killProcessTree(proc: ChildProcess): void {
7273
}
7374
}
7475

75-
// TODO (AleksandrSl 16/12/2025): Could we use helpers from src?
76-
async function isPortInUse(port: number): Promise<boolean> {
77-
try {
78-
const response = await fetch(`http://localhost:${port}`);
79-
return true; // If we get any response, port is in use
80-
} catch (e: any) {
81-
// ECONNREFUSED means port is not in use
82-
if (e.code === "ECONNREFUSED") {
83-
return false;
84-
}
85-
// Other errors might mean port is in use but not responding
86-
return true;
87-
}
88-
}
89-
9076
export type Framework = "next" | "vite";
9177

9278
export interface TestFixtureOptions {
@@ -164,20 +150,12 @@ export async function setupFixture(
164150
// Both Next.js and Vite are configured to use port 3000 in the demo apps
165151
const port = 3000;
166152

167-
// Check if port is already in use
168-
if (await isPortInUse(port)) {
169-
throw new Error(
170-
`Port ${port} is already in use. Please free it before starting dev server.`,
171-
);
172-
}
173-
174153
console.log(`Starting dev server for ${framework} on port ${port}...`);
175-
176-
const isWindows = process.platform === "win32";
154+
const isWindows = os.platform() === "win32";
177155
const devProcess = spawn(isWindows ? "pnpm.cmd" : "pnpm", ["dev"], {
178156
cwd: fixturePath,
179157
stdio: "pipe",
180-
shell: true,
158+
shell: isWindows,
181159
detached: !isWindows, // Use process groups on Unix
182160
});
183161

@@ -265,22 +243,13 @@ export async function setupFixture(
265243
async startProduction(): Promise<ProdServer> {
266244
const port = framework === "next" ? 3000 : 4173;
267245

268-
// Check if port is already in use
269-
if (await isPortInUse(port)) {
270-
throw new Error(
271-
`Port ${port} is already in use. Please free it before starting production server.`,
272-
);
273-
}
274-
275-
console.log(
276-
`Starting production server for ${framework} on port ${port}...`,
277-
);
246+
console.log(`Starting production server for ${framework}...`);
278247

279-
const isWindows = process.platform === "win32";
248+
const isWindows = os.platform() === "win32";
280249
const prodProcess = spawn(isWindows ? "pnpm.cmd" : "pnpm", ["start"], {
281250
cwd: fixturePath,
282251
stdio: "pipe",
283-
shell: true,
252+
shell: isWindows,
284253
detached: !isWindows,
285254
});
286255

cmp/demo/vite-react-spa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@vitejs/plugin-react": "^5.0.4",
3030
"jsdom": "^27.0.0",
3131
"typescript": "^5.7.2",
32-
"vite": "^7.1.7",
32+
"vite": "^7.3.0",
3333
"web-vitals": "^5.1.0"
3434
}
3535
}

cmp/demo/vite-react-spa/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export default defineConfig({
2929
viteReact(),
3030
tailwindcss(),
3131
],
32+
optimizeDeps: {
33+
exclude: ["@lingo.dev/compiler"],
34+
},
3235
resolve: {
3336
alias: {
3437
"@": fileURLToPath(new URL("./src", import.meta.url)),

0 commit comments

Comments
 (0)