This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
Take file path into account when substituting #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.