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() {
return Promise.resolve(false);
return false;
}
readCached(): CachedReadResult {

View File

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

View File

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

View File

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

View File

@ -107,7 +107,7 @@ describe('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', () => {
@ -120,8 +120,8 @@ describe('Module', () => {
it('does not transform the file in order to access the haste status', () => {
const transformCode =
jest.genMockFn().mockReturnValue(Promise.resolve());
return createModule({transformCode}).isHaste()
.then(() => expect(transformCode).not.toBeCalled());
createModule({transformCode}).isHaste();
expect(transformCode).not.toBeCalled();
});
});
@ -135,7 +135,7 @@ describe('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', () => {
@ -148,8 +148,8 @@ describe('Module', () => {
it('does not transform the file in order to access the haste status', () => {
const transformCode =
jest.genMockFn().mockReturnValue(Promise.resolve());
return createModule({transformCode}).isHaste()
.then(() => expect(transformCode).not.toBeCalled());
createModule({transformCode}).isHaste();
expect(transformCode).not.toBeCalled();
});
});
});