mirror of https://github.com/status-im/metro.git
packager: attachHMRServer.js: Flow
Summary: The breakage fixed by changeset [1] could have been identified earlier if we had typing on `attachHMRServer`, so I spent some time on that. This has revealed in turn a few functions across the codebase that were incorrectly typed, and that are now fixed. [1] packager: attachHMRServer.js: fix callsite of Server#getModuleForPath() Reviewed By: davidaurelio Differential Revision: D4706241 fbshipit-source-id: fc4285245921ae45d5781a47d626fc0559dba998
This commit is contained in:
parent
d8bd24fc39
commit
737bf8cffe
|
@ -277,7 +277,7 @@ class Bundler {
|
|||
);
|
||||
}
|
||||
|
||||
hmrBundle(options: {platform: ?string}, host: string, port: number) {
|
||||
hmrBundle(options: {platform: ?string}, host: string, port: number): Promise<HMRBundle> {
|
||||
return this._bundle({
|
||||
...options,
|
||||
bundle: new HMRBundle({
|
||||
|
@ -492,7 +492,7 @@ class Bundler {
|
|||
minify?: boolean,
|
||||
hot?: boolean,
|
||||
generateSourceMaps?: boolean,
|
||||
}) {
|
||||
}): Promise<Array<Module>> {
|
||||
return this.getTransformOptions(
|
||||
entryFile,
|
||||
{
|
||||
|
|
|
@ -87,7 +87,7 @@ class Resolver {
|
|||
getShallowDependencies(
|
||||
entryFile: string,
|
||||
transformOptions: TransformOptions,
|
||||
): Array<string> {
|
||||
): Promise<Array<Module>> {
|
||||
return this._depGraph.getShallowDependencies(entryFile, transformOptions);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import type {Stats} from 'fs';
|
|||
import type {IncomingMessage, ServerResponse} from 'http';
|
||||
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||
import type Bundle from '../Bundler/Bundle';
|
||||
import type HMRBundle from '../Bundler/HMRBundle';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {GetTransformOptions} from '../Bundler';
|
||||
import type GlobalTransformCache from '../lib/GlobalTransformCache';
|
||||
|
@ -157,7 +158,7 @@ class Server {
|
|||
_assetServer: AssetServer;
|
||||
_bundler: Bundler;
|
||||
_debouncedFileChangeHandler: (filePath: string) => mixed;
|
||||
_hmrFileChangeListener: (type: string, filePath: string) => mixed;
|
||||
_hmrFileChangeListener: ?(type: string, filePath: string) => mixed;
|
||||
_reporter: Reporter;
|
||||
_symbolicateInWorker: Symbolicate;
|
||||
|
||||
|
@ -244,9 +245,7 @@ class Server {
|
|||
return this._bundler.end();
|
||||
}
|
||||
|
||||
setHMRFileChangeListener(
|
||||
listener: (type: string, filePath: string) => mixed,
|
||||
) {
|
||||
setHMRFileChangeListener(listener: ?(type: string, filePath: string) => mixed) {
|
||||
this._hmrFileChangeListener = listener;
|
||||
}
|
||||
|
||||
|
@ -276,7 +275,7 @@ class Server {
|
|||
return bundle;
|
||||
}
|
||||
|
||||
buildBundleFromUrl(reqUrl: string): Promise<mixed> {
|
||||
buildBundleFromUrl(reqUrl: string): Promise<Bundle> {
|
||||
const options = this._getOptionsFromUrl(reqUrl);
|
||||
return this.buildBundle(options);
|
||||
}
|
||||
|
@ -285,14 +284,14 @@ class Server {
|
|||
options: {platform: ?string},
|
||||
host: string,
|
||||
port: number,
|
||||
): Promise<string> {
|
||||
): Promise<HMRBundle> {
|
||||
return this._bundler.hmrBundle(options, host, port);
|
||||
}
|
||||
|
||||
getShallowDependencies(options: {
|
||||
entryFile: string,
|
||||
platform?: string,
|
||||
}): Promise<mixed> {
|
||||
}): Promise<Array<Module>> {
|
||||
return Promise.resolve().then(() => {
|
||||
if (!options.platform) {
|
||||
options.platform = getPlatformExtension(options.entryFile);
|
||||
|
@ -335,10 +334,11 @@ class Server {
|
|||
// If Hot Loading is enabled avoid rebuilding bundles and sending live
|
||||
// updates. Instead, send the HMR updates right away and clear the bundles
|
||||
// cache so that if the user reloads we send them a fresh bundle
|
||||
if (this._hmrFileChangeListener) {
|
||||
const {_hmrFileChangeListener} = this;
|
||||
if (_hmrFileChangeListener) {
|
||||
// Clear cached bundles in case user reloads
|
||||
this._clearBundles();
|
||||
this._hmrFileChangeListener(type, filePath);
|
||||
_hmrFileChangeListener(type, filePath);
|
||||
return;
|
||||
} else if (type !== 'change' && filePath.indexOf(NODE_MODULES) !== -1) {
|
||||
// node module resolution can be affected by added or removed files
|
||||
|
|
|
@ -173,7 +173,10 @@ class DependencyGraph extends EventEmitter {
|
|||
* Returns a promise with the direct dependencies the module associated to
|
||||
* the given entryPath has.
|
||||
*/
|
||||
getShallowDependencies(entryPath: string, transformOptions: TransformOptions) {
|
||||
getShallowDependencies(
|
||||
entryPath: string,
|
||||
transformOptions: TransformOptions,
|
||||
): Promise<Array<Module>> {
|
||||
return this._moduleCache
|
||||
.getModule(entryPath)
|
||||
.getDependencies(transformOptions);
|
||||
|
|
Loading…
Reference in New Issue