Skip to content

Commit

Permalink
Add support for RN 73 with backwards compatibility (#45)
Browse files Browse the repository at this point in the history
* add support for RN 73 with backwards compatibility

* fix typo

---------

Co-authored-by: Lukas Müller <[email protected]>
  • Loading branch information
WookieFPV and WookieFPV authored Jan 21, 2024
1 parent f4c0c37 commit f502aae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cli/getAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ const Server = require('metro/src/Server');
const { loadConfig } = require('metro-config');
const output = require('metro/src/shared/output/bundle');

const getBabelTransformerPath = () => {
try {
// for RN 73+
return require.resolve('@react-native/metro-babel-transformer');
} catch (e) {
// to ensure backwards compatibility with old RN versions (RN < 73)
return require.resolve('metro-react-native-babel-transformer');
}
}

async function getAssets(options) {
const args = {
entryFile: options.entryFile,
Expand All @@ -22,9 +32,7 @@ async function getAssets(options) {
},
transformer: {
allowOptionalDependencies: true,
babelTransformerPath: require.resolve(
'metro-react-native-babel-transformer'
),
babelTransformerPath: getBabelTransformerPath(),
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
},
}
Expand Down

0 comments on commit f502aae

Please sign in to comment.