packager: AssetModule: @flow
Reviewed By: cpojer Differential Revision: D4377137 fbshipit-source-id: 991619c0a42319a3bb4bf28dab4dd0fe1a474def
This commit is contained in:
parent
588004b417
commit
26a8da898d
|
@ -5,15 +5,26 @@
|
|||
* 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
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Module = require('./Module');
|
||||
|
||||
const getAssetDataFromName = require('./lib/getAssetDataFromName');
|
||||
|
||||
import type {ConstructorArgs, ReadResult} from './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);
|
||||
const { resolution, name, type } = getAssetDataFromName(this.path, platforms);
|
||||
this.resolution = resolution;
|
||||
|
@ -30,7 +41,9 @@ class AssetModule extends Module {
|
|||
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({});
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import type Cache from './Cache';
|
|||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||
import type ModuleCache from './ModuleCache';
|
||||
|
||||
type ReadResult = {
|
||||
export type ReadResult = {
|
||||
code: string,
|
||||
dependencies?: ?Array<string>,
|
||||
dependencyOffsets?: ?Array<number>,
|
||||
|
|
|
@ -28,7 +28,7 @@ type GetClosestPackageFn = (filePath: string) => ?string;
|
|||
|
||||
class ModuleCache {
|
||||
|
||||
_assetDependencies: mixed;
|
||||
_assetDependencies: Array<string>;
|
||||
_cache: Cache;
|
||||
_depGraphHelpers: DependencyGraphHelpers;
|
||||
_getClosestPackage: GetClosestPackageFn;
|
||||
|
@ -36,7 +36,7 @@ class ModuleCache {
|
|||
_moduleOptions: ModuleOptions;
|
||||
_packageCache: {[filePath: string]: Package};
|
||||
_packageModuleMap: WeakMap<Module, string>;
|
||||
_platforms: mixed;
|
||||
_platforms: Set<string>;
|
||||
_transformCacheKey: string;
|
||||
_transformCode: TransformCode;
|
||||
_reporter: Reporter;
|
||||
|
@ -52,7 +52,7 @@ class ModuleCache {
|
|||
transformCode,
|
||||
reporter,
|
||||
}: {
|
||||
assetDependencies: mixed,
|
||||
assetDependencies: Array<string>,
|
||||
cache: Cache,
|
||||
depGraphHelpers: DependencyGraphHelpers,
|
||||
getClosestPackage: GetClosestPackageFn,
|
||||
|
@ -60,7 +60,7 @@ class ModuleCache {
|
|||
transformCacheKey: string,
|
||||
transformCode: TransformCode,
|
||||
reporter: Reporter,
|
||||
}, platforms: mixed) {
|
||||
}, platforms: Set<string>) {
|
||||
this._assetDependencies = assetDependencies;
|
||||
this._getClosestPackage = getClosestPackage;
|
||||
this._cache = cache;
|
||||
|
@ -97,6 +97,9 @@ class ModuleCache {
|
|||
|
||||
getAssetModule(filePath: string) {
|
||||
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({
|
||||
file: filePath,
|
||||
moduleCache: this,
|
||||
|
|
|
@ -68,7 +68,7 @@ class DependencyGraph {
|
|||
useWatchman: boolean,
|
||||
watch: boolean,
|
||||
|};
|
||||
_assetDependencies: mixed;
|
||||
_assetDependencies: Array<string>;
|
||||
_cache: Cache;
|
||||
_haste: JestHasteMap;
|
||||
_hasteFS: HasteFS;
|
||||
|
@ -103,7 +103,7 @@ class DependencyGraph {
|
|||
watch,
|
||||
reporter,
|
||||
}: {
|
||||
assetDependencies: mixed,
|
||||
assetDependencies: Array<string>,
|
||||
assetExts: Array<string>,
|
||||
cache: Cache,
|
||||
extensions?: ?Array<string>,
|
||||
|
|
Loading…
Reference in New Issue