Assets not picked up with multi project roots
@jeanlauliac is already working on this.
Since Oct 9, 2017.
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 696
- Avg merge
- 8m
- Merged PRs (30d)
- 7
Description
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
If you have a project setup with multiple roots and there are overlapping relative directories, assets are only picked up from directory in the first root.
Here is a failing testcase:
const server = new AssetServer({
projectRoots: ['/root', '/root2'],
assetExts: ['png'],
});
fs.__setMockFilesystem({
'root': {
imgs: {
'a.png': 'a image',
},
},
'root2': {
imgs: {
'b.png': 'b image',
},
},
});
return Promise.all([
server.get('imgs/a.png').then(data =>
expect(data).toBe('a image')
),
server.get('imgs/b.png').then(data =>
expect(data).toBe('b image')
),
]);
The test fails on not being able to find imgs/b.png, because internally _findRoot always returns the first matching path (imgs) and no b.png is present there.
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
Checkout the fork at https://github.com/AlbertBrand/metro-bundler
I added the above testcase to AssetServer-test.js that shows the issue.
What is the expected behavior?
I would expect the asset server to look in each project root for the asset. Or, even more correct: the AssetServer get call should take in account the root of the asset. If you then would refer to an asset from a specific root, it can directly resolve the correct one.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.