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

feat(cli, router, metro, asset): add basePath support #23911

Merged
merged 36 commits into from
Sep 14, 2023

Conversation

EvanBacon
Copy link
Contributor

@EvanBacon EvanBacon commented Aug 10, 2023

Why

How

  • Add expo.experiments.basePath which can be used during npx expo export to modify how assets are referenced.

  • Set the publicPath in Metro to output as expected.

  • Add custom asset writing for web to support stripping the unused prefix.

  • It's unclear if this should also apply to native, and if we should have platform-specific variations.

  • Update Expo Router to support automatically adjusting paths to support basePath in production builds.

Test Plan

  • New expo export test.

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Aug 10, 2023
@linear
Copy link

linear bot commented Aug 21, 2023

ENG-9193 Add assetPrefix for deploying from subpaths

This would support GH Pages deployment

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about bot: suggestions ExpoBot has some suggestions and removed bot: suggestions ExpoBot has some suggestions bot: passed checks ExpoBot has nothing to complain about labels Aug 21, 2023
EvanBacon added a commit that referenced this pull request Aug 24, 2023
# Why

<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

- Prevent writing a `metadata.json` and `bundles/web-xxx.js` with static
Metro web.
- We have two systems for exporting with Metro in here, just haven't had
time to migrate native over to use the new one. Also haven't had time to
add sourcemap support or asset manifests to the new one either.
- Split out of #23911


# How

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
EvanBacon added a commit that referenced this pull request Aug 24, 2023
# Why

<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

- Prevent writing a `metadata.json` and `bundles/web-xxx.js` with static
Metro web.
- We have two systems for exporting with Metro in here, just haven't had
time to migrate native over to use the new one. Also haven't had time to
add sourcemap support or asset manifests to the new one either.
- Split out of #23911


# How

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
EvanBacon added a commit that referenced this pull request Aug 26, 2023
# Why

Convert the `../` segments of the server URL to `_` to support
monorepos. This same transformation takes place in
`AssetSourceResolver.web` (expo-assets, expo-image) and
`persistMetroAssets` of Expo CLI, this originally came from the [Metro
opinion](https://github.com/react-native-community/cli/blob/2204d357379e2067cebe2791e90388f7e97fc5f5/packages/cli-plugin-metro/src/commands/bundle/getAssetDestPathIOS.ts#L19C5-L19C10).

The purpose is to ensure no URL like `/foo/../bar.png` is requested, as
the result would be `/bar.png` which wouldn't work. The of how to handle
this didn't come from us, but we do need to ensure it's unified. At a
high-level, this does prevent the usage of certain files, as
`/foo/../bar.png` will be `/foo/_bar.png`, meaning a file named
`/foo/_bar.png` cannot also exist. This logic, while applied at runtime,
is actually only valid for production exports as we don't move or alias
files in development. The only way to have valid development files is to
ensure `../` never appears in the URL, i.e. by using
`unstable_serverRoot`.

- Drop legacy `expo/tools/hashAssetFiles.js` in favor of `expo-asset`
version.
- Unify runtime logic of asset file loading for monorepos.
- Split out of #23911

<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

# How

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).
@expo-bot expo-bot added bot: suggestions ExpoBot has some suggestions and removed bot: passed checks ExpoBot has nothing to complain about labels Aug 26, 2023
@EvanBacon EvanBacon changed the title feat(cli): add asset prefix support feat(cli): add basePath support Aug 28, 2023
@EvanBacon EvanBacon changed the title feat(cli): add basePath support feat(cli, router, metro, font, asset): add basePath support Aug 28, 2023
@@ -250,6 +250,10 @@ export interface ExpoConfig {
* Enable experimental features that may be unstable, unsupported, or removed without deprecation notices.
*/
experiments?: {
/**
* Export a website relative to a subpath of a domain. The path will be prepended as-is to links to all bundled resources. Prefix the path with a `/` (recommended) to load all resources relative to the server root. If the path **does not** start with a `/` then resources will be loaded relative to the code that requests them, this could lead to unexpected behavior. Example '/subpath'. Defaults to '' (empty string).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should warn if the basePath is not absolute with an ENV to disable the warning. I'd rather help protect against typos than cater for an edge case

docs/pages/more/expo-cli.mdx Outdated Show resolved Hide resolved
docs/pages/more/expo-cli.mdx Outdated Show resolved Hide resolved
docs/pages/more/expo-cli.mdx Outdated Show resolved Hide resolved
docs/pages/more/expo-cli.mdx Outdated Show resolved Hide resolved
@EvanBacon EvanBacon mentioned this pull request Sep 11, 2023
3 tasks
EvanBacon added a commit that referenced this pull request Sep 12, 2023
# Why

- Split out of #23911
- This PR also adds server tests for static rendering.
- Make it easier to run and test e2e metro code.
<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

# How

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@EvanBacon EvanBacon merged commit 7c98c35 into main Sep 14, 2023
13 checks passed
@EvanBacon EvanBacon deleted the @evanbacon/cli/assetPrefix branch September 14, 2023 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

package.json "homepage" is not read by Metro Web support deploying to subfolders on web
4 participants