@expo/metro-config 0.1.82 → 0.2.2
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 +34 -20
- package/build/ExpoMetroConfig.js.map +1 -1
- package/build/importMetroFromProject.d.ts +4 -0
- package/build/importMetroFromProject.js +38 -0
- package/build/importMetroFromProject.js.map +1 -0
- package/build/transformer/createExoticTransformer.d.ts +17 -0
- package/build/transformer/createExoticTransformer.js +183 -0
- package/build/transformer/createExoticTransformer.js.map +1 -0
- package/build/transformer/createMatcher.d.ts +14 -0
- package/build/transformer/createMatcher.js +45 -0
- package/build/transformer/createMatcher.js.map +1 -0
- package/build/transformer/generateFunctionMap.d.ts +2 -0
- package/build/transformer/generateFunctionMap.js +30 -0
- package/build/transformer/generateFunctionMap.js.map +1 -0
- package/build/transformer/getBabelConfig.d.ts +16 -0
- package/build/transformer/getBabelConfig.js +117 -0
- package/build/transformer/getBabelConfig.js.map +1 -0
- package/build/transformer/getCacheKey.d.ts +3 -0
- package/build/transformer/getCacheKey.js +23 -0
- package/build/transformer/getCacheKey.js.map +1 -0
- package/build/{metro-expo-babel-transformer.d.ts → transformer/metro-expo-babel-transformer.d.ts} +0 -0
- package/build/{metro-expo-babel-transformer.js → transformer/metro-expo-babel-transformer.js} +3 -16
- package/build/transformer/metro-expo-babel-transformer.js.map +1 -0
- package/build/transformer/metro-expo-exotic-babel-transformer.d.ts +1 -0
- package/build/transformer/metro-expo-exotic-babel-transformer.js +85 -0
- package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -0
- package/package.json +7 -3
- package/build/metro-expo-babel-transformer.js.map +0 -1
|
@@ -2,6 +2,7 @@ import { ProjectTarget } from '@expo/config';
|
|
|
2
2
|
import { Reporter } from 'metro';
|
|
3
3
|
import type MetroConfig from 'metro-config';
|
|
4
4
|
export declare const EXPO_DEBUG: boolean;
|
|
5
|
+
export declare const EXPO_USE_EXOTIC: boolean;
|
|
5
6
|
export declare const INTERNAL_CALLSITES_REGEX: RegExp;
|
|
6
7
|
export interface DefaultConfigOptions {
|
|
7
8
|
target?: ProjectTarget;
|
package/build/ExpoMetroConfig.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
5
|
};
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_DEBUG = void 0;
|
|
7
|
+
exports.loadAsync = exports.getDefaultConfig = exports.INTERNAL_CALLSITES_REGEX = exports.EXPO_USE_EXOTIC = exports.EXPO_DEBUG = void 0;
|
|
7
8
|
const config_1 = require("@expo/config");
|
|
8
9
|
const paths_1 = require("@expo/config/paths");
|
|
9
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
11
|
const getenv_1 = require("getenv");
|
|
11
12
|
const path_1 = __importDefault(require("path"));
|
|
12
13
|
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
14
|
+
const importMetroFromProject_1 = require("./importMetroFromProject");
|
|
13
15
|
exports.EXPO_DEBUG = getenv_1.boolish('EXPO_DEBUG', false);
|
|
16
|
+
exports.EXPO_USE_EXOTIC = getenv_1.boolish('EXPO_USE_EXOTIC', false);
|
|
14
17
|
// Import only the types here, the values will be imported from the project, at runtime.
|
|
15
18
|
exports.INTERNAL_CALLSITES_REGEX = new RegExp([
|
|
16
19
|
'/Libraries/Renderer/implementations/.+\\.js$',
|
|
@@ -33,6 +36,7 @@ exports.INTERNAL_CALLSITES_REGEX = new RegExp([
|
|
|
33
36
|
'node_modules/event-target-shim/dist/.+\\.js$',
|
|
34
37
|
// Ignore the log forwarder used in the Expo Go app
|
|
35
38
|
'/expo/build/environment/react-native-logs.fx.js$',
|
|
39
|
+
'/src/environment/react-native-logs.fx.ts$',
|
|
36
40
|
'/expo/build/logs/RemoteConsole.js$',
|
|
37
41
|
// Improve errors thrown by invariant (ex: `Invariant Violation: "main" has not been registered`).
|
|
38
42
|
'node_modules/invariant/.+\\.js$',
|
|
@@ -54,8 +58,13 @@ function getProjectBabelConfigFile(projectRoot) {
|
|
|
54
58
|
resolve_from_1.default.silent(projectRoot, './.babelrc') ||
|
|
55
59
|
resolve_from_1.default.silent(projectRoot, './.babelrc.js'));
|
|
56
60
|
}
|
|
61
|
+
let hasWarnedAboutExotic = false;
|
|
57
62
|
function getDefaultConfig(projectRoot, options = {}) {
|
|
58
|
-
|
|
63
|
+
if (exports.EXPO_USE_EXOTIC && !hasWarnedAboutExotic) {
|
|
64
|
+
hasWarnedAboutExotic = true;
|
|
65
|
+
console.log(chalk_1.default.gray(`\u203A Unstable feature ${chalk_1.default.bold `EXPO_USE_EXOTIC`} is enabled. Bundling may not work as expected, and is subject to breaking changes.`));
|
|
66
|
+
}
|
|
67
|
+
const MetroConfig = importMetroFromProject_1.importMetroConfigFromProject(projectRoot);
|
|
59
68
|
const reactNativePath = path_1.default.dirname(resolve_from_1.default(projectRoot, 'react-native/package.json'));
|
|
60
69
|
try {
|
|
61
70
|
// Set the `EXPO_METRO_CACHE_KEY_VERSION` variable for use in the custom babel transformer.
|
|
@@ -114,6 +123,10 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
114
123
|
const sourceExts = target === 'bare'
|
|
115
124
|
? paths_1.getBareExtensions([], sourceExtsConfig)
|
|
116
125
|
: paths_1.getManagedExtensions([], sourceExtsConfig);
|
|
126
|
+
if (exports.EXPO_USE_EXOTIC) {
|
|
127
|
+
// Add support for cjs (without platform extensions).
|
|
128
|
+
sourceExts.push('cjs');
|
|
129
|
+
}
|
|
117
130
|
const babelConfigPath = getProjectBabelConfigFile(projectRoot);
|
|
118
131
|
const isCustomBabelConfigDefined = !!babelConfigPath;
|
|
119
132
|
if (exports.EXPO_DEBUG) {
|
|
@@ -124,17 +137,25 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
124
137
|
console.log(`- Extensions: ${sourceExts.join(', ')}`);
|
|
125
138
|
console.log(`- React Native: ${reactNativePath}`);
|
|
126
139
|
console.log(`- Babel config: ${babelConfigPath || 'babel-preset-expo (default)'}`);
|
|
140
|
+
console.log(`- Exotic: ${exports.EXPO_USE_EXOTIC}`);
|
|
127
141
|
console.log();
|
|
128
142
|
}
|
|
129
143
|
const {
|
|
130
144
|
// Remove the default reporter which metro always resolves to be the react-native-community/cli reporter.
|
|
131
145
|
// This prints a giant React logo which is less accessible to users on smaller terminals.
|
|
132
146
|
reporter, ...metroDefaultValues } = MetroConfig.getDefaultConfig.getDefaultValues(projectRoot);
|
|
147
|
+
const resolverMainFields = [];
|
|
148
|
+
// Disable `react-native` in exotic mode, since library authors
|
|
149
|
+
// use it to ship raw application code to the project.
|
|
150
|
+
if (!exports.EXPO_USE_EXOTIC) {
|
|
151
|
+
resolverMainFields.push('react-native');
|
|
152
|
+
}
|
|
153
|
+
resolverMainFields.push('browser', 'main');
|
|
133
154
|
// Merge in the default config from Metro here, even though loadConfig uses it as defaults.
|
|
134
155
|
// This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts.
|
|
135
156
|
return MetroConfig.mergeConfig(metroDefaultValues, {
|
|
136
157
|
resolver: {
|
|
137
|
-
resolverMainFields
|
|
158
|
+
resolverMainFields,
|
|
138
159
|
platforms: ['ios', 'android', 'native'],
|
|
139
160
|
sourceExts,
|
|
140
161
|
},
|
|
@@ -167,12 +188,15 @@ function getDefaultConfig(projectRoot, options = {}) {
|
|
|
167
188
|
},
|
|
168
189
|
transformer: {
|
|
169
190
|
allowOptionalDependencies: true,
|
|
170
|
-
babelTransformerPath:
|
|
171
|
-
?
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
191
|
+
babelTransformerPath: exports.EXPO_USE_EXOTIC
|
|
192
|
+
? require.resolve('./transformer/metro-expo-exotic-babel-transformer')
|
|
193
|
+
: isCustomBabelConfigDefined
|
|
194
|
+
? // If the user defined a babel config file in their project,
|
|
195
|
+
// then use the default transformer.
|
|
196
|
+
// Try to use the project copy before falling back on the global version
|
|
197
|
+
resolve_from_1.default.silent(projectRoot, 'metro-react-native-babel-transformer')
|
|
198
|
+
: // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.
|
|
199
|
+
require.resolve('./transformer/metro-expo-babel-transformer'),
|
|
176
200
|
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
|
|
177
201
|
assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : undefined,
|
|
178
202
|
},
|
|
@@ -184,18 +208,8 @@ async function loadAsync(projectRoot, { reporter, target, ...metroOptions } = {}
|
|
|
184
208
|
if (reporter) {
|
|
185
209
|
defaultConfig = { ...defaultConfig, reporter };
|
|
186
210
|
}
|
|
187
|
-
const MetroConfig = importMetroConfigFromProject(projectRoot);
|
|
211
|
+
const MetroConfig = importMetroFromProject_1.importMetroConfigFromProject(projectRoot);
|
|
188
212
|
return await MetroConfig.loadConfig({ cwd: projectRoot, projectRoot, ...metroOptions }, defaultConfig);
|
|
189
213
|
}
|
|
190
214
|
exports.loadAsync = loadAsync;
|
|
191
|
-
function importMetroConfigFromProject(projectRoot) {
|
|
192
|
-
const resolvedPath = resolve_from_1.default.silent(projectRoot, 'metro-config');
|
|
193
|
-
if (!resolvedPath) {
|
|
194
|
-
throw new Error('Missing package "metro-config" in the project. ' +
|
|
195
|
-
'This usually means `react-native` is not installed. ' +
|
|
196
|
-
'Please verify that dependencies in package.json include "react-native" ' +
|
|
197
|
-
'and run `yarn` or `npm install`.');
|
|
198
|
-
}
|
|
199
|
-
return require(resolvedPath);
|
|
200
|
-
}
|
|
201
215
|
//# sourceMappingURL=ExpoMetroConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,iDAAiD;YAC/C,sDAAsD;YACtD,yEAAyE;YACzE,kCAAkC,CACrC,CAAC;KACH;IACD,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { 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\nexport const EXPO_DEBUG = boolish('EXPO_DEBUG', 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 '/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}\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\nexport function getDefaultConfig(\n projectRoot: string,\n options: DefaultConfigOptions = {}\n): MetroConfig.InputConfigT {\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 const babelConfigPath = getProjectBabelConfigFile(projectRoot);\n const isCustomBabelConfigDefined = !!babelConfigPath;\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();\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: ['react-native', 'browser', 'main'],\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: isCustomBabelConfigDefined\n ? // If the user defined a babel config file in their project,\n // then use the default transformer.\n require.resolve('metro-react-native-babel-transformer')\n : // Otherwise, use a custom transformer that uses `babel-preset-expo` by default for projects.\n require.resolve('./metro-expo-babel-transformer'),\n assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',\n assetPlugins: hashAssetFilesPath ? [hashAssetFilesPath] : undefined,\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\nfunction importMetroConfigFromProject(projectRoot: string): typeof MetroConfig {\n const resolvedPath = resolveFrom.silent(projectRoot, 'metro-config');\n if (!resolvedPath) {\n throw new Error(\n 'Missing package \"metro-config\" in the project. ' +\n 'This usually means `react-native` is not installed. ' +\n 'Please verify that dependencies in package.json include \"react-native\" ' +\n 'and run `yarn` or `npm install`.'\n );\n }\n return require(resolvedPath);\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;AAC1C,QAAA,eAAe,GAAG,gBAAO,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAEjE,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;AAMF,SAAS,0BAA0B,CAAC,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;SACF;QACD,WAAW,EAAE;YACX,yBAAyB,EAAE,IAAI;YAC/B,oBAAoB,EAAE,uBAAe;gBACnC,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,SAAS;SACpE;KACF,CAAC,CAAC;AACL,CAAC;AA/KD,4CA+KC;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);\nexport const 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}\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 if (EXPO_USE_EXOTIC && !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 (EXPO_USE_EXOTIC) {\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 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(`- Exotic: ${EXPO_USE_EXOTIC}`);\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 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 (!EXPO_USE_EXOTIC) {\n resolverMainFields.push('react-native');\n }\n resolverMainFields.push('browser', 'main');\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: EXPO_USE_EXOTIC\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] : undefined,\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,4 @@
|
|
|
1
|
+
import type MetroConfig from 'metro-config';
|
|
2
|
+
import type MetroSourceMap from 'metro-source-map';
|
|
3
|
+
export declare function importMetroConfigFromProject(projectRoot: string): typeof MetroConfig;
|
|
4
|
+
export declare function importMetroSourceMapFromProject(projectRoot: string): typeof MetroSourceMap;
|
|
@@ -0,0 +1,38 @@
|
|
|
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.importMetroSourceMapFromProject = exports.importMetroConfigFromProject = void 0;
|
|
7
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
8
|
+
class MetroImportError extends Error {
|
|
9
|
+
constructor(projectRoot, moduleId) {
|
|
10
|
+
super(`Missing package "${moduleId}" in the project at: ${projectRoot}\n` +
|
|
11
|
+
'This usually means `react-native` is not installed. ' +
|
|
12
|
+
'Please verify that dependencies in package.json include "react-native" ' +
|
|
13
|
+
'and run `yarn` or `npm install`.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function resolveFromProject(projectRoot, moduleId) {
|
|
17
|
+
const resolvedPath = resolve_from_1.default.silent(projectRoot, moduleId);
|
|
18
|
+
if (!resolvedPath) {
|
|
19
|
+
throw new MetroImportError(projectRoot, moduleId);
|
|
20
|
+
}
|
|
21
|
+
return resolvedPath;
|
|
22
|
+
}
|
|
23
|
+
function importFromProject(projectRoot, moduleId) {
|
|
24
|
+
return require(resolveFromProject(projectRoot, moduleId));
|
|
25
|
+
}
|
|
26
|
+
function importMetroConfigFromProject(projectRoot) {
|
|
27
|
+
return importFromProject(projectRoot, 'metro-config');
|
|
28
|
+
}
|
|
29
|
+
exports.importMetroConfigFromProject = importMetroConfigFromProject;
|
|
30
|
+
let metroSourceMap;
|
|
31
|
+
function importMetroSourceMapFromProject(projectRoot) {
|
|
32
|
+
if (metroSourceMap)
|
|
33
|
+
return metroSourceMap;
|
|
34
|
+
metroSourceMap = importFromProject(projectRoot, 'metro-source-map');
|
|
35
|
+
return metroSourceMap;
|
|
36
|
+
}
|
|
37
|
+
exports.importMetroSourceMapFromProject = importMetroSourceMapFromProject;
|
|
38
|
+
//# sourceMappingURL=importMetroFromProject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importMetroFromProject.js","sourceRoot":"","sources":["../src/importMetroFromProject.ts"],"names":[],"mappings":";;;;;;AAEA,gEAAuC;AAEvC,MAAM,gBAAiB,SAAQ,KAAK;IAClC,YAAY,WAAmB,EAAE,QAAgB;QAC/C,KAAK,CACH,oBAAoB,QAAQ,wBAAwB,WAAW,IAAI;YACjE,sDAAsD;YACtD,yEAAyE;YACzE,kCAAkC,CACrC,CAAC;IACJ,CAAC;CACF;AAED,SAAS,kBAAkB,CAAC,WAAmB,EAAE,QAAgB;IAC/D,MAAM,YAAY,GAAG,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/D,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KACnD;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAU,WAAmB,EAAE,QAAgB;IACvE,OAAO,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,4BAA4B,CAAC,WAAmB;IAC9D,OAAO,iBAAiB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AACxD,CAAC;AAFD,oEAEC;AAED,IAAI,cAAiD,CAAC;AAEtD,SAAgB,+BAA+B,CAAC,WAAmB;IACjE,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC;IAC1C,cAAc,GAAG,iBAAiB,CAAwB,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAC3F,OAAO,cAAc,CAAC;AACxB,CAAC;AAJD,0EAIC","sourcesContent":["import type MetroConfig from 'metro-config';\nimport type MetroSourceMap from 'metro-source-map';\nimport resolveFrom from 'resolve-from';\n\nclass MetroImportError extends Error {\n constructor(projectRoot: string, moduleId: string) {\n super(\n `Missing package \"${moduleId}\" in the project at: ${projectRoot}\\n` +\n 'This usually means `react-native` is not installed. ' +\n 'Please verify that dependencies in package.json include \"react-native\" ' +\n 'and run `yarn` or `npm install`.'\n );\n }\n}\n\nfunction resolveFromProject(projectRoot: string, moduleId: string) {\n const resolvedPath = resolveFrom.silent(projectRoot, moduleId);\n if (!resolvedPath) {\n throw new MetroImportError(projectRoot, moduleId);\n }\n return resolvedPath;\n}\n\nfunction importFromProject<T = any>(projectRoot: string, moduleId: string): T {\n return require(resolveFromProject(projectRoot, moduleId));\n}\n\nexport function importMetroConfigFromProject(projectRoot: string): typeof MetroConfig {\n return importFromProject(projectRoot, 'metro-config');\n}\n\nlet metroSourceMap: typeof MetroSourceMap | undefined;\n\nexport function importMetroSourceMapFromProject(projectRoot: string): typeof MetroSourceMap {\n if (metroSourceMap) return metroSourceMap;\n metroSourceMap = importFromProject<typeof MetroSourceMap>(projectRoot, 'metro-source-map');\n return metroSourceMap;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="metro-source-map" />
|
|
2
|
+
import type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';
|
|
3
|
+
/** Create a transformer that emulates Webpack's loader system. */
|
|
4
|
+
export declare function createExoticTransformer({ getRuleType, rules, }: {
|
|
5
|
+
getRuleType: (args: BabelTransformerArgs) => string;
|
|
6
|
+
rules: {
|
|
7
|
+
warn?: boolean;
|
|
8
|
+
type?: 'module' | 'app';
|
|
9
|
+
test: ((args: BabelTransformerArgs) => boolean) | RegExp;
|
|
10
|
+
transform: BabelTransformer['transform'];
|
|
11
|
+
}[];
|
|
12
|
+
}): (args: BabelTransformerArgs) => {
|
|
13
|
+
ast: any;
|
|
14
|
+
code: string | null;
|
|
15
|
+
functionMap?: import("metro-source-map").FBSourceFunctionMap | null | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare const loaders: Record<string, (args: BabelTransformerArgs) => any>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.loaders = exports.createExoticTransformer = void 0;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
11
|
+
const generateFunctionMap_1 = require("./generateFunctionMap");
|
|
12
|
+
const getBabelConfig_1 = require("./getBabelConfig");
|
|
13
|
+
const debug = debug_1.default('expo:metro:exotic-babel-transformer');
|
|
14
|
+
let babelCore;
|
|
15
|
+
function getBabelCoreFromProject(projectRoot) {
|
|
16
|
+
if (babelCore)
|
|
17
|
+
return babelCore;
|
|
18
|
+
babelCore = require(resolve_from_1.default(projectRoot, '@babel/core'));
|
|
19
|
+
return babelCore;
|
|
20
|
+
}
|
|
21
|
+
let babelParser;
|
|
22
|
+
function getBabelParserFromProject(projectRoot) {
|
|
23
|
+
if (babelParser)
|
|
24
|
+
return babelParser;
|
|
25
|
+
babelParser = require(resolve_from_1.default(projectRoot, '@babel/parser'));
|
|
26
|
+
return babelParser;
|
|
27
|
+
}
|
|
28
|
+
function sucrase(args, { transforms, }) {
|
|
29
|
+
const { src, filename, options: { dev }, } = args;
|
|
30
|
+
const { transform } = require('sucrase');
|
|
31
|
+
const results = transform(src, {
|
|
32
|
+
filePath: filename,
|
|
33
|
+
production: !dev,
|
|
34
|
+
transforms,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
code: results.code,
|
|
38
|
+
functionMap: null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const getExpensiveSucraseTransforms = (filename) => [
|
|
42
|
+
'jsx',
|
|
43
|
+
'imports',
|
|
44
|
+
/\.tsx?$/.test(filename) ? 'typescript' : 'flow',
|
|
45
|
+
];
|
|
46
|
+
function parseAst(projectRoot, sourceCode) {
|
|
47
|
+
const babylon = getBabelParserFromProject(projectRoot);
|
|
48
|
+
return babylon.parse(sourceCode, {
|
|
49
|
+
sourceType: 'unambiguous',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Create a transformer that emulates Webpack's loader system. */
|
|
53
|
+
function createExoticTransformer({ getRuleType, rules, }) {
|
|
54
|
+
// const warnings: string[] = [];
|
|
55
|
+
return function transform(args) {
|
|
56
|
+
const { filename, options } = args;
|
|
57
|
+
const OLD_BABEL_ENV = process.env.BABEL_ENV;
|
|
58
|
+
process.env.BABEL_ENV = options.dev ? 'development' : process.env.BABEL_ENV || 'production';
|
|
59
|
+
try {
|
|
60
|
+
const ruleType = getRuleType(args);
|
|
61
|
+
for (const rule of rules) {
|
|
62
|
+
// optimization for checking node modules
|
|
63
|
+
if (rule.type && rule.type !== ruleType) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const isMatched = typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);
|
|
67
|
+
if (isMatched) {
|
|
68
|
+
const results = rule.transform(args);
|
|
69
|
+
// Perform a basic parse if none exists, this enables us to control the output, but only if it changed.
|
|
70
|
+
if (results.code && !results.ast) {
|
|
71
|
+
// Parse AST with babel otherwise Metro transformer will throw away the returned results.
|
|
72
|
+
results.ast = parseAst(options.projectRoot, results.code);
|
|
73
|
+
}
|
|
74
|
+
// TODO: Suboptimal warnings
|
|
75
|
+
// if (rule.warn) {
|
|
76
|
+
// const matchName =
|
|
77
|
+
// filename.match(/node_modules\/((:?@[\w\d-]+\/[\w\d-]+)|(:?[\w\d-]+))\/?/)?.[1] ??
|
|
78
|
+
// filename;
|
|
79
|
+
// if (matchName && !warnings.includes(matchName)) {
|
|
80
|
+
// warnings.push(matchName);
|
|
81
|
+
// console.warn(chalk.yellow.bold`warn `, matchName);
|
|
82
|
+
// console.warn(
|
|
83
|
+
// chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`
|
|
84
|
+
// );
|
|
85
|
+
// }
|
|
86
|
+
// }
|
|
87
|
+
return results;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw new Error('no loader rule to handle file: ' + filename);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
if (OLD_BABEL_ENV) {
|
|
94
|
+
process.env.BABEL_ENV = OLD_BABEL_ENV;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.createExoticTransformer = createExoticTransformer;
|
|
100
|
+
exports.loaders = {
|
|
101
|
+
// Perform the standard, and most expensive transpilation sequence.
|
|
102
|
+
app(args) {
|
|
103
|
+
debug('app:', args.filename);
|
|
104
|
+
const { filename, options, src, plugins } = args;
|
|
105
|
+
const babelConfig = {
|
|
106
|
+
// ES modules require sourceType='module' but OSS may not always want that
|
|
107
|
+
sourceType: 'unambiguous',
|
|
108
|
+
...getBabelConfig_1.getBabelConfig(filename, options, plugins),
|
|
109
|
+
// Variables that are exposed to the user's babel preset.
|
|
110
|
+
caller: {
|
|
111
|
+
name: 'metro',
|
|
112
|
+
platform: options.platform,
|
|
113
|
+
},
|
|
114
|
+
ast: true,
|
|
115
|
+
};
|
|
116
|
+
// Surface a warning function so babel linters can be used.
|
|
117
|
+
Object.defineProperty(babelConfig.caller, 'onWarning', {
|
|
118
|
+
enumerable: false,
|
|
119
|
+
writable: false,
|
|
120
|
+
value: (babelConfig.caller.onWarning = function (msg) {
|
|
121
|
+
// Format the file path first so users know where the warning came from.
|
|
122
|
+
console.warn(chalk_1.default.bold.yellow `warn ` + args.filename);
|
|
123
|
+
console.warn(msg);
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);
|
|
127
|
+
const sourceAst = parseSync(src, babelConfig);
|
|
128
|
+
// Should never happen.
|
|
129
|
+
if (!sourceAst)
|
|
130
|
+
return { ast: null };
|
|
131
|
+
const result = transformFromAstSync(sourceAst, src, babelConfig);
|
|
132
|
+
// TODO: Disable by default
|
|
133
|
+
const functionMap = generateFunctionMap_1.generateFunctionMap(options.projectRoot, sourceAst, { filename });
|
|
134
|
+
// The result from `transformFromAstSync` can be null (if the file is ignored)
|
|
135
|
+
if (!result) {
|
|
136
|
+
return { ast: null, functionMap };
|
|
137
|
+
}
|
|
138
|
+
return { ast: result.ast, functionMap };
|
|
139
|
+
},
|
|
140
|
+
// Transpile react-native with sucrase.
|
|
141
|
+
reactNativeModule(args) {
|
|
142
|
+
debug('rn:', args.filename);
|
|
143
|
+
return sucrase(args, {
|
|
144
|
+
transforms: ['jsx', 'flow', 'imports'],
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
// Transpile expo modules with sucrase.
|
|
148
|
+
expoModule(args) {
|
|
149
|
+
debug('expo:', args.filename);
|
|
150
|
+
// TODO: Fix all expo packages
|
|
151
|
+
return sucrase(args, {
|
|
152
|
+
transforms: [
|
|
153
|
+
'imports',
|
|
154
|
+
// TODO: fix expo-processing, expo/vector-icons
|
|
155
|
+
/(expo-processing|expo\/vector-icons)/.test(args.filename) && 'jsx',
|
|
156
|
+
// TODO: fix expo-asset-utils
|
|
157
|
+
/(expo-asset-utils)/.test(args.filename) && 'flow',
|
|
158
|
+
].filter(Boolean),
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
// Transpile known community modules with the most expensive sucrase
|
|
162
|
+
untranspiledModule(args) {
|
|
163
|
+
debug('known issues:', args.filename);
|
|
164
|
+
return sucrase(args, {
|
|
165
|
+
transforms: getExpensiveSucraseTransforms(args.filename),
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
// Pass all modules through without transpiling them.
|
|
169
|
+
passthroughModule(args) {
|
|
170
|
+
const { filename, options, src } = args;
|
|
171
|
+
debug('passthrough:', filename);
|
|
172
|
+
// Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
|
|
173
|
+
const ast = parseAst(options.projectRoot, src);
|
|
174
|
+
// TODO: Disable by default
|
|
175
|
+
const functionMap = generateFunctionMap_1.generateFunctionMap(options.projectRoot, ast, { filename });
|
|
176
|
+
return {
|
|
177
|
+
code: src,
|
|
178
|
+
functionMap,
|
|
179
|
+
ast,
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=createExoticTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExoticTransformer.js","sourceRoot":"","sources":["../../src/transformer/createExoticTransformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;;AAErE,kDAA0B;AAC1B,kDAA0B;AAE1B,gEAAuC;AAEvC,+DAA4D;AAC5D,qDAAkD;AAElD,MAAM,KAAK,GAAG,eAAK,CAAC,qCAAqC,CAAC,CAAC;AAE3D,IAAI,SAAmD,CAAC;AAExD,SAAS,uBAAuB,CAAC,WAAmB;IAClD,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,SAAS,GAAG,OAAO,CAAC,sBAAW,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC,CA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QACtC,OAAO,OAAO,CAAC,IAAI,EAAE;YACnB,UAAU,EAAE,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC;SACzD,CAAC,CAAC;IACL,CAAC;IAED,qDAAqD;IACrD,iBAAiB,CAAC,IAAI;QACpB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACxC,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAEhC,iGAAiG;QACjG,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAE/C,2BAA2B;QAC3B,MAAM,WAAW,GAAG,yCAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhF,OAAO;YACL,IAAI,EAAE,GAAG;YACT,WAAW;YACX,GAAG;SACJ,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createExoticTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: {\n warn?: boolean;\n type?: 'module' | 'app';\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n }[];\n}) {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function createModuleMatcher({ folders, moduleIds, }: {
|
|
2
|
+
folders?: string[];
|
|
3
|
+
moduleIds: string[];
|
|
4
|
+
}): RegExp;
|
|
5
|
+
export declare const createReactNativeMatcher: ({ folders }: {
|
|
6
|
+
folders?: string[] | undefined;
|
|
7
|
+
}) => RegExp;
|
|
8
|
+
export declare const createExpoMatcher: ({ folders }: {
|
|
9
|
+
folders?: string[] | undefined;
|
|
10
|
+
}) => RegExp;
|
|
11
|
+
export declare const createKnownCommunityMatcher: ({ folders, moduleIds, }?: {
|
|
12
|
+
folders?: string[] | undefined;
|
|
13
|
+
moduleIds?: string[] | undefined;
|
|
14
|
+
}) => RegExp;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createKnownCommunityMatcher = exports.createExpoMatcher = exports.createReactNativeMatcher = exports.createModuleMatcher = void 0;
|
|
5
|
+
function createModuleMatcher({ folders = ['node_modules'], moduleIds, }) {
|
|
6
|
+
const modulePathsGroup = folders.join('|');
|
|
7
|
+
const moduleMatchersGroup = moduleIds.join('|');
|
|
8
|
+
const moduleMatcherId = '^' + [modulePathsGroup, moduleMatchersGroup].map(value => `(?:${value})`).join('/');
|
|
9
|
+
return new RegExp(moduleMatcherId);
|
|
10
|
+
}
|
|
11
|
+
exports.createModuleMatcher = createModuleMatcher;
|
|
12
|
+
const createReactNativeMatcher = ({ folders }) => createModuleMatcher({
|
|
13
|
+
folders,
|
|
14
|
+
moduleIds: ['react-native/'],
|
|
15
|
+
});
|
|
16
|
+
exports.createReactNativeMatcher = createReactNativeMatcher;
|
|
17
|
+
const createExpoMatcher = ({ folders }) => createModuleMatcher({
|
|
18
|
+
folders,
|
|
19
|
+
// We'll work to start reducing this.
|
|
20
|
+
moduleIds: ['expo', '@expo', '@unimodules', '@use-expo'],
|
|
21
|
+
});
|
|
22
|
+
exports.createExpoMatcher = createExpoMatcher;
|
|
23
|
+
// TODO: Make this list as short as possible before releasing.
|
|
24
|
+
const createKnownCommunityMatcher = ({ folders, moduleIds = [], } = {}) => createModuleMatcher({
|
|
25
|
+
folders,
|
|
26
|
+
moduleIds: [
|
|
27
|
+
...moduleIds,
|
|
28
|
+
// The more complex, the longer the entire project takes...
|
|
29
|
+
// react-native-community, react-native-masked-view, react-native-picker, react-native-segmented-control, react-native
|
|
30
|
+
'@react-',
|
|
31
|
+
'react-native-',
|
|
32
|
+
'victory-',
|
|
33
|
+
'native-base',
|
|
34
|
+
'styled-components',
|
|
35
|
+
// three.js
|
|
36
|
+
'three/build/three.module.js',
|
|
37
|
+
'three/examples/jsm',
|
|
38
|
+
// Special case for testing expo/expo repo
|
|
39
|
+
'html-elements/',
|
|
40
|
+
// shared-element
|
|
41
|
+
'react-navigation-',
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
exports.createKnownCommunityMatcher = createKnownCommunityMatcher;
|
|
45
|
+
//# sourceMappingURL=createMatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMatcher.js","sourceRoot":"","sources":["../../src/transformer/createMatcher.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;AAErE,SAAgB,mBAAmB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AAC,CAAC;AA1BQ,QAAA,2BAA2B,+BA0BnC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nexport function createModuleMatcher({\n folders = ['node_modules'],\n moduleIds,\n}: {\n folders?: string[];\n moduleIds: string[];\n}) {\n const modulePathsGroup = folders.join('|');\n\n const moduleMatchersGroup = moduleIds.join('|');\n\n const moduleMatcherId =\n '^' + [modulePathsGroup, moduleMatchersGroup].map(value => `(?:${value})`).join('/');\n\n return new RegExp(moduleMatcherId);\n}\n\nexport const createReactNativeMatcher = ({ folders }: { folders?: string[] }) =>\n createModuleMatcher({\n folders,\n moduleIds: ['react-native/'],\n });\n\nexport const createExpoMatcher = ({ folders }: { folders?: string[] }) =>\n createModuleMatcher({\n folders,\n // We'll work to start reducing this.\n moduleIds: ['expo', '@expo', '@unimodules', '@use-expo'],\n });\n\n// TODO: Make this list as short as possible before releasing.\nexport const createKnownCommunityMatcher = ({\n folders,\n moduleIds = [],\n}: {\n folders?: string[];\n moduleIds?: string[];\n} = {}) =>\n createModuleMatcher({\n folders,\n moduleIds: [\n ...moduleIds,\n // The more complex, the longer the entire project takes...\n // react-native-community, react-native-masked-view, react-native-picker, react-native-segmented-control, react-native\n '@react-',\n 'react-native-',\n 'victory-',\n 'native-base',\n 'styled-components',\n // three.js\n 'three/build/three.module.js',\n 'three/examples/jsm',\n // Special case for testing expo/expo repo\n 'html-elements/',\n // shared-element\n 'react-navigation-',\n ],\n });\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';
|
|
2
|
+
export declare function generateFunctionMap(projectRoot: string, ast: Parameters<typeof generateFunctionMapType>[0], context: Parameters<typeof generateFunctionMapType>[1]): ReturnType<typeof generateFunctionMapType> | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateFunctionMap = void 0;
|
|
4
|
+
const importMetroFromProject_1 = require("../importMetroFromProject");
|
|
5
|
+
function generateFunctionMap(projectRoot, ast, context) {
|
|
6
|
+
// `x_facebook_sources` is a source map feature that we disable by default since it isn't documented
|
|
7
|
+
// and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.
|
|
8
|
+
// The feature supposedly provides improved function names for anonymous functions, but we will opt towards
|
|
9
|
+
// linting to prevent users from adding anonymous functions for important features like React components.
|
|
10
|
+
//
|
|
11
|
+
// Here is an example stack trace for a component that throws an error
|
|
12
|
+
// in the root component (which is an anonymous function):
|
|
13
|
+
//
|
|
14
|
+
// Before:
|
|
15
|
+
// - <anonymous> App.js:5:9
|
|
16
|
+
// - renderApplication renderApplication.js:54:5
|
|
17
|
+
// - runnables.appKey.run AppRegistry.js:117:26
|
|
18
|
+
//
|
|
19
|
+
// After:
|
|
20
|
+
// - _default App.js:5:9
|
|
21
|
+
// - renderApplication renderApplication.js:54:5
|
|
22
|
+
// - run AppRegistry.js:117:26
|
|
23
|
+
//
|
|
24
|
+
if (process.env.EXPO_USE_FB_SOURCES) {
|
|
25
|
+
return importMetroFromProject_1.importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
exports.generateFunctionMap = generateFunctionMap;
|
|
30
|
+
//# sourceMappingURL=generateFunctionMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateFunctionMap.js","sourceRoot":"","sources":["../../src/transformer/generateFunctionMap.ts"],"names":[],"mappings":";;;AAEA,sEAA4E;AAE5E,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,GAAkD,EAClD,OAAsD;IAEtD,qGAAqG;IACrG,sGAAsG;IACtG,2GAA2G;IAC3G,yGAAyG;IACzG,EAAE;IACF,sEAAsE;IACtE,0DAA0D;IAC1D,EAAE;IACF,UAAU;IACV,2BAA2B;IAC3B,gDAAgD;IAChD,+CAA+C;IAC/C,EAAE;IACF,SAAS;IACT,wBAAwB;IACxB,gDAAgD;IAChD,8BAA8B;IAC9B,EAAE;IACF,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;QACnC,OAAO,wDAA+B,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;KACvF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AA3BD,kDA2BC","sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Expo.
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* Forks the default metro-react-native-babel-transformer and adds support for known transforms.
|
|
9
|
+
*/
|
|
10
|
+
import type { PluginItem as BabelPlugins } from '@babel/core';
|
|
11
|
+
import type { BabelTransformerOptions } from 'metro-babel-transformer';
|
|
12
|
+
/**
|
|
13
|
+
* Given a filename and options, build a Babel
|
|
14
|
+
* config object with the appropriate plugins.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getBabelConfig(filename: string, options: BabelTransformerOptions, plugins?: BabelPlugins): any;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Expo.
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* Forks the default metro-react-native-babel-transformer and adds support for known transforms.
|
|
10
|
+
*/
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getBabelConfig = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
19
|
+
/**
|
|
20
|
+
* Return a memoized function that checks for the existence of a
|
|
21
|
+
* project level .babelrc file, and if it doesn't exist, reads the
|
|
22
|
+
* default RN babelrc file and uses that.
|
|
23
|
+
*/
|
|
24
|
+
const getBabelRC = (function () {
|
|
25
|
+
let babelRC = null;
|
|
26
|
+
return function _getBabelRC(projectRoot, options) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (babelRC != null) {
|
|
29
|
+
return babelRC;
|
|
30
|
+
}
|
|
31
|
+
babelRC = { plugins: [] };
|
|
32
|
+
// Let's look for a babel config file in the project root.
|
|
33
|
+
// TODO look into adding a command line option to specify this location
|
|
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
|
+
// .babelrc
|
|
38
|
+
// if (projectRoot) {
|
|
39
|
+
// projectBabelRCPath = path.resolve(projectRoot, '.babelrc');
|
|
40
|
+
// }
|
|
41
|
+
if (projectBabelRCPath) {
|
|
42
|
+
// .babelrc.js
|
|
43
|
+
// if (!fs.existsSync(projectBabelRCPath)) {
|
|
44
|
+
// projectBabelRCPath = path.resolve(projectRoot, '.babelrc.js');
|
|
45
|
+
// }
|
|
46
|
+
// babel.config.js
|
|
47
|
+
if (!fs_1.default.existsSync(projectBabelRCPath)) {
|
|
48
|
+
projectBabelRCPath = path_1.default.resolve(projectRoot, 'babel.config.js');
|
|
49
|
+
}
|
|
50
|
+
// If we found a babel config file, extend our config off of it
|
|
51
|
+
// otherwise the default config will be used
|
|
52
|
+
if (fs_1.default.existsSync(projectBabelRCPath)) {
|
|
53
|
+
babelRC.extends = projectBabelRCPath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// If a babel config file doesn't exist in the project then
|
|
57
|
+
// the default preset for react-native will be used instead.
|
|
58
|
+
if (!babelRC.extends) {
|
|
59
|
+
const { experimentalImportSupport, ...presetOptions } = options;
|
|
60
|
+
// Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.
|
|
61
|
+
const presetPath = (_b = (_a = resolve_from_1.default.silent(projectRoot, 'babel-preset-expo')) !== null && _a !== void 0 ? _a : resolve_from_1.default.silent(projectRoot, 'metro-react-native-babel-preset')) !== null && _b !== void 0 ? _b : require.resolve('babel-preset-expo');
|
|
62
|
+
babelRC.presets = [
|
|
63
|
+
[
|
|
64
|
+
require(presetPath),
|
|
65
|
+
{
|
|
66
|
+
...presetOptions,
|
|
67
|
+
disableImportExportTransform: experimentalImportSupport,
|
|
68
|
+
enableBabelRuntime: options.enableBabelRuntime,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
return babelRC;
|
|
74
|
+
};
|
|
75
|
+
})();
|
|
76
|
+
/**
|
|
77
|
+
* Given a filename and options, build a Babel
|
|
78
|
+
* config object with the appropriate plugins.
|
|
79
|
+
*/
|
|
80
|
+
function getBabelConfig(filename, options, plugins = []) {
|
|
81
|
+
const babelRC = getBabelRC(options.projectRoot, options);
|
|
82
|
+
const extraConfig = {
|
|
83
|
+
babelrc: typeof options.enableBabelRCLookup === 'boolean' ? options.enableBabelRCLookup : true,
|
|
84
|
+
code: false,
|
|
85
|
+
filename,
|
|
86
|
+
highlightCode: true,
|
|
87
|
+
};
|
|
88
|
+
const config = { ...babelRC, ...extraConfig };
|
|
89
|
+
// Add extra plugins
|
|
90
|
+
const extraPlugins = [];
|
|
91
|
+
// TODO: This probably can be removed
|
|
92
|
+
if (options.inlineRequires) {
|
|
93
|
+
const inlineRequiresPlugin = resolve_from_1.default(options.projectRoot, 'babel-preset-fbjs/plugins/inline-requires');
|
|
94
|
+
extraPlugins.push(inlineRequiresPlugin);
|
|
95
|
+
}
|
|
96
|
+
config.plugins = extraPlugins.concat(config.plugins, plugins);
|
|
97
|
+
if (options.dev && options.hot) {
|
|
98
|
+
// Note: this intentionally doesn't include the path separator because
|
|
99
|
+
// I'm not sure which one it should use on Windows, and false positives
|
|
100
|
+
// are unlikely anyway. If you later decide to include the separator,
|
|
101
|
+
// don't forget that the string usually *starts* with "node_modules" so
|
|
102
|
+
// the first one often won't be there.
|
|
103
|
+
// TODO: Support monorepos
|
|
104
|
+
const mayContainEditableReactComponents = filename.indexOf('node_modules') === -1;
|
|
105
|
+
if (mayContainEditableReactComponents) {
|
|
106
|
+
if (!config.plugins) {
|
|
107
|
+
config.plugins = [];
|
|
108
|
+
}
|
|
109
|
+
// Add react refresh runtime.
|
|
110
|
+
// NOTICE: keep in sync with 'metro-react-native-babel-preset/src/configs/hmr'.
|
|
111
|
+
config.plugins.push(resolve_from_1.default.silent(options.projectRoot, 'react-refresh/babel'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { ...babelRC, ...config };
|
|
115
|
+
}
|
|
116
|
+
exports.getBabelConfig = getBabelConfig;
|
|
117
|
+
//# sourceMappingURL=getBabelConfig.js.map
|
|
@@ -0,0 +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,sDAAsD;QACtD,2EAA2E;QAE3E,WAAW;QACX,qBAAqB;QACrB,gEAAgE;QAChE,IAAI;QAEJ,IAAI,kBAAkB,EAAE;YACtB,cAAc;YACd,4CAA4C;YAC5C,mEAAmE;YACnE,IAAI;YAEJ,kBAAkB;YAClB,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;gBACtC,kBAAkB,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;aACnE;YAED,+DAA+D;YAC/D,4CAA4C;YAC5C,IAAI,YAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;gBACrC,OAAO,CAAC,OAAO,GAAG,kBAAkB,CAAC;aACtC;SACF;QAED,2DAA2D;QAC3D,4DAA4D;QAC5D,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACpB,MAAM,EAAE,yBAAyB,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO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AC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9D,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QAC9B,sEAAsE;QACtE,uEAAuE;QACvE,qEAAqE;QACrE,uEAAuE;QACvE,sCAAsC;QACtC,0BAA0B;QAC1B,MAAM,iCAAiC,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QAElF,IAAI,iCAAiC,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;gBACnB,MAAM,CAAC,OAAO,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 // Since this is an opt-in system, we can make certain\n // assumptions like dropping support for `.babelrc` to speed up resolution.\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 ...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"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.getCacheKey = exports.cacheKeyParts = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
exports.cacheKeyParts = [
|
|
10
|
+
fs_1.readFileSync(__filename),
|
|
11
|
+
// Since babel-preset-fbjs cannot be safely resolved relative to the
|
|
12
|
+
// project root, use this environment variable that we define earlier.
|
|
13
|
+
process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',
|
|
14
|
+
// require('babel-preset-fbjs/package.json').version,
|
|
15
|
+
];
|
|
16
|
+
// Matches upstream
|
|
17
|
+
function getCacheKey() {
|
|
18
|
+
const key = crypto_1.default.createHash('md5');
|
|
19
|
+
exports.cacheKeyParts.forEach(part => key.update(part));
|
|
20
|
+
return key.digest('hex');
|
|
21
|
+
}
|
|
22
|
+
exports.getCacheKey = getCacheKey;
|
|
23
|
+
//# sourceMappingURL=getCacheKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCacheKey.js","sourceRoot":"","sources":["../../src/transformer/getCacheKey.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,2BAAkC;AAErB,QAAA,aAAa,GAAG;IAC3B,iBAAY,CAAC,UAAU,CAAC;IACxB,oEAAoE;IACpE,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,OAAO;IACnD,uDAAuD;CACxD,CAAC;AAEF,mBAAmB;AACnB,SAAgB,WAAW;IACzB,MAAM,GAAG,GAAG,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,qBAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAJD,kCAIC","sourcesContent":["import crypto from 'crypto';\nimport { readFileSync } from 'fs';\n\nexport const cacheKeyParts = [\n readFileSync(__filename),\n // Since babel-preset-fbjs cannot be safely resolved relative to the\n // project root, use this environment variable that we define earlier.\n process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',\n // require('babel-preset-fbjs/package.json').version,\n];\n\n// Matches upstream\nexport function getCacheKey(): string {\n const key = crypto.createHash('md5');\n cacheKeyParts.forEach(part => key.update(part));\n return key.digest('hex');\n}\n"]}
|
package/build/{metro-expo-babel-transformer.d.ts → transformer/metro-expo-babel-transformer.d.ts}
RENAMED
|
File without changes
|
package/build/{metro-expo-babel-transformer.js → transformer/metro-expo-babel-transformer.js}
RENAMED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
2
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
5
|
};
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
9
|
-
const
|
|
10
|
-
fs_1.readFileSync(__filename),
|
|
11
|
-
// Since babel-preset-fbjs cannot be safely resolved relative to the
|
|
12
|
-
// project root, use this environment variable that we define earlier.
|
|
13
|
-
process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',
|
|
14
|
-
// require('babel-preset-fbjs/package.json').version,
|
|
15
|
-
];
|
|
8
|
+
const getCacheKey_1 = require("./getCacheKey");
|
|
16
9
|
let transformer = null;
|
|
17
10
|
function resolveTransformer(projectRoot) {
|
|
18
11
|
if (transformer) {
|
|
@@ -46,14 +39,8 @@ function transform(props) {
|
|
|
46
39
|
props.options.extendsBabelConfigPath = resolve_from_1.default.silent(props.options.projectRoot, 'babel-preset-expo');
|
|
47
40
|
return resolveTransformer(props.options.projectRoot).transform(props);
|
|
48
41
|
}
|
|
49
|
-
// Matches upstream
|
|
50
|
-
function getCacheKey() {
|
|
51
|
-
const key = crypto_1.default.createHash('md5');
|
|
52
|
-
cacheKeyParts.forEach(part => key.update(part));
|
|
53
|
-
return key.digest('hex');
|
|
54
|
-
}
|
|
55
42
|
module.exports = {
|
|
56
|
-
getCacheKey,
|
|
43
|
+
getCacheKey: getCacheKey_1.getCacheKey,
|
|
57
44
|
transform,
|
|
58
45
|
};
|
|
59
46
|
//# sourceMappingURL=metro-expo-babel-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metro-expo-babel-transformer.js","sourceRoot":"","sources":["../../src/transformer/metro-expo-babel-transformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;;;;AAErE,gEAAuC;AAEvC,+CAA4C;AAE5C,IAAI,WAAW,GAAQ,IAAI,CAAC;AAE5B,SAAS,kBAAkB,CAAC,WAAmB;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,YAAY,GAAG,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,sCAAsC,CAAC,CAAC;IAC7F,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,yEAAyE;YACvE,sDAAsD;YACtD,yEAAyE;YACzE,kCAAkC,CACrC,CAAC;KACH;IACD,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACpC,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,SAAS,CAAC,KAKlB;IACC,mDAAmD;IACnD,KAAK,CAAC,OAAO,CAAC,sBAAsB,GAAG,sBAAW,CAAC,MAAM,CACvD,KAAK,CAAC,OAAO,CAAC,WAAW,EACzB,mBAAmB,CACpB,CAAC;IACF,OAAO,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,WAAW,EAAX,yBAAW;IACX,SAAS;CACV,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport resolveFrom from 'resolve-from';\n\nimport { getCacheKey } from './getCacheKey';\n\nlet transformer: any = null;\n\nfunction resolveTransformer(projectRoot: string) {\n if (transformer) {\n return transformer;\n }\n const resolvedPath = resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer');\n if (!resolvedPath) {\n throw new Error(\n 'Missing package \"metro-react-native-babel-transformer\" in the project. ' +\n 'This usually means `react-native` is not installed. ' +\n 'Please verify that dependencies in package.json include \"react-native\" ' +\n 'and run `yarn` or `npm install`.'\n );\n }\n transformer = require(resolvedPath);\n return transformer;\n}\n\n/**\n * Extends the default `metro-react-native-babel-transformer`\n * and uses babel-preset-expo as the default instead of metro-react-native-babel-preset.\n * This enables users to safely transpile an Expo project without\n * needing to explicitly define a `babel.config.js`\n *\n * @param filename string\n * @param options BabelTransformerOptions\n * @param plugins $PropertyType<BabelCoreOptions, 'plugins'>\n * @param src string\n *\n * @returns\n */\nfunction transform(props: {\n filename: string;\n options: Record<string, any> & { projectRoot: string };\n plugins?: unknown;\n src: string;\n}) {\n // Use babel-preset-expo by default if available...\n props.options.extendsBabelConfigPath = resolveFrom.silent(\n props.options.projectRoot,\n 'babel-preset-expo'\n );\n return resolveTransformer(props.options.projectRoot).transform(props);\n}\n\nmodule.exports = {\n getCacheKey,\n transform,\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-present 650 Industries (Expo). All rights reserved.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const createExoticTransformer_1 = require("./createExoticTransformer");
|
|
5
|
+
const createMatcher_1 = require("./createMatcher");
|
|
6
|
+
const getCacheKey_1 = require("./getCacheKey");
|
|
7
|
+
const nodeModulesPaths = ['node_modules'];
|
|
8
|
+
// Match any node modules, or monorepo module.
|
|
9
|
+
const nodeModuleMatcher = createMatcher_1.createModuleMatcher({ folders: nodeModulesPaths, moduleIds: [] });
|
|
10
|
+
// Match node modules which are so oddly written that we must
|
|
11
|
+
// transpile them with every possible option (most expensive).
|
|
12
|
+
const impossibleNodeModuleMatcher = createMatcher_1.createModuleMatcher({
|
|
13
|
+
moduleIds: [
|
|
14
|
+
// victory is too wild
|
|
15
|
+
// SyntaxError in ../../node_modules/victory-native/lib/components/victory-primitives/bar.js: Missing semicolon. (9:1)
|
|
16
|
+
'victory',
|
|
17
|
+
// vector icons has some hidden issues that break NCL
|
|
18
|
+
'@expo/vector-icons',
|
|
19
|
+
],
|
|
20
|
+
folders: nodeModulesPaths,
|
|
21
|
+
});
|
|
22
|
+
const transform = createExoticTransformer_1.createExoticTransformer({
|
|
23
|
+
// Specify which rules to use on a per-file basis, basically
|
|
24
|
+
// this is used to determine which modules are node modules, and which are application code.
|
|
25
|
+
getRuleType({ filename }) {
|
|
26
|
+
// Is a node module, and is not one of the impossible modules.
|
|
27
|
+
return nodeModuleMatcher.test(filename) && !impossibleNodeModuleMatcher.test(filename)
|
|
28
|
+
? 'module'
|
|
29
|
+
: 'app';
|
|
30
|
+
},
|
|
31
|
+
// Order is very important, we use wild card matchers to transpile
|
|
32
|
+
// "every unhandled node module" and "every unhandled application module".
|
|
33
|
+
rules: [
|
|
34
|
+
// Match bob compiler modules, use the passthrough loader.
|
|
35
|
+
{
|
|
36
|
+
type: 'module',
|
|
37
|
+
test: createMatcher_1.createModuleMatcher({ moduleIds: ['.*/lib/commonjs/'], folders: nodeModulesPaths }),
|
|
38
|
+
transform: createExoticTransformer_1.loaders.passthroughModule,
|
|
39
|
+
warn: true,
|
|
40
|
+
},
|
|
41
|
+
// Match React Native modules, convert them statically using sucrase.
|
|
42
|
+
{
|
|
43
|
+
type: 'module',
|
|
44
|
+
test: createMatcher_1.createReactNativeMatcher({ folders: nodeModulesPaths }),
|
|
45
|
+
transform: createExoticTransformer_1.loaders.reactNativeModule,
|
|
46
|
+
warn: true,
|
|
47
|
+
},
|
|
48
|
+
// Match Expo SDK modules, convert them statically using sucrase.
|
|
49
|
+
{
|
|
50
|
+
type: 'module',
|
|
51
|
+
test: createMatcher_1.createExpoMatcher({ folders: nodeModulesPaths }),
|
|
52
|
+
transform: createExoticTransformer_1.loaders.expoModule,
|
|
53
|
+
warn: true,
|
|
54
|
+
},
|
|
55
|
+
// Match known problematic modules, convert them statically using an expensive, dynamic sucrase.
|
|
56
|
+
{
|
|
57
|
+
type: 'module',
|
|
58
|
+
test: createMatcher_1.createKnownCommunityMatcher({ folders: nodeModulesPaths }),
|
|
59
|
+
transform: createExoticTransformer_1.loaders.untranspiledModule,
|
|
60
|
+
warn: true,
|
|
61
|
+
},
|
|
62
|
+
// Pass through any unhandled node modules as passthrough, this is where the most savings occur.
|
|
63
|
+
// Ideally, you want your project to pass all node modules through this loader.
|
|
64
|
+
// This should be the last "module" rule.
|
|
65
|
+
// Message library authors and ask them to ship their modules as pre-transpiled
|
|
66
|
+
// commonjs, to improve the development speed of your project.
|
|
67
|
+
{
|
|
68
|
+
type: 'module',
|
|
69
|
+
test: () => true,
|
|
70
|
+
transform: createExoticTransformer_1.loaders.passthroughModule,
|
|
71
|
+
},
|
|
72
|
+
// All application code should be transpiled with the user's babel preset,
|
|
73
|
+
// this is the most expensive operation but provides the most customization to the user.
|
|
74
|
+
// The goal is to use this as sparingly as possible.
|
|
75
|
+
{
|
|
76
|
+
test: () => true,
|
|
77
|
+
transform: createExoticTransformer_1.loaders.app,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
module.exports = {
|
|
82
|
+
transform,
|
|
83
|
+
getCacheKey: getCacheKey_1.getCacheKey,
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=metro-expo-exotic-babel-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metro-expo-exotic-babel-transformer.js","sourceRoot":"","sources":["../../src/transformer/metro-expo-exotic-babel-transformer.ts"],"names":[],"mappings":";AAAA,qEAAqE;;AAErE,uEAA6E;AAC7E,mDAKyB;AACzB,+CAA4C;AAE5C,MAAM,gBAAgB,GAAa,CAAC,cAAc,CAAC,CAAC;AAEpD,8CAA8C;AAC9C,MAAM,iBAAiB,GAAG,mCAAmB,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;AAE5F,6DAA6D;AAC7D,8DAA8D;AAC9D,MAAM,2BAA2B,GAAG,mCAAmB,CAAC;IACtD,SAAS,EAAE;QACT,sBAAsB;QACtB,sHAAsH;QACtH,SAAS;QACT,qDAAqD;QACrD,oBAAoB;KACrB;IACD,OA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I,EAAE,QAAQ;YACd,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;YAChB,SAAS,EAAE,iCAAO,CAAC,iBAAiB;SACrC;QACD,0EAA0E;QAC1E,wFAAwF;QACxF,oDAAoD;QACpD;YACE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI;YAChB,SAAS,EAAE,iCAAO,CAAC,GAAG;SACvB;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,GAAG;IACf,SAAS;IACT,WAAW,EAAX,yBAAW;CACZ,CAAC","sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport { createExoticTransformer, loaders } from './createExoticTransformer';\nimport {\n createExpoMatcher,\n createKnownCommunityMatcher,\n createModuleMatcher,\n createReactNativeMatcher,\n} from './createMatcher';\nimport { getCacheKey } from './getCacheKey';\n\nconst nodeModulesPaths: string[] = ['node_modules'];\n\n// Match any node modules, or monorepo module.\nconst nodeModuleMatcher = createModuleMatcher({ folders: nodeModulesPaths, moduleIds: [] });\n\n// Match node modules which are so oddly written that we must\n// transpile them with every possible option (most expensive).\nconst impossibleNodeModuleMatcher = createModuleMatcher({\n moduleIds: [\n // victory is too wild\n // SyntaxError in ../../node_modules/victory-native/lib/components/victory-primitives/bar.js: Missing semicolon. (9:1)\n 'victory',\n // vector icons has some hidden issues that break NCL\n '@expo/vector-icons',\n ],\n folders: nodeModulesPaths,\n});\n\nconst transform = createExoticTransformer({\n // Specify which rules to use on a per-file basis, basically\n // this is used to determine which modules are node modules, and which are application code.\n getRuleType({ filename }) {\n // Is a node module, and is not one of the impossible modules.\n return nodeModuleMatcher.test(filename) && !impossibleNodeModuleMatcher.test(filename)\n ? 'module'\n : 'app';\n },\n\n // Order is very important, we use wild card matchers to transpile\n // \"every unhandled node module\" and \"every unhandled application module\".\n rules: [\n // Match bob compiler modules, use the passthrough loader.\n {\n type: 'module',\n test: createModuleMatcher({ moduleIds: ['.*/lib/commonjs/'], folders: nodeModulesPaths }),\n transform: loaders.passthroughModule,\n warn: true,\n },\n // Match React Native modules, convert them statically using sucrase.\n {\n type: 'module',\n test: createReactNativeMatcher({ folders: nodeModulesPaths }),\n transform: loaders.reactNativeModule,\n warn: true,\n },\n // Match Expo SDK modules, convert them statically using sucrase.\n {\n type: 'module',\n test: createExpoMatcher({ folders: nodeModulesPaths }),\n transform: loaders.expoModule,\n warn: true,\n },\n // Match known problematic modules, convert them statically using an expensive, dynamic sucrase.\n {\n type: 'module',\n test: createKnownCommunityMatcher({ folders: nodeModulesPaths }),\n transform: loaders.untranspiledModule,\n warn: true,\n },\n // Pass through any unhandled node modules as passthrough, this is where the most savings occur.\n // Ideally, you want your project to pass all node modules through this loader.\n // This should be the last \"module\" rule.\n // Message library authors and ask them to ship their modules as pre-transpiled\n // commonjs, to improve the development speed of your project.\n {\n type: 'module',\n test: () => true,\n transform: loaders.passthroughModule,\n },\n // All application code should be transpiled with the user's babel preset,\n // this is the most expensive operation but provides the most customization to the user.\n // The goal is to use this as sparingly as possible.\n {\n test: () => true,\n transform: loaders.app,\n },\n ],\n});\n\nmodule.exports = {\n transform,\n getCacheKey,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A Metro config for running React Native projects with the Metro bundler",
|
|
5
5
|
"main": "build/ExpoMetroConfig.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,14 +33,18 @@
|
|
|
33
33
|
"build"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@expo/config": "
|
|
36
|
+
"@expo/config": "6.0.2",
|
|
37
37
|
"chalk": "^4.1.0",
|
|
38
|
+
"debug": "^4.3.2",
|
|
38
39
|
"getenv": "^1.0.0",
|
|
39
|
-
"metro-react-native-babel-transformer": "^0.59.0"
|
|
40
|
+
"metro-react-native-babel-transformer": "^0.59.0",
|
|
41
|
+
"sucrase": "^3.20.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
44
|
+
"@babel/core": "^7.15.5",
|
|
42
45
|
"expo": "37",
|
|
43
46
|
"metro": "^0.59.0",
|
|
47
|
+
"metro-babel-transformer": "^0.66.2",
|
|
44
48
|
"metro-config": "^0.59.0",
|
|
45
49
|
"react-native": "~0.63.4"
|
|
46
50
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metro-expo-babel-transformer.js","sourceRoot":"","sources":["../src/metro-expo-babel-transformer.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,2BAAkC;AAClC,gEAAuC;AAEvC,MAAM,aAAa,GAAG;IACpB,iBAAY,CAAC,UAAU,CAAC;IACxB,oEAAoE;IACpE,sEAAsE;IACtE,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,OAAO;IACnD,uDAAuD;CACxD,CAAC;AAEF,IAAI,WAAW,GAAQ,IAAI,CAAC;AAE5B,SAAS,kBAAkB,CAAC,WAAmB;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,YAAY,GAAG,sBAAW,CAAC,MAAM,CAAC,WAAW,EAAE,sCAAsC,CAAC,CAAC;IAC7F,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CACb,yEAAyE;YACvE,sDAAsD;YACtD,yEAAyE;YACzE,kCAAkC,CACrC,CAAC;KACH;IACD,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACpC,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,SAAS,CAAC,KAKlB;IACC,mDAAmD;IACnD,KAAK,CAAC,OAAO,CAAC,sBAAsB,GAAG,sBAAW,CAAC,MAAM,CACvD,KAAK,CAAC,OAAO,CAAC,WAAW,EACzB,mBAAmB,CACpB,CAAC;IACF,OAAO,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED,mBAAmB;AACnB,SAAS,WAAW;IAClB,MAAM,GAAG,GAAG,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,WAAW;IACX,SAAS;CACV,CAAC","sourcesContent":["import crypto from 'crypto';\nimport { readFileSync } from 'fs';\nimport resolveFrom from 'resolve-from';\n\nconst cacheKeyParts = [\n readFileSync(__filename),\n // Since babel-preset-fbjs cannot be safely resolved relative to the\n // project root, use this environment variable that we define earlier.\n process.env.EXPO_METRO_CACHE_KEY_VERSION || '3.3.0',\n // require('babel-preset-fbjs/package.json').version,\n];\n\nlet transformer: any = null;\n\nfunction resolveTransformer(projectRoot: string) {\n if (transformer) {\n return transformer;\n }\n const resolvedPath = resolveFrom.silent(projectRoot, 'metro-react-native-babel-transformer');\n if (!resolvedPath) {\n throw new Error(\n 'Missing package \"metro-react-native-babel-transformer\" in the project. ' +\n 'This usually means `react-native` is not installed. ' +\n 'Please verify that dependencies in package.json include \"react-native\" ' +\n 'and run `yarn` or `npm install`.'\n );\n }\n transformer = require(resolvedPath);\n return transformer;\n}\n\n/**\n * Extends the default `metro-react-native-babel-transformer`\n * and uses babel-preset-expo as the default instead of metro-react-native-babel-preset.\n * This enables users to safely transpile an Expo project without\n * needing to explicitly define a `babel.config.js`\n *\n * @param filename string\n * @param options BabelTransformerOptions\n * @param plugins $PropertyType<BabelCoreOptions, 'plugins'>\n * @param src string\n *\n * @returns\n */\nfunction transform(props: {\n filename: string;\n options: Record<string, any> & { projectRoot: string };\n plugins?: unknown;\n src: string;\n}) {\n // Use babel-preset-expo by default if available...\n props.options.extendsBabelConfigPath = resolveFrom.silent(\n props.options.projectRoot,\n 'babel-preset-expo'\n );\n return resolveTransformer(props.options.projectRoot).transform(props);\n}\n\n// Matches upstream\nfunction getCacheKey(): string {\n const key = crypto.createHash('md5');\n cacheKeyParts.forEach(part => key.update(part));\n return key.digest('hex');\n}\n\nmodule.exports = {\n getCacheKey,\n transform,\n};\n"]}
|