packager Module.js: fix concurrency issues
Reviewed By: matryoshcow Differential Revision: D4159743 fbshipit-source-id: 41515f2a29344b648c4c52100056d2054e3edff7
This commit is contained in:
parent
70f40ce52b
commit
edf975d903
|
@ -115,10 +115,11 @@ class Transformer {
|
||||||
debug('transforming file', fileName);
|
debug('transforming file', fileName);
|
||||||
return this
|
return this
|
||||||
._transform(this._transformModulePath, fileName, code, options, transformCacheKey)
|
._transform(this._transformModulePath, fileName, code, options, transformCacheKey)
|
||||||
.then(stats => {
|
.then(data => {
|
||||||
Logger.log(stats.transformFileStartLogEntry);
|
Logger.log(data.transformFileStartLogEntry);
|
||||||
Logger.log(stats.transformFileEndLogEntry);
|
Logger.log(data.transformFileEndLogEntry);
|
||||||
debug('done transforming file', fileName);
|
debug('done transforming file', fileName);
|
||||||
|
return data.result;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.type === 'TimeoutError') {
|
if (error.type === 'TimeoutError') {
|
||||||
|
|
|
@ -87,6 +87,7 @@ function transformCode(transform, filename, sourceCode, options, transformCacheK
|
||||||
result,
|
result,
|
||||||
});
|
});
|
||||||
return callback(null, {
|
return callback(null, {
|
||||||
|
result,
|
||||||
transformFileStartLogEntry,
|
transformFileStartLogEntry,
|
||||||
transformFileEndLogEntry,
|
transformFileEndLogEntry,
|
||||||
});
|
});
|
||||||
|
|
|
@ -242,27 +242,9 @@ class Module {
|
||||||
return callback(null, {code: sourceCode});
|
return callback(null, {code: sourceCode});
|
||||||
}
|
}
|
||||||
const codePromise = transformCode(this, sourceCode, transformOptions);
|
const codePromise = transformCode(this, sourceCode, transformOptions);
|
||||||
return codePromise.then(() => {
|
return codePromise.then(freshResult => {
|
||||||
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;
|
|
||||||
}
|
|
||||||
callback(undefined, freshResult);
|
callback(undefined, freshResult);
|
||||||
}, callback);
|
});
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ describe('Module', () => {
|
||||||
transformCacheKey,
|
transformCacheKey,
|
||||||
result: transformResult,
|
result: transformResult,
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
return Promise.resolve(transformResult);
|
||||||
});
|
});
|
||||||
mockIndexFile(fileContents);
|
mockIndexFile(fileContents);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue