Unverified Commit 0fc1c6f6 authored by Harry Terkelsen's avatar Harry Terkelsen Committed by GitHub

[flutter_tool] Make the registrant import relative to the entrypoint (#50302)

parent 181cdec0
......@@ -351,13 +351,14 @@ class FlutterWebShellBuilder implements Builder {
return;
}
final AssetId outputId = buildStep.inputId.changeExtension('_web_entrypoint.dart');
final String pluginRegistrantPath = _getPluginRegistrantPath(dartEntrypointId.path);
if (hasPlugins) {
await buildStep.writeAsString(outputId, '''
import 'dart:ui' as ui;
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'generated_plugin_registrant.dart';
import '$pluginRegistrantPath';
import "${path.url.basename(buildStep.inputId.path)}" as entrypoint;
Future<void> main() async {
......@@ -384,6 +385,13 @@ Future<void> main() async {
}
}
/// Gets the relative path to the generated plugin registrant from the app
/// app entrypoint.
String _getPluginRegistrantPath(String entrypoint) {
return path.url.relative('lib/generated_plugin_registrant.dart',
from: path.url.dirname(entrypoint));
}
@override
Map<String, List<String>> get buildExtensions => const <String, List<String>>{
'.dart': <String>['_web_entrypoint.dart'],
......
......@@ -69,6 +69,21 @@ void main() {
verify(mockBuildStep.writeAsString(any,
argThat(isNot(contains('registerPlugins(webPluginRegistry)'))))).called(1);
});
test('FlutterWebShellBuilder correctly imports registrant', () async {
final AssetId nestedEntrypoint = AssetId('hello_world', 'lib/src/nested_main.dart');
when(mockBuildStep.inputId).thenReturn(nestedEntrypoint);
const FlutterWebShellBuilder builder = FlutterWebShellBuilder(
hasPlugins: true,
initializePlatform: true,
);
await builder.build(mockBuildStep);
verify(mockBuildStep.writeAsString(any,
argThat(contains("import '../generated_plugin_registrant.dart';")))).called(1);
});
}
class MockBuildStep extends Mock implements BuildStep {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment