[hooks] Document user-defines in API#3407
Conversation
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthAPI leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with |
|
(CI redness fix: #3408) |
| /// by the end-user from the workspace `pubspec.yaml` (or the root package | ||
| /// `pubspec.yaml` if not in a workspace) via the `input.userDefines` property. |
There was a problem hiding this comment.
flip this around, the assumption starts with users are not in a workspace.
|
|
||
| /// The user-defines for this hook input. | ||
| /// Custom user-defined configurations specified in the workspace or package | ||
| /// `pubspec.yaml` under the `hooks.user_defines` block. |
There was a problem hiding this comment.
This should be documented in:
https://dart.dev/tools/pub/pubspec
There was a problem hiding this comment.
| /// ```yaml | ||
| /// hooks: | ||
| /// user_defines: | ||
| /// my_database: |
There was a problem hiding this comment.
| /// my_database: | |
| /// my_package: |
| /// <!-- file://./../../example/api/config_snippet_6.dart --> | ||
| /// ```dart | ||
| /// import 'dart:io'; | ||
| /// import 'package:hooks/hooks.dart'; | ||
| /// | ||
| /// void main(List<String> args) async { | ||
| /// await build(args, (input, output) async { | ||
| /// // Access raw user-defines value | ||
| /// final debugLogging = | ||
| /// input.userDefines['enable_debug_logging'] == true; | ||
| /// if (debugLogging) { | ||
| /// print('Debug logging is enabled.'); | ||
| /// } | ||
| /// | ||
| /// // Resolve relative path against pubspec.yaml base path | ||
| /// final customAssetUri = input.userDefines.path('custom_asset'); | ||
| /// if (customAssetUri != null) { | ||
| /// final file = File.fromUri(customAssetUri); | ||
| /// output.dependencies.add(file.uri); // Declare cache dependency | ||
| /// // Use the file... | ||
| /// } | ||
| /// }); | ||
| /// } | ||
| /// ``` |
There was a problem hiding this comment.
| /// <!-- file://./../../example/api/config_snippet_6.dart --> | |
| /// ```dart | |
| /// import 'dart:io'; | |
| /// import 'package:hooks/hooks.dart'; | |
| /// | |
| /// void main(List<String> args) async { | |
| /// await build(args, (input, output) async { | |
| /// // Access raw user-defines value | |
| /// final debugLogging = | |
| /// input.userDefines['enable_debug_logging'] == true; | |
| /// if (debugLogging) { | |
| /// print('Debug logging is enabled.'); | |
| /// } | |
| /// | |
| /// // Resolve relative path against pubspec.yaml base path | |
| /// final customAssetUri = input.userDefines.path('custom_asset'); | |
| /// if (customAssetUri != null) { | |
| /// final file = File.fromUri(customAssetUri); | |
| /// output.dependencies.add(file.uri); // Declare cache dependency | |
| /// // Use the file... | |
| /// } | |
| /// }); | |
| /// } | |
| /// ``` | |
| /// {@example /example/api/config_snippet_6.dart} |
Analyzer might still complain 🙈 , but it should work in dartdoc
There was a problem hiding this comment.
I'll look into adopting the new {@example later, my current script works.
| @@ -120,6 +206,18 @@ final class HookInputUserDefines { | |||
| /// | |||
| /// This can be arbitrary JSON/YAML if provided from the SDK from such source. | |||
There was a problem hiding this comment.
YAML can have circular references, are you sure you want to say YAML?
I think that you should consider running user-defines through json.decode(json.encode()) unless you want package:yaml to accidentally be part of the public API here.
For the record, if done right having package:yaml as part the public API can be cool, because each YamlNode probably has a SourceSpan that makes printing errors really cool.
But also I'm guessing this travels over some serialized protocol so it might already be JSON proper
| // Access raw user-defines value | ||
| final debugLogging = | ||
| input.userDefines['enable_debug_logging'] == true; | ||
| if (debugLogging) { | ||
| print('Debug logging is enabled.'); | ||
| } |
There was a problem hiding this comment.
| // Access raw user-defines value | |
| final debugLogging = | |
| input.userDefines['enable_debug_logging'] == true; | |
| if (debugLogging) { | |
| print('Debug logging is enabled.'); | |
| } | |
| // Access raw user-defines value | |
| final debugLogging = | |
| input.userDefines['enable_debug_logging']; | |
| // Validate input! | |
| if (debugLogging is! bool?) { | |
| throw DacoMightKnowWhatErrorOrExceptionIAmSupposedToThrow('hooks.user_defines.my_package.enable_debug_logging must be a boolean (or omitted)'); | |
| } | |
| if (debugLogging == true) { | |
| print('Debug logging is enabled.'); | |
| } |
There was a problem hiding this comment.
any exception will do
No description provided.