|
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'); |
4 | 3 |
|
5 | 4 | const projectRoot = __dirname; |
| 5 | +const monorepoRoot = path.resolve(__dirname, "../.."); |
| 6 | +const packageRoot = path.resolve(monorepoRoot, "packages/react-native-app-auth"); |
6 | 7 |
|
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], |
44 | 10 | 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, |
76 | 14 | }, |
77 | 15 | }, |
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 | + }), |
88 | 23 | }, |
89 | | - watchFolders, |
90 | | -}; |
91 | | - |
| 24 | +}); |
0 commit comments