Skip to content

Commit d797827

Browse files
committed
fix: use Metro config from rnx-kit
1 parent 4e05c49 commit d797827

File tree

4 files changed

+81
-90
lines changed

4 files changed

+81
-90
lines changed

examples/demo/macos/Example.xcodeproj/project.pbxproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@
488488
ONLY_ACTIVE_ARCH = YES;
489489
OTHER_CFLAGS = "$(inherited)";
490490
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
491-
OTHER_LDFLAGS = "$(inherited) ";
491+
OTHER_LDFLAGS = (
492+
"$(inherited)",
493+
" ",
494+
);
492495
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
493496
SDKROOT = iphoneos;
494497
USE_HERMES = false;
@@ -548,7 +551,10 @@
548551
MTL_ENABLE_DEBUG_INFO = NO;
549552
OTHER_CFLAGS = "$(inherited)";
550553
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
551-
OTHER_LDFLAGS = "$(inherited) ";
554+
OTHER_LDFLAGS = (
555+
"$(inherited)",
556+
" ",
557+
);
552558
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
553559
SDKROOT = iphoneos;
554560
USE_HERMES = false;

examples/demo/metro.config.js

Lines changed: 17 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,24 @@
1-
const { getDefaultConfig } = require('@react-native/metro-config');
2-
3-
const path = require('path');
1+
const path = require('node:path');
2+
const { makeMetroConfig } = require('@rnx-kit/metro-config');
43

54
const projectRoot = __dirname;
5+
const monorepoRoot = path.resolve(__dirname, "../..");
6+
const packageRoot = path.resolve(monorepoRoot, "packages/react-native-app-auth");
67

7-
// If you have a monorepo, the workspace root may be above the project root.
8-
const workspaceRoot = path.resolve(projectRoot, "../..");
9-
const appAuthPackageRoot = path.resolve(workspaceRoot, "packages", "react-native-app-auth");
10-
11-
const packagePath = path.resolve(
12-
path.join(process.cwd(), '..', '..', 'packages', 'react-native-app-auth'),
13-
);
14-
15-
/**
16-
* A crude flag to force Metro to resolve one or another fork of react-native.
17-
* Set to "macos" to resolve react-native-macos.
18-
* Set to "ios" to resolve react-native.
19-
* Welcoming a fully automatic solution by anyone more familiar with Metro!
20-
* @type {"macos" | "ios"}
21-
*/
22-
const applePlatform = "ios";
23-
24-
const extraNodeModules = {
25-
'react-native': path.resolve(
26-
projectRoot,
27-
"node_modules",
28-
applePlatform === 'macos' ? "react-native-macos" : "react-native"
29-
),
30-
'react-native-app-auth': packagePath,
31-
};
32-
const watchFolders = [monorepoRoot, packagePath];
33-
34-
/**
35-
* Metro configuration
36-
* https://facebook.github.io/metro/docs/configuration
37-
*
38-
* @type {import('metro-config').MetroConfig}
39-
*/
40-
const config = getDefaultConfig(__dirname);
41-
42-
module.exports = {
43-
...config,
8+
module.exports = makeMetroConfig({
9+
watchFolders: [projectRoot, packageRoot],
4410
resolver: {
45-
...config.resolver,
46-
disableHierarchicalLookup: true,
47-
nodeModulesPaths: [
48-
path.resolve(workspaceRoot, "node_modules"),
49-
path.resolve(projectRoot, "node_modules"),
50-
// Resolve the node modules of the react-native-app-auth workspace to find
51-
// react-native-base-64.
52-
path.resolve(appAuthPackageRoot, "node_modules"),
53-
],
54-
55-
extraNodeModules: new Proxy(extraNodeModules, {
56-
get: (target, name) =>
57-
name in target
58-
? target[name]
59-
: path.join(process.cwd(), '..', '..', 'node_modules', name),
60-
}),
61-
unstable_enableSymlinks: true,
62-
63-
resolveRequest: (context, moduleName, platform) => {
64-
if (
65-
platform === "macos" &&
66-
(moduleName === "react-native" ||
67-
moduleName.startsWith("react-native/"))
68-
) {
69-
const newModuleName = moduleName.replace(
70-
"react-native",
71-
"react-native-macos",
72-
);
73-
return context.resolveRequest(context, newModuleName, platform);
74-
}
75-
return context.resolveRequest(context, moduleName, platform);
11+
resolverMainFields: ['main', 'react-native'],
12+
extraNodeModules: {
13+
'react-native-app-auth': packageRoot,
7614
},
7715
},
78-
79-
serializer: {
80-
...config.serializer,
81-
getModulesRunBeforeMainModule() {
82-
return [
83-
require.resolve("react-native/Libraries/Core/InitializeCore"),
84-
require.resolve("react-native-macos/Libraries/Core/InitializeCore"),
85-
...config.serializer.getModulesRunBeforeMainModule(),
86-
];
87-
},
16+
transformer: {
17+
getTransformOptions: async () => ({
18+
transform: {
19+
experimentalImportSupport: false,
20+
inlineRequires: false,
21+
},
22+
}),
8823
},
89-
watchFolders,
90-
};
91-
24+
});

examples/demo/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
"dependencies": {
1414
"react": "18.2.0",
1515
"react-native": "0.72.4",
16-
"react-native-macos": "~0.73.30",
17-
"react-native-app-auth": "*"
16+
"react-native-app-auth": "link:../../packages/react-native-app-auth",
17+
"react-native-macos": "~0.73.30"
1818
},
1919
"devDependencies": {
2020
"@babel/core": "^7.20.0",
2121
"@babel/preset-env": "^7.20.0",
2222
"@babel/runtime": "^7.20.0",
2323
"@react-native/eslint-config": "^0.72.2",
2424
"@react-native/metro-config": "^0.72.11",
25+
"@rnx-kit/metro-config": "^1.3.15",
2526
"@tsconfig/react-native": "^3.0.0",
2627
"@types/react": "^18.0.24",
2728
"@types/react-test-renderer": "^18.0.0",

yarn.lock

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,43 @@
26552655
invariant "^2.2.4"
26562656
nullthrows "^1.1.1"
26572657

2658+
"@rnx-kit/console@^1.0.0":
2659+
version "1.1.0"
2660+
resolved "https://registry.yarnpkg.com/@rnx-kit/console/-/console-1.1.0.tgz#86364f8e6c68b01e9493730276c0d8109a80cd41"
2661+
integrity sha512-N+zFhTSXroiK4eL26vs61Pmtl7wzTPAKLd4JKw9/fk5cNAHUscCXF/uclzuYN61Ye5AwygIvcwbm9wv4Jfa92A==
2662+
2663+
"@rnx-kit/metro-config@^1.3.15":
2664+
version "1.3.15"
2665+
resolved "https://registry.yarnpkg.com/@rnx-kit/metro-config/-/metro-config-1.3.15.tgz#357243579d7c96f9931a037864f5c58c0ce3a1cb"
2666+
integrity sha512-6papm4cc6uho39M7E4spxGec4jI0wLUSbvAEho0zITYgGc/U2xNnMHT37hDO4HyZoz72P8BwxsPgGfxa74+epw==
2667+
dependencies:
2668+
"@rnx-kit/console" "^1.0.0"
2669+
"@rnx-kit/tools-node" "^2.0.0"
2670+
"@rnx-kit/tools-react-native" "^1.3.4"
2671+
"@rnx-kit/tools-workspaces" "^0.1.3"
2672+
2673+
"@rnx-kit/tools-node@^2.0.0", "@rnx-kit/tools-node@^2.0.1":
2674+
version "2.1.1"
2675+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-node/-/tools-node-2.1.1.tgz#550016458ec8b67d21949efeafdb4ba2870d5e69"
2676+
integrity sha512-jZC/pmeM3fv4LwpkVWlLyv5dOh6haUw/dBaDC0e5zkfehkIdLtRhVwz4l7iH9MW/i4I9OySoc+2DtDpX7KZyZA==
2677+
2678+
"@rnx-kit/tools-react-native@^1.3.4":
2679+
version "1.3.5"
2680+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-react-native/-/tools-react-native-1.3.5.tgz#57a0dd7056c55a23d311515def44b292bc6aa4fd"
2681+
integrity sha512-fc+3hxdlicW3GEhI0Umjj+rnVLSLuxVJoGvUBwWvcaCnlNaaTssBjhd7xSvlfLDrgtuXxhBruA76wdDdZI8tiQ==
2682+
dependencies:
2683+
"@rnx-kit/tools-node" "^2.0.1"
2684+
2685+
"@rnx-kit/tools-workspaces@^0.1.3":
2686+
version "0.1.6"
2687+
resolved "https://registry.yarnpkg.com/@rnx-kit/tools-workspaces/-/tools-workspaces-0.1.6.tgz#94e5fb72c9857cf4a00d27e931b7ca5a362b4695"
2688+
integrity sha512-af5CYnc1dtnMIAl2u0U1QHUCGgLNN9ZQkYCAtQOHPxxgF5yX2Cr9jrXLZ9M+/h/eSVbK0ETjJWbNbPoiUSW/7w==
2689+
dependencies:
2690+
fast-glob "^3.2.7"
2691+
find-up "^5.0.0"
2692+
read-yaml-file "^2.1.0"
2693+
strip-json-comments "^3.1.1"
2694+
26582695
"@sideway/address@^4.1.5":
26592696
version "4.1.5"
26602697
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5"
@@ -5244,7 +5281,7 @@ fast-diff@^1.1.2:
52445281
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.3.0.tgz#ece407fa550a64d638536cd727e129c61616e0f0"
52455282
integrity sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==
52465283

5247-
fast-glob@^3.2.9:
5284+
fast-glob@^3.2.7, fast-glob@^3.2.9:
52485285
version "3.3.2"
52495286
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129"
52505287
integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==
@@ -7307,7 +7344,7 @@ js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.6.1:
73077344
argparse "^1.0.7"
73087345
esprima "^4.0.0"
73097346

7310-
js-yaml@^4.1.0:
7347+
js-yaml@^4.0.0, js-yaml@^4.1.0:
73117348
version "4.1.0"
73127349
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
73137350
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
@@ -9799,6 +9836,12 @@ react-is@^17.0.1:
97999836
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
98009837
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
98019838

9839+
"react-native-app-auth@link:packages/react-native-app-auth":
9840+
version "7.2.0"
9841+
dependencies:
9842+
invariant "2.2.4"
9843+
react-native-base64 "0.0.2"
9844+
98029845
react-native-base64@0.0.2:
98039846
version "0.0.2"
98049847
resolved "https://registry.yarnpkg.com/react-native-base64/-/react-native-base64-0.0.2.tgz#c28463c2c6779ac3ec5fdd12979ebc8c5f9b410a"
@@ -10010,6 +10053,14 @@ read-yaml-file@^1.1.0:
1001010053
pify "^4.0.1"
1001110054
strip-bom "^3.0.0"
1001210055

10056+
read-yaml-file@^2.1.0:
10057+
version "2.1.0"
10058+
resolved "https://registry.yarnpkg.com/read-yaml-file/-/read-yaml-file-2.1.0.tgz#c5866712db9ef5343b4d02c2413bada53c41c4a9"
10059+
integrity sha512-UkRNRIwnhG+y7hpqnycCL/xbTk7+ia9VuVTC0S+zVbwd65DI9eUpRMfsWIGrCWxTU/mi+JW8cHQCrv+zfCbEPQ==
10060+
dependencies:
10061+
js-yaml "^4.0.0"
10062+
strip-bom "^4.0.0"
10063+
1001310064
readable-stream@^2.0.1, readable-stream@^2.2.2, readable-stream@~2.3.6:
1001410065
version "2.3.8"
1001510066
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b"

0 commit comments

Comments
 (0)