@@ -139,61 +139,62 @@ describe('Angular linker - chunk file linking', () => {
139139 } )
140140} )
141141
142- describe ( 'NODE_MODULES_JS_REGEX filter matching' , ( ) => {
143- // This is the fixed regex from angular-linker-plugin.ts
144- const NODE_MODULES_JS_REGEX = / n o d e _ m o d u l e s [ \\ / ] .* \. [ c m ] ? j s (?: \? .* ) ? $ /
142+ describe ( 'Linker transform filter matching' , ( ) => {
143+ // These mirror the two-stage filter from angular-linker-plugin.ts:
144+ // 1. Broad static filter (NODE_MODULES_JS_REGEX) for Vite's filter mechanism
145+ // 2. Precise handler-level check (JS_EXT_REGEX) inside the transform handler
146+ const NODE_MODULES_JS_REGEX = / n o d e _ m o d u l e s /
147+ const JS_EXT_REGEX = / \. [ c m ] ? j s (?: \? .* ) ? $ /
148+
149+ function matches ( id : string ) {
150+ return NODE_MODULES_JS_REGEX . test ( id ) && JS_EXT_REGEX . test ( id )
151+ }
145152
146153 it ( 'should match standard Angular FESM files' , ( ) => {
147- expect ( NODE_MODULES_JS_REGEX . test ( 'node_modules/@angular/common/fesm2022/common.mjs' ) ) . toBe (
148- true ,
149- )
154+ expect ( matches ( 'node_modules/@angular/common/fesm2022/common.mjs' ) ) . toBe ( true )
150155 } )
151156
152157 it ( 'should match chunk files' , ( ) => {
153- expect (
154- NODE_MODULES_JS_REGEX . test (
155- 'node_modules/@angular/common/fesm2022/_platform_location-chunk.mjs' ,
156- ) ,
157- ) . toBe ( true )
158+ expect ( matches ( 'node_modules/@angular/common/fesm2022/_platform_location-chunk.mjs' ) ) . toBe ( true )
158159 } )
159160
160161 it ( 'should match absolute paths' , ( ) => {
161162 expect (
162- NODE_MODULES_JS_REGEX . test (
163+ matches (
163164 '/Users/dev/project/node_modules/@angular/common/fesm2022/_platform_location-chunk.mjs' ,
164165 ) ,
165166 ) . toBe ( true )
166167 } )
167168
168169 it ( 'should match paths with Vite query strings' , ( ) => {
169- expect (
170- NODE_MODULES_JS_REGEX . test ( 'node_modules/@angular/common/fesm2022/common.mjs?v=abc123' ) ,
171- ) . toBe ( true )
170+ expect ( matches ( 'node_modules/@angular/common/fesm2022/common.mjs?v=abc123' ) ) . toBe ( true )
172171 } )
173172
174173 it ( 'should match chunk files with Vite query strings' , ( ) => {
175174 expect (
176- NODE_MODULES_JS_REGEX . test (
177- 'node_modules/@angular/common/fesm2022/_platform_location-chunk.mjs?v=df7b0864' ,
178- ) ,
175+ matches ( 'node_modules/@angular/common/fesm2022/_platform_location-chunk.mjs?v=df7b0864' ) ,
179176 ) . toBe ( true )
180177 } )
181178
182179 it ( 'should match Windows-style backslash paths' , ( ) => {
183- expect ( NODE_MODULES_JS_REGEX . test ( 'node_modules\\@angular\\common\\fesm2022\\common.mjs' ) ) . toBe (
184- true ,
185- )
180+ expect ( matches ( 'node_modules\\@angular\\common\\fesm2022\\common.mjs' ) ) . toBe ( true )
186181 } )
187182
188183 it ( 'should match .js and .cjs files' , ( ) => {
189- expect ( NODE_MODULES_JS_REGEX . test ( 'node_modules/@ngrx/store/fesm2022/ngrx-store.js' ) ) . toBe ( true )
190- expect ( NODE_MODULES_JS_REGEX . test ( 'node_modules/some-lib/index.cjs' ) ) . toBe ( true )
184+ expect ( matches ( 'node_modules/@ngrx/store/fesm2022/ngrx-store.js' ) ) . toBe ( true )
185+ expect ( matches ( 'node_modules/some-lib/index.cjs' ) ) . toBe ( true )
186+ } )
187+
188+ it ( 'should match PrimeNG files (excluded from optimizeDeps)' , ( ) => {
189+ expect ( matches ( 'node_modules/primeng/fesm2022/primeng-table.mjs' ) ) . toBe ( true )
190+ expect ( matches ( 'node_modules/primeng/fesm2022/primeng-table.mjs?v=abc123' ) ) . toBe ( true )
191191 } )
192192
193193 it ( 'should not match non-JS files' , ( ) => {
194- expect ( NODE_MODULES_JS_REGEX . test ( 'node_modules/@angular/common/fesm2022/common.d.ts' ) ) . toBe (
195- false ,
196- )
197- expect ( NODE_MODULES_JS_REGEX . test ( 'src/app/app.component.ts' ) ) . toBe ( false )
194+ expect ( matches ( 'node_modules/@angular/common/fesm2022/common.d.ts' ) ) . toBe ( false )
195+ } )
196+
197+ it ( 'should not match application source files' , ( ) => {
198+ expect ( matches ( 'src/app/app.component.ts' ) ) . toBe ( false )
198199 } )
199200} )
0 commit comments