From 409e4ad98481c598d3702cca59a7ca90ebc468b9 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Sun, 24 Nov 2024 19:49:41 +0100 Subject: [PATCH] fix: resolve variable --- src/plugins/esm-shim.test.ts | 1 + src/plugins/esm-shim.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/esm-shim.test.ts b/src/plugins/esm-shim.test.ts index ae0c741b..6c3bcb64 100644 --- a/src/plugins/esm-shim.test.ts +++ b/src/plugins/esm-shim.test.ts @@ -7,6 +7,7 @@ describe('require regex', () => { expect(match('require(\n"foo"\n)')).toBe(true) expect(match(`require(\`mod\`)`)).toBe(true) expect(match(`require.resolve('mod')`)).toBe(true) + expect(match(`\nrequire.resolve(value)`)).toBe(true) expect(match('foo.require("foo")')).toBe(false) expect(match(`"require('module')"`)).toBe(false) diff --git a/src/plugins/esm-shim.ts b/src/plugins/esm-shim.ts index a1d316bc..8c0f478f 100644 --- a/src/plugins/esm-shim.ts +++ b/src/plugins/esm-shim.ts @@ -7,7 +7,7 @@ const FILENAME_REGEX = /__filename/ const DIRNAME_REGEX = /__dirname/ // not char, or space before require(.resolve)?( export const GLOBAL_REQUIRE_REGEX = - /(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(['"`])/ + /(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(\w|['"`])/ const PolyfillComment = '/** rollup-private-do-not-use-esm-shim-polyfill */' const createESMShim = ({