Add transform option to module / module cache

Summary:
public

This adds an option to `Module` (and its callers) that allows to transform code before extracting dependencies. The transform function has to return a promise that resolves to an object with `code`, and optionally `dependencies` and/or `asyncDependencies` properties, if standard dependency extraction cannot be applied

Reviewed By: cpojer

Differential Revision: D2870437

fb-gh-sync-id: 806d24ba16b1693d838a3fa747d82be9dc6ccf00
This commit is contained in:
David Aurelio
2016-01-28 16:28:37 -08:00
committed by facebook-github-bot-0
parent ca8792d2cc
commit a61ab8795a
4 changed files with 201 additions and 96 deletions

View File

@@ -7,13 +7,21 @@ const path = require('path');
class ModuleCache {
constructor(fastfs, cache, extractRequires, depGraphHelpers) {
constructor({
fastfs,
cache,
extractRequires,
transformCode,
depGraphHelpers,
}) {
this._moduleCache = Object.create(null);
this._packageCache = Object.create(null);
this._fastfs = fastfs;
this._cache = cache;
this._extractRequires = extractRequires;
this._transformCode = transformCode;
this._depGraphHelpers = depGraphHelpers;
fastfs.on('change', this._processFileChange.bind(this));
}
@@ -26,6 +34,7 @@ class ModuleCache {
moduleCache: this,
cache: this._cache,
extractor: this._extractRequires,
transformCode: this._transformCode,
depGraphHelpers: this._depGraphHelpers,
});
}