Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: example apps metro paths #2511

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions apps/fabric-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
4 changes: 2 additions & 2 deletions apps/fabric-macos-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
17 changes: 9 additions & 8 deletions apps/fabric-windows-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

/**
* Metro configuration
Expand All @@ -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'];
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/paper-macos-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions apps/paper-windows-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 7 additions & 11 deletions apps/tests-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand All @@ -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,
},
}),
},
Expand Down
8 changes: 4 additions & 4 deletions apps/web-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down