diff --git a/packages/core/core/src/public/Bundle.js b/packages/core/core/src/public/Bundle.js index 1c9ae0a2bc7..3581678d33d 100644 --- a/packages/core/core/src/public/Bundle.js +++ b/packages/core/core/src/public/Bundle.js @@ -314,6 +314,12 @@ export class PackagedBundle extends NamedBundle implements IPackagedBundle { ); } + get type(): string { + // The bundle type may be overridden in the packager. + // However, inline bundles will not have a bundleInfo here since they are not written to the filesystem. + return this.#bundleInfo ? this.#bundleInfo.type : this.#bundle.type; + } + get stats(): Stats { return nullthrows(this.#bundleInfo).stats; } diff --git a/packages/core/core/src/requests/WriteBundleRequest.js b/packages/core/core/src/requests/WriteBundleRequest.js index 07fdc488a15..2a2b77bb7ce 100644 --- a/packages/core/core/src/requests/WriteBundleRequest.js +++ b/packages/core/core/src/requests/WriteBundleRequest.js @@ -181,6 +181,7 @@ async function run({input, options, api}: RunInput) { let res = { filePath, + type: info.type, stats: { size, time: info.time ?? 0, diff --git a/packages/core/core/src/requests/WriteBundlesRequest.js b/packages/core/core/src/requests/WriteBundlesRequest.js index e33974e8b93..f93d3df323b 100644 --- a/packages/core/core/src/requests/WriteBundlesRequest.js +++ b/packages/core/core/src/requests/WriteBundlesRequest.js @@ -71,6 +71,7 @@ async function run({input, api, farm, options}: RunInput) { let name = nullthrows(bundle.name).replace(bundle.hashReference, hash); res.set(bundle.id, { filePath: joinProjectPath(bundle.target.distDir, name), + type: bundle.type, // FIXME: this is wrong if the packager changes the type... stats: { time: 0, size: 0, diff --git a/packages/core/core/src/types.js b/packages/core/core/src/types.js index d3a02f1058c..82fa1b3a01d 100644 --- a/packages/core/core/src/types.js +++ b/packages/core/core/src/types.js @@ -500,6 +500,7 @@ export type BundleGroupNode = {| export type PackagedBundleInfo = {| filePath: ProjectPath, + type: string, stats: Stats, |}; diff --git a/packages/reporters/dev-server/src/Server.js b/packages/reporters/dev-server/src/Server.js index 6dfde0aef27..e09fcd3a6b5 100644 --- a/packages/reporters/dev-server/src/Server.js +++ b/packages/reporters/dev-server/src/Server.js @@ -161,16 +161,16 @@ export default class Server { sendIndex(req: Request, res: Response) { if (this.bundleGraph) { // If the main asset is an HTML file, serve it - let htmlBundleFilePaths = []; - this.bundleGraph.traverseBundles(bundle => { - if (bundle.type === 'html' && bundle.bundleBehavior !== 'inline') { - htmlBundleFilePaths.push(bundle.filePath); - } - }); - - htmlBundleFilePaths = htmlBundleFilePaths.map(p => { - return `/${relativePath(this.options.distDir, p, false)}`; - }); + let htmlBundleFilePaths = this.bundleGraph + .getBundles() + .filter(bundle => bundle.type === 'html') + .map(bundle => { + return `/${relativePath( + this.options.distDir, + bundle.filePath, + false, + )}`; + }); let indexFilePath = null; if (htmlBundleFilePaths.length === 1) {