From d3b7342985f41bdd97a484de1d8725aa51cfda96 Mon Sep 17 00:00:00 2001 From: Monica Date: Wed, 22 May 2024 16:33:38 +1000 Subject: [PATCH] Pass through includeInline (#9730) --- packages/core/core/src/BundleGraph.js | 2 +- .../integration-tests/test/BundleGraph.js | 66 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/packages/core/core/src/BundleGraph.js b/packages/core/core/src/BundleGraph.js index 88cbfb9f646..5b9972083d2 100644 --- a/packages/core/core/src/BundleGraph.js +++ b/packages/core/core/src/BundleGraph.js @@ -1600,7 +1600,7 @@ export default class BundleGraph { } for (let referencedBundle of this.getReferencedBundles(bundle, { - includeInline: true, + includeInline: opts?.includeInline, })) { bundles.add(referencedBundle); } diff --git a/packages/core/integration-tests/test/BundleGraph.js b/packages/core/integration-tests/test/BundleGraph.js index 51e9826af6e..c8f72037ba6 100644 --- a/packages/core/integration-tests/test/BundleGraph.js +++ b/packages/core/integration-tests/test/BundleGraph.js @@ -2,7 +2,8 @@ import assert from 'assert'; import path from 'path'; -import {bundle} from '@parcel/test-utils'; +import {bundle, fsFixture, overlayFS} from '@parcel/test-utils'; +import type {BundleGraph, BundleGroup, PackagedBundle} from '@parcel/types'; describe('BundleGraph', () => { it('can traverse assets across bundles and contexts', async () => { @@ -77,4 +78,67 @@ describe('BundleGraph', () => { }, ]); }); + + describe('getBundlesInBundleGroup', () => { + let bundleGraph: BundleGraph; + let bundleGroup: BundleGroup; + let dir = path.join(__dirname, 'get-bundles-in-bundle-group'); + + before(async () => { + await overlayFS.mkdirp(dir); + + await fsFixture(overlayFS, dir)` + logo.svg: + + + index.jsx: + import logo from 'data-url:./logo.svg'; + + yarn.lock: {} + `; + + bundleGraph = await bundle(path.join(dir, 'index.jsx'), { + inputFS: overlayFS, + }); + + bundleGroup = bundleGraph.getBundleGroupsContainingBundle( + bundleGraph.getBundles({includeInline: true})[0], + )[0]; + }); + + after(async () => { + await overlayFS.rimraf(dir); + }); + + it('does not return inlineAssets by default', () => { + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup); + + assert.deepEqual( + bundles.map(b => b.bundleBehavior), + [null], + ); + }); + + it('does not return inlineAssets when requested', () => { + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup, { + includeInline: false, + }); + + assert.deepEqual( + bundles.map(b => b.bundleBehavior), + [null], + ); + }); + + it('returns inlineAssets when requested', () => { + const bundles = bundleGraph.getBundlesInBundleGroup(bundleGroup, { + includeInline: true, + }); + + assert.deepEqual( + bundles.map(b => b.bundleBehavior), + [null, 'inline'], + ); + }); + }); });