-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 🙂 |
DOCS.md
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't all aliases converted into regex anyway?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup I think being consistent here would be less surprising and the note in the DOCS wouldn't be necessary. Win-win!
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.
Done.
DOCS.md
Outdated
"^@namespace/foo-(.+)": ([, name]) => path.join('packages', name) | ||
} | ||
}] | ||
] | ||
} | ||
``` | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will remove them.
This implements a feature requested in #242.