Skip to content

Commit e708ec4

Browse files
authored
fix: esbuild plugins not matching windows paths (#695)
* fix: esbuild plugins not matching windows paths * run biome
1 parent 8530f7c commit e708ec4

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

.changeset/thirty-donuts-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Fix esbuild edge plugins not matching Windows paths.

packages/open-next/src/plugins/edge.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function openNextEdgePlugins({
5858
logger.debug(chalk.blue("OpenNext Edge plugin"));
5959
if (edgeFunctionHandlerPath) {
6060
// If we bundle the routing, we need to resolve the middleware
61-
build.onResolve({ filter: /\.\/middleware.mjs/g }, () => {
61+
build.onResolve({ filter: /\.(\/|\\)middleware.mjs/g }, () => {
6262
return {
6363
path: edgeFunctionHandlerPath,
6464
};
@@ -93,9 +93,11 @@ export function openNextEdgePlugins({
9393
);
9494

9595
// We inject the entry files into the edgeFunctionHandler
96-
build.onLoad({ filter: /\/edgeFunctionHandler.js/g }, async (args) => {
97-
let contents = readFileSync(args.path, "utf-8");
98-
contents = `
96+
build.onLoad(
97+
{ filter: /(\/|\\)edgeFunctionHandler.js/g },
98+
async (args) => {
99+
let contents = readFileSync(args.path, "utf-8");
100+
contents = `
99101
globalThis._ENTRIES = {};
100102
globalThis.self = globalThis;
101103
globalThis._ROUTES = ${JSON.stringify(routes)};
@@ -155,24 +157,27 @@ ${wasmFiles
155157
${entryFiles.map((file) => `require("${file}");`).join("\n")}
156158
${contents}
157159
`;
158-
return {
159-
contents,
160-
};
161-
});
160+
return {
161+
contents,
162+
};
163+
},
164+
);
162165

163-
build.onLoad({ filter: /adapters\/config\/index/g }, async () => {
164-
const NextConfig = loadConfig(nextDir);
165-
const BuildId = loadBuildId(nextDir);
166-
const HtmlPages = loadHtmlPages(nextDir);
167-
const RoutesManifest = loadRoutesManifest(nextDir);
168-
const ConfigHeaders = loadConfigHeaders(nextDir);
169-
const PrerenderManifest = loadPrerenderManifest(nextDir);
170-
const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
171-
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
172-
const AppPathsManifest = loadAppPathsManifest(nextDir);
173-
const AppPathRoutesManifest = loadAppPathRoutesManifest(nextDir);
174-
175-
const contents = `
166+
build.onLoad(
167+
{ filter: /adapters(\/|\\)config(\/|\\)index/g },
168+
async () => {
169+
const NextConfig = loadConfig(nextDir);
170+
const BuildId = loadBuildId(nextDir);
171+
const HtmlPages = loadHtmlPages(nextDir);
172+
const RoutesManifest = loadRoutesManifest(nextDir);
173+
const ConfigHeaders = loadConfigHeaders(nextDir);
174+
const PrerenderManifest = loadPrerenderManifest(nextDir);
175+
const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
176+
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
177+
const AppPathsManifest = loadAppPathsManifest(nextDir);
178+
const AppPathRoutesManifest = loadAppPathRoutesManifest(nextDir);
179+
180+
const contents = `
176181
import path from "node:path";
177182
178183
import { debug } from "../logger";
@@ -198,8 +203,9 @@ ${contents}
198203
199204
process.env.NEXT_BUILD_ID = BuildId;
200205
`;
201-
return { contents };
202-
});
206+
return { contents };
207+
},
208+
);
203209
},
204210
};
205211
}

packages/open-next/src/plugins/replacement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const importPattern = /\/\/#import([\s\S]*?)\n\/\/#endImport/gm;
1818
/**
1919
*
2020
* openNextPlugin({
21-
* target: /plugins\/default\.js/g,
21+
* target: /plugins(\/|\\)default\.js/g,
2222
* replacements: [require.resolve("./plugins/default.js")],
2323
* deletes: ["id1"],
2424
* })

0 commit comments

Comments
 (0)