From b879dfb93766a745e5b86f1038f178be2466a894 Mon Sep 17 00:00:00 2001 From: Ben Vercammen Date: Wed, 18 Oct 2023 11:05:43 +0200 Subject: [PATCH] Still cannot get "enabled: false" to impact the generated "build.dart" file --- _test/build.yaml | 6 ++++ _test/other_builder.build.yaml | 5 +++ _test/pkgs/other_builder/build.yaml | 5 +++ _test/pkgs/other_builder/lib/builders.dart | 36 ++++++++++++++++++++++ _test/pkgs/other_builder/pubspec.yaml | 10 ++++++ _test/pubspec.yaml | 2 ++ 6 files changed, 64 insertions(+) create mode 100644 _test/other_builder.build.yaml create mode 100644 _test/pkgs/other_builder/build.yaml create mode 100644 _test/pkgs/other_builder/lib/builders.dart create mode 100644 _test/pkgs/other_builder/pubspec.yaml diff --git a/_test/build.yaml b/_test/build.yaml index ce556f218..de4aeff3f 100644 --- a/_test/build.yaml +++ b/_test/build.yaml @@ -11,3 +11,9 @@ targets: - test/hello_world_custom_html_test.dart.browser_test.dart - test/other_test.dart.browser_test.dart - test/sub-dir/subdir_test.dart.browser_test.dart + # HELP: the settings below won't have any effect on the builders applied in `build.dart` + provides_builder|not_enabled_builder: + enabled: false + # HELP: Only when adding (even an empty) `other_builder.build.yaml` file, the builder won't show up in `build.dart` + other_builder|other_builder: + enabled: false \ No newline at end of file diff --git a/_test/other_builder.build.yaml b/_test/other_builder.build.yaml new file mode 100644 index 000000000..053f1cd8b --- /dev/null +++ b/_test/other_builder.build.yaml @@ -0,0 +1,5 @@ +#--- +## disable all inherited "provides_builder" builders... +#targets: +# $default: +# auto_apply_builders: false diff --git a/_test/pkgs/other_builder/build.yaml b/_test/pkgs/other_builder/build.yaml new file mode 100644 index 000000000..aaa175aa2 --- /dev/null +++ b/_test/pkgs/other_builder/build.yaml @@ -0,0 +1,5 @@ +builders: + other_builder: + import: "package:provides_builder/builders.dart" + builder_factories: ["someBuilder"] + build_extensions: {".dart": [".something.dart"]} diff --git a/_test/pkgs/other_builder/lib/builders.dart b/_test/pkgs/other_builder/lib/builders.dart new file mode 100644 index 000000000..66053aefb --- /dev/null +++ b/_test/pkgs/other_builder/lib/builders.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; + +import 'package:build/build.dart'; + +class _SomeBuilder implements Builder { + const _SomeBuilder(); + + factory _SomeBuilder.fromOptions(BuilderOptions options) { + if (options.config['throw_in_constructor'] == true) { + throw StateError('Throwing on purpose cause you asked for it!'); + } + return const _SomeBuilder(); + } + + @override + final buildExtensions = const { + '.dart': ['.something.dart'] + }; + + @override + Future build(BuildStep buildStep) async { + if (!await buildStep.canRead(buildStep.inputId)) return; + + await buildStep.writeAsBytes( + buildStep.inputId.changeExtension('.something.dart'), + buildStep.readAsBytes(buildStep.inputId)); + } +} + + +Builder otherBuilder(BuilderOptions options) => + _SomeBuilder.fromOptions(options); diff --git a/_test/pkgs/other_builder/pubspec.yaml b/_test/pkgs/other_builder/pubspec.yaml new file mode 100644 index 000000000..47ff18706 --- /dev/null +++ b/_test/pkgs/other_builder/pubspec.yaml @@ -0,0 +1,10 @@ +name: other_builder + +environment: + sdk: ^3.0.0 + +dependencies: + build: + path: ../../../build + provides_builder: + path: ../provides_builder diff --git a/_test/pubspec.yaml b/_test/pubspec.yaml index 7ba70c14a..ab624d573 100644 --- a/_test/pubspec.yaml +++ b/_test/pubspec.yaml @@ -16,6 +16,8 @@ dev_dependencies: build_web_compilers: any dart_flutter_team_lints: ^2.0.0 io: ^1.0.0 + other_builder: + path: pkgs/other_builder/ path: ^1.8.0 provides_builder: path: pkgs/provides_builder/