From 1203622af9e8b588e098eea4f8b8707fefe2571a Mon Sep 17 00:00:00 2001 From: luhc228 Date: Thu, 28 Mar 2024 10:23:26 +0800 Subject: [PATCH] fix: not compile some deps (#641) --- packages/pkg/src/utils.ts | 2 +- packages/pkg/tests/createScriptsFilter.test.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/pkg/src/utils.ts b/packages/pkg/src/utils.ts index 7216c1a5..83389b24 100644 --- a/packages/pkg/src/utils.ts +++ b/packages/pkg/src/utils.ts @@ -303,7 +303,7 @@ export function getIncludeNodeModuleScripts(compileDependencies: boolean | Array // will not match: // node_modules/abc/node_modules/def/index.js // node_modules/def/index.js - return [new RegExp(`node_modules/(${compileDependencies.map((dep: string | RegExp) => (`${typeof dep === 'string' ? dep : dep.source}`)).join('|')})/(?!node_modules/)[^\\/]+.(?:[cm]?[jt]s|[jt]sx)$`)]; + return [new RegExp(`node_modules/(${compileDependencies.map((dep: string | RegExp) => (`${typeof dep === 'string' ? dep : dep.source}`)).join('|')})/(?!node_modules/).*.(?:[cm]?[jt]s|[jt]sx)$`)]; } // default return []; diff --git a/packages/pkg/tests/createScriptsFilter.test.ts b/packages/pkg/tests/createScriptsFilter.test.ts index 168ee2cc..de6555cb 100644 --- a/packages/pkg/tests/createScriptsFilter.test.ts +++ b/packages/pkg/tests/createScriptsFilter.test.ts @@ -62,12 +62,14 @@ test('createScriptsFilter with some compileDependencies', async () => { expect(scriptsFilter('/w/node_modules/@ice/runtime/node_modules/@ice/app/a.js')).toBe(true); expect(scriptsFilter('/w/node_modules/@ice/app/node_modules/rax-compat/index.js')).toBe(false); expect(scriptsFilter('/w/node_modules/lodash/node_modules/rax-compat/index.js')).toBe(false); + expect(scriptsFilter('/w/node_modules/lodash/node_modules/rax-compat/dist/index.js')).toBe(false); // Windows path expect(scriptsFilter('C:\\w\\node_modules\\lodash\\a.js')).toBe(true); expect(scriptsFilter('C:\\w\\node_modules\\@ice\\app\\a.js')).toBe(true); expect(scriptsFilter('C:\\w\\node_modules\\@ice\\runtime\\node_modules\\lodash\\a.js')).toBe(true); expect(scriptsFilter('C:\\w\\node_modules\\@ice\\runtime\\node_modules\\@ice\\app\\a.js')).toBe(true); expect(scriptsFilter('C:\\w\\node_modules\\@ice\\app\\node_modules\\rax-compat\\index.js')).toBe(false); + expect(scriptsFilter('C:\\w\\node_modules\\@ice\\app\\node_modules\\rax-compat\\dist\\index.js')).toBe(false); // default exclude some deps expect(scriptsFilter('/w/node_modules/@babel/runtime/a.js')).toBe(false);