-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathmetro.config.js
More file actions
70 lines (66 loc) · 3.03 KB
/
Copy pathmetro.config.js
File metadata and controls
70 lines (66 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const path = require('path');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
// Yarn workspace root (where node_modules with all hoisted deps lives)
const workspaceRoot = path.resolve(__dirname, '../../../');
const bufbuildProtobufRoot = path.resolve(
workspaceRoot,
'node_modules/@bufbuild/protobuf'
);
// Use binary-encoding.js directly — the wire/index.js barrel re-exports can be
// empty in Hermes production bundles, breaking ts-proto's `new BinaryWriter()`.
const bufbuildWireCjs = path.join(
bufbuildProtobufRoot,
'dist/cjs/wire/binary-encoding.js'
);
/**
* Metro configuration
* https://reactnative.dev/docs/metro
*
* Yarn workspace setup: deps are hoisted to repo root. Metro must:
* 1. Watch all workspace folders so source changes hot-reload.
* 2. Look up modules in the root node_modules (where yarn hoists them).
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
// Watch source for all workspace packages so edits trigger reload.
watchFolders: [workspaceRoot],
resolver: {
// Search node_modules first locally (in case of nohoist), then at workspace root.
nodeModulesPaths: [
path.resolve(__dirname, 'node_modules'),
path.resolve(workspaceRoot, 'node_modules'),
],
// Single instance enforcement for shared peer deps (RN forbids duplicates).
extraNodeModules: {
'react-native': path.resolve(workspaceRoot, 'node_modules/react-native'),
'react-native-nitro-modules': path.resolve(workspaceRoot, 'node_modules/react-native-nitro-modules'),
'react': path.resolve(workspaceRoot, 'node_modules/react'),
// ts-proto generated code uses @bufbuild/protobuf/wire; Metro must resolve the CJS build.
'@bufbuild/protobuf': bufbuildProtobufRoot,
},
resolveRequest: (context, moduleName, platform) => {
if (
moduleName === '@bufbuild/protobuf/wire' ||
moduleName === '@bufbuild/protobuf/dist/cjs/wire/index.js' ||
moduleName === '@bufbuild/protobuf/dist/cjs/wire/binary-encoding.js' ||
moduleName === '@bufbuild/protobuf/wire/binary-encoding'
) {
return { type: 'sourceFile', filePath: bufbuildWireCjs };
}
// Delegate to Metro's own default resolver. Metro pre-sets
// `context.resolveRequest` to its internal `resolve` (with the
// `resolveRequest !== resolve` recursion guard pointing at the same
// module instance). Importing a separate `metro-resolver` package here
// would bind a *different* `resolve` identity — when the root
// metro-resolver (v0.84.x) and metro's bundled copy (v0.83.x) differ,
// that guard never matches and delegation recurses infinitely
// ("Maximum call stack size exceeded" in metro-resolver/src/resolve.js).
return context.resolveRequest(context, moduleName, platform);
},
// Standard hierarchical lookup; yarn workspace symlinks resolve cleanly.
disableHierarchicalLookup: false,
unstable_enableSymlinks: true,
},
};
module.exports = mergeConfig(getDefaultConfig(__dirname), config);