From b93d5343486874400d227692daf4d927320a85b3 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 20 Dec 2022 00:26:22 +0100 Subject: [PATCH] Fix symlink test --- build_runner_core/lib/src/asset/writer.dart | 46 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/build_runner_core/lib/src/asset/writer.dart b/build_runner_core/lib/src/asset/writer.dart index f5b41f051..1c3f32e3b 100644 --- a/build_runner_core/lib/src/asset/writer.dart +++ b/build_runner_core/lib/src/asset/writer.dart @@ -44,7 +44,17 @@ class DelayedAssetWriter implements RunnerAssetWriter { /// Obtain a [RunnerAssetReader] capable of reading pending writes of this /// writer (before they are persisted with [onBuildComplete]). RunnerAssetReader reader(RunnerAssetReader delegate, String rootPackage) { - return _DelayAwareReader(delegate, this, rootPackage); + final reader = _DelayAwareReader(delegate, this, rootPackage); + + if (delegate is PathProvidingAssetReader) { + // `createMergedOutputDirectories` needs a path providing asset reader, so + // keep that interface intact if we're wrapping a reader capable of doing + // that. + return _PathProvidingDelayAwareReader( + reader, delegate as PathProvidingAssetReader); + } else { + return reader; + } } @override @@ -136,3 +146,37 @@ class _DelayAwareReader extends AssetReader implements RunnerAssetReader { return encoding.decode(await readAsBytes(id)); } } + +class _PathProvidingDelayAwareReader extends AssetReader + with RunnerAssetReader + implements PathProvidingAssetReader { + final _DelayAwareReader _reader; + final PathProvidingAssetReader _original; + + _PathProvidingDelayAwareReader(this._reader, this._original); + + @override + Future canRead(AssetId id) { + return _reader.canRead(id); + } + + @override + Stream findAssets(Glob glob, {String? package}) { + return _reader.findAssets(glob, package: package); + } + + @override + String pathTo(AssetId id) { + return _original.pathTo(id); + } + + @override + Future> readAsBytes(AssetId id) { + return _reader.readAsBytes(id); + } + + @override + Future readAsString(AssetId id, {Encoding encoding = utf8}) { + return _reader.readAsString(id, encoding: encoding); + } +}