mirror of
https://github.com/status-im/metro.git
synced 2025-02-10 18:17:12 +00:00
Remove AssetModule
Reviewed By: jeanlauliac Differential Revision: D7894081 fbshipit-source-id: ca1d91dbd45dd2862e2e72724756965a5a60fa60
This commit is contained in:
parent
e47fdf6f59
commit
058c2ac117
File diff suppressed because it is too large
Load Diff
@ -96,15 +96,11 @@ describe('traverseDependencies', function() {
|
|||||||
|
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
[...dependencies].map(async path => {
|
[...dependencies].map(async path => {
|
||||||
const dep = dgraph.getModuleForPath(path);
|
const transformResult = await transformFile(path);
|
||||||
const moduleDependencies = (await transformFile(path)).dependencies;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: dep.path,
|
path,
|
||||||
isAsset: dep.isAsset(),
|
dependencies: transformResult.dependencies,
|
||||||
isPolyfill: dep.isPolyfill(),
|
|
||||||
resolution: dep.resolution,
|
|
||||||
dependencies: moduleDependencies,
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -3613,13 +3609,11 @@ describe('traverseDependencies', function() {
|
|||||||
it('returns correctly a JS module', async () => {
|
it('returns correctly a JS module', async () => {
|
||||||
const module = dependencyGraph.getModuleForPath('/root/index.js');
|
const module = dependencyGraph.getModuleForPath('/root/index.js');
|
||||||
expect(module.path).toBe('/root/index.js');
|
expect(module.path).toBe('/root/index.js');
|
||||||
expect(module.isAsset()).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns correctly an asset module', async () => {
|
it('returns correctly an asset module', async () => {
|
||||||
const module = dependencyGraph.getModuleForPath('/root/imgs/a.png');
|
const module = dependencyGraph.getModuleForPath('/root/imgs/a.png');
|
||||||
expect(module.path).toBe('/root/imgs/a.png');
|
expect(module.path).toBe('/root/imgs/a.png');
|
||||||
expect(module.isAsset()).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,10 +33,6 @@ module.exports = class ModuleCache {
|
|||||||
this.packages = new Map();
|
this.packages = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
getAssetModule(path: string): Module {
|
|
||||||
return this.getModule(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
getModule(path: string): Module {
|
getModule(path: string): Module {
|
||||||
let m = this.modules.get(path);
|
let m = this.modules.get(path);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
|
@ -39,7 +39,6 @@ export type Package = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ModuleCache = {
|
export type ModuleCache = {
|
||||||
getAssetModule(path: Path): Module,
|
|
||||||
getModule(path: Path): Module,
|
getModule(path: Path): Module,
|
||||||
getPackage(path: Path): Package,
|
getPackage(path: Path): Package,
|
||||||
getPackageOf(path: Path): ?Package,
|
getPackageOf(path: Path): ?Package,
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
* @flow
|
|
||||||
* @format
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const Module = require('./Module');
|
|
||||||
|
|
||||||
class AssetModule extends Module {
|
|
||||||
getPackage() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
isAsset() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_readSourceCode() {
|
|
||||||
// We do not want to return the "source code" of assets, since it's going to
|
|
||||||
// be binary data and can potentially be very large. This source property
|
|
||||||
// is only used to generate the sourcemaps (since we include all the
|
|
||||||
// modules original sources in the sourcemaps).
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = AssetModule;
|
|
@ -213,10 +213,6 @@ class DependencyGraph extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getModuleForPath(entryFile: string): Module {
|
getModuleForPath(entryFile: string): Module {
|
||||||
if (this._helpers.isAssetFile(entryFile)) {
|
|
||||||
return this._moduleCache.getAssetModule(entryFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._moduleCache.getModule(entryFile);
|
return this._moduleCache.getModule(entryFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ export type ModuleishCache<TModule, TPackage> = {
|
|||||||
supportsNativePlatform?: boolean,
|
supportsNativePlatform?: boolean,
|
||||||
): TPackage,
|
): TPackage,
|
||||||
getModule(path: string): TModule,
|
getModule(path: string): TModule,
|
||||||
getAssetModule(path: string): TModule,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options<TModule, TPackage> = {|
|
type Options<TModule, TPackage> = {|
|
||||||
@ -166,7 +165,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|||||||
// not just an arbitrary item!
|
// not just an arbitrary item!
|
||||||
const arbitrary = getArrayLowestItem(resolution.filePaths);
|
const arbitrary = getArrayLowestItem(resolution.filePaths);
|
||||||
invariant(arbitrary != null, 'invalid asset resolution');
|
invariant(arbitrary != null, 'invalid asset resolution');
|
||||||
return this._options.moduleCache.getAssetModule(arbitrary);
|
return this._options.moduleCache.getModule(arbitrary);
|
||||||
case 'empty':
|
case 'empty':
|
||||||
const {moduleCache} = this._options;
|
const {moduleCache} = this._options;
|
||||||
const module = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
|
const module = moduleCache.getModule(ModuleResolver.EMPTY_MODULE);
|
||||||
|
@ -38,7 +38,6 @@ export type ModuleishCache<TModule, TPackage> = {
|
|||||||
supportsNativePlatform?: boolean,
|
supportsNativePlatform?: boolean,
|
||||||
): TPackage,
|
): TPackage,
|
||||||
getModule(path: string): TModule,
|
getModule(path: string): TModule,
|
||||||
getAssetModule(path: string): TModule,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options<TModule, TPackage> = {|
|
type Options<TModule, TPackage> = {|
|
||||||
|
@ -44,14 +44,6 @@ class Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invalidate() {}
|
invalidate() {}
|
||||||
|
|
||||||
isAsset() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
isPolyfill() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Module;
|
module.exports = Module;
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const AssetModule = require('./AssetModule');
|
|
||||||
const Module = require('./Module');
|
const Module = require('./Module');
|
||||||
const Package = require('./Package');
|
const Package = require('./Package');
|
||||||
|
|
||||||
@ -60,22 +59,6 @@ class ModuleCache {
|
|||||||
return this._moduleCache;
|
return this._moduleCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAssetModule(filePath: string) {
|
|
||||||
if (!this._moduleCache[filePath]) {
|
|
||||||
/* FixMe: AssetModule does not need all these 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,
|
|
||||||
localPath: toLocalPath(this._roots, filePath),
|
|
||||||
moduleCache: this,
|
|
||||||
options: this._getModuleOptions(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this._moduleCache[filePath];
|
|
||||||
}
|
|
||||||
|
|
||||||
getPackage(filePath: string): Package {
|
getPackage(filePath: string): Package {
|
||||||
if (!this._packageCache[filePath]) {
|
if (!this._packageCache[filePath]) {
|
||||||
this._packageCache[filePath] = new Package({
|
this._packageCache[filePath] = new Package({
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*
|
|
||||||
* @format
|
|
||||||
* @emails oncall+js_foundation
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const AssetModule = require('../AssetModule');
|
|
||||||
|
|
||||||
describe('AssetModule:', () => {
|
|
||||||
it('is an asset', () => {
|
|
||||||
expect(new AssetModule({file: '/arbitrary.png'}).isAsset()).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
@ -30,8 +30,5 @@ describe('Module', () => {
|
|||||||
it('Returns the correct values for many properties and methods', () => {
|
it('Returns the correct values for many properties and methods', () => {
|
||||||
expect(module.localPath).toBe('file.js');
|
expect(module.localPath).toBe('file.js');
|
||||||
expect(module.path).toBe('/root/to/file.js');
|
expect(module.path).toBe('/root/to/file.js');
|
||||||
|
|
||||||
expect(module.isAsset()).toBe(false);
|
|
||||||
expect(module.isPolyfill()).toBe(false);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user