mirror of https://github.com/status-im/metro.git
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
fb9d114861
commit
64c1205838
|
@ -110,9 +110,8 @@ Builds a bundle according to the provided options.
|
||||||
* `nonPersistent` boolean, defaults to false: Whether the server
|
* `nonPersistent` boolean, defaults to false: Whether the server
|
||||||
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
|
||||||
* `getTransformOptionsModulePath` string: Path to module that exports a function
|
* `getTransformOptions` function: A function that acts as a middleware for
|
||||||
that acts as a middleware for generating options to pass to the transformer
|
generating options to pass to the transformer based on the bundle being built.
|
||||||
based on the bundle being built.
|
|
||||||
|
|
||||||
#### `bundleOptions`
|
#### `bundleOptions`
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ import AssetServer from '../AssetServer';
|
||||||
import Module from '../node-haste/Module';
|
import Module from '../node-haste/Module';
|
||||||
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||||
|
|
||||||
export type TransformOptionsModule<T> = (
|
export type GetTransformOptions<T> = (
|
||||||
string,
|
string,
|
||||||
Object,
|
Object,
|
||||||
string => Promise<Array<string>>,
|
string => Promise<Array<string>>,
|
||||||
|
@ -121,6 +121,7 @@ type Options = {
|
||||||
cacheVersion: string,
|
cacheVersion: string,
|
||||||
resetCache: boolean,
|
resetCache: boolean,
|
||||||
transformModulePath: string,
|
transformModulePath: string,
|
||||||
|
getTransformOptions?: GetTransformOptions<*>,
|
||||||
extraNodeModules: {},
|
extraNodeModules: {},
|
||||||
assetExts: Array<string>,
|
assetExts: Array<string>,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
|
@ -138,7 +139,7 @@ class Bundler {
|
||||||
_resolver: Resolver;
|
_resolver: Resolver;
|
||||||
_projectRoots: Array<string>;
|
_projectRoots: Array<string>;
|
||||||
_assetServer: AssetServer;
|
_assetServer: AssetServer;
|
||||||
_transformOptionsModule: TransformOptionsModule<*>;
|
_getTransformOptions: void | GetTransformOptions<*>;
|
||||||
|
|
||||||
constructor(options: Options) {
|
constructor(options: Options) {
|
||||||
const opts = this._opts = validateOpts(options);
|
const opts = this._opts = validateOpts(options);
|
||||||
|
@ -204,12 +205,7 @@ class Bundler {
|
||||||
this._projectRoots = opts.projectRoots;
|
this._projectRoots = opts.projectRoots;
|
||||||
this._assetServer = opts.assetServer;
|
this._assetServer = opts.assetServer;
|
||||||
|
|
||||||
if (opts.getTransformOptionsModulePath) {
|
this._getTransformOptions = opts.getTransformOptions;
|
||||||
/* $FlowFixMe: dynamic requires prevent static typing :'( */
|
|
||||||
this._transformOptionsModule = require(
|
|
||||||
opts.getTransformOptionsModulePath
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end() {
|
end() {
|
||||||
|
@ -744,8 +740,8 @@ class Bundler {
|
||||||
const getDependencies = (entryFile: string) =>
|
const getDependencies = (entryFile: string) =>
|
||||||
this.getDependencies({...options, entryFile})
|
this.getDependencies({...options, entryFile})
|
||||||
.then(r => r.dependencies.map(d => d.path));
|
.then(r => r.dependencies.map(d => d.path));
|
||||||
const extraOptions = this._transformOptionsModule
|
const extraOptions = this._getTransformOptions
|
||||||
? this._transformOptionsModule(mainModuleName, options, getDependencies)
|
? this._getTransformOptions(mainModuleName, options, getDependencies)
|
||||||
: null;
|
: null;
|
||||||
return Promise.resolve(extraOptions)
|
return Promise.resolve(extraOptions)
|
||||||
.then(extraOpts => Object.assign(options, extraOpts));
|
.then(extraOpts => Object.assign(options, extraOpts));
|
||||||
|
|
|
@ -87,8 +87,8 @@ const validateOpts = declareOpts({
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
getTransformOptionsModulePath: {
|
getTransformOptions: {
|
||||||
type: 'string',
|
type: 'function',
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
silent: {
|
silent: {
|
||||||
|
|
Loading…
Reference in New Issue