Skip to content

Commit d0bb93e

Browse files
committed
[windows] Add Windows compatibility for the resolve ESBuild plugin
Previously, the separator for the filter regex was hardcoded to `/` (Unix separator). Now, instead of hardcoding the separator, we are using the cross-platform `path.join` function. It's result is regex escaped using the `escape-string-regexp` library. Signed-off-by: Costin Sin <[email protected]>
1 parent 001aaa0 commit d0bb93e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/open-next/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"chalk": "^5.3.0",
4747
"esbuild": "0.19.2",
4848
"path-to-regexp": "^6.2.1",
49-
"promise.series": "^0.2.0"
49+
"promise.series": "^0.2.0",
50+
"escape-string-regexp": "^5.0.0"
5051
},
5152
"devDependencies": {
5253
"@types/aws-lambda": "^8.10.109",

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type {
1010
} from "types/open-next";
1111

1212
import logger from "../logger.js";
13+
import path from "path";
14+
import escapeStringRegexp from 'escape-string-regexp';
1315

1416
export interface IPluginSettings {
1517
overrides?: {
@@ -44,7 +46,10 @@ export function openNextResolvePlugin({
4446
name: "opennext-resolve",
4547
setup(build) {
4648
logger.debug(`OpenNext Resolve plugin for ${fnName}`);
47-
build.onLoad({ filter: /core\/resolve.js/g }, async (args) => {
49+
const filter = new RegExp(
50+
escapeStringRegexp(path.join("core", "resolve.js"), "g"),
51+
);
52+
build.onLoad({ filter }, async (args) => {
4853
let contents = readFileSync(args.path, "utf-8");
4954
//TODO: refactor this. Every override should be at the same place so we can generate this dynamically
5055
if (overrides?.wrapper) {

0 commit comments

Comments
 (0)