@@ -3,10 +3,8 @@ import type Graph from '../Graph';
33import type Module from '../Module' ;
44import type {
55 EmittedChunk ,
6- FilePlaceholder ,
76 NormalizedInputOptions ,
87 NormalizedOutputOptions ,
9- OutputBundleWithPlaceholders ,
108 WarningHandler
119} from '../rollup/types' ;
1210import { BuildPhase } from './buildPhase' ;
@@ -24,6 +22,11 @@ import {
2422 error ,
2523 warnDeprecation
2624} from './error' ;
25+ import {
26+ FILE_PLACEHOLDER ,
27+ lowercaseBundleKeys ,
28+ OutputBundleWithPlaceholders
29+ } from './outputBundle' ;
2730import { extname } from './path' ;
2831import { isPathFragment } from './relativeId' ;
2932import { makeUnique , renderNamePattern } from './renderNamePattern' ;
@@ -64,10 +67,12 @@ function reserveFileNameInBundle(
6467 bundle : OutputBundleWithPlaceholders ,
6568 warn : WarningHandler
6669) {
67- if ( fileName in bundle ) {
70+ const lowercaseFileName = fileName . toLowerCase ( ) ;
71+ if ( bundle [ lowercaseBundleKeys ] . has ( lowercaseFileName ) ) {
6872 warn ( errFileNameConflict ( fileName ) ) ;
73+ } else {
74+ bundle [ fileName ] = FILE_PLACEHOLDER ;
6975 }
70- bundle [ fileName ] = FILE_PLACEHOLDER ;
7176}
7277
7378interface ConsumedChunk {
@@ -93,10 +98,6 @@ interface EmittedFile {
9398
9499type ConsumedFile = ConsumedChunk | ConsumedAsset ;
95100
96- export const FILE_PLACEHOLDER : FilePlaceholder = {
97- type : 'placeholder'
98- } ;
99-
100101function hasValidType (
101102 emittedFile : unknown
102103) : emittedFile is { [ key : string ] : unknown ; type : 'asset' | 'chunk' } {
@@ -228,21 +229,21 @@ export class FileEmitter {
228229 } ;
229230
230231 public setOutputBundle = (
231- outputBundle : OutputBundleWithPlaceholders ,
232+ bundle : OutputBundleWithPlaceholders ,
232233 outputOptions : NormalizedOutputOptions ,
233234 facadeChunkByModule : ReadonlyMap < Module , Chunk >
234235 ) : void => {
235236 this . outputOptions = outputOptions ;
236- this . bundle = outputBundle ;
237+ this . bundle = bundle ;
237238 this . facadeChunkByModule = facadeChunkByModule ;
238- for ( const emittedFile of this . filesByReferenceId . values ( ) ) {
239- if ( emittedFile . fileName ) {
240- reserveFileNameInBundle ( emittedFile . fileName , this . bundle , this . options . onwarn ) ;
239+ for ( const { fileName } of this . filesByReferenceId . values ( ) ) {
240+ if ( fileName ) {
241+ reserveFileNameInBundle ( fileName , bundle , this . options . onwarn ) ;
241242 }
242243 }
243244 for ( const [ referenceId , consumedFile ] of this . filesByReferenceId ) {
244245 if ( consumedFile . type === 'asset' && consumedFile . source !== undefined ) {
245- this . finalizeAsset ( consumedFile , consumedFile . source , referenceId , this . bundle ) ;
246+ this . finalizeAsset ( consumedFile , consumedFile . source , referenceId , bundle ) ;
246247 }
247248 }
248249 } ;
@@ -348,6 +349,9 @@ export class FileEmitter {
348349 }
349350}
350351
352+ // TODO This can lead to a performance problem when many assets are emitted.
353+ // Instead, we should only deduplicate string assets and use their sources as
354+ // object keys for better performance.
351355function findExistingAssetFileNameWithSource (
352356 bundle : OutputBundleWithPlaceholders ,
353357 source : string | Uint8Array
0 commit comments