Skip to content

Commit cdf942d

Browse files
committed
fix metro configs for examples
1 parent a81f198 commit cdf942d

File tree

5 files changed

+66
-28
lines changed

5 files changed

+66
-28
lines changed

example/metro.config.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
1+
const MetroConfig = require('@rnx-kit/metro-config');
22

33
const fs = require('fs');
44
const path = require('path');
5-
const exclusionList = require('metro-config/src/defaults/exclusionList');
65

76
const rnwPath = fs.realpathSync(
87
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
98
);
109

10+
//
11+
1112
/**
1213
* Metro configuration
1314
* https://facebook.github.io/metro/docs/configuration
@@ -16,22 +17,19 @@ const rnwPath = fs.realpathSync(
1617
*/
1718

1819
const config = {
20+
//
1921
resolver: {
20-
blockList: exclusionList([
21-
// This stops "react-native run-windows" from causing the metro server to crash if its already running
22+
blockList: MetroConfig.exclusionList([
23+
// This stops "npx @react-native-community/cli run-windows" from causing the metro server to crash if its already running
2224
new RegExp(
2325
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
2426
),
25-
// This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip or other files produced by msbuild
27+
// This prevents "npx @react-native-community/cli run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip or other files produced by msbuild
2628
new RegExp(`${rnwPath}/build/.*`),
2729
new RegExp(`${rnwPath}/target/.*`),
2830
/.*\.ProjectImports\.zip/,
2931
]),
30-
extraNodeModules: {
31-
'react-native-xaml': fs.realpathSync(
32-
path.dirname(require.resolve('react-native-xaml/package.json')),
33-
),
34-
},
32+
//
3533
},
3634
transformer: {
3735
getTransformOptions: async () => ({
@@ -40,9 +38,8 @@ const config = {
4038
inlineRequires: true,
4139
},
4240
}),
43-
// This fixes the 'missing-asset-registry-path` error (see https://github.com/microsoft/react-native-windows/issues/11437)
44-
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
4541
},
42+
projectRoot: __dirname,
4643
};
4744

48-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
45+
module.exports = MetroConfig.makeMetroConfig(config);

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@react-native/eslint-config": "0.77.0",
2626
"@react-native/metro-config": "0.77.0",
2727
"@react-native/typescript-config": "0.77.0",
28+
"@rnx-kit/metro-config": "^1.3.5",
2829
"@types/jest": "^29.5.13",
2930
"@types/react": "^18.2.6",
3031
"@types/react-test-renderer": "^18.0.0",

examplenuget/metro.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
1+
const MetroConfig = require('@rnx-kit/metro-config');
22

33
const fs = require('fs');
44
const path = require('path');
5-
const exclusionList = require('metro-config/src/defaults/exclusionList');
65

76
const rnwPath = fs.realpathSync(
87
path.resolve(require.resolve('react-native-windows/package.json'), '..'),
@@ -20,7 +19,7 @@ const rnwPath = fs.realpathSync(
2019
const config = {
2120
//
2221
resolver: {
23-
blockList: exclusionList([
22+
blockList: MetroConfig.exclusionList([
2423
// This stops "npx @react-native-community/cli run-windows" from causing the metro server to crash if its already running
2524
new RegExp(
2625
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
@@ -40,6 +39,7 @@ const config = {
4039
},
4140
}),
4241
},
42+
projectRoot: __dirname,
4343
};
4444

45-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
45+
module.exports = MetroConfig.makeMetroConfig(config);

examplenuget/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@react-native/eslint-config": "0.77.0",
2626
"@react-native/metro-config": "0.77.0",
2727
"@react-native/typescript-config": "0.77.0",
28+
"@rnx-kit/metro-config": "^1.3.5",
2829
"@types/jest": "^29.5.13",
2930
"@types/react": "^18.2.6",
3031
"@types/react-test-renderer": "^18.0.0",

yarn.lock

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,37 @@
24342434
invariant "^2.2.4"
24352435
nullthrows "^1.1.1"
24362436

2437+
"@rnx-kit/metro-config@^1.3.5":
2438+
version "1.3.17"
2439+
resolved "https://registry.yarnpkg.com/@rnx-kit/metro-config/-/metro-config-1.3.17.tgz#8efc69151161e0ce76b6966d3fc9de284a189391"
2440+
integrity sha512-OAQhevPAYkRcFtGHv8Fxl9P0rQhc3slcclmHHIsV6IYanqeIl8uW/djmLY27MBLu+uvjNCirc7XJ9sH9mUYuRQ==
2441+
dependencies:
2442+
"@rnx-kit/tools-node" "^2.0.0"
2443+
"@rnx-kit/tools-react-native" "^1.4.1"
2444+
"@rnx-kit/tools-workspaces" "^0.1.3"
2445+
2446+
"@rnx-kit/tools-node@^2.0.0", "@rnx-kit/tools-node@^2.0.1":
2447+
version "2.1.2"
2448+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-node/-/tools-node-2.1.2.tgz#8f854b0136beadfc8b8a6c2c8f5f0f0cfefadfc4"
2449+
integrity sha512-pCpiUpC/032ZoN4iFZFWtKp3Vrjma115nXwv2gyD2XFxj6DFyTX6pYjSK70xT7gwLMU0C3bZonN1JxiOBlGb0A==
2450+
2451+
"@rnx-kit/tools-react-native@^1.4.1":
2452+
version "1.4.2"
2453+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-react-native/-/tools-react-native-1.4.2.tgz#099972ecb705276d17fea72da5531f24271fe3a7"
2454+
integrity sha512-dzXMvJdOXWl6hyAem8TceinWIH5zEjCSj0lvtHx09fIPbFu9IjiFT6X8xBBmAOXixzu4FLJw1c41N78a2Q/yCg==
2455+
dependencies:
2456+
"@rnx-kit/tools-node" "^2.0.1"
2457+
2458+
"@rnx-kit/tools-workspaces@^0.1.3":
2459+
version "0.1.6"
2460+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-workspaces/-/tools-workspaces-0.1.6.tgz#94e5fb72c9857cf4a00d27e931b7ca5a362b4695"
2461+
integrity sha512-af5CYnc1dtnMIAl2u0U1QHUCGgLNN9ZQkYCAtQOHPxxgF5yX2Cr9jrXLZ9M+/h/eSVbK0ETjJWbNbPoiUSW/7w==
2462+
dependencies:
2463+
fast-glob "^3.2.7"
2464+
find-up "^5.0.0"
2465+
read-yaml-file "^2.1.0"
2466+
strip-json-comments "^3.1.1"
2467+
24372468
"@sideway/address@^4.1.0":
24382469
version "4.1.2"
24392470
resolved "https://registry.npmjs.org/@sideway/address/-/address-4.1.2.tgz"
@@ -4118,27 +4149,27 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
41184149
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz"
41194150
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
41204151

4121-
fast-glob@^3.2.9:
4122-
version "3.2.12"
4123-
resolved "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz"
4124-
integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==
4152+
fast-glob@^3.2.7, fast-glob@^3.3.2:
4153+
version "3.3.3"
4154+
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.3.tgz#d06d585ce8dba90a16b0505c543c3ccfb3aeb818"
4155+
integrity sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==
41254156
dependencies:
41264157
"@nodelib/fs.stat" "^2.0.2"
41274158
"@nodelib/fs.walk" "^1.2.3"
41284159
glob-parent "^5.1.2"
41294160
merge2 "^1.3.0"
4130-
micromatch "^4.0.4"
4161+
micromatch "^4.0.8"
41314162

4132-
fast-glob@^3.3.2:
4133-
version "3.3.3"
4134-
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.3.tgz#d06d585ce8dba90a16b0505c543c3ccfb3aeb818"
4135-
integrity sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==
4163+
fast-glob@^3.2.9:
4164+
version "3.2.12"
4165+
resolved "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz"
4166+
integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==
41364167
dependencies:
41374168
"@nodelib/fs.stat" "^2.0.2"
41384169
"@nodelib/fs.walk" "^1.2.3"
41394170
glob-parent "^5.1.2"
41404171
merge2 "^1.3.0"
4141-
micromatch "^4.0.8"
4172+
micromatch "^4.0.4"
41424173

41434174
fast-json-stable-stringify@^2.0.0, fast-json-stable-stringify@^2.1.0:
41444175
version "2.1.0"
@@ -5346,7 +5377,7 @@ js-yaml@^3.13.1:
53465377
argparse "^1.0.7"
53475378
esprima "^4.0.0"
53485379

5349-
js-yaml@^4.1.0:
5380+
js-yaml@^4.0.0, js-yaml@^4.1.0:
53505381
version "4.1.0"
53515382
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
53525383
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
@@ -6648,6 +6679,14 @@ react@18.3.1:
66486679
dependencies:
66496680
loose-envify "^1.1.0"
66506681

6682+
read-yaml-file@^2.1.0:
6683+
version "2.1.0"
6684+
resolved "https://registry.yarnpkg.com/read-yaml-file/-/read-yaml-file-2.1.0.tgz#c5866712db9ef5343b4d02c2413bada53c41c4a9"
6685+
integrity sha512-UkRNRIwnhG+y7hpqnycCL/xbTk7+ia9VuVTC0S+zVbwd65DI9eUpRMfsWIGrCWxTU/mi+JW8cHQCrv+zfCbEPQ==
6686+
dependencies:
6687+
js-yaml "^4.0.0"
6688+
strip-bom "^4.0.0"
6689+
66516690
readable-stream@^3.4.0:
66526691
version "3.6.0"
66536692
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz"

0 commit comments

Comments
 (0)