History log of /expo/packages/@expo/cli/src/utils/tsconfig/resolveWithTsConfigPaths.ts (Results 1 – 1 of 1)
Revision Date Author Comments
# d8009c4b 24-Feb-2023 Evan Bacon <[email protected]>

feat(cli): add support for path aliases and absolute imports (#21262)

# Why

- In Expo Router, you have to import outside of the `app` directory
which does not spark joy at scale (e.g. `../../../

feat(cli): add support for path aliases and absolute imports (#21262)

# Why

- In Expo Router, you have to import outside of the `app` directory
which does not spark joy at scale (e.g. `../../../../../../`).
- This is pretty standard functionality in web development, feels odd
not having it in our "Metro for web" system.

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

# How

- Add support for `compilerOptions.baseUrl` from `tsconfig.json` and
`jsconfig.json` files to Metro. This enables absolute imports.
- Add support for `compilerOptions.paths` aliases from `tsconfig.json`
and `jsconfig.json` files to Metro. This enables path aliases. Tried to
keep the implementation as close to TypeScript as possible to reduce
maintenance.
- Absolute imports utilize built-in Metro behavior making it more
reliable. We basically just register the baseUrl as a location to search
for node modules.
- Couldn't decide where to document the feature so I put it in multiple
places.
- We might need to update expo jest to have similar functionality in the
future (it might already support these fields, didn't check).


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

# Test Plan

- Added some unit tests for path aliases (non-exhaustive).
- For correctness, you can use this feature in vscode and all
autocomplete suggestions should work as the bundling now matches the
built-in resolution.

<!--
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 `expo prebuild` & EAS Build (eg:
updated a module plugin).

---------

Co-authored-by: Expo Bot <[email protected]>

show more ...