From 2f06bf9c4daf46e97c9a0719582b1f8e380295e9 Mon Sep 17 00:00:00 2001 From: bohdanprog Date: Mon, 6 May 2024 12:03:45 +0200 Subject: [PATCH] removed unnecessary patch for rn-svg, added compact flag to babel, add comments and blockList to metro config --- babel.config.js | 2 + metro.config.js | 14 +++-- .../react-native-svg-transformer+1.3.0.patch | 59 ------------------- 3 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 patches/react-native-svg-transformer+1.3.0.patch diff --git a/babel.config.js b/babel.config.js index b3d8ea5bf..23bf558f0 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,8 @@ module.exports = function (api) { api.cache(true); return { + //https://github.com/babel/babel/discussions/13676#discussioncomment-1183149 + compact: true, presets: ['babel-preset-expo'], plugins: [ 'transform-inline-environment-variables', diff --git a/metro.config.js b/metro.config.js index abf1c28f1..1a3fc9186 100644 --- a/metro.config.js +++ b/metro.config.js @@ -1,19 +1,25 @@ const {getDefaultConfig} = require('expo/metro-config'); const path = require('path'); -module.exports = (() => { - const projectRoot = __dirname; - const workspaceRoot = path.resolve(projectRoot); - const config = getDefaultConfig(__dirname); +const projectRoot = __dirname; +const workspaceRoot = path.resolve(projectRoot); + +/** @type {import('expo/metro-config').MetroConfig} */ +const config = getDefaultConfig(__dirname); +module.exports = (() => { const {transformer, resolver} = config; config.transformer = { ...transformer, + // For https://github.com/kristerkari/react-native-svg-transformer babelTransformerPath: require.resolve('react-native-svg-transformer'), }; config.resolver = { ...resolver, + // For nodejs-mobile + blockList: [/nodejs-assets\/.*/], + // For https://github.com/kristerkari/react-native-svg-transformer assetExts: resolver.assetExts.filter(ext => ext !== 'svg'), sourceExts: [...resolver.sourceExts, 'svg'], }; diff --git a/patches/react-native-svg-transformer+1.3.0.patch b/patches/react-native-svg-transformer+1.3.0.patch deleted file mode 100644 index d957d7989..000000000 --- a/patches/react-native-svg-transformer+1.3.0.patch +++ /dev/null @@ -1,59 +0,0 @@ -diff --git a/node_modules/react-native-svg-transformer/index.js b/node_modules/react-native-svg-transformer/index.js -index ac1fe67..3a32824 100644 ---- a/node_modules/react-native-svg-transformer/index.js -+++ b/node_modules/react-native-svg-transformer/index.js -@@ -1,6 +1,11 @@ - const { resolveConfig, transform } = require("@svgr/core"); - const resolveConfigDir = require("path-dirname"); - -+// Implementation uses a fragile approach to figure out which babel transformer to use -+// Make it use the one tied to React Native CLI, which is what's used to bundle our app -+// https://github.com/kristerkari/react-native-svg-transformer/issues/333 -+const babelTransformer = require("@react-native/metro-babel-transformer"); -+ - /** - * `metro-react-native-babel-transformer` has recently been migrated to the React Native - * repository and published under the `@react-native/metro-babel-transformer` name. -@@ -9,17 +14,17 @@ const resolveConfigDir = require("path-dirname"); - * Additionally, Expo v50.0.0 has begun using @expo/metro-config/babel-transformer as its upstream transformer. - * To avoid breaking projects, we should prioritze that package if it is available. - */ --const upstreamTransformer = (() => { -- try { -- return require("@expo/metro-config/babel-transformer"); -- } catch (error) { -- try { -- return require("@react-native/metro-babel-transformer"); -- } catch (error) { -- return require("metro-react-native-babel-transformer"); -- } -- } --})(); -+// const upstreamTransformer = (() => { -+// try { -+// return require("@expo/metro-config/babel-transformer"); -+// } catch (error) { -+// try { -+// return require("@react-native/metro-babel-transformer"); -+// } catch (error) { -+// return require("metro-react-native-babel-transformer"); -+// } -+// } -+// })(); - - const defaultSVGRConfig = { - native: true, -@@ -49,11 +54,11 @@ module.exports.transform = async ({ src, filename, options }) => { - const svgrConfig = config - ? { ...defaultSVGRConfig, ...config } - : defaultSVGRConfig; -- return upstreamTransformer.transform({ -+ return babelTransformer.transform({ - src: await transform(src, svgrConfig), - filename, - options - }); - } -- return upstreamTransformer.transform({ src, filename, options }); -+ return babelTransformer.transform({ src, filename, options }); - };