Skip to content

Commit

Permalink
Do not create circular bundle references in library bundler (#9603)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Mar 30, 2024
1 parent 84fc9a9 commit 58b91e5
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/bundlers/library/src/LibraryBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default (new Bundler({
}

// Reference the parent bundle so we create dependencies between them.
if (parentBundle) {
if (parentBundle && parentBundle !== bundle) {
bundleGraph.createBundleReference(parentBundle, bundle);
bundleGraph.createAssetReference(dependency, asset, bundle);
}
Expand Down
87 changes: 87 additions & 0 deletions packages/core/integration-tests/test/library-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,91 @@ describe('library bundler', function () {

assert.equal(res2.default, 'shared-b');
});

it('should not share bundles with circular references in different targets', async function () {
await fsFixture(overlayFS, dir)`
yarn.lock:
.parcelrc:
{
"extends": "@parcel/config-default",
"bundler": "@parcel/bundler-library"
}
packages/a/package.json:
{
"engines": { "node": "*" },
"source": "src/a.js",
"module": "dist/a.js",
"targets": {
"module": {
"includeNodeModules": true
}
}
}
packages/a/src/a.js:
import shared from '/shared.module.css';
export default shared.foo + '-a';
packages/b/package.json:
{
"engines": { "node": "*" },
"source": "src/b.js",
"module": "dist/b.js",
"targets": {
"module": {
"includeNodeModules": true
}
}
}
packages/b/src/b.js:
import shared from '/shared.module.css';
export default shared.foo + '-b';
shared.module.css:
.foo {
composes: bar;
color: white
}
.bar { background: pink }
`;

let b = await bundle(dir + '/packages/*', {
inputFS: overlayFS,
mode: 'production',
});

assertBundles(b, [
{
assets: ['a.js'],
},
{
assets: ['b.js'],
},
{
type: 'js',
assets: ['shared.module.css'],
},
{
type: 'js',
assets: ['shared.module.css'],
},
{
type: 'css',
assets: ['shared.module.css'],
},
{
type: 'css',
assets: ['shared.module.css'],
},
]);

for (let bundle of b.getBundles()) {
let contents = await outputFS.readFile(bundle.filePath, 'utf8');
assert(!contents.includes('../'));
}
});
});

0 comments on commit 58b91e5

Please sign in to comment.