Skip to content

Commit

Permalink
fix(vite-flow): fix metro-preset resolve logic for monorepos
Browse files Browse the repository at this point in the history
  • Loading branch information
natew committed Dec 27, 2024
1 parent 54af604 commit a3f525f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/vite-flow/src/transformFlowBabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ export async function transformFlowBabel(
input: string,
{ development = false }: { development?: boolean } = {}
) {
let metroPresetPath = 'module:metro-react-native-babel-preset'

try {
// the above doesn't work in some monorepos so lets try resolving it specifically ourselves
// has to be relative to this package as it is installed below it
metroPresetPath = resolvePath('metro-react-native-babel-preset', resolvePath('@vxrn/vite-flow'))
} catch (err) {
// fallback to original
}

return await new Promise<string>((res, rej) => {
babel.transform(
input,
{
filename: 'file.js', // this is required for @react-native/babel-plugin-codegen to work.
presets: [
[
resolvePath('metro-react-native-babel-preset'),
metroPresetPath,
{
// To use the `@babel/plugin-transform-react-jsx` plugin for JSX.
useTransformReactJSXExperimental: true,
Expand Down

0 comments on commit a3f525f

Please sign in to comment.