packager Module.js: fix concurrency issues

Reviewed By: matryoshcow

Differential Revision: D4159743

fbshipit-source-id: 41515f2a29344b648c4c52100056d2054e3edff7
This commit is contained in:
Jean Lauliac 2016-11-10 05:43:37 -08:00 committed by Facebook Github Bot
parent 9773229227
commit 31c7108806
4 changed files with 8 additions and 24 deletions

View File

@ -115,10 +115,11 @@ class Transformer {
debug('transforming file', fileName);
return this
._transform(this._transformModulePath, fileName, code, options, transformCacheKey)
.then(stats => {
Logger.log(stats.transformFileStartLogEntry);
Logger.log(stats.transformFileEndLogEntry);
.then(data => {
Logger.log(data.transformFileStartLogEntry);
Logger.log(data.transformFileEndLogEntry);
debug('done transforming file', fileName);
return data.result;
})
.catch(error => {
if (error.type === 'TimeoutError') {

View File

@ -87,6 +87,7 @@ function transformCode(transform, filename, sourceCode, options, transformCacheK
result,
});
return callback(null, {
result,
transformFileStartLogEntry,
transformFileEndLogEntry,
});

View File

@ -242,27 +242,9 @@ class Module {
return callback(null, {code: sourceCode});
}
const codePromise = transformCode(this, sourceCode, transformOptions);
return codePromise.then(() => {
const transformCacheKey = this._transformCacheKey;
invariant(transformCacheKey != null, 'missing transform cache key');
const freshResult =
TransformCache.readSync({
filePath: this.path,
sourceCode,
transformCacheKey,
transformOptions,
cacheOptions: this._options,
});
if (freshResult == null) {
callback(new Error(
'Could not read fresh result from transform cache. This ' +
'means there is probably a bug in the worker code ' +
'that prevents it from writing to the cache correctly.',
));
return;
}
return codePromise.then(freshResult => {
callback(undefined, freshResult);
}, callback);
});
}, callback);
}

View File

@ -285,7 +285,7 @@ describe('Module', () => {
transformCacheKey,
result: transformResult,
});
return Promise.resolve();
return Promise.resolve(transformResult);
});
mockIndexFile(fileContents);
});