BREAKING: expose `getTransformOptions` directly in configuration

Summary:
Instead of exposing a `getTransformOptionsModulePath` function in configurations, we can simply expose a `getTransformOptions` *function*. The necessity of exposing a path comes from the olden days, where we had a server listening on a socket, and a client, talking to that server.

Since that architectural gem no longer exists, we can use functions directly, rather than passing paths to modules around.

Reviewed By: cpojer

Differential Revision: D4233551

fbshipit-source-id: ec1acef8e6495a2f1fd0911a5613c144e8ffd7c3
This commit is contained in:
David Aurelio 2016-11-28 07:27:09 -08:00 committed by Facebook Github Bot
parent fb9d114861
commit 64c1205838
3 changed files with 10 additions and 15 deletions

View File

@ -110,9 +110,8 @@ Builds a bundle according to the provided options.
* `nonPersistent` boolean, defaults to false: Whether the server
should be used as a persistent deamon to watch files and update
itself
* `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 being built.
* `getTransformOptions` function: A function that acts as a middleware for
generating options to pass to the transformer based on the bundle being built.
#### `bundleOptions`

View File

@ -36,7 +36,7 @@ import AssetServer from '../AssetServer';
import Module from '../node-haste/Module';
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
export type TransformOptionsModule<T> = (
export type GetTransformOptions<T> = (
string,
Object,
string => Promise<Array<string>>,
@ -121,6 +121,7 @@ type Options = {
cacheVersion: string,
resetCache: boolean,
transformModulePath: string,
getTransformOptions?: GetTransformOptions<*>,
extraNodeModules: {},
assetExts: Array<string>,
watch: boolean,
@ -138,7 +139,7 @@ class Bundler {
_resolver: Resolver;
_projectRoots: Array<string>;
_assetServer: AssetServer;
_transformOptionsModule: TransformOptionsModule<*>;
_getTransformOptions: void | GetTransformOptions<*>;
constructor(options: Options) {
const opts = this._opts = validateOpts(options);
@ -204,12 +205,7 @@ class Bundler {
this._projectRoots = opts.projectRoots;
this._assetServer = opts.assetServer;
if (opts.getTransformOptionsModulePath) {
/* $FlowFixMe: dynamic requires prevent static typing :'( */
this._transformOptionsModule = require(
opts.getTransformOptionsModulePath
);
}
this._getTransformOptions = opts.getTransformOptions;
}
end() {
@ -744,8 +740,8 @@ class Bundler {
const getDependencies = (entryFile: string) =>
this.getDependencies({...options, entryFile})
.then(r => r.dependencies.map(d => d.path));
const extraOptions = this._transformOptionsModule
? this._transformOptionsModule(mainModuleName, options, getDependencies)
const extraOptions = this._getTransformOptions
? this._getTransformOptions(mainModuleName, options, getDependencies)
: null;
return Promise.resolve(extraOptions)
.then(extraOpts => Object.assign(options, extraOpts));

View File

@ -87,8 +87,8 @@ const validateOpts = declareOpts({
type: 'number',
required: false,
},
getTransformOptionsModulePath: {
type: 'string',
getTransformOptions: {
type: 'function',
required: false,
},
silent: {