Keep the dependencyMaps consistent between runs

Reviewed By: mjesun

Differential Revision: D6413998

fbshipit-source-id: fd0ff9a82dcca23603977456b51213216c370f8d
This commit is contained in:
Rafael Oleza 2017-11-27 08:37:47 -08:00 committed by Facebook Github Bot
parent 167bda72b0
commit d46e4ecb6a
1 changed files with 12 additions and 7 deletions

View File

@ -16,6 +16,7 @@ const DeltaCalculator = require('./DeltaCalculator');
const addParamsToDefineCall = require('../lib/addParamsToDefineCall'); const addParamsToDefineCall = require('../lib/addParamsToDefineCall');
const createModuleIdFactory = require('../lib/createModuleIdFactory'); const createModuleIdFactory = require('../lib/createModuleIdFactory');
const nullthrows = require('fbjs/lib/nullthrows');
const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions'); const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions');
const {EventEmitter} = require('events'); const {EventEmitter} = require('events');
@ -433,6 +434,13 @@ class DeltaTransformer extends EventEmitter {
let wrappedCode; let wrappedCode;
// Get the absolute path of each of the module dependencies from the
// dependency edges. The module dependencies ensure correct order, while
// the dependency edges do not ensure the same order between rebuilds.
const dependencies = metadata.dependencies.map(dependency =>
nullthrows(dependencyPairs.get(dependency)),
);
if (module.isAsset()) { if (module.isAsset()) {
wrappedCode = await this._wrapAsset({ wrappedCode = await this._wrapAsset({
code: metadata.code, code: metadata.code,
@ -443,7 +451,7 @@ class DeltaTransformer extends EventEmitter {
} else if (!module.isPolyfill()) { } else if (!module.isPolyfill()) {
wrappedCode = this._addDependencyMap({ wrappedCode = this._addDependencyMap({
code: metadata.code, code: metadata.code,
dependencyPairs, dependencies,
name, name,
path: module.path, path: module.path,
}); });
@ -483,20 +491,17 @@ class DeltaTransformer extends EventEmitter {
*/ */
_addDependencyMap({ _addDependencyMap({
code, code,
dependencyPairs, dependencies,
name, name,
path, path,
}: { }: {
code: string, code: string,
dependencyPairs: Map<string, string>, dependencies: $ReadOnlyArray<string>,
name: string, name: string,
path: string, path: string,
}): string { }): string {
const moduleId = this._getModuleId(path); const moduleId = this._getModuleId(path);
const params = [ const params = [moduleId, dependencies.map(this._getModuleId)];
moduleId,
Array.from(dependencyPairs.values()).map(this._getModuleId),
];
// Add the module name as the last parameter (to make it easier to do // Add the module name as the last parameter (to make it easier to do
// requires by name when debugging). // requires by name when debugging).