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: add transform react jsx automatic to node module rules #808

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-dragons-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": patch
---

Fix type JSX runtime transform when transpiling node modules
4 changes: 2 additions & 2 deletions apps/tester-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.84.0)
- callstack-repack (5.0.0-rc.0):
- callstack-repack (5.0.0-rc.2):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1852,7 +1852,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
callstack-repack: 75464b0e26467fc4a7236373399bc0fc2281f495
callstack-repack: 3106db24c24f7a76a380230ff7794d225cecb760
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
FBLazyVector: 7075bb12898bc3998fd60f4b7ca422496cc2cdf7
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
Expand Down
83 changes: 35 additions & 48 deletions packages/repack/src/rules/nodeModulesLoadingRules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
import type { RuleSetRule } from '@rspack/core';
import { getModulePaths } from '../utils';

const makeSwcLoaderConfig = (syntax: 'js' | 'ts', jsx: boolean) => ({
loader: 'builtin:swc-loader',
options: {
env: {
targets: { 'react-native': '0.74' },
},
jsc: {
externalHelpers: true,
loose: true,
parser:
syntax === 'js'
? { syntax: 'ecmascript', jsx: jsx }
: { syntax: 'typescript', tsx: jsx },
transform: {
react: {
runtime: 'automatic',
},
},
},
module: {
type: 'commonjs',
strict: false,
strictMode: false,
},
},
});

/**
* @constant NODE_MODULES_LOADING_RULES
* @type {RuleSetRule}
Expand All @@ -19,58 +46,18 @@ export const NODE_MODULES_LOADING_RULES: RuleSetRule = {
'react-native-tvos',
'@callstack/react-native-visionos',
]),
rules: [
oneOf: [
{
test: /jsx?$/,
use: [
{
loader: 'builtin:swc-loader',
options: {
env: {
targets: { 'react-native': '0.74' },
},
jsc: {
loose: true,
parser: {
syntax: 'ecmascript',
jsx: true,
},
externalHelpers: true,
},
module: {
type: 'commonjs',
strict: false,
strictMode: false,
},
},
},
],
use: [makeSwcLoaderConfig('js', true)],
},
{
test: /tsx?$/,
use: [
{
loader: 'builtin:swc-loader',
options: {
env: {
targets: { 'react-native': '0.74' },
},
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
loose: true,
externalHelpers: true,
},
module: {
type: 'commonjs',
strict: false,
strictMode: false,
},
},
},
],
test: /ts$/,
use: [makeSwcLoaderConfig('ts', false)],
},
{
test: /tsx$/,
use: [makeSwcLoaderConfig('ts', true)],
},
],
};
9 changes: 7 additions & 2 deletions packages/repack/src/rules/reactNativeLoadingRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ export const REACT_NATIVE_LOADING_RULES: RuleSetRule = {
targets: { 'react-native': '0.74' },
},
jsc: {
externalHelpers: true,
loose: true,
parser: {
syntax: 'ecmascript',
jsx: true,
exportDefaultFrom: true,
},
loose: true,
externalHelpers: true,
transform: {
react: {
runtime: 'automatic',
},
},
},
module: {
type: 'commonjs',
Expand Down
Loading