rollup 3.0.0-6 → 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-5
4
- Tue, 06 Sep 2022 05:29:28 GMT - commit 1d085668121abe6be83c28c212a02c181c16d2b8
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-5";
18
+ var version$1 = "3.0.0-6";
19
19
 
20
20
  var charToInteger = {};
21
21
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -14065,293 +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 = '!~{';
14072
- const hashPlaceholderRight = '}~';
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}${toBase64(++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
- return placeholder;
14088
- };
14089
- };
14090
- const REPLACER_REGEX = new RegExp(`${hashPlaceholderLeft}[0-9a-zA-Z_$]{1,${maxHashSize - hashPlaceholderOverhead}}${hashPlaceholderRight}`, 'g');
14091
- const replacePlaceholders = (code, hashesByPlaceholder) => code.replace(REPLACER_REGEX, placeholder => hashesByPlaceholder.get(placeholder) || placeholder);
14092
- const replaceSinglePlaceholder = (code, placeholder, value) => code.replace(REPLACER_REGEX, match => (match === placeholder ? value : match));
14093
- const replacePlaceholdersWithDefaultAndGetContainedPlaceholders = (code, placeholders) => {
14094
- const containedPlaceholders = new Set();
14095
- const transformedCode = code.replace(REPLACER_REGEX, placeholder => {
14096
- if (placeholders.has(placeholder)) {
14097
- containedPlaceholders.add(placeholder);
14098
- return `${hashPlaceholderLeft}${'0'.repeat(placeholder.length - hashPlaceholderOverhead)}${hashPlaceholderRight}`;
14099
- }
14100
- return placeholder;
14101
- });
14102
- return { containedPlaceholders, transformedCode };
14103
- };
14104
-
14105
- function renderNamePattern(pattern, patternName, replacements) {
14106
- if (isPathFragment(pattern))
14107
- 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.`));
14108
- return pattern.replace(/\[(\w+)(:\d+)?]/g, (_match, type, size) => {
14109
- if (!replacements.hasOwnProperty(type) || (size && type !== 'hash')) {
14110
- return error(errFailedValidation(`"[${type}${size || ''}]" is not a valid placeholder in the "${patternName}" pattern.`));
14111
- }
14112
- const replacement = replacements[type](size && parseInt(size.slice(1)));
14113
- if (isPathFragment(replacement))
14114
- return error(errFailedValidation(`Invalid substitution "${replacement}" for placeholder "[${type}]" in "${patternName}" pattern, can be neither absolute nor relative path.`));
14115
- return replacement;
14116
- });
14117
- }
14118
- function makeUnique(name, existingNames) {
14119
- const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
14120
- if (!existingNamesLowercase.has(name.toLocaleLowerCase()))
14121
- return name;
14122
- const ext = extname(name);
14123
- name = name.substring(0, name.length - ext.length);
14124
- let uniqueName, uniqueIndex = 1;
14125
- while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()))
14126
- ;
14127
- return uniqueName;
14128
- }
14129
-
14130
- function generateAssetFileName(name, source, outputOptions, bundle) {
14131
- const emittedName = outputOptions.sanitizeFileName(name || 'asset');
14132
- return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
14133
- ? outputOptions.assetFileNames({ name, source, type: 'asset' })
14134
- : outputOptions.assetFileNames, 'output.assetFileNames', {
14135
- ext: () => extname(emittedName).substring(1),
14136
- extname: () => extname(emittedName),
14137
- hash: size => createHash()
14138
- .update(source)
14139
- .digest('hex')
14140
- .substring(0, size || defaultHashSize),
14141
- name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
14142
- }), bundle);
14143
- }
14144
- function reserveFileNameInBundle(fileName, bundle, warn) {
14145
- if (fileName in bundle) {
14146
- warn(errFileNameConflict(fileName));
14147
- }
14148
- bundle[fileName] = FILE_PLACEHOLDER;
14149
- }
14150
- const FILE_PLACEHOLDER = {
14151
- type: 'placeholder'
14152
- };
14153
- function hasValidType(emittedFile) {
14154
- return Boolean(emittedFile &&
14155
- (emittedFile.type === 'asset' ||
14156
- emittedFile.type === 'chunk'));
14157
- }
14158
- function hasValidName(emittedFile) {
14159
- const validatedName = emittedFile.fileName || emittedFile.name;
14160
- return !validatedName || (typeof validatedName === 'string' && !isPathFragment(validatedName));
14161
- }
14162
- function getValidSource(source, emittedFile, fileReferenceId) {
14163
- if (!(typeof source === 'string' || source instanceof Uint8Array)) {
14164
- const assetName = emittedFile.fileName || emittedFile.name || fileReferenceId;
14165
- 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.`));
14166
- }
14167
- return source;
14168
- }
14169
- function getAssetFileName(file, referenceId) {
14170
- if (typeof file.fileName !== 'string') {
14171
- return error(errAssetNotFinalisedForFileName(file.name || referenceId));
14172
- }
14173
- return file.fileName;
14174
- }
14175
- function getChunkFileName(file, facadeChunkByModule) {
14176
- if (file.fileName) {
14177
- return file.fileName;
14178
- }
14179
- if (facadeChunkByModule) {
14180
- const chunk = facadeChunkByModule.get(file.module);
14181
- return chunk.id || chunk.getFileName();
14182
- }
14183
- return error(errChunkNotGeneratedForFileName(file.fileName || file.name));
14184
- }
14185
- class FileEmitter {
14186
- constructor(graph, options, baseFileEmitter) {
14187
- this.graph = graph;
14188
- this.options = options;
14189
- this.bundle = null;
14190
- this.facadeChunkByModule = null;
14191
- this.outputOptions = null;
14192
- this.emitFile = (emittedFile) => {
14193
- if (!hasValidType(emittedFile)) {
14194
- return error(errFailedValidation(`Emitted files must be of type "asset" or "chunk", received "${emittedFile && emittedFile.type}".`));
14195
- }
14196
- if (!hasValidName(emittedFile)) {
14197
- 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}".`));
14198
- }
14199
- if (emittedFile.type === 'chunk') {
14200
- return this.emitChunk(emittedFile);
14201
- }
14202
- return this.emitAsset(emittedFile);
14203
- };
14204
- this.finaliseAssets = () => {
14205
- for (const [referenceId, emittedFile] of this.filesByReferenceId) {
14206
- if (emittedFile.type === 'asset' && typeof emittedFile.fileName !== 'string')
14207
- return error(errNoAssetSourceSet(emittedFile.name || referenceId));
14208
- }
14209
- };
14210
- this.getFileName = (fileReferenceId) => {
14211
- const emittedFile = this.filesByReferenceId.get(fileReferenceId);
14212
- if (!emittedFile)
14213
- return error(errFileReferenceIdNotFoundForFilename(fileReferenceId));
14214
- if (emittedFile.type === 'chunk') {
14215
- return getChunkFileName(emittedFile, this.facadeChunkByModule);
14216
- }
14217
- return getAssetFileName(emittedFile, fileReferenceId);
14218
- };
14219
- this.setAssetSource = (referenceId, requestedSource) => {
14220
- const consumedFile = this.filesByReferenceId.get(referenceId);
14221
- if (!consumedFile)
14222
- return error(errAssetReferenceIdNotFoundForSetSource(referenceId));
14223
- if (consumedFile.type !== 'asset') {
14224
- return error(errFailedValidation(`Asset sources can only be set for emitted assets but "${referenceId}" is an emitted chunk.`));
14225
- }
14226
- if (consumedFile.source !== undefined) {
14227
- return error(errAssetSourceAlreadySet(consumedFile.name || referenceId));
14228
- }
14229
- const source = getValidSource(requestedSource, consumedFile, referenceId);
14230
- if (this.bundle) {
14231
- this.finalizeAsset(consumedFile, source, referenceId, this.bundle);
14232
- }
14233
- else {
14234
- consumedFile.source = source;
14235
- }
14236
- };
14237
- this.setChunkInformation = (facadeChunkByModule) => {
14238
- this.facadeChunkByModule = facadeChunkByModule;
14239
- };
14240
- this.setOutputBundle = (outputBundle, outputOptions) => {
14241
- this.outputOptions = outputOptions;
14242
- this.bundle = outputBundle;
14243
- for (const emittedFile of this.filesByReferenceId.values()) {
14244
- if (emittedFile.fileName) {
14245
- reserveFileNameInBundle(emittedFile.fileName, this.bundle, this.options.onwarn);
14246
- }
14247
- }
14248
- for (const [referenceId, consumedFile] of this.filesByReferenceId) {
14249
- if (consumedFile.type === 'asset' && consumedFile.source !== undefined) {
14250
- this.finalizeAsset(consumedFile, consumedFile.source, referenceId, this.bundle);
14251
- }
14252
- }
14253
- };
14254
- this.filesByReferenceId = baseFileEmitter
14255
- ? new Map(baseFileEmitter.filesByReferenceId)
14256
- : new Map();
14257
- }
14258
- assignReferenceId(file, idBase) {
14259
- let referenceId;
14260
- do {
14261
- referenceId = createHash()
14262
- .update(referenceId || idBase)
14263
- .digest('hex')
14264
- .substring(0, 8);
14265
- } while (this.filesByReferenceId.has(referenceId));
14266
- this.filesByReferenceId.set(referenceId, file);
14267
- return referenceId;
14268
- }
14269
- emitAsset(emittedAsset) {
14270
- const source = typeof emittedAsset.source !== 'undefined'
14271
- ? getValidSource(emittedAsset.source, emittedAsset, null)
14272
- : undefined;
14273
- const consumedAsset = {
14274
- fileName: emittedAsset.fileName,
14275
- name: emittedAsset.name,
14276
- source,
14277
- type: 'asset'
14278
- };
14279
- const referenceId = this.assignReferenceId(consumedAsset, emittedAsset.fileName || emittedAsset.name || emittedAsset.type);
14280
- if (this.bundle) {
14281
- if (emittedAsset.fileName) {
14282
- reserveFileNameInBundle(emittedAsset.fileName, this.bundle, this.options.onwarn);
14283
- }
14284
- if (source !== undefined) {
14285
- this.finalizeAsset(consumedAsset, source, referenceId, this.bundle);
14286
- }
14287
- }
14288
- return referenceId;
14289
- }
14290
- emitChunk(emittedChunk) {
14291
- if (this.graph.phase > BuildPhase.LOAD_AND_PARSE) {
14292
- return error(errInvalidRollupPhaseForChunkEmission());
14293
- }
14294
- if (typeof emittedChunk.id !== 'string') {
14295
- return error(errFailedValidation(`Emitted chunks need to have a valid string id, received "${emittedChunk.id}"`));
14296
- }
14297
- const consumedChunk = {
14298
- fileName: emittedChunk.fileName,
14299
- module: null,
14300
- name: emittedChunk.name || emittedChunk.id,
14301
- type: 'chunk'
14302
- };
14303
- this.graph.moduleLoader
14304
- .emitChunk(emittedChunk)
14305
- .then(module => (consumedChunk.module = module))
14306
- .catch(() => {
14307
- // Avoid unhandled Promise rejection as the error will be thrown later
14308
- // once module loading has finished
14309
- });
14310
- return this.assignReferenceId(consumedChunk, emittedChunk.id);
14311
- }
14312
- finalizeAsset(consumedFile, source, referenceId, bundle) {
14313
- const fileName = consumedFile.fileName ||
14314
- findExistingAssetFileNameWithSource(bundle, source) ||
14315
- generateAssetFileName(consumedFile.name, source, this.outputOptions, bundle);
14316
- // We must not modify the original assets to avoid interaction between outputs
14317
- const assetWithFileName = { ...consumedFile, fileName, source };
14318
- this.filesByReferenceId.set(referenceId, assetWithFileName);
14319
- bundle[fileName] = {
14320
- fileName,
14321
- name: consumedFile.name,
14322
- source,
14323
- type: 'asset'
14324
- };
14325
- }
14326
- }
14327
- function findExistingAssetFileNameWithSource(bundle, source) {
14328
- for (const [fileName, outputFile] of Object.entries(bundle)) {
14329
- if (outputFile.type === 'asset' && areSourcesEqual(source, outputFile.source))
14330
- return fileName;
14331
- }
14332
- return null;
14333
- }
14334
- function areSourcesEqual(sourceA, sourceB) {
14335
- if (typeof sourceA === 'string') {
14336
- return sourceA === sourceB;
14337
- }
14338
- if (typeof sourceB === 'string') {
14339
- return false;
14340
- }
14341
- if ('equals' in sourceA) {
14342
- return sourceA.equals(sourceB);
14343
- }
14344
- if (sourceA.length !== sourceB.length) {
14345
- return false;
14346
- }
14347
- for (let index = 0; index < sourceA.length; index++) {
14348
- if (sourceA[index] !== sourceB[index]) {
14349
- return false;
14350
- }
14351
- }
14352
- return true;
14353
- }
14354
-
14355
14068
  const concatSep = (out, next) => (next ? `${out}\n${next}` : out);
14356
14069
  const concatDblSep = (out, next) => (next ? `${out}\n\n${next}` : out);
14357
14070
  async function createAddons(options, outputPluginDriver, chunk) {
@@ -14624,6 +14337,93 @@ function addStaticDependencies(module, staticDependencies, handledModules, chunk
14624
14337
  }
14625
14338
  }
14626
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
+
14627
14427
  const NON_ASSET_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts', '.cjs', '.cts'];
14628
14428
  function getGlobalName(chunk, globals, hasExports, warn) {
14629
14429
  const globalName = typeof globals === 'function' ? globals(chunk.id) : globals[chunk.id];
@@ -16033,6 +15833,8 @@ function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain,
16033
15833
  return { version: 3, ...map };
16034
15834
  }
16035
15835
 
15836
+ const createHash = () => createHash$1('sha256');
15837
+
16036
15838
  function decodedSourcemap(map) {
16037
15839
  if (!map)
16038
15840
  return null;
@@ -16051,7 +15853,7 @@ function decodedSourcemap(map) {
16051
15853
  return { ...map, mappings };
16052
15854
  }
16053
15855
 
16054
- async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, onwarn) {
15856
+ async function renderChunks(chunks, bundle, pluginDriver, outputOptions, onwarn) {
16055
15857
  timeStart('render chunks', 2);
16056
15858
  reserveEntryChunksInBundle(chunks);
16057
15859
  const renderedChunks = await Promise.all(chunks.map(chunk => chunk.render()));
@@ -16059,8 +15861,8 @@ async function renderChunks(chunks, outputBundle, pluginDriver, outputOptions, o
16059
15861
  timeStart('transform chunks', 2);
16060
15862
  const chunkGraph = getChunkGraph(chunks);
16061
15863
  const { nonHashedChunksWithPlaceholders, renderedChunksByPlaceholder, hashDependenciesByPlaceholder } = await transformChunksAndGenerateContentHashes(renderedChunks, chunkGraph, outputOptions, pluginDriver, onwarn);
16062
- const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle);
16063
- addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
15864
+ const hashesByPlaceholder = generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, bundle);
15865
+ addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, outputOptions);
16064
15866
  timeEnd('transform chunks', 2);
16065
15867
  }
16066
15868
  function reserveEntryChunksInBundle(chunks) {
@@ -16175,7 +15977,7 @@ async function transformChunksAndGenerateContentHashes(renderedChunks, chunkGrap
16175
15977
  renderedChunksByPlaceholder
16176
15978
  };
16177
15979
  }
16178
- function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, outputBundle) {
15980
+ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlaceholder, bundle) {
16179
15981
  const hashesByPlaceholder = new Map();
16180
15982
  for (const [placeholder, { fileName }] of renderedChunksByPlaceholder) {
16181
15983
  let hash = createHash();
@@ -16198,13 +16000,13 @@ function generateFinalHashes(renderedChunksByPlaceholder, hashDependenciesByPlac
16198
16000
  }
16199
16001
  finalHash = hash.digest('hex').slice(0, placeholder.length);
16200
16002
  finalFileName = replaceSinglePlaceholder(fileName, placeholder, finalHash);
16201
- } while (outputBundle[finalFileName]);
16202
- outputBundle[finalFileName] = FILE_PLACEHOLDER;
16203
- 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);
16204
16006
  }
16205
16007
  return hashesByPlaceholder;
16206
16008
  }
16207
- function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, outputBundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16009
+ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bundle, nonHashedChunksWithPlaceholders, pluginDriver, options) {
16208
16010
  for (const { chunk, code, fileName, map } of renderedChunksByPlaceholder.values()) {
16209
16011
  let updatedCode = replacePlaceholders(code, hashesByPlaceholder);
16210
16012
  const finalFileName = replacePlaceholders(fileName, hashesByPlaceholder);
@@ -16212,7 +16014,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, out
16212
16014
  map.file = replacePlaceholders(map.file, hashesByPlaceholder);
16213
16015
  updatedCode += emitSourceMapAndGetComment(finalFileName, map, pluginDriver, options);
16214
16016
  }
16215
- outputBundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16017
+ bundle[finalFileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16216
16018
  }
16217
16019
  for (const { chunk, code, fileName, map } of nonHashedChunksWithPlaceholders) {
16218
16020
  let updatedCode = hashesByPlaceholder.size
@@ -16221,7 +16023,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, out
16221
16023
  if (map) {
16222
16024
  updatedCode += emitSourceMapAndGetComment(fileName, map, pluginDriver, options);
16223
16025
  }
16224
- outputBundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16026
+ bundle[fileName] = chunk.generateOutputChunk(updatedCode, map, hashesByPlaceholder);
16225
16027
  }
16226
16028
  }
16227
16029
  function emitSourceMapAndGetComment(fileName, map, pluginDriver, { sourcemap, sourcemapBaseUrl }) {
@@ -16251,7 +16053,8 @@ class Bundle {
16251
16053
  }
16252
16054
  async generate(isWrite) {
16253
16055
  timeStart('GENERATE', 1);
16254
- const outputBundle = Object.create(null);
16056
+ const outputBundleBase = Object.create(null);
16057
+ const outputBundle = getOutputBundle(outputBundleBase);
16255
16058
  this.pluginDriver.setOutputBundle(outputBundle, this.outputOptions);
16256
16059
  try {
16257
16060
  timeStart('initialize render', 2);
@@ -16283,7 +16086,7 @@ class Bundle {
16283
16086
  this.finaliseAssets(outputBundle);
16284
16087
  timeEnd('generate bundle', 2);
16285
16088
  timeEnd('GENERATE', 1);
16286
- return outputBundle;
16089
+ return outputBundleBase;
16287
16090
  }
16288
16091
  async addManualChunks(manualChunks) {
16289
16092
  const manualChunkAliasByEntry = new Map();
@@ -16319,17 +16122,19 @@ class Bundle {
16319
16122
  }
16320
16123
  return manualChunkAliasByEntry;
16321
16124
  }
16322
- finaliseAssets(outputBundle) {
16323
- for (const file of Object.values(outputBundle)) {
16324
- if (this.outputOptions.validate && 'code' in file) {
16325
- try {
16326
- this.graph.contextParse(file.code, {
16327
- allowHashBang: true,
16328
- ecmaVersion: 'latest'
16329
- });
16330
- }
16331
- catch (err) {
16332
- 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
+ }
16333
16138
  }
16334
16139
  }
16335
16140
  }
@@ -22653,6 +22458,209 @@ class GlobalScope extends Scope$1 {
22653
22458
  }
22654
22459
  }
22655
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
+
22656
22664
  function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, existingPluginNames) {
22657
22665
  let cacheable = true;
22658
22666
  if (typeof plugin.cacheKey !== 'string') {
@@ -23935,13 +23943,7 @@ function getOutputOptions(inputOptions, unsetInputOptions, rawOutputOptions, out
23935
23943
  }
23936
23944
  function createOutput(outputBundle) {
23937
23945
  return {
23938
- output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => {
23939
- const fileTypeA = getSortingFileType(outputFileA);
23940
- const fileTypeB = getSortingFileType(outputFileB);
23941
- if (fileTypeA === fileTypeB)
23942
- return 0;
23943
- return fileTypeA < fileTypeB ? -1 : 1;
23944
- })
23946
+ output: Object.values(outputBundle).filter(outputFile => Object.keys(outputFile).length > 0).sort((outputFileA, outputFileB) => getSortingFileType(outputFileA) - getSortingFileType(outputFileB))
23945
23947
  };
23946
23948
  }
23947
23949
  var SortingFileType;