in packages/metro/src/HmrServer.js [97:188]
async _registerEntryPoint(
client: Client,
requestUrl: string,
sendFn: (data: string) => void,
): Promise<void> {
requestUrl = this._config.server.rewriteRequestUrl(requestUrl);
const clientUrl = nullthrows(url.parse(requestUrl, true));
const options = parseOptionsFromUrl(
requestUrl,
new Set(this._config.resolver.platforms),
BYTECODE_VERSION,
);
const {entryFile, transformOptions, graphOptions} =
splitBundleOptions(options);
/**
* `entryFile` is relative to projectRoot, we need to use resolution function
* to find the appropriate file with supported extensions.
*/
const resolutionFn = await transformHelpers.getResolveDependencyFn(
this._bundler.getBundler(),
transformOptions.platform,
);
const resolvedEntryFilePath = resolutionFn(
(this._config.server.unstable_serverRoot ?? this._config.projectRoot) +
'/.',
entryFile,
);
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
shallow: graphOptions.shallow,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
});
const revPromise = this._bundler.getRevisionByGraphId(graphId);
if (!revPromise) {
send([sendFn], {
type: 'error',
body: formatBundlingError(new GraphNotFoundError(graphId)),
});
return;
}
const {graph, id} = await revPromise;
client.revisionIds.push(id);
let clientGroup = this._clientGroups.get(id);
if (clientGroup != null) {
clientGroup.clients.add(client);
} else {
// Prepare the clientUrl to be used as sourceUrl in HMR updates.
clientUrl.protocol = 'http';
const {
dev,
minify,
runModule,
bundleEntry: _bundleEntry,
...query
} = clientUrl.query || {};
clientUrl.query = {
...query,
dev: dev || 'true',
minify: minify || 'false',
modulesOnly: 'true',
runModule: runModule || 'false',
shallow: 'true',
};
clientUrl.search = '';
clientGroup = {
clients: new Set([client]),
clientUrl,
revisionId: id,
unlisten: (): void => unlisten(),
};
this._clientGroups.set(id, clientGroup);
const unlisten = this._bundler.getDeltaBundler().listen(
graph,
debounceAsyncQueue(
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
this._handleFileChange.bind(this, clientGroup, {
isInitialUpdate: false,
}),
50,
),
);
}
await this._handleFileChange(clientGroup, {isInitialUpdate: true});
send([sendFn], {type: 'bundle-registered'});
}