-
Notifications
You must be signed in to change notification settings - Fork 629
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(config): support typescript configs #1233
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1233 +/- ##
=======================================
Coverage 83.45% 83.45%
=======================================
Files 207 207
Lines 10712 10713 +1
Branches 2669 2669
=======================================
+ Hits 8940 8941 +1
Misses 1772 1772 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, this would be a nice feature.
I do have some concerns about the dependency on jiti here - it's a very oddly assembled package that claims zero dependencies, but actually bundles (some version of) Babel as a 1.6MB file, discarding its licence in the process: https://unpkg.com/browse/jiti@1.21.0/dist/ .
That, and the fact that it's modifying the environment enough to break tests in weird ways, means we really can't accept a dependency on it.
As a possible alternative, transforming files is somewhat within Metro's wheelhouse - we obviously already have a dependency on Babel - and based on https://github.com/Codex-/cosmiconfig-typescript-loader/blob/main/lib/loader.ts it looks like implementing a loader is pretty straightforward - if it's only a few lines (plus tests), and a Babel plugin to roll our own, that might be the best option.
Aside: We're planning to update cosmiconfig for ESM support but are currently blocked by a Node<20 bug, details: react-native-community/cli#2167 (comment)
Allowing the user to user ts config will reduce configuration mistakes
Curious what you mean by this - I can see that TS would be nicer both syntactically and for consistency, but TS should already be checking the JSDoc types in metro.config.js - it's a template bug if not. Was it not working for you?
2. `metro.config.json` | ||
3. The `metro` field in `package.json` | ||
2. `metro.config.ts` | ||
3. `metro.config.cjs` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - we should land this docs fix regardless.
Summary
Allowing the user to user ts config will reduce configuration mistakes
I had to revert 05b9ed4 as jiti uses os.tmpdir and it would conflict. But it seems to be running fine with node 18/20 at least
Test plan
Unsure how to test this, but the code seems pretty straightforward
Happy to discuss if testing is needed