Handle transform problems correctly

Summary: This fixes a piece of promise code that didn’t handle nested rejections. This caused the packager not to recover from transform errors, as the server was waiting for an in-limbo promise forever.

Reviewed By: cpojer

Differential Revision: D4207138

fbshipit-source-id: 8e94ddebd033073f90b79b1c4820c09ac98a4932
This commit is contained in:
David Aurelio 2016-11-18 20:35:16 -08:00 committed by Facebook Github Bot
parent a477aec10d
commit a10eee4372
1 changed files with 18 additions and 13 deletions

View File

@ -223,19 +223,24 @@ class Module {
// never be transformed anyway. // never be transformed anyway.
invariant(_transformCode != null, 'missing code transform funtion'); invariant(_transformCode != null, 'missing code transform funtion');
invariant(_transformCacheKey != null, 'missing cache key'); invariant(_transformCacheKey != null, 'missing cache key');
this._readSourceCode().then(sourceCode => { this._readSourceCode()
return _transformCode(this, sourceCode, transformOptions) .then(sourceCode =>
.then(freshResult => { _transformCode(this, sourceCode, transformOptions)
TransformCache.writeSync({ .then(freshResult => {
filePath: this.path, TransformCache.writeSync({
sourceCode, filePath: this.path,
transformCacheKey: _transformCacheKey, sourceCode,
transformOptions, transformCacheKey: _transformCacheKey,
result: freshResult, transformOptions,
}); result: freshResult,
callback(undefined, freshResult); });
}); return freshResult;
}, callback); })
)
.then(
freshResult => process.nextTick(callback, null, freshResult),
error => process.nextTick(callback, error),
);
} }
/** /**