Skip to content

Commit ebc0f74

Browse files
authored
fix(e2e): Update nextjs version detection logic to work with tags (#7090)
1 parent fb49d29 commit ebc0f74

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

integration/tests/middleware-placement.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,31 @@ function parseSemverMajor(range?: string): number | undefined {
1515
return match ? Number.parseInt(match[0], 10) : undefined;
1616
}
1717

18-
async function detectNext(app: Application): Promise<{ isNext: boolean; version?: string }> {
18+
/**
19+
* Detects the installed Next.js version for a given application.
20+
* Reads the version from node_modules/next/package.json to ensure
21+
* we get the actual installed version rather than a tag like "latest" or "canary".
22+
*/
23+
async function detectNext(app: Application): Promise<{ version: string | undefined | null }> {
1924
// app.appDir exists for normal Application; for long-running apps, read it from the state file by serverUrl
2025
const appDir =
2126
(app as any).appDir ||
2227
Object.values(stateFile.getLongRunningApps() || {}).find(a => a.serverUrl === app.serverUrl)?.appDir;
2328

2429
if (!appDir) {
25-
return { isNext: false };
30+
return { version: null };
2631
}
2732

28-
const pkg = await fs.readJSON(path.join(appDir, 'package.json'));
29-
const nextRange: string | undefined = pkg.dependencies?.next || pkg.devDependencies?.next;
33+
let installedVersion: string | undefined;
34+
try {
35+
const nextPkg = await fs.readJSON(path.join(appDir, 'node_modules', 'next', 'package.json'));
36+
installedVersion = String(nextPkg?.version || '');
37+
} catch {
38+
// ignore
39+
}
3040

31-
return { isNext: Boolean(nextRange), version: nextRange };
41+
console.log('---detectNext---', installedVersion);
42+
return { version: installedVersion };
3243
}
3344

3445
const middlewareFileContents = `

0 commit comments

Comments
 (0)