11const HASH_REGEX = / [ a - f 0 - 9 ] { 8 , } / i;
2- const POTENTIAL_HASHES = [
3- "[hash]" ,
4- "[contenthash]" ,
5- "[fullhash]" ,
6- "[chunkhash]" ,
7- ] ;
2+ const POTENTIAL_HASHES = [ "[contenthash" , "[fullhash" , "[chunkhash" , "[hash" ] ;
83
94const escapeRegex = ( string : string ) : string =>
105 string . replace ( / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g, "\\$&" ) . replace ( / - / g, "\\x2d" ) ;
@@ -33,9 +28,10 @@ export const normalizePath = (path: string, format: string): string => {
3328 leadingDelimiter ,
3429 ) } )`;
3530
31+ const closingBracketIndex = format . slice ( match . hashIndex ) . indexOf ( "]" ) ;
3632 // grab the ending delimiter and create a regex group for it
3733 let endingDelimiter =
38- format . at ( match . hashIndex + match . hashString . length ) ?? "" ;
34+ format . at ( match . hashIndex + closingBracketIndex + 1 ) ?? "" ;
3935
4036 // If the ending delimiter is `[extname]` there won't be a
4137 // `.<file-extension>` so we need to replace it with a `.` for the
@@ -48,8 +44,8 @@ export const normalizePath = (path: string, format: string): string => {
4844
4945 // create a regex that will match the hash
5046 // potential values gathered from: https://en.wikipedia.org/wiki/Base64
51- // added in `\-` to account for the `-` character which seems to be used by Rollup through testing
52- const regexString = `(${ leadingRegex } (?<hash>[0-9a-zA-Z\/+=-]+)${ endingRegex } )` ;
47+ // added in `\-` and `\_` to account for the `-` `_` as they are included in the potential hashes: https://rollupjs.org/configuration-options/#output-hashcharacters
48+ const regexString = `(${ leadingRegex } (?<hash>[0-9a-zA-Z/\+=_ \/+=-]+)${ endingRegex } )` ;
5349 const HASH_REPLACE_REGEX = new RegExp ( regexString , "i" ) ;
5450
5551 // replace the hash with a wildcard and the delimiters
0 commit comments