Skip to content

Commit cc93396

Browse files
committed
fix: add additional check for codegenNativeComponent
see #625 (comment)
1 parent 7b60480 commit cc93396

11 files changed

+39
-17
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
2+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');

packages/react-native-builder-bob/src/__fixtures__/project/code/$exports-output.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export type { A } from "./a";
1313
export const foo = "foo";
1414
const bar = "bar";
1515
export { bar };
16-
export * as NativeLibA from "./NativeMyLib";
17-
export * as NativeLibB from "../NativeMyLib";
18-
export * as NativeLibC from "./NativeMyLib.ts";
19-
export * as NativeLibD from "../NativeMyLib.ts";
20-
export * as NativeLibE from "./NativeMyLib.tsx";
21-
export * as NativeLibF from "../NativeMyLib.tsx";
16+
export * as NativeLibA from "./NativeMyLib.mjs";
17+
export * as NativeLibB from "../NativeMyLib.mjs";
18+
export * as NativeLibC from "./NativeMyLib.mjs";
19+
export * as NativeLibD from "../NativeMyLib.mjs";
20+
export * as NativeLibE from "./NativeMyLib.mjs";
21+
export * as NativeLibF from "../NativeMyLib.mjs";
2222
export * as NativeLibG from "./NativeMyLib.js";
2323
export * as NativeLibH from "../NativeMyLib.js";
2424
export * as NativeLibI from "./NativeMyLib.jsx";

packages/react-native-builder-bob/src/__fixtures__/project/code/$imports-output.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { a as a1 } from "./a.mjs";
1212
import * as b1 from "./b.mjs";
1313
import something, { c as c1 } from "./c.mjs";
1414
import type { A } from "./a";
15-
import "./NativeMyLib";
16-
import "../NativeMyLib";
17-
import "./NativeMyLib.ts";
18-
import "../NativeMyLib.ts";
19-
import "./NativeMyLib.tsx";
20-
import "../NativeMyLib.tsx";
15+
import "./NativeMyLib.mjs";
16+
import "../NativeMyLib.mjs";
17+
import "./NativeMyLib.mjs";
18+
import "../NativeMyLib.mjs";
19+
import "./NativeMyLib.mjs";
20+
import "../NativeMyLib.mjs";
2121
import "./NativeMyLib.js";
2222
import "../NativeMyLib.js";
2323
import "./NativeMyLib.jsx";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default codegenNativeComponent<NativeProps>('Test');
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
export const isCodegenSpec = (filepath: string) => {
2-
return /(?:^|[\\/])(?:Native\w+|(\w+)NativeComponent)\.[jt]sx?$/i.test(
3-
filepath
4-
);
5-
};
1+
import fs from 'fs-extra';
2+
3+
export function isCodegenSpec(filepath: string): boolean {
4+
const looksLikeCodgenSpec =
5+
/(?:^|[\\/])(?:(\w+)NativeComponent)\.[jt]sx?$/i.test(filepath);
6+
7+
if (looksLikeCodgenSpec) {
8+
// This is used in the babel plugin so needs to be synchronous
9+
const content = fs.readFileSync(filepath, 'utf8');
10+
11+
// Regex taken from https://github.com/facebook/react-native/blob/271232d85654cee32322b1c8a3a39ef647ad02e2/packages/react-native-babel-preset/src/configs/main.js#L78C24-L78C47
12+
if (/\bcodegenNativeComponent</.test(content)) {
13+
return true;
14+
}
15+
}
16+
17+
return false;
18+
}

0 commit comments

Comments
 (0)