packager Module.js: fix concurrency issues

Reviewed By: matryoshcow

Differential Revision: D4159743

fbshipit-source-id: 41515f2a29344b648c4c52100056d2054e3edff7
This commit is contained in:
Jean Lauliac authored and Facebook Github Bot committed 2016-11-10 05:58:41 -08:00
1 parent 70f40ce52b
commit edf975d903
4 files changed
+8 -24

No files matched your search

+4 -3
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') {
@@ -87,6 +87,7 @@ function transformCode(transform, filename, sourceCode, options, transformCacheK
result,
});
return callback(null, {
result,
transformFileStartLogEntry,
transformFileEndLogEntry,
});
+2 -20
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);
}
@@ -285,7 +285,7 @@ describe('Module', () => {
transformCacheKey,
result: transformResult,
});
return Promise.resolve();
return Promise.resolve(transformResult);
});
mockIndexFile(fileContents);
});