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<mixed>,
  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
This commit is contained in:
Rafael Oleza 2018-08-23 15:44:48 -07:00 коммит произвёл Lorenzo Sciandra
Родитель a8aa8b673c
Коммит 2fb77a9c10
3 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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<ConfigT> {