Skip to content

fix: esbuild plugins not matching windows paths #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-donuts-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

Fix esbuild edge plugins not matching Windows paths.
52 changes: 29 additions & 23 deletions packages/open-next/src/plugins/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function openNextEdgePlugins({
logger.debug(chalk.blue("OpenNext Edge plugin"));
if (edgeFunctionHandlerPath) {
// If we bundle the routing, we need to resolve the middleware
build.onResolve({ filter: /\.\/middleware.mjs/g }, () => {
build.onResolve({ filter: /\.(\/|\\)middleware.mjs/g }, () => {
return {
path: edgeFunctionHandlerPath,
};
Expand Down Expand Up @@ -93,9 +93,11 @@ export function openNextEdgePlugins({
);

// We inject the entry files into the edgeFunctionHandler
build.onLoad({ filter: /\/edgeFunctionHandler.js/g }, async (args) => {
let contents = readFileSync(args.path, "utf-8");
contents = `
build.onLoad(
{ filter: /(\/|\\)edgeFunctionHandler.js/g },
async (args) => {
let contents = readFileSync(args.path, "utf-8");
contents = `
globalThis._ENTRIES = {};
globalThis.self = globalThis;
globalThis._ROUTES = ${JSON.stringify(routes)};
Expand Down Expand Up @@ -155,24 +157,27 @@ ${wasmFiles
${entryFiles.map((file) => `require("${file}");`).join("\n")}
${contents}
`;
return {
contents,
};
});
return {
contents,
};
},
);

build.onLoad({ filter: /adapters\/config\/index/g }, async () => {
const NextConfig = loadConfig(nextDir);
const BuildId = loadBuildId(nextDir);
const HtmlPages = loadHtmlPages(nextDir);
const RoutesManifest = loadRoutesManifest(nextDir);
const ConfigHeaders = loadConfigHeaders(nextDir);
const PrerenderManifest = loadPrerenderManifest(nextDir);
const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
const AppPathsManifest = loadAppPathsManifest(nextDir);
const AppPathRoutesManifest = loadAppPathRoutesManifest(nextDir);

const contents = `
build.onLoad(
{ filter: /adapters(\/|\\)config(\/|\\)index/g },
async () => {
const NextConfig = loadConfig(nextDir);
const BuildId = loadBuildId(nextDir);
const HtmlPages = loadHtmlPages(nextDir);
const RoutesManifest = loadRoutesManifest(nextDir);
const ConfigHeaders = loadConfigHeaders(nextDir);
const PrerenderManifest = loadPrerenderManifest(nextDir);
const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
const MiddlewareManifest = loadMiddlewareManifest(nextDir);
const AppPathsManifest = loadAppPathsManifest(nextDir);
const AppPathRoutesManifest = loadAppPathRoutesManifest(nextDir);

const contents = `
import path from "node:path";

import { debug } from "../logger";
Expand All @@ -198,8 +203,9 @@ ${contents}

process.env.NEXT_BUILD_ID = BuildId;
`;
return { contents };
});
return { contents };
},
);
},
};
}
2 changes: 1 addition & 1 deletion packages/open-next/src/plugins/replacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const importPattern = /\/\/#import([\s\S]*?)\n\/\/#endImport/gm;
/**
*
* openNextPlugin({
* target: /plugins\/default\.js/g,
* target: /plugins(\/|\\)default\.js/g,
* replacements: [require.resolve("./plugins/default.js")],
* deletes: ["id1"],
* })
Expand Down
Loading