packager: Module: tweak isHaste return type

Reviewed By: cpojer

Differential Revision: D5036181

fbshipit-source-id: 6042beb44bc67e64dd57c8dd6043f8dd690e9382
This commit is contained in:
Jean Lauliac 2017-05-11 04:46:49 -07:00 committed by Facebook Github Bot
parent 695dbbb5c7
commit d7fee2396c
5 changed files with 26 additions and 24 deletions

View File

@ -37,7 +37,7 @@ class AssetModule extends Module {
} }
isHaste() { isHaste() {
return Promise.resolve(false); return false;
} }
readCached(): CachedReadResult { readCached(): CachedReadResult {

View File

@ -123,36 +123,38 @@ class HasteMap extends EventEmitter {
_processHasteModule(file, previousName) { _processHasteModule(file, previousName) {
const module = this._moduleCache.getModule(file); const module = this._moduleCache.getModule(file);
return module.isHaste().then( return Promise.resolve().then(() => {
isHaste => isHaste && module.getName() const isHaste = module.isHaste();
return isHaste && module.getName()
.then(name => { .then(name => {
const result = this._updateHasteMap(name, module); const result = this._updateHasteMap(name, module);
if (previousName && name !== previousName) { if (previousName && name !== previousName) {
this.emit('change'); this.emit('change');
} }
return result; return result;
}) });
); });
} }
_processHastePackage(file, previousName) { _processHastePackage(file, previousName) {
const p = this._moduleCache.getPackage(file); const p = this._moduleCache.getPackage(file);
return p.isHaste() return Promise.resolve().then(() => {
.then(isHaste => isHaste && p.getName() const isHaste = p.isHaste();
return isHaste && p.getName()
.then(name => { .then(name => {
const result = this._updateHasteMap(name, p); const result = this._updateHasteMap(name, p);
if (previousName && name !== previousName) { if (previousName && name !== previousName) {
this.emit('change'); this.emit('change');
} }
return result; return result;
})) });
.catch(e => { }).catch(e => {
if (e instanceof SyntaxError) { if (e instanceof SyntaxError) {
// Malformed package.json. // Malformed package.json.
return; return;
} }
throw e; throw e;
}); });
} }
_updateHasteMap(name, mod) { _updateHasteMap(name, mod) {

View File

@ -133,8 +133,8 @@ class Module {
this._readResultsByOptionsKey = new Map(); this._readResultsByOptionsKey = new Map();
} }
isHaste(): Promise<boolean> { isHaste(): boolean {
return Promise.resolve().then(() => this._getHasteName() != null); return this._getHasteName() != null;
} }
getCode(transformOptions: WorkerOptions) { getCode(transformOptions: WorkerOptions) {

View File

@ -32,7 +32,7 @@ class Polyfill extends Module {
} }
isHaste() { isHaste() {
return Promise.resolve(false); return false;
} }
getName() { getName() {

View File

@ -107,7 +107,7 @@ describe('Module', () => {
); );
it('identifies the module as haste module', () => it('identifies the module as haste module', () =>
module.isHaste().then(isHaste => expect(isHaste).toBe(true)) expect(module.isHaste()).toBe(true)
); );
it('does not transform the file in order to access the name', () => { it('does not transform the file in order to access the name', () => {
@ -120,8 +120,8 @@ describe('Module', () => {
it('does not transform the file in order to access the haste status', () => { it('does not transform the file in order to access the haste status', () => {
const transformCode = const transformCode =
jest.genMockFn().mockReturnValue(Promise.resolve()); jest.genMockFn().mockReturnValue(Promise.resolve());
return createModule({transformCode}).isHaste() createModule({transformCode}).isHaste();
.then(() => expect(transformCode).not.toBeCalled()); expect(transformCode).not.toBeCalled();
}); });
}); });
@ -135,7 +135,7 @@ describe('Module', () => {
); );
it('does not identify the module as haste module', () => it('does not identify the module as haste module', () =>
module.isHaste().then(isHaste => expect(isHaste).toBe(false)) expect(module.isHaste()).toBe(false)
); );
it('does not transform the file in order to access the name', () => { it('does not transform the file in order to access the name', () => {
@ -148,8 +148,8 @@ describe('Module', () => {
it('does not transform the file in order to access the haste status', () => { it('does not transform the file in order to access the haste status', () => {
const transformCode = const transformCode =
jest.genMockFn().mockReturnValue(Promise.resolve()); jest.genMockFn().mockReturnValue(Promise.resolve());
return createModule({transformCode}).isHaste() createModule({transformCode}).isHaste();
.then(() => expect(transformCode).not.toBeCalled()); expect(transformCode).not.toBeCalled();
}); });
}); });
}); });