Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundling assets with a path outside of the project root #939

Merged
merged 1 commit into from
Mar 11, 2020

Conversation

janicduplessis
Copy link
Contributor

Summary:

When an asset is outside of the metro project root, it can lead to relative paths like /assets/../../node_modules/coolpackage/image.png as the httpServerLocation. This can happen for example when using yarn workspaces with hoisted node_modules.

This causes issues when bundling on iOS since we use this path in the filesystem. To avoid this we replace ../ with _ to preserve the uniqueness of the path while avoiding these kind of problematic relative paths. The same logic is used when bundling assets in the rn-cli.

RN part of this PR: facebook/react-native#27932

Test Plan:

Tested that an asset in a hoisted node_modules package doesn't show up before this patch and does after in a release build.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Feb 3, 2020
Summary:
When an asset is outside of the metro project root, it can lead to relative paths like `/assets/../../node_modules/coolpackage/image.png` as the `httpServerLocation`. This can happen for example when using yarn workspaces with hoisted node_modules.

This causes issues when bundling on iOS since we use this path in the filesystem. To avoid this we replace `../` with `_` to preserve the uniqueness of the path while avoiding these kind of problematic relative paths. The same logic is used when bundling assets in the rn-cli.

CLI part of this PR: react-native-community/cli#939

## Changelog

[General] [Fixed] - Fix resolving assets outside of the project root
Pull Request resolved: #27932

Test Plan: Tested that an asset in a hoisted node_modules package doesn't show up before this patch and does after in a release build.

Differential Revision: D19690587

Pulled By: cpojer

fbshipit-source-id: 8a9c68af04594ce1503a810ecf2e97ef5bfb8004
@grabbou
Copy link
Member

grabbou commented Feb 5, 2020

Sounds good, thanks! I'll wait with this one before I release 0.62 of the CLI off master. This is going to go for next React Native release to sync with that diff.

@janicduplessis
Copy link
Contributor Author

RN part of the PR was merged on Feb 3rd

osdnk pushed a commit to osdnk/react-native that referenced this pull request Mar 9, 2020
Summary:
When an asset is outside of the metro project root, it can lead to relative paths like `/assets/../../node_modules/coolpackage/image.png` as the `httpServerLocation`. This can happen for example when using yarn workspaces with hoisted node_modules.

This causes issues when bundling on iOS since we use this path in the filesystem. To avoid this we replace `../` with `_` to preserve the uniqueness of the path while avoiding these kind of problematic relative paths. The same logic is used when bundling assets in the rn-cli.

CLI part of this PR: react-native-community/cli#939

## Changelog

[General] [Fixed] - Fix resolving assets outside of the project root
Pull Request resolved: facebook#27932

Test Plan: Tested that an asset in a hoisted node_modules package doesn't show up before this patch and does after in a release build.

Differential Revision: D19690587

Pulled By: cpojer

fbshipit-source-id: 8a9c68af04594ce1503a810ecf2e97ef5bfb8004
@thymikee
Copy link
Member

Is this backwards compatible? I can see it wasn't picked for 0.62 release (should it be?), so we could merge it to next branch once it's sorted out, or if it doesn't break anybody include in 4.x and have it available for people using 0.62

@janicduplessis
Copy link
Contributor Author

Yes, using paths outside the root is currently broken and it doesn't change the behaviour of paths inside the project root.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase so that tests appear green and I think we're good merging it :)

@thymikee thymikee removed the on hold label Mar 11, 2020
@janicduplessis
Copy link
Contributor Author

Done, tests passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants