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
 
@@ -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.78.1";
17
+ var version$1 = "2.79.1";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -13315,11 +13315,18 @@ function getInteropBlock(dependencies, interop, externalLiveBindings, freeze, na
13315
13315
  return `${getHelpersBlock(neededInteropHelpers, accessedGlobals, indent, snippets, externalLiveBindings, freeze, namespaceToStringTag)}${interopStatements.length > 0 ? `${interopStatements.join(n)}${n}${n}` : ''}`;
13316
13316
  }
13317
13317
 
13318
+ function addJsExtension(name) {
13319
+ return name.endsWith('.js') ? name : name + '.js';
13320
+ }
13321
+
13318
13322
  // AMD resolution will only respect the AMD baseUrl if the .js extension is omitted.
13319
13323
  // The assumption is that this makes sense for all relative ids:
13320
13324
  // https://requirejs.org/docs/api.html#jsfiles
13321
- function removeExtensionFromRelativeAmdId(id) {
13322
- return id[0] === '.' ? removeJsExtension(id) : id;
13325
+ function updateExtensionForRelativeAmdId(id, forceJsExtensionForImports) {
13326
+ if (id[0] !== '.') {
13327
+ return id;
13328
+ }
13329
+ return forceJsExtensionForImports ? addJsExtension(id) : removeJsExtension(id);
13323
13330
  }
13324
13331
 
13325
13332
  const builtins = {
@@ -13358,7 +13365,7 @@ function warnOnBuiltins(warn, dependencies) {
13358
13365
 
13359
13366
  function amd(magicString, { accessedGlobals, dependencies, exports, hasExports, id, indent: t, intro, isEntryFacade, isModuleFacade, namedExportsMode, outro, snippets, warn }, { amd, esModule, externalLiveBindings, freeze, interop, namespaceToStringTag, strict }) {
13360
13367
  warnOnBuiltins(warn, dependencies);
13361
- const deps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
13368
+ const deps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'`);
13362
13369
  const args = dependencies.map(m => m.name);
13363
13370
  const { n, getNonArrowFunctionIntro, _ } = snippets;
13364
13371
  if (namedExportsMode && hasExports) {
@@ -13802,7 +13809,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasExports,
13802
13809
  });
13803
13810
  }
13804
13811
  warnOnBuiltins(warn, dependencies);
13805
- const amdDeps = dependencies.map(m => `'${removeExtensionFromRelativeAmdId(m.id)}'`);
13812
+ const amdDeps = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.id, amd.forceJsExtensionForImports)}'`);
13806
13813
  const cjsDeps = dependencies.map(m => `require('${m.id}')`);
13807
13814
  const trimmedImports = trimEmptyImports(dependencies);
13808
13815
  const globalDeps = trimmedImports.map(module => globalProp(module.globalName, globalVar, getPropertyAccess));
@@ -14337,6 +14344,34 @@ function renderChunk({ code, options, outputPluginDriver, renderChunk, sourcemap
14337
14344
  return outputPluginDriver.hookReduceArg0('renderChunk', [code, renderChunk, options], renderChunkReducer);
14338
14345
  }
14339
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
+
14340
14375
  function renderNamePattern(pattern, patternName, replacements) {
14341
14376
  if (isPathFragment(pattern))
14342
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.`));
@@ -14350,14 +14385,13 @@ function renderNamePattern(pattern, patternName, replacements) {
14350
14385
  return replacement;
14351
14386
  });
14352
14387
  }
14353
- function makeUnique(name, existingNames) {
14354
- const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14355
- if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14388
+ function makeUnique(name, { [lowercaseBundleKeys]: reservedLowercaseBundleKeys }) {
14389
+ if (!reservedLowercaseBundleKeys.has(name.toLowerCase()))
14356
14390
  return name;
14357
14391
  const ext = extname(name);
14358
14392
  name = name.substring(0, name.length - ext.length);
14359
14393
  let uniqueName, uniqueIndex = 1;
14360
- while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14394
+ while (reservedLowercaseBundleKeys.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14361
14395
  ;
14362
14396
  return uniqueName;
14363
14397
  }
@@ -14586,7 +14620,7 @@ class Chunk {
14586
14620
  }
14587
14621
  return facades;
14588
14622
  }
14589
- generateId(addons, options, existingNames, includeHash) {
14623
+ generateId(addons, options, bundle, includeHash) {
14590
14624
  if (this.fileName !== null) {
14591
14625
  return this.fileName;
14592
14626
  }
@@ -14596,12 +14630,12 @@ class Chunk {
14596
14630
  return makeUnique(renderNamePattern(typeof pattern === 'function' ? pattern(this.getChunkInfo()) : pattern, patternName, {
14597
14631
  format: () => options.format,
14598
14632
  hash: () => includeHash
14599
- ? this.computeContentHashWithDependencies(addons, options, existingNames)
14633
+ ? this.computeContentHashWithDependencies(addons, options, bundle)
14600
14634
  : '[hash]',
14601
14635
  name: () => this.getChunkName()
14602
- }), existingNames);
14636
+ }), bundle);
14603
14637
  }
14604
- generateIdPreserveModules(preserveModulesRelativeDir, options, existingNames, unsetOptions) {
14638
+ generateIdPreserveModules(preserveModulesRelativeDir, options, bundle, unsetOptions) {
14605
14639
  const [{ id }] = this.orderedModules;
14606
14640
  const sanitizedId = this.outputOptions.sanitizeFileName(id.split(QUERY_HASH_REGEX, 1)[0]);
14607
14641
  let path;
@@ -14639,7 +14673,7 @@ class Chunk {
14639
14673
  });
14640
14674
  path = `_virtual/${fileName}`;
14641
14675
  }
14642
- return makeUnique(normalize(path), existingNames);
14676
+ return makeUnique(normalize(path), bundle);
14643
14677
  }
14644
14678
  getChunkInfo() {
14645
14679
  const facadeModule = this.facadeModule;
@@ -14960,7 +14994,7 @@ class Chunk {
14960
14994
  } while (alternativeReexportModule);
14961
14995
  }
14962
14996
  }
14963
- computeContentHashWithDependencies(addons, options, existingNames) {
14997
+ computeContentHashWithDependencies(addons, options, bundle) {
14964
14998
  const hash = createHash();
14965
14999
  hash.update([addons.intro, addons.outro, addons.banner, addons.footer].join(':'));
14966
15000
  hash.update(options.format);
@@ -14971,7 +15005,7 @@ class Chunk {
14971
15005
  }
14972
15006
  else {
14973
15007
  hash.update(current.getRenderedHash());
14974
- hash.update(current.generateId(addons, options, existingNames, false));
15008
+ hash.update(current.generateId(addons, options, bundle, false));
14975
15009
  }
14976
15010
  if (current instanceof ExternalModule)
14977
15011
  continue;
@@ -15009,7 +15043,7 @@ class Chunk {
15009
15043
  }
15010
15044
  }
15011
15045
  finaliseDynamicImports(options, snippets) {
15012
- const stripKnownJsExtensions = options.format === 'amd';
15046
+ const stripKnownJsExtensions = options.format === 'amd' && !options.amd.forceJsExtensionForImports;
15013
15047
  for (const [module, code] of this.renderedModuleSources) {
15014
15048
  for (const { node, resolution } of module.dynamicImports) {
15015
15049
  const chunk = this.chunkByModule.get(resolution);
@@ -15412,235 +15446,6 @@ function getChunkNameFromModule(module) {
15412
15446
  }
15413
15447
  const QUERY_HASH_REGEX = /[?#]/;
15414
15448
 
15415
- function generateAssetFileName(name, source, outputOptions, bundle) {
15416
- const emittedName = outputOptions.sanitizeFileName(name || 'asset');
15417
- return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
15418
- ? outputOptions.assetFileNames({ name, source, type: 'asset' })
15419
- : outputOptions.assetFileNames, 'output.assetFileNames', {
15420
- ext: () => extname(emittedName).substring(1),
15421
- extname: () => extname(emittedName),
15422
- hash() {
15423
- return createHash()
15424
- .update(emittedName)
15425
- .update(':')
15426
- .update(source)
15427
- .digest('hex')
15428
- .substring(0, 8);
15429
- },
15430
- name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
15431
- }), bundle);
15432
- }
15433
- function reserveFileNameInBundle(fileName, bundle, warn) {
15434
- if (fileName in bundle) {
15435
- warn(errFileNameConflict(fileName));
15436
- }
15437
- bundle[fileName] = FILE_PLACEHOLDER;
15438
- }
15439
- const FILE_PLACEHOLDER = {
15440
- type: 'placeholder'
15441
- };
15442
- function hasValidType(emittedFile) {
15443
- return Boolean(emittedFile &&
15444
- (emittedFile.type === 'asset' ||
15445
- emittedFile.type === 'chunk'));
15446
- }
15447
- function hasValidName(emittedFile) {
15448
- const validatedName = emittedFile.fileName || emittedFile.name;
15449
- return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
15450
- }
15451
- function getValidSource(source, emittedFile, fileReferenceId) {
15452
- if (!(typeof source === 'string' || source instanceof Uint8Array)) {
15453
- const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
15454
- 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.`));
15455
- }
15456
- return source;
15457
- }
15458
- function getAssetFileName(file, referenceId) {
15459
- if (typeof file.fileName !== 'string') {
15460
- return error(errAssetNotFinalisedForFileName(file.name || referenceId));
15461
- }
15462
- return file.fileName;
15463
- }
15464
- function getChunkFileName(file, facadeChunkByModule) {
15465
- var _a;
15466
- 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));
15467
- if (!fileName)
15468
- return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
15469
- return fileName;
15470
- }
15471
- class FileEmitter {
15472
- constructor(graph, options, baseFileEmitter) {
15473
- this.graph = graph;
15474
- this.options = options;
15475
- this.bundle = null;
15476
- this.facadeChunkByModule = null;
15477
- this.outputOptions = null;
15478
- this.assertAssetsFinalized = () => {
15479
- for (const [referenceId, emittedFile] of this.filesByReferenceId) {
15480
- if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
15481
- return error(errNoAssetSourceSet(emittedFile.name || referenceId));
15482
- }
15483
- };
15484
- this.emitFile = (emittedFile) => {
15485
- if (!hasValidType(emittedFile)) {
15486
- return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
15487
- }
15488
- if (!hasValidName(emittedFile)) {
15489
- 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}".`));
15490
- }
15491
- if (emittedFile.type === 'chunk') {
15492
- return this.emitChunk(emittedFile);
15493
- }
15494
- return this.emitAsset(emittedFile);
15495
- };
15496
- this.getFileName = (fileReferenceId) => {
15497
- const emittedFile = this.filesByReferenceId.get(fileReferenceId);
15498
- if (!emittedFile)
15499
- return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
15500
- if (emittedFile.type === 'chunk') {
15501
- return getChunkFileName(emittedFile, this.facadeChunkByModule);
15502
- }
15503
- return getAssetFileName(emittedFile, fileReferenceId);
15504
- };
15505
- this.setAssetSource = (referenceId, requestedSource) => {
15506
- const consumedFile = this.filesByReferenceId.get(referenceId);
15507
- if (!consumedFile)
15508
- return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
15509
- if (consumedFile.type !== 'asset') {
15510
- return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
15511
- }
15512
- if (consumedFile.source !== undefined) {
15513
- return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
15514
- }
15515
- const source = getValidSource(requestedSource, consumedFile, referenceId);
15516
- if (this.bundle) {
15517
- this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
15518
- }
15519
- else {
15520
- consumedFile.source = source;
15521
- }
15522
- };
15523
- this.setOutputBundle = (outputBundle, outputOptions, facadeChunkByModule) => {
15524
- this.outputOptions = outputOptions;
15525
- this.bundle = outputBundle;
15526
- this.facadeChunkByModule = facadeChunkByModule;
15527
- for (const emittedFile of this.filesByReferenceId.values()) {
15528
- if (emittedFile.fileName) {
15529
- reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn);
15530
- }
15531
- }
15532
- for (const [referenceId, consumedFile] of this.filesByReferenceId) {
15533
- if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
15534
- this.finalizeAsset(consumedFile, consumedFile.source, referenceId, this.bundle);
15535
- }
15536
- }
15537
- };
15538
- this.filesByReferenceId = baseFileEmitter
15539
- ? new Map(baseFileEmitter.filesByReferenceId)
15540
- : new Map();
15541
- }
15542
- assignReferenceId(file, idBase) {
15543
- let referenceId;
15544
- do {
15545
- referenceId = createHash()
15546
- .update(referenceId || idBase)
15547
- .digest('hex')
15548
- .substring(0, 8);
15549
- } while (this.filesByReferenceId.has(referenceId));
15550
- this.filesByReferenceId.set(referenceId, file);
15551
- return referenceId;
15552
- }
15553
- emitAsset(emittedAsset) {
15554
- const source = typeof emittedAsset.source !== 'undefined'
15555
- ? getValidSource(emittedAsset.source, emittedAsset, null)
15556
- : undefined;
15557
- const consumedAsset = {
15558
- fileName: emittedAsset.fileName,
15559
- name: emittedAsset.name,
15560
- source,
15561
- type: 'asset'
15562
- };
15563
- const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
15564
- if (this.bundle) {
15565
- if (emittedAsset.fileName) {
15566
- reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
15567
- }
15568
- if (source !== undefined) {
15569
- this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
15570
- }
15571
- }
15572
- return referenceId;
15573
- }
15574
- emitChunk(emittedChunk) {
15575
- if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
15576
- return error(errInvalidRollupPhaseForChunkEmission());
15577
- }
15578
- if (typeof emittedChunk.id !== 'string') {
15579
- return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
15580
- }
15581
- const consumedChunk = {
15582
- fileName: emittedChunk.fileName,
15583
- module: null,
15584
- name: emittedChunk.name || emittedChunk.id,
15585
- type: 'chunk'
15586
- };
15587
- this.graph.moduleLoader
15588
- .emitChunk(emittedChunk)
15589
- .then(module => (consumedChunk.module = module))
15590
- .catch(() => {
15591
- // Avoid unhandled Promise rejection as the error will be thrown later
15592
- // once module loading has finished
15593
- });
15594
- return this.assignReferenceId(consumedChunk, emittedChunk.id);
15595
- }
15596
- finalizeAsset(consumedFile, source, referenceId, bundle) {
15597
- const fileName = consumedFile.fileName ||
15598
- findExistingAssetFileNameWithSource(bundle, source) ||
15599
- generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
15600
- // We must not modify the original assets to avoid interaction between outputs
15601
- const assetWithFileName = { ...consumedFile, fileName, source };
15602
- this.filesByReferenceId.set(referenceId, assetWithFileName);
15603
- const { options } = this;
15604
- bundle[fileName] = {
15605
- fileName,
15606
- get isAsset() {
15607
- warnDeprecation('Accessing "isAsset" on files in the bundle is deprecated, please use "type === \'asset\'" instead', true, options);
15608
- return true;
15609
- },
15610
- name: consumedFile.name,
15611
- source,
15612
- type: 'asset'
15613
- };
15614
- }
15615
- }
15616
- function findExistingAssetFileNameWithSource(bundle, source) {
15617
- for (const [fileName, outputFile] of Object.entries(bundle)) {
15618
- if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
15619
- return fileName;
15620
- }
15621
- return null;
15622
- }
15623
- function areSourcesEqual(sourceA, sourceB) {
15624
- if (typeof sourceA === 'string') {
15625
- return sourceA === sourceB;
15626
- }
15627
- if (typeof sourceB === 'string') {
15628
- return false;
15629
- }
15630
- if ('equals' in sourceA) {
15631
- return sourceA.equals(sourceB);
15632
- }
15633
- if (sourceA.length !== sourceB.length) {
15634
- return false;
15635
- }
15636
- for (let index = 0; index < sourceA.length; index++) {
15637
- if (sourceA[index] !== sourceB[index]) {
15638
- return false;
15639
- }
15640
- }
15641
- return true;
15642
- }
15643
-
15644
15449
  const concatSep = (out, next) => (next ? `${out}\n${next}` : out);
15645
15450
  const concatDblSep = (out, next) => (next ? `${out}\n\n${next}` : out);
15646
15451
  async function createAddons(options, outputPluginDriver) {
@@ -15963,7 +15768,8 @@ class Bundle {
15963
15768
  }
15964
15769
  async generate(isWrite) {
15965
15770
  timeStart('GENERATE', 1);
15966
- const outputBundle = Object.create(null);
15771
+ const outputBundleBase = Object.create(null);
15772
+ const outputBundle = getOutputBundle(outputBundleBase);
15967
15773
  this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions, this.facadeChunkByModule);
15968
15774
  try {
15969
15775
  await this.pluginDriver.hookParallel('renderStart', [this.outputOptions, this.inputOptions]);
@@ -15994,15 +15800,15 @@ class Bundle {
15994
15800
  ]);
15995
15801
  this.finaliseAssets(outputBundle);
15996
15802
  timeEnd('GENERATE', 1);
15997
- return outputBundle;
15803
+ return outputBundleBase;
15998
15804
  }
15999
- async addFinalizedChunksToBundle(chunks, inputBase, addons, outputBundle, snippets) {
16000
- this.assignChunkIds(chunks, inputBase, addons, outputBundle);
15805
+ async addFinalizedChunksToBundle(chunks, inputBase, addons, bundle, snippets) {
15806
+ this.assignChunkIds(chunks, inputBase, addons, bundle);
16001
15807
  for (const chunk of chunks) {
16002
- outputBundle[chunk.id] = chunk.getChunkInfoWithFileNames();
15808
+ bundle[chunk.id] = chunk.getChunkInfoWithFileNames();
16003
15809
  }
16004
15810
  await Promise.all(chunks.map(async (chunk) => {
16005
- const outputChunk = outputBundle[chunk.id];
15811
+ const outputChunk = bundle[chunk.id];
16006
15812
  Object.assign(outputChunk, await chunk.render(this.outputOptions, addons, outputChunk, snippets));
16007
15813
  }));
16008
15814
  }
@@ -22452,6 +22258,238 @@ class GlobalScope extends Scope$1 {
22452
22258
  }
22453
22259
  }
22454
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
+
22455
22493
  function getDeprecatedContextHandler(handler, handlerName, newHandlerName, pluginName, activeDeprecation, options) {
22456
22494
  let deprecationWarningShown = false;
22457
22495
  return ((...args) => {
@@ -23523,6 +23561,7 @@ const getAmd = (config) => {
23523
23561
  autoId: false,
23524
23562
  basePath: '',
23525
23563
  define: 'define',
23564
+ forceJsExtensionForImports: false,
23526
23565
  ...config.amd
23527
23566
  };
23528
23567
  if ((mergedOption.autoId || mergedOption.basePath) && mergedOption.id) {
@@ -23536,13 +23575,15 @@ const getAmd = (config) => {
23536
23575
  normalized = {
23537
23576
  autoId: true,
23538
23577
  basePath: mergedOption.basePath,
23539
- define: mergedOption.define
23578
+ define: mergedOption.define,
23579
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports
23540
23580
  };
23541
23581
  }
23542
23582
  else {
23543
23583
  normalized = {
23544
23584
  autoId: false,
23545
23585
  define: mergedOption.define,
23586
+ forceJsExtensionForImports: mergedOption.forceJsExtensionForImports,
23546
23587
  id: mergedOption.id
23547
23588
  };
23548
23589
  }
@@ -23789,13 +23830,7 @@ function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, out
23789
23830
  }
23790
23831
  function createOutput(outputBundle) {
23791
23832
  return {
23792
- output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => {
23793
- const fileTypeA = getSortingFileType(outputFileA);
23794
- const fileTypeB = getSortingFileType(outputFileB);
23795
- if (fileTypeA === fileTypeB)
23796
- return 0;
23797
- return fileTypeA < fileTypeB ? -1 : 1;
23798
- })
23833
+ output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => getSortingFileType(outputFileA) - getSortingFileType(outputFileB))
23799
23834
  };
23800
23835
  }
23801
23836
  var SortingFileType;