From 7035fbc58d122d2ac8ef1e2f775064529347ed58 Mon Sep 17 00:00:00 2001 From: Bhuwan Khattar Date: Thu, 24 Dec 2015 01:01:18 -0800 Subject: [PATCH] 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 --- local-cli/bundle/buildBundle.js | 1 + local-cli/dependencies/dependencies.js | 1 + local-cli/server/runServer.js | 1 + packager/README.md | 5 +++-- .../react-packager/src/Bundler/__tests__/Bundler-test.js | 1 - packager/react-packager/src/Bundler/index.js | 7 +++++-- packager/react-packager/src/Server/index.js | 6 +++--- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index f2f1e3291..6c946a885 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -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, }; diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index 6a8fbb310..adc1e8897 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -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, }; diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index a05b0e2e5..b4a690f4c 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -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'], diff --git a/packager/README.md b/packager/README.md index d14ae0320..039865ba6 100644 --- a/packager/README.md +++ b/packager/README.md @@ -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) diff --git a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js index 37d200f25..ccdc84961 100644 --- a/packager/react-packager/src/Bundler/__tests__/Bundler-test.js +++ b/packager/react-packager/src/Bundler/__tests__/Bundler-test.js @@ -81,7 +81,6 @@ describe('Bundler', function() { bundler = new Bundler({ projectRoots: ['/root'], assetServer: assetServer, - getTransformOptions: () => ({}), }); modules = [ diff --git a/packager/react-packager/src/Bundler/index.js b/packager/react-packager/src/Bundler/index.js index 19174129d..824331c49 100644 --- a/packager/react-packager/src/Bundler/index.js +++ b/packager/react-packager/src/Bundler/index.js @@ -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}) : {} ); } } diff --git a/packager/react-packager/src/Server/index.js b/packager/react-packager/src/Server/index.js index a1fb415a4..c1bc5ce19 100644 --- a/packager/react-packager/src/Server/index.js +++ b/packager/react-packager/src/Server/index.js @@ -64,9 +64,9 @@ const validateOpts = declareOpts({ type: 'number', required: false, }, - getTransformOptions: { - type: 'function', - default: () => ({}), + getTransformOptionsModulePath: { + type: 'string', + required: false, } });