-
Notifications
You must be signed in to change notification settings - Fork 3
Provide path to replace(); undefined value -> empty replacement string #1
Conversation
Two related changes, plus eslint cleaning, dependencies, and tests. - If no `value` key is given, the replacement string is '' rather than the 'undefined' provided by JSON.stringify(). - The `file.path` parameter is given to the replacement function. Note: this updates the dependency on eslint from 3.x to 4.x. This is because eslint-config-brunch@1.0.0 now requires eslint@^4.
- `lib/simpletest` now requires `./lib/inner` - Replace `__filename` with the filename using tkesgar/replacer-brunch#1
I tried replacing `__filename` in the wrapper at first, but that didn't work (and I'm not sure why). Now that tkesgar/replacer-brunch#1 is taking care of that, I put the wrapper back in, and it seems to be doing OK.
@@ -6,12 +6,18 @@ class BrunchReplacer { | |||
|
|||
// Set defaults for config. | |||
if (!this.config.dict) this.config.dict = []; | |||
if (!this.config.replace) this.config.replace = (str, key, value) => str.replace(key, value); | |||
if (!this.config.replace) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint flagged the missing {}
, so I added them.
@@ -41,12 +41,18 @@ describe('Plugin', () => { | |||
dict: [{key: '__KEY__', value: '__VALUE__'}], | |||
}}}); | |||
|
|||
it('should replace key with value', () => { | |||
it('should not replace when key is absent', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test was correct but the description was copied and pasted from elsewhere. I updated the description to match the test.
Hello there, thanks for the pull request! I'm currently away from computer over the weekend, but from here the PR looks okay. Using empty string as default for value seems fair game, since I can't think any use cases where people want to replace strings with undefined (they can use For the file path, I am okay with the feature; it is useful and doesn't seem to break anything. However, there are a few things to consider:
I'll have a further look ASAP, but if you can investigate these things before me it would be great 🙂 |
Thanks for the quick response! Edited Tested on Win8.1 using Node 8.11.4 x86, npm 6.4.1, npx 10.2.0 (
|
I think adding I'll merge and publish this ASAP, thank you for your help! |
@tkesgar Thanks! Let me know if you ever run across any slash-related problems, and I'll do likewise. |
Thanks for this plugin! I am relatively new to brunch. My use case is to replace
__filename
with the name of the file being processed, and this plugin and PR are the most direct way I could find to do it. My example is in cxw42/brunch-test.This PR introduces two related changes, plus documentation, tests, and cleaning to pass
eslint
checks.file.path
parameter is given to the replacement function.value
key is given, the replacement string is''
rather than theundefined
provided byJSON.stringify()
. That way, if your custom replacement function is going to use thepath
argument anyway, the behaviour is well-defined even if you don't specify a replacement string.Note: this PR also updates the dependency on eslint from 3.x to 4.x. This is because eslint-config-brunch@1.0.0 now requires eslint@^4. I see that you did not check in the package-lock.json, so I also did not do so.
Thanks for considering this PR!