rollup 3.0.0-5 → 3.0.0-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v3.0.0-4
4
- Wed, 31 Aug 2022 05:26:36 GMT - commit 392609619bcb75a0c7216f38e40d9573419a8e3f
3
+ Rollup.js v3.0.0-6
4
+ Fri, 23 Sep 2022 04:45:13 GMT - commit 8015be75da6c0861998eb093fb040d0b17679b20
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -15,7 +15,7 @@ import { createHash as createHash$1 } from 'node:crypto';
15
15
  import { promises } from 'node:fs';
16
16
  import { EventEmitter } from 'node:events';
17
17
 
18
- var version$1 = "3.0.0-4";
18
+ var version$1 = "3.0.0-6";
19
19
 
20
20
  var charToInteger = {};
21
21
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -6458,7 +6458,7 @@ function toBase64(num) {
6458
6458
  let outStr = '';
6459
6459
  do {
6460
6460
  const curDigit = num % base;
6461
- num = Math.floor(num / base);
6461
+ num = (num / base) | 0;
6462
6462
  outStr = chars[curDigit] + outStr;
6463
6463
  } while (num !== 0);
6464
6464
  return outStr;
@@ -14065,294 +14065,6 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
14065
14065
 
14066
14066
  const finalisers = { amd, cjs, es, iife, system, umd };
14067
14067
 
14068
- const createHash = () => createHash$1('sha256');
14069
-
14070
- // Four random characters from the private use area to minimize risk of conflicts
14071
- const hashPlaceholderLeft = '\uf7f9\ue4d3';
14072
- const hashPlaceholderRight = '\ue3cc\uf1fe';
14073
- const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length;
14074
- // This is the size of a sha256
14075
- const maxHashSize = 64;
14076
- const defaultHashSize = 8;
14077
- const getHashPlaceholderGenerator = () => {
14078
- let nextIndex = 0;
14079
- return (optionName, hashSize = defaultHashSize) => {
14080
- if (hashSize > maxHashSize) {
14081
- return error(errFailedValidation(`Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.`));
14082
- }
14083
- const placeholder = `${hashPlaceholderLeft}${String(++nextIndex).padStart(hashSize - hashPlaceholderOverhead, '0')}${hashPlaceholderRight}`;
14084
- if (placeholder.length > hashSize) {
14085
- return error(errFailedValidation(`To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.`));
14086
- }
14087
- nextIndex++;
14088
- return placeholder;
14089
- };
14090
- };
14091
- const REPLACER_REGEX = new RegExp(`${hashPlaceholderLeft}\\d{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, 'g');
14092
- const replacePlaceholders = (code, hashesByPlaceholder) => code.replace(REPLACER_REGEX, placeholder => hashesByPlaceholder.get(placeholder) || placeholder);
14093
- const replaceSinglePlaceholder = (code, placeholder, value) => code.replace(REPLACER_REGEX, match => (match === placeholder ? value : match));
14094
- const replacePlaceholdersWithDefaultAndGetContainedPlaceholders = (code, placeholders) => {
14095
- const containedPlaceholders = new Set();
14096
- const transformedCode = code.replace(REPLACER_REGEX, placeholder => {
14097
- if (placeholders.has(placeholder)) {
14098
- containedPlaceholders.add(placeholder);
14099
- return `${hashPlaceholderLeft}${'0'.repeat(placeholder.length - hashPlaceholderOverhead)}${hashPlaceholderRight}`;
14100
- }
14101
- return placeholder;
14102
- });
14103
- return { containedPlaceholders, transformedCode };
14104
- };
14105
-
14106
- function renderNamePattern(pattern, patternName, replacements) {
14107
- if (isPathFragment(pattern))
14108
- 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.`));
14109
- return pattern.replace(/\[(\w+)(:\d+)?]/g, (_match, type, size) => {
14110
- if (!replacements.hasOwnProperty(type) || (size && type !== 'hash')) {
14111
- return error(errFailedValidation(`"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.`));
14112
- }
14113
- const replacement = replacements[type](size && parseInt(size.slice(1)));
14114
- if (isPathFragment(replacement))
14115
- return error(errFailedValidation(`Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.`));
14116
- return replacement;
14117
- });
14118
- }
14119
- function makeUnique(name, existingNames) {
14120
- const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14121
- if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14122
- return name;
14123
- const ext = extname(name);
14124
- name = name.substring(0, name.length - ext.length);
14125
- let uniqueName, uniqueIndex = 1;
14126
- while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14127
- ;
14128
- return uniqueName;
14129
- }
14130
-
14131
- function generateAssetFileName(name, source, outputOptions, bundle) {
14132
- const emittedName = outputOptions.sanitizeFileName(name || 'asset');
14133
- return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
14134
- ? outputOptions.assetFileNames({ name, source, type: 'asset' })
14135
- : outputOptions.assetFileNames, 'output.assetFileNames', {
14136
- ext: () => extname(emittedName).substring(1),
14137
- extname: () => extname(emittedName),
14138
- hash: size => createHash()
14139
- .update(source)
14140
- .digest('hex')
14141
- .substring(0, size || defaultHashSize),
14142
- name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
14143
- }), bundle);
14144
- }
14145
- function reserveFileNameInBundle(fileName, bundle, warn) {
14146
- if (fileName in bundle) {
14147
- warn(errFileNameConflict(fileName));
14148
- }
14149
- bundle[fileName] = FILE_PLACEHOLDER;
14150
- }
14151
- const FILE_PLACEHOLDER = {
14152
- type: 'placeholder'
14153
- };
14154
- function hasValidType(emittedFile) {
14155
- return Boolean(emittedFile &&
14156
- (emittedFile.type === 'asset' ||
14157
- emittedFile.type === 'chunk'));
14158
- }
14159
- function hasValidName(emittedFile) {
14160
- const validatedName = emittedFile.fileName || emittedFile.name;
14161
- return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
14162
- }
14163
- function getValidSource(source, emittedFile, fileReferenceId) {
14164
- if (!(typeof source === 'string' || source instanceof Uint8Array)) {
14165
- const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
14166
- 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.`));
14167
- }
14168
- return source;
14169
- }
14170
- function getAssetFileName(file, referenceId) {
14171
- if (typeof file.fileName !== 'string') {
14172
- return error(errAssetNotFinalisedForFileName(file.name || referenceId));
14173
- }
14174
- return file.fileName;
14175
- }
14176
- function getChunkFileName(file, facadeChunkByModule) {
14177
- if (file.fileName) {
14178
- return file.fileName;
14179
- }
14180
- if (facadeChunkByModule) {
14181
- const chunk = facadeChunkByModule.get(file.module);
14182
- return chunk.id || chunk.getFileName();
14183
- }
14184
- return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
14185
- }
14186
- class FileEmitter {
14187
- constructor(graph, options, baseFileEmitter) {
14188
- this.graph = graph;
14189
- this.options = options;
14190
- this.bundle = null;
14191
- this.facadeChunkByModule = null;
14192
- this.outputOptions = null;
14193
- this.emitFile = (emittedFile) => {
14194
- if (!hasValidType(emittedFile)) {
14195
- return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
14196
- }
14197
- if (!hasValidName(emittedFile)) {
14198
- 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}".`));
14199
- }
14200
- if (emittedFile.type === 'chunk') {
14201
- return this.emitChunk(emittedFile);
14202
- }
14203
- return this.emitAsset(emittedFile);
14204
- };
14205
- this.finaliseAssets = () => {
14206
- for (const [referenceId, emittedFile] of this.filesByReferenceId) {
14207
- if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
14208
- return error(errNoAssetSourceSet(emittedFile.name || referenceId));
14209
- }
14210
- };
14211
- this.getFileName = (fileReferenceId) => {
14212
- const emittedFile = this.filesByReferenceId.get(fileReferenceId);
14213
- if (!emittedFile)
14214
- return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
14215
- if (emittedFile.type === 'chunk') {
14216
- return getChunkFileName(emittedFile, this.facadeChunkByModule);
14217
- }
14218
- return getAssetFileName(emittedFile, fileReferenceId);
14219
- };
14220
- this.setAssetSource = (referenceId, requestedSource) => {
14221
- const consumedFile = this.filesByReferenceId.get(referenceId);
14222
- if (!consumedFile)
14223
- return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
14224
- if (consumedFile.type !== 'asset') {
14225
- return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
14226
- }
14227
- if (consumedFile.source !== undefined) {
14228
- return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
14229
- }
14230
- const source = getValidSource(requestedSource, consumedFile, referenceId);
14231
- if (this.bundle) {
14232
- this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
14233
- }
14234
- else {
14235
- consumedFile.source = source;
14236
- }
14237
- };
14238
- this.setChunkInformation = (facadeChunkByModule) => {
14239
- this.facadeChunkByModule = facadeChunkByModule;
14240
- };
14241
- this.setOutputBundle = (outputBundle, outputOptions) => {
14242
- this.outputOptions = outputOptions;
14243
- this.bundle = outputBundle;
14244
- for (const emittedFile of this.filesByReferenceId.values()) {
14245
- if (emittedFile.fileName) {
14246
- reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn);
14247
- }
14248
- }
14249
- for (const [referenceId, consumedFile] of this.filesByReferenceId) {
14250
- if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
14251
- this.finalizeAsset(consumedFile, consumedFile.source, referenceId, this.bundle);
14252
- }
14253
- }
14254
- };
14255
- this.filesByReferenceId = baseFileEmitter
14256
- ? new Map(baseFileEmitter.filesByReferenceId)
14257
- : new Map();
14258
- }
14259
- assignReferenceId(file, idBase) {
14260
- let referenceId;
14261
- do {
14262
- referenceId = createHash()
14263
- .update(referenceId || idBase)
14264
- .digest('hex')
14265
- .substring(0, 8);
14266
- } while (this.filesByReferenceId.has(referenceId));
14267
- this.filesByReferenceId.set(referenceId, file);
14268
- return referenceId;
14269
- }
14270
- emitAsset(emittedAsset) {
14271
- const source = typeof emittedAsset.source !== 'undefined'
14272
- ? getValidSource(emittedAsset.source, emittedAsset, null)
14273
- : undefined;
14274
- const consumedAsset = {
14275
- fileName: emittedAsset.fileName,
14276
- name: emittedAsset.name,
14277
- source,
14278
- type: 'asset'
14279
- };
14280
- const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
14281
- if (this.bundle) {
14282
- if (emittedAsset.fileName) {
14283
- reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
14284
- }
14285
- if (source !== undefined) {
14286
- this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
14287
- }
14288
- }
14289
- return referenceId;
14290
- }
14291
- emitChunk(emittedChunk) {
14292
- if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
14293
- return error(errInvalidRollupPhaseForChunkEmission());
14294
- }
14295
- if (typeof emittedChunk.id !== 'string') {
14296
- return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
14297
- }
14298
- const consumedChunk = {
14299
- fileName: emittedChunk.fileName,
14300
- module: null,
14301
- name: emittedChunk.name || emittedChunk.id,
14302
- type: 'chunk'
14303
- };
14304
- this.graph.moduleLoader
14305
- .emitChunk(emittedChunk)
14306
- .then(module => (consumedChunk.module = module))
14307
- .catch(() => {
14308
- // Avoid unhandled Promise rejection as the error will be thrown later
14309
- // once module loading has finished
14310
- });
14311
- return this.assignReferenceId(consumedChunk, emittedChunk.id);
14312
- }
14313
- finalizeAsset(consumedFile, source, referenceId, bundle) {
14314
- const fileName = consumedFile.fileName ||
14315
- findExistingAssetFileNameWithSource(bundle, source) ||
14316
- generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
14317
- // We must not modify the original assets to avoid interaction between outputs
14318
- const assetWithFileName = { ...consumedFile, fileName, source };
14319
- this.filesByReferenceId.set(referenceId, assetWithFileName);
14320
- bundle[fileName] = {
14321
- fileName,
14322
- name: consumedFile.name,
14323
- source,
14324
- type: 'asset'
14325
- };
14326
- }
14327
- }
14328
- function findExistingAssetFileNameWithSource(bundle, source) {
14329
- for (const [fileName, outputFile] of Object.entries(bundle)) {
14330
- if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
14331
- return fileName;
14332
- }
14333
- return null;
14334
- }
14335
- function areSourcesEqual(sourceA, sourceB) {
14336
- if (typeof sourceA === 'string') {
14337
- return sourceA === sourceB;
14338
- }
14339
- if (typeof sourceB === 'string') {
14340
- return false;
14341
- }
14342
- if ('equals' in sourceA) {
14343
- return sourceA.equals(sourceB);
14344
- }
14345
- if (sourceA.length !== sourceB.length) {
14346
- return false;
14347
- }
14348
- for (let index = 0; index < sourceA.length; index++) {
14349
- if (sourceA[index] !== sourceB[index]) {
14350
- return false;
14351
- }
14352
- }
14353
- return true;
14354
- }
14355
-
14356
14068
  const concatSep = (out, next) => (next ? `${out}\n${next}` : out);
14357
14069
  const concatDblSep = (out, next) => (next ? `${out}\n\n${next}` : out);
14358
14070
  async function createAddons(options, outputPluginDriver, chunk) {
@@ -14625,6 +14337,93 @@ function addStaticDependencies(module, staticDependencies, handledModules, chunk
14625
14337
  }
14626
14338
  }
14627
14339
 
14340
+ // Four random characters from the private use area to minimize risk of conflicts
14341
+ const hashPlaceholderLeft = '!~{';
14342
+ const hashPlaceholderRight = '}~';
14343
+ const hashPlaceholderOverhead = hashPlaceholderLeft.length + hashPlaceholderRight.length;
14344
+ // This is the size of a sha256
14345
+ const maxHashSize = 64;
14346
+ const defaultHashSize = 8;
14347
+ const getHashPlaceholderGenerator = () => {
14348
+ let nextIndex = 0;
14349
+ return (optionName, hashSize = defaultHashSize) => {
14350
+ if (hashSize > maxHashSize) {
14351
+ return error(errFailedValidation(`Hashes cannot be longer than ${maxHashSize} characters, received ${hashSize}. Check the "${optionName}" option.`));
14352
+ }
14353
+ const placeholder = `${hashPlaceholderLeft}${toBase64(++nextIndex).padStart(hashSize - hashPlaceholderOverhead, '0')}${hashPlaceholderRight}`;
14354
+ if (placeholder.length > hashSize) {
14355
+ return error(errFailedValidation(`To generate hashes for this number of chunks (currently ${nextIndex}), you need a minimum hash size of ${placeholder.length}, received ${hashSize}. Check the "${optionName}" option.`));
14356
+ }
14357
+ return placeholder;
14358
+ };
14359
+ };
14360
+ const REPLACER_REGEX = new RegExp(`${hashPlaceholderLeft}[0-9a-zA-Z_$]{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, 'g');
14361
+ const replacePlaceholders = (code, hashesByPlaceholder) => code.replace(REPLACER_REGEX, placeholder => hashesByPlaceholder.get(placeholder) || placeholder);
14362
+ const replaceSinglePlaceholder = (code, placeholder, value) => code.replace(REPLACER_REGEX, match => (match === placeholder ? value : match));
14363
+ const replacePlaceholdersWithDefaultAndGetContainedPlaceholders = (code, placeholders) => {
14364
+ const containedPlaceholders = new Set();
14365
+ const transformedCode = code.replace(REPLACER_REGEX, placeholder => {
14366
+ if (placeholders.has(placeholder)) {
14367
+ containedPlaceholders.add(placeholder);
14368
+ return `${hashPlaceholderLeft}${'0'.repeat(placeholder.length - hashPlaceholderOverhead)}${hashPlaceholderRight}`;
14369
+ }
14370
+ return placeholder;
14371
+ });
14372
+ return { containedPlaceholders, transformedCode };
14373
+ };
14374
+
14375
+ const lowercaseBundleKeys = Symbol('bundleKeys');
14376
+ const FILE_PLACEHOLDER = {
14377
+ type: 'placeholder'
14378
+ };
14379
+ const getOutputBundle = (outputBundleBase) => {
14380
+ const reservedLowercaseBundleKeys = new Set();
14381
+ return new Proxy(outputBundleBase, {
14382
+ deleteProperty(target, key) {
14383
+ if (typeof key === 'string') {
14384
+ reservedLowercaseBundleKeys.delete(key.toLowerCase());
14385
+ }
14386
+ return Reflect.deleteProperty(target, key);
14387
+ },
14388
+ get(target, key) {
14389
+ if (key === lowercaseBundleKeys) {
14390
+ return reservedLowercaseBundleKeys;
14391
+ }
14392
+ return Reflect.get(target, key);
14393
+ },
14394
+ set(target, key, value) {
14395
+ if (typeof key === 'string') {
14396
+ reservedLowercaseBundleKeys.add(key.toLowerCase());
14397
+ }
14398
+ return Reflect.set(target, key, value);
14399
+ }
14400
+ });
14401
+ };
14402
+
14403
+ function renderNamePattern(pattern, patternName, replacements) {
14404
+ if (isPathFragment(pattern))
14405
+ 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.`));
14406
+ return pattern.replace(/\[(\w+)(:\d+)?]/g, (_match, type, size) => {
14407
+ if (!replacements.hasOwnProperty(type) || (size && type !== 'hash')) {
14408
+ return error(errFailedValidation(`"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.`));
14409
+ }
14410
+ const replacement = replacements[type](size && parseInt(size.slice(1)));
14411
+ if (isPathFragment(replacement))
14412
+ return error(errFailedValidation(`Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.`));
14413
+ return replacement;
14414
+ });
14415
+ }
14416
+ function makeUnique(name, { [lowercaseBundleKeys]: reservedLowercaseBundleKeys }) {
14417
+ if (!reservedLowercaseBundleKeys.has(name.toLowerCase()))
14418
+ return name;
14419
+ const ext = extname(name);
14420
+ name = name.substring(0, name.length - ext.length);
14421
+ let uniqueName, uniqueIndex = 1;
14422
+ while (reservedLowercaseBundleKeys.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14423
+ ;
14424
+ return uniqueName;
14425
+ }
14426
+
14628
14427
  const NON_ASSET_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts', '.cjs', '.cts'];
14629
14428
  function getGlobalName(chunk, globals, hasExports, warn) {
14630
14429
  const globalName = typeof globals === 'function' ? globals(chunk.id) : globals[chunk.id];
@@ -16034,6 +15833,8 @@ function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain,
16034
15833
  return { version: 3, ...map };
16035
15834
  }
16036
15835
 
15836
+ const createHash = () => createHash$1('sha256');
15837
+
16037
15838
  function decodedSourcemap(map) {
16038
15839
  if (!map)
16039
15840
  return null;
@@ -16052,7 +15853,7 @@ function decodedSourcemap(map) {
16052
15853
  return { ...map, mappings };
16053
15854
  }
16054
15855
 
16055
- async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, onwarn) {
15856
+ async function renderChunks(chunks, bundle, pluginDriver, outputOptions, onwarn) {
16056
15857
  timeStart('render chunks', 2);
16057
15858
  reserveEntryChunksInBundle(chunks);
16058
15859
  const renderedChunks = await Promise.all(chunks.map(chunk => chunk.render()));
@@ -16060,8 +15861,8 @@ async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, o
16060
15861
  timeStart('transform chunks', 2);
16061
15862
  const chunkGraph = getChunkGraph(chunks);
16062
15863
  const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
16063
- const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle);
16064
- addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
15864
+ const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, bundle);
15865
+ addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
16065
15866
  timeEnd('transform chunks', 2);
16066
15867
  }
16067
15868
  function reserveEntryChunksInBundle(chunks) {
@@ -16176,7 +15977,7 @@ async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGrap
16176
15977
  renderedChunksByPlaceholder
16177
15978
  };
16178
15979
  }
16179
- function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle) {
15980
+ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, bundle) {
16180
15981
  const hashesByPlaceholder = new Map();
16181
15982
  for (const [placeholder, { fileName }] of renderedChunksByPlaceholder) {
16182
15983
  let hash = createHash();
@@ -16199,13 +16000,13 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
16199
16000
  }
16200
16001
  finalHash = hash.digest('hex').slice(0, placeholder.length);
16201
16002
  finalFileName = replaceSinglePlaceholder(fileName, placeholder, finalHash);
16202
- } while (outputBundle[finalFileName]);
16203
- outputBundle[finalFileName] = FILE_PLACEHOLDER;
16204
- hashesByPlaceholder.set(placeholder, finalHash.slice(0, placeholder.length));
16003
+ } while (bundle[lowercaseBundleKeys].has(finalFileName.toLowerCase()));
16004
+ bundle[finalFileName] = FILE_PLACEHOLDER;
16005
+ hashesByPlaceholder.set(placeholder, finalHash);
16205
16006
  }
16206
16007
  return hashesByPlaceholder;
16207
16008
  }
16208
- function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16009
+ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16209
16010
  for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) {
16210
16011
  let updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16211
16012
  const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
@@ -16213,7 +16014,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, out
16213
16014
  map.file = replacePlaceholders(map.file, hashesByPlaceholder);
16214
16015
  updatedCode += emitSourceMapAndGetComment(finalFileName, map, pluginDriver, options);
16215
16016
  }
16216
- outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16017
+ bundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16217
16018
  }
16218
16019
  for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) {
16219
16020
  let updatedCode = hashesByPlaceholder.size
@@ -16222,7 +16023,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, out
16222
16023
  if (map) {
16223
16024
  updatedCode += emitSourceMapAndGetComment(fileName, map, pluginDriver, options);
16224
16025
  }
16225
- outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16026
+ bundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16226
16027
  }
16227
16028
  }
16228
16029
  function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
@@ -16252,7 +16053,8 @@ class Bundle {
16252
16053
  }
16253
16054
  async generate(isWrite) {
16254
16055
  timeStart('GENERATE', 1);
16255
- const outputBundle = Object.create(null);
16056
+ const outputBundleBase = Object.create(null);
16057
+ const outputBundle = getOutputBundle(outputBundleBase);
16256
16058
  this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions);
16257
16059
  try {
16258
16060
  timeStart('initialize render', 2);
@@ -16284,7 +16086,7 @@ class Bundle {
16284
16086
  this.finaliseAssets(outputBundle);
16285
16087
  timeEnd('generate bundle', 2);
16286
16088
  timeEnd('GENERATE', 1);
16287
- return outputBundle;
16089
+ return outputBundleBase;
16288
16090
  }
16289
16091
  async addManualChunks(manualChunks) {
16290
16092
  const manualChunkAliasByEntry = new Map();
@@ -16320,17 +16122,19 @@ class Bundle {
16320
16122
  }
16321
16123
  return manualChunkAliasByEntry;
16322
16124
  }
16323
- finaliseAssets(outputBundle) {
16324
- for (const file of Object.values(outputBundle)) {
16325
- if (this.outputOptions.validate && 'code' in file) {
16326
- try {
16327
- this.graph.contextParse(file.code, {
16328
- allowHashBang: true,
16329
- ecmaVersion: 'latest'
16330
- });
16331
- }
16332
- catch (err) {
16333
- this.inputOptions.onwarn(errChunkInvalid(file, err));
16125
+ finaliseAssets(bundle) {
16126
+ if (this.outputOptions.validate) {
16127
+ for (const file of Object.values(bundle)) {
16128
+ if ('code' in file) {
16129
+ try {
16130
+ this.graph.contextParse(file.code, {
16131
+ allowHashBang: true,
16132
+ ecmaVersion: 'latest'
16133
+ });
16134
+ }
16135
+ catch (err) {
16136
+ this.inputOptions.onwarn(errChunkInvalid(file, err));
16137
+ }
16334
16138
  }
16335
16139
  }
16336
16140
  }
@@ -22654,6 +22458,209 @@ class GlobalScope extends Scope$1 {
22654
22458
  }
22655
22459
  }
22656
22460
 
22461
+ function generateAssetFileName(name, source, outputOptions, bundle) {
22462
+ const emittedName = outputOptions.sanitizeFileName(name || 'asset');
22463
+ return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
22464
+ ? outputOptions.assetFileNames({ name, source, type: 'asset' })
22465
+ : outputOptions.assetFileNames, 'output.assetFileNames', {
22466
+ ext: () => extname(emittedName).substring(1),
22467
+ extname: () => extname(emittedName),
22468
+ hash: size => createHash()
22469
+ .update(source)
22470
+ .digest('hex')
22471
+ .substring(0, size || defaultHashSize),
22472
+ name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
22473
+ }), bundle);
22474
+ }
22475
+ function reserveFileNameInBundle(fileName, { bundle }, warn) {
22476
+ if (bundle[lowercaseBundleKeys].has(fileName.toLowerCase())) {
22477
+ warn(errFileNameConflict(fileName));
22478
+ }
22479
+ else {
22480
+ bundle[fileName] = FILE_PLACEHOLDER;
22481
+ }
22482
+ }
22483
+ function hasValidType(emittedFile) {
22484
+ return Boolean(emittedFile &&
22485
+ (emittedFile.type === 'asset' ||
22486
+ emittedFile.type === 'chunk'));
22487
+ }
22488
+ function hasValidName(emittedFile) {
22489
+ const validatedName = emittedFile.fileName || emittedFile.name;
22490
+ return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
22491
+ }
22492
+ function getValidSource(source, emittedFile, fileReferenceId) {
22493
+ if (!(typeof source === 'string' || source instanceof Uint8Array)) {
22494
+ const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
22495
+ 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.`));
22496
+ }
22497
+ return source;
22498
+ }
22499
+ function getAssetFileName(file, referenceId) {
22500
+ if (typeof file.fileName !== 'string') {
22501
+ return error(errAssetNotFinalisedForFileName(file.name || referenceId));
22502
+ }
22503
+ return file.fileName;
22504
+ }
22505
+ function getChunkFileName(file, facadeChunkByModule) {
22506
+ if (file.fileName) {
22507
+ return file.fileName;
22508
+ }
22509
+ if (facadeChunkByModule) {
22510
+ const chunk = facadeChunkByModule.get(file.module);
22511
+ return chunk.id || chunk.getFileName();
22512
+ }
22513
+ return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
22514
+ }
22515
+ class FileEmitter {
22516
+ constructor(graph, options, baseFileEmitter) {
22517
+ this.graph = graph;
22518
+ this.options = options;
22519
+ this.facadeChunkByModule = null;
22520
+ this.nextIdBase = 1;
22521
+ this.output = null;
22522
+ this.emitFile = (emittedFile) => {
22523
+ if (!hasValidType(emittedFile)) {
22524
+ return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
22525
+ }
22526
+ if (!hasValidName(emittedFile)) {
22527
+ 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}".`));
22528
+ }
22529
+ if (emittedFile.type === 'chunk') {
22530
+ return this.emitChunk(emittedFile);
22531
+ }
22532
+ return this.emitAsset(emittedFile);
22533
+ };
22534
+ this.finaliseAssets = () => {
22535
+ for (const [referenceId, emittedFile] of this.filesByReferenceId) {
22536
+ if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
22537
+ return error(errNoAssetSourceSet(emittedFile.name || referenceId));
22538
+ }
22539
+ };
22540
+ this.getFileName = (fileReferenceId) => {
22541
+ const emittedFile = this.filesByReferenceId.get(fileReferenceId);
22542
+ if (!emittedFile)
22543
+ return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
22544
+ if (emittedFile.type === 'chunk') {
22545
+ return getChunkFileName(emittedFile, this.facadeChunkByModule);
22546
+ }
22547
+ return getAssetFileName(emittedFile, fileReferenceId);
22548
+ };
22549
+ this.setAssetSource = (referenceId, requestedSource) => {
22550
+ const consumedFile = this.filesByReferenceId.get(referenceId);
22551
+ if (!consumedFile)
22552
+ return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
22553
+ if (consumedFile.type !== 'asset') {
22554
+ return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
22555
+ }
22556
+ if (consumedFile.source !== undefined) {
22557
+ return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
22558
+ }
22559
+ const source = getValidSource(requestedSource, consumedFile, referenceId);
22560
+ if (this.output) {
22561
+ this.finalizeAsset(consumedFile, source, referenceId, this.output);
22562
+ }
22563
+ else {
22564
+ consumedFile.source = source;
22565
+ }
22566
+ };
22567
+ this.setChunkInformation = (facadeChunkByModule) => {
22568
+ this.facadeChunkByModule = facadeChunkByModule;
22569
+ };
22570
+ this.setOutputBundle = (bundle, outputOptions) => {
22571
+ const fileNamesBySource = new Map();
22572
+ const output = (this.output = { bundle, fileNamesBySource, outputOptions });
22573
+ for (const emittedFile of this.filesByReferenceId.values()) {
22574
+ if (emittedFile.fileName) {
22575
+ reserveFileNameInBundle(emittedFile.fileName, output, this.options.onwarn);
22576
+ if (emittedFile.type === 'asset' && typeof emittedFile.source === 'string') {
22577
+ fileNamesBySource.set(emittedFile.source, emittedFile.fileName);
22578
+ }
22579
+ }
22580
+ }
22581
+ for (const [referenceId, consumedFile] of this.filesByReferenceId) {
22582
+ if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
22583
+ this.finalizeAsset(consumedFile, consumedFile.source, referenceId, output);
22584
+ }
22585
+ }
22586
+ };
22587
+ this.filesByReferenceId = baseFileEmitter
22588
+ ? new Map(baseFileEmitter.filesByReferenceId)
22589
+ : new Map();
22590
+ }
22591
+ assignReferenceId(file, idBase) {
22592
+ let referenceId;
22593
+ do {
22594
+ referenceId = createHash()
22595
+ .update(referenceId || idBase)
22596
+ .digest('hex')
22597
+ .substring(0, 8);
22598
+ } while (this.filesByReferenceId.has(referenceId));
22599
+ this.filesByReferenceId.set(referenceId, file);
22600
+ return referenceId;
22601
+ }
22602
+ emitAsset(emittedAsset) {
22603
+ const source = typeof emittedAsset.source !== 'undefined'
22604
+ ? getValidSource(emittedAsset.source, emittedAsset, null)
22605
+ : undefined;
22606
+ const consumedAsset = {
22607
+ fileName: emittedAsset.fileName,
22608
+ name: emittedAsset.name,
22609
+ source,
22610
+ type: 'asset'
22611
+ };
22612
+ const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || String(this.nextIdBase++));
22613
+ if (this.output) {
22614
+ if (emittedAsset.fileName) {
22615
+ reserveFileNameInBundle(emittedAsset.fileName, this.output, this.options.onwarn);
22616
+ }
22617
+ if (source !== undefined) {
22618
+ this.finalizeAsset(consumedAsset, source, referenceId, this.output);
22619
+ }
22620
+ }
22621
+ return referenceId;
22622
+ }
22623
+ emitChunk(emittedChunk) {
22624
+ if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
22625
+ return error(errInvalidRollupPhaseForChunkEmission());
22626
+ }
22627
+ if (typeof emittedChunk.id !== 'string') {
22628
+ return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
22629
+ }
22630
+ const consumedChunk = {
22631
+ fileName: emittedChunk.fileName,
22632
+ module: null,
22633
+ name: emittedChunk.name || emittedChunk.id,
22634
+ type: 'chunk'
22635
+ };
22636
+ this.graph.moduleLoader
22637
+ .emitChunk(emittedChunk)
22638
+ .then(module => (consumedChunk.module = module))
22639
+ .catch(() => {
22640
+ // Avoid unhandled Promise rejection as the error will be thrown later
22641
+ // once module loading has finished
22642
+ });
22643
+ return this.assignReferenceId(consumedChunk, emittedChunk.id);
22644
+ }
22645
+ finalizeAsset(consumedFile, source, referenceId, { bundle, fileNamesBySource, outputOptions }) {
22646
+ const fileName = consumedFile.fileName ||
22647
+ (typeof source === 'string' && fileNamesBySource.get(source)) ||
22648
+ generateAssetFileName(consumedFile.name, source, outputOptions, bundle);
22649
+ // We must not modify the original assets to avoid interaction between outputs
22650
+ const assetWithFileName = { ...consumedFile, fileName, source };
22651
+ this.filesByReferenceId.set(referenceId, assetWithFileName);
22652
+ if (typeof source === 'string') {
22653
+ fileNamesBySource.set(source, fileName);
22654
+ }
22655
+ bundle[fileName] = {
22656
+ fileName,
22657
+ name: consumedFile.name,
22658
+ source,
22659
+ type: 'asset'
22660
+ };
22661
+ }
22662
+ }
22663
+
22657
22664
  function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, existingPluginNames) {
22658
22665
  let cacheable = true;
22659
22666
  if (typeof plugin.cacheKey !== 'string') {
@@ -23936,13 +23943,7 @@ function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, out
23936
23943
  }
23937
23944
  function createOutput(outputBundle) {
23938
23945
  return {
23939
- output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => {
23940
- const fileTypeA = getSortingFileType(outputFileA);
23941
- const fileTypeB = getSortingFileType(outputFileB);
23942
- if (fileTypeA === fileTypeB)
23943
- return 0;
23944
- return fileTypeA < fileTypeB ? -1 : 1;
23945
- })
23946
+ output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => getSortingFileType(outputFileA) - getSortingFileType(outputFileB))
23946
23947
  };
23947
23948
  }
23948
23949
  var SortingFileType;