From d70ff047461fdbd0adfea9a200165175598b2037 Mon Sep 17 00:00:00 2001 From: Johannes Lumpe Date: Fri, 26 Jun 2015 15:56:22 -0700 Subject: [PATCH] [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 Test Plan: Imported from GitHub, without a `Test Plan:` line. --- packager.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packager.js b/packager.js index f2d526e0..d179617c 100644 --- a/packager.js +++ b/packager.js @@ -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: [