mirror of https://github.com/status-im/metro.git
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:
parent
61c745b8e6
commit
19e7bf2322
|
@ -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)
|
||||
|
||||
|
|
|
@ -81,7 +81,6 @@ describe('Bundler', function() {
|
|||
bundler = new Bundler({
|
||||
projectRoots: ['/root'],
|
||||
assetServer: assetServer,
|
||||
getTransformOptions: () => ({}),
|
||||
});
|
||||
|
||||
modules = [
|
||||
|
|
|
@ -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}) : {}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,9 +64,9 @@ const validateOpts = declareOpts({
|
|||
type: 'number',
|
||||
required: false,
|
||||
},
|
||||
getTransformOptions: {
|
||||
type: 'function',
|
||||
default: () => ({}),
|
||||
getTransformOptionsModulePath: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue