From 2fb77a9c1097e7b05d583e91a37981dfc7b6640f Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 23 Aug 2018 15:44:48 -0700 Subject: [PATCH] Expose the actual transformer in the config Summary: This diff exposes the new more generic way to configure transformers in `Metro` via the config parameter `transformerPath`. The new generic transformers can be used to transform any kind of file, since they don't call any JS-specific method and their API is generic. They only need to implement a single `transform` method: ``` async function transform( absolutePath: string, relativePath: string, fileContents: Buffer, options: TransformOptions, // very soon these will be configurable ): Promise<{ output: Array, dependencies: Array<{ name: string, data: mixed, // very soon }>, }> { // ... } ``` Metro already had a `transformModulePath` config param, which was used to configure how babel was called in order to generate the AST. In order to avoid confusion, but keep the current open source transformer worker, I've renamed this param to `babelTransformerPath`. We can add a layer of compatibility and detect old config params in order to show a deprecation warning. Reviewed By: pvdz Differential Revision: D9070810 fbshipit-source-id: aebde879736026c09537f5d236eae24c06640abf --- local-cli/bundle/buildBundle.js | 4 ++-- local-cli/dependencies/dependencies.js | 6 +++--- local-cli/util/Config.js | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index cd31e21e0de..426365a2612 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -44,9 +44,9 @@ async function buildBundle( sourceMapUrl = path.basename(sourceMapUrl); } - config.transformModulePath = args.transformer + config.transformerPath = args.transformer ? path.resolve(args.transformer) - : config.transformModulePath; + : config.transformerPath; const requestOpts: RequestOptions = { entryFile: args.entryFile, diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index 6191548073c..e72293e646b 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -25,9 +25,9 @@ async function dependencies(argv, configPromise, args, packagerInstance) { } config.cacheStores = []; - config.transformModulePath = args.transformer - ? path.resolve(args.transformer) - : config.transformModulePath; + if (args.transformer) { + config.transformer.babelTransformerPath = path.resolve(args.transformer); + } const relativePath = path.relative( config.projectRoot, diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index d6d0134d133..d6a8e24bec5 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -76,8 +76,10 @@ const Config = { ], getPolyfills, }, + transformer: { + babelTransformerPath: require.resolve('metro/src/reactNativeTransformer'), + }, watchFolders: getWatchFolders(), - transformModulePath: require.resolve('metro/src/reactNativeTransformer'), }, async load(configFile: ?string): Promise {