@@ -232,6 +232,81 @@ these options should be used rarely.
232232 and `applies_builder` to configure both ordering and ensure that steps are not
233233 skipped.
234234
235+ # # Triggers
236+
237+ Triggers are a performance heuristic that allow builders to quickly decide
238+ _not_ to run.
239+
240+ A builder runs only if triggered if the option `run_only_if_triggered` is
241+ `true`. This can be enabled for the builder :
242+
243+ ` ` ` yaml
244+ builders:
245+ my_builder:
246+ import: "package:my_package/builder.dart"
247+ builder_factories: ["myBuilder"]
248+ build_extensions: {".dart": [".my_package.dart"]}
249+ defaults:
250+ options:
251+ run_only_if_triggered: true
252+ ` ` `
253+
254+ Or, enabled/disabled in the `build.yaml` of the package applying the builder :
255+
256+ ` ` ` yaml
257+ targets:
258+ $default:
259+ builders:
260+ my_package:my_builder:
261+ options:
262+ run_only_if_triggered: true # or ` false`
263+ ```
264+
265+ Triggers are defined in a new top-level section called ` triggers ` :
266+
267+ ``` yaml
268+ triggers :
269+ my_package:my_builder :
270+ - annotation MyAnnotation
271+ - import my_package/my_builder_annotation.dart
272+ ` ` `
273+
274+ An ` annotation` trigger causes the builder to run if an annotation is used.
275+ So, `- annotation MyAnnotation` is a check for `@MyAnnotation` being used.
276+ A part file included from a library is also checked for the annotation.
277+
278+ An `import` trigger says that the builder runs if there is a direct import
279+ of the specified library. This might be useful if a builder can run on code
280+ without annotations, for example on all classes that `implement` a particular
281+ type. Then, the import of the type used to trigger generation can be the
282+ trigger.
283+
284+ Only one trigger has to match for the builder to run; adding more triggers
285+ can never prevent a builder from running. So, a builder usually only needs
286+ either an `import` trigger or an `annotation` trigger, not both.
287+
288+ Triggers are collected from all packages in the codebase, not just packages
289+ defining or applying builders. This allows a package to provide new ways to
290+ trigger a builder from an unrelated package. For example, if
291+ ` third_party_package` re-exports the annotation in
292+ ` package:my_package/my_builder_annotation.dart` then it should also add a
293+ trigger :
294+
295+ ` ` ` yaml
296+ triggers:
297+ my_package:my_builder:
298+ - import third_party_package/annotations.dart
299+ ` ` `
300+
301+ Or, if `third_party_package` defines a new constant `NewAnnotation` that can be
302+ used as an annotation for `my_builder`, it should add a trigger :
303+
304+ ` ` ` yaml
305+ triggers:
306+ my_package:my_builder:
307+ - annotation NewAnnotation
308+ ` ` `
309+
235310# Publishing `build.yaml` files
236311
237312` build.yaml` configuration should be published to pub with the package and
0 commit comments