@@ -119,6 +119,7 @@ class AngularPolyfillsPlugin {
119
119
static createPlugin (
120
120
polyfillsFile : FilePattern ,
121
121
jasmineCleanupFiles : FilePattern ,
122
+ scriptsFiles : FilePattern [ ] ,
122
123
) : InlinePluginDef {
123
124
return {
124
125
// This has to be a "reporter" because reporters run _after_ frameworks
@@ -161,16 +162,14 @@ class AngularPolyfillsPlugin {
161
162
// page load. `type` won't affect them.
162
163
continue ;
163
164
}
164
- if ( f . pattern === 'scripts.js' ) {
165
- // Don't consider "scripts" option files as module types.
166
- // This should be expanded if custom scripts bundle names support is added.
167
- continue ;
168
- }
169
165
if ( f . pattern . endsWith ( '.js' ) && 'js' === ( f . type ?? 'js' ) ) {
170
166
f . type = 'module' ;
171
167
}
172
168
}
173
169
170
+ // Add "scripts" option files as classic scripts
171
+ files . unshift ( ...scriptsFiles ) ;
172
+
174
173
// Add browser sourcemap support as a classic script
175
174
files . unshift ( {
176
175
pattern : localResolve ( 'source-map-support/browser-source-map-support.js' ) ,
@@ -493,17 +492,28 @@ async function initializeApplication(
493
492
494
493
karmaOptions . basePath = outputPath ;
495
494
496
- karmaOptions . files ?? = [ ] ;
495
+ const scriptsFiles : FilePattern [ ] = [ ] ;
497
496
if ( options . scripts ?. length ) {
498
- // This should be more granular to support named bundles.
499
- // However, it replicates the behavior of the Karma Webpack-based builder.
500
- karmaOptions . files . push ( {
501
- pattern : `scripts.js` ,
502
- watched : false ,
503
- type : 'js' ,
504
- } ) ;
497
+ const outputScripts = new Set < string > ( ) ;
498
+ for ( const scriptEntry of options . scripts ) {
499
+ const outputName =
500
+ typeof scriptEntry === 'string'
501
+ ? 'scripts.js'
502
+ : `${ scriptEntry . bundleName ?? 'scripts' } .js` ;
503
+
504
+ if ( outputScripts . has ( outputName ) ) {
505
+ continue ;
506
+ }
507
+ outputScripts . add ( outputName ) ;
508
+ scriptsFiles . push ( {
509
+ pattern : `${ outputPath } /${ outputName } ` ,
510
+ watched : false ,
511
+ type : 'js' ,
512
+ } ) ;
513
+ }
505
514
}
506
515
516
+ karmaOptions . files ??= [ ] ;
507
517
karmaOptions . files . push (
508
518
// Serve global setup script.
509
519
{ pattern : `${ mainName } .js` , type : 'module' , watched : false } ,
@@ -577,7 +587,7 @@ async function initializeApplication(
577
587
parsedKarmaConfig . middleware . push ( AngularAssetsMiddleware . NAME ) ;
578
588
579
589
parsedKarmaConfig . plugins . push (
580
- AngularPolyfillsPlugin . createPlugin ( polyfillsFile , jasmineCleanupFiles ) ,
590
+ AngularPolyfillsPlugin . createPlugin ( polyfillsFile , jasmineCleanupFiles , scriptsFiles ) ,
581
591
) ;
582
592
parsedKarmaConfig . reporters ??= [ ] ;
583
593
parsedKarmaConfig . reporters . push ( AngularPolyfillsPlugin . NAME ) ;
0 commit comments