Skip to content
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

feat(processPattern): add support for {RegExp) matches (pattern.test) #235

Merged
merged 1 commit into from
Mar 2, 2018

Conversation

jkrems
Copy link
Contributor

@jkrems jkrems commented Mar 1, 2018

We want to match some of our existing asset logic which generates image file names from the source paths. Having a function that generates those paths seemed like the simplest solution.

This mirrors the way the file-loader works, allowing to reuse logic. https://github.com/webpack-contrib/file-loader#regexp

@jsf-clabot
Copy link

jsf-clabot commented Mar 1, 2018

CLA assistant check
All committers have signed the CLA.

@jkrems
Copy link
Contributor Author

jkrems commented Mar 1, 2018

Actually, trying to make sure that templates are supported in the returned value.

@jkrems jkrems changed the title Add support for toType "function" Add support for regex matches in to templates Mar 1, 2018
@michael-ciniawsky michael-ciniawsky changed the title Add support for regex matches in to templates feat(processPattern): add support for {RegExp) matches (patterns.toRegExp) Mar 1, 2018
@michael-ciniawsky michael-ciniawsky added this to the 4.5.0 milestone Mar 1, 2018
@michael-ciniawsky michael-ciniawsky changed the title feat(processPattern): add support for {RegExp) matches (patterns.toRegExp) feat(processPattern): add support for {RegExp) matches (pattern.toRegExp) Mar 1, 2018
Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor renaming pattern.toRegExp => pattern.test instead

README.md Outdated
@@ -138,6 +138,9 @@ Or, in case of just a `from` with the default destination, you can also use a `{
from: 'src/'
to: 'dest/[name].[hash].[ext]',
toType: 'template'
// Optional: provide a regExp to extract additional placeholders
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a new 'section' for this option, or does it only work with toType: 'template' ?

Copy link
Member

@michael-ciniawsky michael-ciniawsky Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs to be added to options table please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only work with the template toType. Will update the table.

@michael-ciniawsky michael-ciniawsky changed the title feat(processPattern): add support for {RegExp) matches (pattern.toRegExp) feat(processPattern): add support for {RegExp) matches (pattern.test) Mar 1, 2018
@jkrems
Copy link
Contributor Author

jkrems commented Mar 1, 2018

Would it make sense to use pattern.regExp instead of pattern.test? That's consistent with how file-loader exposes this feature. Happy to switch to either. :)

@jkrems
Copy link
Contributor Author

jkrems commented Mar 1, 2018

  • Added to options table
  • Renamed to options.test
  • Added dedicated section for options.test to the README containing the same docs that also appear in the file-loader README for options.regExp

@alexander-akait
Copy link
Member

@jkrems rebase 👍

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jkrems
Copy link
Contributor Author

jkrems commented Mar 1, 2018

Rebase'd.

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor important nitpicks, please rebase :)

README.md Outdated
@@ -143,6 +144,27 @@ Or, in case of just a `from` with the default destination, you can also use a `{
]
```

### `test`

Defines a regExp to match some parts of the file path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regExp => {RegExp}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

README.md Outdated

Defines a regExp to match some parts of the file path.
These capture groups can be reused in the name property using `[N]` placeholder.
Note that `[0]` will be replaced by the entire tested string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


> ℹ️ Note

string => {String}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with "entire relative path of the file" while I was touching it since that seemed easier to understand than what the "tested string" was.

README.md Outdated
Defines a regExp to match some parts of the file path.
These capture groups can be reused in the name property using `[N]` placeholder.
Note that `[0]` will be replaced by the entire tested string,
whereas `[1]` will contain the first capturing parenthesis of your regex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regex => {RegExp}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jkrems
Copy link
Contributor Author

jkrems commented Mar 2, 2018

Alright, the arguments to the interpolate call changed (relative -> absolute). Updated the test and docs to match that.

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkrems Thx

@michael-ciniawsky michael-ciniawsky merged commit 1861730 into webpack-contrib:master Mar 2, 2018
@michael-ciniawsky
Copy link
Member

Released in v4.5.0 🎉

@jkrems
Copy link
Contributor Author

jkrems commented Mar 2, 2018

Niiice! That was fast! Thanks a lot for the quick review & release. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants