Skip to content

Commit

Permalink
Revert "Revert "[web] Move JS content to its own .js files (#117691…
Browse files Browse the repository at this point in the history
…)" (#120275)" (#120363)

This reverts commit 0fb4406.
  • Loading branch information
mdebbar authored Feb 10, 2023
1 parent 65fd924 commit d5dbcb7
Show file tree
Hide file tree
Showing 9 changed files with 667 additions and 568 deletions.
39 changes: 39 additions & 0 deletions packages/flutter_tools/lib/src/artifacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'base/common.dart';
import 'base/file_system.dart';
import 'base/os.dart';
import 'base/platform.dart';
import 'base/user_messages.dart';
import 'base/utils.dart';
import 'build_info.dart';
import 'cache.dart';
Expand Down Expand Up @@ -62,6 +63,9 @@ enum Artifact {
/// Tools related to subsetting or icon font files.
fontSubset,
constFinder,

/// The location of file generators.
flutterToolsFileGenerators,
}

/// A subset of [Artifact]s that are platform and build mode independent
Expand Down Expand Up @@ -202,6 +206,8 @@ String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [ BuildMod
return 'font-subset$exe';
case Artifact.constFinder:
return 'const_finder.dart.snapshot';
case Artifact.flutterToolsFileGenerators:
return '';
}
}

Expand Down Expand Up @@ -525,6 +531,8 @@ class CachedArtifacts implements Artifacts {
case Artifact.windowsCppClientWrapper:
case Artifact.windowsDesktopPath:
return _getHostArtifactPath(artifact, platform, mode);
case Artifact.flutterToolsFileGenerators:
return _getFileGeneratorsPath();
}
}

Expand Down Expand Up @@ -562,6 +570,8 @@ class CachedArtifacts implements Artifacts {
case Artifact.windowsCppClientWrapper:
case Artifact.windowsDesktopPath:
return _getHostArtifactPath(artifact, platform, mode);
case Artifact.flutterToolsFileGenerators:
return _getFileGeneratorsPath();
}
}

Expand Down Expand Up @@ -611,6 +621,8 @@ class CachedArtifacts implements Artifacts {
case Artifact.windowsCppClientWrapper:
case Artifact.windowsDesktopPath:
return _getHostArtifactPath(artifact, platform, mode);
case Artifact.flutterToolsFileGenerators:
return _getFileGeneratorsPath();
}
}

Expand Down Expand Up @@ -685,6 +697,8 @@ class CachedArtifacts implements Artifacts {
case Artifact.fuchsiaFlutterRunner:
case Artifact.fuchsiaKernelCompiler:
throw StateError('Artifact $artifact not available for platform $platform.');
case Artifact.flutterToolsFileGenerators:
return _getFileGeneratorsPath();
}
}

Expand Down Expand Up @@ -952,6 +966,8 @@ class CachedLocalEngineArtifacts implements Artifacts {
case Artifact.dart2wasmSnapshot:
case Artifact.frontendServerSnapshotForEngineDartSdk:
return _fileSystem.path.join(_getDartSdkPath(), 'bin', 'snapshots', artifactFileName);
case Artifact.flutterToolsFileGenerators:
return _getFileGeneratorsPath();
}
}

Expand Down Expand Up @@ -1099,6 +1115,7 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
case Artifact.fuchsiaFlutterRunner:
case Artifact.fontSubset:
case Artifact.constFinder:
case Artifact.flutterToolsFileGenerators:
break;
}
}
Expand Down Expand Up @@ -1298,6 +1315,11 @@ class _TestArtifacts implements Artifacts {
BuildMode? mode,
EnvironmentType? environmentType,
}) {
// The path to file generators is the same even in the test environment.
if (artifact == Artifact.flutterToolsFileGenerators) {
return _getFileGeneratorsPath();
}

final StringBuffer buffer = StringBuffer();
buffer.write(artifact);
if (platform != null) {
Expand Down Expand Up @@ -1340,3 +1362,20 @@ class _TestLocalEngine extends _TestArtifacts {
@override
final LocalEngineInfo localEngineInfo;
}

String _getFileGeneratorsPath() {
final String flutterRoot = Cache.defaultFlutterRoot(
fileSystem: globals.localFileSystem,
platform: const LocalPlatform(),
userMessages: UserMessages(),
);
return globals.localFileSystem.path.join(
flutterRoot,
'packages',
'flutter_tools',
'lib',
'src',
'web',
'file_generators',
);
}
8 changes: 7 additions & 1 deletion packages/flutter_tools/lib/src/build_system/targets/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,10 @@ class WebBuiltInAssets extends Target {

// Write the flutter.js file
final File flutterJsFile = environment.outputDir.childFile('flutter.js');
flutterJsFile.writeAsStringSync(flutter_js.generateFlutterJsFile());
final String fileGeneratorsPath =
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
flutterJsFile.writeAsStringSync(
flutter_js.generateFlutterJsFile(fileGeneratorsPath));
}
}

Expand Down Expand Up @@ -598,7 +601,10 @@ class WebServiceWorker extends Target {
final ServiceWorkerStrategy serviceWorkerStrategy = _serviceWorkerStrategyFromString(
environment.defines[kServiceWorkerStrategy],
);
final String fileGeneratorsPath =
globals.artifacts!.getArtifactPath(Artifact.flutterToolsFileGenerators);
final String serviceWorker = generateServiceWorker(
fileGeneratorsPath,
urlToHash,
<String>[
'main.dart.js',
Expand Down
5 changes: 4 additions & 1 deletion packages/flutter_tools/lib/src/isolated/devfs_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,10 @@ class WebDevFS implements DevFS {
'stack_trace_mapper.js', stackTraceMapper.readAsBytesSync());
webAssetServer.writeFile(
'manifest.json', '{"info":"manifest not generated in run mode."}');
webAssetServer.writeFile('flutter.js', flutter_js.generateFlutterJsFile());
final String fileGeneratorsPath = globals.artifacts!
.getArtifactPath(Artifact.flutterToolsFileGenerators);
webAssetServer.writeFile(
'flutter.js', flutter_js.generateFlutterJsFile(fileGeneratorsPath));
webAssetServer.writeFile('flutter_service_worker.js',
'// Service worker not loaded in run mode.');
webAssetServer.writeFile(
Expand Down
Loading

0 comments on commit d5dbcb7

Please sign in to comment.