mirror of https://github.com/status-im/metro.git
packager: Module: tweak isHaste return type
Reviewed By: cpojer Differential Revision: D5036181 fbshipit-source-id: 6042beb44bc67e64dd57c8dd6043f8dd690e9382
This commit is contained in:
parent
695dbbb5c7
commit
d7fee2396c
|
@ -37,7 +37,7 @@ class AssetModule extends Module {
|
|||
}
|
||||
|
||||
isHaste() {
|
||||
return Promise.resolve(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
readCached(): CachedReadResult {
|
||||
|
|
|
@ -123,30 +123,32 @@ 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 => {
|
||||
});
|
||||
}).catch(e => {
|
||||
if (e instanceof SyntaxError) {
|
||||
// Malformed package.json.
|
||||
return;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -32,7 +32,7 @@ class Polyfill extends Module {
|
|||
}
|
||||
|
||||
isHaste() {
|
||||
return Promise.resolve(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
getName() {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue