rollup 2.78.1 → 2.79.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 v2.78.1
4
- Fri, 19 Aug 2022 05:19:43 GMT - commit 398d0c4970b679795025f36e320f8aecb2859d24
3
+ Rollup.js v2.79.1
4
+ Thu, 22 Sep 2022 04:55:29 GMT - commit 69ff4181e701a0fe0026d0ba147f31bc86beffa8
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -27,7 +27,7 @@ function _interopNamespaceDefault(e) {
27
27
  return n;
28
28
  }
29
29
 
30
- var version$1 = "2.78.1";
30
+ var version$1 = "2.79.1";
31
31
 
32
32
  function ensureArray$1(items) {
33
33
  if (Array.isArray(items)) {
@@ -13446,11 +13446,18 @@ function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, na
13446
13446
  return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, indent, snippets, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
13447
13447
  }
13448
13448
 
13449
+ function addJsExtension(name) {
13450
+ return name.endsWith('.js') ? name : name + '.js';
13451
+ }
13452
+
13449
13453
  // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
13450
13454
  // The assumption is that this makes sense for all relative ids:
13451
13455
  // https://requirejs.org/docs/api.html#jsfiles
13452
- function removeExtensionFromRelativeAmdId(id) {
13453
- return id[0] === '.' ? removeJsExtension(id) : id;
13456
+ function updateExtensionForRelativeAmdId(id, forceJsExtensionForImports) {
13457
+ if (id[0] !== '.') {
13458
+ return id;
13459
+ }
13460
+ return forceJsExtensionForImports ? addJsExtension(id) : removeJsExtension(id);
13454
13461
  }
13455
13462
 
13456
13463
  const builtins = {
@@ -13489,7 +13496,7 @@ function warnOnBuiltins(warn, dependencies) {
13489
13496
 
13490
13497
  function amd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets, warn }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13491
13498
  warnOnBuiltins(warn, dependencies);
13492
- const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
13499
+ const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'`);
13493
13500
  const args = dependencies.map(m => m.name);
13494
13501
  const { n, getNonArrowFunctionIntro, _ } = snippets;
13495
13502
  if (namedExportsMode && hasExports) {
@@ -13933,7 +13940,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13933
13940
  });
13934
13941
  }
13935
13942
  warnOnBuiltins(warn, dependencies);
13936
- const amdDeps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
13943
+ const amdDeps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'`);
13937
13944
  const cjsDeps = dependencies.map(m => `require('${m.id}')`);
13938
13945
  const trimmedImports = trimEmptyImports(dependencies);
13939
13946
  const globalDeps = trimmedImports.map(module => globalProp(module.globalName, globalVar, getPropertyAccess));
@@ -14468,6 +14475,34 @@ function renderChunk({ code, options, outputPluginDriver, renderChunk, sourcemap
14468
14475
  return outputPluginDriver.hookReduceArg0('renderChunk', [code, renderChunk, options], renderChunkReducer);
14469
14476
  }
14470
14477
 
14478
+ const lowercaseBundleKeys = Symbol('bundleKeys');
14479
+ const FILE_PLACEHOLDER = {
14480
+ type: 'placeholder'
14481
+ };
14482
+ const getOutputBundle = (outputBundleBase) => {
14483
+ const reservedLowercaseBundleKeys = new Set();
14484
+ return new Proxy(outputBundleBase, {
14485
+ deleteProperty(target, key) {
14486
+ if (typeof key === 'string') {
14487
+ reservedLowercaseBundleKeys.delete(key.toLowerCase());
14488
+ }
14489
+ return Reflect.deleteProperty(target, key);
14490
+ },
14491
+ get(target, key) {
14492
+ if (key === lowercaseBundleKeys) {
14493
+ return reservedLowercaseBundleKeys;
14494
+ }
14495
+ return Reflect.get(target, key);
14496
+ },
14497
+ set(target, key, value) {
14498
+ if (typeof key === 'string') {
14499
+ reservedLowercaseBundleKeys.add(key.toLowerCase());
14500
+ }
14501
+ return Reflect.set(target, key, value);
14502
+ }
14503
+ });
14504
+ };
14505
+
14471
14506
  function renderNamePattern(pattern, patternName, replacements) {
14472
14507
  if (isPathFragment(pattern))
14473
14508
  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.`));
@@ -14481,14 +14516,13 @@ function renderNamePattern(pattern, patternName, replacements) {
14481
14516
  return replacement;
14482
14517
  });
14483
14518
  }
14484
- function makeUnique(name, existingNames) {
14485
- const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14486
- if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14519
+ function makeUnique(name, { [lowercaseBundleKeys]: reservedLowercaseBundleKeys }) {
14520
+ if (!reservedLowercaseBundleKeys.has(name.toLowerCase()))
14487
14521
  return name;
14488
14522
  const ext = require$$0.extname(name);
14489
14523
  name = name.substring(0, name.length - ext.length);
14490
14524
  let uniqueName, uniqueIndex = 1;
14491
- while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14525
+ while (reservedLowercaseBundleKeys.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14492
14526
  ;
14493
14527
  return uniqueName;
14494
14528
  }
@@ -14717,7 +14751,7 @@ class Chunk {
14717
14751
  }
14718
14752
  return facades;
14719
14753
  }
14720
- generateId(addons, options, existingNames, includeHash) {
14754
+ generateId(addons, options, bundle, includeHash) {
14721
14755
  if (this.fileName !== null) {
14722
14756
  return this.fileName;
14723
14757
  }
@@ -14727,12 +14761,12 @@ class Chunk {
14727
14761
  return makeUnique(renderNamePattern(typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern, patternName, {
14728
14762
  format: () => options.format,
14729
14763
  hash: () => includeHash
14730
- ? this.computeContentHashWithDependencies(addons, options, existingNames)
14764
+ ? this.computeContentHashWithDependencies(addons, options, bundle)
14731
14765
  : '[hash]',
14732
14766
  name: () => this.getChunkName()
14733
- }), existingNames);
14767
+ }), bundle);
14734
14768
  }
14735
- generateIdPreserveModules(preserveModulesRelativeDir, options, existingNames, unsetOptions) {
14769
+ generateIdPreserveModules(preserveModulesRelativeDir, options, bundle, unsetOptions) {
14736
14770
  const [{ id }] = this.orderedModules;
14737
14771
  const sanitizedId = this.outputOptions.sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]);
14738
14772
  let path;
@@ -14770,7 +14804,7 @@ class Chunk {
14770
14804
  });
14771
14805
  path = `_virtual/${fileName}`;
14772
14806
  }
14773
- return makeUnique(normalize(path), existingNames);
14807
+ return makeUnique(normalize(path), bundle);
14774
14808
  }
14775
14809
  getChunkInfo() {
14776
14810
  const facadeModule = this.facadeModule;
@@ -15091,7 +15125,7 @@ class Chunk {
15091
15125
  } while (alternativeReexportModule);
15092
15126
  }
15093
15127
  }
15094
- computeContentHashWithDependencies(addons, options, existingNames) {
15128
+ computeContentHashWithDependencies(addons, options, bundle) {
15095
15129
  const hash = createHash();
15096
15130
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].join(':'));
15097
15131
  hash.update(options.format);
@@ -15102,7 +15136,7 @@ class Chunk {
15102
15136
  }
15103
15137
  else {
15104
15138
  hash.update(current.getRenderedHash());
15105
- hash.update(current.generateId(addons, options, existingNames, false));
15139
+ hash.update(current.generateId(addons, options, bundle, false));
15106
15140
  }
15107
15141
  if (current instanceof ExternalModule)
15108
15142
  continue;
@@ -15140,7 +15174,7 @@ class Chunk {
15140
15174
  }
15141
15175
  }
15142
15176
  finaliseDynamicImports(options, snippets) {
15143
- const stripKnownJsExtensions = options.format === 'amd';
15177
+ const stripKnownJsExtensions = options.format === 'amd' && !options.amd.forceJsExtensionForImports;
15144
15178
  for (const [module, code] of this.renderedModuleSources) {
15145
15179
  for (const { node, resolution } of module.dynamicImports) {
15146
15180
  const chunk = this.chunkByModule.get(resolution);
@@ -15543,235 +15577,6 @@ function getChunkNameFromModule(module) {
15543
15577
  }
15544
15578
  const QUERY_HASH_REGEX = /[?#]/;
15545
15579
 
15546
- function generateAssetFileName(name, source, outputOptions, bundle) {
15547
- const emittedName = outputOptions.sanitizeFileName(name || 'asset');
15548
- return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
15549
- ? outputOptions.assetFileNames({ name, source, type: 'asset' })
15550
- : outputOptions.assetFileNames, 'output.assetFileNames', {
15551
- ext: () => require$$0.extname(emittedName).substring(1),
15552
- extname: () => require$$0.extname(emittedName),
15553
- hash() {
15554
- return createHash()
15555
- .update(emittedName)
15556
- .update(':')
15557
- .update(source)
15558
- .digest('hex')
15559
- .substring(0, 8);
15560
- },
15561
- name: () => emittedName.substring(0, emittedName.length - require$$0.extname(emittedName).length)
15562
- }), bundle);
15563
- }
15564
- function reserveFileNameInBundle(fileName, bundle, warn) {
15565
- if (fileName in bundle) {
15566
- warn(errFileNameConflict(fileName));
15567
- }
15568
- bundle[fileName] = FILE_PLACEHOLDER;
15569
- }
15570
- const FILE_PLACEHOLDER = {
15571
- type: 'placeholder'
15572
- };
15573
- function hasValidType(emittedFile) {
15574
- return Boolean(emittedFile &&
15575
- (emittedFile.type === 'asset' ||
15576
- emittedFile.type === 'chunk'));
15577
- }
15578
- function hasValidName(emittedFile) {
15579
- const validatedName = emittedFile.fileName || emittedFile.name;
15580
- return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
15581
- }
15582
- function getValidSource(source, emittedFile, fileReferenceId) {
15583
- if (!(typeof source === 'string' || source instanceof Uint8Array)) {
15584
- const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
15585
- 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.`));
15586
- }
15587
- return source;
15588
- }
15589
- function getAssetFileName(file, referenceId) {
15590
- if (typeof file.fileName !== 'string') {
15591
- return error(errAssetNotFinalisedForFileName(file.name || referenceId));
15592
- }
15593
- return file.fileName;
15594
- }
15595
- function getChunkFileName(file, facadeChunkByModule) {
15596
- var _a;
15597
- 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));
15598
- if (!fileName)
15599
- return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
15600
- return fileName;
15601
- }
15602
- class FileEmitter {
15603
- constructor(graph, options, baseFileEmitter) {
15604
- this.graph = graph;
15605
- this.options = options;
15606
- this.bundle = null;
15607
- this.facadeChunkByModule = null;
15608
- this.outputOptions = null;
15609
- this.assertAssetsFinalized = () => {
15610
- for (const [referenceId, emittedFile] of this.filesByReferenceId) {
15611
- if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
15612
- return error(errNoAssetSourceSet(emittedFile.name || referenceId));
15613
- }
15614
- };
15615
- this.emitFile = (emittedFile) => {
15616
- if (!hasValidType(emittedFile)) {
15617
- return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
15618
- }
15619
- if (!hasValidName(emittedFile)) {
15620
- 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}".`));
15621
- }
15622
- if (emittedFile.type === 'chunk') {
15623
- return this.emitChunk(emittedFile);
15624
- }
15625
- return this.emitAsset(emittedFile);
15626
- };
15627
- this.getFileName = (fileReferenceId) => {
15628
- const emittedFile = this.filesByReferenceId.get(fileReferenceId);
15629
- if (!emittedFile)
15630
- return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
15631
- if (emittedFile.type === 'chunk') {
15632
- return getChunkFileName(emittedFile, this.facadeChunkByModule);
15633
- }
15634
- return getAssetFileName(emittedFile, fileReferenceId);
15635
- };
15636
- this.setAssetSource = (referenceId, requestedSource) => {
15637
- const consumedFile = this.filesByReferenceId.get(referenceId);
15638
- if (!consumedFile)
15639
- return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
15640
- if (consumedFile.type !== 'asset') {
15641
- return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
15642
- }
15643
- if (consumedFile.source !== undefined) {
15644
- return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
15645
- }
15646
- const source = getValidSource(requestedSource, consumedFile, referenceId);
15647
- if (this.bundle) {
15648
- this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
15649
- }
15650
- else {
15651
- consumedFile.source = source;
15652
- }
15653
- };
15654
- this.setOutputBundle = (outputBundle, outputOptions, facadeChunkByModule) => {
15655
- this.outputOptions = outputOptions;
15656
- this.bundle = outputBundle;
15657
- this.facadeChunkByModule = facadeChunkByModule;
15658
- for (const emittedFile of this.filesByReferenceId.values()) {
15659
- if (emittedFile.fileName) {
15660
- reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn);
15661
- }
15662
- }
15663
- for (const [referenceId, consumedFile] of this.filesByReferenceId) {
15664
- if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
15665
- this.finalizeAsset(consumedFile, consumedFile.source, referenceId, this.bundle);
15666
- }
15667
- }
15668
- };
15669
- this.filesByReferenceId = baseFileEmitter
15670
- ? new Map(baseFileEmitter.filesByReferenceId)
15671
- : new Map();
15672
- }
15673
- assignReferenceId(file, idBase) {
15674
- let referenceId;
15675
- do {
15676
- referenceId = createHash()
15677
- .update(referenceId || idBase)
15678
- .digest('hex')
15679
- .substring(0, 8);
15680
- } while (this.filesByReferenceId.has(referenceId));
15681
- this.filesByReferenceId.set(referenceId, file);
15682
- return referenceId;
15683
- }
15684
- emitAsset(emittedAsset) {
15685
- const source = typeof emittedAsset.source !== 'undefined'
15686
- ? getValidSource(emittedAsset.source, emittedAsset, null)
15687
- : undefined;
15688
- const consumedAsset = {
15689
- fileName: emittedAsset.fileName,
15690
- name: emittedAsset.name,
15691
- source,
15692
- type: 'asset'
15693
- };
15694
- const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
15695
- if (this.bundle) {
15696
- if (emittedAsset.fileName) {
15697
- reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
15698
- }
15699
- if (source !== undefined) {
15700
- this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
15701
- }
15702
- }
15703
- return referenceId;
15704
- }
15705
- emitChunk(emittedChunk) {
15706
- if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
15707
- return error(errInvalidRollupPhaseForChunkEmission());
15708
- }
15709
- if (typeof emittedChunk.id !== 'string') {
15710
- return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
15711
- }
15712
- const consumedChunk = {
15713
- fileName: emittedChunk.fileName,
15714
- module: null,
15715
- name: emittedChunk.name || emittedChunk.id,
15716
- type: 'chunk'
15717
- };
15718
- this.graph.moduleLoader
15719
- .emitChunk(emittedChunk)
15720
- .then(module => (consumedChunk.module = module))
15721
- .catch(() => {
15722
- // Avoid unhandled Promise rejection as the error will be thrown later
15723
- // once module loading has finished
15724
- });
15725
- return this.assignReferenceId(consumedChunk, emittedChunk.id);
15726
- }
15727
- finalizeAsset(consumedFile, source, referenceId, bundle) {
15728
- const fileName = consumedFile.fileName ||
15729
- findExistingAssetFileNameWithSource(bundle, source) ||
15730
- generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
15731
- // We must not modify the original assets to avoid interaction between outputs
15732
- const assetWithFileName = { ...consumedFile, fileName, source };
15733
- this.filesByReferenceId.set(referenceId, assetWithFileName);
15734
- const { options } = this;
15735
- bundle[fileName] = {
15736
- fileName,
15737
- get isAsset() {
15738
- warnDeprecation('Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead', true, options);
15739
- return true;
15740
- },
15741
- name: consumedFile.name,
15742
- source,
15743
- type: 'asset'
15744
- };
15745
- }
15746
- }
15747
- function findExistingAssetFileNameWithSource(bundle, source) {
15748
- for (const [fileName, outputFile] of Object.entries(bundle)) {
15749
- if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
15750
- return fileName;
15751
- }
15752
- return null;
15753
- }
15754
- function areSourcesEqual(sourceA, sourceB) {
15755
- if (typeof sourceA === 'string') {
15756
- return sourceA === sourceB;
15757
- }
15758
- if (typeof sourceB === 'string') {
15759
- return false;
15760
- }
15761
- if ('equals' in sourceA) {
15762
- return sourceA.equals(sourceB);
15763
- }
15764
- if (sourceA.length !== sourceB.length) {
15765
- return false;
15766
- }
15767
- for (let index = 0; index < sourceA.length; index++) {
15768
- if (sourceA[index] !== sourceB[index]) {
15769
- return false;
15770
- }
15771
- }
15772
- return true;
15773
- }
15774
-
15775
15580
  const concatSep = (out, next) => (next ? `${out}\n${next}` : out);
15776
15581
  const concatDblSep = (out, next) => (next ? `${out}\n\n${next}` : out);
15777
15582
  async function createAddons(options, outputPluginDriver) {
@@ -16094,7 +15899,8 @@ class Bundle {
16094
15899
  }
16095
15900
  async generate(isWrite) {
16096
15901
  timeStart('GENERATE', 1);
16097
- const outputBundle = Object.create(null);
15902
+ const outputBundleBase = Object.create(null);
15903
+ const outputBundle = getOutputBundle(outputBundleBase);
16098
15904
  this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions, this.facadeChunkByModule);
16099
15905
  try {
16100
15906
  await this.pluginDriver.hookParallel('renderStart', [this.outputOptions, this.inputOptions]);
@@ -16125,15 +15931,15 @@ class Bundle {
16125
15931
  ]);
16126
15932
  this.finaliseAssets(outputBundle);
16127
15933
  timeEnd('GENERATE', 1);
16128
- return outputBundle;
15934
+ return outputBundleBase;
16129
15935
  }
16130
- async addFinalizedChunksToBundle(chunks, inputBase, addons, outputBundle, snippets) {
16131
- this.assignChunkIds(chunks, inputBase, addons, outputBundle);
15936
+ async addFinalizedChunksToBundle(chunks, inputBase, addons, bundle, snippets) {
15937
+ this.assignChunkIds(chunks, inputBase, addons, bundle);
16132
15938
  for (const chunk of chunks) {
16133
- outputBundle[chunk.id] = chunk.getChunkInfoWithFileNames();
15939
+ bundle[chunk.id] = chunk.getChunkInfoWithFileNames();
16134
15940
  }
16135
15941
  await Promise.all(chunks.map(async (chunk) => {
16136
- const outputChunk = outputBundle[chunk.id];
15942
+ const outputChunk = bundle[chunk.id];
16137
15943
  Object.assign(outputChunk, await chunk.render(this.outputOptions, addons, outputChunk, snippets));
16138
15944
  }));
16139
15945
  }
@@ -22583,6 +22389,238 @@ class GlobalScope extends Scope$1 {
22583
22389
  }
22584
22390
  }
22585
22391
 
22392
+ function generateAssetFileName(name, source, outputOptions, bundle) {
22393
+ const emittedName = outputOptions.sanitizeFileName(name || 'asset');
22394
+ return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
22395
+ ? outputOptions.assetFileNames({ name, source, type: 'asset' })
22396
+ : outputOptions.assetFileNames, 'output.assetFileNames', {
22397
+ ext: () => require$$0.extname(emittedName).substring(1),
22398
+ extname: () => require$$0.extname(emittedName),
22399
+ hash() {
22400
+ return createHash()
22401
+ .update(emittedName)
22402
+ .update(':')
22403
+ .update(source)
22404
+ .digest('hex')
22405
+ .substring(0, 8);
22406
+ },
22407
+ name: () => emittedName.substring(0, emittedName.length - require$$0.extname(emittedName).length)
22408
+ }), bundle);
22409
+ }
22410
+ function reserveFileNameInBundle(fileName, bundle, warn) {
22411
+ const lowercaseFileName = fileName.toLowerCase();
22412
+ if (bundle[lowercaseBundleKeys].has(lowercaseFileName)) {
22413
+ warn(errFileNameConflict(fileName));
22414
+ }
22415
+ else {
22416
+ bundle[fileName] = FILE_PLACEHOLDER;
22417
+ }
22418
+ }
22419
+ function hasValidType(emittedFile) {
22420
+ return Boolean(emittedFile &&
22421
+ (emittedFile.type === 'asset' ||
22422
+ emittedFile.type === 'chunk'));
22423
+ }
22424
+ function hasValidName(emittedFile) {
22425
+ const validatedName = emittedFile.fileName || emittedFile.name;
22426
+ return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
22427
+ }
22428
+ function getValidSource(source, emittedFile, fileReferenceId) {
22429
+ if (!(typeof source === 'string' || source instanceof Uint8Array)) {
22430
+ const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
22431
+ 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.`));
22432
+ }
22433
+ return source;
22434
+ }
22435
+ function getAssetFileName(file, referenceId) {
22436
+ if (typeof file.fileName !== 'string') {
22437
+ return error(errAssetNotFinalisedForFileName(file.name || referenceId));
22438
+ }
22439
+ return file.fileName;
22440
+ }
22441
+ function getChunkFileName(file, facadeChunkByModule) {
22442
+ var _a;
22443
+ 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));
22444
+ if (!fileName)
22445
+ return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
22446
+ return fileName;
22447
+ }
22448
+ class FileEmitter {
22449
+ constructor(graph, options, baseFileEmitter) {
22450
+ this.graph = graph;
22451
+ this.options = options;
22452
+ this.bundle = null;
22453
+ this.facadeChunkByModule = null;
22454
+ this.outputOptions = null;
22455
+ this.assertAssetsFinalized = () => {
22456
+ for (const [referenceId, emittedFile] of this.filesByReferenceId) {
22457
+ if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
22458
+ return error(errNoAssetSourceSet(emittedFile.name || referenceId));
22459
+ }
22460
+ };
22461
+ this.emitFile = (emittedFile) => {
22462
+ if (!hasValidType(emittedFile)) {
22463
+ return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
22464
+ }
22465
+ if (!hasValidName(emittedFile)) {
22466
+ 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}".`));
22467
+ }
22468
+ if (emittedFile.type === 'chunk') {
22469
+ return this.emitChunk(emittedFile);
22470
+ }
22471
+ return this.emitAsset(emittedFile);
22472
+ };
22473
+ this.getFileName = (fileReferenceId) => {
22474
+ const emittedFile = this.filesByReferenceId.get(fileReferenceId);
22475
+ if (!emittedFile)
22476
+ return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
22477
+ if (emittedFile.type === 'chunk') {
22478
+ return getChunkFileName(emittedFile, this.facadeChunkByModule);
22479
+ }
22480
+ return getAssetFileName(emittedFile, fileReferenceId);
22481
+ };
22482
+ this.setAssetSource = (referenceId, requestedSource) => {
22483
+ const consumedFile = this.filesByReferenceId.get(referenceId);
22484
+ if (!consumedFile)
22485
+ return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
22486
+ if (consumedFile.type !== 'asset') {
22487
+ return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
22488
+ }
22489
+ if (consumedFile.source !== undefined) {
22490
+ return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
22491
+ }
22492
+ const source = getValidSource(requestedSource, consumedFile, referenceId);
22493
+ if (this.bundle) {
22494
+ this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
22495
+ }
22496
+ else {
22497
+ consumedFile.source = source;
22498
+ }
22499
+ };
22500
+ this.setOutputBundle = (bundle, outputOptions, facadeChunkByModule) => {
22501
+ this.outputOptions = outputOptions;
22502
+ this.bundle = bundle;
22503
+ this.facadeChunkByModule = facadeChunkByModule;
22504
+ for (const { fileName } of this.filesByReferenceId.values()) {
22505
+ if (fileName) {
22506
+ reserveFileNameInBundle(fileName, bundle, this.options.onwarn);
22507
+ }
22508
+ }
22509
+ for (const [referenceId, consumedFile] of this.filesByReferenceId) {
22510
+ if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
22511
+ this.finalizeAsset(consumedFile, consumedFile.source, referenceId, bundle);
22512
+ }
22513
+ }
22514
+ };
22515
+ this.filesByReferenceId = baseFileEmitter
22516
+ ? new Map(baseFileEmitter.filesByReferenceId)
22517
+ : new Map();
22518
+ }
22519
+ assignReferenceId(file, idBase) {
22520
+ let referenceId;
22521
+ do {
22522
+ referenceId = createHash()
22523
+ .update(referenceId || idBase)
22524
+ .digest('hex')
22525
+ .substring(0, 8);
22526
+ } while (this.filesByReferenceId.has(referenceId));
22527
+ this.filesByReferenceId.set(referenceId, file);
22528
+ return referenceId;
22529
+ }
22530
+ emitAsset(emittedAsset) {
22531
+ const source = typeof emittedAsset.source !== 'undefined'
22532
+ ? getValidSource(emittedAsset.source, emittedAsset, null)
22533
+ : undefined;
22534
+ const consumedAsset = {
22535
+ fileName: emittedAsset.fileName,
22536
+ name: emittedAsset.name,
22537
+ source,
22538
+ type: 'asset'
22539
+ };
22540
+ const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
22541
+ if (this.bundle) {
22542
+ if (emittedAsset.fileName) {
22543
+ reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
22544
+ }
22545
+ if (source !== undefined) {
22546
+ this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
22547
+ }
22548
+ }
22549
+ return referenceId;
22550
+ }
22551
+ emitChunk(emittedChunk) {
22552
+ if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
22553
+ return error(errInvalidRollupPhaseForChunkEmission());
22554
+ }
22555
+ if (typeof emittedChunk.id !== 'string') {
22556
+ return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
22557
+ }
22558
+ const consumedChunk = {
22559
+ fileName: emittedChunk.fileName,
22560
+ module: null,
22561
+ name: emittedChunk.name || emittedChunk.id,
22562
+ type: 'chunk'
22563
+ };
22564
+ this.graph.moduleLoader
22565
+ .emitChunk(emittedChunk)
22566
+ .then(module => (consumedChunk.module = module))
22567
+ .catch(() => {
22568
+ // Avoid unhandled Promise rejection as the error will be thrown later
22569
+ // once module loading has finished
22570
+ });
22571
+ return this.assignReferenceId(consumedChunk, emittedChunk.id);
22572
+ }
22573
+ finalizeAsset(consumedFile, source, referenceId, bundle) {
22574
+ const fileName = consumedFile.fileName ||
22575
+ findExistingAssetFileNameWithSource(bundle, source) ||
22576
+ generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
22577
+ // We must not modify the original assets to avoid interaction between outputs
22578
+ const assetWithFileName = { ...consumedFile, fileName, source };
22579
+ this.filesByReferenceId.set(referenceId, assetWithFileName);
22580
+ const { options } = this;
22581
+ bundle[fileName] = {
22582
+ fileName,
22583
+ get isAsset() {
22584
+ warnDeprecation('Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead', true, options);
22585
+ return true;
22586
+ },
22587
+ name: consumedFile.name,
22588
+ source,
22589
+ type: 'asset'
22590
+ };
22591
+ }
22592
+ }
22593
+ // TODO This can lead to a performance problem when many assets are emitted.
22594
+ // Instead, we should only deduplicate string assets and use their sources as
22595
+ // object keys for better performance.
22596
+ function findExistingAssetFileNameWithSource(bundle, source) {
22597
+ for (const [fileName, outputFile] of Object.entries(bundle)) {
22598
+ if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
22599
+ return fileName;
22600
+ }
22601
+ return null;
22602
+ }
22603
+ function areSourcesEqual(sourceA, sourceB) {
22604
+ if (typeof sourceA === 'string') {
22605
+ return sourceA === sourceB;
22606
+ }
22607
+ if (typeof sourceB === 'string') {
22608
+ return false;
22609
+ }
22610
+ if ('equals' in sourceA) {
22611
+ return sourceA.equals(sourceB);
22612
+ }
22613
+ if (sourceA.length !== sourceB.length) {
22614
+ return false;
22615
+ }
22616
+ for (let index = 0; index < sourceA.length; index++) {
22617
+ if (sourceA[index] !== sourceB[index]) {
22618
+ return false;
22619
+ }
22620
+ }
22621
+ return true;
22622
+ }
22623
+
22586
22624
  function getDeprecatedContextHandler(handler, handlerName, newHandlerName, pluginName, activeDeprecation, options) {
22587
22625
  let deprecationWarningShown = false;
22588
22626
  return ((...args) => {
@@ -23561,6 +23599,7 @@ const getAmd = (config) => {
23561
23599
  autoId: false,
23562
23600
  basePath: '',
23563
23601
  define: 'define',
23602
+ forceJsExtensionForImports: false,
23564
23603
  ...config.amd
23565
23604
  };
23566
23605
  if ((mergedOption.autoId || mergedOption.basePath) && mergedOption.id) {
@@ -23574,13 +23613,15 @@ const getAmd = (config) => {
23574
23613
  normalized = {
23575
23614
  autoId: true,
23576
23615
  basePath: mergedOption.basePath,
23577
- define: mergedOption.define
23616
+ define: mergedOption.define,
23617
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports
23578
23618
  };
23579
23619
  }
23580
23620
  else {
23581
23621
  normalized = {
23582
23622
  autoId: false,
23583
23623
  define: mergedOption.define,
23624
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports,
23584
23625
  id: mergedOption.id
23585
23626
  };
23586
23627
  }
@@ -23827,13 +23868,7 @@ function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, out
23827
23868
  }
23828
23869
  function createOutput(outputBundle) {
23829
23870
  return {
23830
- output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => {
23831
- const fileTypeA = getSortingFileType(outputFileA);
23832
- const fileTypeB = getSortingFileType(outputFileB);
23833
- if (fileTypeA === fileTypeB)
23834
- return 0;
23835
- return fileTypeA < fileTypeB ? -1 : 1;
23836
- })
23871
+ output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => getSortingFileType(outputFileA) - getSortingFileType(outputFileB))
23837
23872
  };
23838
23873
  }
23839
23874
  var SortingFileType;