-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Goal: add option to overwrite existing modules #86
Conversation
Hi Icaro! Thanks for the PR. Can you show me the paths config you're using? |
Sure "paths": {
"preact/hooks": ["https://cdnjs.cloudflare.com/ajax/libs/preact/10.5.7/hooks.module.min.js"],
"preact": ["https://cdnjs.cloudflare.com/ajax/libs/preact/10.5.7/preact.module.min.js"]
} Anything else? |
This comment has been minimized.
This comment has been minimized.
@danielpza In the same vein, at least! For that, I'm planning on adding In addition, I was going to introduce |
As far as this goes, I think Icaro's approach makes sense. Our default behaviour is to not transform for any existing node modules, which in retrospect, I'm not entirely positive should be the default. But to avoid breaking side-effects, I think introducing a config option is a good idea, and I'm good with the option name. @danielpza What do you think? |
PR looks good, I think the only issue is I find the name a little confusing. Is it only intended for node modules? Looking at the code perhaps a more appropriate name would be |
@danielpza I wasn't sure on that either. Generally my approach on this sort of thing is to weigh the idiomatic popularity and go with what would be more widely understood unless one of the the specific nomenclatures is more precise in a way that is significant enough to justify using it as opposed to the more commonly understood one. This is something I've run into quite a bit with the compiler, and, notably, I have almost always ended up having to use the more precise term due to certain edge cases being included that couldn't be classified by the more narrow term. With that in mind, I just had a look through the compiler code to see exactly what an 'external library` is. Specifically, I wanted to see if an 'external library' could reasonably have some outside case that isn't well represented by the term 'node modules'. From what I've observed, I'm of the opinion that it does not in this case. (Feel free to correct me if I'm wrong!) Throughout the tests, I noted that all examples of 'external libraries' have a Then I also found this line: This shows that isExternalLibrary is determined by Considering all that, I think that |
@nonara alright, looks good to me then, thanks for the research. And you @icaro-capobianco for putting up the PR :D |
@icaro-capobianco Looks good, thanks for the work! I'll be adding a few other features here in the next week or so, so I will add some tests and roll this into that release. |
Looks like I don't have access to make changes on this. I'm going to go ahead and merge and apply styling in a separate PR. Thanks @icaro-capobianco for the PR! Good work. |
Quick update on this - in further digging into this, the proposed solution had some issues. Namely, the option implies that it allows overriding a To compensate, we could write logic to allow full override, but this would mean diverging from or replicating TypeScript's logic for module resolution, which is something that we do not want to do. However, in order to help you with your situation, I've introduced the In your case, you can use: // @transform-path https://cdnjs.cloudflare.com/ajax/libs/preact/10.5.7/preact.module.min.js
import { render, h } from 'preact'; Hope this helps, and thanks again for the contribution. |
My goal was to import preact like this:
But have my JS code like this:
But instead I was getting
So I looked at the code here and made a few changes that solved my problem, I am not sure if this breaks anything else, havent tested it, but it worked to solve my problem, so here it is.
Documentation on the feature/option:
Option: overwriteNodeModules
If you wish to replace an import for a package that exists on node_modules you can set the option "overwriteNodeModules".
This can be useful when you are planning to use a cdn like in this example:
Becomes: