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
This commit is contained in:
Philipp von Weitershausen 2016-06-06 17:45:30 -07:00 committed by Facebook Github Bot 7
parent 93c7a93de9
commit 588f01e998
5 changed files with 7 additions and 12 deletions

View File

@ -9,6 +9,7 @@
const log = require('../util/log').out('bundle'); const log = require('../util/log').out('bundle');
const outputBundle = require('./output/bundle'); const outputBundle = require('./output/bundle');
const path = require('path');
const Promise = require('promise'); const Promise = require('promise');
const saveAssets = require('./saveAssets'); const saveAssets = require('./saveAssets');
const Server = require('../../packager/react-packager/src/Server'); const Server = require('../../packager/react-packager/src/Server');
@ -31,7 +32,7 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
assetRoots: config.getAssetRoots(), assetRoots: config.getAssetRoots(),
blacklistRE: config.getBlacklistRE(args.platform), blacklistRE: config.getBlacklistRE(args.platform),
getTransformOptionsModulePath: config.getTransformOptionsModulePath, getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: path.resolve(args.transformer),
extraNodeModules: config.extraNodeModules, extraNodeModules: config.extraNodeModules,
nonPersistent: true, nonPersistent: true,
resetCache: args['reset-cache'], resetCache: args['reset-cache'],

View File

@ -20,7 +20,7 @@ module.exports = [
type: 'string', type: 'string',
}, { }, {
command: 'transformer', command: 'transformer',
description: 'Specify a custom transformer to be used (absolute path)', description: 'Specify a custom transformer to be used',
type: 'string', type: 'string',
default: require.resolve('../../packager/transformer'), default: require.resolve('../../packager/transformer'),
}, { }, {

View File

@ -41,7 +41,7 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) {
command: 'transformer', command: 'transformer',
type: 'string', type: 'string',
default: require.resolve('../../packager/transformer'), 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', command: 'verbose',
description: 'Enables logging', description: 'Enables logging',
@ -59,7 +59,7 @@ function _dependencies(argv, config, resolve, reject, packagerInstance) {
assetRoots: config.getAssetRoots(), assetRoots: config.getAssetRoots(),
blacklistRE: config.getBlacklistRE(args.platform), blacklistRE: config.getBlacklistRE(args.platform),
getTransformOptionsModulePath: config.getTransformOptionsModulePath, getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: path.resolve(args.transformer),
extraNodeModules: config.extraNodeModules, extraNodeModules: config.extraNodeModules,
verbose: config.verbose, verbose: config.verbose,
}; };

View File

@ -13,7 +13,6 @@ const connect = require('connect');
const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware'); const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware'); const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
const http = require('http'); const http = require('http');
const isAbsolutePath = require('absolute-path');
const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware'); const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware');
const messageSocket = require('./util/messageSocket.js'); const messageSocket = require('./util/messageSocket.js');
const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware'); const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware');
@ -68,18 +67,13 @@ function runServer(args, config, readyCallback) {
} }
function getPackagerServer(args, config) { function getPackagerServer(args, config) {
let transformerPath = args.transformer;
if (!isAbsolutePath(transformerPath)) {
transformerPath = path.resolve(process.cwd(), transformerPath);
}
return ReactPackager.createServer({ return ReactPackager.createServer({
nonPersistent: args.nonPersistent, nonPersistent: args.nonPersistent,
projectRoots: args.projectRoots, projectRoots: args.projectRoots,
blacklistRE: config.getBlacklistRE(), blacklistRE: config.getBlacklistRE(),
cacheVersion: '3', cacheVersion: '3',
getTransformOptionsModulePath: config.getTransformOptionsModulePath, getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: transformerPath, transformModulePath: path.resolve(args.transformer),
extraNodeModules: config.extraNodeModules, extraNodeModules: config.extraNodeModules,
assetRoots: args.assetRoots, assetRoots: args.assetRoots,
assetExts: [ assetExts: [

View File

@ -55,7 +55,7 @@ function _server(argv, config, resolve, reject) {
command: 'transformer', command: 'transformer',
type: 'string', type: 'string',
default: require.resolve('../../packager/transformer'), 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', command: 'resetCache',
description: 'Removes cached files', description: 'Removes cached files',