mirror of https://github.com/status-im/metro.git
packager: AssetModule: @flow
Reviewed By: cpojer Differential Revision: D4377137 fbshipit-source-id: 991619c0a42319a3bb4bf28dab4dd0fe1a474def
This commit is contained in:
parent
033e7a0d6f
commit
754e7015d9
|
@ -5,15 +5,26 @@
|
||||||
* This source code is licensed under the BSD-style license found in the
|
* This source code is licensed under the BSD-style license found in the
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Module = require('./Module');
|
const Module = require('./Module');
|
||||||
|
|
||||||
const getAssetDataFromName = require('./lib/getAssetDataFromName');
|
const getAssetDataFromName = require('./lib/getAssetDataFromName');
|
||||||
|
|
||||||
|
import type {ConstructorArgs, ReadResult} from './Module';
|
||||||
|
|
||||||
class AssetModule extends Module {
|
class AssetModule extends Module {
|
||||||
constructor(args, platforms) {
|
|
||||||
|
resolution: mixed;
|
||||||
|
_name: string;
|
||||||
|
_type: string;
|
||||||
|
_dependencies: Array<string>;
|
||||||
|
|
||||||
|
constructor(args: ConstructorArgs & {dependencies: Array<string>}, platforms: Set<string>) {
|
||||||
super(args);
|
super(args);
|
||||||
const { resolution, name, type } = getAssetDataFromName(this.path, platforms);
|
const { resolution, name, type } = getAssetDataFromName(this.path, platforms);
|
||||||
this.resolution = resolution;
|
this.resolution = resolution;
|
||||||
|
@ -30,7 +41,9 @@ class AssetModule extends Module {
|
||||||
return Promise.resolve(this._dependencies);
|
return Promise.resolve(this._dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
read() {
|
read(): Promise<ReadResult> {
|
||||||
|
/** $FlowFixMe: improper OOP design. AssetModule, being different from a
|
||||||
|
* normal Module, shouldn't inherit it in the first place. */
|
||||||
return Promise.resolve({});
|
return Promise.resolve({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import type Cache from './Cache';
|
||||||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||||
import type ModuleCache from './ModuleCache';
|
import type ModuleCache from './ModuleCache';
|
||||||
|
|
||||||
type ReadResult = {
|
export type ReadResult = {
|
||||||
code: string,
|
code: string,
|
||||||
dependencies?: ?Array<string>,
|
dependencies?: ?Array<string>,
|
||||||
dependencyOffsets?: ?Array<number>,
|
dependencyOffsets?: ?Array<number>,
|
||||||
|
|
|
@ -28,7 +28,7 @@ type GetClosestPackageFn = (filePath: string) => ?string;
|
||||||
|
|
||||||
class ModuleCache {
|
class ModuleCache {
|
||||||
|
|
||||||
_assetDependencies: mixed;
|
_assetDependencies: Array<string>;
|
||||||
_cache: Cache;
|
_cache: Cache;
|
||||||
_depGraphHelpers: DependencyGraphHelpers;
|
_depGraphHelpers: DependencyGraphHelpers;
|
||||||
_getClosestPackage: GetClosestPackageFn;
|
_getClosestPackage: GetClosestPackageFn;
|
||||||
|
@ -36,7 +36,7 @@ class ModuleCache {
|
||||||
_moduleOptions: ModuleOptions;
|
_moduleOptions: ModuleOptions;
|
||||||
_packageCache: {[filePath: string]: Package};
|
_packageCache: {[filePath: string]: Package};
|
||||||
_packageModuleMap: WeakMap<Module, string>;
|
_packageModuleMap: WeakMap<Module, string>;
|
||||||
_platforms: mixed;
|
_platforms: Set<string>;
|
||||||
_transformCacheKey: string;
|
_transformCacheKey: string;
|
||||||
_transformCode: TransformCode;
|
_transformCode: TransformCode;
|
||||||
_reporter: Reporter;
|
_reporter: Reporter;
|
||||||
|
@ -52,7 +52,7 @@ class ModuleCache {
|
||||||
transformCode,
|
transformCode,
|
||||||
reporter,
|
reporter,
|
||||||
}: {
|
}: {
|
||||||
assetDependencies: mixed,
|
assetDependencies: Array<string>,
|
||||||
cache: Cache,
|
cache: Cache,
|
||||||
depGraphHelpers: DependencyGraphHelpers,
|
depGraphHelpers: DependencyGraphHelpers,
|
||||||
getClosestPackage: GetClosestPackageFn,
|
getClosestPackage: GetClosestPackageFn,
|
||||||
|
@ -60,7 +60,7 @@ class ModuleCache {
|
||||||
transformCacheKey: string,
|
transformCacheKey: string,
|
||||||
transformCode: TransformCode,
|
transformCode: TransformCode,
|
||||||
reporter: Reporter,
|
reporter: Reporter,
|
||||||
}, platforms: mixed) {
|
}, platforms: Set<string>) {
|
||||||
this._assetDependencies = assetDependencies;
|
this._assetDependencies = assetDependencies;
|
||||||
this._getClosestPackage = getClosestPackage;
|
this._getClosestPackage = getClosestPackage;
|
||||||
this._cache = cache;
|
this._cache = cache;
|
||||||
|
@ -97,6 +97,9 @@ class ModuleCache {
|
||||||
|
|
||||||
getAssetModule(filePath: string) {
|
getAssetModule(filePath: string) {
|
||||||
if (!this._moduleCache[filePath]) {
|
if (!this._moduleCache[filePath]) {
|
||||||
|
/* $FlowFixMe: missing options. This is because 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({
|
this._moduleCache[filePath] = new AssetModule({
|
||||||
file: filePath,
|
file: filePath,
|
||||||
moduleCache: this,
|
moduleCache: this,
|
||||||
|
|
|
@ -68,7 +68,7 @@ class DependencyGraph {
|
||||||
useWatchman: boolean,
|
useWatchman: boolean,
|
||||||
watch: boolean,
|
watch: boolean,
|
||||||
|};
|
|};
|
||||||
_assetDependencies: mixed;
|
_assetDependencies: Array<string>;
|
||||||
_cache: Cache;
|
_cache: Cache;
|
||||||
_haste: JestHasteMap;
|
_haste: JestHasteMap;
|
||||||
_hasteFS: HasteFS;
|
_hasteFS: HasteFS;
|
||||||
|
@ -103,7 +103,7 @@ class DependencyGraph {
|
||||||
watch,
|
watch,
|
||||||
reporter,
|
reporter,
|
||||||
}: {
|
}: {
|
||||||
assetDependencies: mixed,
|
assetDependencies: Array<string>,
|
||||||
assetExts: Array<string>,
|
assetExts: Array<string>,
|
||||||
cache: Cache,
|
cache: Cache,
|
||||||
extensions?: ?Array<string>,
|
extensions?: ?Array<string>,
|
||||||
|
|
Loading…
Reference in New Issue