diff --git a/build_web_compilers/CHANGELOG.md b/build_web_compilers/CHANGELOG.md index 30aa5f2e1..27e7ae028 100644 --- a/build_web_compilers/CHANGELOG.md +++ b/build_web_compilers/CHANGELOG.md @@ -1,3 +1,6 @@ +## 4.4.8-wip +- Minor updates to flag resolution logic. + ## 4.4.7 - Add support for DDC's Library Bundle module system, which is compatible with web hot reload. This is not yet enabled by default. diff --git a/build_web_compilers/lib/src/dev_compiler_builder.dart b/build_web_compilers/lib/src/dev_compiler_builder.dart index 3ca325b73..b3cbe9677 100644 --- a/build_web_compilers/lib/src/dev_compiler_builder.dart +++ b/build_web_compilers/lib/src/dev_compiler_builder.dart @@ -74,7 +74,7 @@ class DevCompilerBuilder implements Builder { this.generateFullDill = false, this.emitDebugSymbols = false, this.canaryFeatures = false, - this.ddcLibraryBundle = false, + this.ddcLibraryBundle = true, this.trackUnusedInputs = false, required this.platform, String? sdkKernelPath, diff --git a/build_web_compilers/lib/src/web_entrypoint_builder.dart b/build_web_compilers/lib/src/web_entrypoint_builder.dart index 0c6d1f396..68e814e21 100644 --- a/build_web_compilers/lib/src/web_entrypoint_builder.dart +++ b/build_web_compilers/lib/src/web_entrypoint_builder.dart @@ -188,9 +188,11 @@ final class EntrypointBuilderOptions { final config = options.config; final nativeNullAssertions = options.config[nativeNullAssertionsOption] as bool?; - final usesWebHotReload = options.config[webHotReloadOption] as bool?; + final usesWebHotReload = + options.config[webHotReloadOption] as bool? ?? false; final usesDdcLibraryBundle = - usesWebHotReload ?? options.config[ddcLibraryBundleOption] as bool?; + usesWebHotReload || + (options.config[ddcLibraryBundleOption] as bool? ?? false); final librariesPath = options.config[librariesPathOption] as String?; final unsafeAllowUnsupportedModules = options.config[unsafeAllowUnsupportedModulesOption] as bool?; @@ -281,8 +283,8 @@ final class EntrypointBuilderOptions { config.containsKey(loaderOption) ? config[loaderOption] as String? : defaultLoaderOption, - usesWebHotReload: usesWebHotReload ?? false, - ddcLibraryBundle: usesDdcLibraryBundle ?? false, + usesWebHotReload: usesWebHotReload, + ddcLibraryBundle: usesDdcLibraryBundle, librariesPath: librariesPath, unsafeAllowUnsupportedModules: unsafeAllowUnsupportedModules ?? false, ); diff --git a/build_web_compilers/pubspec.yaml b/build_web_compilers/pubspec.yaml index 1a03e75b6..c9e60fb45 100644 --- a/build_web_compilers/pubspec.yaml +++ b/build_web_compilers/pubspec.yaml @@ -1,5 +1,5 @@ name: build_web_compilers -version: 4.4.6 +version: 4.4.8-wip description: Builder implementations wrapping the dart2js and DDC compilers. repository: https://github.com/dart-lang/build/tree/master/build_web_compilers resolution: workspace diff --git a/build_web_compilers/test/ddc_library_bundle_bootstrap_test.dart b/build_web_compilers/test/ddc_library_bundle_bootstrap_test.dart index c0274305a..b0aa4e901 100644 --- a/build_web_compilers/test/ddc_library_bundle_bootstrap_test.dart +++ b/build_web_compilers/test/ddc_library_bundle_bootstrap_test.dart @@ -9,9 +9,11 @@ import 'package:build_web_compilers/build_web_compilers.dart'; import 'package:build_web_compilers/builders.dart'; import 'package:test/test.dart'; +const ddcLibraryBundle = true; + final defaultBuilderOptions = const BuilderOptions({ 'compiler': 'dartdevc', - 'ddc-library-bundle': true, + 'ddc-library-bundle': ddcLibraryBundle, 'native_null_assertions': false, }); @@ -27,7 +29,10 @@ void main() { MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), ddcKernelBuilder(const BuilderOptions({})), - DevCompilerBuilder(platform: ddcPlatform, ddcLibraryBundle: true), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ), }; group('DDC Library Bundle:', () { group('simple project', () { diff --git a/build_web_compilers/test/ddc_library_bundle_builder_test.dart b/build_web_compilers/test/ddc_library_bundle_builder_test.dart index b6b16fde4..2fd73cf20 100644 --- a/build_web_compilers/test/ddc_library_bundle_builder_test.dart +++ b/build_web_compilers/test/ddc_library_bundle_builder_test.dart @@ -10,9 +10,11 @@ import 'package:build_web_compilers/builders.dart'; import 'package:logging/logging.dart'; import 'package:test/test.dart'; +const ddcLibraryBundle = true; + final builderOptions = const BuilderOptions({ 'track-unused-inputs': false, - 'ddc-library-bundle': true, + 'ddc-library-bundle': ddcLibraryBundle, }); void main() { @@ -84,7 +86,7 @@ void main() { platform: ddcPlatform, useIncrementalCompiler: trackUnusedInputs, trackUnusedInputs: trackUnusedInputs, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ @@ -132,7 +134,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, environment: {'foo': 'zap'}, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -158,7 +160,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, canaryFeatures: true, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': decodedMatches(contains('canary')), @@ -183,7 +185,7 @@ void main() { () async { final builder = DevCompilerBuilder( platform: ddcPlatform, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': decodedMatches( @@ -213,7 +215,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, generateFullDill: true, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$fullKernelExtension': isNotNull, @@ -239,7 +241,7 @@ void main() { test('does not generate full dill by default', () async { final builder = DevCompilerBuilder( platform: ddcPlatform, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -263,7 +265,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, emitDebugSymbols: true, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -289,7 +291,7 @@ void main() { test('does not emit debug symbols by default', () async { final builder = DevCompilerBuilder( platform: ddcPlatform, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'b|lib/b$jsModuleExtension': isNotNull, @@ -312,7 +314,7 @@ void main() { test('strips scratch paths from metadata', () async { final builder = DevCompilerBuilder( platform: ddcPlatform, - ddcLibraryBundle: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -366,7 +368,10 @@ void main() { MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), ddcKernelBuilder(builderOptions), - DevCompilerBuilder(platform: ddcPlatform, ddcLibraryBundle: true), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ), ], assets, outputs: expectedOutputs, @@ -412,7 +417,10 @@ void main() { MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), ddcKernelBuilder(builderOptions), - DevCompilerBuilder(platform: ddcPlatform, ddcLibraryBundle: true), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ), ], assets, outputs: expectedOutputs, diff --git a/build_web_compilers/test/dev_compiler_bootstrap_test.dart b/build_web_compilers/test/dev_compiler_bootstrap_test.dart index 7891275d1..79a1d0f79 100644 --- a/build_web_compilers/test/dev_compiler_bootstrap_test.dart +++ b/build_web_compilers/test/dev_compiler_bootstrap_test.dart @@ -12,18 +12,29 @@ import 'package:build_web_compilers/builders.dart'; import 'package:file/memory.dart'; import 'package:test/test.dart'; +const ddcLibraryBundle = false; + +final defaultBuilderOptions = const BuilderOptions({ + 'compiler': 'dartdevc', + 'ddc-library-bundle': ddcLibraryBundle, + 'native_null_assertions': false, +}); + void main() { initializePlatforms(); final startingBuilders = { // Uses the real sdk copy builder to copy required files from the SDK. sdkJsCopyRequirejs(const BuilderOptions({})), - sdkJsCompile(const BuilderOptions({})), + sdkJsCompile(defaultBuilderOptions), const ModuleLibraryBuilder(), MetaModuleBuilder(ddcPlatform), MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), ddcKernelBuilder(const BuilderOptions({})), - DevCompilerBuilder(platform: ddcPlatform), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ), }; group('simple project', () { @@ -85,12 +96,7 @@ void main() { test('can bootstrap dart entrypoints', () async { // Just do some basic sanity checking, integration tests will validate // things actually work. - final builder = WebEntrypointBuilder.fromOptions( - const BuilderOptions({ - 'compiler': 'dartdevc', - 'native_null_assertions': false, - }), - ); + final builder = WebEntrypointBuilder.fromOptions(defaultBuilderOptions); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|web/index.dart.bootstrap.js': decodedMatches( allOf([ @@ -122,12 +128,7 @@ void main() { }); group('regression tests', () { test('root dart file is not the primary source, #2269', () async { - final builder = WebEntrypointBuilder.fromOptions( - const BuilderOptions({ - 'compiler': 'dartdevc', - 'native_null_assertions': false, - }), - ); + final builder = WebEntrypointBuilder.fromOptions(defaultBuilderOptions); final assets = { // Becomes the primary source for the module, since it we alpha-sort. 'a|web/a.dart': ''' @@ -187,12 +188,7 @@ void main() { }); test('root dart file is under lib', () async { - final builder = WebEntrypointBuilder.fromOptions( - const BuilderOptions({ - 'compiler': 'dartdevc', - 'native_null_assertions': false, - }), - ); + final builder = WebEntrypointBuilder.fromOptions(defaultBuilderOptions); final assets = { 'a|lib/app.dart': 'void main() {}', // Add a fake asset so that the build_web_compilers package exists. @@ -235,7 +231,9 @@ void main() { }); test('can enable canary features for SDK', () async { - final builder = sdkJsCompile(const BuilderOptions({'canary': true})); + final builder = sdkJsCompile( + const BuilderOptions({'canary': true, 'ddc-library-bundle': false}), + ); final sdkAssets = {'build_web_compilers|fake.txt': ''}; final expectedOutputs = { 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js': decodedMatches( @@ -247,7 +245,7 @@ void main() { }); test('does not enable canary features for SDK by default', () async { - final builder = sdkJsCompile(const BuilderOptions({})); + final builder = sdkJsCompile(defaultBuilderOptions); final sdkAssets = {'build_web_compilers|fake.txt': ''}; final expectedOutputs = { 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js': decodedMatches( @@ -260,7 +258,10 @@ void main() { test('can use prebuilt sdk from path', () async { final builder = sdkJsCompile( - const BuilderOptions({'use-prebuilt-sdk-from-path': 'path/to/sdk'}), + const BuilderOptions({ + 'use-prebuilt-sdk-from-path': 'path/to/sdk', + 'ddc-library-bundle': false, + }), ); final sdkAssets = {'build_web_compilers|fake.txt': ''}; final expectedOutputs = { diff --git a/build_web_compilers/test/dev_compiler_builder_test.dart b/build_web_compilers/test/dev_compiler_builder_test.dart index 235bdd3b7..530387954 100644 --- a/build_web_compilers/test/dev_compiler_builder_test.dart +++ b/build_web_compilers/test/dev_compiler_builder_test.dart @@ -10,6 +10,13 @@ import 'package:build_web_compilers/builders.dart'; import 'package:logging/logging.dart'; import 'package:test/test.dart'; +const ddcLibraryBundle = false; + +final builderOptions = const BuilderOptions({ + 'track-unused-inputs': false, + 'ddc-library-bundle': ddcLibraryBundle, +}); + void main() { initializePlatforms(); @@ -37,7 +44,7 @@ void main() { MetaModuleBuilder(ddcPlatform), MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), - ddcKernelBuilder(const BuilderOptions({'track-unused-inputs': false})), + ddcKernelBuilder(builderOptions), ]; final startingExpectedOutputs = { 'a|lib/.ddc.meta_module.clean': isNotNull, @@ -78,6 +85,7 @@ void main() { platform: ddcPlatform, useIncrementalCompiler: trackUnusedInputs, trackUnusedInputs: trackUnusedInputs, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ @@ -125,6 +133,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, environment: {'foo': 'zap'}, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -150,6 +159,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, canaryFeatures: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': decodedMatches(contains('canary')), @@ -170,7 +180,10 @@ void main() { }); test('does not enable DDC canary features by default', () async { - final builder = DevCompilerBuilder(platform: ddcPlatform); + final builder = DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': decodedMatches(isNot(contains('canary'))), 'a|lib/a$jsSourceMapExtension': isNotNull, @@ -193,6 +206,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, generateFullDill: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$fullKernelExtension': isNotNull, @@ -216,7 +230,10 @@ void main() { }); test('does not generate full dill by default', () async { - final builder = DevCompilerBuilder(platform: ddcPlatform); + final builder = DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, 'a|lib/a$jsSourceMapExtension': isNotNull, @@ -239,6 +256,7 @@ void main() { final builder = DevCompilerBuilder( platform: ddcPlatform, emitDebugSymbols: true, + ddcLibraryBundle: ddcLibraryBundle, ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, @@ -262,7 +280,10 @@ void main() { }); test('does not emit debug symbols by default', () async { - final builder = DevCompilerBuilder(platform: ddcPlatform); + final builder = DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'b|lib/b$jsModuleExtension': isNotNull, 'b|lib/b$jsSourceMapExtension': isNotNull, @@ -282,7 +303,10 @@ void main() { }); test('strips scratch paths from metadata', () async { - final builder = DevCompilerBuilder(platform: ddcPlatform); + final builder = DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, + ); final expectedOutputs = Map.of(startingExpectedOutputs)..addAll({ 'a|lib/a$jsModuleExtension': isNotNull, 'a|lib/a$jsSourceMapExtension': isNotNull, @@ -330,10 +354,11 @@ void main() { MetaModuleBuilder(ddcPlatform), MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), - ddcKernelBuilder( - const BuilderOptions({'track-unused-inputs': false}), + ddcKernelBuilder(builderOptions), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, ), - DevCompilerBuilder(platform: ddcPlatform), ], assets, outputs: expectedOutputs, @@ -378,10 +403,11 @@ void main() { MetaModuleBuilder(ddcPlatform), MetaModuleCleanBuilder(ddcPlatform), ModuleBuilder(ddcPlatform), - ddcKernelBuilder( - const BuilderOptions({'track-unused-inputs': false}), + ddcKernelBuilder(builderOptions), + DevCompilerBuilder( + platform: ddcPlatform, + ddcLibraryBundle: ddcLibraryBundle, ), - DevCompilerBuilder(platform: ddcPlatform), ], assets, outputs: expectedOutputs,