From 8e566fdd148ead810c7cb686cab001252fda3bb0 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 2 Nov 2022 20:55:07 +0100 Subject: [PATCH 01/16] Write docs --- docs/999-big-list-of-options.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 0eff6b40e3c..72fcab4df6e 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -1890,6 +1890,16 @@ Type: `number`
CLI: `--experimentalCacheExpiry `
Default: Determines after how many runs cached assets that are no longer used by plugins should be removed. +#### experimentalMinChunkSize + +Type: `number`
CLI: `--experimentalMinChunkSize `
Default: `0` + +Set a minimal chunk size target when code-splitting. When this value is greater than `0`, Rollup will try to merge any chunk that does not have side effects when executed, i.e. it only contains function definitions etc., and is below this size limit into another chunk that is likely to be loaded under similar conditions. + +This will mean that the generated bundle will possibly load code that is not needed yet in order to need fewer chunks. The condition for the merged chunks to be side effect free ensures that this does not change behaviour. + +Unfortunately, due to the way chunking works, chunk size is measured before any plugins like minifiers ran, which means this number is slightly inaccurate. + #### perf Type: `boolean`
CLI: `--perf`/`--no-perf`
Default: `false` From 9eb71e0fffb2a55e69e6b6e9f84a1d043b4b738c Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Wed, 2 Nov 2022 20:56:51 +0100 Subject: [PATCH 02/16] Define new option (no effect yet) --- src/rollup/types.d.ts | 2 ++ src/utils/options/mergeOptions.ts | 1 + src/utils/options/normalizeOutputOptions.ts | 1 + 3 files changed, 4 insertions(+) diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index 70805021277..f40a3c8804b 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -639,6 +639,7 @@ export interface OutputOptions { dynamicImportInCjs?: boolean; entryFileNames?: string | ((chunkInfo: PreRenderedChunk) => string); esModule?: boolean | 'if-default-prop'; + experimentalMinChunkSize?: number; exports?: 'default' | 'named' | 'none' | 'auto'; extend?: boolean; externalImportAssertions?: boolean; @@ -691,6 +692,7 @@ export interface NormalizedOutputOptions { dynamicImportInCjs: boolean; entryFileNames: string | ((chunkInfo: PreRenderedChunk) => string); esModule: boolean | 'if-default-prop'; + experimentalMinChunkSize: number; exports: 'default' | 'named' | 'none' | 'auto'; extend: boolean; externalImportAssertions: boolean; diff --git a/src/utils/options/mergeOptions.ts b/src/utils/options/mergeOptions.ts index be429cfb598..84426118b93 100644 --- a/src/utils/options/mergeOptions.ts +++ b/src/utils/options/mergeOptions.ts @@ -232,6 +232,7 @@ async function mergeOutputOptions( dynamicImportInCjs: getOption('dynamicImportInCjs'), entryFileNames: getOption('entryFileNames'), esModule: getOption('esModule'), + experimentalMinChunkSize: getOption('experimentalMinChunkSize'), exports: getOption('exports'), extend: getOption('extend'), externalImportAssertions: getOption('externalImportAssertions'), diff --git a/src/utils/options/normalizeOutputOptions.ts b/src/utils/options/normalizeOutputOptions.ts index e03e92eba9b..8fc7974a4b1 100644 --- a/src/utils/options/normalizeOutputOptions.ts +++ b/src/utils/options/normalizeOutputOptions.ts @@ -50,6 +50,7 @@ export async function normalizeOutputOptions( dynamicImportInCjs: config.dynamicImportInCjs ?? true, entryFileNames: getEntryFileNames(config, unsetOptions), esModule: config.esModule ?? 'if-default-prop', + experimentalMinChunkSize: config.experimentalMinChunkSize || 0, exports: getExports(config, unsetOptions), extend: config.extend || false, externalImportAssertions: config.externalImportAssertions ?? true, From 59613658660b338991be3bff9b62560152d81644 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 3 Nov 2022 06:21:19 +0100 Subject: [PATCH 03/16] Add first tests --- .../merge-chunk-into-shared/_config.js | 11 +++++++++++ .../_expected/amd/generated-big.js | 7 +++++++ .../_expected/amd/generated-small.js | 7 +++++++ .../_expected/amd/main1.js | 5 +++++ .../_expected/amd/main2.js | 5 +++++ .../_expected/amd/main3.js | 5 +++++ .../_expected/cjs/generated-big.js | 5 +++++ .../_expected/cjs/generated-small.js | 5 +++++ .../_expected/cjs/main1.js | 6 ++++++ .../_expected/cjs/main2.js | 6 ++++++ .../_expected/cjs/main3.js | 5 +++++ .../_expected/es/generated-small.js | 5 +++++ .../_expected/es/main1.js | 3 +++ .../_expected/es/main2.js | 3 +++ .../_expected/es/main3.js | 3 +++ .../_expected/system/generated-big.js | 10 ++++++++++ .../_expected/system/generated-small.js | 10 ++++++++++ .../_expected/system/main1.js | 16 ++++++++++++++++ .../_expected/system/main2.js | 16 ++++++++++++++++ .../_expected/system/main3.js | 14 ++++++++++++++ .../minChunkSize/merge-chunk-into-shared/big.js | 1 + .../merge-chunk-into-shared/main1.js | 4 ++++ .../merge-chunk-into-shared/main2.js | 4 ++++ .../merge-chunk-into-shared/main3.js | 3 +++ .../merge-chunk-into-shared/small.js | 1 + .../no-merge-side-effects/_config.js | 10 ++++++++++ .../_expected/amd/generated-big.js | 7 +++++++ .../_expected/amd/generated-small.js | 8 ++++++++ .../no-merge-side-effects/_expected/amd/main1.js | 5 +++++ .../no-merge-side-effects/_expected/amd/main2.js | 5 +++++ .../no-merge-side-effects/_expected/amd/main3.js | 5 +++++ .../_expected/cjs/generated-big.js | 5 +++++ .../_expected/cjs/generated-small.js | 6 ++++++ .../no-merge-side-effects/_expected/cjs/main1.js | 6 ++++++ .../no-merge-side-effects/_expected/cjs/main2.js | 6 ++++++ .../no-merge-side-effects/_expected/cjs/main3.js | 5 +++++ .../_expected/es/generated-big.js | 3 +++ .../_expected/es/generated-small.js | 4 ++++ .../no-merge-side-effects/_expected/es/main1.js | 4 ++++ .../no-merge-side-effects/_expected/es/main2.js | 4 ++++ .../no-merge-side-effects/_expected/es/main3.js | 3 +++ .../_expected/system/generated-big.js | 10 ++++++++++ .../_expected/system/generated-small.js | 11 +++++++++++ .../_expected/system/main1.js | 16 ++++++++++++++++ .../_expected/system/main2.js | 16 ++++++++++++++++ .../_expected/system/main3.js | 14 ++++++++++++++ .../minChunkSize/no-merge-side-effects/big.js | 1 + .../minChunkSize/no-merge-side-effects/main1.js | 4 ++++ .../minChunkSize/no-merge-side-effects/main2.js | 4 ++++ .../minChunkSize/no-merge-side-effects/main3.js | 3 +++ .../minChunkSize/no-merge-side-effects/small.js | 2 ++ 51 files changed, 327 insertions(+) create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/small.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-small.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/big.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/no-merge-side-effects/small.js diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js new file mode 100644 index 00000000000..f83f353ce74 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js @@ -0,0 +1,11 @@ +module.exports = { + solo: true, + description: + 'merges small chunks into shared chunks that are loaded by a super-set of entry points', + options: { + input: ['main1.js', 'main2.js', 'main3.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js new file mode 100644 index 00000000000..ee89ef5bdf5 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small = '1'; + + exports.small = small; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js new file mode 100644 index 00000000000..9f1e89308c2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; + + console.log(big.big, small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js new file mode 100644 index 00000000000..9f1e89308c2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; + + console.log(big.big, small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js new file mode 100644 index 00000000000..87b6a754d97 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-small'], (function (small) { 'use strict'; + + console.log(small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js new file mode 100644 index 00000000000..c7bcc6a74b7 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js @@ -0,0 +1,5 @@ +'use strict'; + +const small = '1'; + +exports.small = small; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js new file mode 100644 index 00000000000..b3a7679c4a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small = require('./generated-small.js'); + +console.log(big.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js new file mode 100644 index 00000000000..b3a7679c4a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small = require('./generated-small.js'); + +console.log(big.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js new file mode 100644 index 00000000000..e9f5c811d62 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js @@ -0,0 +1,5 @@ +'use strict'; + +var small = require('./generated-small.js'); + +console.log(small.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/generated-small.js new file mode 100644 index 00000000000..3a60fcf90de --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/generated-small.js @@ -0,0 +1,5 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +const small = '1'; + +export { big as b, small as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main1.js new file mode 100644 index 00000000000..f72ae2e2c0b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { b as big, s as small } from './generated-small.js'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main2.js new file mode 100644 index 00000000000..f72ae2e2c0b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main2.js @@ -0,0 +1,3 @@ +import { b as big, s as small } from './generated-small.js'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js new file mode 100644 index 00000000000..3f8fefa28aa --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js @@ -0,0 +1,3 @@ +import { s as small } from './generated-small.js'; + +console.log(small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js new file mode 100644 index 00000000000..a446c6116c9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small = exports('s', '1'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js new file mode 100644 index 00000000000..1b80803b9e5 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small.js'], (function () { + 'use strict'; + var big, small; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small = module.s; + }], + execute: (function () { + + console.log(big, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js new file mode 100644 index 00000000000..1b80803b9e5 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small.js'], (function () { + 'use strict'; + var big, small; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small = module.s; + }], + execute: (function () { + + console.log(big, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js new file mode 100644 index 00000000000..6e93391fab8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js @@ -0,0 +1,14 @@ +System.register(['./generated-small.js'], (function () { + 'use strict'; + var small; + return { + setters: [function (module) { + small = module.s; + }], + execute: (function () { + + console.log(small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main1.js new file mode 100644 index 00000000000..ca84399ef67 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main1.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small } from './small'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main2.js new file mode 100644 index 00000000000..ca84399ef67 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main2.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small } from './small'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js new file mode 100644 index 00000000000..445919e6d15 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js @@ -0,0 +1,3 @@ +import { small } from './small'; + +console.log(small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/small.js new file mode 100644 index 00000000000..64e15634102 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/small.js @@ -0,0 +1 @@ +export const small = '1'; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js new file mode 100644 index 00000000000..ca26c20da09 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'does not merge small chunks that have side effects', + options: { + input: ['main1.js', 'main2.js', 'main3.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-small.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-small.js new file mode 100644 index 00000000000..60ddec3c69f --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/generated-small.js @@ -0,0 +1,8 @@ +define(['exports'], (function (exports) { 'use strict'; + + console.log('effect'); + const small = '1'; + + exports.small = small; + +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main1.js new file mode 100644 index 00000000000..9f1e89308c2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; + + console.log(big.big, small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main2.js new file mode 100644 index 00000000000..9f1e89308c2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; + + console.log(big.big, small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js new file mode 100644 index 00000000000..87b6a754d97 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-small'], (function (small) { 'use strict'; + + console.log(small.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-small.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-small.js new file mode 100644 index 00000000000..f28ad7e891d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/generated-small.js @@ -0,0 +1,6 @@ +'use strict'; + +console.log('effect'); +const small = '1'; + +exports.small = small; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main1.js new file mode 100644 index 00000000000..b3a7679c4a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small = require('./generated-small.js'); + +console.log(big.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main2.js new file mode 100644 index 00000000000..b3a7679c4a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small = require('./generated-small.js'); + +console.log(big.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js new file mode 100644 index 00000000000..e9f5c811d62 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js @@ -0,0 +1,5 @@ +'use strict'; + +var small = require('./generated-small.js'); + +console.log(small.small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-big.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-big.js new file mode 100644 index 00000000000..f26e52dae36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-big.js @@ -0,0 +1,3 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +export { big as b }; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-small.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-small.js new file mode 100644 index 00000000000..71d7aa578ee --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/generated-small.js @@ -0,0 +1,4 @@ +console.log('effect'); +const small = '1'; + +export { small as s }; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main1.js new file mode 100644 index 00000000000..003370663b0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main1.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small } from './generated-small.js'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main2.js new file mode 100644 index 00000000000..003370663b0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main2.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small } from './generated-small.js'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js new file mode 100644 index 00000000000..3f8fefa28aa --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js @@ -0,0 +1,3 @@ +import { s as small } from './generated-small.js'; + +console.log(small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-small.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-small.js new file mode 100644 index 00000000000..ca96da94b50 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/generated-small.js @@ -0,0 +1,11 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + console.log('effect'); + const small = exports('s', '1'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main1.js new file mode 100644 index 00000000000..1b80803b9e5 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main1.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small.js'], (function () { + 'use strict'; + var big, small; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small = module.s; + }], + execute: (function () { + + console.log(big, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main2.js new file mode 100644 index 00000000000..1b80803b9e5 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main2.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small.js'], (function () { + 'use strict'; + var big, small; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small = module.s; + }], + execute: (function () { + + console.log(big, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js new file mode 100644 index 00000000000..6e93391fab8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js @@ -0,0 +1,14 @@ +System.register(['./generated-small.js'], (function () { + 'use strict'; + var small; + return { + setters: [function (module) { + small = module.s; + }], + execute: (function () { + + console.log(small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/big.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main1.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main1.js new file mode 100644 index 00000000000..ca84399ef67 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main1.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small } from './small'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main2.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main2.js new file mode 100644 index 00000000000..ca84399ef67 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main2.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small } from './small'; + +console.log(big, small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js new file mode 100644 index 00000000000..445919e6d15 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js @@ -0,0 +1,3 @@ +import { small } from './small'; + +console.log(small); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/small.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/small.js new file mode 100644 index 00000000000..d41bd10033c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/small.js @@ -0,0 +1,2 @@ +console.log('effect'); +export const small = '1'; From 8b759690ab261f51130518c86a61891a07042b4f Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 3 Nov 2022 06:28:29 +0100 Subject: [PATCH 04/16] small refactoring --- src/utils/chunkAssignment.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index 4a42e3da78a..f4d92526763 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -13,9 +13,11 @@ export function getChunkAssignments( const modulesInManualChunks = new Set(manualChunkAliasByEntry.keys()); const manualChunkModulesByAlias: Record = Object.create(null); for (const [entry, alias] of manualChunkAliasByEntry) { - const chunkModules = (manualChunkModulesByAlias[alias] = - manualChunkModulesByAlias[alias] || []); - addStaticDependenciesToManualChunk(entry, chunkModules, modulesInManualChunks); + addStaticDependenciesToManualChunk( + entry, + (manualChunkModulesByAlias[alias] ||= []), + modulesInManualChunks + ); } for (const [alias, modules] of Object.entries(manualChunkModulesByAlias)) { chunkDefinitions.push({ alias, modules }); From 3f6cd46adba06b54e7d001675461b09a1af541b5 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Thu, 3 Nov 2022 10:11:28 +0100 Subject: [PATCH 05/16] Forbid unused vars vie ESLint rather than TypeScript That way, we can easily ignore errors to include debug code --- .eslintrc.js | 6 +- src/finalisers/es.ts | 16 ++--- src/utils/resolveIdViaPlugins.ts | 7 +- .../_expected/es/main3.js | 4 +- .../merge-chunk-into-shared/main3.js | 4 +- .../_expected/amd/main3.js | 4 +- .../_expected/cjs/main3.js | 4 +- .../_expected/es/main3.js | 4 +- .../_expected/system/main3.js | 8 +-- .../no-merge-side-effects/main3.js | 4 +- .../samples/render-chunk-transform/_config.js | 1 - .../rollup.config.js | 2 - .../samples/watch/no-config-file/_config.js | 2 - .../samples/watch/node-config-file/_config.js | 2 - .../dynamic-import-this-arrow/_config.js | 2 - .../dynamic-import-this-function/_config.js | 2 - .../samples/enforce-addon-order/_config.js | 8 --- .../reserved-names-as-props-false/_config.js | 2 +- .../reserved-names-as-props-true/_config.js | 2 +- .../keep-dynamic-assertions/_config.js | 2 +- .../removes-dynamic-assertions/_config.js | 2 +- .../samples/return-after-error/_config.js | 2 - .../samples/deconflicts-interop/_config.js | 5 +- .../samples/external-function/_config.js | 4 +- .../plugin-assertions-this-resolve/_config.js | 2 +- .../deoptimized-props-with-getter/_config.js | 2 +- .../unknown-prop-unknown-access/_config.js | 2 +- .../unknown-property-access/_config.js | 2 +- .../unknown-super-prop/_config.js | 2 +- .../deoptimized-props-with-setter/_config.js | 2 +- .../unknown-prop-setter/_config.js | 2 +- .../unknown-prop-unknown-access/_config.js | 2 +- .../unknown-super-prop/_config.js | 2 +- .../module-side-effects/writable/_config.js | 3 - .../samples/preload-loading-module/_config.js | 2 +- .../samples/transformer-multiple/_config.js | 4 +- test/hooks/index.js | 28 ++++---- test/incremental/index.js | 49 ++++++------- test/misc/bundle-information.js | 70 ++++++++----------- test/misc/deprecations.js | 7 +- test/misc/misc.js | 13 ++-- test/misc/umd.js | 2 +- test/typescript/index.ts | 16 ++--- tsconfig.json | 1 - 44 files changed, 131 insertions(+), 181 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c26b7c1c426..c40b7adf8ad 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -74,7 +74,11 @@ module.exports = { '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', ignoreRestSiblings: true, varsIgnorePattern: '^_' } + ], + 'arrow-body-style': ['error', 'as-needed'], 'dot-notation': 'error', 'import/no-unresolved': [ 'error', diff --git a/src/finalisers/es.ts b/src/finalisers/es.ts index 3e0b3abab5a..f40cf512b7d 100644 --- a/src/finalisers/es.ts +++ b/src/finalisers/es.ts @@ -62,11 +62,11 @@ function getImportBlock(dependencies: ChunkDependency[], { _ }: GenerateCodeSnip } else if (importedNames.length > 0) { importBlock.push( `import ${defaultImport ? `${defaultImport.local},${_}` : ''}{${_}${importedNames - .map(specifier => { - return specifier.imported === specifier.local + .map(specifier => + specifier.imported === specifier.local ? specifier.imported - : `${specifier.imported} as ${specifier.local}`; - }) + : `${specifier.imported} as ${specifier.local}` + ) .join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}` ); } @@ -105,11 +105,11 @@ function getImportBlock(dependencies: ChunkDependency[], { _ }: GenerateCodeSnip if (namedReexports.length > 0) { importBlock.push( `export${_}{${_}${namedReexports - .map(specifier => { - return specifier.imported === specifier.reexported + .map(specifier => + specifier.imported === specifier.reexported ? specifier.imported - : `${specifier.imported} as ${specifier.reexported}`; - }) + : `${specifier.imported} as ${specifier.reexported}` + ) .join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}` ); } diff --git a/src/utils/resolveIdViaPlugins.ts b/src/utils/resolveIdViaPlugins.ts index e842ac7a901..968754eb158 100644 --- a/src/utils/resolveIdViaPlugins.ts +++ b/src/utils/resolveIdViaPlugins.ts @@ -24,16 +24,15 @@ export function resolveIdViaPlugins( } replaceContext = (pluginContext, plugin): PluginContext => ({ ...pluginContext, - resolve: (source, importer, { assertions, custom, isEntry, skipSelf } = BLANK) => { - return moduleLoaderResolveId( + resolve: (source, importer, { assertions, custom, isEntry, skipSelf } = BLANK) => + moduleLoaderResolveId( source, importer, custom, isEntry, assertions || EMPTY_OBJECT, skipSelf ? [...skip, { importer, plugin, source }] : skip - ); - } + ) }); } return pluginDriver.hookFirst( diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js index 3f8fefa28aa..68f15d2638c 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/es/main3.js @@ -1,3 +1,3 @@ -import { s as small } from './generated-small.js'; +import { b as big } from './generated-small.js'; -console.log(small); +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js index 445919e6d15..99752c1c3b4 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/main3.js @@ -1,3 +1,3 @@ -import { small } from './small'; +import { big } from './big'; -console.log(small); +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js index 87b6a754d97..1bddbc92f18 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/amd/main3.js @@ -1,5 +1,5 @@ -define(['./generated-small'], (function (small) { 'use strict'; +define(['./generated-big'], (function (big) { 'use strict'; - console.log(small.small); + console.log(big.big); })); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js index e9f5c811d62..5a574b96fe4 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/cjs/main3.js @@ -1,5 +1,5 @@ 'use strict'; -var small = require('./generated-small.js'); +var big = require('./generated-big.js'); -console.log(small.small); +console.log(big.big); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js index 3f8fefa28aa..00748695997 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/es/main3.js @@ -1,3 +1,3 @@ -import { s as small } from './generated-small.js'; +import { b as big } from './generated-big.js'; -console.log(small); +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js index 6e93391fab8..9d92d0a9972 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_expected/system/main3.js @@ -1,13 +1,13 @@ -System.register(['./generated-small.js'], (function () { +System.register(['./generated-big.js'], (function () { 'use strict'; - var small; + var big; return { setters: [function (module) { - small = module.s; + big = module.b; }], execute: (function () { - console.log(small); + console.log(big); }) }; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js index 445919e6d15..99752c1c3b4 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/main3.js @@ -1,3 +1,3 @@ -import { small } from './small'; +import { big } from './big'; -console.log(small); +console.log(big); diff --git a/test/chunking-form/samples/render-chunk-transform/_config.js b/test/chunking-form/samples/render-chunk-transform/_config.js index 02ec529781f..b623fa23427 100644 --- a/test/chunking-form/samples/render-chunk-transform/_config.js +++ b/test/chunking-form/samples/render-chunk-transform/_config.js @@ -1,5 +1,4 @@ const assert = require('node:assert'); -const path = require('node:path'); const { replaceDirectoryInStringifiedObject } = require('../../../utils'); module.exports = { diff --git a/test/cli/samples/unfulfilled-hook-actions-manual-exit/rollup.config.js b/test/cli/samples/unfulfilled-hook-actions-manual-exit/rollup.config.js index f63dae4d349..0c565b2e067 100644 --- a/test/cli/samples/unfulfilled-hook-actions-manual-exit/rollup.config.js +++ b/test/cli/samples/unfulfilled-hook-actions-manual-exit/rollup.config.js @@ -1,5 +1,3 @@ -const path = require('node:path'); - let resolveA; const waitForA = new Promise(resolve => (resolveA = resolve)); diff --git a/test/cli/samples/watch/no-config-file/_config.js b/test/cli/samples/watch/no-config-file/_config.js index d7aa14e8e79..c671e90a607 100644 --- a/test/cli/samples/watch/no-config-file/_config.js +++ b/test/cli/samples/watch/no-config-file/_config.js @@ -1,5 +1,3 @@ -const path = require('node:path'); - module.exports = { description: 'watches without a config file', command: 'rollup main.js --watch --format es --file _actual/main.js', diff --git a/test/cli/samples/watch/node-config-file/_config.js b/test/cli/samples/watch/node-config-file/_config.js index 62fcf51923b..1cbfcf60c82 100644 --- a/test/cli/samples/watch/node-config-file/_config.js +++ b/test/cli/samples/watch/node-config-file/_config.js @@ -1,5 +1,3 @@ -const path = require('node:path'); - module.exports = { description: 'watches using a node_modules config files', command: 'rollup --watch --config node:custom', diff --git a/test/form/samples/dynamic-import-this-arrow/_config.js b/test/form/samples/dynamic-import-this-arrow/_config.js index 972c5922768..2a4145afc99 100644 --- a/test/form/samples/dynamic-import-this-arrow/_config.js +++ b/test/form/samples/dynamic-import-this-arrow/_config.js @@ -1,5 +1,3 @@ -const assert = require('node:assert'); - module.exports = { description: 'uses correct "this" in dynamic imports when using arrow functions', options: { diff --git a/test/form/samples/dynamic-import-this-function/_config.js b/test/form/samples/dynamic-import-this-function/_config.js index 6c22d856484..53feb9f5913 100644 --- a/test/form/samples/dynamic-import-this-function/_config.js +++ b/test/form/samples/dynamic-import-this-function/_config.js @@ -1,5 +1,3 @@ -const assert = require('node:assert'); - module.exports = { description: 'uses correct "this" in dynamic imports when not using arrow functions', options: { diff --git a/test/form/samples/enforce-addon-order/_config.js b/test/form/samples/enforce-addon-order/_config.js index 800a0e9b4a1..0814c90772b 100644 --- a/test/form/samples/enforce-addon-order/_config.js +++ b/test/form/samples/enforce-addon-order/_config.js @@ -1,11 +1,3 @@ -const assert = require('node:assert'); -const fs = require('node:fs'); -const path = require('node:path'); -const acorn = require('acorn'); - -const ID_MAIN = path.join(__dirname, 'main.js'); -const code = fs.readFileSync(ID_MAIN, 'utf8'); - const hooks = ['banner', 'footer', 'intro', 'outro']; const plugins = []; diff --git a/test/form/samples/generated-code-compact/reserved-names-as-props-false/_config.js b/test/form/samples/generated-code-compact/reserved-names-as-props-false/_config.js index f7631ff116c..0fff50bba3a 100644 --- a/test/form/samples/generated-code-compact/reserved-names-as-props-false/_config.js +++ b/test/form/samples/generated-code-compact/reserved-names-as-props-false/_config.js @@ -14,7 +14,7 @@ module.exports = { }, plugins: [ { - transform(code, id) { + transform() { return { syntheticNamedExports: true }; } } diff --git a/test/form/samples/generated-code-compact/reserved-names-as-props-true/_config.js b/test/form/samples/generated-code-compact/reserved-names-as-props-true/_config.js index d40ba895944..5687b9a5fa4 100644 --- a/test/form/samples/generated-code-compact/reserved-names-as-props-true/_config.js +++ b/test/form/samples/generated-code-compact/reserved-names-as-props-true/_config.js @@ -14,7 +14,7 @@ module.exports = { }, plugins: [ { - transform(code, id) { + transform() { return { syntheticNamedExports: true }; } } diff --git a/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js b/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js index e2571b057c7..d46209bfcea 100644 --- a/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js +++ b/test/form/samples/import-assertions/keep-dynamic-assertions/_config.js @@ -8,7 +8,7 @@ module.exports = { }, plugins: [ { - resolveDynamicImport(specifier, importer) { + resolveDynamicImport(specifier) { if (typeof specifier === 'object') { if (specifier.type === 'TemplateLiteral') { return "'resolvedString'"; diff --git a/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js b/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js index b939795fd58..74a50e2c816 100644 --- a/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js +++ b/test/form/samples/import-assertions/removes-dynamic-assertions/_config.js @@ -8,7 +8,7 @@ module.exports = { }, plugins: [ { - resolveDynamicImport(specifier, importer) { + resolveDynamicImport(specifier) { if (typeof specifier === 'object') { if (specifier.type === 'TemplateLiteral') { return "'resolvedString'"; diff --git a/test/form/samples/return-after-error/_config.js b/test/form/samples/return-after-error/_config.js index db8aa326bbb..e45fd11d277 100644 --- a/test/form/samples/return-after-error/_config.js +++ b/test/form/samples/return-after-error/_config.js @@ -1,5 +1,3 @@ -const path = require('node:path'); - module.exports = { description: 'tree-shakes entities referenced in a return statement after an error' }; diff --git a/test/function/samples/deconflicts-interop/_config.js b/test/function/samples/deconflicts-interop/_config.js index 63729a30fe5..e569d383180 100644 --- a/test/function/samples/deconflicts-interop/_config.js +++ b/test/function/samples/deconflicts-interop/_config.js @@ -25,8 +25,7 @@ module.exports = { } }, context: { - require: () => { - return Object.defineProperty({ foo: 'foo', default: 'bar' }, '__esModule', { value: true }); - } + require: () => + Object.defineProperty({ foo: 'foo', default: 'bar' }, '__esModule', { value: true }) } }; diff --git a/test/function/samples/external-function/_config.js b/test/function/samples/external-function/_config.js index cabe004fca3..05832e1686a 100644 --- a/test/function/samples/external-function/_config.js +++ b/test/function/samples/external-function/_config.js @@ -1,9 +1,7 @@ module.exports = { description: 'allows external option to be a function (#522)', options: { - external: id => { - return id === 'external'; - } + external: id => id === 'external' }, context: { require: id => { diff --git a/test/function/samples/import-assertions/plugin-assertions-this-resolve/_config.js b/test/function/samples/import-assertions/plugin-assertions-this-resolve/_config.js index 42c28ecd730..37eb8231488 100644 --- a/test/function/samples/import-assertions/plugin-assertions-this-resolve/_config.js +++ b/test/function/samples/import-assertions/plugin-assertions-this-resolve/_config.js @@ -6,7 +6,7 @@ module.exports = { plugins: [ { name: 'first', - async resolveId(source, importer, { assertions }) { + async resolveId() { assert.deepStrictEqual( await this.resolve('external', undefined, { skipSelf: true, diff --git a/test/function/samples/modify-this-via-getter/deoptimized-props-with-getter/_config.js b/test/function/samples/modify-this-via-getter/deoptimized-props-with-getter/_config.js index 4b7c9b3ebb3..d5d93d31690 100644 --- a/test/function/samples/modify-this-via-getter/deoptimized-props-with-getter/_config.js +++ b/test/function/samples/modify-this-via-getter/deoptimized-props-with-getter/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles fully deoptimized objects', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-getter/unknown-prop-unknown-access/_config.js b/test/function/samples/modify-this-via-getter/unknown-prop-unknown-access/_config.js index 884460d181b..f7ad11093ff 100644 --- a/test/function/samples/modify-this-via-getter/unknown-prop-unknown-access/_config.js +++ b/test/function/samples/modify-this-via-getter/unknown-prop-unknown-access/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles unknown getters that modify "this" for unknown property access', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-getter/unknown-property-access/_config.js b/test/function/samples/modify-this-via-getter/unknown-property-access/_config.js index 98690a2ad8d..5b8bf4cebb8 100644 --- a/test/function/samples/modify-this-via-getter/unknown-property-access/_config.js +++ b/test/function/samples/modify-this-via-getter/unknown-property-access/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles getters that modify "this" for unknown property access', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-getter/unknown-super-prop/_config.js b/test/function/samples/modify-this-via-getter/unknown-super-prop/_config.js index 362170a081b..aadb521b9c2 100644 --- a/test/function/samples/modify-this-via-getter/unknown-super-prop/_config.js +++ b/test/function/samples/modify-this-via-getter/unknown-super-prop/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles getters that modify "this" on prototypes for unknown properties', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-setter/deoptimized-props-with-setter/_config.js b/test/function/samples/modify-this-via-setter/deoptimized-props-with-setter/_config.js index 4b7c9b3ebb3..d5d93d31690 100644 --- a/test/function/samples/modify-this-via-setter/deoptimized-props-with-setter/_config.js +++ b/test/function/samples/modify-this-via-setter/deoptimized-props-with-setter/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles fully deoptimized objects', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-setter/unknown-prop-setter/_config.js b/test/function/samples/modify-this-via-setter/unknown-prop-setter/_config.js index d6305f6c204..ada935cacc5 100644 --- a/test/function/samples/modify-this-via-setter/unknown-prop-setter/_config.js +++ b/test/function/samples/modify-this-via-setter/unknown-prop-setter/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles unknown setters that modify "this"', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-setter/unknown-prop-unknown-access/_config.js b/test/function/samples/modify-this-via-setter/unknown-prop-unknown-access/_config.js index 5b67fd6ea0e..e3522b87aa3 100644 --- a/test/function/samples/modify-this-via-setter/unknown-prop-unknown-access/_config.js +++ b/test/function/samples/modify-this-via-setter/unknown-prop-unknown-access/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles unknown setters that modify "this" for unknown property access', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/modify-this-via-setter/unknown-super-prop/_config.js b/test/function/samples/modify-this-via-setter/unknown-super-prop/_config.js index 5bd99dc35bf..cabfbba9c53 100644 --- a/test/function/samples/modify-this-via-setter/unknown-super-prop/_config.js +++ b/test/function/samples/modify-this-via-setter/unknown-super-prop/_config.js @@ -1,7 +1,7 @@ module.exports = { description: 'handles setters that modify "this" on prototypes for unknown properties', context: { - require(id) { + require() { return { unknown: 'prop' }; } }, diff --git a/test/function/samples/module-side-effects/writable/_config.js b/test/function/samples/module-side-effects/writable/_config.js index bfb846e46c6..1a21c1ee4a4 100644 --- a/test/function/samples/module-side-effects/writable/_config.js +++ b/test/function/samples/module-side-effects/writable/_config.js @@ -1,6 +1,3 @@ -const assert = require('node:assert'); -const path = require('node:assert'); - // We prefix the polyfill with \0 to tell other plugins not to try to load or // transform it const POLYFILL_ID = '\0polyfill'; diff --git a/test/function/samples/preload-loading-module/_config.js b/test/function/samples/preload-loading-module/_config.js index ca1e93c1184..8891fd910aa 100644 --- a/test/function/samples/preload-loading-module/_config.js +++ b/test/function/samples/preload-loading-module/_config.js @@ -11,7 +11,7 @@ module.exports = { load(id) { this.load({ id }).then(({ code }) => (preloadedCode = code)); }, - buildEnd(error) { + buildEnd() { assert.strictEqual(preloadedCode, 'assert.ok(true);\n'); } } diff --git a/test/function/samples/transformer-multiple/_config.js b/test/function/samples/transformer-multiple/_config.js index 0c918b03121..3e5d98ed043 100644 --- a/test/function/samples/transformer-multiple/_config.js +++ b/test/function/samples/transformer-multiple/_config.js @@ -12,9 +12,7 @@ module.exports = { { transform(code) { - return code.replace(/\d+/g, match => { - return 2 * +match; - }); + return code.replace(/\d+/g, match => 2 * +match); } } ] diff --git a/test/hooks/index.js b/test/hooks/index.js index 66cf29b0f24..a5d52d0cdb5 100644 --- a/test/hooks/index.js +++ b/test/hooks/index.js @@ -56,7 +56,7 @@ describe('hooks', () => { } ] }) - .then(bundle => { + .then(() => { assert.strictEqual(buildStartCnt, 1); assert.strictEqual(buildEndCnt, 1); @@ -222,8 +222,8 @@ describe('hooks', () => { }); }); - it('does not overwrite files in other outputs when emitting assets during generate', () => { - return rollup + it('does not overwrite files in other outputs when emitting assets during generate', () => + rollup .rollup({ input: 'input', plugins: [ @@ -248,8 +248,7 @@ describe('hooks', () => { assert.strictEqual(output2.length, 2, 'output2'); assert.strictEqual(output2[1].fileName, 'asset'); assert.strictEqual(output2[1].source, 'cjs'); - }); - }); + })); it('caches asset emission in transform hook', () => { let cache; @@ -889,7 +888,7 @@ describe('hooks', () => { d: `export default {};` }), { - renderChunk(code, chunk, options) { + renderChunk(code, chunk) { chunks.push({ fileName: chunk.fileName, imports: chunk.imports, @@ -957,7 +956,7 @@ describe('hooks', () => { entryFileNames: '[name]-[hash].js' }) ) - .then(output => { + .then(() => { assert.strictEqual(augmentChunkHashCalls, 1); }); }); @@ -1028,8 +1027,8 @@ describe('hooks', () => { }); }); - it('supports disabling sanitization for in-memory / in-browser / non-fs builds', () => { - return rollup + it('supports disabling sanitization for in-memory / in-browser / non-fs builds', () => + rollup .rollup({ input: 'input.js', plugins: [ @@ -1039,17 +1038,16 @@ describe('hooks', () => { } ] }) - .then(bundle => { - return bundle.generate({ + .then(bundle => + bundle.generate({ format: 'es', sanitizeFileName: false, entryFileNames: 'test:[name]' - }); - }) + }) + ) .then(({ output }) => { assert.strictEqual(output[0].fileName, 'test:input'); - }); - }); + })); it('allows to enforce plugin hook order in watch mode', async () => { const hooks = ['closeBundle', 'closeWatcher', 'renderError', 'watchChange', 'writeBundle']; diff --git a/test/incremental/index.js b/test/incremental/index.js index a78ab91fedf..0811864ff34 100644 --- a/test/incremental/index.js +++ b/test/incremental/index.js @@ -14,9 +14,7 @@ describe('incremental', () => { return id === 'external' ? false : id; }, - load: id => { - return modules[id]; - }, + load: id => modules[id], transform: code => { transformCalls++; @@ -74,7 +72,7 @@ describe('incremental', () => { cache: bundle }); }) - .then(bundle => { + .then(() => { assert.strictEqual(resolveIdCalls, 3); // +1 for entry point which is resolved every time assert.strictEqual(transformCalls, 2); }); @@ -98,13 +96,13 @@ describe('incremental', () => { cache = bundle.cache; }); }) - .then(() => { - return rollup.rollup({ + .then(() => + rollup.rollup({ input: 'entry', plugins: [plugin], cache - }); - }) + }) + ) .then(bundle => { assert.strictEqual(transformCalls, 3); @@ -133,13 +131,13 @@ describe('incremental', () => { cache = bundle.cache; }); }) - .then(() => { - return rollup.rollup({ + .then(() => + rollup.rollup({ input: 'entry', plugins: [plugin], cache - }); - }) + }) + ) .then(bundle => { assert.strictEqual(resolveIdCalls, 4); @@ -170,13 +168,13 @@ describe('incremental', () => { cache = bundle.cache; }); }) - .then(() => { - return rollup.rollup({ + .then(() => + rollup.rollup({ input: 'entry', plugins: [plugin], cache - }); - }) + }) + ) .then(bundle => { assert.strictEqual(resolveIdCalls, 4); @@ -187,8 +185,8 @@ describe('incremental', () => { }); }); - it('keeps ASTs between runs', () => { - return rollup + it('keeps ASTs between runs', () => + rollup .rollup({ input: 'entry', plugins: [plugin] @@ -207,8 +205,7 @@ describe('incremental', () => { asts.foo, acorn.parse(modules.foo, { sourceType: 'module', ecmaVersion: 2020 }) ); - }); - }); + })); it('recovers from errors', () => { modules.entry = `import foo from 'foo'; import bar from 'bar'; export default foo + bar;`; @@ -227,9 +224,7 @@ describe('incremental', () => { plugins: [plugin], cache }) - .catch(error => { - return cache; - }); + .catch(() => cache); }) .then(cache => { modules.foo = `export default 42;`; @@ -240,9 +235,7 @@ describe('incremental', () => { plugins: [plugin], cache }) - .then(bundle => { - return executeBundle(bundle); - }) + .then(bundle => executeBundle(bundle)) .then(result => { assert.strictEqual(result, 63); }); @@ -399,9 +392,7 @@ describe('incremental', () => { } } }, - transform: (code, id) => { - return { meta: { transform: { calls: transformCalls, id } } }; - } + transform: (code, id) => ({ meta: { transform: { calls: transformCalls, id } } }) }; const cache = await rollup.rollup({ input: 'entry', diff --git a/test/misc/bundle-information.js b/test/misc/bundle-information.js index 75f5cbca2ce..1b9ae79ff4a 100644 --- a/test/misc/bundle-information.js +++ b/test/misc/bundle-information.js @@ -3,8 +3,8 @@ const rollup = require('../../dist/rollup'); const { loader } = require('../utils.js'); describe('The bundle object', () => { - it('contains information about the generated chunks', () => { - return rollup + it('contains information about the generated chunks', () => + rollup .rollup({ input: ['input1', 'input2'], plugins: [ @@ -117,11 +117,10 @@ describe('The bundle object', () => { ], 'modules' ); - }); - }); + })); - it('contains information about external imports and reexports', () => { - return rollup + it('contains information about external imports and reexports', () => + rollup .rollup({ input: ['input'], external: ['external1', 'external2', 'external3'], @@ -207,11 +206,10 @@ describe('The bundle object', () => { ], 'modules' ); - }); - }); + })); - it('handles entry facades as entry points but not the facaded chunk', () => { - return rollup + it('handles entry facades as entry points but not the facaded chunk', () => + rollup .rollup({ input: ['input1', 'input2'], plugins: [ @@ -251,11 +249,10 @@ describe('The bundle object', () => { ['input1', 'input2', null], 'facadeModuleId' ); - }); - }); + })); - it('prioritizes the proper facade name over the proper facaded chunk name', () => { - return rollup + it('prioritizes the proper facade name over the proper facaded chunk name', () => + rollup .rollup({ input: ['input1', 'input2'], plugins: [ @@ -286,11 +283,10 @@ describe('The bundle object', () => { ['input1', 'input2', null], 'facadeModuleId' ); - }); - }); + })); - it('marks dynamic entry points but only marks them as normal entry points if they actually are', () => { - return rollup + it('marks dynamic entry points but only marks them as normal entry points if they actually are', () => + rollup .rollup({ input: ['input', 'dynamic1'], plugins: [ @@ -344,11 +340,10 @@ describe('The bundle object', () => { [['dynamic1.js', 'generated-dynamic2.js'], [], []], 'dynamicImports' ); - }); - }); + })); - it('handles tainted dynamic entries', () => { - return rollup + it('handles tainted dynamic entries', () => + rollup .rollup({ input: ['input1', 'input2'], plugins: [ @@ -394,11 +389,10 @@ describe('The bundle object', () => { [['generated-dynamic.js'], [], []], 'dynamicImports' ); - }); - }); + })); - it('removes tree-shaken dynamic imports', () => { - return rollup + it('removes tree-shaken dynamic imports', () => + rollup .rollup({ input: ['input'], plugins: [ @@ -452,11 +446,10 @@ describe('The bundle object', () => { ], 'modules' ); - }); - }); + })); - it('adds correct flags to files when preserving modules', () => { - return rollup + it('adds correct flags to files when preserving modules', () => + rollup .rollup({ input: ['input', 'dynamic1'], plugins: [ @@ -582,11 +575,10 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') ['input', 'dynamic1', 'dynamic2', 'other'], 'facadeModuleId' ); - }); - }); + })); - it('contains correct information about rendered/removedExports when directly exporting items', () => { - return rollup + it('contains correct information about rendered/removedExports when directly exporting items', () => + rollup .rollup({ input: ['input'], plugins: [ @@ -636,11 +628,10 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') }, 'modules' ); - }); - }); + })); - it('contains correct information about rendered/removedExports when using export declaration', () => { - return rollup + it('contains correct information about rendered/removedExports when using export declaration', () => + rollup .rollup({ input: ['input'], plugins: [ @@ -690,6 +681,5 @@ console.log(other);Promise.all([import('./dynamic1.js'), import('./dynamic2.js') }, 'modules' ); - }); - }); + })); }); diff --git a/test/misc/deprecations.js b/test/misc/deprecations.js index 2882fb8e97d..05235ffe141 100644 --- a/test/misc/deprecations.js +++ b/test/misc/deprecations.js @@ -3,12 +3,11 @@ const rollup = require('../../dist/rollup'); const { loader } = require('../utils.js'); describe('deprecations', () => { - it('supports es format alias', () => { - return rollup + it('supports es format alias', () => + rollup .rollup({ input: 'x', plugins: [loader({ x: 'export const x = function () {}' })] }) .then(bundle => bundle.generate({ format: 'es' })) .then(({ output: [{ code }] }) => { assert.equal(code, 'const x = function () {};\n\nexport { x };\n'); - }); - }); + })); }); diff --git a/test/misc/misc.js b/test/misc/misc.js index 037d9ff0616..7597346481b 100644 --- a/test/misc/misc.js +++ b/test/misc/misc.js @@ -1,6 +1,6 @@ const assert = require('node:assert'); const rollup = require('../../dist/rollup'); -const { assertIncludes, loader } = require('../utils.js'); +const { loader } = require('../utils.js'); describe('misc', () => { it('avoids modification of options or their properties', () => { @@ -122,8 +122,8 @@ describe('misc', () => { plugins: [loader({ x: `console.log( 42 );` }), null, false, undefined] })); - it('handles different import paths for different outputs', () => { - return rollup + it('handles different import paths for different outputs', () => + rollup .rollup({ input: 'x', external: ['the-answer'], @@ -151,8 +151,7 @@ describe('misc', () => { assert.equal(generated.output[0].code, "import 'the-answer';\n", 'no render path 2') ) ]) - ); - }); + )); it('allows passing the same object to `rollup` and `generate`', () => { const options = { @@ -286,7 +285,7 @@ console.log(x); }) ] }); - const first = await bundle.generate({ format: 'iife', inlineDynamicImports: true }); - const second = await bundle.generate({ format: 'es', exports: 'auto' }); + await bundle.generate({ format: 'iife', inlineDynamicImports: true }); + await bundle.generate({ format: 'es', exports: 'auto' }); }); }); diff --git a/test/misc/umd.js b/test/misc/umd.js index fb5e157cc65..37d0e0aaed4 100644 --- a/test/misc/umd.js +++ b/test/misc/umd.js @@ -33,7 +33,7 @@ function runNodeTest(code) { return module.exports; } -function runAmdTest(code, outputOptions) { +function runAmdTest(code) { let defineArguments; function define(...parameters) { defineArguments = parameters; diff --git a/test/typescript/index.ts b/test/typescript/index.ts index 2c34dbdc597..92f4c5cf8b6 100644 --- a/test/typescript/index.ts +++ b/test/typescript/index.ts @@ -7,13 +7,13 @@ interface Options { } const plugin: rollup.PluginImpl = (options = {}) => { - const extensions = options.extensions || ['.js']; + const _extensions = options.extensions || ['.js']; return { name: 'my-plugin', resolveId: { - handler(source, importer, options) { + handler(source, _importer, _options) { // @ts-expect-error source is typed as string - const s: number = source; + const _s: number = source; } } }; @@ -22,29 +22,29 @@ const plugin: rollup.PluginImpl = (options = {}) => { plugin(); plugin({ extensions: ['.js', 'json'] }); -const pluginHooks: rollup.Plugin = { +const _pluginHooks: rollup.Plugin = { buildStart: { handler() {}, sequential: true }, async load(id) { // @ts-expect-error id is typed as string - const index: number = id; + const _index: number = id; await this.resolve('rollup'); }, name: 'test', resolveId: { - async handler(source, importer, options) { + async handler(source, _importer, _options) { await this.resolve('rollup'); // @ts-expect-error source is typed as string - const s: number = source; + const _s: number = source; }, // @ts-expect-error sequential is only supported for parallel hooks sequential: true } }; -const amdOutputOptions: rollup.OutputOptions['amd'][] = [ +const _amdOutputOptions: rollup.OutputOptions['amd'][] = [ {}, { id: 'a' diff --git a/tsconfig.json b/tsconfig.json index 131d042624f..8f8ee12e84a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,6 @@ "module": "ESNext", "moduleResolution": "Node", "noEmitOnError": true, - "noUnusedLocals": true, "noUnusedParameters": true, "pretty": true, "resolveJsonModule": true, From d0e32ac08983138dfcd5d5b70f6a376b6db6742a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 4 Nov 2022 06:32:42 +0100 Subject: [PATCH 06/16] First draft for algorithm --- src/Bundle.ts | 9 +- src/Module.ts | 2 +- src/utils/chunkAssignment.ts | 177 +++++++++++++++++- .../merge-chunk-into-shared/_config.js | 2 +- .../_expected/amd/generated-big.js | 7 - .../_expected/amd/generated-small.js | 3 + .../_expected/amd/main1.js | 4 +- .../_expected/amd/main2.js | 4 +- .../_expected/amd/main3.js | 2 +- .../_expected/cjs/generated-big.js | 5 - .../_expected/cjs/generated-small.js | 3 + .../_expected/cjs/main1.js | 3 +- .../_expected/cjs/main2.js | 3 +- .../_expected/cjs/main3.js | 2 +- .../_expected/system/generated-big.js | 10 - .../_expected/system/generated-small.js | 2 + .../_expected/system/main1.js | 3 +- .../_expected/system/main2.js | 3 +- .../_expected/system/main3.js | 6 +- .../no-merge-side-effects/_config.js | 2 +- 20 files changed, 200 insertions(+), 52 deletions(-) delete mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js delete mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js delete mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js diff --git a/src/Bundle.ts b/src/Bundle.ts index 0fa74c6acbd..5969c4f2891 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -158,7 +158,8 @@ export default class Bundle { bundle: OutputBundleWithPlaceholders, getHashPlaceholder: HashPlaceholderGenerator ): Promise { - const { inlineDynamicImports, manualChunks, preserveModules } = this.outputOptions; + const { experimentalMinChunkSize, inlineDynamicImports, manualChunks, preserveModules } = + this.outputOptions; const manualChunkAliasByEntry = typeof manualChunks === 'object' ? await this.addManualChunks(manualChunks) @@ -177,7 +178,11 @@ export default class Bundle { ? [{ alias: null, modules: includedModules }] : preserveModules ? includedModules.map(module => ({ alias: null, modules: [module] })) - : getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry)) { + : getChunkAssignments( + this.graph.entryModules, + manualChunkAliasByEntry, + experimentalMinChunkSize + )) { sortByExecutionOrder(modules); const chunk = new Chunk( modules, diff --git a/src/Module.ts b/src/Module.ts index 9beefc79190..c7057240875 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -219,6 +219,7 @@ export default class Module { readonly info: ModuleInfo; isExecuted = false; isUserDefinedEntryPoint = false; + declare magicString: MagicString; declare namespace: NamespaceVariable; needsExportShim = false; declare originalCode: string; @@ -241,7 +242,6 @@ export default class Module { private exportNamesByVariable: Map | null = null; private readonly exportShimVariable = new ExportShimVariable(this); private readonly exports = new Map(); - private declare magicString: MagicString; private readonly namespaceReexportsByName = new Map< string, [variable: Variable | null, indirectExternal?: boolean] diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index f4d92526763..d0036366e03 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -1,13 +1,15 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { getOrCreate } from './getOrCreate'; +import relativeId from './relativeId'; type DependentModuleMap = Map>; type ChunkDefinitions = { alias: string | null; modules: Module[] }[]; export function getChunkAssignments( entryModules: readonly Module[], - manualChunkAliasByEntry: ReadonlyMap + manualChunkAliasByEntry: ReadonlyMap, + minChunkSize: number ): ChunkDefinitions { const chunkDefinitions: ChunkDefinitions = []; const modulesInManualChunks = new Set(manualChunkAliasByEntry.keys()); @@ -89,7 +91,11 @@ export function getChunkAssignments( } chunkDefinitions.push( - ...createChunks([...entryModules, ...dynamicEntryModules], assignedEntryPointsByModule) + ...createChunks( + [...entryModules, ...dynamicEntryModules], + assignedEntryPointsByModule, + minChunkSize + ) ); return chunkDefinitions; } @@ -165,15 +171,97 @@ function getDynamicDependentEntryPoints( return dynamicallyDependentEntryPointsByDynamicEntry; } +interface ChunkDescription { + modules: Module[]; + signature: string; + size: number | null; +} + +interface MergeableChunkDescription extends ChunkDescription { + size: number; +} + function createChunks( allEntryPoints: readonly Module[], - assignedEntryPointsByModule: DependentModuleMap + assignedEntryPointsByModule: DependentModuleMap, + minChunkSize: number ): ChunkDefinitions { + const chunkModulesBySignature = getChunkModulesBySignature( + assignedEntryPointsByModule, + allEntryPoints + ); + printChunkModules('chunkModules', chunkModulesBySignature); + if (minChunkSize === 0) { + return Object.values(chunkModulesBySignature).map(modules => ({ + alias: null, + modules + })); + } + + const { chunksToBeMerged, unmergeableChunks } = getMergeableChunks( + chunkModulesBySignature, + minChunkSize + ); + nextChunkToBeMerged: for (const sourceChunk of chunksToBeMerged) { + let closestChunk: ChunkDescription | null = null; + let closestChunkDistance = Infinity; + const { signature, size, modules } = sourceChunk; + for (const targetChunk of chunksToBeMerged) { + if (targetChunk !== sourceChunk) { + const distance = getSignatureDistance(signature, targetChunk.signature); + if (distance === 1) { + // console.log('merge1', signature, 'into', targetChunk.signature); + targetChunk.size += size; + targetChunk.modules.push(...modules); + chunksToBeMerged.delete(sourceChunk); + if (targetChunk.size > minChunkSize) { + chunksToBeMerged.delete(targetChunk); + unmergeableChunks.push(targetChunk); + } + continue nextChunkToBeMerged; + } else if (distance < closestChunkDistance) { + closestChunk = targetChunk; + closestChunkDistance = distance; + } + } + } + for (const targetChunk of unmergeableChunks) { + const distance = getSignatureDistance(signature, targetChunk.signature); + if (distance === 1) { + // console.log('merge2', signature, 'into', targetChunk.signature); + targetChunk.modules.push(...modules); + chunksToBeMerged.delete(sourceChunk); + continue nextChunkToBeMerged; + } else if (distance < closestChunkDistance) { + closestChunk = targetChunk; + closestChunkDistance = distance; + } + } + if (closestChunk) { + // console.log('merge3', signature, 'into', closestChunk.signature); + closestChunk.modules.push(...modules); + chunksToBeMerged.delete(sourceChunk); + } + } + return [...chunksToBeMerged, ...unmergeableChunks].map(({ modules }) => ({ + alias: null, + modules + })); +} + +const CHAR_DEPENDENT = 'X'; +const CHAR_INDEPENDENT = '_'; +const CHAR_CODE_DEPENDENT = CHAR_DEPENDENT.charCodeAt(0); + +function getChunkModulesBySignature( + assignedEntryPointsByModule: Map>, + allEntryPoints: readonly Module[] +) { const chunkModules: { [chunkSignature: string]: Module[] } = Object.create(null); for (const [module, assignedEntryPoints] of assignedEntryPointsByModule) { let chunkSignature = ''; for (const entry of allEntryPoints) { - chunkSignature += assignedEntryPoints.has(entry) ? 'X' : '_'; + chunkSignature += assignedEntryPoints.has(entry) ? CHAR_DEPENDENT : CHAR_INDEPENDENT; } const chunk = chunkModules[chunkSignature]; if (chunk) { @@ -182,8 +270,81 @@ function createChunks( chunkModules[chunkSignature] = [module]; } } - return Object.values(chunkModules).map(modules => ({ - alias: null, - modules - })); + return chunkModules; } + +function getMergeableChunks( + chunkModulesBySignature: { [chunkSignature: string]: Module[] }, + minChunkSize: number +) { + const chunksToBeMerged = new Set(); + const unmergeableChunks: ChunkDescription[] = []; + for (const [signature, modules] of Object.entries(chunkModulesBySignature)) { + let size = 0; + checkModules: { + for (const module of modules) { + if (module.hasEffects()) { + break checkModules; + } + size += module.magicString.toString().length; + if (size > minChunkSize) { + break checkModules; + } + } + chunksToBeMerged.add({ modules, signature, size }); + continue; + } + unmergeableChunks.push({ modules, signature, size: null }); + } + return { chunksToBeMerged, unmergeableChunks }; +} + +function getSignatureDistance(sourceSignature: string, targetSignature: string): number { + let distance = 0; + const { length } = sourceSignature; + for (let index = 0; index < length; index++) { + const sourceValue = sourceSignature.charCodeAt(index); + if (sourceValue !== targetSignature.charCodeAt(index)) { + if (sourceValue === CHAR_CODE_DEPENDENT) { + return Infinity; + } + distance++; + } + } + return distance; +} + +// DEBUGGING HELPERS, REMOVED BY TREE-SHAKING +/* eslint-disable @typescript-eslint/no-unused-vars */ + +const relativeModuleId = (module: Module) => relativeId(module.id); + +const printModuleMap = (label: string, map: DependentModuleMap) => + console.log( + label, + Object.fromEntries( + [...map].map(([module, dependentModules]) => [ + relativeModuleId(module), + [...dependentModules].map(relativeModuleId) + ]) + ) + ); + +const printChunkModules = (label: string, modules: { [chunkSignature: string]: Module[] }) => { + console.log( + label, + Object.fromEntries( + Object.entries(modules).map(([signature, chunkModules]) => [ + signature, + { + hasEffects: chunkModules.some(module => module.hasEffects()), + modules: chunkModules.map(relativeModuleId), + size: chunkModules.reduce( + (size, module) => size + module.magicString.toString().length, + 0 + ) + } + ]) + ) + ); +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js index f83f353ce74..f862373c412 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js @@ -1,5 +1,5 @@ module.exports = { - solo: true, + // solo: true, description: 'merges small chunks into shared chunks that are loaded by a super-set of entry points', options: { diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js deleted file mode 100644 index 1c86c5f3245..00000000000 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-big.js +++ /dev/null @@ -1,7 +0,0 @@ -define(['exports'], (function (exports) { 'use strict'; - - const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; - - exports.big = big; - -})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js index ee89ef5bdf5..1353d019769 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/generated-small.js @@ -1,7 +1,10 @@ define(['exports'], (function (exports) { 'use strict'; + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + const small = '1'; + exports.big = big; exports.small = small; })); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js index 9f1e89308c2..ec8f5125645 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main1.js @@ -1,5 +1,5 @@ -define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; +define(['./generated-small'], (function (small) { 'use strict'; - console.log(big.big, small.small); + console.log(small.big, small.small); })); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js index 9f1e89308c2..ec8f5125645 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main2.js @@ -1,5 +1,5 @@ -define(['./generated-big', './generated-small'], (function (big, small) { 'use strict'; +define(['./generated-small'], (function (small) { 'use strict'; - console.log(big.big, small.small); + console.log(small.big, small.small); })); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js index 87b6a754d97..7691effe419 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/amd/main3.js @@ -1,5 +1,5 @@ define(['./generated-small'], (function (small) { 'use strict'; - console.log(small.small); + console.log(small.big); })); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js deleted file mode 100644 index 02f83e81fc3..00000000000 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-big.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; - -exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js index c7bcc6a74b7..9834f833d9c 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/generated-small.js @@ -1,5 +1,8 @@ 'use strict'; +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + const small = '1'; +exports.big = big; exports.small = small; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js index b3a7679c4a0..8d1efac502d 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main1.js @@ -1,6 +1,5 @@ 'use strict'; -var big = require('./generated-big.js'); var small = require('./generated-small.js'); -console.log(big.big, small.small); +console.log(small.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js index b3a7679c4a0..8d1efac502d 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main2.js @@ -1,6 +1,5 @@ 'use strict'; -var big = require('./generated-big.js'); var small = require('./generated-small.js'); -console.log(big.big, small.small); +console.log(small.big, small.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js index e9f5c811d62..168bfc47fb1 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/cjs/main3.js @@ -2,4 +2,4 @@ var small = require('./generated-small.js'); -console.log(small.small); +console.log(small.big); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js deleted file mode 100644 index c924360b7cd..00000000000 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-big.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], (function (exports) { - 'use strict'; - return { - execute: (function () { - - const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); - - }) - }; -})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js index a446c6116c9..58f4f322104 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/generated-small.js @@ -3,6 +3,8 @@ System.register([], (function (exports) { return { execute: (function () { + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + const small = exports('s', '1'); }) diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js index 1b80803b9e5..d9c93667327 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main1.js @@ -1,10 +1,9 @@ -System.register(['./generated-big.js', './generated-small.js'], (function () { +System.register(['./generated-small.js'], (function () { 'use strict'; var big, small; return { setters: [function (module) { big = module.b; - }, function (module) { small = module.s; }], execute: (function () { diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js index 1b80803b9e5..d9c93667327 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main2.js @@ -1,10 +1,9 @@ -System.register(['./generated-big.js', './generated-small.js'], (function () { +System.register(['./generated-small.js'], (function () { 'use strict'; var big, small; return { setters: [function (module) { big = module.b; - }, function (module) { small = module.s; }], execute: (function () { diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js index 6e93391fab8..90ebf97d750 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_expected/system/main3.js @@ -1,13 +1,13 @@ System.register(['./generated-small.js'], (function () { 'use strict'; - var small; + var big; return { setters: [function (module) { - small = module.s; + big = module.b; }], execute: (function () { - console.log(small); + console.log(big); }) }; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js index ca26c20da09..4349b72b848 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js @@ -1,5 +1,5 @@ module.exports = { - solo: true, + // solo: true, description: 'does not merge small chunks that have side effects', options: { input: ['main1.js', 'main2.js', 'main3.js'], From 7f7d8ebd6e9c3be0ab06f98e149aae1db1f96fa3 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 4 Nov 2022 21:02:20 +0100 Subject: [PATCH 07/16] Start adding tests --- src/utils/chunkAssignment.ts | 40 +++++++++++++++++-- .../merge-chunk-into-shared/_config.js | 2 +- .../merge-three-small-chunks-a/_config.js | 10 +++++ .../_expected/amd/generated-big.js | 7 ++++ .../_expected/amd/generated-small3.js | 13 ++++++ .../_expected/amd/main1.js | 5 +++ .../_expected/amd/main2.js | 5 +++ .../_expected/amd/main3.js | 5 +++ .../_expected/amd/main4.js | 5 +++ .../_expected/amd/main5.js | 5 +++ .../_expected/cjs/generated-big.js | 5 +++ .../_expected/cjs/generated-small3.js | 11 +++++ .../_expected/cjs/main1.js | 6 +++ .../_expected/cjs/main2.js | 6 +++ .../_expected/cjs/main3.js | 6 +++ .../_expected/cjs/main4.js | 6 +++ .../_expected/cjs/main5.js | 5 +++ .../_expected/es/generated-big.js | 3 ++ .../_expected/es/generated-small3.js | 7 ++++ .../_expected/es/main1.js | 4 ++ .../_expected/es/main2.js | 4 ++ .../_expected/es/main3.js | 4 ++ .../_expected/es/main4.js | 4 ++ .../_expected/es/main5.js | 3 ++ .../_expected/system/generated-big.js | 10 +++++ .../_expected/system/generated-small3.js | 14 +++++++ .../_expected/system/main1.js | 18 +++++++++ .../_expected/system/main2.js | 18 +++++++++ .../_expected/system/main3.js | 17 ++++++++ .../_expected/system/main4.js | 16 ++++++++ .../_expected/system/main5.js | 14 +++++++ .../merge-three-small-chunks-a/big.js | 1 + .../merge-three-small-chunks-a/main1.js | 6 +++ .../merge-three-small-chunks-a/main2.js | 6 +++ .../merge-three-small-chunks-a/main3.js | 5 +++ .../merge-three-small-chunks-a/main4.js | 4 ++ .../merge-three-small-chunks-a/main5.js | 3 ++ .../merge-three-small-chunks-a/small1.js | 1 + .../merge-three-small-chunks-a/small2.js | 1 + .../merge-three-small-chunks-a/small3.js | 1 + .../merge-three-small-chunks-b/_config.js | 10 +++++ .../_expected/amd/generated-big.js | 7 ++++ .../_expected/amd/generated-small1.js | 13 ++++++ .../_expected/amd/main1.js | 5 +++ .../_expected/amd/main2.js | 5 +++ .../_expected/amd/main3.js | 5 +++ .../_expected/amd/main4.js | 5 +++ .../_expected/amd/main5.js | 5 +++ .../_expected/cjs/generated-big.js | 5 +++ .../_expected/cjs/generated-small1.js | 11 +++++ .../_expected/cjs/main1.js | 6 +++ .../_expected/cjs/main2.js | 6 +++ .../_expected/cjs/main3.js | 6 +++ .../_expected/cjs/main4.js | 6 +++ .../_expected/cjs/main5.js | 5 +++ .../_expected/es/generated-big.js | 3 ++ .../_expected/es/generated-small1.js | 7 ++++ .../_expected/es/main1.js | 4 ++ .../_expected/es/main2.js | 4 ++ .../_expected/es/main3.js | 4 ++ .../_expected/es/main4.js | 4 ++ .../_expected/es/main5.js | 3 ++ .../_expected/system/generated-big.js | 10 +++++ .../_expected/system/generated-small1.js | 14 +++++++ .../_expected/system/main1.js | 18 +++++++++ .../_expected/system/main2.js | 18 +++++++++ .../_expected/system/main3.js | 17 ++++++++ .../_expected/system/main4.js | 16 ++++++++ .../_expected/system/main5.js | 14 +++++++ .../merge-three-small-chunks-b/big.js | 1 + .../merge-three-small-chunks-b/main1.js | 6 +++ .../merge-three-small-chunks-b/main2.js | 6 +++ .../merge-three-small-chunks-b/main3.js | 5 +++ .../merge-three-small-chunks-b/main4.js | 4 ++ .../merge-three-small-chunks-b/main5.js | 3 ++ .../merge-three-small-chunks-b/small1.js | 1 + .../merge-three-small-chunks-b/small2.js | 1 + .../merge-three-small-chunks-b/small3.js | 1 + .../merge-two-small-chunks-a/_config.js | 10 +++++ .../_expected/amd/generated-big.js | 7 ++++ .../_expected/amd/generated-small2.js | 10 +++++ .../_expected/amd/main1.js | 5 +++ .../_expected/amd/main2.js | 5 +++ .../_expected/amd/main3.js | 5 +++ .../_expected/amd/main4.js | 5 +++ .../_expected/cjs/generated-big.js | 5 +++ .../_expected/cjs/generated-small2.js | 8 ++++ .../_expected/cjs/main1.js | 6 +++ .../_expected/cjs/main2.js | 6 +++ .../_expected/cjs/main3.js | 6 +++ .../_expected/cjs/main4.js | 5 +++ .../_expected/es/generated-big.js | 3 ++ .../_expected/es/generated-small2.js | 5 +++ .../_expected/es/main1.js | 4 ++ .../_expected/es/main2.js | 4 ++ .../_expected/es/main3.js | 4 ++ .../_expected/es/main4.js | 3 ++ .../_expected/system/generated-big.js | 10 +++++ .../_expected/system/generated-small2.js | 12 ++++++ .../_expected/system/main1.js | 17 ++++++++ .../_expected/system/main2.js | 17 ++++++++ .../_expected/system/main3.js | 16 ++++++++ .../_expected/system/main4.js | 14 +++++++ .../merge-two-small-chunks-a/big.js | 1 + .../merge-two-small-chunks-a/main1.js | 5 +++ .../merge-two-small-chunks-a/main2.js | 5 +++ .../merge-two-small-chunks-a/main3.js | 4 ++ .../merge-two-small-chunks-a/main4.js | 3 ++ .../merge-two-small-chunks-a/small1.js | 1 + .../merge-two-small-chunks-a/small2.js | 1 + .../merge-two-small-chunks-b/_config.js | 10 +++++ .../_expected/amd/generated-big.js | 7 ++++ .../_expected/amd/generated-small2.js | 10 +++++ .../_expected/amd/main1.js | 5 +++ .../_expected/amd/main2.js | 5 +++ .../_expected/amd/main3.js | 5 +++ .../_expected/amd/main4.js | 5 +++ .../_expected/cjs/generated-big.js | 5 +++ .../_expected/cjs/generated-small2.js | 8 ++++ .../_expected/cjs/main1.js | 6 +++ .../_expected/cjs/main2.js | 6 +++ .../_expected/cjs/main3.js | 6 +++ .../_expected/cjs/main4.js | 5 +++ .../_expected/es/generated-big.js | 3 ++ .../_expected/es/generated-small2.js | 5 +++ .../_expected/es/main1.js | 4 ++ .../_expected/es/main2.js | 4 ++ .../_expected/es/main3.js | 4 ++ .../_expected/es/main4.js | 3 ++ .../_expected/system/generated-big.js | 10 +++++ .../_expected/system/generated-small2.js | 12 ++++++ .../_expected/system/main1.js | 17 ++++++++ .../_expected/system/main2.js | 17 ++++++++ .../_expected/system/main3.js | 16 ++++++++ .../_expected/system/main4.js | 14 +++++++ .../merge-two-small-chunks-b/big.js | 1 + .../merge-two-small-chunks-b/main1.js | 5 +++ .../merge-two-small-chunks-b/main2.js | 5 +++ .../merge-two-small-chunks-b/main3.js | 4 ++ .../merge-two-small-chunks-b/main4.js | 3 ++ .../merge-two-small-chunks-b/small1.js | 1 + .../merge-two-small-chunks-b/small2.js | 1 + .../no-merge-side-effects/_config.js | 2 +- 143 files changed, 990 insertions(+), 6 deletions(-) create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/big.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small2.js diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index d0036366e03..4d19634ea74 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -202,17 +202,40 @@ function createChunks( chunkModulesBySignature, minChunkSize ); + // TODO Lukas merge unrelated chunks? + console.log( + 'toBeMerged', + [...chunksToBeMerged].map(({ modules, signature }) => ({ + modules: modules.map(relativeModuleId), + signature + })) + ); nextChunkToBeMerged: for (const sourceChunk of chunksToBeMerged) { + console.log('check chunk', sourceChunk.signature, sourceChunk.modules.map(relativeModuleId)); let closestChunk: ChunkDescription | null = null; let closestChunkDistance = Infinity; + let reverseClosestChunkMerge = false; const { signature, size, modules } = sourceChunk; for (const targetChunk of chunksToBeMerged) { if (targetChunk !== sourceChunk) { - const distance = getSignatureDistance(signature, targetChunk.signature); + let needsReversedMerge = false; + let distance = getSignatureDistance(signature, targetChunk.signature); + if (distance === Infinity) { + needsReversedMerge = true; + distance = getSignatureDistance(targetChunk.signature, signature); + } if (distance === 1) { - // console.log('merge1', signature, 'into', targetChunk.signature); + console.log( + 'merge into', + targetChunk.signature, + targetChunk.modules.map(relativeModuleId), + targetChunk.size + ); targetChunk.size += size; targetChunk.modules.push(...modules); + if (needsReversedMerge) { + targetChunk.signature = signature; + } chunksToBeMerged.delete(sourceChunk); if (targetChunk.size > minChunkSize) { chunksToBeMerged.delete(targetChunk); @@ -222,25 +245,34 @@ function createChunks( } else if (distance < closestChunkDistance) { closestChunk = targetChunk; closestChunkDistance = distance; + reverseClosestChunkMerge = needsReversedMerge; + throw new Error('10'); + } else { + // throw new Error('11'); } } } for (const targetChunk of unmergeableChunks) { const distance = getSignatureDistance(signature, targetChunk.signature); if (distance === 1) { - // console.log('merge2', signature, 'into', targetChunk.signature); targetChunk.modules.push(...modules); chunksToBeMerged.delete(sourceChunk); continue nextChunkToBeMerged; } else if (distance < closestChunkDistance) { closestChunk = targetChunk; closestChunkDistance = distance; + reverseClosestChunkMerge = false; } } if (closestChunk) { - // console.log('merge3', signature, 'into', closestChunk.signature); closestChunk.modules.push(...modules); + if (reverseClosestChunkMerge) { + closestChunk.signature = signature; + throw new Error('17'); + } chunksToBeMerged.delete(sourceChunk); + } else { + // throw new Error('19'); } } return [...chunksToBeMerged, ...unmergeableChunks].map(({ modules }) => ({ diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js index f862373c412..f83f353ce74 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js @@ -1,5 +1,5 @@ module.exports = { - // solo: true, + solo: true, description: 'merges small chunks into shared chunks that are loaded by a super-set of entry points', options: { diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js new file mode 100644 index 00000000000..cb2c4d9d513 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'merges small chunks into other small chunks first before merging into a big chunk', + options: { + input: ['main1.js', 'main2.js', 'main3.js', 'main4.js', 'main5.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-small3.js new file mode 100644 index 00000000000..625da1771ec --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/generated-small3.js @@ -0,0 +1,13 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small1 = '123456789012345678901234567890'; + + const small2 = '123456789012345678901234567890'; + + const small3 = '123456789012345678901234567890'; + + exports.small1 = small1; + exports.small2 = small2; + exports.small3 = small3; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main1.js new file mode 100644 index 00000000000..d0d2cfb93b8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small3'], (function (big, small3) { 'use strict'; + + console.log(big.big, small3.small1, small3.small2, small3.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main2.js new file mode 100644 index 00000000000..d0d2cfb93b8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small3'], (function (big, small3) { 'use strict'; + + console.log(big.big, small3.small1, small3.small2, small3.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main3.js new file mode 100644 index 00000000000..9d2010b95eb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small3'], (function (big, small3) { 'use strict'; + + console.log(big.big, small3.small1, small3.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main4.js new file mode 100644 index 00000000000..7312a27862b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small3'], (function (big, small3) { 'use strict'; + + console.log(big.big, small3.small1); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main5.js new file mode 100644 index 00000000000..1bddbc92f18 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/amd/main5.js @@ -0,0 +1,5 @@ +define(['./generated-big'], (function (big) { 'use strict'; + + console.log(big.big); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-small3.js new file mode 100644 index 00000000000..87d7d067ca9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/generated-small3.js @@ -0,0 +1,11 @@ +'use strict'; + +const small1 = '123456789012345678901234567890'; + +const small2 = '123456789012345678901234567890'; + +const small3 = '123456789012345678901234567890'; + +exports.small1 = small1; +exports.small2 = small2; +exports.small3 = small3; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main1.js new file mode 100644 index 00000000000..d9f3890d96c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small3 = require('./generated-small3.js'); + +console.log(big.big, small3.small1, small3.small2, small3.small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main2.js new file mode 100644 index 00000000000..d9f3890d96c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small3 = require('./generated-small3.js'); + +console.log(big.big, small3.small1, small3.small2, small3.small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main3.js new file mode 100644 index 00000000000..73003dba83d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main3.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small3 = require('./generated-small3.js'); + +console.log(big.big, small3.small1, small3.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main4.js new file mode 100644 index 00000000000..6fcbd15c395 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main4.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small3 = require('./generated-small3.js'); + +console.log(big.big, small3.small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main5.js new file mode 100644 index 00000000000..5a574b96fe4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/cjs/main5.js @@ -0,0 +1,5 @@ +'use strict'; + +var big = require('./generated-big.js'); + +console.log(big.big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-big.js new file mode 100644 index 00000000000..f26e52dae36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-big.js @@ -0,0 +1,3 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +export { big as b }; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-small3.js new file mode 100644 index 00000000000..93e17caa740 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/generated-small3.js @@ -0,0 +1,7 @@ +const small1 = '123456789012345678901234567890'; + +const small2 = '123456789012345678901234567890'; + +const small3 = '123456789012345678901234567890'; + +export { small2 as a, small3 as b, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main1.js new file mode 100644 index 00000000000..caa52941627 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main1.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2, b as small3 } from './generated-small3.js'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main2.js new file mode 100644 index 00000000000..caa52941627 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main2.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2, b as small3 } from './generated-small3.js'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main3.js new file mode 100644 index 00000000000..da18f44ef36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main3.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small3.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main4.js new file mode 100644 index 00000000000..49c455f0f55 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main4.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1 } from './generated-small3.js'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main5.js new file mode 100644 index 00000000000..00748695997 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/es/main5.js @@ -0,0 +1,3 @@ +import { b as big } from './generated-big.js'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-small3.js new file mode 100644 index 00000000000..472c8458bcb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/generated-small3.js @@ -0,0 +1,14 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small1 = exports('s', '123456789012345678901234567890'); + + const small2 = exports('a', '123456789012345678901234567890'); + + const small3 = exports('b', '123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main1.js new file mode 100644 index 00000000000..0eac3017079 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main1.js @@ -0,0 +1,18 @@ +System.register(['./generated-big.js', './generated-small3.js'], (function () { + 'use strict'; + var big, small1, small2, small3; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + small3 = module.b; + }], + execute: (function () { + + console.log(big, small1, small2, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main2.js new file mode 100644 index 00000000000..0eac3017079 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main2.js @@ -0,0 +1,18 @@ +System.register(['./generated-big.js', './generated-small3.js'], (function () { + 'use strict'; + var big, small1, small2, small3; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + small3 = module.b; + }], + execute: (function () { + + console.log(big, small1, small2, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main3.js new file mode 100644 index 00000000000..a468ee7d78b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main3.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small3.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main4.js new file mode 100644 index 00000000000..9a715d3675e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main4.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small3.js'], (function () { + 'use strict'; + var big, small1; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + }], + execute: (function () { + + console.log(big, small1); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main5.js new file mode 100644 index 00000000000..9d92d0a9972 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_expected/system/main5.js @@ -0,0 +1,14 @@ +System.register(['./generated-big.js'], (function () { + 'use strict'; + var big; + return { + setters: [function (module) { + big = module.b; + }], + execute: (function () { + + console.log(big); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main1.js new file mode 100644 index 00000000000..e70a88fd206 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main1.js @@ -0,0 +1,6 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; +import { small3 } from './small3'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main2.js new file mode 100644 index 00000000000..e70a88fd206 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main2.js @@ -0,0 +1,6 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; +import { small3 } from './small3'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main3.js new file mode 100644 index 00000000000..fdd9ede4919 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main3.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main4.js new file mode 100644 index 00000000000..c1f7ef30971 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main4.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small1 } from './small1'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main5.js new file mode 100644 index 00000000000..99752c1c3b4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/main5.js @@ -0,0 +1,3 @@ +import { big } from './big'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small1.js new file mode 100644 index 00000000000..c904f7abf7f --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small1.js @@ -0,0 +1 @@ +export const small1 = '123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small2.js new file mode 100644 index 00000000000..5e0bda4f9dc --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small2.js @@ -0,0 +1 @@ +export const small2 = '123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small3.js new file mode 100644 index 00000000000..7f85958f33f --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/small3.js @@ -0,0 +1 @@ +export const small3 = '123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js new file mode 100644 index 00000000000..cb2c4d9d513 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'merges small chunks into other small chunks first before merging into a big chunk', + options: { + input: ['main1.js', 'main2.js', 'main3.js', 'main4.js', 'main5.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-small1.js new file mode 100644 index 00000000000..d9c528caa84 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/generated-small1.js @@ -0,0 +1,13 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small3 = '12345678901234567890'; + + const small2 = '12345678901234567890'; + + const small1 = '12345678901234567890'; + + exports.small1 = small1; + exports.small2 = small2; + exports.small3 = small3; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main1.js new file mode 100644 index 00000000000..5df77865a27 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small1'], (function (big, small1) { 'use strict'; + + console.log(big.big, small1.small1, small1.small2, small1.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main2.js new file mode 100644 index 00000000000..5df77865a27 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small1'], (function (big, small1) { 'use strict'; + + console.log(big.big, small1.small1, small1.small2, small1.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main3.js new file mode 100644 index 00000000000..b0a3dab9e69 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small1'], (function (big, small1) { 'use strict'; + + console.log(big.big, small1.small1, small1.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main4.js new file mode 100644 index 00000000000..446e8f47e4b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small1'], (function (big, small1) { 'use strict'; + + console.log(big.big, small1.small1); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main5.js new file mode 100644 index 00000000000..1bddbc92f18 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/amd/main5.js @@ -0,0 +1,5 @@ +define(['./generated-big'], (function (big) { 'use strict'; + + console.log(big.big); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-small1.js new file mode 100644 index 00000000000..a5ceab98a97 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/generated-small1.js @@ -0,0 +1,11 @@ +'use strict'; + +const small3 = '12345678901234567890'; + +const small2 = '12345678901234567890'; + +const small1 = '12345678901234567890'; + +exports.small1 = small1; +exports.small2 = small2; +exports.small3 = small3; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main1.js new file mode 100644 index 00000000000..bb36b0d98c0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small1 = require('./generated-small1.js'); + +console.log(big.big, small1.small1, small1.small2, small1.small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main2.js new file mode 100644 index 00000000000..bb36b0d98c0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small1 = require('./generated-small1.js'); + +console.log(big.big, small1.small1, small1.small2, small1.small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main3.js new file mode 100644 index 00000000000..8c1c9e18ea4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main3.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small1 = require('./generated-small1.js'); + +console.log(big.big, small1.small1, small1.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main4.js new file mode 100644 index 00000000000..33d5232d2ab --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main4.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small1 = require('./generated-small1.js'); + +console.log(big.big, small1.small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main5.js new file mode 100644 index 00000000000..5a574b96fe4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/cjs/main5.js @@ -0,0 +1,5 @@ +'use strict'; + +var big = require('./generated-big.js'); + +console.log(big.big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-big.js new file mode 100644 index 00000000000..f26e52dae36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-big.js @@ -0,0 +1,3 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +export { big as b }; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-small1.js new file mode 100644 index 00000000000..a0e70170a83 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/generated-small1.js @@ -0,0 +1,7 @@ +const small3 = '12345678901234567890'; + +const small2 = '12345678901234567890'; + +const small1 = '12345678901234567890'; + +export { small2 as a, small3 as b, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main1.js new file mode 100644 index 00000000000..4f2df12daa4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main1.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2, b as small3 } from './generated-small1.js'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main2.js new file mode 100644 index 00000000000..4f2df12daa4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main2.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2, b as small3 } from './generated-small1.js'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main3.js new file mode 100644 index 00000000000..38a9dbbe51a --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main3.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small1.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main4.js new file mode 100644 index 00000000000..5ca874ae49a --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main4.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1 } from './generated-small1.js'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main5.js new file mode 100644 index 00000000000..00748695997 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/es/main5.js @@ -0,0 +1,3 @@ +import { b as big } from './generated-big.js'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-small1.js new file mode 100644 index 00000000000..f473b370ca8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/generated-small1.js @@ -0,0 +1,14 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small3 = exports('b', '12345678901234567890'); + + const small2 = exports('a', '12345678901234567890'); + + const small1 = exports('s', '12345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main1.js new file mode 100644 index 00000000000..fe599e7228c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main1.js @@ -0,0 +1,18 @@ +System.register(['./generated-big.js', './generated-small1.js'], (function () { + 'use strict'; + var big, small1, small2, small3; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + small3 = module.b; + }], + execute: (function () { + + console.log(big, small1, small2, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main2.js new file mode 100644 index 00000000000..fe599e7228c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main2.js @@ -0,0 +1,18 @@ +System.register(['./generated-big.js', './generated-small1.js'], (function () { + 'use strict'; + var big, small1, small2, small3; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + small3 = module.b; + }], + execute: (function () { + + console.log(big, small1, small2, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main3.js new file mode 100644 index 00000000000..d60c23e1ce3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main3.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small1.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main4.js new file mode 100644 index 00000000000..6cd5881a16c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main4.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small1.js'], (function () { + 'use strict'; + var big, small1; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + }], + execute: (function () { + + console.log(big, small1); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main5.js new file mode 100644 index 00000000000..9d92d0a9972 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_expected/system/main5.js @@ -0,0 +1,14 @@ +System.register(['./generated-big.js'], (function () { + 'use strict'; + var big; + return { + setters: [function (module) { + big = module.b; + }], + execute: (function () { + + console.log(big); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/big.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main1.js new file mode 100644 index 00000000000..862c33c94df --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main1.js @@ -0,0 +1,6 @@ +import { big } from './big'; +import { small3 } from './small3'; +import { small2 } from './small2'; +import { small1 } from './small1'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main2.js new file mode 100644 index 00000000000..862c33c94df --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main2.js @@ -0,0 +1,6 @@ +import { big } from './big'; +import { small3 } from './small3'; +import { small2 } from './small2'; +import { small1 } from './small1'; + +console.log(big, small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main3.js new file mode 100644 index 00000000000..9d7a846ceee --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main3.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small2 } from './small2'; +import { small1 } from './small1'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main4.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main4.js new file mode 100644 index 00000000000..c1f7ef30971 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main4.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small1 } from './small1'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main5.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main5.js new file mode 100644 index 00000000000..99752c1c3b4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/main5.js @@ -0,0 +1,3 @@ +import { big } from './big'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small1.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small1.js new file mode 100644 index 00000000000..252f8149a51 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small1.js @@ -0,0 +1 @@ +export const small1 = '12345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small2.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small2.js new file mode 100644 index 00000000000..b0de5c31cd3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small2.js @@ -0,0 +1 @@ +export const small2 = '12345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small3.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small3.js new file mode 100644 index 00000000000..16389e0bbd3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/small3.js @@ -0,0 +1 @@ +export const small3 = '12345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js new file mode 100644 index 00000000000..83edf5b8bc9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'merges small chunks into other small chunks first before merging into a big chunk', + options: { + input: ['main1.js', 'main2.js', 'main3.js', 'main4.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-small2.js new file mode 100644 index 00000000000..2f2c139dfb3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/generated-small2.js @@ -0,0 +1,10 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small1 = '12345678901234567890123456789012345678901234567890'; + + const small2 = '12345678901234567890123456789012345678901234567890'; + + exports.small1 = small1; + exports.small2 = small2; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main1.js new file mode 100644 index 00000000000..bc4923ac6d3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small1, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main2.js new file mode 100644 index 00000000000..bc4923ac6d3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small1, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main3.js new file mode 100644 index 00000000000..8e153b9ed3b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small1); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main4.js new file mode 100644 index 00000000000..1bddbc92f18 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-big'], (function (big) { 'use strict'; + + console.log(big.big); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-small2.js new file mode 100644 index 00000000000..2de161519be --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/generated-small2.js @@ -0,0 +1,8 @@ +'use strict'; + +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small2 = '12345678901234567890123456789012345678901234567890'; + +exports.small1 = small1; +exports.small2 = small2; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main1.js new file mode 100644 index 00000000000..5568961ddb9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small1, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main2.js new file mode 100644 index 00000000000..5568961ddb9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small1, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main3.js new file mode 100644 index 00000000000..5e0f9817ff2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main3.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main4.js new file mode 100644 index 00000000000..5a574b96fe4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/cjs/main4.js @@ -0,0 +1,5 @@ +'use strict'; + +var big = require('./generated-big.js'); + +console.log(big.big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-big.js new file mode 100644 index 00000000000..f26e52dae36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-big.js @@ -0,0 +1,3 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +export { big as b }; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-small2.js new file mode 100644 index 00000000000..f553b8cf7b9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/generated-small2.js @@ -0,0 +1,5 @@ +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small2 = '12345678901234567890123456789012345678901234567890'; + +export { small2 as a, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main1.js new file mode 100644 index 00000000000..c1241a35e57 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main1.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small2.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main2.js new file mode 100644 index 00000000000..c1241a35e57 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main2.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small2.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main3.js new file mode 100644 index 00000000000..faec0a7604b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main3.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1 } from './generated-small2.js'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main4.js new file mode 100644 index 00000000000..00748695997 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/es/main4.js @@ -0,0 +1,3 @@ +import { b as big } from './generated-big.js'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-small2.js new file mode 100644 index 00000000000..e873de9734e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/generated-small2.js @@ -0,0 +1,12 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small1 = exports('s', '12345678901234567890123456789012345678901234567890'); + + const small2 = exports('a', '12345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main1.js new file mode 100644 index 00000000000..4a0d3a436f0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main1.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main2.js new file mode 100644 index 00000000000..4a0d3a436f0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main2.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main3.js new file mode 100644 index 00000000000..d6bdd772385 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main3.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small1; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + }], + execute: (function () { + + console.log(big, small1); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main4.js new file mode 100644 index 00000000000..9d92d0a9972 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_expected/system/main4.js @@ -0,0 +1,14 @@ +System.register(['./generated-big.js'], (function () { + 'use strict'; + var big; + return { + setters: [function (module) { + big = module.b; + }], + execute: (function () { + + console.log(big); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main1.js new file mode 100644 index 00000000000..fdd9ede4919 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main1.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main2.js new file mode 100644 index 00000000000..fdd9ede4919 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main2.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main3.js new file mode 100644 index 00000000000..c1f7ef30971 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main3.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small1 } from './small1'; + +console.log(big, small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main4.js new file mode 100644 index 00000000000..99752c1c3b4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/main4.js @@ -0,0 +1,3 @@ +import { big } from './big'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small1.js new file mode 100644 index 00000000000..076d519a29d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small1.js @@ -0,0 +1 @@ +export const small1 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small2.js new file mode 100644 index 00000000000..1baf7456bcb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/small2.js @@ -0,0 +1 @@ +export const small2 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js new file mode 100644 index 00000000000..83edf5b8bc9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'merges small chunks into other small chunks first before merging into a big chunk', + options: { + input: ['main1.js', 'main2.js', 'main3.js', 'main4.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-big.js new file mode 100644 index 00000000000..1c86c5f3245 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-big.js @@ -0,0 +1,7 @@ +define(['exports'], (function (exports) { 'use strict'; + + const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + + exports.big = big; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-small2.js new file mode 100644 index 00000000000..2f2c139dfb3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/generated-small2.js @@ -0,0 +1,10 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small1 = '12345678901234567890123456789012345678901234567890'; + + const small2 = '12345678901234567890123456789012345678901234567890'; + + exports.small1 = small1; + exports.small2 = small2; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main1.js new file mode 100644 index 00000000000..bc4923ac6d3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small1, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main2.js new file mode 100644 index 00000000000..bc4923ac6d3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small1, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main3.js new file mode 100644 index 00000000000..8e5db6f86a2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-big', './generated-small2'], (function (big, small2) { 'use strict'; + + console.log(big.big, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main4.js new file mode 100644 index 00000000000..1bddbc92f18 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-big'], (function (big) { 'use strict'; + + console.log(big.big); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-big.js new file mode 100644 index 00000000000..02f83e81fc3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-big.js @@ -0,0 +1,5 @@ +'use strict'; + +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +exports.big = big; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-small2.js new file mode 100644 index 00000000000..2de161519be --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/generated-small2.js @@ -0,0 +1,8 @@ +'use strict'; + +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small2 = '12345678901234567890123456789012345678901234567890'; + +exports.small1 = small1; +exports.small2 = small2; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main1.js new file mode 100644 index 00000000000..5568961ddb9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main1.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small1, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main2.js new file mode 100644 index 00000000000..5568961ddb9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main2.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small1, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main3.js new file mode 100644 index 00000000000..123fd6d3984 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main3.js @@ -0,0 +1,6 @@ +'use strict'; + +var big = require('./generated-big.js'); +var small2 = require('./generated-small2.js'); + +console.log(big.big, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main4.js new file mode 100644 index 00000000000..5a574b96fe4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/cjs/main4.js @@ -0,0 +1,5 @@ +'use strict'; + +var big = require('./generated-big.js'); + +console.log(big.big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-big.js new file mode 100644 index 00000000000..f26e52dae36 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-big.js @@ -0,0 +1,3 @@ +const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; + +export { big as b }; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-small2.js new file mode 100644 index 00000000000..f553b8cf7b9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/generated-small2.js @@ -0,0 +1,5 @@ +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small2 = '12345678901234567890123456789012345678901234567890'; + +export { small2 as a, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main1.js new file mode 100644 index 00000000000..c1241a35e57 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main1.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small2.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main2.js new file mode 100644 index 00000000000..c1241a35e57 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main2.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { s as small1, a as small2 } from './generated-small2.js'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main3.js new file mode 100644 index 00000000000..665add312b7 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main3.js @@ -0,0 +1,4 @@ +import { b as big } from './generated-big.js'; +import { a as small2 } from './generated-small2.js'; + +console.log(big, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main4.js new file mode 100644 index 00000000000..00748695997 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/es/main4.js @@ -0,0 +1,3 @@ +import { b as big } from './generated-big.js'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-big.js new file mode 100644 index 00000000000..c924360b7cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-big.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const big = exports('b', '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-small2.js new file mode 100644 index 00000000000..e873de9734e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/generated-small2.js @@ -0,0 +1,12 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small1 = exports('s', '12345678901234567890123456789012345678901234567890'); + + const small2 = exports('a', '12345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main1.js new file mode 100644 index 00000000000..4a0d3a436f0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main1.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main2.js new file mode 100644 index 00000000000..4a0d3a436f0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main2.js @@ -0,0 +1,17 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small1, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(big, small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main3.js new file mode 100644 index 00000000000..065b4d1c19e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main3.js @@ -0,0 +1,16 @@ +System.register(['./generated-big.js', './generated-small2.js'], (function () { + 'use strict'; + var big, small2; + return { + setters: [function (module) { + big = module.b; + }, function (module) { + small2 = module.a; + }], + execute: (function () { + + console.log(big, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main4.js new file mode 100644 index 00000000000..9d92d0a9972 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_expected/system/main4.js @@ -0,0 +1,14 @@ +System.register(['./generated-big.js'], (function () { + 'use strict'; + var big; + return { + setters: [function (module) { + big = module.b; + }], + execute: (function () { + + console.log(big); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/big.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/big.js new file mode 100644 index 00000000000..aa804924cba --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/big.js @@ -0,0 +1 @@ +export const big = '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main1.js new file mode 100644 index 00000000000..fdd9ede4919 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main1.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main2.js new file mode 100644 index 00000000000..fdd9ede4919 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main2.js @@ -0,0 +1,5 @@ +import { big } from './big'; +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(big, small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main3.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main3.js new file mode 100644 index 00000000000..2071c835839 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main3.js @@ -0,0 +1,4 @@ +import { big } from './big'; +import { small2 } from './small2'; + +console.log(big, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main4.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main4.js new file mode 100644 index 00000000000..99752c1c3b4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/main4.js @@ -0,0 +1,3 @@ +import { big } from './big'; + +console.log(big); diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small1.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small1.js new file mode 100644 index 00000000000..076d519a29d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small1.js @@ -0,0 +1 @@ +export const small1 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small2.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small2.js new file mode 100644 index 00000000000..1baf7456bcb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/small2.js @@ -0,0 +1 @@ +export const small2 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js index 4349b72b848..ca26c20da09 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js @@ -1,5 +1,5 @@ module.exports = { - // solo: true, + solo: true, description: 'does not merge small chunks that have side effects', options: { input: ['main1.js', 'main2.js', 'main3.js'], From 53d928bbd5191f752a2e5562e102a21923edd8e6 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 5 Nov 2022 12:56:52 +0100 Subject: [PATCH 08/16] Refine implementation --- src/utils/chunkAssignment.ts | 111 ++++++++---------- .../minChunkSize/best-merge-target/_config.js | 20 ++++ .../_expected/amd/generated-small3.js | 10 ++ .../_expected/amd/generated-small4.js | 10 ++ .../best-merge-target/_expected/amd/main1.js | 5 + .../best-merge-target/_expected/amd/main2.js | 5 + .../best-merge-target/_expected/amd/main3.js | 5 + .../best-merge-target/_expected/amd/main4.js | 5 + .../best-merge-target/_expected/amd/main5.js | 5 + .../best-merge-target/_expected/amd/main6.js | 5 + .../best-merge-target/_expected/amd/main7.js | 5 + .../best-merge-target/_expected/amd/main8.js | 5 + .../best-merge-target/_expected/amd/main9.js | 5 + .../_expected/cjs/generated-small3.js | 8 ++ .../_expected/cjs/generated-small4.js | 8 ++ .../best-merge-target/_expected/cjs/main1.js | 5 + .../best-merge-target/_expected/cjs/main2.js | 5 + .../best-merge-target/_expected/cjs/main3.js | 6 + .../best-merge-target/_expected/cjs/main4.js | 6 + .../best-merge-target/_expected/cjs/main5.js | 6 + .../best-merge-target/_expected/cjs/main6.js | 5 + .../best-merge-target/_expected/cjs/main7.js | 5 + .../best-merge-target/_expected/cjs/main8.js | 5 + .../best-merge-target/_expected/cjs/main9.js | 5 + .../_expected/es/generated-small3.js | 5 + .../_expected/es/generated-small4.js | 5 + .../best-merge-target/_expected/es/main1.js | 3 + .../best-merge-target/_expected/es/main2.js | 3 + .../best-merge-target/_expected/es/main3.js | 4 + .../best-merge-target/_expected/es/main4.js | 4 + .../best-merge-target/_expected/es/main5.js | 4 + .../best-merge-target/_expected/es/main6.js | 3 + .../best-merge-target/_expected/es/main7.js | 3 + .../best-merge-target/_expected/es/main8.js | 3 + .../best-merge-target/_expected/es/main9.js | 3 + .../_expected/system/generated-small3.js | 12 ++ .../_expected/system/generated-small4.js | 12 ++ .../_expected/system/main1.js | 15 +++ .../_expected/system/main2.js | 15 +++ .../_expected/system/main3.js | 17 +++ .../_expected/system/main4.js | 17 +++ .../_expected/system/main5.js | 18 +++ .../_expected/system/main6.js | 14 +++ .../_expected/system/main7.js | 14 +++ .../_expected/system/main8.js | 14 +++ .../_expected/system/main9.js | 14 +++ .../minChunkSize/best-merge-target/main1.js | 4 + .../minChunkSize/best-merge-target/main2.js | 4 + .../minChunkSize/best-merge-target/main3.js | 5 + .../minChunkSize/best-merge-target/main4.js | 5 + .../minChunkSize/best-merge-target/main5.js | 6 + .../minChunkSize/best-merge-target/main6.js | 3 + .../minChunkSize/best-merge-target/main7.js | 3 + .../minChunkSize/best-merge-target/main8.js | 3 + .../minChunkSize/best-merge-target/main9.js | 3 + .../minChunkSize/best-merge-target/small1.js | 1 + .../minChunkSize/best-merge-target/small2.js | 1 + .../minChunkSize/best-merge-target/small3.js | 1 + .../minChunkSize/best-merge-target/small4.js | 1 + .../_config.js | 11 ++ .../_expected/amd/generated-shared.js | 11 ++ .../_expected/amd/main1.js | 5 + .../_expected/amd/main2.js | 5 + .../_expected/amd/main3.js | 5 + .../_expected/amd/main4.js | 5 + .../_expected/cjs/generated-shared.js | 9 ++ .../_expected/cjs/main1.js | 5 + .../_expected/cjs/main2.js | 5 + .../_expected/cjs/main3.js | 5 + .../_expected/cjs/main4.js | 5 + .../_expected/es/generated-shared.js | 6 + .../_expected/es/main1.js | 3 + .../_expected/es/main2.js | 3 + .../_expected/es/main3.js | 3 + .../_expected/es/main4.js | 3 + .../_expected/system/generated-shared.js | 13 ++ .../_expected/system/main1.js | 15 +++ .../_expected/system/main2.js | 15 +++ .../_expected/system/main3.js | 14 +++ .../_expected/system/main4.js | 14 +++ .../merge-chunk-into-distant-shared/main1.js | 4 + .../merge-chunk-into-distant-shared/main2.js | 4 + .../merge-chunk-into-distant-shared/main3.js | 3 + .../merge-chunk-into-distant-shared/main4.js | 3 + .../merge-chunk-into-distant-shared/shared.js | 2 + .../merge-chunk-into-distant-shared/small.js | 1 + .../minChunkSize/merge-unrelated/_config.js | 10 ++ .../_expected/amd/generated-small2.js | 10 ++ .../merge-unrelated/_expected/amd/main1.js | 5 + .../merge-unrelated/_expected/amd/main2.js | 5 + .../merge-unrelated/_expected/amd/main3.js | 5 + .../_expected/cjs/generated-small2.js | 8 ++ .../merge-unrelated/_expected/cjs/main1.js | 5 + .../merge-unrelated/_expected/cjs/main2.js | 5 + .../merge-unrelated/_expected/cjs/main3.js | 5 + .../_expected/es/generated-small2.js | 5 + .../merge-unrelated/_expected/es/main1.js | 3 + .../merge-unrelated/_expected/es/main2.js | 3 + .../merge-unrelated/_expected/es/main3.js | 3 + .../_expected/system/generated-small2.js | 12 ++ .../merge-unrelated/_expected/system/main1.js | 15 +++ .../merge-unrelated/_expected/system/main2.js | 14 +++ .../merge-unrelated/_expected/system/main3.js | 14 +++ .../minChunkSize/merge-unrelated/main1.js | 4 + .../minChunkSize/merge-unrelated/main2.js | 3 + .../minChunkSize/merge-unrelated/main3.js | 3 + .../minChunkSize/merge-unrelated/small1.js | 1 + .../minChunkSize/merge-unrelated/small2.js | 1 + 108 files changed, 755 insertions(+), 63 deletions(-) create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main6.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main7.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main8.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main9.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main6.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main7.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main8.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main9.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main6.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main7.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main8.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main9.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main6.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main7.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main8.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main9.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main5.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main6.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main7.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main8.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/main9.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/small2.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/small3.js create mode 100644 test/chunking-form/samples/minChunkSize/best-merge-target/small4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/generated-shared.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/generated-shared.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/generated-shared.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/generated-shared.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main4.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/shared.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/small.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/generated-small2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/main1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/main2.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/main3.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/small1.js create mode 100644 test/chunking-form/samples/minChunkSize/merge-unrelated/small2.js diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index 4d19634ea74..e1aa522358e 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -190,7 +190,6 @@ function createChunks( assignedEntryPointsByModule, allEntryPoints ); - printChunkModules('chunkModules', chunkModulesBySignature); if (minChunkSize === 0) { return Object.values(chunkModulesBySignature).map(modules => ({ alias: null, @@ -202,80 +201,41 @@ function createChunks( chunkModulesBySignature, minChunkSize ); - // TODO Lukas merge unrelated chunks? - console.log( - 'toBeMerged', - [...chunksToBeMerged].map(({ modules, signature }) => ({ - modules: modules.map(relativeModuleId), - signature - })) - ); - nextChunkToBeMerged: for (const sourceChunk of chunksToBeMerged) { - console.log('check chunk', sourceChunk.signature, sourceChunk.modules.map(relativeModuleId)); + for (const sourceChunk of chunksToBeMerged) { + chunksToBeMerged.delete(sourceChunk); let closestChunk: ChunkDescription | null = null; let closestChunkDistance = Infinity; - let reverseClosestChunkMerge = false; const { signature, size, modules } = sourceChunk; - for (const targetChunk of chunksToBeMerged) { - if (targetChunk !== sourceChunk) { - let needsReversedMerge = false; - let distance = getSignatureDistance(signature, targetChunk.signature); - if (distance === Infinity) { - needsReversedMerge = true; - distance = getSignatureDistance(targetChunk.signature, signature); - } - if (distance === 1) { - console.log( - 'merge into', - targetChunk.signature, - targetChunk.modules.map(relativeModuleId), - targetChunk.size - ); - targetChunk.size += size; - targetChunk.modules.push(...modules); - if (needsReversedMerge) { - targetChunk.signature = signature; - } - chunksToBeMerged.delete(sourceChunk); - if (targetChunk.size > minChunkSize) { - chunksToBeMerged.delete(targetChunk); - unmergeableChunks.push(targetChunk); - } - continue nextChunkToBeMerged; - } else if (distance < closestChunkDistance) { - closestChunk = targetChunk; - closestChunkDistance = distance; - reverseClosestChunkMerge = needsReversedMerge; - throw new Error('10'); - } else { - // throw new Error('11'); - } - } - } - for (const targetChunk of unmergeableChunks) { - const distance = getSignatureDistance(signature, targetChunk.signature); + + for (const targetChunk of concatLazy(chunksToBeMerged, unmergeableChunks)) { + const distance = getSignatureDistance( + signature, + targetChunk.signature, + !chunksToBeMerged.has(targetChunk) + ); if (distance === 1) { - targetChunk.modules.push(...modules); - chunksToBeMerged.delete(sourceChunk); - continue nextChunkToBeMerged; + closestChunk = targetChunk; + break; } else if (distance < closestChunkDistance) { closestChunk = targetChunk; closestChunkDistance = distance; - reverseClosestChunkMerge = false; } } if (closestChunk) { closestChunk.modules.push(...modules); - if (reverseClosestChunkMerge) { - closestChunk.signature = signature; - throw new Error('17'); + if (chunksToBeMerged.has(closestChunk)) { + closestChunk.signature = mergeSignatures(signature, closestChunk.signature); + closestChunk.size += size; + if (closestChunk.size > minChunkSize) { + chunksToBeMerged.delete(closestChunk); + unmergeableChunks.push(closestChunk); + } } - chunksToBeMerged.delete(sourceChunk); } else { - // throw new Error('19'); + unmergeableChunks.push(sourceChunk); } } - return [...chunksToBeMerged, ...unmergeableChunks].map(({ modules }) => ({ + return unmergeableChunks.map(({ modules }) => ({ alias: null, modules })); @@ -309,7 +269,9 @@ function getMergeableChunks( chunkModulesBySignature: { [chunkSignature: string]: Module[] }, minChunkSize: number ) { - const chunksToBeMerged = new Set(); + const chunksToBeMerged = new Set() as Set & { + has(chunk: unknown): chunk is MergeableChunkDescription; + }; const unmergeableChunks: ChunkDescription[] = []; for (const [signature, modules] of Object.entries(chunkModulesBySignature)) { let size = 0; @@ -331,13 +293,17 @@ function getMergeableChunks( return { chunksToBeMerged, unmergeableChunks }; } -function getSignatureDistance(sourceSignature: string, targetSignature: string): number { +function getSignatureDistance( + sourceSignature: string, + targetSignature: string, + enforceSubset: boolean +): number { let distance = 0; const { length } = sourceSignature; for (let index = 0; index < length; index++) { const sourceValue = sourceSignature.charCodeAt(index); if (sourceValue !== targetSignature.charCodeAt(index)) { - if (sourceValue === CHAR_CODE_DEPENDENT) { + if (enforceSubset && sourceValue === CHAR_CODE_DEPENDENT) { return Infinity; } distance++; @@ -346,6 +312,25 @@ function getSignatureDistance(sourceSignature: string, targetSignature: string): return distance; } +function mergeSignatures(sourceSignature: string, targetSignature: string): string { + let signature = ''; + const { length } = sourceSignature; + for (let index = 0; index < length; index++) { + signature += + sourceSignature.charCodeAt(index) === CHAR_CODE_DEPENDENT || + targetSignature.charCodeAt(index) === CHAR_CODE_DEPENDENT + ? CHAR_DEPENDENT + : CHAR_INDEPENDENT; + } + return signature; +} + +function* concatLazy(...iterators: Iterable[]) { + for (const iterator of iterators) { + yield* iterator; + } +} + // DEBUGGING HELPERS, REMOVED BY TREE-SHAKING /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js new file mode 100644 index 00000000000..67c2f82d5fb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js @@ -0,0 +1,20 @@ +module.exports = { + solo: true, + description: 'uses the merge target that is closest', + options: { + input: [ + 'main1.js', + 'main2.js', + 'main3.js', + 'main4.js', + 'main5.js', + 'main6.js', + 'main7.js', + 'main8.js', + 'main9.js' + ], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small3.js new file mode 100644 index 00000000000..49e6098bfc0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small3.js @@ -0,0 +1,10 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small1 = '12345678901234567890123456789012345678901234567890'; + + const small3 = '12345678901234567890123456789012345678901234567890'; + + exports.small1 = small1; + exports.small3 = small3; + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small4.js new file mode 100644 index 00000000000..daf2c213f67 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/generated-small4.js @@ -0,0 +1,10 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small2 = '12345678901234567890123456789012345678901234567890'; + + const small4 = '12345678901234567890123456789012345678901234567890'; + + exports.small2 = small2; + exports.small4 = small4; + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main1.js new file mode 100644 index 00000000000..f074a6d5def --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-small3'], (function (small3) { 'use strict'; + + console.log(small3.small1, small3.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main2.js new file mode 100644 index 00000000000..44bef49d72c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-small4'], (function (small4) { 'use strict'; + + console.log(small4.small2, small4.small4); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main3.js new file mode 100644 index 00000000000..0785e712ab3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-small3', './generated-small4'], (function (small3, small4) { 'use strict'; + + console.log(small3.small1, small4.small2, small3.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main4.js new file mode 100644 index 00000000000..12b20b02070 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-small4', './generated-small3'], (function (small4, small3) { 'use strict'; + + console.log(small4.small2, small3.small3, small4.small4); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main5.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main5.js new file mode 100644 index 00000000000..1a1b040b4e1 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main5.js @@ -0,0 +1,5 @@ +define(['./generated-small3', './generated-small4'], (function (small3, small4) { 'use strict'; + + console.log(small3.small1, small4.small2, small3.small3, small4.small4); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main6.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main6.js new file mode 100644 index 00000000000..fc661223ef6 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main6.js @@ -0,0 +1,5 @@ +define(['./generated-small3'], (function (small3) { 'use strict'; + + console.log(small3.small1); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main7.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main7.js new file mode 100644 index 00000000000..a3cb8a97dc1 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main7.js @@ -0,0 +1,5 @@ +define(['./generated-small4'], (function (small4) { 'use strict'; + + console.log(small4.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main8.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main8.js new file mode 100644 index 00000000000..3a158711344 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main8.js @@ -0,0 +1,5 @@ +define(['./generated-small3'], (function (small3) { 'use strict'; + + console.log(small3.small3); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main9.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main9.js new file mode 100644 index 00000000000..6b8c31423f9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/amd/main9.js @@ -0,0 +1,5 @@ +define(['./generated-small4'], (function (small4) { 'use strict'; + + console.log(small4.small4); + +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small3.js new file mode 100644 index 00000000000..18069fd3f58 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small3.js @@ -0,0 +1,8 @@ +'use strict'; + +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small3 = '12345678901234567890123456789012345678901234567890'; + +exports.small1 = small1; +exports.small3 = small3; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small4.js new file mode 100644 index 00000000000..21aa5ce965e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/generated-small4.js @@ -0,0 +1,8 @@ +'use strict'; + +const small2 = '12345678901234567890123456789012345678901234567890'; + +const small4 = '12345678901234567890123456789012345678901234567890'; + +exports.small2 = small2; +exports.small4 = small4; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main1.js new file mode 100644 index 00000000000..c646be4cd02 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main1.js @@ -0,0 +1,5 @@ +'use strict'; + +var small3 = require('./generated-small3.js'); + +console.log(small3.small1, small3.small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main2.js new file mode 100644 index 00000000000..cf6c1d83230 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main2.js @@ -0,0 +1,5 @@ +'use strict'; + +var small4 = require('./generated-small4.js'); + +console.log(small4.small2, small4.small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main3.js new file mode 100644 index 00000000000..7d7d2d0408d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main3.js @@ -0,0 +1,6 @@ +'use strict'; + +var small3 = require('./generated-small3.js'); +var small4 = require('./generated-small4.js'); + +console.log(small3.small1, small4.small2, small3.small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main4.js new file mode 100644 index 00000000000..bf856f12b5e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main4.js @@ -0,0 +1,6 @@ +'use strict'; + +var small4 = require('./generated-small4.js'); +var small3 = require('./generated-small3.js'); + +console.log(small4.small2, small3.small3, small4.small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main5.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main5.js new file mode 100644 index 00000000000..717cc3bd42c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main5.js @@ -0,0 +1,6 @@ +'use strict'; + +var small3 = require('./generated-small3.js'); +var small4 = require('./generated-small4.js'); + +console.log(small3.small1, small4.small2, small3.small3, small4.small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main6.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main6.js new file mode 100644 index 00000000000..18b40850296 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main6.js @@ -0,0 +1,5 @@ +'use strict'; + +var small3 = require('./generated-small3.js'); + +console.log(small3.small1); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main7.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main7.js new file mode 100644 index 00000000000..acc70495643 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main7.js @@ -0,0 +1,5 @@ +'use strict'; + +var small4 = require('./generated-small4.js'); + +console.log(small4.small2); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main8.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main8.js new file mode 100644 index 00000000000..75828acc595 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main8.js @@ -0,0 +1,5 @@ +'use strict'; + +var small3 = require('./generated-small3.js'); + +console.log(small3.small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main9.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main9.js new file mode 100644 index 00000000000..ca6f97d273b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/cjs/main9.js @@ -0,0 +1,5 @@ +'use strict'; + +var small4 = require('./generated-small4.js'); + +console.log(small4.small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small3.js new file mode 100644 index 00000000000..36334b79679 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small3.js @@ -0,0 +1,5 @@ +const small1 = '12345678901234567890123456789012345678901234567890'; + +const small3 = '12345678901234567890123456789012345678901234567890'; + +export { small3 as a, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small4.js new file mode 100644 index 00000000000..40d723d32e9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/generated-small4.js @@ -0,0 +1,5 @@ +const small2 = '12345678901234567890123456789012345678901234567890'; + +const small4 = '12345678901234567890123456789012345678901234567890'; + +export { small4 as a, small2 as s }; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main1.js new file mode 100644 index 00000000000..5d5b1f0dfb4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { s as small1, a as small3 } from './generated-small3.js'; + +console.log(small1, small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main2.js new file mode 100644 index 00000000000..59889e86399 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main2.js @@ -0,0 +1,3 @@ +import { s as small2, a as small4 } from './generated-small4.js'; + +console.log(small2, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main3.js new file mode 100644 index 00000000000..62ec7ca146c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main3.js @@ -0,0 +1,4 @@ +import { s as small1, a as small3 } from './generated-small3.js'; +import { s as small2 } from './generated-small4.js'; + +console.log(small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main4.js new file mode 100644 index 00000000000..d619901318e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main4.js @@ -0,0 +1,4 @@ +import { s as small2, a as small4 } from './generated-small4.js'; +import { a as small3 } from './generated-small3.js'; + +console.log(small2, small3, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main5.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main5.js new file mode 100644 index 00000000000..3f66bbac955 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main5.js @@ -0,0 +1,4 @@ +import { s as small1, a as small3 } from './generated-small3.js'; +import { s as small2, a as small4 } from './generated-small4.js'; + +console.log(small1, small2, small3, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main6.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main6.js new file mode 100644 index 00000000000..f20d527cc99 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main6.js @@ -0,0 +1,3 @@ +import { s as small1 } from './generated-small3.js'; + +console.log(small1); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main7.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main7.js new file mode 100644 index 00000000000..feb560c7ef1 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main7.js @@ -0,0 +1,3 @@ +import { s as small2 } from './generated-small4.js'; + +console.log(small2); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main8.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main8.js new file mode 100644 index 00000000000..89638c4dde1 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main8.js @@ -0,0 +1,3 @@ +import { a as small3 } from './generated-small3.js'; + +console.log(small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main9.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main9.js new file mode 100644 index 00000000000..2d15dc3b226 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/es/main9.js @@ -0,0 +1,3 @@ +import { a as small4 } from './generated-small4.js'; + +console.log(small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small3.js new file mode 100644 index 00000000000..ea38d4313cd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small3.js @@ -0,0 +1,12 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small1 = exports('s', '12345678901234567890123456789012345678901234567890'); + + const small3 = exports('a', '12345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small4.js new file mode 100644 index 00000000000..2ef00acfb34 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/generated-small4.js @@ -0,0 +1,12 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small2 = exports('s', '12345678901234567890123456789012345678901234567890'); + + const small4 = exports('a', '12345678901234567890123456789012345678901234567890'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main1.js new file mode 100644 index 00000000000..88018d85dec --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main1.js @@ -0,0 +1,15 @@ +System.register(['./generated-small3.js'], (function () { + 'use strict'; + var small1, small3; + return { + setters: [function (module) { + small1 = module.s; + small3 = module.a; + }], + execute: (function () { + + console.log(small1, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main2.js new file mode 100644 index 00000000000..98383c7ab5e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main2.js @@ -0,0 +1,15 @@ +System.register(['./generated-small4.js'], (function () { + 'use strict'; + var small2, small4; + return { + setters: [function (module) { + small2 = module.s; + small4 = module.a; + }], + execute: (function () { + + console.log(small2, small4); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main3.js new file mode 100644 index 00000000000..d8f0bbb6977 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main3.js @@ -0,0 +1,17 @@ +System.register(['./generated-small3.js', './generated-small4.js'], (function () { + 'use strict'; + var small1, small3, small2; + return { + setters: [function (module) { + small1 = module.s; + small3 = module.a; + }, function (module) { + small2 = module.s; + }], + execute: (function () { + + console.log(small1, small2, small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main4.js new file mode 100644 index 00000000000..b2b5a623b50 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main4.js @@ -0,0 +1,17 @@ +System.register(['./generated-small4.js', './generated-small3.js'], (function () { + 'use strict'; + var small2, small4, small3; + return { + setters: [function (module) { + small2 = module.s; + small4 = module.a; + }, function (module) { + small3 = module.a; + }], + execute: (function () { + + console.log(small2, small3, small4); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main5.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main5.js new file mode 100644 index 00000000000..4a9d1ec994f --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main5.js @@ -0,0 +1,18 @@ +System.register(['./generated-small3.js', './generated-small4.js'], (function () { + 'use strict'; + var small1, small3, small2, small4; + return { + setters: [function (module) { + small1 = module.s; + small3 = module.a; + }, function (module) { + small2 = module.s; + small4 = module.a; + }], + execute: (function () { + + console.log(small1, small2, small3, small4); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main6.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main6.js new file mode 100644 index 00000000000..78f62d05c7c --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main6.js @@ -0,0 +1,14 @@ +System.register(['./generated-small3.js'], (function () { + 'use strict'; + var small1; + return { + setters: [function (module) { + small1 = module.s; + }], + execute: (function () { + + console.log(small1); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main7.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main7.js new file mode 100644 index 00000000000..f1fa78b8e8b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main7.js @@ -0,0 +1,14 @@ +System.register(['./generated-small4.js'], (function () { + 'use strict'; + var small2; + return { + setters: [function (module) { + small2 = module.s; + }], + execute: (function () { + + console.log(small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main8.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main8.js new file mode 100644 index 00000000000..f35ef372918 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main8.js @@ -0,0 +1,14 @@ +System.register(['./generated-small3.js'], (function () { + 'use strict'; + var small3; + return { + setters: [function (module) { + small3 = module.a; + }], + execute: (function () { + + console.log(small3); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main9.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main9.js new file mode 100644 index 00000000000..918f32f15a3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_expected/system/main9.js @@ -0,0 +1,14 @@ +System.register(['./generated-small4.js'], (function () { + 'use strict'; + var small4; + return { + setters: [function (module) { + small4 = module.a; + }], + execute: (function () { + + console.log(small4); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main1.js new file mode 100644 index 00000000000..ff00ad482a2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main1.js @@ -0,0 +1,4 @@ +import { small1 } from './small1'; +import { small3 } from './small3'; + +console.log(small1, small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main2.js new file mode 100644 index 00000000000..b25ce08596e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main2.js @@ -0,0 +1,4 @@ +import { small2 } from './small2'; +import { small4 } from './small4'; + +console.log(small2, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main3.js new file mode 100644 index 00000000000..8b799fc2a7b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main3.js @@ -0,0 +1,5 @@ +import { small1 } from './small1'; +import { small2 } from './small2'; +import { small3 } from './small3'; + +console.log(small1, small2, small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main4.js new file mode 100644 index 00000000000..8a49a8ebc7b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main4.js @@ -0,0 +1,5 @@ +import { small2 } from './small2'; +import { small3 } from './small3'; +import { small4 } from './small4'; + +console.log(small2, small3, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main5.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main5.js new file mode 100644 index 00000000000..8f8fc42d6c6 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main5.js @@ -0,0 +1,6 @@ +import { small1 } from './small1'; +import { small2 } from './small2'; +import { small3 } from './small3'; +import { small4 } from './small4'; + +console.log(small1, small2, small3, small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main6.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main6.js new file mode 100644 index 00000000000..e7180b14932 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main6.js @@ -0,0 +1,3 @@ +import { small1 } from './small1'; + +console.log(small1); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main7.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main7.js new file mode 100644 index 00000000000..5104c70fc70 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main7.js @@ -0,0 +1,3 @@ +import { small2 } from './small2'; + +console.log(small2); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main8.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main8.js new file mode 100644 index 00000000000..9b3e32cd341 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main8.js @@ -0,0 +1,3 @@ +import { small3 } from './small3'; + +console.log(small3); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/main9.js b/test/chunking-form/samples/minChunkSize/best-merge-target/main9.js new file mode 100644 index 00000000000..87d1370ae33 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/main9.js @@ -0,0 +1,3 @@ +import { small4 } from './small4'; + +console.log(small4); diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/small1.js b/test/chunking-form/samples/minChunkSize/best-merge-target/small1.js new file mode 100644 index 00000000000..076d519a29d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/small1.js @@ -0,0 +1 @@ +export const small1 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/small2.js b/test/chunking-form/samples/minChunkSize/best-merge-target/small2.js new file mode 100644 index 00000000000..1baf7456bcb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/small2.js @@ -0,0 +1 @@ +export const small2 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/small3.js b/test/chunking-form/samples/minChunkSize/best-merge-target/small3.js new file mode 100644 index 00000000000..ca3abd77d3e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/small3.js @@ -0,0 +1 @@ +export const small3 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/small4.js b/test/chunking-form/samples/minChunkSize/best-merge-target/small4.js new file mode 100644 index 00000000000..98e02ed47e9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/small4.js @@ -0,0 +1 @@ +export const small4 = '12345678901234567890123456789012345678901234567890'; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js new file mode 100644 index 00000000000..f6dda0da6df --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js @@ -0,0 +1,11 @@ +module.exports = { + solo: true, + description: + 'merges small chunks into shared chunks that are loaded by a non-close super-set of entry points', + options: { + input: ['main1.js', 'main2.js', 'main3.js', 'main4.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/generated-shared.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/generated-shared.js new file mode 100644 index 00000000000..14143b2a6af --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/generated-shared.js @@ -0,0 +1,11 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small = '1'; + + const shared = '1'; + console.log('effect'); + + exports.shared = shared; + exports.small = small; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main1.js new file mode 100644 index 00000000000..da13f87a714 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-shared'], (function (shared) { 'use strict'; + + console.log(shared.shared, shared.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main2.js new file mode 100644 index 00000000000..da13f87a714 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-shared'], (function (shared) { 'use strict'; + + console.log(shared.shared, shared.small); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main3.js new file mode 100644 index 00000000000..4402ec2e891 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-shared'], (function (shared) { 'use strict'; + + console.log(shared.shared); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main4.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main4.js new file mode 100644 index 00000000000..4402ec2e891 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/amd/main4.js @@ -0,0 +1,5 @@ +define(['./generated-shared'], (function (shared) { 'use strict'; + + console.log(shared.shared); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/generated-shared.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/generated-shared.js new file mode 100644 index 00000000000..2de6f6481e3 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/generated-shared.js @@ -0,0 +1,9 @@ +'use strict'; + +const small = '1'; + +const shared = '1'; +console.log('effect'); + +exports.shared = shared; +exports.small = small; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main1.js new file mode 100644 index 00000000000..d789523b554 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main1.js @@ -0,0 +1,5 @@ +'use strict'; + +var shared = require('./generated-shared.js'); + +console.log(shared.shared, shared.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main2.js new file mode 100644 index 00000000000..d789523b554 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main2.js @@ -0,0 +1,5 @@ +'use strict'; + +var shared = require('./generated-shared.js'); + +console.log(shared.shared, shared.small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main3.js new file mode 100644 index 00000000000..ca2995738b8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main3.js @@ -0,0 +1,5 @@ +'use strict'; + +var shared = require('./generated-shared.js'); + +console.log(shared.shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main4.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main4.js new file mode 100644 index 00000000000..ca2995738b8 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/cjs/main4.js @@ -0,0 +1,5 @@ +'use strict'; + +var shared = require('./generated-shared.js'); + +console.log(shared.shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/generated-shared.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/generated-shared.js new file mode 100644 index 00000000000..5f64665d615 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/generated-shared.js @@ -0,0 +1,6 @@ +const small = '1'; + +const shared = '1'; +console.log('effect'); + +export { small as a, shared as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main1.js new file mode 100644 index 00000000000..7632ccbb92d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { s as shared, a as small } from './generated-shared.js'; + +console.log(shared, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main2.js new file mode 100644 index 00000000000..7632ccbb92d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main2.js @@ -0,0 +1,3 @@ +import { s as shared, a as small } from './generated-shared.js'; + +console.log(shared, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main3.js new file mode 100644 index 00000000000..5fa03d326a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main3.js @@ -0,0 +1,3 @@ +import { s as shared } from './generated-shared.js'; + +console.log(shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main4.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main4.js new file mode 100644 index 00000000000..5fa03d326a0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/es/main4.js @@ -0,0 +1,3 @@ +import { s as shared } from './generated-shared.js'; + +console.log(shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/generated-shared.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/generated-shared.js new file mode 100644 index 00000000000..55a1c5bbefd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/generated-shared.js @@ -0,0 +1,13 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small = exports('a', '1'); + + const shared = exports('s', '1'); + console.log('effect'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main1.js new file mode 100644 index 00000000000..46b5be2e994 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main1.js @@ -0,0 +1,15 @@ +System.register(['./generated-shared.js'], (function () { + 'use strict'; + var shared, small; + return { + setters: [function (module) { + shared = module.s; + small = module.a; + }], + execute: (function () { + + console.log(shared, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main2.js new file mode 100644 index 00000000000..46b5be2e994 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main2.js @@ -0,0 +1,15 @@ +System.register(['./generated-shared.js'], (function () { + 'use strict'; + var shared, small; + return { + setters: [function (module) { + shared = module.s; + small = module.a; + }], + execute: (function () { + + console.log(shared, small); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main3.js new file mode 100644 index 00000000000..f926486d97e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main3.js @@ -0,0 +1,14 @@ +System.register(['./generated-shared.js'], (function () { + 'use strict'; + var shared; + return { + setters: [function (module) { + shared = module.s; + }], + execute: (function () { + + console.log(shared); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main4.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main4.js new file mode 100644 index 00000000000..f926486d97e --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_expected/system/main4.js @@ -0,0 +1,14 @@ +System.register(['./generated-shared.js'], (function () { + 'use strict'; + var shared; + return { + setters: [function (module) { + shared = module.s; + }], + execute: (function () { + + console.log(shared); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main1.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main1.js new file mode 100644 index 00000000000..93f92a531bb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main1.js @@ -0,0 +1,4 @@ +import { small } from './small'; +import { shared } from './shared'; + +console.log(shared, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main2.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main2.js new file mode 100644 index 00000000000..93f92a531bb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main2.js @@ -0,0 +1,4 @@ +import { small } from './small'; +import { shared } from './shared'; + +console.log(shared, small); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main3.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main3.js new file mode 100644 index 00000000000..72cff2a340b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main3.js @@ -0,0 +1,3 @@ +import { shared } from './shared'; + +console.log(shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main4.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main4.js new file mode 100644 index 00000000000..72cff2a340b --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/main4.js @@ -0,0 +1,3 @@ +import { shared } from './shared'; + +console.log(shared); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/shared.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/shared.js new file mode 100644 index 00000000000..fda6d079f86 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/shared.js @@ -0,0 +1,2 @@ +export const shared = '1'; +console.log('effect'); diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/small.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/small.js new file mode 100644 index 00000000000..64e15634102 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/small.js @@ -0,0 +1 @@ +export const small = '1'; diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js new file mode 100644 index 00000000000..436f1161d76 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js @@ -0,0 +1,10 @@ +module.exports = { + solo: true, + description: 'merges unrelated small chunks if there is no better alternative', + options: { + input: ['main1.js', 'main2.js', 'main3.js'], + output: { + experimentalMinChunkSize: 100 + } + } +}; diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/generated-small2.js new file mode 100644 index 00000000000..0329d284b07 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/generated-small2.js @@ -0,0 +1,10 @@ +define(['exports'], (function (exports) { 'use strict'; + + const small1 = '1'; + + const small2 = '1'; + + exports.small1 = small1; + exports.small2 = small2; + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main1.js new file mode 100644 index 00000000000..189d163ea42 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main1.js @@ -0,0 +1,5 @@ +define(['./generated-small2'], (function (small2) { 'use strict'; + + console.log(small2.small1, small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main2.js new file mode 100644 index 00000000000..933e6f8fc01 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main2.js @@ -0,0 +1,5 @@ +define(['./generated-small2'], (function (small2) { 'use strict'; + + console.log(small2.small1); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main3.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main3.js new file mode 100644 index 00000000000..f7a8bc388f2 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/amd/main3.js @@ -0,0 +1,5 @@ +define(['./generated-small2'], (function (small2) { 'use strict'; + + console.log(small2.small2); + +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/generated-small2.js new file mode 100644 index 00000000000..73ed4392701 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/generated-small2.js @@ -0,0 +1,8 @@ +'use strict'; + +const small1 = '1'; + +const small2 = '1'; + +exports.small1 = small1; +exports.small2 = small2; diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main1.js new file mode 100644 index 00000000000..dd3c763d78a --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main1.js @@ -0,0 +1,5 @@ +'use strict'; + +var small2 = require('./generated-small2.js'); + +console.log(small2.small1, small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main2.js new file mode 100644 index 00000000000..680aff2ffe1 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main2.js @@ -0,0 +1,5 @@ +'use strict'; + +var small2 = require('./generated-small2.js'); + +console.log(small2.small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main3.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main3.js new file mode 100644 index 00000000000..cfd5e278dbd --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/cjs/main3.js @@ -0,0 +1,5 @@ +'use strict'; + +var small2 = require('./generated-small2.js'); + +console.log(small2.small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/generated-small2.js new file mode 100644 index 00000000000..2f0c5c65af4 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/generated-small2.js @@ -0,0 +1,5 @@ +const small1 = '1'; + +const small2 = '1'; + +export { small2 as a, small1 as s }; diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main1.js new file mode 100644 index 00000000000..c0544864943 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main1.js @@ -0,0 +1,3 @@ +import { s as small1, a as small2 } from './generated-small2.js'; + +console.log(small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main2.js new file mode 100644 index 00000000000..e30e3ce1ca9 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main2.js @@ -0,0 +1,3 @@ +import { s as small1 } from './generated-small2.js'; + +console.log(small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main3.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main3.js new file mode 100644 index 00000000000..edc8ae8b0c0 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/es/main3.js @@ -0,0 +1,3 @@ +import { a as small2 } from './generated-small2.js'; + +console.log(small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/generated-small2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/generated-small2.js new file mode 100644 index 00000000000..e636d763844 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/generated-small2.js @@ -0,0 +1,12 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const small1 = exports('s', '1'); + + const small2 = exports('a', '1'); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main1.js new file mode 100644 index 00000000000..cfb4b5a9ceb --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main1.js @@ -0,0 +1,15 @@ +System.register(['./generated-small2.js'], (function () { + 'use strict'; + var small1, small2; + return { + setters: [function (module) { + small1 = module.s; + small2 = module.a; + }], + execute: (function () { + + console.log(small1, small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main2.js new file mode 100644 index 00000000000..a9fde34525d --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main2.js @@ -0,0 +1,14 @@ +System.register(['./generated-small2.js'], (function () { + 'use strict'; + var small1; + return { + setters: [function (module) { + small1 = module.s; + }], + execute: (function () { + + console.log(small1); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main3.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main3.js new file mode 100644 index 00000000000..114aa710b39 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_expected/system/main3.js @@ -0,0 +1,14 @@ +System.register(['./generated-small2.js'], (function () { + 'use strict'; + var small2; + return { + setters: [function (module) { + small2 = module.a; + }], + execute: (function () { + + console.log(small2); + + }) + }; +})); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/main1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/main1.js new file mode 100644 index 00000000000..b8159efe933 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/main1.js @@ -0,0 +1,4 @@ +import { small1 } from './small1'; +import { small2 } from './small2'; + +console.log(small1, small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/main2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/main2.js new file mode 100644 index 00000000000..e7180b14932 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/main2.js @@ -0,0 +1,3 @@ +import { small1 } from './small1'; + +console.log(small1); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/main3.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/main3.js new file mode 100644 index 00000000000..5104c70fc70 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/main3.js @@ -0,0 +1,3 @@ +import { small2 } from './small2'; + +console.log(small2); diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/small1.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/small1.js new file mode 100644 index 00000000000..7d722b9f6d7 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/small1.js @@ -0,0 +1 @@ +export const small1 = '1'; diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/small2.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/small2.js new file mode 100644 index 00000000000..53ce25e7164 --- /dev/null +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/small2.js @@ -0,0 +1 @@ +export const small2 = '1'; From 36cd729f2c37b368efe3cc0ecf421a96bbc4befa Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 5 Nov 2022 13:03:52 +0100 Subject: [PATCH 09/16] Refine implementation --- src/utils/chunkAssignment.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index e1aa522358e..2bd1397f3cc 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -172,6 +172,7 @@ function getDynamicDependentEntryPoints( } interface ChunkDescription { + alias: null; modules: Module[]; signature: string; size: number | null; @@ -190,13 +191,18 @@ function createChunks( assignedEntryPointsByModule, allEntryPoints ); - if (minChunkSize === 0) { - return Object.values(chunkModulesBySignature).map(modules => ({ - alias: null, - modules - })); - } + return minChunkSize === 0 + ? Object.values(chunkModulesBySignature).map(modules => ({ + alias: null, + modules + })) + : getOptimizedChunks(chunkModulesBySignature, minChunkSize); +} +function getOptimizedChunks( + chunkModulesBySignature: { [chunkSignature: string]: Module[] }, + minChunkSize: number +) { const { chunksToBeMerged, unmergeableChunks } = getMergeableChunks( chunkModulesBySignature, minChunkSize @@ -225,8 +231,7 @@ function createChunks( closestChunk.modules.push(...modules); if (chunksToBeMerged.has(closestChunk)) { closestChunk.signature = mergeSignatures(signature, closestChunk.signature); - closestChunk.size += size; - if (closestChunk.size > minChunkSize) { + if ((closestChunk.size += size) > minChunkSize) { chunksToBeMerged.delete(closestChunk); unmergeableChunks.push(closestChunk); } @@ -235,10 +240,7 @@ function createChunks( unmergeableChunks.push(sourceChunk); } } - return unmergeableChunks.map(({ modules }) => ({ - alias: null, - modules - })); + return unmergeableChunks; } const CHAR_DEPENDENT = 'X'; @@ -273,6 +275,7 @@ function getMergeableChunks( has(chunk: unknown): chunk is MergeableChunkDescription; }; const unmergeableChunks: ChunkDescription[] = []; + const alias = null; for (const [signature, modules] of Object.entries(chunkModulesBySignature)) { let size = 0; checkModules: { @@ -285,10 +288,10 @@ function getMergeableChunks( break checkModules; } } - chunksToBeMerged.add({ modules, signature, size }); + chunksToBeMerged.add({ alias, modules, signature, size }); continue; } - unmergeableChunks.push({ modules, signature, size: null }); + unmergeableChunks.push({ alias, modules, signature, size: null }); } return { chunksToBeMerged, unmergeableChunks }; } From 329a3eb1607106b09ba6e2fa45e39b3011c8a206 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 5 Nov 2022 20:44:57 +0100 Subject: [PATCH 10/16] Fix tests --- src/utils/chunkAssignment.ts | 3 +++ .../samples/minChunkSize/best-merge-target/_config.js | 1 - .../minChunkSize/merge-chunk-into-distant-shared/_config.js | 1 - .../samples/minChunkSize/merge-chunk-into-shared/_config.js | 1 - .../minChunkSize/merge-three-small-chunks-a/_config.js | 1 - .../minChunkSize/merge-three-small-chunks-b/_config.js | 1 - .../samples/minChunkSize/merge-two-small-chunks-a/_config.js | 1 - .../samples/minChunkSize/merge-two-small-chunks-b/_config.js | 1 - .../samples/minChunkSize/merge-unrelated/_config.js | 1 - .../samples/minChunkSize/no-merge-side-effects/_config.js | 1 - test/function/samples/output-options-hook/_config.js | 1 + test/misc/optionList.js | 4 ++-- 12 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index 2bd1397f3cc..c456ad21f47 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -2,6 +2,7 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { getOrCreate } from './getOrCreate'; import relativeId from './relativeId'; +import { timeEnd, timeStart } from './timers'; type DependentModuleMap = Map>; type ChunkDefinitions = { alias: string | null; modules: Module[] }[]; @@ -203,6 +204,7 @@ function getOptimizedChunks( chunkModulesBySignature: { [chunkSignature: string]: Module[] }, minChunkSize: number ) { + timeStart('optimize chunks', 3); const { chunksToBeMerged, unmergeableChunks } = getMergeableChunks( chunkModulesBySignature, minChunkSize @@ -240,6 +242,7 @@ function getOptimizedChunks( unmergeableChunks.push(sourceChunk); } } + timeEnd('optimize chunks', 3); return unmergeableChunks; } diff --git a/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js b/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js index 67c2f82d5fb..ca1b905a639 100644 --- a/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js +++ b/test/chunking-form/samples/minChunkSize/best-merge-target/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'uses the merge target that is closest', options: { input: [ diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js index f6dda0da6df..1b184ed33a0 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-distant-shared/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into shared chunks that are loaded by a non-close super-set of entry points', options: { diff --git a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js index f83f353ce74..a6b8f26fbba 100644 --- a/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-chunk-into-shared/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into shared chunks that are loaded by a super-set of entry points', options: { diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js index cb2c4d9d513..69504dba2e8 100644 --- a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-a/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into other small chunks first before merging into a big chunk', options: { input: ['main1.js', 'main2.js', 'main3.js', 'main4.js', 'main5.js'], diff --git a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js index cb2c4d9d513..69504dba2e8 100644 --- a/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-three-small-chunks-b/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into other small chunks first before merging into a big chunk', options: { input: ['main1.js', 'main2.js', 'main3.js', 'main4.js', 'main5.js'], diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js index 83edf5b8bc9..2b0b389db7d 100644 --- a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-a/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into other small chunks first before merging into a big chunk', options: { input: ['main1.js', 'main2.js', 'main3.js', 'main4.js'], diff --git a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js index 83edf5b8bc9..2b0b389db7d 100644 --- a/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-two-small-chunks-b/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges small chunks into other small chunks first before merging into a big chunk', options: { input: ['main1.js', 'main2.js', 'main3.js', 'main4.js'], diff --git a/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js b/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js index 436f1161d76..7bc0924b1a2 100644 --- a/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js +++ b/test/chunking-form/samples/minChunkSize/merge-unrelated/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'merges unrelated small chunks if there is no better alternative', options: { input: ['main1.js', 'main2.js', 'main3.js'], diff --git a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js index ca26c20da09..5146a813748 100644 --- a/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js +++ b/test/chunking-form/samples/minChunkSize/no-merge-side-effects/_config.js @@ -1,5 +1,4 @@ module.exports = { - solo: true, description: 'does not merge small chunks that have side effects', options: { input: ['main1.js', 'main2.js', 'main3.js'], diff --git a/test/function/samples/output-options-hook/_config.js b/test/function/samples/output-options-hook/_config.js index ed8e82de12c..8c661e955d7 100644 --- a/test/function/samples/output-options-hook/_config.js +++ b/test/function/samples/output-options-hook/_config.js @@ -27,6 +27,7 @@ module.exports = { dynamicImportInCjs: true, entryFileNames: '[name].js', esModule: 'if-default-prop', + experimentalMinChunkSize: 0, exports: 'auto', extend: false, externalImportAssertions: true, diff --git a/test/misc/optionList.js b/test/misc/optionList.js index 9cf18ae43ca..eadb77c7133 100644 --- a/test/misc/optionList.js +++ b/test/misc/optionList.js @@ -1,6 +1,6 @@ exports.input = 'acorn, acornInjectPlugins, cache, context, experimentalCacheExpiry, external, inlineDynamicImports, input, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, moduleContext, onwarn, perf, plugins, preserveEntrySignatures, preserveModules, preserveSymlinks, shimMissingExports, strictDeprecations, treeshake, watch'; exports.flags = - 'acorn, acornInjectPlugins, amd, assetFileNames, banner, bundleConfigAsCjs, c, cache, chunkFileNames, compact, config, configPlugin, context, d, dir, dynamicImportFunction, dynamicImportInCjs, e, entryFileNames, environment, esModule, experimentalCacheExpiry, exports, extend, external, externalImportAssertions, externalLiveBindings, f, failAfterWarnings, file, footer, format, freeze, g, generatedCode, globals, h, hoistTransitiveImports, i, indent, inlineDynamicImports, input, interop, intro, m, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, minifyInternalExports, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, p, paths, perf, plugin, plugins, preferConst, preserveEntrySignatures, preserveModules, preserveModulesRoot, preserveSymlinks, sanitizeFileName, shimMissingExports, silent, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, stdin, strict, strictDeprecations, systemNullSetters, treeshake, v, validate, w, waitForBundleInput, watch'; + 'acorn, acornInjectPlugins, amd, assetFileNames, banner, bundleConfigAsCjs, c, cache, chunkFileNames, compact, config, configPlugin, context, d, dir, dynamicImportFunction, dynamicImportInCjs, e, entryFileNames, environment, esModule, experimentalCacheExpiry, experimentalMinChunkSize, exports, extend, external, externalImportAssertions, externalLiveBindings, f, failAfterWarnings, file, footer, format, freeze, g, generatedCode, globals, h, hoistTransitiveImports, i, indent, inlineDynamicImports, input, interop, intro, m, makeAbsoluteExternalsRelative, manualChunks, maxParallelFileOps, maxParallelFileReads, minifyInternalExports, moduleContext, n, name, namespaceToStringTag, noConflict, o, onwarn, outro, p, paths, perf, plugin, plugins, preferConst, preserveEntrySignatures, preserveModules, preserveModulesRoot, preserveSymlinks, sanitizeFileName, shimMissingExports, silent, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, stdin, strict, strictDeprecations, systemNullSetters, treeshake, v, validate, w, waitForBundleInput, watch'; exports.output = - 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, dynamicImportInCjs, entryFileNames, esModule, exports, extend, externalImportAssertions, externalLiveBindings, file, footer, format, freeze, generatedCode, globals, hoistTransitiveImports, indent, inlineDynamicImports, interop, intro, manualChunks, minifyInternalExports, name, namespaceToStringTag, noConflict, outro, paths, plugins, preferConst, preserveModules, preserveModulesRoot, sanitizeFileName, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict, systemNullSetters, validate'; + 'amd, assetFileNames, banner, chunkFileNames, compact, dir, dynamicImportFunction, dynamicImportInCjs, entryFileNames, esModule, experimentalMinChunkSize, exports, extend, externalImportAssertions, externalLiveBindings, file, footer, format, freeze, generatedCode, globals, hoistTransitiveImports, indent, inlineDynamicImports, interop, intro, manualChunks, minifyInternalExports, name, namespaceToStringTag, noConflict, outro, paths, plugins, preferConst, preserveModules, preserveModulesRoot, sanitizeFileName, sourcemap, sourcemapBaseUrl, sourcemapExcludeSources, sourcemapFile, sourcemapPathTransform, strict, systemNullSetters, validate'; From 7b81abe5954541d13ef2d3783720cab2f498ea78 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 5 Nov 2022 20:53:17 +0100 Subject: [PATCH 11/16] Refine docs --- docs/999-big-list-of-options.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 72fcab4df6e..0b5177987d9 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -1894,9 +1894,9 @@ Determines after how many runs cached assets that are no longer used by plugins Type: `number`
CLI: `--experimentalMinChunkSize `
Default: `0` -Set a minimal chunk size target when code-splitting. When this value is greater than `0`, Rollup will try to merge any chunk that does not have side effects when executed, i.e. it only contains function definitions etc., and is below this size limit into another chunk that is likely to be loaded under similar conditions. +Set a minimal chunk size target in Byte for code-splitting setups. When this value is greater than `0`, Rollup will try to merge any chunk that does not have side effects when executed, i.e. any chunk that only contains function definitions etc., and is below this size limit into another chunk that is likely to be loaded under similar conditions. -This will mean that the generated bundle will possibly load code that is not needed yet in order to need fewer chunks. The condition for the merged chunks to be side effect free ensures that this does not change behaviour. +This will mean that the generated bundle will possibly load code that is not required yet in order to reduce the number of chunks. The condition for the merged chunks to be side effect free ensures that this does not change behaviour. Unfortunately, due to the way chunking works, chunk size is measured before any plugins like minifiers ran, which means this number is slightly inaccurate. From f696b4c205bee65f18b34761ec9d0be88be90ca1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 5 Nov 2022 21:18:26 +0100 Subject: [PATCH 12/16] Extract helper --- src/utils/chunkAssignment.ts | 8 +------- src/utils/iterators.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/utils/iterators.ts diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index c456ad21f47..3186f6912a1 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -1,6 +1,7 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { getOrCreate } from './getOrCreate'; +import { concatLazy } from './iterators'; import relativeId from './relativeId'; import { timeEnd, timeStart } from './timers'; @@ -331,15 +332,8 @@ function mergeSignatures(sourceSignature: string, targetSignature: string): stri return signature; } -function* concatLazy(...iterators: Iterable[]) { - for (const iterator of iterators) { - yield* iterator; - } -} - // DEBUGGING HELPERS, REMOVED BY TREE-SHAKING /* eslint-disable @typescript-eslint/no-unused-vars */ - const relativeModuleId = (module: Module) => relativeId(module.id); const printModuleMap = (label: string, map: DependentModuleMap) => diff --git a/src/utils/iterators.ts b/src/utils/iterators.ts new file mode 100644 index 00000000000..afbe9eb1850 --- /dev/null +++ b/src/utils/iterators.ts @@ -0,0 +1,10 @@ +/** + * Concatenate a number of iterables to a new iterable without fully evaluating + * their iterators. Useful when e.g. working with large sets or lists and when + * there is a chance that the iterators will not be fully exhausted. + */ +export function* concatLazy(...iterables: Iterable[]) { + for (const iterable of iterables) { + yield* iterable; + } +} From a7371983277dccacf9aff14869f8e9e9d37de80a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 8 Nov 2022 06:37:58 +0100 Subject: [PATCH 13/16] 3.3.0-0 --- browser/package.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/browser/package.json b/browser/package.json index 59f30d54713..35f4e533114 100644 --- a/browser/package.json +++ b/browser/package.json @@ -1,6 +1,6 @@ { "name": "@rollup/browser", - "version": "3.2.5", + "version": "3.3.0-0", "description": "Next-generation ES module bundler browser build", "main": "dist/rollup.browser.js", "module": "dist/es/rollup.browser.js", diff --git a/package-lock.json b/package-lock.json index 0daf0cc81ac..181f122115b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rollup", - "version": "3.2.5", + "version": "3.3.0-0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rollup", - "version": "3.2.5", + "version": "3.3.0-0", "license": "MIT", "bin": { "rollup": "dist/bin/rollup" diff --git a/package.json b/package.json index d9eaa45b58c..1086375784d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rollup", - "version": "3.2.5", + "version": "3.3.0-0", "description": "Next-generation ES module bundler", "main": "dist/rollup.js", "module": "dist/es/rollup.js", From db494cb02f0c0008e215291ad8b6abacb31d9335 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 11 Nov 2022 20:40:18 +0100 Subject: [PATCH 14/16] Improve wording in docs --- docs/999-big-list-of-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 0b5177987d9..2f87c1887b0 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -1898,7 +1898,7 @@ Set a minimal chunk size target in Byte for code-splitting setups. When this val This will mean that the generated bundle will possibly load code that is not required yet in order to reduce the number of chunks. The condition for the merged chunks to be side effect free ensures that this does not change behaviour. -Unfortunately, due to the way chunking works, chunk size is measured before any plugins like minifiers ran, which means this number is slightly inaccurate. +Unfortunately, due to the way chunking works, chunk size is measured before any chunk rendering plugins like minifiers ran, which means you should use a high enough limit to take this into account. #### perf From 49ae9b853b6dfdff8d7c3b48e62d24659d5f5363 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Fri, 11 Nov 2022 20:45:19 +0100 Subject: [PATCH 15/16] Remove debug code --- src/utils/chunkAssignment.ts | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/utils/chunkAssignment.ts b/src/utils/chunkAssignment.ts index 3186f6912a1..945a7393b7f 100644 --- a/src/utils/chunkAssignment.ts +++ b/src/utils/chunkAssignment.ts @@ -2,7 +2,6 @@ import ExternalModule from '../ExternalModule'; import Module from '../Module'; import { getOrCreate } from './getOrCreate'; import { concatLazy } from './iterators'; -import relativeId from './relativeId'; import { timeEnd, timeStart } from './timers'; type DependentModuleMap = Map>; @@ -331,37 +330,3 @@ function mergeSignatures(sourceSignature: string, targetSignature: string): stri } return signature; } - -// DEBUGGING HELPERS, REMOVED BY TREE-SHAKING -/* eslint-disable @typescript-eslint/no-unused-vars */ -const relativeModuleId = (module: Module) => relativeId(module.id); - -const printModuleMap = (label: string, map: DependentModuleMap) => - console.log( - label, - Object.fromEntries( - [...map].map(([module, dependentModules]) => [ - relativeModuleId(module), - [...dependentModules].map(relativeModuleId) - ]) - ) - ); - -const printChunkModules = (label: string, modules: { [chunkSignature: string]: Module[] }) => { - console.log( - label, - Object.fromEntries( - Object.entries(modules).map(([signature, chunkModules]) => [ - signature, - { - hasEffects: chunkModules.some(module => module.hasEffects()), - modules: chunkModules.map(relativeModuleId), - size: chunkModules.reduce( - (size, module) => size + module.magicString.toString().length, - 0 - ) - } - ]) - ) - ); -}; From 3aad8fdc3d6d72c5bfe7fa0ef2190a42bbb3988a Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 12 Nov 2022 06:11:17 +0100 Subject: [PATCH 16/16] Remove wrongly committed file --- test/cli/samples/watch/bundle-error/main.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/cli/samples/watch/bundle-error/main.js diff --git a/test/cli/samples/watch/bundle-error/main.js b/test/cli/samples/watch/bundle-error/main.js deleted file mode 100644 index a4012bff06c..00000000000 --- a/test/cli/samples/watch/bundle-error/main.js +++ /dev/null @@ -1 +0,0 @@ -export default 42; \ No newline at end of file