Skip to content

Commit bb1e08a

Browse files
authored
[code_assets] Document asset namespacing (#2734)
1 parent 93c6972 commit bb1e08a

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

pkgs/code_assets/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.19.10
22

33
- Document `input.packageRoot` in more places.
4+
- Document `CodeAsset.id` package namespacing.
45

56
## 0.19.9
67

pkgs/code_assets/lib/src/code_assets/code_asset.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ import 'syntax.g.dart';
5353
/// specified location on the current system into the application bundle.
5454
final class CodeAsset {
5555
/// The id of this code asset.
56+
///
57+
/// The identifier is a uri `package:<package>/<name>`. In build hooks,
58+
/// `<package>` must be the name of the package containing the build hook.
59+
/// Code assets are name-spaced in their own package to avoid naming
60+
/// conflicts.
5661
final String id;
5762

5863
/// The link mode for this native code.
@@ -71,18 +76,23 @@ final class CodeAsset {
7176
///
7277
/// If the [linkMode] is [LookupInProcess], or [LookupInExecutable] the file
7378
/// must be omitted in the [BuildOutput].
79+
///
80+
/// Code assets with [DynamicLoadingBundled] may not have conflicting file
81+
/// names, the dynamic linker treats them as a single namespace.
7482
final Uri? file;
7583

7684
/// Constructs a native code asset.
7785
///
7886
/// The [id] of this asset is a uri `package:<package>/<name>` from [package]
79-
/// and [name].
87+
/// and [name]. In build hooks, [package] must be the name of the package
88+
/// containing the build hook. Code assets are name-spaced in their own
89+
/// package to avoid naming conflicts.
8090
CodeAsset({
8191
required String package,
8292
required String name,
83-
required LinkMode linkMode,
84-
Uri? file,
85-
}) : this._(id: 'package:$package/$name', linkMode: linkMode, file: file);
93+
required this.linkMode,
94+
this.file,
95+
}) : id = 'package:$package/$name';
8696

8797
CodeAsset._({required this.id, required this.linkMode, required this.file});
8898

pkgs/code_assets/lib/src/code_assets/config.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ final class BuildOutputCodeAssetBuilder {
169169
/// The [CodeAsset.file], if provided, must be an absolute path. Prefer
170170
/// constructing the path via [HookInput.outputDirectoryShared] or
171171
/// [HookInput.outputDirectory].
172+
///
173+
/// The [CodeAsset.id] must be starting with `package:<package>/` where
174+
/// `<package>` is the package name of the build hook where this method is
175+
/// called.
172176
void add(CodeAsset asset, {AssetRouting routing = const ToAppBundle()}) =>
173177
_output.addEncodedAsset(asset.encode(), routing: routing);
174178

@@ -177,6 +181,10 @@ final class BuildOutputCodeAssetBuilder {
177181
/// The [CodeAsset.file]s, if provided, must be absolute paths. Prefer
178182
/// constructing the paths via [HookInput.outputDirectoryShared] or
179183
/// [HookInput.outputDirectory].
184+
///
185+
/// The [CodeAsset.id]s must be starting with `package:<package>/` where
186+
/// `<package>` is the package name of the build hook where this method is
187+
/// called.
180188
void addAll(
181189
Iterable<CodeAsset> assets, {
182190
AssetRouting routing = const ToAppBundle(),

0 commit comments

Comments
 (0)