Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/jaspr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased 0.24.0-beta.2

- Fixed `jaspr serve` with Flutter embedding or plugins failing on Flutter 3.50, which moved the precompiled DDC SDK to `kernel/ddc/canary` and `kernel/ddc/stable`.

## 0.24.0-beta.1

### New Features and Improvements
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr_cli/lib/src/commands/build_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class BuildCommand extends BaseCommand with ProxyHelper {

List<String> additionalFlutterBuildArgs() {
final librariesPath = p.join(FlutterRunner.webSdkDir, 'libraries.json');
final sdkJsPath = p.join(FlutterRunner.webSdkDir, 'kernel', 'amd-canvaskit');
final sdkJsPath = FlutterRunner.precompiledDdcSdkDir(FlutterRunner.webSdkDir, ddcLibraryBundle: false);
return [
'--define=build_web_compilers:entrypoint=use-ui-libraries=true',
'--define=build_web_compilers:entrypoint_marker=use-ui-libraries=true',
Expand Down
6 changes: 4 additions & 2 deletions packages/jaspr_cli/lib/src/commands/dev_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,10 @@ abstract class DevCommand extends BaseCommand with ProxyHelper {
List<String> additionalFlutterBuildArgs() {
final sdkKernelPath = p.url.join('kernel', 'ddc_outline.dill');
final librariesPath = p.join(FlutterRunner.webSdkDir, 'libraries.json');
final ddcSdkPrefix = usesDdcLibraryBundles ? 'ddcLibraryBundle-canvaskit' : 'amd-canvaskit';
final sdkJsPath = p.join(FlutterRunner.webSdkDir, 'kernel', ddcSdkPrefix);
final sdkJsPath = FlutterRunner.precompiledDdcSdkDir(
FlutterRunner.webSdkDir,
ddcLibraryBundle: usesDdcLibraryBundles,
);
return [
'--define=build_web_compilers:entrypoint=use-ui-libraries=true',
'--define=build_web_compilers:entrypoint_marker=use-ui-libraries=true',
Expand Down
20 changes: 20 additions & 0 deletions packages/jaspr_cli/lib/src/dev/flutter_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,24 @@ class FlutterRunner {
}
return webSdkPath;
})();

/// The folder in [webSdkDir] with the precompiled DDC SDK (`dart_sdk.js`)
/// for the DDC library bundle or the AMD module format.
///
/// Flutter 3.50 moved it from `kernel/ddcLibraryBundle-canvaskit` and
/// `kernel/amd-canvaskit` to `kernel/ddc/canary` and `kernel/ddc/stable`, and
/// no longer ships an AMD build. `build_web_compilers` compiles DDC library
/// bundles with `--canary`, which matches `kernel/ddc/canary`. Otherwise it
/// compiles without `--canary`, which matches `kernel/ddc/stable`. Older
/// Flutter versions keep using their folders.
static String precompiledDdcSdkDir(String webSdkDir, {required bool ddcLibraryBundle}) {
final (ddcDir, legacyDir) = ddcLibraryBundle
? ('canary', 'ddcLibraryBundle-canvaskit')
: ('stable', 'amd-canvaskit');
final dir = p.join(webSdkDir, 'kernel', 'ddc', ddcDir);
if (Directory(dir).existsSync()) {
return dir;
}
return p.join(webSdkDir, 'kernel', legacyDir);
}
}
47 changes: 47 additions & 0 deletions packages/jaspr_cli/test/src/commands/build_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,53 @@ void main() {
});
});

// https://github.com/schultek/jaspr/issues/999
test('uses the precompiled DDC SDK from kernel/ddc/stable on Flutter 3.50 and later', () async {
await io.runZoned(() async {
io.setupFakeProject('myapp', mode: 'client', flutterEmbedding: true);
io.stubDartSDK();
io.stubFlutterSDK();
// Flutter 3.50 ships the precompiled SDKs in kernel/ddc/{stable,canary}
// instead of kernel/{amd,ddcLibraryBundle}-canvaskit.
io.fs.file('/fake/flutter/bin/cache/flutter_web_sdk/kernel/ddc/canary/dart_sdk.js').createSync(recursive: true);
io.fs.file('/fake/flutter/bin/cache/flutter_web_sdk/kernel/ddc/stable/dart_sdk.js').createSync(recursive: true);

final buildDaemon = io.setupFakeBuildDaemon(
verifyArgs: [
for (final arg in buildRunnerFlutterBuildArgs)
arg.replaceFirst('kernel/amd-canvaskit', 'kernel/ddc/stable'),
],
);

final buildResult = runner.run(['build', '--verbose']);

await expectLater(io.stdout.queue, emits('Building myapp in client rendering mode.'));

when(
() => io.process.start(
'flutter',
[
'build',
'web',
'-t',
'.dart_tool/jaspr/flutter_target.dart',
'--no-wasm-dry-run',
'--no-tree-shake-icons',
'--output=build/flutter',
],
workingDirectory: '/root/myapp',
runInShell: true,
),
).thenAnswer((_) async => FakeProcess.sync());

await io.runReleaseBuild(buildDaemon);

await expectLater(io.stdout.queue, emitsThrough(contains('Completed building')));

expect(await buildResult, equals(0));
});
});

test('builds project with flutter embedding', () async {
await io.runZoned(() async {
io.setupFakeProject('myapp', mode: 'client', flutterEmbedding: true);
Expand Down
71 changes: 71 additions & 0 deletions packages/jaspr_cli/test/src/commands/serve_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,77 @@ void main() {
});
});

// https://github.com/schultek/jaspr/issues/999
test('uses the precompiled DDC SDK from kernel/ddc/canary on Flutter 3.50 and later', () async {
await io.runZoned(() async {
io.setupFakeProject('myapp', mode: 'server', flutterEmbedding: true);
io.stubDartSDK();
io.stubFlutterSDK();
// Flutter 3.50 ships the precompiled SDKs in kernel/ddc/{stable,canary}
// instead of kernel/{ddcLibraryBundle,amd}-canvaskit.
io.fs.file('/fake/flutter/bin/cache/flutter_web_sdk/kernel/ddc/canary/dart_sdk.js').createSync(recursive: true);
io.fs.file('/fake/flutter/bin/cache/flutter_web_sdk/kernel/ddc/stable/dart_sdk.js').createSync(recursive: true);

final buildDaemon = io.setupFakeBuildDaemon(
verifyArgs: [
for (final arg in buildRunnerFlutterArgs)
arg.replaceFirst('kernel/ddcLibraryBundle-canvaskit', 'kernel/ddc/canary'),
],
);
final server = io.stubFakeServer();

FakeProcess? flutterProcess;
when(
() => io.process.start(
'flutter',
[
'run',
'--device-id=web-server',
'-t',
'.dart_tool/jaspr/flutter_target.dart',
'--web-port=$flutterProxyPort',
],
workingDirectory: '/root/myapp',
runInShell: true,
),
).thenAnswer((_) async => flutterProcess = FakeProcess());

final serveResult = runner.run(['serve', '--verbose']);

await expectLater(
io.stdout.queue,
emitsInOrderWithTimeout([
'Starting myapp in server rendering mode.',
'[BUILDER] Starting web compilers...',
'[BUILDER] Connecting to the build daemon...',
'[BUILDER] Starting initial build...',
]),
);

await io.runInitialBuild(buildDaemon);

expect(io.stdout.queue, emits('[BUILDER] Done building web assets.'));

await io.connectToProxy();

expect(flutterProcess, isNotNull);

await io.expectServerStarted(server);

server.exit(0);

expect(
io.stdout.queue,
emitsInOrderWithTimeout([
'Stopping web compilers...',
'Stopping flutter run...',
]),
);

expect(await serveResult, equals(0));
});
});

test('serves project with automatic port fallback when default port is in use', () async {
await io.runZoned(() async {
io.setupFakeProject('myapp', mode: 'client');
Expand Down
Loading