@expo/metro-config 0.2.7 → 0.2.8
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 +0 -1
- package/build/ExpoMetroConfig.js +12 -58
- package/build/ExpoMetroConfig.js.map +1 -1
- package/package.json +1 -3
- package/build/getWatchFolders.d.ts +0 -16
- package/build/getWatchFolders.js +0 -89
- package/build/getWatchFolders.js.map +0 -1
- package/build/monorepoAssetsPlugin.d.ts +0 -19
- package/build/monorepoAssetsPlugin.js +0 -22
- package/build/monorepoAssetsPlugin.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
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[];
|
|
5
4
|
export declare const EXPO_DEBUG: boolean;
|
|
6
5
|
export declare const INTERNAL_CALLSITES_REGEX: RegExp;
|
|
7
6
|
export interface DefaultConfigOptions {
|
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -4,26 +4,14 @@ 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 =
|
|
7
|
+
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = 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"));
|
|
12
11
|
const getenv_1 = require("getenv");
|
|
13
12
|
const path_1 = __importDefault(require("path"));
|
|
14
13
|
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
15
|
-
const getWatchFolders_1 = require("./getWatchFolders");
|
|
16
14
|
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;
|
|
27
15
|
exports.EXPO_DEBUG = getenv_1.boolish('EXPO_DEBUG', false);
|
|
28
16
|
const EXPO_USE_EXOTIC = getenv_1.boolish('EXPO_USE_EXOTIC', false);
|
|
29
17
|
// Import only the types here, the values will be imported from the project, at runtime.
|
|
@@ -70,27 +58,8 @@ function getProjectBabelConfigFile(projectRoot) {
|
|
|
70
58
|
resolve_from_1.default.silent(projectRoot, './.babelrc') ||
|
|
71
59
|
resolve_from_1.default.silent(projectRoot, './.babelrc.js'));
|
|
72
60
|
}
|
|
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
|
-
}
|
|
91
61
|
let hasWarnedAboutExotic = false;
|
|
92
62
|
function getDefaultConfig(projectRoot, options = {}) {
|
|
93
|
-
var _a;
|
|
94
63
|
const isExotic = options.mode === 'exotic' || EXPO_USE_EXOTIC;
|
|
95
64
|
if (isExotic && !hasWarnedAboutExotic) {
|
|
96
65
|
hasWarnedAboutExotic = true;
|
|
@@ -108,6 +77,16 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
108
77
|
catch {
|
|
109
78
|
// noop -- falls back to a hardcoded value.
|
|
110
79
|
}
|
|
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
|
+
}
|
|
111
90
|
const isLegacy = readIsLegacyImportsEnabled(projectRoot);
|
|
112
91
|
// Deprecated -- SDK 41 --
|
|
113
92
|
if (options.target) {
|
|
@@ -158,8 +137,6 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
158
137
|
resolverMainFields.push('react-native');
|
|
159
138
|
}
|
|
160
139
|
resolverMainFields.push('browser', 'main');
|
|
161
|
-
const watchFolders = getWatchFolders_1.getWatchFolders(projectRoot);
|
|
162
|
-
const nodeModulesPaths = getModulesPaths(projectRoot);
|
|
163
140
|
if (exports.EXPO_DEBUG) {
|
|
164
141
|
console.log();
|
|
165
142
|
console.log(`Expo Metro config:`);
|
|
@@ -169,8 +146,6 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
169
146
|
console.log(`- React Native: ${reactNativePath}`);
|
|
170
147
|
console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
|
|
171
148
|
console.log(`- Resolver Fields: ${resolverMainFields.join(', ')}`);
|
|
172
|
-
console.log(`- Watch Folders: ${watchFolders.join(', ')}`);
|
|
173
|
-
console.log(`- Node Module Paths: ${nodeModulesPaths.join(', ')}`);
|
|
174
149
|
console.log(`- Exotic: ${isExotic}`);
|
|
175
150
|
console.log();
|
|
176
151
|
}
|
|
@@ -178,33 +153,13 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
178
153
|
// Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
|
|
179
154
|
// This prints a giant React logo which is less accessible to users on smaller terminals.
|
|
180
155
|
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
|
-
};
|
|
199
156
|
// Merge in the default config from Metro here, even though loadConfig uses it as defaults.
|
|
200
157
|
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
201
158
|
return MetroConfig.mergeConfig(metroDefaultValues, {
|
|
202
|
-
watchFolders,
|
|
203
159
|
resolver: {
|
|
204
160
|
resolverMainFields,
|
|
205
161
|
platforms: ['ios', 'android', 'native'],
|
|
206
162
|
sourceExts,
|
|
207
|
-
nodeModulesPaths,
|
|
208
163
|
},
|
|
209
164
|
serializer: {
|
|
210
165
|
getModulesRunBeforeMainModule: () => [
|
|
@@ -215,7 +170,6 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
215
170
|
},
|
|
216
171
|
server: {
|
|
217
172
|
port: Number(process.env.RCT_METRO_PORT) || 8081,
|
|
218
|
-
enhanceMiddleware,
|
|
219
173
|
},
|
|
220
174
|
symbolicator: {
|
|
221
175
|
customizeFrame: frame => {
|
|
@@ -246,7 +200,7 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
246
200
|
: // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
|
|
247
201
|
require.resolve('./transformer/metro-expo-babel-transformer'),
|
|
248
202
|
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
|
|
249
|
-
assetPlugins:
|
|
203
|
+
assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : [],
|
|
250
204
|
},
|
|
251
205
|
});
|
|
252
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoMetroConfig.js","sourceRoot":"","sources":["../src/ExpoMetroConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,yCAAkG;AAClG,8CAA6E;AAC7E,kDAA0B;AAC1B,wFAAyD;AACzD,mCAAiC;AAIjC,gDAAwB;AACxB,gEAAuC;AAEvC,uDAAoD;AACpD,qEAAwE;AAExE,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;IAE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AAA,EAClC;wBACA,QAAQ,GAAG,IAAI,CAAC;qBACjB;iBACF;gBAED,OAAO,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;YACxC,CAAC;SACF;QACD,WAAW,EAAE;YACX,yBAAyB,EAAE,IAAI;YAC/B,oBAAoB,EAAE,QAAQ;gBAC5B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mDAAmD,CAAC;gBACtE,CAAC,CAAC,0BAA0B;oBAC5B,CAAC,CAAC,4DAA4D;wBAC5D,oCAAoC;wBACpC,wEAAwE;wBACxE,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,sCAAsC,CAAC;oBACzE,CAAC,CAAC,6FAA6F;wBAC7F,OAAO,CAAC,OAAO,CAAC,4CAA4C,CAAC;YACjE,iBAAiB,EAAE,4CAA4C;YAC/D,YAAY,EAAE,eAAe,CAAC,WAAW,CAAC;SAC3C;KACF,CAAC,CAAC;AACL,CAAC;AAtMD,4CAsMC;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 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"]}
|
|
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,CAAC,CAAC;AAE1D,wFAAwF;AAC3E,QAAA,wBAAwB,GAAG,IAAI,MAAM,CAChD;IACE,8CAA8C;IAC9C,6CAA6C;IAC7C,+BAA+B;IAC/B,4BAA4B;IAC5B,iCAAiC;IACjC,2CAA2C;IAC3C,qCAAqC;IACrC,iCAAiC;IACjC,sDAAsD;IACtD,oDAAoD;IACpD,sCAAsC;IACtC,iCAAiC;IACjC,yCAAyC;IACzC,uCAAuC;IACvC,uCAAuC;IACvC,6DAA6D;IAC7D,qCAAqC;IACrC,8CAA8C;IAC9C,mDAAmD;IACnD,kDAAkD;IAClD,2CAA2C;IAC3C,oCAAoC;IACpC,kGAAkG;IAClG,iCAAiC;IACjC,iCAAiC;IACjC,2CAA2C;IAC3C,4CAA4C;IAC5C,4CAA4C;IAC5C,iDAAiD;IACjD,sCAAsC;IACtC,gCAAgC;IAChC,mBAAmB;CACpB,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;AAOF,SAAS,0BAA0B,CAAC,WAAmB;IACrD,MAAM,MAAM,GAAG,kBAAS,CAAC,WAAW,EAAE,EAA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AC;qBACjB;iBACF;gBAED,OAAO,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;YACxC,CAAC;SACF;QACD,WAAW,EAAE;YACX,yBAAyB,EAAE,IAAI;YAC/B,oBAAoB,EAAE,QAAQ;gBAC5B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,mDAAmD,CAAC;gBACtE,CAAC,CAAC,0BAA0B;oBAC5B,CAAC,CAAC,4DAA4D;wBAC5D,oCAAoC;wBACpC,wEAAwE;wBACxE,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,sCAAsC,CAAC;oBACzE,CAAC,CAAC,6FAA6F;wBAC7F,OAAO,CAAC,OAAO,CAAC,4CAA4C,CAAC;YACjE,iBAAiB,EAAE,4CAA4C;YAC/D,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,kBAAkB,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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,10 +35,8 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@expo/config": "6.0.6",
|
|
38
|
-
"@expo/json-file": "^8.2.33",
|
|
39
38
|
"chalk": "^4.1.0",
|
|
40
39
|
"debug": "^4.3.2",
|
|
41
|
-
"find-yarn-workspace-root": "~2.0.0",
|
|
42
40
|
"getenv": "^1.0.0",
|
|
43
41
|
"sucrase": "^3.20.0"
|
|
44
42
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
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[];
|
package/build/getWatchFolders.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAdD,kFAcC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,aAAa,GAAG,kCAAiB,CAAC,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,iDAAiD;IACjD,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,QAAQ,GAAG,mCAAmC,CAAC,aAAa,CAAC,CAAC;IACpE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,CAAC;KACX;IAED,OAAO,WAAW,CAAC;QACjB,cAAI,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;QACxC,GAAG,QAAQ,CAAC,GAAG,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"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|