mirror of https://github.com/status-im/metro.git
packager Module.js: fix concurrency issues
Reviewed By: matryoshcow Differential Revision: D4159743 fbshipit-source-id: 41515f2a29344b648c4c52100056d2054e3edff7
This commit is contained in:
parent
9773229227
commit
31c7108806
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue