mirror of
https://github.com/status-im/metro.git
synced 2025-02-08 01:03:28 +00:00
Fix a bunch of flow annotations
Reviewed By: jeanlauliac Differential Revision: D4611846 fbshipit-source-id: c2fe468e34a3b1eba7fcd2596020aad136285363
This commit is contained in:
parent
33c594508e
commit
a26d3c43ef
@ -116,9 +116,9 @@ class Bundle extends BundleBase {
|
||||
|
||||
finalize(options: FinalizeOptions) {
|
||||
options = options || {};
|
||||
if (options.runMainModule) {
|
||||
if (options.runModule) {
|
||||
/* $FlowFixMe: this is unsound, as nothing enforces runBeforeMainModule
|
||||
* to be available if `runMainModule` is true. Refactor. */
|
||||
* to be available if `runModule` is true. Refactor. */
|
||||
options.runBeforeMainModule.forEach(this._addRequireCall, this);
|
||||
/* $FlowFixMe: this is unsound, as nothing enforces the module ID to have
|
||||
* been set beforehand. */
|
||||
@ -143,7 +143,7 @@ class Bundle extends BundleBase {
|
||||
this._numRequireCalls += 1;
|
||||
}
|
||||
|
||||
_getInlineSourceMap(dev) {
|
||||
_getInlineSourceMap(dev: ?boolean) {
|
||||
if (this._inlineSourceMap == null) {
|
||||
const sourceMap = this.getSourceMapString({excludeSource: true, dev});
|
||||
/*eslint-env node*/
|
||||
@ -206,7 +206,7 @@ class Bundle extends BundleBase {
|
||||
* that makes use of of the `sections` field to combine sourcemaps by adding
|
||||
* an offset. This is supported only by Chrome for now.
|
||||
*/
|
||||
_getCombinedSourceMaps(options): CombinedSourceMap {
|
||||
_getCombinedSourceMaps(options: {excludeSource?: boolean}): CombinedSourceMap {
|
||||
const result = {
|
||||
version: 3,
|
||||
file: this._getSourceMapFile(),
|
||||
|
@ -15,7 +15,7 @@ const ModuleTransport = require('../lib/ModuleTransport');
|
||||
export type FinalizeOptions = {
|
||||
allowUpdates?: boolean,
|
||||
runBeforeMainModule?: Array<string>,
|
||||
runMainModule?: boolean,
|
||||
runModule?: boolean,
|
||||
};
|
||||
|
||||
export type GetSourceOptions = {
|
||||
|
@ -95,7 +95,7 @@ describe('Bundle', () => {
|
||||
bundle.setMainModuleId('foo');
|
||||
bundle.finalize({
|
||||
runBeforeMainModule: ['bar'],
|
||||
runMainModule: true,
|
||||
runModule: true,
|
||||
});
|
||||
expect(bundle.getSource({dev: true})).toBe([
|
||||
'transformed foo;',
|
||||
@ -172,7 +172,7 @@ describe('Bundle', () => {
|
||||
otherBundle.setMainModuleId('foo');
|
||||
otherBundle.finalize({
|
||||
runBeforeMainModule: ['InitializeCore'],
|
||||
runMainModule: true,
|
||||
runModule: true,
|
||||
});
|
||||
|
||||
const sourceMap = otherBundle.getSourceMap({dev: true});
|
||||
|
@ -173,7 +173,7 @@ describe('Bundler', function() {
|
||||
expect(ithAddedModule(3)).toEqual('/root/file.json');
|
||||
|
||||
expect(bundle.finalize.mock.calls[0]).toEqual([{
|
||||
runMainModule: true,
|
||||
runModule: true,
|
||||
runBeforeMainModule: [],
|
||||
allowUpdates: false,
|
||||
}]);
|
||||
|
@ -47,6 +47,19 @@ export type GetTransformOptions = (
|
||||
getDependencies: string => Promise<Array<string>>,
|
||||
) => {} | Promise<{}>;
|
||||
|
||||
type Asset = {
|
||||
__packager_asset: boolean,
|
||||
fileSystemLocation: string,
|
||||
httpServerLocation: string,
|
||||
width: ?number,
|
||||
height: ?number,
|
||||
scales: number,
|
||||
files: Array<string>,
|
||||
hash: string,
|
||||
name: string,
|
||||
type: string,
|
||||
};
|
||||
|
||||
const sizeOf = denodeify(imageSize);
|
||||
|
||||
const noop = () => {};
|
||||
@ -205,7 +218,7 @@ class Bundler {
|
||||
});
|
||||
}
|
||||
|
||||
_sourceHMRURL(platform, hmrpath) {
|
||||
_sourceHMRURL(platform: ?string, hmrpath: string) {
|
||||
return this._hmrURL(
|
||||
'',
|
||||
platform,
|
||||
@ -214,7 +227,7 @@ class Bundler {
|
||||
);
|
||||
}
|
||||
|
||||
_sourceMappingHMRURL(platform, hmrpath) {
|
||||
_sourceMappingHMRURL(platform: ?string, hmrpath: string) {
|
||||
// Chrome expects `sourceURL` when eval'ing code
|
||||
return this._hmrURL(
|
||||
'\/\/# sourceURL=',
|
||||
@ -224,7 +237,7 @@ class Bundler {
|
||||
);
|
||||
}
|
||||
|
||||
_hmrURL(prefix, platform, extensionOverride, filePath) {
|
||||
_hmrURL(prefix: string, platform: ?string, extensionOverride: string, filePath: string) {
|
||||
const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root));
|
||||
|
||||
if (!matchingRoot) {
|
||||
@ -245,7 +258,7 @@ class Bundler {
|
||||
return (
|
||||
prefix + resource +
|
||||
'.' + extensionOverride + '?' +
|
||||
'platform=' + platform + '&runModule=false&entryModuleOnly=true&hot=true'
|
||||
'platform=' + (platform || '') + '&runModule=false&entryModuleOnly=true&hot=true'
|
||||
);
|
||||
}
|
||||
|
||||
@ -265,30 +278,47 @@ class Bundler {
|
||||
}
|
||||
|
||||
_bundle({
|
||||
bundle,
|
||||
entryFile,
|
||||
runModule: runMainModule,
|
||||
runBeforeMainModule,
|
||||
dev,
|
||||
minify,
|
||||
platform,
|
||||
moduleSystemDeps = [],
|
||||
hot,
|
||||
unbundle,
|
||||
entryModuleOnly,
|
||||
resolutionResponse,
|
||||
isolateModuleIDs,
|
||||
generateSourceMaps,
|
||||
assetPlugins,
|
||||
bundle,
|
||||
dev,
|
||||
entryFile,
|
||||
entryModuleOnly,
|
||||
generateSourceMaps,
|
||||
hot,
|
||||
isolateModuleIDs,
|
||||
minify,
|
||||
moduleSystemDeps = [],
|
||||
onProgress,
|
||||
platform,
|
||||
resolutionResponse,
|
||||
runBeforeMainModule,
|
||||
runModule,
|
||||
unbundle,
|
||||
}: {
|
||||
assetPlugins?: Array<string>,
|
||||
bundle: Bundle,
|
||||
dev: boolean,
|
||||
entryFile?: string,
|
||||
entryModuleOnly?: boolean,
|
||||
generateSourceMaps?: boolean,
|
||||
hot?: boolean,
|
||||
isolateModuleIDs?: boolean,
|
||||
minify?: boolean,
|
||||
moduleSystemDeps?: Array<Module>,
|
||||
onProgress?: () => void,
|
||||
platform?: ?string,
|
||||
resolutionResponse?: ResolutionResponse,
|
||||
runBeforeMainModule?: boolean,
|
||||
runModule?: boolean,
|
||||
unbundle?: boolean,
|
||||
}) {
|
||||
const onResolutionResponse = (response: ResolutionResponse) => {
|
||||
/* $FlowFixMe: looks like ResolutionResponse is monkey-patched
|
||||
* with `getModuleId`. */
|
||||
bundle.setMainModuleId(response.getModuleId(getMainModule(response)));
|
||||
if (entryModuleOnly) {
|
||||
if (entryModuleOnly && entryFile) {
|
||||
response.dependencies = response.dependencies.filter(module =>
|
||||
module.path.endsWith(entryFile)
|
||||
module.path.endsWith(entryFile || '')
|
||||
);
|
||||
} else {
|
||||
response.dependencies = moduleSystemDeps.concat(response.dependencies);
|
||||
@ -313,7 +343,7 @@ class Bundler {
|
||||
: undefined;
|
||||
|
||||
finalBundle.finalize({
|
||||
runMainModule,
|
||||
runModule,
|
||||
runBeforeMainModule: runBeforeMainModuleIds,
|
||||
allowUpdates: this._opts.allowBundleUpdates,
|
||||
});
|
||||
@ -608,7 +638,11 @@ class Bundler {
|
||||
});
|
||||
}
|
||||
|
||||
_generateAssetObjAndCode(module, assetPlugins, platform: ?string = null) {
|
||||
_generateAssetObjAndCode(
|
||||
module: Module,
|
||||
assetPlugins: Array<string>,
|
||||
platform: ?string = null,
|
||||
) {
|
||||
const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
|
||||
var assetUrlPath = joinPath('/assets', pathDirname(relPath));
|
||||
|
||||
@ -659,7 +693,10 @@ class Bundler {
|
||||
});
|
||||
}
|
||||
|
||||
_applyAssetPlugins(assetPlugins, asset) {
|
||||
_applyAssetPlugins(
|
||||
assetPlugins: Array<string>,
|
||||
asset: Asset,
|
||||
) {
|
||||
if (!assetPlugins.length) {
|
||||
return asset;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class B64Builder {
|
||||
return this.buffer.toString('ascii', 0, this.pos);
|
||||
}
|
||||
|
||||
_writeByte(byte) {
|
||||
_writeByte(byte: number) {
|
||||
if (this.pos === this.buffer.length) {
|
||||
this._realloc();
|
||||
}
|
||||
|
@ -48,6 +48,12 @@ module.exports = class HasteFS {
|
||||
return Array.from(this.files.keys());
|
||||
}
|
||||
|
||||
matchFiles() {
|
||||
throw new Error(
|
||||
'HasteFS.matchFiles is not implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
matches(directory: string, pattern: RegExp) {
|
||||
const entries = this.directoryEntries.get(directory);
|
||||
return entries ? entries.filter(pattern.test, pattern) : [];
|
||||
|
@ -78,7 +78,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
||||
dirExists: filePath => hasteFS.dirExists(filePath),
|
||||
entryPath: '',
|
||||
extraNodeModules,
|
||||
/* $FlowFixMe: object is missing matchFiles method */
|
||||
hasteFS,
|
||||
hasteMap,
|
||||
helpers,
|
||||
|
@ -82,7 +82,7 @@ class ResolutionRequest {
|
||||
this._resetResolutionCache();
|
||||
}
|
||||
|
||||
_tryResolve(action, secondaryAction) {
|
||||
_tryResolve(action: () => Promise<string>, secondaryAction: () => ?Promise<string>) {
|
||||
return action().catch((error) => {
|
||||
if (error.type !== 'UnableToResolveError') {
|
||||
throw error;
|
||||
@ -219,7 +219,7 @@ class ResolutionRequest {
|
||||
});
|
||||
}
|
||||
|
||||
_resolveHasteDependency(fromModule, toModuleName) {
|
||||
_resolveHasteDependency(fromModule: Module, toModuleName: string) {
|
||||
toModuleName = normalizePath(toModuleName);
|
||||
|
||||
let p = fromModule.getPackage();
|
||||
@ -267,7 +267,7 @@ class ResolutionRequest {
|
||||
});
|
||||
}
|
||||
|
||||
_redirectRequire(fromModule, modulePath) {
|
||||
_redirectRequire(fromModule: Module, modulePath: string) {
|
||||
return Promise.resolve(fromModule.getPackage()).then(p => {
|
||||
if (p) {
|
||||
return p.redirectRequire(modulePath);
|
||||
@ -276,7 +276,7 @@ class ResolutionRequest {
|
||||
});
|
||||
}
|
||||
|
||||
_resolveFileOrDir(fromModule, toModuleName) {
|
||||
_resolveFileOrDir(fromModule: Module, toModuleName: string) {
|
||||
const potentialModulePath = isAbsolutePath(toModuleName) ?
|
||||
toModuleName :
|
||||
path.join(path.dirname(fromModule.path), toModuleName);
|
||||
@ -299,7 +299,7 @@ class ResolutionRequest {
|
||||
);
|
||||
}
|
||||
|
||||
_resolveNodeDependency(fromModule, toModuleName) {
|
||||
_resolveNodeDependency(fromModule: Module, toModuleName: string) {
|
||||
if (isRelativeImport(toModuleName) || isAbsolutePath(toModuleName)) {
|
||||
return this._resolveFileOrDir(fromModule, toModuleName);
|
||||
} else {
|
||||
@ -379,7 +379,7 @@ class ResolutionRequest {
|
||||
}
|
||||
}
|
||||
|
||||
_loadAsFile(potentialModulePath, fromModule, toModule) {
|
||||
_loadAsFile(potentialModulePath: string, fromModule: Module, toModule: string) {
|
||||
return Promise.resolve().then(() => {
|
||||
if (this._helpers.isAssetFile(potentialModulePath)) {
|
||||
let dirname = path.dirname(potentialModulePath);
|
||||
@ -439,7 +439,7 @@ class ResolutionRequest {
|
||||
});
|
||||
}
|
||||
|
||||
_loadAsDir(potentialDirPath, fromModule, toModule) {
|
||||
_loadAsDir(potentialDirPath: string, fromModule: Module, toModule: string) {
|
||||
return Promise.resolve().then(() => {
|
||||
if (!this._dirExists(potentialDirPath)) {
|
||||
throw new UnableToResolveError(
|
||||
|
@ -264,7 +264,7 @@ class DependencyGraph {
|
||||
return platform;
|
||||
}
|
||||
|
||||
_getAbsolutePath(filePath) {
|
||||
_getAbsolutePath(filePath: string) {
|
||||
if (isAbsolutePath(filePath)) {
|
||||
return path.resolve(filePath);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user