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(),
assetRoots: config.getAssetRoots(),
blacklistRE: config.getBlacklistRE(),
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer,
verbose: args.verbose,
};

View File

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

View File

@ -66,6 +66,7 @@ function getAppMiddleware(args, config) {
projectRoots: args.projectRoots,
blacklistRE: config.getBlacklistRE(),
cacheVersion: '3',
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: transformerPath,
assetRoots: args.assetRoots,
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
itself
* `assetRoots` array: Where should the packager look for assets
* `getTransformOptions` function: Middleware to get custom options for the
transformer based on the bundle and module being transformed.
* `getTransformOptionsModulePath` string: Path to module that exports a function
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)

View File

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

View File

@ -136,7 +136,9 @@ class Bundler {
this._projectRoots = opts.projectRoots;
this._assetServer = opts.assetServer;
this._getTransformOptions = opts.getTransformOptions;
if (opts.getTransformOptionsModulePath) {
this._getTransformOptions = require(opts.getTransformOptionsModulePath);
}
}
kill() {
@ -325,7 +327,8 @@ class Bundler {
} else {
return this._transformer.loadFileAndTransform(
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',
required: false,
},
getTransformOptions: {
type: 'function',
default: () => ({}),
getTransformOptionsModulePath: {
type: 'string',
required: false,
}
});