diff --git a/packages/expo-app/babel.config.js b/packages/expo-app/babel.config.js index 54751c2de..4587c554e 100644 --- a/packages/expo-app/babel.config.js +++ b/packages/expo-app/babel.config.js @@ -1,3 +1,14 @@ -module.exports = { - presets: ["babel-preset-expo"], -}; +/* eslint-env node */ +const path = require("path"); +const { getConfig } = require("react-native-builder-bob/babel-config"); + +const pkg = require("../../package.json"); + +const root = path.resolve(__dirname, "..", ".."); + +module.exports = getConfig( + { + presets: ["babel-preset-expo"], + }, + { root, pkg }, +); diff --git a/packages/expo-app/metro.config.js b/packages/expo-app/metro.config.js index 0a475929d..c9bed4911 100644 --- a/packages/expo-app/metro.config.js +++ b/packages/expo-app/metro.config.js @@ -1,9 +1,12 @@ /* eslint-env node */ const { getDefaultConfig } = require("expo/metro-config"); const path = require("path"); +const { getConfig } = require("react-native-builder-bob/metro-config"); -const projectRoot = __dirname; -const workspaceRoot = path.resolve(projectRoot, "../.."); +const pkg = require("../../package.json"); + +const project = __dirname; +const root = path.resolve(project, "..", ".."); /** * @param config {import('expo/metro-config').MetroConfig} @@ -11,19 +14,37 @@ const workspaceRoot = path.resolve(projectRoot, "../.."); */ function withMonorepoPaths(config) { // Watch all files in the monorepo - config.watchFolders = [workspaceRoot]; + config.watchFolders = [root]; // Set `node_modules` to resolve config.resolver.nodeModulesPaths = [ - path.resolve(projectRoot, "node_modules"), - path.resolve(workspaceRoot, "packages/examples/node_modules"), - path.resolve(workspaceRoot, "node_modules"), + path.resolve(project, "node_modules"), + path.resolve(root, "packages/examples/node_modules"), + path.resolve(root, "node_modules"), ]; // Resolve only (sub)dependencies from the `nodeModulesPaths` config.resolver.disableHierarchicalLookup = true; + // Use src instead of lib + config.resolver.resolveRequest = (context, moduleName, platform) => { + if (moduleName.startsWith(pkg.name)) { + return { + filePath: path.resolve(__dirname, "..", "..", "src", "index.ts"), + type: "sourceFile", + }; + } + + return context.resolveRequest(context, moduleName, platform); + }; + return config; } -module.exports = withMonorepoPaths(getDefaultConfig(projectRoot)); +module.exports = withMonorepoPaths( + getConfig(getDefaultConfig(project), { + root, + pkg, + project, + }), +); diff --git a/packages/react-native-app/metro.config.js b/packages/react-native-app/metro.config.js index 189bc09e6..8320f44bf 100644 --- a/packages/react-native-app/metro.config.js +++ b/packages/react-native-app/metro.config.js @@ -3,29 +3,30 @@ const { getDefaultConfig } = require("@react-native/metro-config"); const path = require("path"); const { getConfig } = require("react-native-builder-bob/metro-config"); -const root = path.resolve(__dirname, "..", ".."); -const projectRoot = __dirname; -const workspaceRoot = path.resolve(projectRoot, "../.."); const pkg = require("../../package.json"); +const project = __dirname; +const root = path.resolve(project, "..", ".."); + /** * @param config {import('metro-config').MetroConfig} * @returns {import('expo/metro-config').MetroConfig} */ function withMonorepoPaths(config) { // Watch all files in the monorepo - config.watchFolders = [workspaceRoot]; + config.watchFolders = [root]; // Set `node_modules` to resolve config.resolver.nodeModulesPaths = [ - path.resolve(projectRoot, "node_modules"), - path.resolve(workspaceRoot, "packages/examples/node_modules"), - path.resolve(workspaceRoot, "node_modules"), + path.resolve(project, "node_modules"), + path.resolve(root, "packages/examples/node_modules"), + path.resolve(root, "node_modules"), ]; // Resolve only (sub)dependencies from the `nodeModulesPaths` config.resolver.disableHierarchicalLookup = true; + // Use src instead of lib config.resolver.resolveRequest = (context, moduleName, platform) => { if (moduleName.startsWith(pkg.name)) { return { @@ -41,9 +42,9 @@ function withMonorepoPaths(config) { } module.exports = withMonorepoPaths( - getConfig(getDefaultConfig(projectRoot), { + getConfig(getDefaultConfig(project), { root, pkg, - project: __dirname, + project, }), );