Skip to content

Commit

Permalink
feat: update metro configs to find hoised modules
Browse files Browse the repository at this point in the history
  • Loading branch information
iykazrji committed Dec 19, 2024
1 parent cf25533 commit f27b456
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 151 deletions.
25 changes: 23 additions & 2 deletions account-kit/rn-signer/example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,41 @@ const { getDefaultConfig } = require("@react-native/metro-config");
const { getConfig } = require("react-native-builder-bob/metro-config");
const pkg = require("../package.json");

const root = path.resolve(__dirname, "..");
// handles the hoisted modules
const root = path.resolve(__dirname, "..");
const repoRoot = path.resolve(__dirname, "../../..");
const bareExamplePath = path.resolve(
__dirname,
"../../../examples/react-native-bare-example"
);
const expoExamplePath = path.resolve(
__dirname,
"../../../examples/react-native-expo-example"
);

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
*/
const defaultResolver = getDefaultConfig(__dirname).resolver;

module.exports = {
...getConfig(getDefaultConfig(__dirname), {
root,
pkg,
project: __dirname,
}),
watchFolders: [root, repoRoot],
watchFolders: [__dirname, root, repoRoot],
resolver: {
...defaultResolver,
disableHierarchicalLookup: true,
nodeModulesPaths: [
path.resolve(__dirname, "node_modules"),
path.resolve(repoRoot, "node_modules"),
path.resolve(root, "node_modules"),
path.resolve(bareExamplePath, "node_modules"),
path.resolve(expoExamplePath, "node_modules"),
],
},
};
5 changes: 0 additions & 5 deletions account-kit/rn-signer/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,5 @@
},
"engines": {
"node": ">=18"
},
"workspaces": {
"nohoist": [
"**"
]
}
}
7 changes: 6 additions & 1 deletion examples/react-native-bare-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ config.watchFolders = [workspaceRoot, projectRoot];

// config.watchFolders = [projectRoot, ...Object.values(monorepoPackages)];

// Let Metro know where to resolve packages and in what order
// Add all the React Native node_modules paths
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(workspaceRoot, 'node_modules'),
path.resolve(workspaceRoot, 'account-kit/rn-signer/node_modules'),
path.resolve(workspaceRoot, 'account-kit/rn-signer/example/node_modules'),
path.resolve(
workspaceRoot,
'examples/react-native-expo-example/node_modules',
),
];
// Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
config.resolver.disableHierarchicalLookup = true;
Expand Down
8 changes: 0 additions & 8 deletions examples/react-native-bare-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,5 @@
},
"engines": {
"node": ">=18"
},
"workspaces": {
"nohoist": [
"**/react",
"**/react/**",
"**/react-native",
"**/react-native/**"
]
}
}
2 changes: 1 addition & 1 deletion examples/react-native-bare-example/src/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from 'react-native';
import {API_KEY} from '@env';

const signer = new RNAlchemySigner({
const signer = RNAlchemySigner({
client: {connection: {apiKey: API_KEY!}},
});

Expand Down
2 changes: 2 additions & 0 deletions examples/react-native-expo-example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, "node_modules"),
path.resolve(monorepoRoot, "node_modules"),
path.resolve(monorepoRoot, "account-kit/rn-signer/node_modules"),
path.resolve(monorepoRoot, "account-kit/rn-signer/example/node_modules"),
path.resolve(monorepoRoot, "examples/react-native-bare-example/node_modules"),
];

// Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
Expand Down
10 changes: 1 addition & 9 deletions examples/react-native-expo-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,5 @@
"react": "18.3.1",
"react-native": "0.76.5"
},
"private": true,
"workspaces": {
"nohoist": [
"**/expo",
"**/expo/**",
"**/expo-router",
"**/expo-router/**"
]
}
"private": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"**/react-native-test-app",
"**/react-native-test-app/**",
"**/react-native-config",
"**react-native-config/**"
"**/react-native-config/**"
]
},
"resolutions": {
Expand Down
Loading

0 comments on commit f27b456

Please sign in to comment.