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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Regex in module value, function in rename value when selecting module #54

Closed
tjcouch-sil opened this issue May 8, 2023 · 7 comments 路 Fixed by #55
Closed

Support Regex in module value, function in rename value when selecting module #54

tjcouch-sil opened this issue May 8, 2023 · 7 comments 路 Fixed by #55
Labels
enhancement New feature or request

Comments

@tjcouch-sil
Copy link
Contributor

tjcouch-sil commented May 8, 2023

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch rollup-plugin-import-manager@0.5.3 for the project I'm working on source code for the plugin configuration here.

I needed to make exact matches to module names (instead of the current matching where it looks for the config-provided module name anywhere in the module name string) so that I could remove a specific module but not modules whose names included that module name, so I added Regex support in the module name.

I also needed to modify the relative path to modules programmatically when renaming them, not only replace module names one-for-one, so I added the ability to provide a function that receives the full raw module source path and returns a new full raw module source path.

Here is the diff that solved my problem:

diff --git a/node_modules/rollup-plugin-import-manager/README.md b/node_modules/rollup-plugin-import-manager/README.md
index f1bbebd..b13192a 100644
--- a/node_modules/rollup-plugin-import-manager/README.md
+++ b/node_modules/rollup-plugin-import-manager/README.md
@@ -162,7 +162,7 @@ This is where the plugin comes to life. Here is the place where units are gettin
 ---
 
 #### `module` <samp>[option for units]</samp>
-Type: `String`  
+Type: `String` | `RexExp`  
 Default: `null`  
 
 Selects a unit by its module name. Each import has a name object. This is constructed from the module.
@@ -353,10 +353,10 @@ An option to target an alias of a [selected](#select-option-for-actions) `defaul
 
 
 ##### `rename` <samp>[option for actions]</samp>
-Type: `String`  
+Type: `String` | `(moduleSourceRaw: string) => string`  
 Default: `null`  
 
-This option is used to rename a [selected](#select-option-for-actions) specific part (`defaultMember`, `member`, `module`). The value is the new name of the selected part. See this [example](#changing-the-module).
+This option is used to rename a [selected](#select-option-for-actions) specific part (`defaultMember`, `member`, `module`). The value is a string of the new name of the selected part. See this [example](#changing-the-module). If the selected part is `module`, the value could alternatively be a function accepting the whole raw module source (ex: `"./module-name"` including quotes) and returning the whole new name (ex: `"./newmodule-name"` including quotes).
 
 
 ##### `modType` <samp>[option for actions]</samp>

This change corresponds to UmamiAppearance/ImportManager#47

Please let me know if you would like me to submit a pull request with these changes.

This issue body was partially generated by patch-package.

@UmamiAppearance
Copy link
Owner

UmamiAppearance commented May 9, 2023

Hi.
This is a great idea. Regex support would enhance module selection by a lot. Please submit a pull request. I have already created a new branch:
regex-module-selection_plugin

@tjcouch-sil
Copy link
Contributor Author

Created pull request #55

@UmamiAppearance
Copy link
Owner

I think we are good to go. I additionally introduced a method to match the module via the raw source.
Your example has found its place here. It is narrowed down to the particularities of using a function.
RegExp has its own example here.

Any final objections?

@tjcouch-sil
Copy link
Contributor Author

tjcouch-sil commented May 11, 2023

I think that's great!! Thanks for the great support and help. The ImportManager dependency needs to be updated whenever you publish that first, though, right?

@UmamiAppearance
Copy link
Owner

Thanks for your contribution. This is a real enhancement. 馃憤

The ImportManager dependency needs to be updated whenever you publish that first, though, right?

Yes.

@UmamiAppearance
Copy link
Owner

Resolved in #56

@tjcouch-sil
Copy link
Contributor Author

Thank you very much for all your hard work on this!! So thankful for the quick turnaround and the great improvements. Have a great week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants