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:
parent
c197c49123
commit
8ad2ab3b5e
|
@ -52,7 +52,7 @@ function buildBundle(args, config, output = outputBundle, packagerInstance) {
|
|||
projectRoots: config.getProjectRoots(),
|
||||
assetExts: defaultAssetExts.concat(assetExts),
|
||||
blacklistRE: config.getBlacklistRE(),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
getTransformOptions: config.getTransformOptions,
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
resetCache: args.resetCache,
|
||||
|
|
|
@ -28,7 +28,7 @@ function dependencies(argv, config, args, packagerInstance) {
|
|||
const packageOpts = {
|
||||
projectRoots: config.getProjectRoots(),
|
||||
blacklistRE: config.getBlacklistRE(),
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
getTransformOptions: config.getTransformOptions,
|
||||
transformModulePath: transformModulePath,
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
verbose: config.verbose,
|
||||
|
|
|
@ -90,7 +90,7 @@ function getPackagerServer(args, config) {
|
|||
blacklistRE: config.getBlacklistRE(),
|
||||
cacheVersion: '3',
|
||||
extraNodeModules: config.extraNodeModules,
|
||||
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
|
||||
getTransformOptions: config.getTransformOptions,
|
||||
projectRoots: args.projectRoots,
|
||||
resetCache: args.resetCache,
|
||||
transformModulePath: transformModulePath,
|
||||
|
|
|
@ -14,13 +14,15 @@ const assert = require('assert');
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
import type {GetTransformOptions} from '../../packager/react-packager/src/Bundler/index.js';
|
||||
|
||||
const RN_CLI_CONFIG = 'rn-cli.config.js';
|
||||
|
||||
export type ConfigT = {
|
||||
extraNodeModules?: {[id: string]: string},
|
||||
getAssetExts?: () => Array<string>,
|
||||
getTransformModulePath?: () => string,
|
||||
getTransformOptionsModulePath?: () => string,
|
||||
getTransformOptions?: GetTransformOptions<*>,
|
||||
transformVariants?: () => {[name: string]: Object},
|
||||
|
||||
getBlacklistRE(): RegExp,
|
||||
|
|
|
@ -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`
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -87,8 +87,8 @@ const validateOpts = declareOpts({
|
|||
type: 'number',
|
||||
required: false,
|
||||
},
|
||||
getTransformOptionsModulePath: {
|
||||
type: 'string',
|
||||
getTransformOptions: {
|
||||
type: 'function',
|
||||
required: false,
|
||||
},
|
||||
silent: {
|
||||
|
|
Loading…
Reference in New Issue