parent
0b95e9c278
commit
e5aead03cc
@ -479,7 +479,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
|||||||
packageMap,
|
packageMap,
|
||||||
assetBase,
|
assetBase,
|
||||||
asset,
|
asset,
|
||||||
packageName
|
packageName,
|
||||||
);
|
);
|
||||||
if (!baseAsset.assetFileExists) {
|
if (!baseAsset.assetFileExists) {
|
||||||
printError('Error: unable to locate asset entry in pubspec.yaml: "$asset".');
|
printError('Error: unable to locate asset entry in pubspec.yaml: "$asset".');
|
||||||
@ -502,37 +502,42 @@ _Asset _resolveAsset(
|
|||||||
) {
|
) {
|
||||||
if (asset.startsWith('packages/') && !fs.isFileSync(fs.path.join(assetBase, asset))) {
|
if (asset.startsWith('packages/') && !fs.isFileSync(fs.path.join(assetBase, asset))) {
|
||||||
// The asset is referenced in the pubspec.yaml as
|
// The asset is referenced in the pubspec.yaml as
|
||||||
// 'packages/PACKAGE_NAME/PATH/TO/ASSET
|
// 'packages/PACKAGE_NAME/PATH/TO/ASSET .
|
||||||
final _Asset packageAsset = _resolvePackageAsset(asset, packageMap);
|
final _Asset packageAsset = _resolvePackageAsset(asset, packageMap);
|
||||||
if (packageAsset != null)
|
if (packageAsset != null)
|
||||||
return packageAsset;
|
return packageAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String assetEntry = packageName != null
|
final String assetEntry = packageName != null
|
||||||
? 'packages/$packageName/$asset' // Asset from, and declared in $packageName
|
? 'packages/$packageName/$asset' // Asset from, and declared in $packageName.
|
||||||
: null; // Asset from the current application
|
: null; // Asset from the current application.
|
||||||
return new _Asset(base: assetBase, assetEntry: assetEntry, relativePath: asset);
|
return new _Asset(base: assetBase, assetEntry: assetEntry, relativePath: asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Asset _resolvePackageAsset(String asset, PackageMap packageMap) {
|
_Asset _resolvePackageAsset(String asset, PackageMap packageMap) {
|
||||||
assert(asset.startsWith('packages/'));
|
assert(asset.startsWith('packages/'));
|
||||||
String packageKey = asset.substring(9);
|
String packageKey = asset.substring('packages/'.length);
|
||||||
String relativeAsset = asset;
|
String relativeAsset = asset;
|
||||||
|
|
||||||
final int index = packageKey.indexOf('/');
|
final int index = packageKey.indexOf('/');
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
relativeAsset = packageKey.substring(index + 1);
|
relativeAsset = packageKey.substring(index + 1);
|
||||||
packageKey = packageKey.substring(0, index);
|
packageKey = packageKey.substring(0, index);
|
||||||
}
|
|
||||||
|
|
||||||
final Uri uri = packageMap.map[packageKey];
|
final Uri uri = packageMap.map[packageKey];
|
||||||
if (uri != null && uri.scheme == 'file') {
|
if (uri != null && uri.scheme == 'file') {
|
||||||
final File file = fs.file(uri);
|
final File file = fs.file(uri);
|
||||||
final String base = file.path.substring(0, file.path.length - 1);
|
final String base = file.path.substring(0, file.path.length - 1);
|
||||||
return new _Asset(base: base, assetEntry: asset, relativePath: relativeAsset);
|
return new _Asset(
|
||||||
|
base: base,
|
||||||
|
assetEntry: asset,
|
||||||
|
relativePath: relativeAsset,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printStatus('Error detected in pubspec.yaml:', emphasis: true);
|
printStatus('Error detected in pubspec.yaml:', emphasis: true);
|
||||||
printError('Could not resolve $packageKey for asset $asset.\n');
|
printError('Could not resolve package $packageKey for asset $asset.\n');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +93,8 @@ $assetsSection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
group('AssetBundle assets from package', () {
|
group('AssetBundle assets from packages', () {
|
||||||
testUsingContext('One package with no assets', () async {
|
testUsingContext('No assets are bundled when the package has no assets', () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile('pubspec.yaml', 'test');
|
writePubspecFile('pubspec.yaml', 'test');
|
||||||
@ -104,11 +104,35 @@ $assetsSection
|
|||||||
final AssetBundle bundle = new AssetBundle();
|
final AssetBundle bundle = new AssetBundle();
|
||||||
await bundle.build(manifestPath: 'pubspec.yaml');
|
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||||
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
||||||
}, overrides: <Type, Generator>{
|
final String expectedAssetManifest = '{}';
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
expect(
|
||||||
});
|
UTF8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
|
||||||
|
expectedAssetManifest,
|
||||||
|
);
|
||||||
|
}, overrides: contextOverrides);
|
||||||
|
|
||||||
testUsingContext('One package with one asset', () async {
|
testUsingContext('No assets are bundled when the package has an asset that is not listed', () async {
|
||||||
|
establishFlutterRoot();
|
||||||
|
|
||||||
|
writePubspecFile('pubspec.yaml', 'test');
|
||||||
|
writePackagesFile('test_package:p/p/lib/');
|
||||||
|
writePubspecFile('p/p/pubspec.yaml', 'test_package');
|
||||||
|
|
||||||
|
final List<String> assets = <String>['a/foo'];
|
||||||
|
writeAssets('p/p/', assets);
|
||||||
|
|
||||||
|
final AssetBundle bundle = new AssetBundle();
|
||||||
|
await bundle.build(manifestPath: 'pubspec.yaml');
|
||||||
|
expect(bundle.entries.length, 2); // LICENSE, AssetManifest
|
||||||
|
final String expectedAssetManifest = '{}';
|
||||||
|
expect(
|
||||||
|
UTF8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
|
||||||
|
expectedAssetManifest,
|
||||||
|
);
|
||||||
|
|
||||||
|
}, overrides: contextOverrides);
|
||||||
|
|
||||||
|
testUsingContext('One asset is bundled when the package has and lists one asset its pubspec', () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile('pubspec.yaml', 'test');
|
writePubspecFile('pubspec.yaml', 'test');
|
||||||
@ -130,11 +154,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('One package with one asset not specified', () async {
|
testUsingContext("One asset is bundled when the package has one asset, listed in the app's pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
final List<String> assetEntries = <String>['packages/test_package/a/foo'];
|
final List<String> assetEntries = <String>['packages/test_package/a/foo'];
|
||||||
@ -156,11 +178,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('One package with asset variants', () async {
|
testUsingContext("One asset and its variant are bundled when the package has an asset and a variant, and lists the asset in its pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile('pubspec.yaml', 'test');
|
writePubspecFile('pubspec.yaml', 'test');
|
||||||
@ -182,11 +202,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedManifest,
|
expectedManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('One package with asset variants not specified', () async {
|
testUsingContext("One asset and its variant are bundled when the package has an asset and a variant, and the app lists the asset in its pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile(
|
writePubspecFile(
|
||||||
@ -211,11 +229,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedManifest,
|
expectedManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('One package with two assets', () async {
|
testUsingContext("Two assets are bundled when the package has and lists two assets in its pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile('pubspec.yaml', 'test');
|
writePubspecFile('pubspec.yaml', 'test');
|
||||||
@ -238,11 +254,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('One package with two assets not specified', () async {
|
testUsingContext("Two assets are bundled when the package has two assets, listed in the app's pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
final List<String> assetEntries = <String>[
|
final List<String> assetEntries = <String>[
|
||||||
@ -272,11 +286,9 @@ $assetsSection
|
|||||||
<String>['test_package'],
|
<String>['test_package'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('Two packages with assets', () async {
|
testUsingContext("Two assets are bundled when two packages each have and list an asset their pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
writePubspecFile(
|
writePubspecFile(
|
||||||
@ -310,11 +322,9 @@ $assetsSection
|
|||||||
<String>['test_package', 'test_package2'],
|
<String>['test_package', 'test_package2'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('Two packages with assets not specified', () async {
|
testUsingContext("Two assets are bundled when two packages each have an asset, listed in the app's pubspec", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
|
|
||||||
final List<String> assetEntries = <String>[
|
final List<String> assetEntries = <String>[
|
||||||
@ -351,11 +361,9 @@ $assetsSection
|
|||||||
<String>['test_package', 'test_package2'],
|
<String>['test_package', 'test_package2'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('Transitive asset dependency', () async {
|
testUsingContext("One asset is bundled when the app depends on a package, listing in its pubspec an asset from another package", () async {
|
||||||
establishFlutterRoot();
|
establishFlutterRoot();
|
||||||
writePubspecFile(
|
writePubspecFile(
|
||||||
'pubspec.yaml',
|
'pubspec.yaml',
|
||||||
@ -365,7 +373,7 @@ $assetsSection
|
|||||||
writePubspecFile(
|
writePubspecFile(
|
||||||
'p/p/pubspec.yaml',
|
'p/p/pubspec.yaml',
|
||||||
'test_package',
|
'test_package',
|
||||||
assets: <String>['packages/test_package2/a/foo']
|
assets: <String>['packages/test_package2/a/foo'],
|
||||||
);
|
);
|
||||||
writePubspecFile(
|
writePubspecFile(
|
||||||
'p2/p/pubspec.yaml',
|
'p2/p/pubspec.yaml',
|
||||||
@ -384,8 +392,10 @@ $assetsSection
|
|||||||
<String>['test_package2'],
|
<String>['test_package2'],
|
||||||
expectedAssetManifest,
|
expectedAssetManifest,
|
||||||
);
|
);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: contextOverrides);
|
||||||
FileSystem: () => new MemoryFileSystem(),
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<Type, Generator> get contextOverrides => <Type, Generator>{
|
||||||
|
FileSystem: () => new MemoryFileSystem()
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user