-
Notifications
You must be signed in to change notification settings - Fork 58
Add RegExp support and strict order of entries (+unit-tests) #53
Conversation
Hurr, pardon me for the weird commit comments in regards to the README.md 🐵 (ffs, almost typed .me again). |
Ping @shellscape maybe that PR is interesting for you guys? Otherwise I'll release this as a fork (I'd hate doing that, out of principle). |
@thiscantbeserious please bear with us. We're a team of 3 (sometimes 4) right now juggling the ecosystem 😄 We just got about 2/3 of the way through the rollup core backlog and the plugins are next on my list. I promise you we'll get to this soon. |
I'm fine with that 💃 ... I actually forgot to mention that this also supports subpattern matching & replacing - so this can be very powerfull in total, e.g. when migrating a larger code-base with previous loader-syntax support - for example to remove those to get rollup to correctly load the files:
I'm not to good with examples so maybe when you merge it (if you do) maybe you'll come up with better examples or a better Readme to outline the changes 🔢 . Cheers! |
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.
Good work, I think this is a really nice improvement, though of course it is a breaking change. Left some comments and suggestions.
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.
Cleaned the mess up and pushed it to my repo.
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.
Great work, this looks good from my side!
@@ -27,36 +27,31 @@ For Webpack users: This is a plugin to mimic the `resolve.alias` functionality i | |||
``` | |||
$ npm install rollup-plugin-alias | |||
``` | |||
|
|||
# |
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.
Is this intended?
}; | ||
``` | ||
If not given local aliases will be resolved with a `.js` extension. | ||
You can use either simple Strings or Regular Expressions to search in a more distinct and complex manner (e.g. to do partial replacements via subpattern-matching, see aboves example). |
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.
Looks good 👍
Too bad this was not implemented with backwards compatibility. Objects have a strict ordering as far as I know https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/ It seems that only a tiny fraction of projects needs the regex feature while other projects now get a more complex configuration. If you consider accepting a PR that restores backwards compatibility I would be willing to try that. This seems not to be true anymore: |
@thgh that sounds like a regression if back-compat has been lost. Would you be willing to open a new issue (or straight to PR if you'd like). I'm absolutely certain we'd entertain restoring back-compat. |
Actually you don't need to use Regular Expressions they are still I can understand that you might feel a bit confused by the differences in Previously in V1 it was abusing object-properties (key = find, value = While an object key can actually hold any string it can only be accessed by Let me give you an example (not syntax correct I know - just for the sake of keeping things together):
Logically speaking (what the user excepts) when using the above config all Right? That's not what happens in V1. Objects sort properties alphabetically by their key (you can verify that by You'll get this: So what would happen is that the rule "awesome" would be executed first, Now that is just an super simple example - imagine like multiple rules
I think we can agree on that its a bad reference and never actually worked that way anyway (as such I should be simply removed - I mean that reference)? Imagine them completely changing the way resolve.alias in the next version - just for the sake of it should we adjust? I don't think so. A plugin should fullfill a specific purpose - and use the configuration it needs and not what someone else decides it should have just for the sake of it @shellscape I would agree on simplifying things but full backwards compability is not 100% fesible as I see it - not in regards to using object keys for the definition see my above explanation. @lukastaegert actually agreed on the breaking changes by definition - I mentioned that in the PR - so it didn't accidently slipped in as far as I could get. |
Added support for Regular Expressions and switched from an object to an array for the entries to keep a strict order in which rules are queried (unlike previously).
This will change the options a bit - with the added bonus of better readability (basically you'll have to specify the 'find' property instead of abusing the object-key for the search-string.
Edit: Maybe a Set would give better performance, will have to revisit later on - for now this is sufficient to get started (at least for us)
Edit 2: Also keep in mind that this is currently not backwards compatible with the old configuration, that would need some extra work, if desired.
Edit 3: For examples see README.md in my Repo.