@expo/metro-config
Advanced tools
Comparing version 0.2.6 to 0.2.7
import { ProjectTarget } from '@expo/config'; | ||
import { Reporter } from 'metro'; | ||
import type MetroConfig from 'metro-config'; | ||
export declare function getModulesPaths(projectRoot: string): string[]; | ||
export declare const EXPO_DEBUG: boolean; | ||
@@ -5,0 +6,0 @@ export declare const INTERNAL_CALLSITES_REGEX: RegExp; |
@@ -7,10 +7,22 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0; | ||
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = exports.getModulesPaths = void 0; | ||
const config_1 = require("@expo/config"); | ||
const paths_1 = require("@expo/config/paths"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root")); | ||
const getenv_1 = require("getenv"); | ||
const path_1 = __importDefault(require("path")); | ||
const resolve_from_1 = __importDefault(require("resolve-from")); | ||
const getWatchFolders_1 = require("./getWatchFolders"); | ||
const importMetroFromProject_1 = require("./importMetroFromProject"); | ||
function getModulesPaths(projectRoot) { | ||
const paths = []; | ||
paths.push(path_1.default.resolve(projectRoot, 'node_modules')); | ||
const workspaceRoot = find_yarn_workspace_root_1.default(path_1.default.resolve(projectRoot)); // Absolute path or null | ||
if (workspaceRoot) { | ||
paths.push(path_1.default.resolve(workspaceRoot, 'node_modules')); | ||
} | ||
return paths; | ||
} | ||
exports.getModulesPaths = getModulesPaths; | ||
exports.EXPO_DEBUG = getenv_1.boolish('EXPO_DEBUG', false); | ||
@@ -62,4 +74,23 @@ const EXPO_USE_EXOTIC = getenv_1.boolish('EXPO_USE_EXOTIC', false); | ||
} | ||
function getAssetPlugins(projectRoot) { | ||
const assetPlugins = []; | ||
assetPlugins.push(require.resolve('./monorepoAssetsPlugin')); | ||
let hashAssetFilesPath; | ||
try { | ||
hashAssetFilesPath = resolve_from_1.default(projectRoot, 'expo-asset/tools/hashAssetFiles'); | ||
} | ||
catch { | ||
// TODO: we should warn/throw an error if the user has expo-updates installed but does not | ||
// have hashAssetFiles available, or if the user is in managed workflow and does not have | ||
// hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client, | ||
// it is not needed | ||
} | ||
if (hashAssetFilesPath) { | ||
assetPlugins.push(hashAssetFilesPath); | ||
} | ||
return assetPlugins; | ||
} | ||
let hasWarnedAboutExotic = false; | ||
function getDefaultConfig(projectRoot, options = {}) { | ||
var _a; | ||
const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC; | ||
@@ -82,12 +113,2 @@ if (isExotic && !hasWarnedAboutExotic) { | ||
} | ||
let hashAssetFilesPath; | ||
try { | ||
hashAssetFilesPath = resolve_from_1.default(projectRoot, 'expo-asset/tools/hashAssetFiles'); | ||
} | ||
catch { | ||
// TODO: we should warn/throw an error if the user has expo-updates installed but does not | ||
// have hashAssetFiles available, or if the user is in managed workflow and does not have | ||
// hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client, | ||
// it is not needed | ||
} | ||
const isLegacy = readIsLegacyImportsEnabled(projectRoot); | ||
@@ -143,2 +164,4 @@ // Deprecated -- SDK 41 -- | ||
resolverMainFields.push('browser', 'main'); | ||
const watchFolders = getWatchFolders_1.getWatchFolders(projectRoot); | ||
const nodeModulesPaths = getModulesPaths(projectRoot); | ||
if (exports.EXPO_DEBUG) { | ||
@@ -153,2 +176,4 @@ console.log(); | ||
console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`); | ||
console.log(`- Watch Folders: ${watchFolders.join(', ')}`); | ||
console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`); | ||
console.log(`- Exotic: ${isExotic}`); | ||
@@ -161,5 +186,24 @@ console.log(); | ||
reporter, ...metroDefaultValues } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot); | ||
const customEnhanceMiddleware = (_a = metroDefaultValues.server) === null || _a === void 0 ? void 0 : _a.enhanceMiddleware; | ||
// @ts-ignore can't mutate readonly config | ||
const enhanceMiddleware = (metroMiddleware, server) => { | ||
if (customEnhanceMiddleware) { | ||
metroMiddleware = customEnhanceMiddleware(metroMiddleware, server); | ||
} | ||
const debug = require('debug')('expo:metro-config:middleware'); | ||
// Add extra middleware to redirect assets in a monorepo. | ||
return (req, res, next) => { | ||
const { url } = req; | ||
if (url && url.startsWith('/assets/')) { | ||
// Added by the assetPlugins | ||
req.url = url.replace(/@@\//g, '../'); | ||
debug('Redirect asset:', url, '->', req.url); | ||
} | ||
return metroMiddleware(req, res, next); | ||
}; | ||
}; | ||
// Merge in the default config from Metro here, even though loadConfig uses it as defaults. | ||
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts. | ||
return MetroConfig.mergeConfig(metroDefaultValues, { | ||
watchFolders, | ||
resolver: { | ||
@@ -169,2 +213,3 @@ resolverMainFields, | ||
sourceExts, | ||
nodeModulesPaths, | ||
}, | ||
@@ -180,2 +225,3 @@ serializer: { | ||
port: Number(process.env.RCT_METRO_PORT) || 8081, | ||
enhanceMiddleware, | ||
}, | ||
@@ -211,3 +257,3 @@ symbolicator: { | ||
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry', | ||
assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : [], | ||
assetPlugins: getAssetPlugins(projectRoot), | ||
}, | ||
@@ -214,0 +260,0 @@ }); |
@@ -35,13 +35,11 @@ "use strict"; | ||
let projectBabelRCPath; | ||
// Since this is an opt-in system, we can make certain | ||
// assumptions like dropping support for `.babelrc` to speed up resolution. | ||
// .babelrc | ||
// if (projectRoot) { | ||
// projectBabelRCPath = path.resolve(projectRoot, '.babelrc'); | ||
// } | ||
if (projectRoot) { | ||
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc'); | ||
} | ||
if (projectBabelRCPath) { | ||
// .babelrc.js | ||
// if (!fs.existsSync(projectBabelRCPath)) { | ||
// projectBabelRCPath = path.resolve(projectRoot, '.babelrc.js'); | ||
// } | ||
if (!fs_1.default.existsSync(projectBabelRCPath)) { | ||
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc.js'); | ||
} | ||
// babel.config.js | ||
@@ -67,2 +65,4 @@ if (!fs_1.default.existsSync(projectBabelRCPath)) { | ||
{ | ||
// Default to React 17 automatic JSX transform. | ||
jsxRuntime: 'automatic', | ||
...presetOptions, | ||
@@ -69,0 +69,0 @@ disableImportExportTransform: experimentalImportSupport, |
{ | ||
"name": "@expo/metro-config", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "A Metro config for running React Native projects with the Metro bundler", | ||
@@ -38,4 +38,6 @@ "main": "build/ExpoMetroConfig.js", | ||
"@expo/config": "6.0.6", | ||
"@expo/json-file": "^8.2.33", | ||
"chalk": "^4.1.0", | ||
"debug": "^4.3.2", | ||
"find-yarn-workspace-root": "~2.0.0", | ||
"getenv": "^1.0.0", | ||
@@ -42,0 +44,0 @@ "sucrase": "^3.20.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
127694
44
1117
7
+ Added@expo/json-file@^8.2.33
+ Added@expo/json-file@8.3.3(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-yarn-workspace-root@2.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)