@expo/metro-config
Advanced tools
Comparing version 0.18.7 to 0.18.8
@@ -1,1 +0,17 @@ | ||
export {}; | ||
import type { TransformOptions } from './babel-core'; | ||
export type ExpoBabelCaller = TransformOptions['caller'] & { | ||
supportsReactCompiler?: boolean; | ||
isReactServer?: boolean; | ||
isHMREnabled?: boolean; | ||
isServer?: boolean; | ||
isNodeModule?: boolean; | ||
preserveEnvVars?: boolean; | ||
isDev?: boolean; | ||
asyncRoutes?: boolean; | ||
baseUrl?: string; | ||
engine?: string; | ||
bundler?: 'metro' | (string & object); | ||
platform?: string | null; | ||
routerRoot?: string; | ||
projectRoot: string; | ||
}; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const transformSync_1 = require("./transformSync"); | ||
const debug = require('debug')('expo:metro-config:babel-transformer'); | ||
function isCustomTruthy(value) { | ||
@@ -26,5 +27,5 @@ return value === true || value === 'true'; | ||
const memoizeWarning = memoize((message) => { | ||
console.warn(message); | ||
debug(message); | ||
}); | ||
function getBabelCaller({ filename, options }) { | ||
function getBabelCaller({ filename, options, }) { | ||
const isNodeModule = filename.includes('node_modules'); | ||
@@ -38,3 +39,3 @@ const isReactServer = options.customTransformOptions?.environment === 'react-server'; | ||
if (routerRoot == null) { | ||
memoizeWarning('Missing transform.routerRoot option in Metro bundling request, falling back to `app` as routes directory.'); | ||
memoizeWarning('Warning: Missing transform.routerRoot option in Metro bundling request, falling back to `app` as routes directory. This can occur if you bundle without Expo CLI or expo/metro-config.'); | ||
} | ||
@@ -66,3 +67,3 @@ return { | ||
// target environment. | ||
engine: options.customTransformOptions?.engine, | ||
engine: stringOrUndefined(options.customTransformOptions?.engine), | ||
// Provide the project root for accurately reading the Expo config. | ||
@@ -74,4 +75,12 @@ projectRoot: options.projectRoot, | ||
supportsStaticESM: options.experimentalImportSupport, | ||
// Enable React compiler support in Babel. | ||
// TODO: Remove this in the future when compiler is on by default. | ||
supportsReactCompiler: isCustomTruthy(options.customTransformOptions?.reactCompiler) | ||
? true | ||
: undefined, | ||
}; | ||
} | ||
function stringOrUndefined(value) { | ||
return typeof value === 'string' ? value : undefined; | ||
} | ||
const transform = ({ filename, src, options, | ||
@@ -78,0 +87,0 @@ // `plugins` is used for `functionMapBabelPlugin` from `metro-source-map`. Could make sense to move this to `babel-preset-expo` too. |
@@ -137,2 +137,3 @@ "use strict"; | ||
}); | ||
const serverRoot = (0, getModulesPaths_1.getServerRoot)(projectRoot); | ||
// Merge in the default config from Metro here, even though loadConfig uses it as defaults. | ||
@@ -185,3 +186,17 @@ // This is a convenience for getDefaultConfig use in metro.config.js, e.g. to modify assetExts. | ||
}, | ||
getPolyfills: () => require('@react-native/js-polyfills')(), | ||
getPolyfills: ({ platform }) => { | ||
// Do nothing for nullish platforms. | ||
if (!platform) { | ||
return []; | ||
} | ||
if (platform === 'web') { | ||
return [ | ||
// Ensure that the error-guard polyfill is included in the web polyfills to | ||
// make metro-runtime work correctly. | ||
require.resolve('@react-native/js-polyfills/error-guard'), | ||
]; | ||
} | ||
// Native behavior. | ||
return require('@react-native/js-polyfills')(); | ||
}, | ||
}, | ||
@@ -193,3 +208,3 @@ server: { | ||
// This enables proper monorepo support for web. | ||
unstable_serverRoot: (0, getModulesPaths_1.getServerRoot)(projectRoot), | ||
unstable_serverRoot: serverRoot, | ||
}, | ||
@@ -203,2 +218,3 @@ symbolicator: { | ||
// @ts-expect-error: not on type. | ||
unstable_renameRequire: false, | ||
postcssHash: (0, postcss_1.getPostcssConfigHash)(projectRoot), | ||
@@ -211,2 +227,4 @@ browserslistHash: pkg.browserslist | ||
reanimatedVersion, | ||
// Ensure invalidation when using identical projects in monorepos | ||
_expoRelativeProjectRoot: path_1.default.relative(serverRoot, projectRoot), | ||
// `require.context` support | ||
@@ -213,0 +231,0 @@ unstable_allowRequireContext: true, |
@@ -71,2 +71,5 @@ "use strict"; | ||
} | ||
if (!ensured.searchParams.has('transform.reactCompiler') && exp.experiments?.reactCompiler) { | ||
ensured.searchParams.set('transform.reactCompiler', String(!!exp.experiments?.reactCompiler)); | ||
} | ||
if (!ensured.searchParams.has('transform.engine')) { | ||
@@ -73,0 +76,0 @@ const isHermesEnabled = isEnableHermesManaged(exp, platform); |
@@ -100,4 +100,4 @@ "use strict"; | ||
// multiple files. It's usually used for things like TypeScript where you want the file name to appear with a | ||
// different extension. Since it's unclear to me (Bacon) how it is used on native, I'm only disabling in web. | ||
sourceUrl: options.platform === 'web' ? undefined : options.sourceUrl, | ||
// different extension. Since it's unclear to me (Bacon) how it is used on native, I'm only disabling in web and native in production. | ||
sourceUrl: options.platform === 'web' ? undefined : !options.dev ? undefined : options.sourceUrl, | ||
}); | ||
@@ -104,0 +104,0 @@ // If the `debugId` annotation is available and we aren't inlining the source map, add it to the bundle. |
@@ -233,3 +233,4 @@ "use strict"; | ||
} | ||
const isAbsolute = this.getPlatform() !== 'web'; | ||
const platform = this.getPlatform(); | ||
const isAbsolute = platform !== 'web'; | ||
const baseUrl = (0, baseJSBundle_1.getBaseUrlOption)(this.graph, this.options); | ||
@@ -255,2 +256,6 @@ const filename = this.getFilenameForConfig(serializerConfig); | ||
catch (error) { | ||
// NOTE: export:embed that don't use baseUrl will use file paths instead of URLs. | ||
if (!this.options.dev && isAbsolute) { | ||
return adjustedSourceMapUrl; | ||
} | ||
console.error(`Failed to link source maps because the source map URL "${this.options.sourceMapUrl}" is corrupt:`, error); | ||
@@ -257,0 +262,0 @@ return null; |
@@ -260,3 +260,8 @@ "use strict"; | ||
// TODO: Replace this with a cheaper transform that doesn't require AST. | ||
({ ast: wrappedAst } = JsFileWrapping_1.default.wrapModule(ast, importDefault, importAll, dependencyMapName, config.globalPrefix)); | ||
({ ast: wrappedAst } = JsFileWrapping_1.default.wrapModule(ast, importDefault, importAll, dependencyMapName, config.globalPrefix, | ||
// TODO: This config is optional to allow its introduction in a minor | ||
// release. It should be made non-optional in ConfigT or removed in | ||
// future. | ||
// @ts-expect-error: Not on types yet (Metro 0.80.9). | ||
config.unstable_renameRequire === false)); | ||
} | ||
@@ -327,2 +332,12 @@ } | ||
const transformer = require(babelTransformerPath); | ||
// HACK: React Compiler injects import statements and exits the Babel process which leaves the code in | ||
// a malformed state. For now, we'll enable the experimental import support which compiles import statements | ||
// outside of the standard Babel process. | ||
if (!context.options.experimentalImportSupport) { | ||
const reactCompilerFlag = context.options.customTransformOptions?.reactCompiler; | ||
if (reactCompilerFlag === true || reactCompilerFlag === 'true') { | ||
// @ts-expect-error: readonly. | ||
context.options.experimentalImportSupport = true; | ||
} | ||
} | ||
const transformResult = await transformer.transform( | ||
@@ -329,0 +344,0 @@ // functionMapBabelPlugin populates metadata.metro.functionMap |
{ | ||
"name": "@expo/metro-config", | ||
"version": "0.18.7", | ||
"version": "0.18.8", | ||
"description": "A Metro config for running React Native projects with the Metro bundler", | ||
@@ -63,3 +63,3 @@ "main": "build/ExpoMetroConfig.js", | ||
}, | ||
"gitHead": "6f609a05a2d4dac7fd281bcc502575440c5af7c9" | ||
"gitHead": "09b2d97bbc0f70f7c811ff9b6c9ad8808c5ad84b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274242
3925