diff --git a/packages/bundlers/experimental/src/ExperimentalBundler.js b/packages/bundlers/experimental/src/ExperimentalBundler.js index 7a54af5f544..d01d7737c5a 100644 --- a/packages/bundlers/experimental/src/ExperimentalBundler.js +++ b/packages/bundlers/experimental/src/ExperimentalBundler.js @@ -283,7 +283,7 @@ function decorateLegacyGraph( function createIdealGraph( assetGraph: MutableBundleGraph, config: ResolvedBundlerConfig, - selectedEntries: Set, + entries: Map, ): IdealGraph { // Asset to the bundle and group it's an entry of let bundleRoots: Map = new Map(); @@ -312,31 +312,13 @@ function createIdealGraph( // Models bundleRoots and the assets that require it synchronously let reachableRoots: ContentGraph = new ContentGraph(); - // Step Create Entry Bundles: Find and create bundles for entries from assetGraph - let entries: Map = new Map(); let sharedToSourceBundleIds: Map> = new Map(); - assetGraph.traverse((node, context, actions) => { - if (node.type !== 'asset') { - return node; - } - if (!selectedEntries.has(node.value)) { - actions.skipChildren(); //this can be replaced with selected entries if we store dependency in target map and pass in with selected entries - return node; - } - - invariant( - context != null && context.type === 'dependency' && context.value.isEntry, - ); - entries.set(node.value, context.value); - actions.skipChildren(); - }); - let rootNodeId = nullthrows(asyncBundleRootGraph.addNode('root')); let bundleGraphRootNodeId = nullthrows(bundleGraph.addNode('root')); asyncBundleRootGraph.setRootNodeId(rootNodeId); bundleGraph.setRootNodeId(bundleGraphRootNodeId); - + // Step Create Entry Bundles for (let [asset, dependency] of entries) { let bundle = createBundle({ asset, @@ -377,7 +359,7 @@ function createIdealGraph( if ( context?.type === 'dependency' && context?.value.isEntry && - !selectedEntries.has(node.value) + !entries.has(node.value) ) { actions.skipChildren(); return node; @@ -1151,8 +1133,11 @@ function getReachableBundleRoots(asset, graph): Array { function getEntryByTarget( bundleGraph: MutableBundleGraph, -): DefaultMap> { - let targets: DefaultMap> = new DefaultMap(() => new Set()); +): DefaultMap> { + // Find entries from assetGraph per target + let targets: DefaultMap> = new DefaultMap( + () => new Map(), + ); bundleGraph.traverse({ enter(node, context, actions) { if (node.type !== 'asset') { @@ -1164,7 +1149,7 @@ function getEntryByTarget( context.value.isEntry && context.value.target != null, ); - targets.get(context.value.target.distDir).add(node.value); + targets.get(context.value.target.distDir).set(node.value, context.value); actions.skipChildren(); return node; }, diff --git a/packages/core/core/src/BundleGraph.js b/packages/core/core/src/BundleGraph.js index 07548f04c61..b0ab7d12864 100644 --- a/packages/core/core/src/BundleGraph.js +++ b/packages/core/core/src/BundleGraph.js @@ -1312,7 +1312,6 @@ export default class BundleGraph { nodeId, bundleGraphEdgeTypes.references, ), - //.reverse(), }); return [...referencedBundles];