rollup 2.79.0 → 2.79.2

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.
package/dist/es/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.79.0
4
- Wed, 31 Aug 2022 04:52:13 GMT - commit 8477f8ff1fe80086556021542b22942ad27a0a69
3
+ Rollup.js v2.79.2
4
+ Thu, 26 Sep 2024 18:44:14 GMT - commit 48aef33cf2f2a6dfb175afb3bcd6a977c81f1d5c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.79.0
4
- Wed, 31 Aug 2022 04:52:13 GMT - commit 8477f8ff1fe80086556021542b22942ad27a0a69
3
+ Rollup.js v2.79.2
4
+ Thu, 26 Sep 2024 18:44:14 GMT - commit 48aef33cf2f2a6dfb175afb3bcd6a977c81f1d5c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.79.0";
17
+ var version$1 = "2.79.2";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -10706,7 +10706,7 @@ const accessedFileUrlGlobals = {
10706
10706
  umd: ['document', 'require', 'URL']
10707
10707
  };
10708
10708
  const getResolveUrl = (path, URL = 'URL') => `new ${URL}(${path}).href`;
10709
- const getRelativeUrlFromDocument = (relativePath, umd = false) => getResolveUrl(`'${relativePath}', ${umd ? `typeof document === 'undefined' ? location.href : ` : ''}document.currentScript && document.currentScript.src || document.baseURI`);
10709
+ const getRelativeUrlFromDocument = (relativePath, umd = false) => getResolveUrl(`'${relativePath}', ${umd ? `typeof document === 'undefined' ? location.href : ` : ''}document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || document.baseURI`);
10710
10710
  const getGenericImportMetaMechanism = (getUrl) => (prop, { chunkId }) => {
10711
10711
  const urlMechanism = getUrl(chunkId);
10712
10712
  return prop === null
@@ -10715,7 +10715,7 @@ const getGenericImportMetaMechanism = (getUrl) => (prop, { chunkId }) => {
10715
10715
  ? urlMechanism
10716
10716
  : 'undefined';
10717
10717
  };
10718
- const getUrlFromDocument = (chunkId, umd = false) => `${umd ? `typeof document === 'undefined' ? location.href : ` : ''}(document.currentScript && document.currentScript.src || new URL('${chunkId}', document.baseURI).href)`;
10718
+ const getUrlFromDocument = (chunkId, umd = false) => `${umd ? `typeof document === 'undefined' ? location.href : ` : ''}(document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('${chunkId}', document.baseURI).href)`;
10719
10719
  const relativeUrlMechanisms = {
10720
10720
  amd: relativePath => {
10721
10721
  if (relativePath[0] !== '.')
@@ -14344,6 +14344,34 @@ function renderChunk({ code, options, outputPluginDriver, renderChunk, sourcemap
14344
14344
  return outputPluginDriver.hookReduceArg0('renderChunk', [code, renderChunk, options], renderChunkReducer);
14345
14345
  }
14346
14346
 
14347
+ const lowercaseBundleKeys = Symbol('bundleKeys');
14348
+ const FILE_PLACEHOLDER = {
14349
+ type: 'placeholder'
14350
+ };
14351
+ const getOutputBundle = (outputBundleBase) => {
14352
+ const reservedLowercaseBundleKeys = new Set();
14353
+ return new Proxy(outputBundleBase, {
14354
+ deleteProperty(target, key) {
14355
+ if (typeof key === 'string') {
14356
+ reservedLowercaseBundleKeys.delete(key.toLowerCase());
14357
+ }
14358
+ return Reflect.deleteProperty(target, key);
14359
+ },
14360
+ get(target, key) {
14361
+ if (key === lowercaseBundleKeys) {
14362
+ return reservedLowercaseBundleKeys;
14363
+ }
14364
+ return Reflect.get(target, key);
14365
+ },
14366
+ set(target, key, value) {
14367
+ if (typeof key === 'string') {
14368
+ reservedLowercaseBundleKeys.add(key.toLowerCase());
14369
+ }
14370
+ return Reflect.set(target, key, value);
14371
+ }
14372
+ });
14373
+ };
14374
+
14347
14375
  function renderNamePattern(pattern, patternName, replacements) {
14348
14376
  if (isPathFragment(pattern))
14349
14377
  return error(errFailedValidation(`Invalid pattern "${pattern}" for "${patternName}", patterns can be neither absolute nor relative paths. If you want your files to be stored in a subdirectory, write its name without a leading slash like this: subdirectory/pattern.`));
@@ -14357,14 +14385,13 @@ function renderNamePattern(pattern, patternName, replacements) {
14357
14385
  return replacement;
14358
14386
  });
14359
14387
  }
14360
- function makeUnique(name, existingNames) {
14361
- const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14362
- if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14388
+ function makeUnique(name, { [lowercaseBundleKeys]: reservedLowercaseBundleKeys }) {
14389
+ if (!reservedLowercaseBundleKeys.has(name.toLowerCase()))
14363
14390
  return name;
14364
14391
  const ext = extname(name);
14365
14392
  name = name.substring(0, name.length - ext.length);
14366
14393
  let uniqueName, uniqueIndex = 1;
14367
- while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14394
+ while (reservedLowercaseBundleKeys.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14368
14395
  ;
14369
14396
  return uniqueName;
14370
14397
  }
@@ -14593,7 +14620,7 @@ class Chunk {
14593
14620
  }
14594
14621
  return facades;
14595
14622
  }
14596
- generateId(addons, options, existingNames, includeHash) {
14623
+ generateId(addons, options, bundle, includeHash) {
14597
14624
  if (this.fileName !== null) {
14598
14625
  return this.fileName;
14599
14626
  }
@@ -14603,12 +14630,12 @@ class Chunk {
14603
14630
  return makeUnique(renderNamePattern(typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern, patternName, {
14604
14631
  format: () => options.format,
14605
14632
  hash: () => includeHash
14606
- ? this.computeContentHashWithDependencies(addons, options, existingNames)
14633
+ ? this.computeContentHashWithDependencies(addons, options, bundle)
14607
14634
  : '[hash]',
14608
14635
  name: () => this.getChunkName()
14609
- }), existingNames);
14636
+ }), bundle);
14610
14637
  }
14611
- generateIdPreserveModules(preserveModulesRelativeDir, options, existingNames, unsetOptions) {
14638
+ generateIdPreserveModules(preserveModulesRelativeDir, options, bundle, unsetOptions) {
14612
14639
  const [{ id }] = this.orderedModules;
14613
14640
  const sanitizedId = this.outputOptions.sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]);
14614
14641
  let path;
@@ -14646,7 +14673,7 @@ class Chunk {
14646
14673
  });
14647
14674
  path = `_virtual/${fileName}`;
14648
14675
  }
14649
- return makeUnique(normalize(path), existingNames);
14676
+ return makeUnique(normalize(path), bundle);
14650
14677
  }
14651
14678
  getChunkInfo() {
14652
14679
  const facadeModule = this.facadeModule;
@@ -14967,7 +14994,7 @@ class Chunk {
14967
14994
  } while (alternativeReexportModule);
14968
14995
  }
14969
14996
  }
14970
- computeContentHashWithDependencies(addons, options, existingNames) {
14997
+ computeContentHashWithDependencies(addons, options, bundle) {
14971
14998
  const hash = createHash();
14972
14999
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].join(':'));
14973
15000
  hash.update(options.format);
@@ -14978,7 +15005,7 @@ class Chunk {
14978
15005
  }
14979
15006
  else {
14980
15007
  hash.update(current.getRenderedHash());
14981
- hash.update(current.generateId(addons, options, existingNames, false));
15008
+ hash.update(current.generateId(addons, options, bundle, false));
14982
15009
  }
14983
15010
  if (current instanceof ExternalModule)
14984
15011
  continue;
@@ -15419,235 +15446,6 @@ function getChunkNameFromModule(module) {
15419
15446
  }
15420
15447
  const QUERY_HASH_REGEX = /[?#]/;
15421
15448
 
15422
- function generateAssetFileName(name, source, outputOptions, bundle) {
15423
- const emittedName = outputOptions.sanitizeFileName(name || 'asset');
15424
- return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
15425
- ? outputOptions.assetFileNames({ name, source, type: 'asset' })
15426
- : outputOptions.assetFileNames, 'output.assetFileNames', {
15427
- ext: () => extname(emittedName).substring(1),
15428
- extname: () => extname(emittedName),
15429
- hash() {
15430
- return createHash()
15431
- .update(emittedName)
15432
- .update(':')
15433
- .update(source)
15434
- .digest('hex')
15435
- .substring(0, 8);
15436
- },
15437
- name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
15438
- }), bundle);
15439
- }
15440
- function reserveFileNameInBundle(fileName, bundle, warn) {
15441
- if (fileName in bundle) {
15442
- warn(errFileNameConflict(fileName));
15443
- }
15444
- bundle[fileName] = FILE_PLACEHOLDER;
15445
- }
15446
- const FILE_PLACEHOLDER = {
15447
- type: 'placeholder'
15448
- };
15449
- function hasValidType(emittedFile) {
15450
- return Boolean(emittedFile &&
15451
- (emittedFile.type === 'asset' ||
15452
- emittedFile.type === 'chunk'));
15453
- }
15454
- function hasValidName(emittedFile) {
15455
- const validatedName = emittedFile.fileName || emittedFile.name;
15456
- return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
15457
- }
15458
- function getValidSource(source, emittedFile, fileReferenceId) {
15459
- if (!(typeof source === 'string' || source instanceof Uint8Array)) {
15460
- const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
15461
- return error(errFailedValidation(`Could not set source for ${typeof assetName === 'string' ? `asset "${assetName}"` : 'unnamed asset'}, asset source needs to be a string, Uint8Array or Buffer.`));
15462
- }
15463
- return source;
15464
- }
15465
- function getAssetFileName(file, referenceId) {
15466
- if (typeof file.fileName !== 'string') {
15467
- return error(errAssetNotFinalisedForFileName(file.name || referenceId));
15468
- }
15469
- return file.fileName;
15470
- }
15471
- function getChunkFileName(file, facadeChunkByModule) {
15472
- var _a;
15473
- const fileName = file.fileName || (file.module && ((_a = facadeChunkByModule === null || facadeChunkByModule === void 0 ? void 0 : facadeChunkByModule.get(file.module)) === null || _a === void 0 ? void 0 : _a.id));
15474
- if (!fileName)
15475
- return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
15476
- return fileName;
15477
- }
15478
- class FileEmitter {
15479
- constructor(graph, options, baseFileEmitter) {
15480
- this.graph = graph;
15481
- this.options = options;
15482
- this.bundle = null;
15483
- this.facadeChunkByModule = null;
15484
- this.outputOptions = null;
15485
- this.assertAssetsFinalized = () => {
15486
- for (const [referenceId, emittedFile] of this.filesByReferenceId) {
15487
- if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
15488
- return error(errNoAssetSourceSet(emittedFile.name || referenceId));
15489
- }
15490
- };
15491
- this.emitFile = (emittedFile) => {
15492
- if (!hasValidType(emittedFile)) {
15493
- return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
15494
- }
15495
- if (!hasValidName(emittedFile)) {
15496
- return error(errFailedValidation(`The "fileName" or "name" properties of emitted files must be strings that are neither absolute nor relative paths, received "${emittedFile.fileName || emittedFile.name}".`));
15497
- }
15498
- if (emittedFile.type === 'chunk') {
15499
- return this.emitChunk(emittedFile);
15500
- }
15501
- return this.emitAsset(emittedFile);
15502
- };
15503
- this.getFileName = (fileReferenceId) => {
15504
- const emittedFile = this.filesByReferenceId.get(fileReferenceId);
15505
- if (!emittedFile)
15506
- return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
15507
- if (emittedFile.type === 'chunk') {
15508
- return getChunkFileName(emittedFile, this.facadeChunkByModule);
15509
- }
15510
- return getAssetFileName(emittedFile, fileReferenceId);
15511
- };
15512
- this.setAssetSource = (referenceId, requestedSource) => {
15513
- const consumedFile = this.filesByReferenceId.get(referenceId);
15514
- if (!consumedFile)
15515
- return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
15516
- if (consumedFile.type !== 'asset') {
15517
- return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
15518
- }
15519
- if (consumedFile.source !== undefined) {
15520
- return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
15521
- }
15522
- const source = getValidSource(requestedSource, consumedFile, referenceId);
15523
- if (this.bundle) {
15524
- this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
15525
- }
15526
- else {
15527
- consumedFile.source = source;
15528
- }
15529
- };
15530
- this.setOutputBundle = (outputBundle, outputOptions, facadeChunkByModule) => {
15531
- this.outputOptions = outputOptions;
15532
- this.bundle = outputBundle;
15533
- this.facadeChunkByModule = facadeChunkByModule;
15534
- for (const emittedFile of this.filesByReferenceId.values()) {
15535
- if (emittedFile.fileName) {
15536
- reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn);
15537
- }
15538
- }
15539
- for (const [referenceId, consumedFile] of this.filesByReferenceId) {
15540
- if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
15541
- this.finalizeAsset(consumedFile, consumedFile.source, referenceId, this.bundle);
15542
- }
15543
- }
15544
- };
15545
- this.filesByReferenceId = baseFileEmitter
15546
- ? new Map(baseFileEmitter.filesByReferenceId)
15547
- : new Map();
15548
- }
15549
- assignReferenceId(file, idBase) {
15550
- let referenceId;
15551
- do {
15552
- referenceId = createHash()
15553
- .update(referenceId || idBase)
15554
- .digest('hex')
15555
- .substring(0, 8);
15556
- } while (this.filesByReferenceId.has(referenceId));
15557
- this.filesByReferenceId.set(referenceId, file);
15558
- return referenceId;
15559
- }
15560
- emitAsset(emittedAsset) {
15561
- const source = typeof emittedAsset.source !== 'undefined'
15562
- ? getValidSource(emittedAsset.source, emittedAsset, null)
15563
- : undefined;
15564
- const consumedAsset = {
15565
- fileName: emittedAsset.fileName,
15566
- name: emittedAsset.name,
15567
- source,
15568
- type: 'asset'
15569
- };
15570
- const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
15571
- if (this.bundle) {
15572
- if (emittedAsset.fileName) {
15573
- reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
15574
- }
15575
- if (source !== undefined) {
15576
- this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
15577
- }
15578
- }
15579
- return referenceId;
15580
- }
15581
- emitChunk(emittedChunk) {
15582
- if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
15583
- return error(errInvalidRollupPhaseForChunkEmission());
15584
- }
15585
- if (typeof emittedChunk.id !== 'string') {
15586
- return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
15587
- }
15588
- const consumedChunk = {
15589
- fileName: emittedChunk.fileName,
15590
- module: null,
15591
- name: emittedChunk.name || emittedChunk.id,
15592
- type: 'chunk'
15593
- };
15594
- this.graph.moduleLoader
15595
- .emitChunk(emittedChunk)
15596
- .then(module => (consumedChunk.module = module))
15597
- .catch(() => {
15598
- // Avoid unhandled Promise rejection as the error will be thrown later
15599
- // once module loading has finished
15600
- });
15601
- return this.assignReferenceId(consumedChunk, emittedChunk.id);
15602
- }
15603
- finalizeAsset(consumedFile, source, referenceId, bundle) {
15604
- const fileName = consumedFile.fileName ||
15605
- findExistingAssetFileNameWithSource(bundle, source) ||
15606
- generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
15607
- // We must not modify the original assets to avoid interaction between outputs
15608
- const assetWithFileName = { ...consumedFile, fileName, source };
15609
- this.filesByReferenceId.set(referenceId, assetWithFileName);
15610
- const { options } = this;
15611
- bundle[fileName] = {
15612
- fileName,
15613
- get isAsset() {
15614
- warnDeprecation('Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead', true, options);
15615
- return true;
15616
- },
15617
- name: consumedFile.name,
15618
- source,
15619
- type: 'asset'
15620
- };
15621
- }
15622
- }
15623
- function findExistingAssetFileNameWithSource(bundle, source) {
15624
- for (const [fileName, outputFile] of Object.entries(bundle)) {
15625
- if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
15626
- return fileName;
15627
- }
15628
- return null;
15629
- }
15630
- function areSourcesEqual(sourceA, sourceB) {
15631
- if (typeof sourceA === 'string') {
15632
- return sourceA === sourceB;
15633
- }
15634
- if (typeof sourceB === 'string') {
15635
- return false;
15636
- }
15637
- if ('equals' in sourceA) {
15638
- return sourceA.equals(sourceB);
15639
- }
15640
- if (sourceA.length !== sourceB.length) {
15641
- return false;
15642
- }
15643
- for (let index = 0; index < sourceA.length; index++) {
15644
- if (sourceA[index] !== sourceB[index]) {
15645
- return false;
15646
- }
15647
- }
15648
- return true;
15649
- }
15650
-
15651
15449
  const concatSep = (out, next) => (next ? `${out}\n${next}` : out);
15652
15450
  const concatDblSep = (out, next) => (next ? `${out}\n\n${next}` : out);
15653
15451
  async function createAddons(options, outputPluginDriver) {
@@ -15970,7 +15768,8 @@ class Bundle {
15970
15768
  }
15971
15769
  async generate(isWrite) {
15972
15770
  timeStart('GENERATE', 1);
15973
- const outputBundle = Object.create(null);
15771
+ const outputBundleBase = Object.create(null);
15772
+ const outputBundle = getOutputBundle(outputBundleBase);
15974
15773
  this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions, this.facadeChunkByModule);
15975
15774
  try {
15976
15775
  await this.pluginDriver.hookParallel('renderStart', [this.outputOptions, this.inputOptions]);
@@ -16001,15 +15800,15 @@ class Bundle {
16001
15800
  ]);
16002
15801
  this.finaliseAssets(outputBundle);
16003
15802
  timeEnd('GENERATE', 1);
16004
- return outputBundle;
15803
+ return outputBundleBase;
16005
15804
  }
16006
- async addFinalizedChunksToBundle(chunks, inputBase, addons, outputBundle, snippets) {
16007
- this.assignChunkIds(chunks, inputBase, addons, outputBundle);
15805
+ async addFinalizedChunksToBundle(chunks, inputBase, addons, bundle, snippets) {
15806
+ this.assignChunkIds(chunks, inputBase, addons, bundle);
16008
15807
  for (const chunk of chunks) {
16009
- outputBundle[chunk.id] = chunk.getChunkInfoWithFileNames();
15808
+ bundle[chunk.id] = chunk.getChunkInfoWithFileNames();
16010
15809
  }
16011
15810
  await Promise.all(chunks.map(async (chunk) => {
16012
- const outputChunk = outputBundle[chunk.id];
15811
+ const outputChunk = bundle[chunk.id];
16013
15812
  Object.assign(outputChunk, await chunk.render(this.outputOptions, addons, outputChunk, snippets));
16014
15813
  }));
16015
15814
  }
@@ -22459,6 +22258,238 @@ class GlobalScope extends Scope$1 {
22459
22258
  }
22460
22259
  }
22461
22260
 
22261
+ function generateAssetFileName(name, source, outputOptions, bundle) {
22262
+ const emittedName = outputOptions.sanitizeFileName(name || 'asset');
22263
+ return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
22264
+ ? outputOptions.assetFileNames({ name, source, type: 'asset' })
22265
+ : outputOptions.assetFileNames, 'output.assetFileNames', {
22266
+ ext: () => extname(emittedName).substring(1),
22267
+ extname: () => extname(emittedName),
22268
+ hash() {
22269
+ return createHash()
22270
+ .update(emittedName)
22271
+ .update(':')
22272
+ .update(source)
22273
+ .digest('hex')
22274
+ .substring(0, 8);
22275
+ },
22276
+ name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
22277
+ }), bundle);
22278
+ }
22279
+ function reserveFileNameInBundle(fileName, bundle, warn) {
22280
+ const lowercaseFileName = fileName.toLowerCase();
22281
+ if (bundle[lowercaseBundleKeys].has(lowercaseFileName)) {
22282
+ warn(errFileNameConflict(fileName));
22283
+ }
22284
+ else {
22285
+ bundle[fileName] = FILE_PLACEHOLDER;
22286
+ }
22287
+ }
22288
+ function hasValidType(emittedFile) {
22289
+ return Boolean(emittedFile &&
22290
+ (emittedFile.type === 'asset' ||
22291
+ emittedFile.type === 'chunk'));
22292
+ }
22293
+ function hasValidName(emittedFile) {
22294
+ const validatedName = emittedFile.fileName || emittedFile.name;
22295
+ return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
22296
+ }
22297
+ function getValidSource(source, emittedFile, fileReferenceId) {
22298
+ if (!(typeof source === 'string' || source instanceof Uint8Array)) {
22299
+ const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
22300
+ return error(errFailedValidation(`Could not set source for ${typeof assetName === 'string' ? `asset "${assetName}"` : 'unnamed asset'}, asset source needs to be a string, Uint8Array or Buffer.`));
22301
+ }
22302
+ return source;
22303
+ }
22304
+ function getAssetFileName(file, referenceId) {
22305
+ if (typeof file.fileName !== 'string') {
22306
+ return error(errAssetNotFinalisedForFileName(file.name || referenceId));
22307
+ }
22308
+ return file.fileName;
22309
+ }
22310
+ function getChunkFileName(file, facadeChunkByModule) {
22311
+ var _a;
22312
+ const fileName = file.fileName || (file.module && ((_a = facadeChunkByModule === null || facadeChunkByModule === void 0 ? void 0 : facadeChunkByModule.get(file.module)) === null || _a === void 0 ? void 0 : _a.id));
22313
+ if (!fileName)
22314
+ return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
22315
+ return fileName;
22316
+ }
22317
+ class FileEmitter {
22318
+ constructor(graph, options, baseFileEmitter) {
22319
+ this.graph = graph;
22320
+ this.options = options;
22321
+ this.bundle = null;
22322
+ this.facadeChunkByModule = null;
22323
+ this.outputOptions = null;
22324
+ this.assertAssetsFinalized = () => {
22325
+ for (const [referenceId, emittedFile] of this.filesByReferenceId) {
22326
+ if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
22327
+ return error(errNoAssetSourceSet(emittedFile.name || referenceId));
22328
+ }
22329
+ };
22330
+ this.emitFile = (emittedFile) => {
22331
+ if (!hasValidType(emittedFile)) {
22332
+ return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
22333
+ }
22334
+ if (!hasValidName(emittedFile)) {
22335
+ return error(errFailedValidation(`The "fileName" or "name" properties of emitted files must be strings that are neither absolute nor relative paths, received "${emittedFile.fileName || emittedFile.name}".`));
22336
+ }
22337
+ if (emittedFile.type === 'chunk') {
22338
+ return this.emitChunk(emittedFile);
22339
+ }
22340
+ return this.emitAsset(emittedFile);
22341
+ };
22342
+ this.getFileName = (fileReferenceId) => {
22343
+ const emittedFile = this.filesByReferenceId.get(fileReferenceId);
22344
+ if (!emittedFile)
22345
+ return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
22346
+ if (emittedFile.type === 'chunk') {
22347
+ return getChunkFileName(emittedFile, this.facadeChunkByModule);
22348
+ }
22349
+ return getAssetFileName(emittedFile, fileReferenceId);
22350
+ };
22351
+ this.setAssetSource = (referenceId, requestedSource) => {
22352
+ const consumedFile = this.filesByReferenceId.get(referenceId);
22353
+ if (!consumedFile)
22354
+ return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
22355
+ if (consumedFile.type !== 'asset') {
22356
+ return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
22357
+ }
22358
+ if (consumedFile.source !== undefined) {
22359
+ return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
22360
+ }
22361
+ const source = getValidSource(requestedSource, consumedFile, referenceId);
22362
+ if (this.bundle) {
22363
+ this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
22364
+ }
22365
+ else {
22366
+ consumedFile.source = source;
22367
+ }
22368
+ };
22369
+ this.setOutputBundle = (bundle, outputOptions, facadeChunkByModule) => {
22370
+ this.outputOptions = outputOptions;
22371
+ this.bundle = bundle;
22372
+ this.facadeChunkByModule = facadeChunkByModule;
22373
+ for (const { fileName } of this.filesByReferenceId.values()) {
22374
+ if (fileName) {
22375
+ reserveFileNameInBundle(fileName, bundle, this.options.onwarn);
22376
+ }
22377
+ }
22378
+ for (const [referenceId, consumedFile] of this.filesByReferenceId) {
22379
+ if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
22380
+ this.finalizeAsset(consumedFile, consumedFile.source, referenceId, bundle);
22381
+ }
22382
+ }
22383
+ };
22384
+ this.filesByReferenceId = baseFileEmitter
22385
+ ? new Map(baseFileEmitter.filesByReferenceId)
22386
+ : new Map();
22387
+ }
22388
+ assignReferenceId(file, idBase) {
22389
+ let referenceId;
22390
+ do {
22391
+ referenceId = createHash()
22392
+ .update(referenceId || idBase)
22393
+ .digest('hex')
22394
+ .substring(0, 8);
22395
+ } while (this.filesByReferenceId.has(referenceId));
22396
+ this.filesByReferenceId.set(referenceId, file);
22397
+ return referenceId;
22398
+ }
22399
+ emitAsset(emittedAsset) {
22400
+ const source = typeof emittedAsset.source !== 'undefined'
22401
+ ? getValidSource(emittedAsset.source, emittedAsset, null)
22402
+ : undefined;
22403
+ const consumedAsset = {
22404
+ fileName: emittedAsset.fileName,
22405
+ name: emittedAsset.name,
22406
+ source,
22407
+ type: 'asset'
22408
+ };
22409
+ const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
22410
+ if (this.bundle) {
22411
+ if (emittedAsset.fileName) {
22412
+ reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
22413
+ }
22414
+ if (source !== undefined) {
22415
+ this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
22416
+ }
22417
+ }
22418
+ return referenceId;
22419
+ }
22420
+ emitChunk(emittedChunk) {
22421
+ if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
22422
+ return error(errInvalidRollupPhaseForChunkEmission());
22423
+ }
22424
+ if (typeof emittedChunk.id !== 'string') {
22425
+ return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
22426
+ }
22427
+ const consumedChunk = {
22428
+ fileName: emittedChunk.fileName,
22429
+ module: null,
22430
+ name: emittedChunk.name || emittedChunk.id,
22431
+ type: 'chunk'
22432
+ };
22433
+ this.graph.moduleLoader
22434
+ .emitChunk(emittedChunk)
22435
+ .then(module => (consumedChunk.module = module))
22436
+ .catch(() => {
22437
+ // Avoid unhandled Promise rejection as the error will be thrown later
22438
+ // once module loading has finished
22439
+ });
22440
+ return this.assignReferenceId(consumedChunk, emittedChunk.id);
22441
+ }
22442
+ finalizeAsset(consumedFile, source, referenceId, bundle) {
22443
+ const fileName = consumedFile.fileName ||
22444
+ findExistingAssetFileNameWithSource(bundle, source) ||
22445
+ generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
22446
+ // We must not modify the original assets to avoid interaction between outputs
22447
+ const assetWithFileName = { ...consumedFile, fileName, source };
22448
+ this.filesByReferenceId.set(referenceId, assetWithFileName);
22449
+ const { options } = this;
22450
+ bundle[fileName] = {
22451
+ fileName,
22452
+ get isAsset() {
22453
+ warnDeprecation('Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead', true, options);
22454
+ return true;
22455
+ },
22456
+ name: consumedFile.name,
22457
+ source,
22458
+ type: 'asset'
22459
+ };
22460
+ }
22461
+ }
22462
+ // TODO This can lead to a performance problem when many assets are emitted.
22463
+ // Instead, we should only deduplicate string assets and use their sources as
22464
+ // object keys for better performance.
22465
+ function findExistingAssetFileNameWithSource(bundle, source) {
22466
+ for (const [fileName, outputFile] of Object.entries(bundle)) {
22467
+ if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
22468
+ return fileName;
22469
+ }
22470
+ return null;
22471
+ }
22472
+ function areSourcesEqual(sourceA, sourceB) {
22473
+ if (typeof sourceA === 'string') {
22474
+ return sourceA === sourceB;
22475
+ }
22476
+ if (typeof sourceB === 'string') {
22477
+ return false;
22478
+ }
22479
+ if ('equals' in sourceA) {
22480
+ return sourceA.equals(sourceB);
22481
+ }
22482
+ if (sourceA.length !== sourceB.length) {
22483
+ return false;
22484
+ }
22485
+ for (let index = 0; index < sourceA.length; index++) {
22486
+ if (sourceA[index] !== sourceB[index]) {
22487
+ return false;
22488
+ }
22489
+ }
22490
+ return true;
22491
+ }
22492
+
22462
22493
  function getDeprecatedContextHandler(handler, handlerName, newHandlerName, pluginName, activeDeprecation, options) {
22463
22494
  let deprecationWarningShown = false;
22464
22495
  return ((...args) => {
@@ -23799,13 +23830,7 @@ function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, out
23799
23830
  }
23800
23831
  function createOutput(outputBundle) {
23801
23832
  return {
23802
- output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => {
23803
- const fileTypeA = getSortingFileType(outputFileA);
23804
- const fileTypeB = getSortingFileType(outputFileB);
23805
- if (fileTypeA === fileTypeB)
23806
- return 0;
23807
- return fileTypeA < fileTypeB ? -1 : 1;
23808
- })
23833
+ output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => getSortingFileType(outputFileA) - getSortingFileType(outputFileB))
23809
23834
  };
23810
23835
  }
23811
23836
  var SortingFileType;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.79.0
4
- Wed, 31 Aug 2022 04:52:13 GMT - commit 8477f8ff1fe80086556021542b22942ad27a0a69
3
+ Rollup.js v2.79.2
4
+ Thu, 26 Sep 2024 18:44:14 GMT - commit 48aef33cf2f2a6dfb175afb3bcd6a977c81f1d5c
5
5
 
6
6
  https://github.com/rollup/rollup
7
7