@expo/metro-config 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ExpoMetroConfig.d.ts +1 -0
- package/build/ExpoMetroConfig.js +58 -12
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/getWatchFolders.d.ts +16 -0
- package/build/getWatchFolders.js +89 -0
- package/build/getWatchFolders.js.map +1 -0
- package/build/monorepoAssetsPlugin.d.ts +19 -0
- package/build/monorepoAssetsPlugin.js +22 -0
- package/build/monorepoAssetsPlugin.js.map +1 -0
- package/build/transformer/getBabelConfig.js +8 -8
- package/build/transformer/getBabelConfig.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProjectTarget } from '@expo/config';
|
|
2
2
|
import { Reporter } from 'metro';
|
|
3
3
|
import type MetroConfig from 'metro-config';
|
|
4
|
+
export declare function getModulesPaths(projectRoot: string): string[];
|
|
4
5
|
export declare const EXPO_DEBUG: boolean;
|
|
5
6
|
export declare const INTERNAL_CALLSITES_REGEX: RegExp;
|
|
6
7
|
export interface DefaultConfigOptions {
|
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -4,14 +4,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0;
|
|
7
|
+
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = exports.getModulesPaths = void 0;
|
|
8
8
|
const config_1 = require("@expo/config");
|
|
9
9
|
const paths_1 = require("@expo/config/paths");
|
|
10
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root"));
|
|
11
12
|
const getenv_1 = require("getenv");
|
|
12
13
|
const path_1 = __importDefault(require("path"));
|
|
13
14
|
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
15
|
+
const getWatchFolders_1 = require("./getWatchFolders");
|
|
14
16
|
const importMetroFromProject_1 = require("./importMetroFromProject");
|
|
17
|
+
function getModulesPaths(projectRoot) {
|
|
18
|
+
const paths = [];
|
|
19
|
+
paths.push(path_1.default.resolve(projectRoot, 'node_modules'));
|
|
20
|
+
const workspaceRoot = find_yarn_workspace_root_1.default(path_1.default.resolve(projectRoot)); // Absolute path or null
|
|
21
|
+
if (workspaceRoot) {
|
|
22
|
+
paths.push(path_1.default.resolve(workspaceRoot, 'node_modules'));
|
|
23
|
+
}
|
|
24
|
+
return paths;
|
|
25
|
+
}
|
|
26
|
+
exports.getModulesPaths = getModulesPaths;
|
|
15
27
|
exports.EXPO_DEBUG = getenv_1.boolish('EXPO_DEBUG', false);
|
|
16
28
|
const EXPO_USE_EXOTIC = getenv_1.boolish('EXPO_USE_EXOTIC', false);
|
|
17
29
|
// Import only the types here, the values will be imported from the project, at runtime.
|
|
@@ -58,8 +70,27 @@ function getProjectBabelConfigFile(projectRoot) {
|
|
|
58
70
|
resolve_from_1.default.silent(projectRoot, './.babelrc') ||
|
|
59
71
|
resolve_from_1.default.silent(projectRoot, './.babelrc.js'));
|
|
60
72
|
}
|
|
73
|
+
function getAssetPlugins(projectRoot) {
|
|
74
|
+
const assetPlugins = [];
|
|
75
|
+
assetPlugins.push(require.resolve('./monorepoAssetsPlugin'));
|
|
76
|
+
let hashAssetFilesPath;
|
|
77
|
+
try {
|
|
78
|
+
hashAssetFilesPath = resolve_from_1.default(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// TODO: we should warn/throw an error if the user has expo-updates installed but does not
|
|
82
|
+
// have hashAssetFiles available, or if the user is in managed workflow and does not have
|
|
83
|
+
// hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
|
|
84
|
+
// it is not needed
|
|
85
|
+
}
|
|
86
|
+
if (hashAssetFilesPath) {
|
|
87
|
+
assetPlugins.push(hashAssetFilesPath);
|
|
88
|
+
}
|
|
89
|
+
return assetPlugins;
|
|
90
|
+
}
|
|
61
91
|
let hasWarnedAboutExotic = false;
|
|
62
92
|
function getDefaultConfig(projectRoot, options = {}) {
|
|
93
|
+
var _a;
|
|
63
94
|
const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
|
|
64
95
|
if (isExotic && !hasWarnedAboutExotic) {
|
|
65
96
|
hasWarnedAboutExotic = true;
|
|
@@ -77,16 +108,6 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
77
108
|
catch {
|
|
78
109
|
// noop -- falls back to a hardcoded value.
|
|
79
110
|
}
|
|
80
|
-
let hashAssetFilesPath;
|
|
81
|
-
try {
|
|
82
|
-
hashAssetFilesPath = resolve_from_1.default(projectRoot, 'expo-asset/tools/hashAssetFiles');
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// TODO: we should warn/throw an error if the user has expo-updates installed but does not
|
|
86
|
-
// have hashAssetFiles available, or if the user is in managed workflow and does not have
|
|
87
|
-
// hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,
|
|
88
|
-
// it is not needed
|
|
89
|
-
}
|
|
90
111
|
const isLegacy = readIsLegacyImportsEnabled(projectRoot);
|
|
91
112
|
// Deprecated -- SDK 41 --
|
|
92
113
|
if (options.target) {
|
|
@@ -137,6 +158,8 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
137
158
|
resolverMainFields.push('react-native');
|
|
138
159
|
}
|
|
139
160
|
resolverMainFields.push('browser', 'main');
|
|
161
|
+
const watchFolders = getWatchFolders_1.getWatchFolders(projectRoot);
|
|
162
|
+
const nodeModulesPaths = getModulesPaths(projectRoot);
|
|
140
163
|
if (exports.EXPO_DEBUG) {
|
|
141
164
|
console.log();
|
|
142
165
|
console.log(`Expo Metro config:`);
|
|
@@ -146,6 +169,8 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
146
169
|
console.log(`- React Native: ${reactNativePath}`);
|
|
147
170
|
console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
|
|
148
171
|
console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);
|
|
172
|
+
console.log(`- Watch Folders: ${watchFolders.join(', ')}`);
|
|
173
|
+
console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);
|
|
149
174
|
console.log(`- Exotic: ${isExotic}`);
|
|
150
175
|
console.log();
|
|
151
176
|
}
|
|
@@ -153,13 +178,33 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
153
178
|
// Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
|
|
154
179
|
// This prints a giant React logo which is less accessible to users on smaller terminals.
|
|
155
180
|
reporter, ...metroDefaultValues } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
|
|
181
|
+
const customEnhanceMiddleware = (_a = metroDefaultValues.server) === null || _a === void 0 ? void 0 : _a.enhanceMiddleware;
|
|
182
|
+
// @ts-ignore can't mutate readonly config
|
|
183
|
+
const enhanceMiddleware = (metroMiddleware, server) => {
|
|
184
|
+
if (customEnhanceMiddleware) {
|
|
185
|
+
metroMiddleware = customEnhanceMiddleware(metroMiddleware, server);
|
|
186
|
+
}
|
|
187
|
+
const debug = require('debug')('expo:metro-config:middleware');
|
|
188
|
+
// Add extra middleware to redirect assets in a monorepo.
|
|
189
|
+
return (req, res, next) => {
|
|
190
|
+
const { url } = req;
|
|
191
|
+
if (url && url.startsWith('/assets/')) {
|
|
192
|
+
// Added by the assetPlugins
|
|
193
|
+
req.url = url.replace(/@@\//g, '../');
|
|
194
|
+
debug('Redirect asset:', url, '->', req.url);
|
|
195
|
+
}
|
|
196
|
+
return metroMiddleware(req, res, next);
|
|
197
|
+
};
|
|
198
|
+
};
|
|
156
199
|
// Merge in the default config from Metro here, even though loadConfig uses it as defaults.
|
|
157
200
|
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
158
201
|
return MetroConfig.mergeConfig(metroDefaultValues, {
|
|
202
|
+
watchFolders,
|
|
159
203
|
resolver: {
|
|
160
204
|
resolverMainFields,
|
|
161
205
|
platforms: ['ios', 'android', 'native'],
|
|
162
206
|
sourceExts,
|
|
207
|
+
nodeModulesPaths,
|
|
163
208
|
},
|
|
164
209
|
serializer: {
|
|
165
210
|
getModulesRunBeforeMainModule: () => [
|
|
@@ -170,6 +215,7 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
170
215
|
},
|
|
171
216
|
server: {
|
|
172
217
|
port: Number(process.env.RCT_METRO_PORT) || 8081,
|
|
218
|
+
enhanceMiddleware,
|
|
173
219
|
},
|
|
174
220
|
symbolicator: {
|
|
175
221
|
customizeFrame: frame => {
|
|
@@ -200,7 +246,7 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
200
246
|
: // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
|
|
201
247
|
require.resolve('./transformer/metro-expo-babel-transformer'),
|
|
202
248
|
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
|
|
203
|
-
assetPlugins:
|
|
249
|
+
assetPlugins: getAssetPlugins(projectRoot),
|
|
204
250
|
},
|
|
205
251
|
});
|
|
206
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,yCAAkG;AAClG,8CAA6E;AAC7E,kDAA0B;AAC1B,mCAAiC;AAGjC,gDAAwB;AACxB,gEAAuC;AAEvC,qEAAwE;AAE3D,QAAA,UAAU,GAAG,gBAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACvD,MAAM,eAAe,GAAG,gBAAO,CAAC,iBAAiB,EAAE,KAAK,CA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B,CAAC,CAAC,CAAC,CAAC,EAAE;SAC7D;KACF,CAAC,CAAC;AACL,CAAC;AAlLD,4CAkLC;AAWM,KAAK,UAAU,SAAS,CAC7B,WAAmB,EACnB,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,KAAkB,EAAE;IAEvD,IAAI,aAAa,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,QAAQ,EAAE,CAAC;KAChD;IACD,MAAM,WAAW,GAAG,qDAA4B,CAAC,WAAW,CAAC,CAAC;IAC9D,OAAO,MAAM,WAAW,CAAC,UAAU,CACjC,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,EAAE,EAClD,aAAa,CACd,CAAC;AACJ,CAAC;AAbD,8BAaC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { getConfig, getDefaultTarget, isLegacyImportsEnabled, ProjectTarget } from '@expo/config';\nimport { getBareExtensions, getManagedExtensions } from '@expo/config/paths';\nimport chalk from 'chalk';\nimport { boolish } from 'getenv';\nimport { Reporter } from 'metro';\nimport type MetroConfig from 'metro-config';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { importMetroConfigFromProject } from './importMetroFromProject';\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_USE_EXOTIC = boolish('EXPO_USE_EXOTIC', false);\n\n// Import only the types here, the values will be imported from the project, at runtime.\nexport const INTERNAL_CALLSITES_REGEX = new RegExp(\n [\n '/Libraries/Renderer/implementations/.+\\\\.js$',\n '/Libraries/BatchedBridge/MessageQueue\\\\.js$',\n '/Libraries/YellowBox/.+\\\\.js$',\n '/Libraries/LogBox/.+\\\\.js$',\n '/Libraries/Core/Timers/.+\\\\.js$',\n 'node_modules/react-devtools-core/.+\\\\.js$',\n 'node_modules/react-refresh/.+\\\\.js$',\n 'node_modules/scheduler/.+\\\\.js$',\n // Metro replaces `require()` with a different method,\n // we want to omit this method from the stack trace.\n // This is akin to most React tooling.\n '/metro/.*/polyfills/require.js$',\n // Hide frames related to a fast refresh.\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n 'node_modules/react-native/Libraries/Utilities/HMRClient.js$',\n 'node_modules/eventemitter3/index.js',\n 'node_modules/event-target-shim/dist/.+\\\\.js$',\n // Ignore the log forwarder used in the Expo Go app\n '/expo/build/environment/react-native-logs.fx.js$',\n '/src/environment/react-native-logs.fx.ts$',\n '/expo/build/logs/RemoteConsole.js$',\n // Improve errors thrown by invariant (ex: `Invariant Violation: \"main\" has not been registered`).\n 'node_modules/invariant/.+\\\\.js$',\n // Remove babel runtime additions\n 'node_modules/regenerator-runtime/.+\\\\.js$',\n // Remove react native setImmediate ponyfill\n 'node_modules/promise/setimmediate/.+\\\\.js$',\n // Babel helpers that implement language features\n 'node_modules/@babel/runtime/.+\\\\.js$',\n // Block native code invocations\n `\\\\[native code\\\\]`,\n ].join('|')\n);\n\nexport interface DefaultConfigOptions {\n target?: ProjectTarget;\n mode?: 'exotic';\n}\n\nfunction readIsLegacyImportsEnabled(projectRoot: string): boolean {\n const config = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n return isLegacyImportsEnabled(config.exp);\n}\n\nfunction getProjectBabelConfigFile(projectRoot: string): string | undefined {\n return (\n resolveFrom.silent(projectRoot, './babel.config.js') ||\n resolveFrom.silent(projectRoot, './.babelrc') ||\n resolveFrom.silent(projectRoot, './.babelrc.js')\n );\n}\n\nlet hasWarnedAboutExotic = false;\n\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\n const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;\n\n if (isExotic && !hasWarnedAboutExotic) {\n hasWarnedAboutExotic = true;\n console.log(\n chalk.gray(\n `\\u203A Unstable feature ${chalk.bold`EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`\n )\n );\n }\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n\n const reactNativePath = path.dirname(resolveFrom(projectRoot, 'react-native/package.json'));\n\n try {\n // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.\n // This hack is used because there doesn't appear to be anyway to resolve\n // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).\n const babelPresetFbjsPath = resolveFrom(projectRoot, 'babel-preset-fbjs/package.json');\n process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);\n } catch {\n // noop -- falls back to a hardcoded value.\n }\n\n let hashAssetFilesPath;\n try {\n hashAssetFilesPath = resolveFrom(projectRoot, 'expo-asset/tools/hashAssetFiles');\n } catch {\n // TODO: we should warn/throw an error if the user has expo-updates installed but does not\n // have hashAssetFiles available, or if the user is in managed workflow and does not have\n // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,\n // it is not needed\n }\n\n const isLegacy = readIsLegacyImportsEnabled(projectRoot);\n // Deprecated -- SDK 41 --\n if (options.target) {\n if (!isLegacy) {\n console.warn(\n chalk.yellow(\n `The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`\n )\n );\n delete options.target;\n }\n } else if (process.env.EXPO_TARGET) {\n console.error(\n 'EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration'\n );\n if (isLegacy) {\n // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is\n // called from metro.config.js.\n // @ts-ignore\n options.target = process.env.EXPO_TARGET;\n }\n } else if (isLegacy) {\n // Fall back to guessing based on the project structure in legacy mode.\n options.target = getDefaultTarget(projectRoot);\n }\n\n if (!options.target) {\n // Default to bare -- no .expo extension.\n options.target = 'bare';\n }\n // End deprecated -- SDK 41 --\n\n const { target } = options;\n if (!(target === 'managed' || target === 'bare')) {\n throw new Error(\n `Invalid target: '${target}'. Debug info: \\n${JSON.stringify(\n {\n 'options.target': options.target,\n default: getDefaultTarget(projectRoot),\n },\n null,\n 2\n )}`\n );\n }\n const sourceExtsConfig = { isTS: true, isReact: true, isModern: false };\n const sourceExts =\n target === 'bare'\n ? getBareExtensions([], sourceExtsConfig)\n : getManagedExtensions([], sourceExtsConfig);\n\n if (isExotic) {\n // Add support for cjs (without platform extensions).\n sourceExts.push('cjs');\n }\n\n const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\n\n const resolverMainFields: string[] = [];\n\n // Disable `react-native` in exotic mode, since library authors\n // use it to ship raw application code to the project.\n if (!isExotic) {\n resolverMainFields.push('react-native');\n }\n resolverMainFields.push('browser', 'main');\n\n if (EXPO_DEBUG) {\n console.log();\n console.log(`Expo Metro config:`);\n console.log(`- Bundler target: ${target}`);\n console.log(`- Legacy: ${isLegacy}`);\n console.log(`- Extensions: ${sourceExts.join(', ')}`);\n console.log(`- React Native: ${reactNativePath}`);\n console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);\n console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);\n console.log(`- Exotic: ${isExotic}`);\n console.log();\n }\n const {\n // Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.\n // This prints a giant React logo which is less accessible to users on smaller terminals.\n reporter,\n ...metroDefaultValues\n } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);\n\n // Merge in the default config from Metro here, even though loadConfig uses it as defaults.\n // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.\n return MetroConfig.mergeConfig(metroDefaultValues, {\n resolver: {\n resolverMainFields,\n platforms: ['ios', 'android', 'native'],\n sourceExts,\n },\n serializer: {\n getModulesRunBeforeMainModule: () => [\n require.resolve(path.join(reactNativePath, 'Libraries/Core/InitializeCore')),\n // TODO: Bacon: load Expo side-effects\n ],\n getPolyfills: () => require(path.join(reactNativePath, 'rn-get-polyfills'))(),\n },\n server: {\n port: Number(process.env.RCT_METRO_PORT) || 8081,\n },\n symbolicator: {\n customizeFrame: frame => {\n let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));\n\n if (!collapse) {\n // This represents the first frame of the stacktrace.\n // Often this looks like: `__r(0);`.\n // The URL will also be unactionable in the app and therefore not very useful to the developer.\n if (\n frame.column === 3 &&\n frame.methodName === 'global code' &&\n frame.file?.match(/^https?:\\/\\//g)\n ) {\n collapse = true;\n }\n }\n\n return { ...(frame || {}), collapse };\n },\n },\n transformer: {\n allowOptionalDependencies: true,\n babelTransformerPath: isExotic\n ? require.resolve('./transformer/metro-expo-exotic-babel-transformer')\n : isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n // Try to use the project copy before falling back on the global version\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./transformer/metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : [],\n },\n });\n}\n\nexport interface LoadOptions {\n config?: string;\n maxWorkers?: number;\n port?: number;\n reporter?: Reporter;\n resetCache?: boolean;\n target?: ProjectTarget;\n}\n\nexport async function loadAsync(\n projectRoot: string,\n { reporter, target, ...metroOptions }: LoadOptions = {}\n): Promise<MetroConfig.ConfigT> {\n let defaultConfig = getDefaultConfig(projectRoot, { target });\n if (reporter) {\n defaultConfig = { ...defaultConfig, reporter };\n }\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n return await MetroConfig.loadConfig(\n { cwd: projectRoot, projectRoot, ...metroOptions },\n defaultConfig\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,yCAAkG;AAClG,8CAA6E;AAC7E,k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,MAAM,WAAW,CAAC,UAAU,CACjC,EAAE,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,YAAY,EAAE,EAClD,aAAa,CACd,CAAC;AACJ,CAAC;AAbD,8BAaC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { getConfig, getDefaultTarget, isLegacyImportsEnabled, ProjectTarget } from '@expo/config';\nimport { getBareExtensions, getManagedExtensions } from '@expo/config/paths';\nimport chalk from 'chalk';\nimport findWorkspaceRoot from 'find-yarn-workspace-root';\nimport { boolish } from 'getenv';\nimport type { IncomingMessage, ServerResponse } from 'http';\nimport { Reporter } from 'metro';\nimport type MetroConfig from 'metro-config';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { getWatchFolders } from './getWatchFolders';\nimport { importMetroConfigFromProject } from './importMetroFromProject';\n\nexport function getModulesPaths(projectRoot: string): string[] {\n const paths: string[] = [];\n paths.push(path.resolve(projectRoot, 'node_modules'));\n\n const workspaceRoot = findWorkspaceRoot(path.resolve(projectRoot)); // Absolute path or null\n if (workspaceRoot) {\n paths.push(path.resolve(workspaceRoot, 'node_modules'));\n }\n\n return paths;\n}\n\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', false);\nconst EXPO_USE_EXOTIC = boolish('EXPO_USE_EXOTIC', false);\n\n// Import only the types here, the values will be imported from the project, at runtime.\nexport const INTERNAL_CALLSITES_REGEX = new RegExp(\n [\n '/Libraries/Renderer/implementations/.+\\\\.js$',\n '/Libraries/BatchedBridge/MessageQueue\\\\.js$',\n '/Libraries/YellowBox/.+\\\\.js$',\n '/Libraries/LogBox/.+\\\\.js$',\n '/Libraries/Core/Timers/.+\\\\.js$',\n 'node_modules/react-devtools-core/.+\\\\.js$',\n 'node_modules/react-refresh/.+\\\\.js$',\n 'node_modules/scheduler/.+\\\\.js$',\n // Metro replaces `require()` with a different method,\n // we want to omit this method from the stack trace.\n // This is akin to most React tooling.\n '/metro/.*/polyfills/require.js$',\n // Hide frames related to a fast refresh.\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n '/metro/.*/lib/bundle-modules/.+\\\\.js$',\n 'node_modules/react-native/Libraries/Utilities/HMRClient.js$',\n 'node_modules/eventemitter3/index.js',\n 'node_modules/event-target-shim/dist/.+\\\\.js$',\n // Ignore the log forwarder used in the Expo Go app\n '/expo/build/environment/react-native-logs.fx.js$',\n '/src/environment/react-native-logs.fx.ts$',\n '/expo/build/logs/RemoteConsole.js$',\n // Improve errors thrown by invariant (ex: `Invariant Violation: \"main\" has not been registered`).\n 'node_modules/invariant/.+\\\\.js$',\n // Remove babel runtime additions\n 'node_modules/regenerator-runtime/.+\\\\.js$',\n // Remove react native setImmediate ponyfill\n 'node_modules/promise/setimmediate/.+\\\\.js$',\n // Babel helpers that implement language features\n 'node_modules/@babel/runtime/.+\\\\.js$',\n // Block native code invocations\n `\\\\[native code\\\\]`,\n ].join('|')\n);\n\nexport interface DefaultConfigOptions {\n target?: ProjectTarget;\n mode?: 'exotic';\n}\n\nfunction readIsLegacyImportsEnabled(projectRoot: string): boolean {\n const config = getConfig(projectRoot, { skipSDKVersionRequirement: true });\n return isLegacyImportsEnabled(config.exp);\n}\n\nfunction getProjectBabelConfigFile(projectRoot: string): string | undefined {\n return (\n resolveFrom.silent(projectRoot, './babel.config.js') ||\n resolveFrom.silent(projectRoot, './.babelrc') ||\n resolveFrom.silent(projectRoot, './.babelrc.js')\n );\n}\n\nfunction getAssetPlugins(projectRoot: string): string[] {\n const assetPlugins: string[] = [];\n\n assetPlugins.push(require.resolve('./monorepoAssetsPlugin'));\n\n let hashAssetFilesPath;\n try {\n hashAssetFilesPath = resolveFrom(projectRoot, 'expo-asset/tools/hashAssetFiles');\n } catch {\n // TODO: we should warn/throw an error if the user has expo-updates installed but does not\n // have hashAssetFiles available, or if the user is in managed workflow and does not have\n // hashAssetFiles available. but in a bare app w/o expo-updates, just using dev-client,\n // it is not needed\n }\n\n if (hashAssetFilesPath) {\n assetPlugins.push(hashAssetFilesPath);\n }\n\n return assetPlugins;\n}\n\nlet hasWarnedAboutExotic = false;\n\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\n const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;\n\n if (isExotic && !hasWarnedAboutExotic) {\n hasWarnedAboutExotic = true;\n console.log(\n chalk.gray(\n `\\u203A Unstable feature ${chalk.bold`EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`\n )\n );\n }\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n\n const reactNativePath = path.dirname(resolveFrom(projectRoot, 'react-native/package.json'));\n\n try {\n // Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.\n // This hack is used because there doesn't appear to be anyway to resolve\n // `babel-preset-fbjs` relative to the project root later (in `metro-expo-babel-transformer`).\n const babelPresetFbjsPath = resolveFrom(projectRoot, 'babel-preset-fbjs/package.json');\n process.env.EXPO_METRO_CACHE_KEY_VERSION = String(require(babelPresetFbjsPath).version);\n } catch {\n // noop -- falls back to a hardcoded value.\n }\n\n const isLegacy = readIsLegacyImportsEnabled(projectRoot);\n // Deprecated -- SDK 41 --\n if (options.target) {\n if (!isLegacy) {\n console.warn(\n chalk.yellow(\n `The target option is deprecated. Learn more: http://expo.fyi/expo-extension-migration`\n )\n );\n delete options.target;\n }\n } else if (process.env.EXPO_TARGET) {\n console.error(\n 'EXPO_TARGET is deprecated. Learn more: http://expo.fyi/expo-extension-migration'\n );\n if (isLegacy) {\n // EXPO_TARGET is used by @expo/metro-config to determine the target when getDefaultConfig is\n // called from metro.config.js.\n // @ts-ignore\n options.target = process.env.EXPO_TARGET;\n }\n } else if (isLegacy) {\n // Fall back to guessing based on the project structure in legacy mode.\n options.target = getDefaultTarget(projectRoot);\n }\n\n if (!options.target) {\n // Default to bare -- no .expo extension.\n options.target = 'bare';\n }\n // End deprecated -- SDK 41 --\n\n const { target } = options;\n if (!(target === 'managed' || target === 'bare')) {\n throw new Error(\n `Invalid target: '${target}'. Debug info: \\n${JSON.stringify(\n {\n 'options.target': options.target,\n default: getDefaultTarget(projectRoot),\n },\n null,\n 2\n )}`\n );\n }\n const sourceExtsConfig = { isTS: true, isReact: true, isModern: false };\n const sourceExts =\n target === 'bare'\n ? getBareExtensions([], sourceExtsConfig)\n : getManagedExtensions([], sourceExtsConfig);\n\n if (isExotic) {\n // Add support for cjs (without platform extensions).\n sourceExts.push('cjs');\n }\n\n const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\n\n const resolverMainFields: string[] = [];\n\n // Disable `react-native` in exotic mode, since library authors\n // use it to ship raw application code to the project.\n if (!isExotic) {\n resolverMainFields.push('react-native');\n }\n resolverMainFields.push('browser', 'main');\n\n const watchFolders = getWatchFolders(projectRoot);\n const nodeModulesPaths = getModulesPaths(projectRoot);\n if (EXPO_DEBUG) {\n console.log();\n console.log(`Expo Metro config:`);\n console.log(`- Bundler target: ${target}`);\n console.log(`- Legacy: ${isLegacy}`);\n console.log(`- Extensions: ${sourceExts.join(', ')}`);\n console.log(`- React Native: ${reactNativePath}`);\n console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);\n console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);\n console.log(`- Watch Folders: ${watchFolders.join(', ')}`);\n console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);\n console.log(`- Exotic: ${isExotic}`);\n console.log();\n }\n const {\n // Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.\n // This prints a giant React logo which is less accessible to users on smaller terminals.\n reporter,\n ...metroDefaultValues\n } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);\n\n const customEnhanceMiddleware = metroDefaultValues.server?.enhanceMiddleware;\n\n // @ts-ignore can't mutate readonly config\n const enhanceMiddleware = (metroMiddleware: any, server: Metro.Server) => {\n if (customEnhanceMiddleware) {\n metroMiddleware = customEnhanceMiddleware(metroMiddleware, server);\n }\n\n const debug = require('debug')('expo:metro-config:middleware');\n\n // Add extra middleware to redirect assets in a monorepo.\n return (req: IncomingMessage, res: ServerResponse, next: (err?: Error) => void) => {\n const { url } = req;\n if (url && url.startsWith('/assets/')) {\n // Added by the assetPlugins\n req.url = url.replace(/@@\\//g, '../');\n debug('Redirect asset:', url, '->', req.url);\n }\n\n return metroMiddleware(req, res, next);\n };\n };\n\n // Merge in the default config from Metro here, even though loadConfig uses it as defaults.\n // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.\n return MetroConfig.mergeConfig(metroDefaultValues, {\n watchFolders,\n resolver: {\n resolverMainFields,\n platforms: ['ios', 'android', 'native'],\n sourceExts,\n nodeModulesPaths,\n },\n serializer: {\n getModulesRunBeforeMainModule: () => [\n require.resolve(path.join(reactNativePath, 'Libraries/Core/InitializeCore')),\n // TODO: Bacon: load Expo side-effects\n ],\n getPolyfills: () => require(path.join(reactNativePath, 'rn-get-polyfills'))(),\n },\n server: {\n port: Number(process.env.RCT_METRO_PORT) || 8081,\n enhanceMiddleware,\n },\n symbolicator: {\n customizeFrame: frame => {\n let collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));\n\n if (!collapse) {\n // This represents the first frame of the stacktrace.\n // Often this looks like: `__r(0);`.\n // The URL will also be unactionable in the app and therefore not very useful to the developer.\n if (\n frame.column === 3 &&\n frame.methodName === 'global code' &&\n frame.file?.match(/^https?:\\/\\//g)\n ) {\n collapse = true;\n }\n }\n\n return { ...(frame || {}), collapse };\n },\n },\n transformer: {\n allowOptionalDependencies: true,\n babelTransformerPath: isExotic\n ? require.resolve('./transformer/metro-expo-exotic-babel-transformer')\n : isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n // Try to use the project copy before falling back on the global version\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./transformer/metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: getAssetPlugins(projectRoot),\n },\n });\n}\n\nexport interface LoadOptions {\n config?: string;\n maxWorkers?: number;\n port?: number;\n reporter?: Reporter;\n resetCache?: boolean;\n target?: ProjectTarget;\n}\n\nexport async function loadAsync(\n projectRoot: string,\n { reporter, target, ...metroOptions }: LoadOptions = {}\n): Promise<MetroConfig.ConfigT> {\n let defaultConfig = getDefaultConfig(projectRoot, { target });\n if (reporter) {\n defaultConfig = { ...defaultConfig, reporter };\n }\n const MetroConfig = importMetroConfigFromProject(projectRoot);\n return await MetroConfig.loadConfig(\n { cwd: projectRoot, projectRoot, ...metroOptions },\n defaultConfig\n );\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param workspaceProjectRoot Root file path for the yarn workspace
|
|
3
|
+
* @param linkedPackages List of folders that contain linked node modules, ex: `['packages/*', 'apps/*']`
|
|
4
|
+
* @returns List of valid package.json file paths, ex: `['/Users/me/app/apps/my-app/package.json', '/Users/me/app/packages/my-package/package.json']`
|
|
5
|
+
*/
|
|
6
|
+
export declare function globAllPackageJsonPaths(workspaceProjectRoot: string, linkedPackages: string[]): string[];
|
|
7
|
+
/**
|
|
8
|
+
* @param workspaceProjectRoot root file path for a yarn workspace.
|
|
9
|
+
* @returns list of package.json file paths that are linked to the yarn workspace.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveAllWorkspacePackageJsonPaths(workspaceProjectRoot: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* @param projectRoot file path to app's project root
|
|
14
|
+
* @returns list of node module paths to watch in Metro bundler, ex: `['/Users/me/app/node_modules/', '/Users/me/app/apps/my-app/', '/Users/me/app/packages/my-package/']`
|
|
15
|
+
*/
|
|
16
|
+
export declare function getWatchFolders(projectRoot: string): string[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWatchFolders = exports.resolveAllWorkspacePackageJsonPaths = exports.globAllPackageJsonPaths = void 0;
|
|
7
|
+
const json_file_1 = __importDefault(require("@expo/json-file"));
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const find_yarn_workspace_root_1 = __importDefault(require("find-yarn-workspace-root"));
|
|
10
|
+
const glob_1 = require("glob");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
/**
|
|
13
|
+
* @param workspaceProjectRoot Root file path for the yarn workspace
|
|
14
|
+
* @param linkedPackages List of folders that contain linked node modules, ex: `['packages/*', 'apps/*']`
|
|
15
|
+
* @returns List of valid package.json file paths, ex: `['/Users/me/app/apps/my-app/package.json', '/Users/me/app/packages/my-package/package.json']`
|
|
16
|
+
*/
|
|
17
|
+
function globAllPackageJsonPaths(workspaceProjectRoot, linkedPackages) {
|
|
18
|
+
return linkedPackages
|
|
19
|
+
.map(glob => {
|
|
20
|
+
return glob_1.sync(path_1.default.join(glob, 'package.json').replace(/\\/g, '/'), {
|
|
21
|
+
cwd: workspaceProjectRoot,
|
|
22
|
+
absolute: true,
|
|
23
|
+
ignore: ['**/@(Carthage|Pods|node_modules)/**'],
|
|
24
|
+
}).map(pkgPath => {
|
|
25
|
+
try {
|
|
26
|
+
json_file_1.default.read(pkgPath);
|
|
27
|
+
return pkgPath;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Skip adding path if the package.json is invalid or cannot be read.
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
.flat()
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.map(p => path_1.default.join(p));
|
|
38
|
+
}
|
|
39
|
+
exports.globAllPackageJsonPaths = globAllPackageJsonPaths;
|
|
40
|
+
function getWorkspacePackagesArray({ workspaces }) {
|
|
41
|
+
if (Array.isArray(workspaces)) {
|
|
42
|
+
return workspaces;
|
|
43
|
+
}
|
|
44
|
+
assert_1.default(workspaces === null || workspaces === void 0 ? void 0 : workspaces.packages, 'Could not find a `workspaces` object in the root package.json');
|
|
45
|
+
return workspaces.packages;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @param workspaceProjectRoot root file path for a yarn workspace.
|
|
49
|
+
* @returns list of package.json file paths that are linked to the yarn workspace.
|
|
50
|
+
*/
|
|
51
|
+
function resolveAllWorkspacePackageJsonPaths(workspaceProjectRoot) {
|
|
52
|
+
try {
|
|
53
|
+
const rootPackageJsonFilePath = path_1.default.join(workspaceProjectRoot, 'package.json');
|
|
54
|
+
// Could throw if package.json is invalid.
|
|
55
|
+
const rootPackageJson = json_file_1.default.read(rootPackageJsonFilePath);
|
|
56
|
+
// Extract the "packages" array or use "workspaces" as packages array (yarn workspaces spec).
|
|
57
|
+
const packages = getWorkspacePackagesArray(rootPackageJson);
|
|
58
|
+
// Glob all package.json files and return valid paths.
|
|
59
|
+
return globAllPackageJsonPaths(workspaceProjectRoot, packages);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.resolveAllWorkspacePackageJsonPaths = resolveAllWorkspacePackageJsonPaths;
|
|
66
|
+
/**
|
|
67
|
+
* @param projectRoot file path to app's project root
|
|
68
|
+
* @returns list of node module paths to watch in Metro bundler, ex: `['/Users/me/app/node_modules/', '/Users/me/app/apps/my-app/', '/Users/me/app/packages/my-package/']`
|
|
69
|
+
*/
|
|
70
|
+
function getWatchFolders(projectRoot) {
|
|
71
|
+
const workspaceRoot = find_yarn_workspace_root_1.default(path_1.default.resolve(projectRoot));
|
|
72
|
+
// Rely on default behavior in standard projects.
|
|
73
|
+
if (!workspaceRoot) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const packages = resolveAllWorkspacePackageJsonPaths(workspaceRoot);
|
|
77
|
+
if (!packages.length) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return uniqueItems([
|
|
81
|
+
path_1.default.join(workspaceRoot, 'node_modules'),
|
|
82
|
+
...packages.map(pkg => path_1.default.dirname(pkg)),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
exports.getWatchFolders = getWatchFolders;
|
|
86
|
+
function uniqueItems(items) {
|
|
87
|
+
return [...new Set(items)];
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=getWatchFolders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWatchFolders.js","sourceRoot":"","sources":["../src/getWatchFolders.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AACvC,oDAA4B;AAC5B,wFAAyD;AACzD,+BAAwC;AACxC,gDAAwB;AAExB;;;;GAIG;AACH,SAAgB,uBAAuB,CACrC,oBAA4B,EAC5B,cAAwB;IAExB,OAAO,cAAc;SAClB,GAAG,CAAC,IAAI,CAAC,EAAE;QACV,OAAO,WAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE;YACnE,GAAG,EAAE,oBAAoB;YACzB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,CAAC,qCAAqC,CAAC;SAChD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACf,IAAI;gBACF,mBAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACvB,OAAO,OAAO,CAAC;aAChB;YAAC,MAAM;gBACN,qEAAqE;aACtE;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;SACD,IAAI,EAAE;SACN,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,c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AG,CAAC,GAAG,CAAC,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAhBD,0CAgBC;AAED,SAAS,WAAW,CAAC,KAAe;IAClC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import JsonFile from '@expo/json-file';\nimport assert from 'assert';\nimport findWorkspaceRoot from 'find-yarn-workspace-root';\nimport { sync as globSync } from 'glob';\nimport path from 'path';\n\n/**\n * @param workspaceProjectRoot Root file path for the yarn workspace\n * @param linkedPackages List of folders that contain linked node modules, ex: `['packages/*', 'apps/*']`\n * @returns List of valid package.json file paths, ex: `['/Users/me/app/apps/my-app/package.json', '/Users/me/app/packages/my-package/package.json']`\n */\nexport function globAllPackageJsonPaths(\n workspaceProjectRoot: string,\n linkedPackages: string[]\n): string[] {\n return linkedPackages\n .map(glob => {\n return globSync(path.join(glob, 'package.json').replace(/\\\\/g, '/'), {\n cwd: workspaceProjectRoot,\n absolute: true,\n ignore: ['**/@(Carthage|Pods|node_modules)/**'],\n }).map(pkgPath => {\n try {\n JsonFile.read(pkgPath);\n return pkgPath;\n } catch {\n // Skip adding path if the package.json is invalid or cannot be read.\n }\n return null;\n });\n })\n .flat()\n .filter(Boolean)\n .map(p => path.join(p as string));\n}\n\nfunction getWorkspacePackagesArray({ workspaces }: any): string[] {\n if (Array.isArray(workspaces)) {\n return workspaces;\n }\n\n assert(workspaces?.packages, 'Could not find a `workspaces` object in the root package.json');\n\n return workspaces.packages;\n}\n\n/**\n * @param workspaceProjectRoot root file path for a yarn workspace.\n * @returns list of package.json file paths that are linked to the yarn workspace.\n */\nexport function resolveAllWorkspacePackageJsonPaths(workspaceProjectRoot: string) {\n try {\n const rootPackageJsonFilePath = path.join(workspaceProjectRoot, 'package.json');\n // Could throw if package.json is invalid.\n const rootPackageJson = JsonFile.read(rootPackageJsonFilePath);\n\n // Extract the \"packages\" array or use \"workspaces\" as packages array (yarn workspaces spec).\n const packages = getWorkspacePackagesArray(rootPackageJson);\n\n // Glob all package.json files and return valid paths.\n return globAllPackageJsonPaths(workspaceProjectRoot, packages);\n } catch {\n return [];\n }\n}\n\n/**\n * @param projectRoot file path to app's project root\n * @returns list of node module paths to watch in Metro bundler, ex: `['/Users/me/app/node_modules/', '/Users/me/app/apps/my-app/', '/Users/me/app/packages/my-package/']`\n */\nexport function getWatchFolders(projectRoot: string): string[] {\n const workspaceRoot = findWorkspaceRoot(path.resolve(projectRoot));\n // Rely on default behavior in standard projects.\n if (!workspaceRoot) {\n return [];\n }\n\n const packages = resolveAllWorkspacePackageJsonPaths(workspaceRoot);\n if (!packages.length) {\n return [];\n }\n\n return uniqueItems([\n path.join(workspaceRoot, 'node_modules'),\n ...packages.map(pkg => path.dirname(pkg)),\n ]);\n}\n\nfunction uniqueItems(items: string[]): string[] {\n return [...new Set(items)];\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assets work by fetching from the localhost using a filepath, example:
|
|
3
|
+
* `./icon.png` would be fetched via `http://127.0.0.1:19000/assets/./icon.png`
|
|
4
|
+
*
|
|
5
|
+
* In the case of a monorepo, you may need to reach outside of the root folder:
|
|
6
|
+
*
|
|
7
|
+
* App running at `monorepo/apps/my-app/` would fetch a resource from `monorepo/node_modules/my-package/icon.png`
|
|
8
|
+
* this would be done with `http://127.0.0.1:19000/assets/../../node_modules/my-package/icon.png`.
|
|
9
|
+
*
|
|
10
|
+
* The problem is that Metro dev server would collapse this URL into `http://127.0.0.1:19000/node_modules/my-package/icon.png` which is invalid.
|
|
11
|
+
*
|
|
12
|
+
* To combat this, we replace the `../` with a random character that cannot be collapsed: `@@/` (must be a character that can be encoded), then we add some dev server middleware to transform this back to `../` before fetching the asset.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
declare function monorepoAssetsPlugin(assetData: {
|
|
16
|
+
httpServerLocation: string;
|
|
17
|
+
}): {
|
|
18
|
+
httpServerLocation: string;
|
|
19
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Assets work by fetching from the localhost using a filepath, example:
|
|
4
|
+
* `./icon.png` would be fetched via `http://127.0.0.1:19000/assets/./icon.png`
|
|
5
|
+
*
|
|
6
|
+
* In the case of a monorepo, you may need to reach outside of the root folder:
|
|
7
|
+
*
|
|
8
|
+
* App running at `monorepo/apps/my-app/` would fetch a resource from `monorepo/node_modules/my-package/icon.png`
|
|
9
|
+
* this would be done with `http://127.0.0.1:19000/assets/../../node_modules/my-package/icon.png`.
|
|
10
|
+
*
|
|
11
|
+
* The problem is that Metro dev server would collapse this URL into `http://127.0.0.1:19000/node_modules/my-package/icon.png` which is invalid.
|
|
12
|
+
*
|
|
13
|
+
* To combat this, we replace the `../` with a random character that cannot be collapsed: `@@/` (must be a character that can be encoded), then we add some dev server middleware to transform this back to `../` before fetching the asset.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
function monorepoAssetsPlugin(assetData) {
|
|
17
|
+
assetData.httpServerLocation = assetData.httpServerLocation.replace(/\.\.\//g, '@@/');
|
|
18
|
+
return assetData;
|
|
19
|
+
}
|
|
20
|
+
// Export with `module.exports` for Metro asset plugin loading.
|
|
21
|
+
module.exports = monorepoAssetsPlugin;
|
|
22
|
+
//# sourceMappingURL=monorepoAssetsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monorepoAssetsPlugin.js","sourceRoot":"","sources":["../src/monorepoAssetsPlugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;AACH,SAAS,oBAAoB,CAAC,SAAyC;IACrE,SAAS,CAAC,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACtF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,+DAA+D;AAC/D,MAAM,CAAC,OAAO,GAAG,oBAAoB,CAAC","sourcesContent":["/**\n * Assets work by fetching from the localhost using a filepath, example:\n * `./icon.png` would be fetched via `http://127.0.0.1:19000/assets/./icon.png`\n *\n * In the case of a monorepo, you may need to reach outside of the root folder:\n *\n * App running at `monorepo/apps/my-app/` would fetch a resource from `monorepo/node_modules/my-package/icon.png`\n * this would be done with `http://127.0.0.1:19000/assets/../../node_modules/my-package/icon.png`.\n *\n * The problem is that Metro dev server would collapse this URL into `http://127.0.0.1:19000/node_modules/my-package/icon.png` which is invalid.\n *\n * To combat this, we replace the `../` with a random character that cannot be collapsed: `@@/` (must be a character that can be encoded), then we add some dev server middleware to transform this back to `../` before fetching the asset.\n *\n */\nfunction monorepoAssetsPlugin(assetData: { httpServerLocation: string }) {\n assetData.httpServerLocation = assetData.httpServerLocation.replace(/\\.\\.\\//g, '@@/');\n return assetData;\n}\n\n// Export with `module.exports` for Metro asset plugin loading.\nmodule.exports = monorepoAssetsPlugin;\n"]}
|
|
@@ -32,17 +32,15 @@ const getBabelRC = (function () {
|
|
|
32
32
|
// Let's look for a babel config file in the project root.
|
|
33
33
|
// TODO look into adding a command line option to specify this location
|
|
34
34
|
let projectBabelRCPath;
|
|
35
|
-
// Since this is an opt-in system, we can make certain
|
|
36
|
-
// assumptions like dropping support for `.babelrc` to speed up resolution.
|
|
37
35
|
// .babelrc
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
if (projectRoot) {
|
|
37
|
+
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc');
|
|
38
|
+
}
|
|
41
39
|
if (projectBabelRCPath) {
|
|
42
40
|
// .babelrc.js
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (!fs_1.default.existsSync(projectBabelRCPath)) {
|
|
42
|
+
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc.js');
|
|
43
|
+
}
|
|
46
44
|
// babel.config.js
|
|
47
45
|
if (!fs_1.default.existsSync(projectBabelRCPath)) {
|
|
48
46
|
projectBabelRCPath = path_1.default.resolve(projectRoot, 'babel.config.js');
|
|
@@ -63,6 +61,8 @@ const getBabelRC = (function () {
|
|
|
63
61
|
[
|
|
64
62
|
require(presetPath),
|
|
65
63
|
{
|
|
64
|
+
// Default to React 17 automatic JSX transform.
|
|
65
|
+
jsxRuntime: 'automatic',
|
|
66
66
|
...presetOptions,
|
|
67
67
|
disableImportExportTransform: experimentalImportSupport,
|
|
68
68
|
enableBabelRuntime: options.enableBabelRuntime,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBabelConfig.js","sourceRoot":"","sources":["../../src/transformer/getBabelConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAGH,4CAAoB;AAEpB,gDAAwB;AACxB,gEAAuC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC;IAClB,IAAI,OAAO,GAMA,IAAI,CAAC;IAEhB,OAAO,SAAS,WAAW,CAAC,WAAmB,EAAE,OAAgC;;QAC/E,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAE1B,0DAA0D;QAC1D,uEAAuE;QACvE,IAAI,kBAAkB,CAAC;QAEvB,
|
|
1
|
+
{"version":3,"file":"getBabelConfig.js","sourceRoot":"","sources":["../../src/transformer/getBabelConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAGH,4CAAoB;AAEpB,gDAAwB;AACxB,gEAAuC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC;IAClB,IAAI,OAAO,GAMA,IAAI,CAAC;IAEhB,OAAO,SAAS,WAAW,CAAC,WAAmB,EAAE,OAAgC;;QAC/E,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,GAAG,EAAE,OAAO,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AAO,GAAG,EAAE,CAAC;aACrB;YACD,6BAA6B;YAC7B,+EAA+E;YAC/E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC;SACrF;KACF;IAED,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;AACnC,CAAC;AAlDD,wCAkDC","sourcesContent":["/**\n * Copyright (c) Expo.\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Forks the default metro-react-native-babel-transformer and adds support for known transforms.\n */\n\nimport type { PluginItem as BabelPlugins, PluginItem } from '@babel/core';\nimport fs from 'fs';\nimport type { BabelTransformerOptions } from 'metro-babel-transformer';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\n/**\n * Return a memoized function that checks for the existence of a\n * project level .babelrc file, and if it doesn't exist, reads the\n * default RN babelrc file and uses that.\n */\nconst getBabelRC = (function () {\n let babelRC: {\n // `any` to avoid flow type mismatch with Babel 7's internal type of\n // `Array<string>` even though it correctly accepts the usage below.\n presets?: any;\n extends?: string;\n plugins: BabelPlugins;\n } | null = null;\n\n return function _getBabelRC(projectRoot: string, options: BabelTransformerOptions) {\n if (babelRC != null) {\n return babelRC;\n }\n\n babelRC = { plugins: [] };\n\n // Let's look for a babel config file in the project root.\n // TODO look into adding a command line option to specify this location\n let projectBabelRCPath;\n\n // .babelrc\n if (projectRoot) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc');\n }\n\n if (projectBabelRCPath) {\n // .babelrc.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc.js');\n }\n\n // babel.config.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, 'babel.config.js');\n }\n\n // If we found a babel config file, extend our config off of it\n // otherwise the default config will be used\n if (fs.existsSync(projectBabelRCPath)) {\n babelRC.extends = projectBabelRCPath;\n }\n }\n\n // If a babel config file doesn't exist in the project then\n // the default preset for react-native will be used instead.\n if (!babelRC.extends) {\n const { experimentalImportSupport, ...presetOptions } = options;\n\n // Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.\n const presetPath =\n resolveFrom.silent(projectRoot, 'babel-preset-expo') ??\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-preset') ??\n require.resolve('babel-preset-expo');\n\n babelRC.presets = [\n [\n require(presetPath),\n {\n // Default to React 17 automatic JSX transform.\n jsxRuntime: 'automatic',\n ...presetOptions,\n disableImportExportTransform: experimentalImportSupport,\n enableBabelRuntime: options.enableBabelRuntime,\n },\n ],\n ];\n }\n\n return babelRC;\n };\n})();\n\n/**\n * Given a filename and options, build a Babel\n * config object with the appropriate plugins.\n */\nexport function getBabelConfig(\n filename: string,\n options: BabelTransformerOptions,\n plugins: BabelPlugins = []\n) {\n const babelRC = getBabelRC(options.projectRoot, options);\n\n const extraConfig = {\n babelrc: typeof options.enableBabelRCLookup === 'boolean' ? options.enableBabelRCLookup : true,\n code: false,\n filename,\n highlightCode: true,\n };\n\n const config: any = { ...babelRC, ...extraConfig };\n\n // Add extra plugins\n const extraPlugins: (string | PluginItem)[] = [];\n\n // TODO: This probably can be removed\n if (options.inlineRequires) {\n const inlineRequiresPlugin = resolveFrom(\n options.projectRoot,\n 'babel-preset-fbjs/plugins/inline-requires'\n );\n extraPlugins.push(inlineRequiresPlugin);\n }\n\n config.plugins = extraPlugins.concat(config.plugins, plugins);\n\n if (options.dev && options.hot) {\n // Note: this intentionally doesn't include the path separator because\n // I'm not sure which one it should use on Windows, and false positives\n // are unlikely anyway. If you later decide to include the separator,\n // don't forget that the string usually *starts* with \"node_modules\" so\n // the first one often won't be there.\n // TODO: Support monorepos\n const mayContainEditableReactComponents = filename.indexOf('node_modules') === -1;\n\n if (mayContainEditableReactComponents) {\n if (!config.plugins) {\n config.plugins = [];\n }\n // Add react refresh runtime.\n // NOTICE: keep in sync with 'metro-react-native-babel-preset/src/configs/hmr'.\n config.plugins.push(resolveFrom.silent(options.projectRoot, 'react-refresh/babel'));\n }\n }\n\n return { ...babelRC, ...config };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "A Metro config for running React Native projects with the Metro bundler",
|
|
5
5
|
"main": "build/ExpoMetroConfig.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,8 +35,10 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@expo/config": "6.0.6",
|
|
38
|
+
"@expo/json-file": "^8.2.33",
|
|
38
39
|
"chalk": "^4.1.0",
|
|
39
40
|
"debug": "^4.3.2",
|
|
41
|
+
"find-yarn-workspace-root": "~2.0.0",
|
|
40
42
|
"getenv": "^1.0.0",
|
|
41
43
|
"sucrase": "^3.20.0"
|
|
42
44
|
},
|