Add option to disable internal transforms

Reviewed By: davidaurelio

Differential Revision: D2815307

fb-gh-sync-id: 17ed8f13de7b4c41111efa4a5f2af5283e6ef3e0
This commit is contained in:
Martín Bigio 2016-01-08 11:09:17 -08:00 committed by facebook-github-bot-3
parent 1dc56a6758
commit 8604bd1812
4 changed files with 32 additions and 11 deletions

View File

@ -28,6 +28,7 @@ function buildBundle(args, config, output = outputBundle) {
getTransformOptionsModulePath: config.getTransformOptionsModulePath, getTransformOptionsModulePath: config.getTransformOptionsModulePath,
transformModulePath: args.transformer, transformModulePath: args.transformer,
verbose: args.verbose, verbose: args.verbose,
disableInternalTransforms: true,
}; };
const requestOpts = { const requestOpts = {

View File

@ -80,6 +80,10 @@ const validateOpts = declareOpts({
type: 'number', type: 'number',
required: false, required: false,
}, },
disableInternalTransforms: {
type: 'boolean',
default: false,
},
}); });
class Bundler { class Bundler {
@ -131,6 +135,7 @@ class Bundler {
blacklistRE: opts.blacklistRE, blacklistRE: opts.blacklistRE,
cache: this._cache, cache: this._cache,
transformModulePath: opts.transformModulePath, transformModulePath: opts.transformModulePath,
disableInternalTransforms: opts.disableInternalTransforms,
}); });
this._projectRoots = opts.projectRoots; this._projectRoots = opts.projectRoots;

View File

@ -54,6 +54,10 @@ const validateOpts = declareOpts({
type: 'number', type: 'number',
default: DEFAULT_MAX_CALL_TIME, default: DEFAULT_MAX_CALL_TIME,
}, },
disableInternalTransforms: {
type: 'boolean',
default: false,
},
}); });
class Transformer { class Transformer {
@ -64,14 +68,20 @@ class Transformer {
this._transformModulePath = opts.transformModulePath; this._transformModulePath = opts.transformModulePath;
if (opts.transformModulePath != null) { if (opts.transformModulePath != null) {
this._workerWrapperPath = temp.path(); let transformer;
fs.writeFileSync(
this._workerWrapperPath, if (opts.disableInternalTransforms) {
` transformer = opts.transformModulePath;
module.exports = require(${JSON.stringify(require.resolve('./worker'))}); } else {
require(${JSON.stringify(String(opts.transformModulePath))}); transformer = this._workerWrapperPath = temp.path();
` fs.writeFileSync(
); this._workerWrapperPath,
`
module.exports = require(${JSON.stringify(require.resolve('./worker'))});
require(${JSON.stringify(String(opts.transformModulePath))});
`
);
}
this._workers = workerFarm({ this._workers = workerFarm({
autoStart: true, autoStart: true,
@ -79,7 +89,7 @@ class Transformer {
maxCallsPerWorker: MAX_CALLS_PER_WORKER, maxCallsPerWorker: MAX_CALLS_PER_WORKER,
maxCallTime: opts.transformTimeoutInterval, maxCallTime: opts.transformTimeoutInterval,
maxRetries: MAX_RETRIES, maxRetries: MAX_RETRIES,
}, this._workerWrapperPath); }, transformer);
this._transform = Promise.denodeify(this._workers); this._transform = Promise.denodeify(this._workers);
} }
@ -87,7 +97,8 @@ class Transformer {
kill() { kill() {
this._workers && workerFarm.end(this._workers); this._workers && workerFarm.end(this._workers);
if (typeof this._workerWrapperPath === 'string') { if (this._workerWrapperPath &&
typeof this._workerWrapperPath === 'string') {
fs.unlink(this._workerWrapperPath, () => {}); // we don't care about potential errors here fs.unlink(this._workerWrapperPath, () => {}); // we don't care about potential errors here
} }
} }

View File

@ -67,7 +67,11 @@ const validateOpts = declareOpts({
getTransformOptionsModulePath: { getTransformOptionsModulePath: {
type: 'string', type: 'string',
required: false, required: false,
} },
disableInternalTransforms: {
type: 'boolean',
default: false,
},
}); });
const bundleOpts = declareOpts({ const bundleOpts = declareOpts({