diff --git a/packages/metro-transform-plugins/src/import-export-plugin.js b/packages/metro-transform-plugins/src/import-export-plugin.js index 35c3c926b9..9cf2f09835 100644 --- a/packages/metro-transform-plugins/src/import-export-plugin.js +++ b/packages/metro-transform-plugins/src/import-export-plugin.js @@ -27,6 +27,13 @@ import typeof * as Types from '@babel/types'; const template = require('@babel/template').default; const nullthrows = require('nullthrows'); +export type Options = $ReadOnly<{ + importDefault: string, + importAll: string, + resolve: boolean, + out?: {isESModule: boolean, ...}, +}>; + type State = { exportAll: Array<{file: string, loc: ?BabelSourceLocation, ...}>, exportDefault: Array<{local: string, loc: ?BabelSourceLocation, ...}>, @@ -39,13 +46,7 @@ type State = { imports: Array<{node: Statement}>, importDefault: BabelNode, importAll: BabelNode, - opts: { - importDefault: string, - importAll: string, - resolve: boolean, - out?: {isESModule: boolean, ...}, - ... - }, + opts: Options, ... }; diff --git a/packages/metro-transform-plugins/src/index.js b/packages/metro-transform-plugins/src/index.js index 646a72d4e6..bada3fea27 100644 --- a/packages/metro-transform-plugins/src/index.js +++ b/packages/metro-transform-plugins/src/index.js @@ -16,7 +16,9 @@ import typeof ImportExportPlugin from './import-export-plugin'; import typeof InlineRequiresPlugin from './inline-requires-plugin'; import typeof InlinePlugin from './inline-plugin'; import typeof NormalizePseudoGlobalsFn from './normalizePseudoGlobals'; +export type {Options as ImportExportPluginOptions} from './import-export-plugin'; export type {Options as InlinePluginOptions} from './inline-plugin'; +export type {PluginOptions as InlineRequiresPluginOptions} from './inline-requires-plugin'; type TransformPlugins = { addParamsToDefineCall(string, ...Array): string, diff --git a/packages/metro-transform-plugins/src/inline-plugin.js b/packages/metro-transform-plugins/src/inline-plugin.js index 1961c413c2..48603b46c2 100644 --- a/packages/metro-transform-plugins/src/inline-plugin.js +++ b/packages/metro-transform-plugins/src/inline-plugin.js @@ -25,13 +25,13 @@ import typeof * as Types from '@babel/types'; const createInlinePlatformChecks = require('./utils/createInlinePlatformChecks'); -export type Options = { +export type Options = $ReadOnly<{ dev: boolean, inlinePlatform: boolean, isWrapped: boolean, requireName?: string, platform: string, -}; +}>; type State = {opts: Options}; diff --git a/packages/metro-transform-worker/src/index.js b/packages/metro-transform-worker/src/index.js index 3dea59440f..33c48e97e6 100644 --- a/packages/metro-transform-worker/src/index.js +++ b/packages/metro-transform-worker/src/index.js @@ -23,6 +23,11 @@ import type { FBSourceFunctionMap, MetroSourceMapSegmentTuple, } from 'metro-source-map'; +import type { + ImportExportPluginOptions, + InlinePluginOptions, + InlineRequiresPluginOptions, +} from 'metro-transform-plugins'; import type {TransformResultDependency} from 'metro/src/DeltaBundler'; import type {AllowOptionalDependencies} from 'metro/src/DeltaBundler/types.flow.js'; import type { @@ -287,32 +292,43 @@ async function transformJS( // Perform the import-export transform (in case it's still needed), then // fold requires and perform constant folding (if in dev). const plugins: Array = []; - const babelPluginOpts = { - ...options, - inlineableCalls: [importDefault, importAll], - importDefault, - importAll, - }; if (options.experimentalImportSupport === true) { - plugins.push([metroTransformPlugins.importExportPlugin, babelPluginOpts]); + plugins.push([ + metroTransformPlugins.importExportPlugin, + { + importAll, + importDefault, + resolve: false, + } as ImportExportPluginOptions, + ]); } if (options.inlineRequires) { plugins.push([ metroTransformPlugins.inlineRequiresPlugin, { - ...babelPluginOpts, ignoredRequires: options.nonInlinedRequires, + inlineableCalls: [importDefault, importAll], memoizeCalls: + // $FlowFixMe[incompatible-cast] is this always (?boolean)? options.customTransformOptions?.unstable_memoizeInlineRequires ?? options.unstable_memoizeInlineRequires, nonMemoizedModules: options.unstable_nonMemoizedInlineRequires, - }, + } as InlineRequiresPluginOptions, ]); } - plugins.push([metroTransformPlugins.inlinePlugin, babelPluginOpts]); + plugins.push([ + metroTransformPlugins.inlinePlugin, + { + dev: options.dev, + inlinePlatform: options.inlinePlatform, + isWrapped: false, + // $FlowFixMe[incompatible-cast] expects a string if inlinePlatform + platform: options.platform, + } as InlinePluginOptions, + ]); ast = nullthrows( transformFromAstSync(ast, '', { @@ -345,9 +361,7 @@ async function transformJS( configFile: false, comments: true, filename: file.filename, - plugins: [ - [metroTransformPlugins.constantFoldingPlugin, babelPluginOpts], - ], + plugins: [metroTransformPlugins.constantFoldingPlugin], sourceMaps: false, cloneInputAst: false, }).ast,