Do not calculate inverseDependencies when processing a standard delta bundle

Reviewed By: mjesun

Differential Revision: D6373006

fbshipit-source-id: 86863595b1e5f0417e898f19f21ed83147b46db3
This commit is contained in:
Rafael Oleza 2017-11-21 05:22:27 -08:00 committed by Facebook Github Bot
parent b77f177f92
commit e58b7f1d73
2 changed files with 27 additions and 26 deletions

View File

@ -49,10 +49,6 @@ export type DeltaTransformResponse = {|
+pre: DeltaEntries,
+post: DeltaEntries,
+delta: DeltaEntries,
+inverseDependencies: {
[key: string]: $ReadOnlyArray<string>,
__proto__: null,
},
+reset: boolean,
|};
@ -161,6 +157,32 @@ class DeltaTransformer extends EventEmitter {
return this._getDependencies;
}
/**
* Returns a function that can be used to calculate synchronously the
* transitive dependencies of any given file within the dependency graph.
**/
async getInverseDependencies(): Promise<{
[key: string]: $ReadOnlyArray<string>,
__proto__: null,
}> {
if (!this._deltaCalculator.getDependencyEdges().size) {
// If by any means the dependency graph has not been initialized, call
// getDelta() to initialize it.
await this._getDelta();
}
const dependencyEdges = this._deltaCalculator.getDependencyEdges();
const output = Object.create(null);
for (const [path, {inverseDependencies}] of dependencyEdges.entries()) {
output[this._getModuleId({path})] = Array.from(
inverseDependencies,
).map(dep => this._getModuleId({path: dep}));
}
return output;
}
async getRamOptions(
entryFile: string,
options: {dev: boolean, platform: ?string},
@ -238,14 +260,10 @@ class DeltaTransformer extends EventEmitter {
? await this._getAppend(dependencyEdges)
: new Map();
// Inverse dependencies are needed for HMR.
const inverseDependencies = this._getInverseDependencies(dependencyEdges);
return {
pre: prependSources,
post: appendSources,
delta: modifiedDelta,
inverseDependencies,
reset,
};
}
@ -379,23 +397,6 @@ class DeltaTransformer extends EventEmitter {
return append;
}
/**
* Converts the paths in the inverse dependendencies to module ids.
*/
_getInverseDependencies(
dependencyEdges: DependencyEdges,
): {[key: string]: $ReadOnlyArray<string>, __proto__: null} {
const output = Object.create(null);
for (const [path, {inverseDependencies}] of dependencyEdges.entries()) {
output[this._getModuleId({path})] = Array.from(
inverseDependencies,
).map(dep => this._getModuleId({path: dep}));
}
return output;
}
async _transformModules(
modules: Array<Module>,
transformOptions: JSTransformerOptions,

View File

@ -140,7 +140,7 @@ class HmrServer<TClient: Client> {
type: 'update',
body: {
modules,
inverseDependencies: result.inverseDependencies,
inverseDependencies: await client.deltaTransformer.getInverseDependencies(),
sourceURLs: {},
sourceMappingURLs: {}, // TODO: handle Source Maps
},