From 588f01e9982775f0699c7bfd56623d4ed3949810 Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Mon, 6 Jun 2016 17:45:30 -0700 Subject: [PATCH] Packager: accept relative --transformer paths everywhere. Summary: `react-native start` already ensures that the `--transformer` path is understood to be relative to CWD, not to the module that ends up importing that file. `react-native bundle` and `react-native dependencies` didn't up until this point. **Test plan:** Ensured that `react-native bundle ... --transformer ./relative/path` works with this patch applied. Closes https://github.com/facebook/react-native/pull/7857 Differential Revision: D3393777 fbshipit-source-id: 303a226fae9c8087c3dd3b2e8d004462ca66665e --- local-cli/bundle/buildBundle.js | 3 ++- local-cli/bundle/bundleCommandLineArgs.js | 2 +- local-cli/dependencies/dependencies.js | 4 ++-- local-cli/server/runServer.js | 8 +------- local-cli/server/server.js | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index 7c9b3f4d0..d71b7515d 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -9,6 +9,7 @@ const log = require('../util/log').out('bundle'); const outputBundle = require('./output/bundle'); +const path = require('path'); const Promise = require('promise'); const saveAssets = require('./saveAssets'); const Server = require('../../packager/react-packager/src/Server'); @@ -31,7 +32,7 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) { assetRoots: config.getAssetRoots(), blacklistRE: config.getBlacklistRE(args.platform), getTransformOptionsModulePath: config.getTransformOptionsModulePath, - transformModulePath: args.transformer, + transformModulePath: path.resolve(args.transformer), extraNodeModules: config.extraNodeModules, nonPersistent: true, resetCache: args['reset-cache'], diff --git a/local-cli/bundle/bundleCommandLineArgs.js b/local-cli/bundle/bundleCommandLineArgs.js index c22aa3946..b3b30dd5b 100644 --- a/local-cli/bundle/bundleCommandLineArgs.js +++ b/local-cli/bundle/bundleCommandLineArgs.js @@ -20,7 +20,7 @@ module.exports = [ type: 'string', }, { command: 'transformer', - description: 'Specify a custom transformer to be used (absolute path)', + description: 'Specify a custom transformer to be used', type: 'string', default: require.resolve('../../packager/transformer'), }, { diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index d9ad3da1d..0010e11c9 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -41,7 +41,7 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) { command: 'transformer', type: 'string', default: require.resolve('../../packager/transformer'), - description: 'Specify a custom transformer to be used (absolute path)' + description: 'Specify a custom transformer to be used' }, { command: 'verbose', description: 'Enables logging', @@ -59,7 +59,7 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) { assetRoots: config.getAssetRoots(), blacklistRE: config.getBlacklistRE(args.platform), getTransformOptionsModulePath: config.getTransformOptionsModulePath, - transformModulePath: args.transformer, + transformModulePath: path.resolve(args.transformer), extraNodeModules: config.extraNodeModules, verbose: config.verbose, }; diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index 362a09ca4..4106102b2 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -13,7 +13,6 @@ const connect = require('connect'); const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware'); const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware'); const http = require('http'); -const isAbsolutePath = require('absolute-path'); const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware'); const messageSocket = require('./util/messageSocket.js'); const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware'); @@ -68,18 +67,13 @@ function runServer(args, config, readyCallback) { } function getPackagerServer(args, config) { - let transformerPath = args.transformer; - if (!isAbsolutePath(transformerPath)) { - transformerPath = path.resolve(process.cwd(), transformerPath); - } - return ReactPackager.createServer({ nonPersistent: args.nonPersistent, projectRoots: args.projectRoots, blacklistRE: config.getBlacklistRE(), cacheVersion: '3', getTransformOptionsModulePath: config.getTransformOptionsModulePath, - transformModulePath: transformerPath, + transformModulePath: path.resolve(args.transformer), extraNodeModules: config.extraNodeModules, assetRoots: args.assetRoots, assetExts: [ diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 2b7efe803..f2766bc46 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -55,7 +55,7 @@ function _server(argv, config, resolve, reject) { command: 'transformer', type: 'string', default: require.resolve('../../packager/transformer'), - description: 'Specify a custom transformer to be used (absolute path)' + description: 'Specify a custom transformer to be used' }, { command: 'resetCache', description: 'Removes cached files',