facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 626 forks source link

Fix bug in symlink traversal with indirect targets #1084

Closed robhogan closed 1 year ago

robhogan commented 1 year ago

Summary: Fixes a bug where symlinks beginning with indirections (../) may fail to traverse in some projectRoot / watchFolders configurations.

This occurs due to incomplete "normalisation" of a symlink target in metro-file-map, relative to the project root. Given a project root of /project and a symlink /project/src/link-to-foo -> ../../project/foo.js, we would normalise the target to ../project/foo.js rather than simply foo.js - we were not taking into account that further normalisation could be possible after joining with projectRoot.

"Normal" paths are defined as being fully normalised relative to the project root. The unnecessary indirection out and back into the project root fails because TreeFS is a DAG, and internally there is no entry for rootNode.get('..').get('project') - this would be a cycle back to rootNode.

Changelog:

 * **[Fix]:** Symlinks with indirections may not be resolvable

Differential Revision: D49323614

facebook-github-bot commented 1 year ago

This pull request was exported from Phabricator. Differential Revision: D49323614

facebook-github-bot commented 1 year ago

This pull request has been merged in facebook/metro@6f3f7e681a3f400c2332b92105812339e4dbf1f4.