From d2cc9780e7c29f5bfb9ee883e3e015e40bc5ff7b Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 1 Sep 2026 06:28:59 +0200 Subject: [PATCH] test: launch QA standalone server as CommonJS --- scripts/release-v2-qa/runtime.mts | 6 +++++- scripts/release-v2-qa/runtime.spec.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/release-v2-qa/runtime.mts b/scripts/release-v2-qa/runtime.mts index ced370bfb..c7ef013f7 100644 --- a/scripts/release-v2-qa/runtime.mts +++ b/scripts/release-v2-qa/runtime.mts @@ -90,7 +90,8 @@ export const createCandidateBuildPaths = (candidateSha: string) => { buildDir, standaloneRoot, standaloneAppDir, - serverPath: path.join(standaloneAppDir, "server.js"), + generatedServerPath: path.join(standaloneAppDir, "server.js"), + serverPath: path.join(standaloneAppDir, "server.cjs"), markerPath: path.join(buildDir, "qa-build-manifest.json"), }; }; @@ -431,6 +432,9 @@ const ensureCandidateBuild = async (runRoot: string, candidateSha: string) => { await mkdir(path.dirname(staticTarget), { recursive: true }); await cp(path.join(buildPaths.buildDir, "static"), staticTarget, { recursive: true, force: true }); await cp(path.join(buildPaths.appRoot, "public"), publicTarget, { recursive: true, force: true }); + // The app package is ESM, while Next emits a CommonJS standalone launcher. + // Give the generated launcher an explicit CommonJS extension before executing it. + await rename(buildPaths.generatedServerPath, buildPaths.serverPath); const serverStats = await stat(buildPaths.serverPath); if (!serverStats.isFile()) throw new Error(`Standalone server is missing after build: ${buildPaths.serverPath}`); await writeJsonAtomic(buildPaths.markerPath, { diff --git a/scripts/release-v2-qa/runtime.spec.ts b/scripts/release-v2-qa/runtime.spec.ts index 1986852b7..d877e3c72 100644 --- a/scripts/release-v2-qa/runtime.spec.ts +++ b/scripts/release-v2-qa/runtime.spec.ts @@ -139,7 +139,8 @@ describe("release-v2 QA app execution contract", () => { const paths = createCandidateBuildPaths("0123456789abcdef0123456789abcdef01234567"); expect(paths.distDirName).toBe(".next-qa/release-v2-0123456789abcdef0123456789abcdef01234567"); - expect(paths.serverPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.js`); + expect(paths.generatedServerPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.js`); + expect(paths.serverPath).toBe(`${paths.buildDir}/standalone/apps/nextjs/server.cjs`); expect(paths.standaloneRoot).toBe(`${paths.buildDir}/standalone`); expect(() => createCandidateBuildPaths("not-a-commit")).toThrow(/40-character lowercase commit SHA/u); });