Skip to content

Commit

Permalink
ExperimentalBundler: merge bundleBehavior and needsStableName
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed May 4, 2022
1 parent 836fac2 commit 672a414
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 35 deletions.
9 changes: 9 additions & 0 deletions packages/bundlers/experimental/src/ExperimentalBundler.js
Expand Up @@ -404,6 +404,15 @@ function createIdealGraph(
} else {
bundle = nullthrows(bundleGraph.getNode(bundleId));
invariant(bundle !== 'root');

if (
// If this dependency requests isolated, but the bundle is not,
// make the bundle isolated for all uses.
dependency.bundleBehavior === 'isolated' &&
bundle.bundleBehavior == null
) {
bundle.bundleBehavior = dependency.bundleBehavior;
}
}

dependencyBundleGraph.addEdge(
Expand Down
105 changes: 70 additions & 35 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -5699,27 +5699,47 @@ describe('javascript', function () {
),
);

assertBundles(b, [
{
type: 'js',
assets: [
'dynamic-url.js',
'esmodule-helpers.js',
'bundle-url.js',
'cacheLoader.js',
'js-loader.js',
],
},
{
type: 'js',
assets: ['other.js'],
},
{
type: 'js',
assets: ['other.js', 'esmodule-helpers.js'],
},
]);

// Change in behavior: ExperimentalBundler now produces a single bundle
// of the lowest common denominator of bundleBehavior
if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) {
assertBundles(b, [
{
type: 'js',
assets: [
'dynamic-url.js',
'esmodule-helpers.js',
'bundle-url.js',
'cacheLoader.js',
'js-loader.js',
],
},
{
type: 'js',
assets: ['other.js', 'esmodule-helpers.js'],
},
]);
} else {
assertBundles(b, [
{
type: 'js',
assets: [
'dynamic-url.js',
'esmodule-helpers.js',
'bundle-url.js',
'cacheLoader.js',
'js-loader.js',
],
},
{
type: 'js',
assets: ['other.js'],
},
{
type: 'js',
assets: ['other.js', 'esmodule-helpers.js'],
},
]);
}
let res = await run(b);
assert.equal(typeof res.lazy, 'object');
assert.equal(typeof (await res.lazy), 'function');
Expand All @@ -5744,20 +5764,35 @@ describe('javascript', function () {
},
);

assertBundles(b, [
{
type: 'js',
assets: ['dynamic-url.js'],
},
{
type: 'js',
assets: ['other.js'],
},
{
type: 'js',
assets: ['other.js'],
},
]);
if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) {
// Change in behavior: ExperimentalBundler now produces a single bundle
// of the lowest common denominator of bundleBehavior
assertBundles(b, [
{
type: 'js',
assets: ['dynamic-url.js'],
},
{
type: 'js',
assets: ['other.js'],
},
]);
} else {
assertBundles(b, [
{
type: 'js',
assets: ['dynamic-url.js'],
},
{
type: 'js',
assets: ['other.js'],
},
{
type: 'js',
assets: ['other.js'],
},
]);
}

let res = await run(b);
assert.equal(typeof res.lazy, 'object');
Expand Down

0 comments on commit 672a414

Please sign in to comment.