From 5b59e2200b71f19590fee7e1aa7c6ba017bbfc97 Mon Sep 17 00:00:00 2001 From: Leonardo Ortiz Date: Tue, 13 Aug 2024 14:51:12 -0300 Subject: [PATCH] fix esbuild path used to bundle next.config.js on Windows (#7555) * use path from npx which to run esbuild * fix test * prevent findEsbuildPath to throw when npx which returns undefined * prevent throw when version not found in getGlobalEsbuildVersion * changelog --- CHANGELOG.md | 1 + src/frameworks/next/utils.spec.ts | 7 +++++-- src/frameworks/next/utils.ts | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..623b1d6ea68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fix esbuild path used to bundle next.config.js on Windows (#7555) diff --git a/src/frameworks/next/utils.spec.ts b/src/frameworks/next/utils.spec.ts index 158b3d7d7cb..f82713bd8ed 100644 --- a/src/frameworks/next/utils.spec.ts +++ b/src/frameworks/next/utils.spec.ts @@ -573,17 +573,20 @@ describe("Next.js utils", () => { it("should warn if global esbuild version does not match required version", () => { const mockBinaryPath = "/path/to/.bin/esbuild"; + const mockGlobalVersion = "1.2.3"; execSyncStub .withArgs("npx which esbuild", { encoding: "utf8" }) .returns(mockBinaryPath + "\n"); - execSyncStub.withArgs("esbuild --version", { encoding: "utf8" }).returns("0.18.0\n"); + execSyncStub + .withArgs(`${mockBinaryPath} --version`, { encoding: "utf8" }) + .returns(`${mockGlobalVersion}\n`); const consoleWarnStub = sinon.stub(console, "warn"); findEsbuildPath(); expect( consoleWarnStub.calledWith( - `Warning: Global esbuild version (0.18.0) does not match the required version (${ESBUILD_VERSION}).`, + `Warning: Global esbuild version (${mockGlobalVersion}) does not match the required version (${ESBUILD_VERSION}).`, ), ).to.be.true; diff --git a/src/frameworks/next/utils.ts b/src/frameworks/next/utils.ts index fdb99381ecd..2ead4fb8d30 100644 --- a/src/frameworks/next/utils.ts +++ b/src/frameworks/next/utils.ts @@ -498,8 +498,12 @@ export async function whichNextConfigFile(dir: string): Promise