[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 737a32417f
commit d70ff04746
1 changed files with 12 additions and 1 deletions

View File

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