Allow passing a function as a RegExp substitute#245
Conversation
|
@tleunen This still requires a docs update, will do that tomorrow. For now please give me a heads up if more tests are necessary. |
Codecov Report
|
|
looks good to me |
24c5d1f to
728dd9e
Compare
|
We can merge if you're ok with the wording in the docs 🙂 |
|
|
||
| Because the function is only called when there is a match, the argument can never be `null`. | ||
|
|
||
| *Important: a function can only be used with regular expressions.* |
There was a problem hiding this comment.
Aren't all aliases converted into regex anyway?
There was a problem hiding this comment.
They are, but the value for the "basic" alias is made into a substitution string like so:
getAliasPair(`^${key}(/.*|)$`, `${alias[key]}\\1`);I could add some more logic there to always detect functions.
There was a problem hiding this comment.
Yup I think being consistent here would be less surprising and the note in the DOCS wouldn't be necessary. Win-win!
|
|
||
| Using the config from this example `'@namespace/foo-bar'` will become `'packages/bar'` or `'packages\\bar'` depending on the OS. | ||
| Using the config from this example: | ||
| * `'foo/baz'` will become `'bar/baz'` or `'bar\\baz'` |
There was a problem hiding this comment.
Not sure if we should use path.join as an example.
On windows or unix, all paths in node for the import/require files should in theory be in a posix format afaik... right?
There was a problem hiding this comment.
AFAIK Node allows me to use \ on Windows. I'll adjust the examples though, to make them more simple.
There was a problem hiding this comment.
On a second thought, manually joining path parts is a bad practice... I'd rather stick to path.join than use +.
There was a problem hiding this comment.
Yeah, I agree that in general people should always use path.join to create a path. But in this case, inside a node/web project, I don't think it's a good idea to mix posix and windows paths.
What if a project is built on windows and provide paths with \? Would it run on a mac/linux pc? Will webpack understand the paths?
I feel it's risky to have this in our doc since most people should never use windows paths for their imports/require.
Maybe replacing the example to remove path.join would be best.
There was a problem hiding this comment.
Ok, will remove them.
This implements a feature requested in #242.