Fix bundling to use typescript files rather than js files #3934
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Platforms Impacted
Description of changes
We used to have the package.json main field pointing at src/index.ts, then we would change it to point to lib-commonjs/index.js on publish. This served to ensure that metro bundling used the typescript files directly when bundling. This avoids the need to build, while also ensuring fast-refresh worked correctly when changes were made. This was changed as part of modernizing the way modules were defined and referenced in the repo (which was previously hiding bugs) but had the downside of breaking fast-refresh in the repo.
Instead of the old system (with the custom publishing hook) instead I added "react-native": "src/index.ts" references to the packages. This will cause the metro bundler to use the typescript entry-point and causes fast-refresh to work again. This will also cause downstream consumers to use the typescript entry points in their builds as well which is good for type-checking, good for avoiding intermediate helpers being added as part of JS build targeting, and eventually good for allowing static hermes to better optimize the code.
Verification
Normal build & pipeline checks, also checked that bundling runs without building the repo first.