@@ -93,7 +93,6 @@ class WebEntrypointTarget extends Target {
93
93
}
94
94
}
95
95
96
- /// Compiles a web entry point with dart2js.
97
96
abstract class Dart2WebTarget extends Target {
98
97
const Dart2WebTarget ();
99
98
@@ -102,7 +101,8 @@ abstract class Dart2WebTarget extends Target {
102
101
WebCompilerConfig get compilerConfig;
103
102
104
103
Map <String , Object ?> get buildConfig;
105
- List <String > get buildFiles;
104
+ Iterable <File > buildFiles (Environment environment);
105
+ Iterable <String > get buildPatternStems;
106
106
107
107
@override
108
108
List <Target > get dependencies => const < Target > [
@@ -120,14 +120,15 @@ abstract class Dart2WebTarget extends Target {
120
120
];
121
121
122
122
@override
123
- List <Source > get outputs => buildFiles. map (
124
- ( String file) => Source .pattern ('{BUILD_DIR}/$file ' )
125
- ). toList () ;
123
+ List <Source > get outputs => < Source > [
124
+ for ( final String stem in buildPatternStems) Source .pattern ('{BUILD_DIR}/$stem ' ),
125
+ ] ;
126
126
127
127
@override
128
128
String get buildKey => compilerConfig.buildKey;
129
129
}
130
130
131
+ /// Compiles a web entry point with dart2js.
131
132
class Dart2JSTarget extends Dart2WebTarget {
132
133
Dart2JSTarget (this .compilerConfig);
133
134
@@ -230,12 +231,43 @@ class Dart2JSTarget extends Dart2WebTarget {
230
231
};
231
232
232
233
@override
233
- List <String > get buildFiles => < String > [
234
+ Iterable <File > buildFiles (Environment environment)
235
+ => environment.buildDir
236
+ .listSync (recursive: true )
237
+ .whereType <File >()
238
+ .where ((File file) {
239
+ if (file.basename == 'main.dart.js' ) {
240
+ return true ;
241
+ }
242
+ if (file.basename == 'main.dart.js.map' ) {
243
+ return compilerConfig.sourceMaps;
244
+ }
245
+ final RegExp partFileRegex = RegExp (r'main\.dart\.js_[0-9].*\.part\.js' );
246
+ if (partFileRegex.hasMatch (file.basename)) {
247
+ return true ;
248
+ }
249
+
250
+ if (compilerConfig.sourceMaps) {
251
+ final RegExp partFileSourceMapRegex = RegExp (r'main\.dart\.js_[0-9].*.part\.js\.map' );
252
+ if (partFileSourceMapRegex.hasMatch (file.basename)) {
253
+ return true ;
254
+ }
255
+ }
256
+ return false ;
257
+ });
258
+
259
+ @override
260
+ Iterable <String > get buildPatternStems => < String > [
234
261
'main.dart.js' ,
235
- if (compilerConfig.sourceMaps) 'main.dart.js.map' ,
262
+ 'main.dart.js_*.part.js' ,
263
+ if (compilerConfig.sourceMaps) ...< String > [
264
+ 'main.dart.js.map' ,
265
+ 'main.dart.js_*.part.js.map' ,
266
+ ],
236
267
];
237
268
}
238
269
270
+ /// Compiles a web entry point with dart2wasm.
239
271
class Dart2WasmTarget extends Dart2WebTarget {
240
272
Dart2WasmTarget (this .compilerConfig);
241
273
@@ -273,7 +305,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
273
305
if (compilerConfig.renderer == WebRendererMode .skwasm) ...< String > [
274
306
'--extra-compiler-option=--import-shared-memory' ,
275
307
'--extra-compiler-option=--shared-memory-max-pages=32768' ,
276
- ],
308
+ ],
277
309
if (buildMode == BuildMode .profile)
278
310
'-Ddart.vm.profile=true'
279
311
else
@@ -320,7 +352,17 @@ class Dart2WasmTarget extends Dart2WebTarget {
320
352
};
321
353
322
354
@override
323
- List <String > get buildFiles => < String > [
355
+ Iterable <File > buildFiles (Environment environment)
356
+ => environment.buildDir
357
+ .listSync (recursive: true )
358
+ .whereType <File >()
359
+ .where ((File file) => switch (file.basename) {
360
+ 'main.dart.wasm' || 'main.dart.mjs' => true ,
361
+ _ => false ,
362
+ });
363
+
364
+ @override
365
+ Iterable <String > get buildPatternStems => const < String > [
324
366
'main.dart.wasm' ,
325
367
'main.dart.mjs' ,
326
368
];
@@ -361,11 +403,6 @@ _flutter.buildConfig = ${jsonEncode(buildConfig)};
361
403
final List <Dart2WebTarget > compileTargets;
362
404
final WebTemplatedFiles templatedFilesTarget;
363
405
364
- List <String > get buildFiles => compileTargets.fold (
365
- const Iterable <String >.empty (),
366
- (Iterable <String > current, Dart2WebTarget target) => current.followedBy (target.buildFiles)
367
- ).toList ();
368
-
369
406
@override
370
407
String get name => 'web_release_bundle' ;
371
408
@@ -375,15 +412,19 @@ _flutter.buildConfig = ${jsonEncode(buildConfig)};
375
412
templatedFilesTarget,
376
413
];
377
414
415
+ Iterable <String > get buildPatternStems => compileTargets.expand (
416
+ (Dart2WebTarget target) => target.buildPatternStems,
417
+ );
418
+
378
419
@override
379
420
List <Source > get inputs => < Source > [
380
421
const Source .pattern ('{PROJECT_DIR}/pubspec.yaml' ),
381
- ...buildFiles .map ((String file) => Source .pattern ('{BUILD_DIR}/$file ' ))
422
+ ...buildPatternStems .map ((String file) => Source .pattern ('{BUILD_DIR}/$file ' ))
382
423
];
383
424
384
425
@override
385
426
List <Source > get outputs => < Source > [
386
- ...buildFiles .map ((String file) => Source .pattern ('{OUTPUT_DIR}/$file ' ))
427
+ ...buildPatternStems .map ((String file) => Source .pattern ('{OUTPUT_DIR}/$file ' ))
387
428
];
388
429
389
430
@override
@@ -395,9 +436,8 @@ _flutter.buildConfig = ${jsonEncode(buildConfig)};
395
436
@override
396
437
Future <void > build (Environment environment) async {
397
438
final FileSystem fileSystem = environment.fileSystem;
398
- for (final File outputFile in environment.buildDir.listSync (recursive: true ).whereType <File >()) {
399
- final String basename = fileSystem.path.basename (outputFile.path);
400
- if (buildFiles.contains (basename)) {
439
+ for (final Dart2WebTarget target in compileTargets) {
440
+ for (final File outputFile in target.buildFiles (environment)) {
401
441
outputFile.copySync (
402
442
environment.outputDir.childFile (fileSystem.path.basename (outputFile.path)).path
403
443
);
0 commit comments