rollup 3.7.6-0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.7.6-0
4
- Sun, 18 Dec 2022 05:56:49 GMT - commit d226f7976dc543ff814af389e183d627d4e94ed4
3
+ Rollup.js v3.8.1
4
+ Fri, 23 Dec 2022 05:34:14 GMT - commit 571f3a83d4e24f7bfa9b085cf9736ccdf89e8251
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -31,7 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
 
32
32
  const tty__namespace = /*#__PURE__*/_interopNamespaceDefault(tty);
33
33
 
34
- var version$1 = "3.7.6-0";
34
+ var version$1 = "3.8.1";
35
35
 
36
36
  function ensureArray$1(items) {
37
37
  if (Array.isArray(items)) {
@@ -6082,7 +6082,7 @@ function getAndCreateKeys(esTreeNode) {
6082
6082
 
6083
6083
  const INCLUDE_PARAMETERS = 'variables';
6084
6084
  class NodeBase extends ExpressionEntity {
6085
- constructor(esTreeNode, parent, parentScope) {
6085
+ constructor(esTreeNode, parent, parentScope, keepEsTreeNode = false) {
6086
6086
  super();
6087
6087
  /**
6088
6088
  * Nodes can apply custom deoptimizations once they become part of the
@@ -6091,7 +6091,9 @@ class NodeBase extends ExpressionEntity {
6091
6091
  * custom handlers
6092
6092
  */
6093
6093
  this.deoptimized = false;
6094
- this.esTreeNode = esTreeNode;
6094
+ // Nodes can opt-in to keep the AST if needed during the build pipeline.
6095
+ // Avoid true when possible as large AST takes up memory.
6096
+ this.esTreeNode = keepEsTreeNode ? esTreeNode : null;
6095
6097
  this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode);
6096
6098
  this.parent = parent;
6097
6099
  this.context = parent.context;
@@ -6177,7 +6179,7 @@ class NodeBase extends ExpressionEntity {
6177
6179
  code.appendLeft(this.end, ';');
6178
6180
  }
6179
6181
  }
6180
- parseNode(esTreeNode) {
6182
+ parseNode(esTreeNode, keepEsTreeNodeKeys) {
6181
6183
  for (const [key, value] of Object.entries(esTreeNode)) {
6182
6184
  // That way, we can override this function to add custom initialisation and then call super.parseNode
6183
6185
  if (this.hasOwnProperty(key))
@@ -6199,11 +6201,11 @@ class NodeBase extends ExpressionEntity {
6199
6201
  for (const child of value) {
6200
6202
  this[key].push(child === null
6201
6203
  ? null
6202
- : new (this.context.getNodeConstructor(child.type))(child, this, this.scope));
6204
+ : new (this.context.getNodeConstructor(child.type))(child, this, this.scope, keepEsTreeNodeKeys?.includes(key)));
6203
6205
  }
6204
6206
  }
6205
6207
  else {
6206
- this[key] = new (this.context.getNodeConstructor(value.type))(value, this, this.scope);
6208
+ this[key] = new (this.context.getNodeConstructor(value.type))(value, this, this.scope, keepEsTreeNodeKeys?.includes(key));
6207
6209
  }
6208
6210
  }
6209
6211
  }
@@ -11190,6 +11192,10 @@ class ImportExpression extends NodeBase {
11190
11192
  initialise() {
11191
11193
  this.context.addDynamicImport(this);
11192
11194
  }
11195
+ parseNode(esTreeNode) {
11196
+ // Keep the source AST to be used by renderDynamicImport
11197
+ super.parseNode(esTreeNode, ['source']);
11198
+ }
11193
11199
  render(code, options) {
11194
11200
  const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess } } = options;
11195
11201
  if (this.inlineNamespace) {
@@ -11795,12 +11801,7 @@ class PrivateIdentifier extends NodeBase {
11795
11801
  class Program extends NodeBase {
11796
11802
  constructor() {
11797
11803
  super(...arguments);
11798
- this.hasCachedEffect = null;
11799
- }
11800
- hasCachedEffects() {
11801
- return this.hasCachedEffect === null
11802
- ? (this.hasCachedEffect = this.hasEffects(createHasEffectsContext()))
11803
- : this.hasCachedEffect;
11804
+ this.hasCachedEffect = false;
11804
11805
  }
11805
11806
  hasEffects(context) {
11806
11807
  // We are caching here to later more efficiently identify side-effect-free modules
@@ -13702,7 +13703,8 @@ class Module {
13702
13703
  return [null];
13703
13704
  }
13704
13705
  hasEffects() {
13705
- return this.info.moduleSideEffects === 'no-treeshake' || this.ast.hasCachedEffects();
13706
+ return (this.info.moduleSideEffects === 'no-treeshake' ||
13707
+ (this.ast.included && this.ast.hasEffects(createHasEffectsContext())));
13706
13708
  }
13707
13709
  include() {
13708
13710
  const context = createInclusionContext();
@@ -13784,9 +13786,7 @@ class Module {
13784
13786
  this.transformDependencies = transformDependencies;
13785
13787
  this.customTransformCache = customTransformCache;
13786
13788
  this.updateOptions(moduleOptions);
13787
- if (!ast) {
13788
- ast = this.tryParse();
13789
- }
13789
+ const moduleAst = ast || this.tryParse();
13790
13790
  timeEnd('generate ast', 3);
13791
13791
  timeStart('analyze ast', 3);
13792
13792
  this.resolvedIds = resolvedIds || Object.create(null);
@@ -13828,14 +13828,33 @@ class Module {
13828
13828
  };
13829
13829
  this.scope = new ModuleScope(this.graph.scope, this.astContext);
13830
13830
  this.namespace = new NamespaceVariable(this.astContext);
13831
- this.ast = new Program(ast, { context: this.astContext, type: 'Module' }, this.scope);
13832
- this.info.ast = ast;
13831
+ this.ast = new Program(moduleAst, { context: this.astContext, type: 'Module' }, this.scope);
13832
+ // Assign AST directly if has existing one as there's no way to drop it from memory.
13833
+ // If cache is enabled, also assign directly as otherwise it takes more CPU and memory to re-compute.
13834
+ if (ast || this.options.cache !== false) {
13835
+ this.info.ast = moduleAst;
13836
+ }
13837
+ else {
13838
+ // Make lazy and apply LRU cache to not hog the memory
13839
+ Object.defineProperty(this.info, 'ast', {
13840
+ get: () => {
13841
+ if (this.graph.astLru.has(fileName)) {
13842
+ return this.graph.astLru.get(fileName);
13843
+ }
13844
+ else {
13845
+ const parsedAst = this.tryParse();
13846
+ this.graph.astLru.set(fileName, parsedAst);
13847
+ return parsedAst;
13848
+ }
13849
+ }
13850
+ });
13851
+ }
13833
13852
  timeEnd('analyze ast', 3);
13834
13853
  }
13835
13854
  toJSON() {
13836
13855
  return {
13837
13856
  assertions: this.info.assertions,
13838
- ast: this.ast.esTreeNode,
13857
+ ast: this.info.ast,
13839
13858
  code: this.info.code,
13840
13859
  customTransformCache: this.customTransformCache,
13841
13860
  // eslint-disable-next-line unicorn/prefer-spread
@@ -15639,12 +15658,17 @@ class Chunk {
15639
15658
  const renderedExports = exportMode === 'none' ? [] : this.getChunkExportDeclarations(format);
15640
15659
  let hasExports = renderedExports.length > 0;
15641
15660
  let hasDefaultExport = false;
15642
- for (const { reexports } of renderedDependencies) {
15661
+ for (const renderedDependence of renderedDependencies) {
15662
+ const { reexports } = renderedDependence;
15643
15663
  if (reexports?.length) {
15644
15664
  hasExports = true;
15645
- if (reexports.some(reexport => reexport.reexported === 'default')) {
15665
+ if (!hasDefaultExport && reexports.some(reexport => reexport.reexported === 'default')) {
15646
15666
  hasDefaultExport = true;
15647
- break;
15667
+ }
15668
+ if (format === 'es') {
15669
+ renderedDependence.reexports = reexports.filter(
15670
+ // eslint-disable-next-line unicorn/prefer-array-some
15671
+ ({ reexported }) => !renderedExports.find(({ exported }) => exported === reexported));
15648
15672
  }
15649
15673
  }
15650
15674
  }
@@ -15777,8 +15801,24 @@ class Chunk {
15777
15801
  const variable = this.exportsByName.get(exportName);
15778
15802
  if (!(variable instanceof SyntheticNamedExportVariable)) {
15779
15803
  const module = variable.module;
15780
- if (module && this.chunkByModule.get(module) !== this)
15781
- continue;
15804
+ if (module) {
15805
+ const chunk = this.chunkByModule.get(module);
15806
+ if (chunk !== this) {
15807
+ if (!chunk || format !== 'es') {
15808
+ continue;
15809
+ }
15810
+ const chunkDep = this.renderedDependencies.get(chunk);
15811
+ if (!chunkDep) {
15812
+ continue;
15813
+ }
15814
+ const { imports, reexports } = chunkDep;
15815
+ const importedByReexported = reexports?.find(({ reexported }) => reexported === exportName);
15816
+ const isImported = imports?.find(({ imported }) => imported === importedByReexported?.imported);
15817
+ if (!isImported) {
15818
+ continue;
15819
+ }
15820
+ }
15821
+ }
15782
15822
  }
15783
15823
  let expression = null;
15784
15824
  let hoisted = false;
@@ -16301,132 +16341,12 @@ function getImportedBindingsPerDependency(renderedDependencies, resolveFileName)
16301
16341
  const QUERY_HASH_REGEX = /[#?]/;
16302
16342
  const resolveFileName = (dependency) => dependency.getFileName();
16303
16343
 
16304
- const BYTE_UNITS = [
16305
- 'B',
16306
- 'kB',
16307
- 'MB',
16308
- 'GB',
16309
- 'TB',
16310
- 'PB',
16311
- 'EB',
16312
- 'ZB',
16313
- 'YB',
16314
- ];
16315
-
16316
- const BIBYTE_UNITS = [
16317
- 'B',
16318
- 'kiB',
16319
- 'MiB',
16320
- 'GiB',
16321
- 'TiB',
16322
- 'PiB',
16323
- 'EiB',
16324
- 'ZiB',
16325
- 'YiB',
16326
- ];
16327
-
16328
- const BIT_UNITS = [
16329
- 'b',
16330
- 'kbit',
16331
- 'Mbit',
16332
- 'Gbit',
16333
- 'Tbit',
16334
- 'Pbit',
16335
- 'Ebit',
16336
- 'Zbit',
16337
- 'Ybit',
16338
- ];
16339
-
16340
- const BIBIT_UNITS = [
16341
- 'b',
16342
- 'kibit',
16343
- 'Mibit',
16344
- 'Gibit',
16345
- 'Tibit',
16346
- 'Pibit',
16347
- 'Eibit',
16348
- 'Zibit',
16349
- 'Yibit',
16350
- ];
16351
-
16352
- /*
16353
- Formats the given number using `Number#toLocaleString`.
16354
- - If locale is a string, the value is expected to be a locale-key (for example: `de`).
16355
- - If locale is true, the system default locale is used for translation.
16356
- - If no value for locale is specified, the number is returned unmodified.
16357
- */
16358
- const toLocaleString = (number, locale, options) => {
16359
- let result = number;
16360
- if (typeof locale === 'string' || Array.isArray(locale)) {
16361
- result = number.toLocaleString(locale, options);
16362
- } else if (locale === true || options !== undefined) {
16363
- result = number.toLocaleString(undefined, options);
16364
- }
16365
-
16366
- return result;
16367
- };
16368
-
16369
- function prettyBytes(number, options) {
16370
- if (!Number.isFinite(number)) {
16371
- throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
16372
- }
16373
-
16374
- options = {
16375
- bits: false,
16376
- binary: false,
16377
- ...options,
16378
- };
16379
-
16380
- const UNITS = options.bits
16381
- ? (options.binary ? BIBIT_UNITS : BIT_UNITS)
16382
- : (options.binary ? BIBYTE_UNITS : BYTE_UNITS);
16383
-
16384
- if (options.signed && number === 0) {
16385
- return ` 0 ${UNITS[0]}`;
16386
- }
16387
-
16388
- const isNegative = number < 0;
16389
- const prefix = isNegative ? '-' : (options.signed ? '+' : '');
16390
-
16391
- if (isNegative) {
16392
- number = -number;
16393
- }
16394
-
16395
- let localeOptions;
16396
-
16397
- if (options.minimumFractionDigits !== undefined) {
16398
- localeOptions = {minimumFractionDigits: options.minimumFractionDigits};
16399
- }
16400
-
16401
- if (options.maximumFractionDigits !== undefined) {
16402
- localeOptions = {maximumFractionDigits: options.maximumFractionDigits, ...localeOptions};
16403
- }
16404
-
16405
- if (number < 1) {
16406
- const numberString = toLocaleString(number, options.locale, localeOptions);
16407
- return prefix + numberString + ' ' + UNITS[0];
16408
- }
16409
-
16410
- const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
16411
- number /= (options.binary ? 1024 : 1000) ** exponent;
16412
-
16413
- if (!localeOptions) {
16414
- number = number.toPrecision(3);
16415
- }
16416
-
16417
- const numberString = toLocaleString(Number(number), options.locale, localeOptions);
16418
-
16419
- const unit = UNITS[exponent];
16420
-
16421
- return prefix + numberString + ' ' + unit;
16422
- }
16423
-
16424
16344
  /**
16425
16345
  * Concatenate a number of iterables to a new iterable without fully evaluating
16426
16346
  * their iterators. Useful when e.g. working with large sets or lists and when
16427
16347
  * there is a chance that the iterators will not be fully exhausted.
16428
16348
  */
16429
- function* concatLazy(iterables) {
16349
+ function* concatLazy(...iterables) {
16430
16350
  for (const iterable of iterables) {
16431
16351
  yield* iterable;
16432
16352
  }
@@ -16567,11 +16487,47 @@ function createChunks(allEntries, assignedEntriesByModule, minChunkSize) {
16567
16487
  alias: null,
16568
16488
  modules
16569
16489
  }))
16570
- : getOptimizedChunks(chunkModulesBySignature, minChunkSize).map(({ modules }) => ({
16571
- alias: null,
16572
- modules
16573
- }));
16490
+ : getOptimizedChunks(chunkModulesBySignature, minChunkSize);
16491
+ }
16492
+ function getOptimizedChunks(chunkModulesBySignature, minChunkSize) {
16493
+ timeStart('optimize chunks', 3);
16494
+ const { chunksToBeMerged, unmergeableChunks } = getMergeableChunks(chunkModulesBySignature, minChunkSize);
16495
+ for (const sourceChunk of chunksToBeMerged) {
16496
+ chunksToBeMerged.delete(sourceChunk);
16497
+ let closestChunk = null;
16498
+ let closestChunkDistance = Infinity;
16499
+ const { signature, size, modules } = sourceChunk;
16500
+ for (const targetChunk of concatLazy(chunksToBeMerged, unmergeableChunks)) {
16501
+ const distance = getSignatureDistance(signature, targetChunk.signature, !chunksToBeMerged.has(targetChunk));
16502
+ if (distance === 1) {
16503
+ closestChunk = targetChunk;
16504
+ break;
16505
+ }
16506
+ else if (distance < closestChunkDistance) {
16507
+ closestChunk = targetChunk;
16508
+ closestChunkDistance = distance;
16509
+ }
16510
+ }
16511
+ if (closestChunk) {
16512
+ closestChunk.modules.push(...modules);
16513
+ if (chunksToBeMerged.has(closestChunk)) {
16514
+ closestChunk.signature = mergeSignatures(signature, closestChunk.signature);
16515
+ if ((closestChunk.size += size) > minChunkSize) {
16516
+ chunksToBeMerged.delete(closestChunk);
16517
+ unmergeableChunks.push(closestChunk);
16518
+ }
16519
+ }
16520
+ }
16521
+ else {
16522
+ unmergeableChunks.push(sourceChunk);
16523
+ }
16524
+ }
16525
+ timeEnd('optimize chunks', 3);
16526
+ return unmergeableChunks;
16574
16527
  }
16528
+ const CHAR_DEPENDENT = 'X';
16529
+ const CHAR_INDEPENDENT = '_';
16530
+ const CHAR_CODE_DEPENDENT = CHAR_DEPENDENT.charCodeAt(0);
16575
16531
  function getChunkModulesBySignature(assignedEntriesByModule, allEntries) {
16576
16532
  const chunkModules = Object.create(null);
16577
16533
  for (const [module, assignedEntries] of assignedEntriesByModule) {
@@ -16589,205 +16545,28 @@ function getChunkModulesBySignature(assignedEntriesByModule, allEntries) {
16589
16545
  }
16590
16546
  return chunkModules;
16591
16547
  }
16592
- /**
16593
- * This function tries to get rid of small chunks by merging them with other
16594
- * chunks. In order to merge chunks, one must obey the following rule:
16595
- * - When merging several chunks, at most one of the chunks can have side
16596
- * effects
16597
- * - When one of the chunks has side effects, the entry points depending on that
16598
- * chunk need to be a super set of the entry points depending on the other
16599
- * chunks
16600
- * - Pure chunks can always be merged
16601
- * - We use the entry point dependence signature to calculate "chunk distance",
16602
- * i.e. how likely it is that two chunks are loaded together
16603
- */
16604
- function getOptimizedChunks(chunkModulesBySignature, minChunkSize) {
16605
- timeStart('optimize chunks', 3);
16606
- const chunkPartition = getPartitionedChunks(chunkModulesBySignature, minChunkSize);
16607
- console.log(`Created ${chunkPartition.big.pure.size +
16608
- chunkPartition.big.sideEffect.size +
16609
- chunkPartition.small.pure.size +
16610
- chunkPartition.small.sideEffect.size} chunks
16611
- ----- pure side effects
16612
- small ${`${chunkPartition.small.pure.size}`.padEnd(5, ' ')} ${chunkPartition.small.sideEffect.size}
16613
- big ${`${chunkPartition.big.pure.size}`.padEnd(5, ' ')} ${chunkPartition.big.sideEffect.size}
16614
- Unoptimized chunks contain ${getNumberOfCycles(chunkPartition)} cycles.
16615
- `);
16616
- if (chunkPartition.small.sideEffect.size > 0) {
16617
- console.log(`Trying to find merge targets for ${chunkPartition.small.sideEffect.size} chunks smaller than ${prettyBytes(minChunkSize)} with side effects...`);
16618
- mergeChunks(chunkPartition.small.sideEffect, [chunkPartition.small.pure, chunkPartition.big.pure], minChunkSize, chunkPartition);
16619
- console.log(`${chunkPartition.small.sideEffect.size} chunks smaller than ${prettyBytes(minChunkSize)} with side effects remaining.\nGenerated chunks contain ${getNumberOfCycles(chunkPartition)} cycles.\n`);
16620
- }
16621
- if (chunkPartition.small.pure.size > 0) {
16622
- console.log(`Trying to find merge targets for ${chunkPartition.small.pure.size} pure chunks smaller than ${prettyBytes(minChunkSize)}...`);
16623
- mergeChunks(chunkPartition.small.pure, [chunkPartition.small.pure, chunkPartition.big.sideEffect, chunkPartition.big.pure], minChunkSize, chunkPartition);
16624
- console.log(`${chunkPartition.small.pure.size} pure chunks smaller than ${prettyBytes(minChunkSize)} remaining.\nGenerated chunks contain ${getNumberOfCycles(chunkPartition)} cycles.\n`);
16625
- }
16626
- timeEnd('optimize chunks', 3);
16627
- const result = [
16628
- ...chunkPartition.small.sideEffect,
16629
- ...chunkPartition.small.pure,
16630
- ...chunkPartition.big.sideEffect,
16631
- ...chunkPartition.big.pure
16632
- ];
16633
- console.log(`${result.length} chunks remaining.`);
16634
- return result;
16635
- }
16636
- const CHAR_DEPENDENT = 'X';
16637
- const CHAR_INDEPENDENT = '_';
16638
- const CHAR_CODE_DEPENDENT = CHAR_DEPENDENT.charCodeAt(0);
16639
- function getPartitionedChunks(chunkModulesBySignature, minChunkSize) {
16640
- const smallPureChunks = [];
16641
- const bigPureChunks = [];
16642
- const smallSideEffectChunks = [];
16643
- const bigSideEffectChunks = [];
16644
- const chunkByModule = new Map();
16548
+ function getMergeableChunks(chunkModulesBySignature, minChunkSize) {
16549
+ const chunksToBeMerged = new Set();
16550
+ const unmergeableChunks = [];
16551
+ const alias = null;
16645
16552
  for (const [signature, modules] of Object.entries(chunkModulesBySignature)) {
16646
- const chunkDescription = {
16647
- dependencies: new Set(),
16648
- dependentChunks: new Set(),
16649
- modules,
16650
- pure: true,
16651
- signature,
16652
- size: 0
16653
- };
16654
16553
  let size = 0;
16655
- let pure = true;
16656
- for (const module of modules) {
16657
- chunkByModule.set(module, chunkDescription);
16658
- pure && (pure = !module.hasEffects());
16659
- // Unfortunately, we cannot take tree-shaking into account here because
16660
- // rendering did not happen yet
16661
- size += module.originalCode.length;
16662
- }
16663
- chunkDescription.pure = pure;
16664
- chunkDescription.size = size;
16665
- (size < minChunkSize
16666
- ? pure
16667
- ? smallPureChunks
16668
- : smallSideEffectChunks
16669
- : pure
16670
- ? bigPureChunks
16671
- : bigSideEffectChunks).push(chunkDescription);
16672
- }
16673
- sortChunksAndAddDependencies([bigPureChunks, bigSideEffectChunks, smallPureChunks, smallSideEffectChunks], chunkByModule);
16674
- return {
16675
- big: { pure: new Set(bigPureChunks), sideEffect: new Set(bigSideEffectChunks) },
16676
- small: { pure: new Set(smallPureChunks), sideEffect: new Set(smallSideEffectChunks) }
16677
- };
16678
- }
16679
- function getNumberOfCycles(partition) {
16680
- const parents = new Set();
16681
- const analysedChunks = new Set();
16682
- let cycles = 0;
16683
- const analyseChunk = (chunk) => {
16684
- for (const dependency of chunk.dependencies) {
16685
- if (parents.has(dependency)) {
16686
- if (!analysedChunks.has(dependency)) {
16687
- cycles++;
16688
- }
16689
- continue;
16690
- }
16691
- parents.add(dependency);
16692
- analyseChunk(dependency);
16693
- }
16694
- analysedChunks.add(chunk);
16695
- };
16696
- for (const chunk of [
16697
- ...partition.big.pure,
16698
- ...partition.big.sideEffect,
16699
- ...partition.small.pure,
16700
- ...partition.small.sideEffect
16701
- ]) {
16702
- if (!parents.has(chunk)) {
16703
- parents.add(chunk);
16704
- analyseChunk(chunk);
16705
- }
16706
- }
16707
- return cycles;
16708
- }
16709
- function sortChunksAndAddDependencies(chunkLists, chunkByModule) {
16710
- for (const chunks of chunkLists) {
16711
- chunks.sort(compareChunks);
16712
- for (const chunk of chunks) {
16713
- const { dependencies, modules } = chunk;
16554
+ checkModules: {
16714
16555
  for (const module of modules) {
16715
- for (const dependency of module.getDependenciesToBeIncluded()) {
16716
- const dependencyChunk = chunkByModule.get(dependency);
16717
- if (dependencyChunk && dependencyChunk !== chunk) {
16718
- dependencies.add(dependencyChunk);
16719
- dependencyChunk.dependentChunks.add(chunk);
16720
- }
16556
+ if (module.hasEffects()) {
16557
+ break checkModules;
16721
16558
  }
16722
- }
16723
- }
16724
- }
16725
- }
16726
- function compareChunks({ size: sizeA }, { size: sizeB }) {
16727
- return sizeA - sizeB;
16728
- }
16729
- function mergeChunks(chunksToBeMerged, targetChunks, minChunkSize, chunkPartition) {
16730
- for (const mergedChunk of chunksToBeMerged) {
16731
- let closestChunk = null;
16732
- let closestChunkDistance = Infinity;
16733
- const { signature, modules, pure, size } = mergedChunk;
16734
- for (const targetChunk of concatLazy(targetChunks)) {
16735
- if (mergedChunk === targetChunk)
16736
- continue;
16737
- const distance = pure
16738
- ? getSignatureDistance(signature, targetChunk.signature, !targetChunk.pure)
16739
- : getSignatureDistance(targetChunk.signature, signature, true);
16740
- if (distance < closestChunkDistance && isValidMerge(mergedChunk, targetChunk)) {
16741
- if (distance === 1) {
16742
- closestChunk = targetChunk;
16743
- break;
16559
+ size += module.magicString.toString().length;
16560
+ if (size > minChunkSize) {
16561
+ break checkModules;
16744
16562
  }
16745
- closestChunk = targetChunk;
16746
- closestChunkDistance = distance;
16747
- }
16748
- }
16749
- if (closestChunk) {
16750
- chunksToBeMerged.delete(mergedChunk);
16751
- getChunksInPartition(closestChunk, minChunkSize, chunkPartition).delete(closestChunk);
16752
- closestChunk.modules.push(...modules);
16753
- closestChunk.size += size;
16754
- closestChunk.pure && (closestChunk.pure = pure);
16755
- closestChunk.signature = mergeSignatures(signature, closestChunk.signature);
16756
- const { dependencies, dependentChunks } = closestChunk;
16757
- for (const dependency of mergedChunk.dependencies) {
16758
- dependencies.add(dependency);
16759
- }
16760
- for (const dependentChunk of mergedChunk.dependentChunks) {
16761
- dependentChunks.add(dependentChunk);
16762
- dependentChunk.dependencies.delete(mergedChunk);
16763
- dependentChunk.dependencies.add(closestChunk);
16764
- }
16765
- dependencies.delete(closestChunk);
16766
- getChunksInPartition(closestChunk, minChunkSize, chunkPartition).add(closestChunk);
16767
- }
16768
- }
16769
- }
16770
- // Merging will not produce cycles if none of the direct non-merged dependencies
16771
- // of a chunk have the other chunk as a transitive dependency
16772
- function isValidMerge(mergedChunk, targetChunk) {
16773
- return !(hasTransitiveDependency(mergedChunk, targetChunk) ||
16774
- hasTransitiveDependency(targetChunk, mergedChunk));
16775
- }
16776
- function hasTransitiveDependency(dependentChunk, dependencyChunk) {
16777
- const chunksToCheck = new Set(dependentChunk.dependencies);
16778
- for (const { dependencies } of chunksToCheck) {
16779
- for (const dependency of dependencies) {
16780
- if (dependency === dependencyChunk) {
16781
- return true;
16782
16563
  }
16783
- chunksToCheck.add(dependency);
16564
+ chunksToBeMerged.add({ alias, modules, signature, size });
16565
+ continue;
16784
16566
  }
16567
+ unmergeableChunks.push({ alias, modules, signature, size: null });
16785
16568
  }
16786
- return false;
16787
- }
16788
- function getChunksInPartition(chunk, minChunkSize, chunkPartition) {
16789
- const subPartition = chunk.size < minChunkSize ? chunkPartition.small : chunkPartition.big;
16790
- return chunk.pure ? subPartition.pure : subPartition.sideEffect;
16569
+ return { chunksToBeMerged, unmergeableChunks };
16791
16570
  }
16792
16571
  function getSignatureDistance(sourceSignature, targetSignature, enforceSubset) {
16793
16572
  let distance = 0;
@@ -23091,6 +22870,50 @@ const acorn = /*#__PURE__*/Object.defineProperty({
23091
22870
  version
23092
22871
  }, Symbol.toStringTag, { value: 'Module' });
23093
22872
 
22873
+ function flru (max) {
22874
+ var num, curr, prev;
22875
+ var limit = max || 1;
22876
+
22877
+ function keep(key, value) {
22878
+ if (++num > limit) {
22879
+ prev = curr;
22880
+ reset(1);
22881
+ ++num;
22882
+ }
22883
+ curr[key] = value;
22884
+ }
22885
+
22886
+ function reset(isPartial) {
22887
+ num = 0;
22888
+ curr = Object.create(null);
22889
+ isPartial || (prev=Object.create(null));
22890
+ }
22891
+
22892
+ reset();
22893
+
22894
+ return {
22895
+ clear: reset,
22896
+ has: function (key) {
22897
+ return curr[key] !== void 0 || prev[key] !== void 0;
22898
+ },
22899
+ get: function (key) {
22900
+ var val = curr[key];
22901
+ if (val !== void 0) return val;
22902
+ if ((val=prev[key]) !== void 0) {
22903
+ keep(key, val);
22904
+ return val;
22905
+ }
22906
+ },
22907
+ set: function (key, value) {
22908
+ if (curr[key] !== void 0) {
22909
+ curr[key] = value;
22910
+ } else {
22911
+ keep(key, value);
22912
+ }
22913
+ }
22914
+ };
22915
+ }
22916
+
23094
22917
  function resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, assertions) {
23095
22918
  let skipped = null;
23096
22919
  let replaceContext = null;
@@ -23852,6 +23675,7 @@ class FileEmitter {
23852
23675
  this.facadeChunkByModule = null;
23853
23676
  this.nextIdBase = 1;
23854
23677
  this.output = null;
23678
+ this.outputFileEmitters = [];
23855
23679
  this.emitFile = (emittedFile) => {
23856
23680
  if (!hasValidType(emittedFile)) {
23857
23681
  return error(errorFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
@@ -23895,6 +23719,9 @@ class FileEmitter {
23895
23719
  }
23896
23720
  else {
23897
23721
  consumedFile.source = source;
23722
+ for (const emitter of this.outputFileEmitters) {
23723
+ emitter.finalizeAsset(consumedFile, source, referenceId, emitter.output);
23724
+ }
23898
23725
  }
23899
23726
  };
23900
23727
  this.setChunkInformation = (facadeChunkByModule) => {
@@ -23917,6 +23744,10 @@ class FileEmitter {
23917
23744
  this.filesByReferenceId = baseFileEmitter
23918
23745
  ? new Map(baseFileEmitter.filesByReferenceId)
23919
23746
  : new Map();
23747
+ baseFileEmitter?.addOutputFileEmitter(this);
23748
+ }
23749
+ addOutputFileEmitter(outputFileEmitter) {
23750
+ this.outputFileEmitters.push(outputFileEmitter);
23920
23751
  }
23921
23752
  assignReferenceId(file, idBase) {
23922
23753
  let referenceId;
@@ -23925,8 +23756,12 @@ class FileEmitter {
23925
23756
  .update(referenceId || idBase)
23926
23757
  .digest('hex')
23927
23758
  .slice(0, 8);
23928
- } while (this.filesByReferenceId.has(referenceId));
23759
+ } while (this.filesByReferenceId.has(referenceId) ||
23760
+ this.outputFileEmitters.some(({ filesByReferenceId }) => filesByReferenceId.has(referenceId)));
23929
23761
  this.filesByReferenceId.set(referenceId, file);
23762
+ for (const { filesByReferenceId } of this.outputFileEmitters) {
23763
+ filesByReferenceId.set(referenceId, file);
23764
+ }
23930
23765
  return referenceId;
23931
23766
  }
23932
23767
  emitAsset(emittedAsset) {
@@ -23941,15 +23776,24 @@ class FileEmitter {
23941
23776
  };
23942
23777
  const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || String(this.nextIdBase++));
23943
23778
  if (this.output) {
23944
- if (emittedAsset.fileName) {
23945
- reserveFileNameInBundle(emittedAsset.fileName, this.output, this.options.onwarn);
23946
- }
23947
- if (source !== undefined) {
23948
- this.finalizeAsset(consumedAsset, source, referenceId, this.output);
23779
+ this.emitAssetWithReferenceId(consumedAsset, referenceId, this.output);
23780
+ }
23781
+ else {
23782
+ for (const fileEmitter of this.outputFileEmitters) {
23783
+ fileEmitter.emitAssetWithReferenceId(consumedAsset, referenceId, fileEmitter.output);
23949
23784
  }
23950
23785
  }
23951
23786
  return referenceId;
23952
23787
  }
23788
+ emitAssetWithReferenceId(consumedAsset, referenceId, output) {
23789
+ const { fileName, source } = consumedAsset;
23790
+ if (fileName) {
23791
+ reserveFileNameInBundle(fileName, output, this.options.onwarn);
23792
+ }
23793
+ if (source !== undefined) {
23794
+ this.finalizeAsset(consumedAsset, source, referenceId, output);
23795
+ }
23796
+ }
23953
23797
  emitChunk(emittedChunk) {
23954
23798
  if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
23955
23799
  return error(errorInvalidRollupPhaseForChunkEmission());
@@ -24371,6 +24215,7 @@ function normalizeEntryModules(entryModules) {
24371
24215
  class Graph {
24372
24216
  constructor(options, watcher) {
24373
24217
  this.options = options;
24218
+ this.astLru = flru(5);
24374
24219
  this.cachedModules = new Map();
24375
24220
  this.deoptimizationTracker = new PathTracker();
24376
24221
  this.entryModules = [];
@@ -25376,10 +25221,12 @@ async function rollupInternal(rawInputOptions, watcher) {
25376
25221
  const { options: inputOptions, unsetOptions: unsetInputOptions } = await getInputOptions(rawInputOptions, watcher !== null);
25377
25222
  initialiseTimers(inputOptions);
25378
25223
  const graph = new Graph(inputOptions, watcher);
25379
- // remove the cache option from the memory after graph creation (cache is not used anymore)
25224
+ // remove the cache object from the memory after graph creation (cache is not used anymore)
25380
25225
  const useCache = rawInputOptions.cache !== false;
25381
- delete inputOptions.cache;
25382
- delete rawInputOptions.cache;
25226
+ if (rawInputOptions.cache) {
25227
+ inputOptions.cache = undefined;
25228
+ rawInputOptions.cache = undefined;
25229
+ }
25383
25230
  timeStart('BUILD', 1);
25384
25231
  await catchUnfinishedHookActions(graph.pluginDriver, async () => {
25385
25232
  try {
@@ -25621,7 +25468,6 @@ exports.loadFsEvents = loadFsEvents;
25621
25468
  exports.mergeOptions = mergeOptions;
25622
25469
  exports.normalizePluginOption = normalizePluginOption;
25623
25470
  exports.picomatch = picomatch$1;
25624
- exports.prettyBytes = prettyBytes;
25625
25471
  exports.printQuotedStringList = printQuotedStringList;
25626
25472
  exports.relativeId = relativeId;
25627
25473
  exports.rollup = rollup;