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 4501181cc9
commit 0cc1132b8c
3 changed files with 31 additions and 11 deletions

View File

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

View File

@ -54,6 +54,10 @@ const validateOpts = declareOpts({
type: 'number',
default: DEFAULT_MAX_CALL_TIME,
},
disableInternalTransforms: {
type: 'boolean',
default: false,
},
});
class Transformer {
@ -64,7 +68,12 @@ class Transformer {
this._transformModulePath = opts.transformModulePath;
if (opts.transformModulePath != null) {
this._workerWrapperPath = temp.path();
let transformer;
if (opts.disableInternalTransforms) {
transformer = opts.transformModulePath;
} else {
transformer = this._workerWrapperPath = temp.path();
fs.writeFileSync(
this._workerWrapperPath,
`
@ -72,6 +81,7 @@ class Transformer {
require(${JSON.stringify(String(opts.transformModulePath))});
`
);
}
this._workers = workerFarm({
autoStart: true,
@ -79,7 +89,7 @@ class Transformer {
maxCallsPerWorker: MAX_CALLS_PER_WORKER,
maxCallTime: opts.transformTimeoutInterval,
maxRetries: MAX_RETRIES,
}, this._workerWrapperPath);
}, transformer);
this._transform = Promise.denodeify(this._workers);
}
@ -87,7 +97,8 @@ class Transformer {
kill() {
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
}
}

View File

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