From f8dc1dd1726fb74c4be61e9cc02029817cac2463 Mon Sep 17 00:00:00 2001 From: Jakub Grzywacz Date: Fri, 25 Oct 2024 18:35:09 +0200 Subject: [PATCH] fix: example apps metro --- apps/fabric-example/metro.config.js | 9 +++------ apps/fabric-macos-example/metro.config.js | 4 ++-- apps/fabric-windows-example/metro.config.js | 17 +++++++++-------- apps/paper-macos-example/metro.config.js | 2 +- apps/paper-windows-example/metro.config.js | 4 ++-- apps/tests-example/metro.config.js | 18 +++++++----------- apps/web-example/metro.config.js | 8 ++++---- 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/apps/fabric-example/metro.config.js b/apps/fabric-example/metro.config.js index f71cdbe26..d227bdba5 100644 --- a/apps/fabric-example/metro.config.js +++ b/apps/fabric-example/metro.config.js @@ -2,19 +2,16 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); /** * Metro configuration - * https://facebook.github.io/metro/docs/configuration + * https://reactnative.dev/docs/metro * * @type {import('metro-config').MetroConfig} */ - -/* eslint-disable import/no-commonjs */ - const path = require('path'); const exclusionList = require('metro-config/src/defaults/exclusionList'); const escape = require('escape-string-regexp'); -const pack = require('../package.json'); +const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const modules = [...Object.keys(pack.peerDependencies)]; diff --git a/apps/fabric-macos-example/metro.config.js b/apps/fabric-macos-example/metro.config.js index ba5f7c8ae..ad3bfb306 100644 --- a/apps/fabric-macos-example/metro.config.js +++ b/apps/fabric-macos-example/metro.config.js @@ -9,9 +9,9 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); const path = require('path'); const exclusionList = require('metro-config/src/defaults/exclusionList'); -const pack = require('../package.json'); +const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const modules = [...Object.keys(pack.peerDependencies), 'react-native-macos']; diff --git a/apps/fabric-windows-example/metro.config.js b/apps/fabric-windows-example/metro.config.js index 86edefa74..e922a7b3b 100644 --- a/apps/fabric-windows-example/metro.config.js +++ b/apps/fabric-windows-example/metro.config.js @@ -1,4 +1,4 @@ -const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); +const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); /** * Metro configuration @@ -9,14 +9,14 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); const path = require('path'); const exclusionList = require('metro-config/src/defaults/exclusionList'); const escape = require('escape-string-regexp'); -const pack = require('../package.json'); +const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const fs = require('fs'); const rnwPath = fs.realpathSync( - path.resolve(require.resolve('react-native-windows/package.json'), '..') + path.resolve(require.resolve('react-native-windows/package.json'), '..'), ); const modules = [...Object.keys(pack.peerDependencies), 'react-native-windows']; @@ -30,16 +30,17 @@ const config = { resolver: { blockList: exclusionList( modules.map( - (m) => - new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) + m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`), ), // This stops "react-native run-windows" from causing the metro server to // crash if its already running - new RegExp(`${path.join(__dirname, 'windows').replace(/[/\\]+/g, '/')}.*`), + new RegExp( + `${path.join(__dirname, 'windows').replace(/[/\\]+/g, '/')}.*`, + ), // This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip or other files produced by msbuild new RegExp(`${rnwPath}/build/.*`), new RegExp(`${rnwPath}/target/.*`), - /.*\.ProjectImports\.zip/ + /.*\.ProjectImports\.zip/, ), nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')], extraNodeModules: modules.reduce((acc, name) => { diff --git a/apps/paper-macos-example/metro.config.js b/apps/paper-macos-example/metro.config.js index b78a15447..ad3bfb306 100644 --- a/apps/paper-macos-example/metro.config.js +++ b/apps/paper-macos-example/metro.config.js @@ -11,7 +11,7 @@ const exclusionList = require('metro-config/src/defaults/exclusionList'); const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const modules = [...Object.keys(pack.peerDependencies), 'react-native-macos']; diff --git a/apps/paper-windows-example/metro.config.js b/apps/paper-windows-example/metro.config.js index 3311da21b..d84f77dd2 100644 --- a/apps/paper-windows-example/metro.config.js +++ b/apps/paper-windows-example/metro.config.js @@ -9,9 +9,9 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); const path = require('path'); const exclusionList = require('metro-config/src/defaults/exclusionList'); const escape = require('escape-string-regexp'); -const pack = require('../package.json'); +const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const fs = require('fs'); diff --git a/apps/tests-example/metro.config.js b/apps/tests-example/metro.config.js index 997fe73f3..d227bdba5 100644 --- a/apps/tests-example/metro.config.js +++ b/apps/tests-example/metro.config.js @@ -6,14 +6,12 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); * * @type {import('metro-config').MetroConfig} */ -/* eslint-disable import/no-commonjs */ - const path = require('path'); const exclusionList = require('metro-config/src/defaults/exclusionList'); const escape = require('escape-string-regexp'); -const pack = require('../package.json'); +const pack = require('../../package.json'); -const root = path.resolve(__dirname, '..'); +const root = path.resolve(__dirname, '../..'); const projectNodeModules = path.join(__dirname, 'node_modules'); const modules = [...Object.keys(pack.peerDependencies)]; @@ -32,19 +30,17 @@ const config = { ) ), nodeModulesPaths: [projectNodeModules, path.join(__dirname, '../../')], - extraNodeModules: modules.reduce( - (acc, name) => { - acc[name] = path.join(__dirname, 'node_modules', name); - return acc; - }, - { 'react-native-svg': `${__dirname}/../` } - ), + extraNodeModules: modules.reduce((acc, name) => { + acc[name] = path.join(__dirname, 'node_modules', name); + return acc; + }, {}), }, transformer: { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, + inlineRequires: true, }, }), }, diff --git a/apps/web-example/metro.config.js b/apps/web-example/metro.config.js index 47f7e7967..36593ece0 100644 --- a/apps/web-example/metro.config.js +++ b/apps/web-example/metro.config.js @@ -9,16 +9,16 @@ const config = getDefaultConfig(__dirname); // excludes the one from the parent folder when bundling. config.resolver.blockList = [ ...Array.from(config.resolver.blockList ?? []), - new RegExp(path.resolve('..', 'node_modules', 'react-native')), - new RegExp(path.resolve('..', 'node_modules', 'react')), + new RegExp(path.resolve('../..', 'node_modules', 'react-native')), + new RegExp(path.resolve('../..', 'node_modules', 'react')), ]; config.resolver.nodeModulesPaths = [ path.resolve(__dirname, './node_modules'), - path.resolve(__dirname, '../node_modules'), + path.resolve(__dirname, '../../node_modules'), ]; -config.watchFolders = [path.resolve(__dirname, '..')]; +config.watchFolders = [path.resolve(__dirname, '../..')]; config.transformer.getTransformOptions = async () => ({ transform: {