Skip to content

Commit

Permalink
achan3/P2X-1041 new disableSharedBundles config option (#9209)
Browse files Browse the repository at this point in the history
* Add initial config logic to disable shared bundles

* Add test cases for disableSharedBundles config

* Shared bundle creation now relies on disableSharedBundles

* Add yarn.lock

* add new logger warning when both minBundleSize and disableSharedBundles are manually set

* Revert "add new logger warning when both minBundleSize and disableSharedBundles are manually set"

This reverts commit fd2cdaa.

* add warning for conflicting setting of both minBundleSize and disableSharedBundles config options

* add test when disableSharedBundler config option isn't set - revert to default value

* add test cases for instances that should not throw warnings

* add test case where warning is expected

* edit defaultBundler to throw warnings for minBundles and maxParallelRequests

* condense test cases into minimal combos to test minBundles and maxParallelRequests

* prevent reuse of bundles when disableSharedBundles is set

* remove import used only for testing

* add warning for minBundleSize when shared bundles are disabled

* add warning for minBundleSize, remove duplicate disableSharedConfig checks, update test accordingly

* stop removal of shared bundles if shared bundles are disabled to begin with

---------

Co-authored-by: Iris Moini <[email protected]>
Co-authored-by: achan3 <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2023
1 parent df8f72b commit 6dcba36
Show file tree
Hide file tree
Showing 44 changed files with 619 additions and 126 deletions.
306 changes: 180 additions & 126 deletions packages/bundlers/default/src/DefaultBundler.js

Large diffs are not rendered by default.

311 changes: 311 additions & 0 deletions packages/core/integration-tests/test/bundler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,319 @@
import path from 'path';
import assert from 'assert';
import Logger from '@parcel/logger';
import {bundle, assertBundles, findAsset} from '@parcel/test-utils';

describe('bundler', function () {
it('should not create shared bundles when a bundle is being reused and disableSharedBundles is enabled', async function () {
let b = await bundle(
path.join(
__dirname,
'integration/disable-shared-bundle-single-source/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);

assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['a.js', 'b.js', 'foo.js', 'bar.js'],
},
]);
});

it('should not create shared bundles and should warn when disableSharedBundles is set to true with maxParallelRequests set', async function () {
let messages = [];
let loggerDisposable = Logger.onLog(message => {
messages.push(message);
});
let b = await bundle(
path.join(
__dirname,
'integration/disable-shared-bundles-true-parallel/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
loggerDisposable.dispose();

assert.deepEqual(messages, [
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "100" set for maxParallelRequests will not be used as shared bundles have been disabled',
},
],
},
]);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['bar.js', 'a.js', 'b.js'],
},
]);
});

it('should not create shared bundles and should warn when disableSharedBundles is set to true with minBundleSize set', async function () {
let messages = [];
let loggerDisposable = Logger.onLog(message => {
messages.push(message);
});
let b = await bundle(
path.join(
__dirname,
'integration/disable-shared-bundles-true-min-bundleSize/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
loggerDisposable.dispose();

assert.deepEqual(messages, [
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "200" set for minBundleSize will not be used as shared bundles have been disabled',
},
],
},
]);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['bar.js', 'a.js', 'b.js'],
},
]);
});

it('should not create shared bundles and should warn when disableSharedBundles is set to true with minBundles set', async function () {
let messages = [];
let loggerDisposable = Logger.onLog(message => {
messages.push(message);
});
let b = await bundle(
path.join(
__dirname,
'integration/disable-shared-bundles-true-min-bundles/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
loggerDisposable.dispose();

assert.deepEqual(messages, [
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "0" set for minBundles will not be used as shared bundles have been disabled',
},
],
},
]);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['bar.js', 'a.js', 'b.js'],
},
]);
});

it('should not create shared bundles and should warn when disableSharedBundles is set to true with minBundles, minBundleSize and maxParallelRequests set', async function () {
let messages = [];
let loggerDisposable = Logger.onLog(message => {
messages.push(message);
});
let b = await bundle(
path.join(
__dirname,
'integration/disable-shared-bundles-true-min-bundles-parallel/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
loggerDisposable.dispose();

assert.deepEqual(messages, [
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "0" set for minBundles will not be used as shared bundles have been disabled',
},
],
},
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "200" set for minBundleSize will not be used as shared bundles have been disabled',
},
],
},
{
type: 'log',
level: 'warn',
diagnostics: [
{
origin: '@parcel/bundler-default',
message:
'The value of "100" set for maxParallelRequests will not be used as shared bundles have been disabled',
},
],
},
]);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['bar.js', 'a.js', 'b.js'],
},
]);
});

it('should create shared bundles and should not throw a warning when disableSharedBundles is set to false', async function () {
let messages = [];
let loggerDisposable = Logger.onLog(message => {
messages.push(message);
});
let b = await bundle(
path.join(__dirname, 'integration/disable-shared-bundles-false/index.js'),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
loggerDisposable.dispose();

assert.deepEqual(messages, []);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['foo.js'],
},
{
assets: ['bar.js'],
},
{
assets: ['a.js', 'b.js'],
},
]);
});

it('should not count inline assests towards parallel request limit', async function () {
// Shared bundle should not be removed in this case
let b = await bundle(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import foo from './foo';

export default 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import a from './a';
import b from './b';

export default 3;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import a from './a';
import b from './b';

export default 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import('./foo');
import('./bar');

export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@parcel/bundler-default": {
"minBundles": 0,
"minBundleSize": 200,
"maxParallelRequests": 100,
"disableSharedBundles": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import a from './a';
import b from './b';

export default 3;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import a from './a';
import b from './b';

export default 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import('./foo');
import('./bar');

export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"@parcel/bundler-default": {
"minBundles": 0,
"minBundleSize": 200,
"maxParallelRequests": 100,
"disableSharedBundles": false
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import a from './a';
import b from './b';

export default 3;
Loading

0 comments on commit 6dcba36

Please sign in to comment.