getTransformOptionsModulePath

Summary:
Passing around a `getTransformOptions` function doesn't really work with the CLI utils, so I'm changing this to `getTransformOptionsModulePath` instead, which can easily be injected in through `rn-cli.config.js`.

public

Reviewed By: martinbigio

Differential Revision: D2785789

fb-gh-sync-id: c9fdc358cb5d0db27e0d02496e44c013c77f3d5f
This commit is contained in:
Bhuwan Khattar 2015-12-24 01:01:18 -08:00 committed by facebook-github-bot-5
parent 893a54d0cd
commit 7035fbc58d
7 changed files with 14 additions and 8 deletions

View File

@ -25,6 +25,7 @@ function buildBundle(args, config, output = outputBundle) {
projectRoots: config.getProjectRoots(), projectRoots: config.getProjectRoots(),
assetRoots: config.getAssetRoots(), assetRoots: config.getAssetRoots(),
blacklistRE: config.getBlacklistRE(), blacklistRE: config.getBlacklistRE(),
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: args.transformer,
verbose: args.verbose, verbose: args.verbose,
}; };

View File

@ -60,6 +60,7 @@ function _dependencies(argv, config, resolve, reject) {
projectRoots: config.getProjectRoots(), projectRoots: config.getProjectRoots(),
assetRoots: config.getAssetRoots(), assetRoots: config.getAssetRoots(),
blacklistRE: config.getBlacklistRE(args.platform), blacklistRE: config.getBlacklistRE(args.platform),
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: args.transformer,
verbose: config.verbose, verbose: config.verbose,
}; };

View File

@ -66,6 +66,7 @@ function getAppMiddleware(args, config) {
projectRoots: args.projectRoots, projectRoots: args.projectRoots,
blacklistRE: config.getBlacklistRE(), blacklistRE: config.getBlacklistRE(),
cacheVersion: '3', cacheVersion: '3',
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: transformerPath, transformModulePath: transformerPath,
assetRoots: args.assetRoots, assetRoots: args.assetRoots,
assetExts: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'], assetExts: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'],

View File

@ -112,8 +112,9 @@ middleware. Takes the following options:
should be used as a persistent deamon to watch files and update should be used as a persistent deamon to watch files and update
itself itself
* `assetRoots` array: Where should the packager look for assets * `assetRoots` array: Where should the packager look for assets
* `getTransformOptions` function: Middleware to get custom options for the * `getTransformOptionsModulePath` string: Path to module that exports a function
transformer based on the bundle and module being transformed. that acts as a middleware for generating options to pass to the transformer
based on the bundle and module being transformed.
### ReactPackager.buildPackageFromUrl(options, url) ### ReactPackager.buildPackageFromUrl(options, url)

View File

@ -81,7 +81,6 @@ describe('Bundler', function() {
bundler = new Bundler({ bundler = new Bundler({
projectRoots: ['/root'], projectRoots: ['/root'],
assetServer: assetServer, assetServer: assetServer,
getTransformOptions: () => ({}),
}); });
modules = [ modules = [

View File

@ -136,7 +136,9 @@ class Bundler {
this._projectRoots = opts.projectRoots; this._projectRoots = opts.projectRoots;
this._assetServer = opts.assetServer; this._assetServer = opts.assetServer;
this._getTransformOptions = opts.getTransformOptions; if (opts.getTransformOptionsModulePath) {
this._getTransformOptions = require(opts.getTransformOptionsModulePath);
}
} }
kill() { kill() {
@ -325,7 +327,8 @@ class Bundler {
} else { } else {
return this._transformer.loadFileAndTransform( return this._transformer.loadFileAndTransform(
path.resolve(module.path), path.resolve(module.path),
this._getTransformOptions({bundle, module, platform}) this._getTransformOptions ?
this._getTransformOptions({bundle, module, platform}) : {}
); );
} }
} }

View File

@ -64,9 +64,9 @@ const validateOpts = declareOpts({
type: 'number', type: 'number',
required: false, required: false,
}, },
getTransformOptions: { getTransformOptionsModulePath: {
type: 'function', type: 'string',
default: () => ({}), required: false,
} }
}); });