[Packager] Allow user to specify a custom transformer file

Summary:
This is an edited re-submission of #1458 because I'm stupid.
Closes https://github.com/facebook/react-native/pull/1497
Github Author: Johannes Lumpe <johannes@johanneslumpe.de>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
Johannes Lumpe 2015-06-26 15:56:22 -07:00
parent 29e49bdb91
commit 1461e4a17e
1 changed files with 12 additions and 1 deletions

View File

@ -12,6 +12,7 @@ var fs = require('fs');
var path = require('path');
var execFile = require('child_process').execFile;
var http = require('http');
var isAbsolutePath = require('absolute-path');
var getFlowTypeCheckMiddleware = require('./getFlowTypeCheckMiddleware');
@ -56,6 +57,11 @@ var options = parseCommandLine([{
}, {
command: 'nonPersistent',
description: 'Disable file watcher'
}, {
command: 'transformer',
type: 'string',
default: require.resolve('./transformer.js'),
description: 'Specify a custom transformer to be used (absolute path)'
}]);
if (options.projectRoots) {
@ -208,12 +214,17 @@ function statusPageMiddleware(req, res, next) {
}
function getAppMiddleware(options) {
var transformerPath = options.transformer;
if (!isAbsolutePath(transformerPath)) {
transformerPath = path.resolve(process.cwd(), transformerPath);
}
return ReactPackager.middleware({
nonPersistent: options.nonPersistent,
projectRoots: options.projectRoots,
blacklistRE: blacklist(options.platform),
cacheVersion: '2',
transformModulePath: require.resolve('./transformer.js'),
transformModulePath: transformerPath,
assetRoots: options.assetRoots,
assetExts: ['png', 'jpeg', 'jpg'],
polyfillModuleNames: [