File tree Expand file tree Collapse file tree 5 files changed +24
-17
lines changed
native_assets_builder/test_data/treeshaking_native_assets/hook
example/link/package_with_assets/hook Expand file tree Collapse file tree 5 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -11,21 +11,23 @@ const packageName = 'treeshaking_native_assets';
11
11
void main (List <String > arguments) async {
12
12
await link (arguments, (config, output) async {
13
13
final usedSymbols =
14
- config.resources.map ((resource) => resource.metadata.toString ());
14
+ config.resources? .map ((resource) => resource.metadata.toString ());
15
15
final dynamicLibrary = config.assets.firstWhere ((asset) =>
16
16
asset.id == 'package:$packageName /src/${packageName }_bindings.dart' );
17
17
final staticLibrary = config.assets
18
18
.firstWhere ((asset) => asset.id == 'package:$packageName /staticlib' );
19
19
20
- final linkerScript = await _writeLinkerScript (usedSymbols);
21
- await _treeshakeStaticLibrary (
22
- usedSymbols,
23
- linkerScript,
24
- dynamicLibrary,
25
- staticLibrary,
26
- );
27
- output.addAsset (dynamicLibrary);
28
- output.addDependency (config.packageRoot.resolve ('hook/link.dart' ));
20
+ if (usedSymbols != null ) {
21
+ final linkerScript = await _writeLinkerScript (usedSymbols);
22
+ await _treeshakeStaticLibrary (
23
+ usedSymbols,
24
+ linkerScript,
25
+ dynamicLibrary,
26
+ staticLibrary,
27
+ );
28
+ output.addAsset (dynamicLibrary);
29
+ output.addDependency (config.packageRoot.resolve ('hook/link.dart' ));
30
+ }
29
31
});
30
32
}
31
33
Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ import 'package:native_assets_cli/native_assets_cli.dart';
7
7
void main (List <String > args) async {
8
8
await link (args, (config, output) async {
9
9
final assetsWithResource = config.assets.whereType <DataAsset >().where (
10
- (asset) => config.resources
11
- .any ((resource) => resource.metadata == asset.name));
10
+ (asset) =>
11
+ config.resources
12
+ ? .any ((resource) => resource.metadata == asset.name) ??
13
+ true );
12
14
output.addAssets (assetsWithResource);
13
15
});
14
16
}
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ import 'link_config.dart';
17
17
///
18
18
/// As the linking runs after kernel compilation, you can use treeshaking
19
19
/// information provided through [LinkConfig.resources] to decide which assets
20
- /// to include.
20
+ /// to include. The resources are only collected in AOT mode, therefore the
21
+ /// field is null in JIT mode.
21
22
///
22
23
///
23
24
/// ```dart
Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ abstract class LinkConfig implements HookConfig {
35
35
/// A collection of methods annotated with `@ResourceIdentifier` , which are
36
36
/// called in the tree-shaken Dart code. This information can be used to
37
37
/// dispose unused [assets] .
38
- List <Resource > get resources;
38
+ ///
39
+ /// This is `null` in JIT mode, where no resources are collected.
40
+ List <Resource >? get resources;
39
41
40
42
/// Generate the [LinkConfig] from the input arguments to the linking script.
41
43
factory LinkConfig .fromArguments (List <String > arguments) =>
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
19
19
final BuildConfigImpl _buildConfig;
20
20
21
21
@override
22
- final List <Resource > resources;
22
+ final List <Resource >? resources;
23
23
24
24
final _LinkConfigArgs _args;
25
25
@@ -99,8 +99,8 @@ class LinkConfigImpl extends HookConfigImpl implements LinkConfig {
99
99
static Version latestVersion = Version (1 , 0 , 0 );
100
100
}
101
101
102
- List <Resource > fromIdentifiers (ResourceIdentifiers ? resourceIdentifiers) =>
103
- ( resourceIdentifiers? .identifiers ?? [])
102
+ List <Resource >? fromIdentifiers (ResourceIdentifiers ? resourceIdentifiers) =>
103
+ resourceIdentifiers? .identifiers
104
104
.map ((e) => Resource (name: e.name, metadata: e.id))
105
105
.toList ();
106
106
You can’t perform that action at this time.
0 commit comments