mirror of https://github.com/status-im/metro.git
Simplify AssetModule logic
Reviewed By: jeanlauliac Differential Revision: D6438714 fbshipit-source-id: ec1cfe0d439b1dcb07a0861872df5318f468396a
This commit is contained in:
parent
fbdbd7ae2c
commit
f3ea76a0b4
File diff suppressed because it is too large
Load Diff
|
@ -12,29 +12,22 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const AssetPaths = require('./lib/AssetPaths');
|
||||
const Module = require('./Module');
|
||||
|
||||
import type {CachedReadResult, ConstructorArgs, ReadResult} from './Module';
|
||||
|
||||
class AssetModule extends Module {
|
||||
resolution: mixed;
|
||||
_name: string;
|
||||
_type: string;
|
||||
_dependencies: Array<string>;
|
||||
|
||||
constructor(
|
||||
args: ConstructorArgs & {dependencies: Array<string>},
|
||||
platforms: Set<string>,
|
||||
) {
|
||||
constructor(args: ConstructorArgs & {dependencies: Array<string>}) {
|
||||
super(args);
|
||||
const {resolution, name, type} = AssetPaths.parse(this.path, platforms);
|
||||
this.resolution = resolution;
|
||||
this._name = name;
|
||||
this._type = type;
|
||||
this._dependencies = args.dependencies || [];
|
||||
}
|
||||
|
||||
getPackage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
isHaste() {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,10 +46,6 @@ class AssetModule extends Module {
|
|||
return Promise.resolve({dependencies: this._dependencies});
|
||||
}
|
||||
|
||||
getName() {
|
||||
return super.getName().replace(/\/[^\/]+$/, `/${this._name}.${this._type}`);
|
||||
}
|
||||
|
||||
hash() {
|
||||
return `AssetModule : ${this.path}`;
|
||||
}
|
||||
|
|
|
@ -110,22 +110,18 @@ class ModuleCache {
|
|||
* this is an incorrect OOP design in the first place: AssetModule, being
|
||||
* simpler than a normal Module, should not inherit the Module class.
|
||||
*/
|
||||
this._moduleCache[filePath] = new AssetModule(
|
||||
{
|
||||
dependencies: this._assetDependencies,
|
||||
this._moduleCache[filePath] = new AssetModule({
|
||||
depGraphHelpers: this._depGraphHelpers,
|
||||
dependencies: this._assetDependencies,
|
||||
file: filePath,
|
||||
getTransformCacheKey: this._getTransformCacheKey,
|
||||
globalTransformCache: null,
|
||||
globalTransformCache: this._globalTransformCache,
|
||||
localPath: toLocalPath(this._roots, filePath),
|
||||
moduleCache: this,
|
||||
reporter: this._reporter,
|
||||
resetCache: this._opts.resetCache,
|
||||
transformCode: this._transformCode,
|
||||
options: this._getModuleOptions(),
|
||||
},
|
||||
this._platforms,
|
||||
);
|
||||
reporter: this._reporter,
|
||||
transformCode: this._transformCode,
|
||||
});
|
||||
}
|
||||
return this._moduleCache[filePath];
|
||||
}
|
||||
|
|
|
@ -17,16 +17,7 @@ const AssetModule = require('../AssetModule');
|
|||
describe('AssetModule:', () => {
|
||||
const defaults = {file: '/arbitrary.png'};
|
||||
|
||||
it('has no dependencies by default', () => {
|
||||
return new AssetModule(defaults)
|
||||
.getDependencies()
|
||||
.then(deps => expect(deps).toEqual([]));
|
||||
});
|
||||
|
||||
it('can be parametrized with dependencies', () => {
|
||||
const dependencies = ['arbitrary', 'dependencies'];
|
||||
return new AssetModule({...defaults, dependencies})
|
||||
.getDependencies()
|
||||
.then(deps => expect(deps).toEqual(dependencies));
|
||||
it('is an asset', () => {
|
||||
expect(new AssetModule(defaults).isAsset()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue