Skip to content

Commit ce9f735

Browse files
authored
Fixing DDC + FES not properly reading entrypointAssetId when re-serving an app. (#4273)
Read from our .web.entrypoint.json file instead, which would have been generated in a previous compile.
1 parent 69dbcff commit ce9f735

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

build_modules/lib/src/frontend_server_resources.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FrontendServerState {
1313
///
1414
/// This must be set before any asset builders run when compiling with DDC and
1515
/// hot reload.
16-
late AssetId entrypointAssetId;
16+
AssetId? entrypointAssetId;
1717
}
1818

1919
/// A shared [Resource] for a [FrontendServerState].

build_web_compilers/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.4.2
2+
3+
- Fixes DDC + FES not reading the entrypoint when serving a prebuilt app.
4+
15
## 4.4.1
26

37
- Read `multiRootScheme` from `build_modules`.

build_web_compilers/lib/src/ddc_frontend_server_builder.dart

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,31 @@ class DdcFrontendServerBuilder implements Builder {
6666
final frontendServerState = await buildStep.fetchResource(
6767
frontendServerStateResource,
6868
);
69+
70+
if (frontendServerState.entrypointAssetId == null) {
71+
// Reuse the recorded entrypoint asset if it was generated in a previous
72+
// build.
73+
final webEntrypointAsset = AssetId(
74+
buildStep.inputId.package,
75+
'web/.web.entrypoint.json',
76+
);
77+
if (await buildStep.canRead(webEntrypointAsset)) {
78+
final contents =
79+
json.decode(await buildStep.readAsString(webEntrypointAsset))
80+
as Map<String, dynamic>;
81+
frontendServerState.entrypointAssetId = AssetId.parse(
82+
contents['entrypoint'] as String,
83+
);
84+
} else {
85+
log.severe(
86+
'Unable to read entrypoint when building ${buildStep.inputId}.',
87+
);
88+
return;
89+
}
90+
}
91+
6992
final scratchSpace = await buildStep.fetchResource(scratchSpaceResource);
70-
final webEntrypointAsset = frontendServerState.entrypointAssetId;
93+
final webEntrypointAsset = frontendServerState.entrypointAssetId!;
7194
await buildStep.trackStage(
7295
'EnsureAssets',
7396
() => scratchSpace.ensureAssets([
@@ -127,8 +150,8 @@ class DdcFrontendServerBuilder implements Builder {
127150
final metadataId = ddcEntrypointId.changeExtension(metadataExtension);
128151
final file = scratchSpace.fileFor(metadataId);
129152
final content = await file.readAsString();
130-
final json = jsonDecode(content) as Map<String, Object?>;
131-
fixMetadataSources(json, scratchSpace.tempDir.uri);
132-
await buildStep.writeAsString(metadataId, jsonEncode(json));
153+
final metadataJson = jsonDecode(content) as Map<String, Object?>;
154+
fixMetadataSources(metadataJson, scratchSpace.tempDir.uri);
155+
await buildStep.writeAsString(metadataId, jsonEncode(metadataJson));
133156
}
134157
}

build_web_compilers/lib/src/web_entrypoint_marker_builder.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class WebEntrypointMarkerBuilder implements Builder {
3030
final frontendServerState = await buildStep.fetchResource(
3131
frontendServerStateResource,
3232
);
33+
final webEntrypointAsset = AssetId(
34+
buildStep.inputId.package,
35+
'web/.web.entrypoint.json',
36+
);
3337
final webAssets = await buildStep.findAssets(Glob('web/**')).toList();
3438
final webEntrypointJson = <String, dynamic>{};
3539

@@ -43,14 +47,14 @@ class WebEntrypointMarkerBuilder implements Builder {
4347
// We must save the main entrypoint as the recompilation target for
4448
// the Frontend Server before any JS files are emitted.
4549
frontendServerState.entrypointAssetId = asset;
46-
webEntrypointJson['entrypoint'] = asset.uri.toString();
50+
webEntrypointJson['entrypoint'] = asset.toString();
4751
break;
4852
}
4953
}
5054
}
5155

5256
await buildStep.writeAsString(
53-
AssetId(buildStep.inputId.package, 'web/.web.entrypoint.json'),
57+
webEntrypointAsset,
5458
jsonEncode(webEntrypointJson),
5559
);
5660
}

build_web_compilers/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_web_compilers
2-
version: 4.4.1
2+
version: 4.4.2
33
description: Builder implementations wrapping the dart2js and DDC compilers.
44
repository: https://github.com/dart-lang/build/tree/master/build_web_compilers
55
resolution: workspace

0 commit comments

Comments
 (0)