Skip to content

Commit c798f70

Browse files
committed
Revert "fix: skip compiling fabric view as react native freaks out (#720)"
This reverts commit 2ec645b.
1 parent c999fb2 commit c798f70

File tree

7 files changed

+672
-55
lines changed

7 files changed

+672
-55
lines changed

packages/react-native-builder-bob/babel-config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,7 @@ const getConfig = (defaultConfig, { root, pkg }) => {
6161
},
6262
{
6363
include: path.join(root, src),
64-
presets: [
65-
[
66-
require.resolve('./babel-preset'),
67-
{
68-
// Let the app's preset handle the commonjs transform
69-
// Otherwise this causes issues with `@react-native/babel-plugin-codegen`
70-
// Codegen generates `export` statements in wrong places causing syntax error
71-
supportsStaticESM: true,
72-
},
73-
],
74-
],
64+
presets: [require.resolve('./babel-preset')],
7565
},
7666
],
7767
};

packages/react-native-builder-bob/babel-preset.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ const browserslist = require('browserslist');
44

55
/**
66
* Babel preset for React Native Builder Bob
7-
*
8-
* @param {Boolean} options.supportsStaticESM - Whether to preserve ESM imports/exports, defaults to `false`
9-
* @param {Boolean} options.rewriteImportExtensions - Whether to rewrite import extensions to '.js', defaults to `false`
10-
* @param {'automatic' | 'classic'} options.jsxRuntime - Which JSX runtime to use, defaults to 'automatic'
117
*/
128
module.exports = function (api, options, cwd) {
139
const opt = (name) =>
14-
options[name] !== undefined
15-
? options[name]
16-
: api.caller((caller) => (caller != null ? caller[name] : undefined));
10+
api.caller((caller) => (caller != null ? caller[name] : undefined));
1711

1812
const supportsStaticESM = opt('supportsStaticESM');
1913
const rewriteImportExtensions = opt('rewriteImportExtensions');
@@ -53,6 +47,7 @@ module.exports = function (api, options, cwd) {
5347
require.resolve('@babel/preset-flow'),
5448
],
5549
plugins: [
50+
require.resolve('@react-native/babel-plugin-codegen'),
5651
require.resolve('@babel/plugin-transform-strict-mode'),
5752
[
5853
require.resolve('./lib/babel'),

packages/react-native-builder-bob/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@babel/preset-flow": "^7.24.7",
5252
"@babel/preset-react": "^7.24.7",
5353
"@babel/preset-typescript": "^7.24.7",
54+
"@react-native/babel-plugin-codegen": "^0.76.3",
5455
"babel-plugin-module-resolver": "^5.0.2",
5556
"browserslist": "^4.20.4",
5657
"cosmiconfig": "^9.0.0",

packages/react-native-builder-bob/src/babel.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
ExportAllDeclaration,
77
ExportNamedDeclaration,
88
} from '@babel/types';
9-
import isFabricComponentFile from './utils/isFabricComponentFile';
109

1110
type Options = {
1211
/**
@@ -39,18 +38,17 @@ const isDirectory = (filename: string): boolean => {
3938
return exists;
4039
};
4140

42-
const checkExts = (
41+
const isModule = (
4342
filename: string,
4443
extension: string,
45-
platforms: string[],
46-
callback: (ext: string) => boolean
44+
platforms: string[]
4745
): boolean => {
4846
const exts = ['js', 'ts', 'jsx', 'tsx', extension];
4947

5048
return exts.some(
5149
(ext) =>
52-
callback(`${filename}.${ext}`) &&
53-
platforms.every((platform) => !callback(`${filename}.${platform}.${ext}`))
50+
isFile(`${filename}.${ext}`) &&
51+
platforms.every((platform) => !isFile(`${filename}.${platform}.${ext}`))
5452
);
5553
};
5654

@@ -114,29 +112,22 @@ export default function (
114112
node.source.value
115113
);
116114

117-
// Skip if file is a fabric view
118-
if (
119-
checkExts(filename, extension, platforms, (f) => isFabricComponentFile(f))
120-
) {
121-
return;
122-
}
123-
124115
// Replace .ts extension with .js if file with extension is explicitly imported
125116
if (isFile(filename)) {
126117
node.source.value = node.source.value.replace(/\.tsx?$/, `.${extension}`);
127118
return;
128119
}
129120

130121
// Add extension if .ts file or file with extension exists
131-
if (checkExts(filename, extension, platforms, isFile)) {
122+
if (isModule(filename, extension, platforms)) {
132123
node.source.value += `.${extension}`;
133124
return;
134125
}
135126

136127
// Expand folder imports to index and add extension
137128
if (
138129
isDirectory(filename) &&
139-
checkExts(path.join(filename, 'index'), extension, platforms, isFile)
130+
isModule(path.join(filename, 'index'), extension, platforms)
140131
) {
141132
node.source.value = node.source.value.replace(
142133
/\/?$/,

packages/react-native-builder-bob/src/utils/compile.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import kleur from 'kleur';
44
import * as babel from '@babel/core';
55
import glob from 'glob';
66
import type { Input } from '../types';
7-
import isFabricComponentFile from './isFabricComponentFile';
87

98
type Options = Input & {
109
esm?: boolean;
@@ -96,13 +95,6 @@ export default async function compile({
9695
return;
9796
}
9897

99-
if (isFabricComponentFile(filepath)) {
100-
// React Native wants to handle compiling the file for fabric components
101-
// So we just copy it over as is
102-
fs.copy(filepath, path.join(output, path.relative(source, filepath)));
103-
return;
104-
}
105-
10698
const content = await fs.readFile(filepath, 'utf-8');
10799
const result = await babel.transformAsync(content, {
108100
caller: {

packages/react-native-builder-bob/src/utils/isFabricComponentFile.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)