Open ebello opened 10 years ago
Good stuff! I ran in to this bug myself on the weekend
Error: Warning: Invalid regular expression: /build\js\1.libs\boot\-libs\.[0-9a-f]{8}\.js/: Unterminated character class Use
OS: Windows
options: {
encoding: 'utf8',
fileNameFormat: '${name}.${hash}.${ext}',
renameFiles: true
},
main: {
src: [
'build/js/*.js',
'build/js/1.libs/*.js',
'build/css/*.css',
'build/imgs/*.jpg',
'build/imgs/*.png',
],
dest: [
'build/tree.json',
'build/css/*.css'
],
}
I have a use case similar to the test, in that I have two files of the same name in different directories that both need to be substituted in my file. In the current version of hashres it only takes the filename into account when substituting, so in the destination file both instances would be replaced with the same hash.
The easiest way I found to take path into account is to find the common path that all files in the src have and remove that when considering the substitution. The test file illustrates this. The files to be hashed are:
In the destination file though, the files are referenced relatively:
So, it would not suffice to simply substitute by file path + file name. This code introduces a
findCommonPath
method that will end up removing./temp/helper/subfolders-same-filename/
above in order to substitute as expected.This is a breaking change, however, as the following src list may break for substitutions, depending on how the destination file is referencing the source files:
Although, my guess is that in practice this functionality change wouldn't affect most implementations. An alternative is to perhaps add a flag in options to take path substitutions into account.