@@ -334,6 +334,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
334334 @override
335335 List <Source > get outputs => const < Source > [
336336 Source .pattern ('{OUTPUT_DIR}/main.dart.wasm' ),
337+ Source .pattern ('{OUTPUT_DIR}/main.dart.mjs' ),
337338 ];
338339
339340 // TODO(jacksongardner): override `depfiles` once dart2wasm begins producing
@@ -348,7 +349,9 @@ class WebReleaseBundle extends Target {
348349 final WebRendererMode webRenderer;
349350 final bool isWasm;
350351
351- String get outputFileName => isWasm ? 'main.dart.wasm' : 'main.dart.js' ;
352+ String get outputFileNameNoSuffix => 'main.dart' ;
353+ String get outputFileName => '$outputFileNameNoSuffix ${isWasm ? '.wasm' : '.js' }' ;
354+ String get wasmJSRuntimeFileName => '$outputFileNameNoSuffix .mjs' ;
352355
353356 @override
354357 String get name => 'web_release_bundle' ;
@@ -362,11 +365,13 @@ class WebReleaseBundle extends Target {
362365 List <Source > get inputs => < Source > [
363366 Source .pattern ('{BUILD_DIR}/$outputFileName ' ),
364367 const Source .pattern ('{PROJECT_DIR}/pubspec.yaml' ),
368+ if (isWasm) Source .pattern ('{BUILD_DIR}/$wasmJSRuntimeFileName ' ),
365369 ];
366370
367371 @override
368372 List <Source > get outputs => < Source > [
369373 Source .pattern ('{OUTPUT_DIR}/$outputFileName ' ),
374+ if (isWasm) Source .pattern ('{OUTPUT_DIR}/$wasmJSRuntimeFileName ' ),
370375 ];
371376
372377 @override
@@ -376,20 +381,20 @@ class WebReleaseBundle extends Target {
376381 'web_resources.d' ,
377382 ];
378383
384+ bool shouldCopy (String name) =>
385+ // Do not copy the deps file.
386+ (name.contains (outputFileName) && ! name.endsWith ('.deps' )) ||
387+ (isWasm && name == wasmJSRuntimeFileName);
388+
379389 @override
380390 Future <void > build (Environment environment) async {
381391 for (final File outputFile in environment.buildDir.listSync (recursive: true ).whereType <File >()) {
382392 final String basename = globals.fs.path.basename (outputFile.path);
383- if (! basename.contains (outputFileName)) {
384- continue ;
385- }
386- // Do not copy the deps file.
387- if (basename.endsWith ('.deps' )) {
388- continue ;
393+ if (shouldCopy (basename)) {
394+ outputFile.copySync (
395+ environment.outputDir.childFile (globals.fs.path.basename (outputFile.path)).path
396+ );
389397 }
390- outputFile.copySync (
391- environment.outputDir.childFile (globals.fs.path.basename (outputFile.path)).path
392- );
393398 }
394399
395400 if (isWasm) {
@@ -533,16 +538,6 @@ class WebBuiltInAssets extends Target {
533538 }
534539
535540 if (isWasm) {
536- final String dartSdkPath =
537- globals.artifacts! .getArtifactPath (Artifact .engineDartSdkPath);
538- final File dart2wasmRuntime = fileSystem.directory (dartSdkPath)
539- .childDirectory ('bin' )
540- .childFile ('dart2wasm_runtime.mjs' );
541- final String targetPath = fileSystem.path.join (
542- environment.outputDir.path,
543- 'dart2wasm_runtime.mjs' );
544- dart2wasmRuntime.copySync (targetPath);
545-
546541 final File bootstrapFile = environment.outputDir.childFile ('main.dart.js' );
547542 bootstrapFile.writeAsStringSync (wasm_bootstrap.generateWasmBootstrapFile ());
548543 }
0 commit comments