Skip to content

Commit e4621f4

Browse files
rafecafacebook-github-bot
authored andcommitted
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
1 parent dd0900a commit e4621f4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

local-cli/bundle/buildBundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ async function buildBundle(
4444
sourceMapUrl = path.basename(sourceMapUrl);
4545
}
4646

47-
config.transformModulePath = args.transformer
47+
config.transformerPath = args.transformer
4848
? path.resolve(args.transformer)
49-
: config.transformModulePath;
49+
: config.transformerPath;
5050

5151
const requestOpts: RequestOptions = {
5252
entryFile: args.entryFile,

local-cli/dependencies/dependencies.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ async function dependencies(argv, configPromise, args, packagerInstance) {
2525
}
2626

2727
config.cacheStores = [];
28-
config.transformModulePath = args.transformer
29-
? path.resolve(args.transformer)
30-
: config.transformModulePath;
28+
if (args.transformer) {
29+
config.transformer.babelTransformerPath = path.resolve(args.transformer);
30+
}
3131

3232
const relativePath = path.relative(
3333
config.projectRoot,

local-cli/util/Config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ const Config = {
7676
],
7777
getPolyfills,
7878
},
79+
transformer: {
80+
babelTransformerPath: require.resolve('metro/src/reactNativeTransformer'),
81+
},
7982
watchFolders: getWatchFolders(),
80-
transformModulePath: require.resolve('metro/src/reactNativeTransformer'),
8183
},
8284

8385
async load(configFile: ?string): Promise<ConfigT> {

0 commit comments

Comments
 (0)