-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor: use import()
to enable update of p-map
#11147
refactor: use import()
to enable update of p-map
#11147
Conversation
import()
to enable update of p-map
import()
to enable update of p-map
This is something I had no idea about until now. Wondering if there's any case studies or technical posts about successfully using this approach? Downstream I am also using CJS: will this result be compatible? Will defer to @viceice and @JamieMagee on if this is safe for us to merge. |
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.
Nope, this won't solve the issue. This PR will cause runtime issues, as cjs code can't import esm code!
The approach I took here is the second listed solution by The use of
It is also what I got suggested by
So, all in all, the use of |
typescript compiler will convert that to So your solution will maybe work for plain JavaScript but not typescript. |
Didn't know that TypeScript breaks this behavior, here's a tracking bug in TypeScript: microsoft/TypeScript#43329 |
Have the dynamic import() happen in an uncompiled dependency instead, that way TypeScript can't convert the import() to a require() and thus it will work with ESM modules in TS as well. Relevant TypeScript issue: microsoft/TypeScript#43329
Instead of adding those dynamic imports, i would suggest to make renovate fully esm compatible and provide cjs and esm in one package for a while. So @rarkins can make the hosted app esm compatible smoothly. Finally we drop cjs build and then update blocked deps as normal. |
be sure to be careful with this approach when esm-only dependencies are involved. if there are dependencies that are esm-only, consumers won't be able to use those dependencies in common-js, even if renovate exports both esm and cjs of itself. the only way that those dependencies could be made compatible, if consumed by renovate as esm-only, would be to bundle the transpiled result into the published renovate exports. |
@travi we don't upgrade to esm deps until renovate itself only publish esm. So no issue with esm imports. Also renovate isn't ment to be used as library. We always told people that we dont have a stable api. So this nom package should only be used as a cli tool. Please follow the issue linked for further discussion about renovate esm transition. |
@travi This isn’t true, as I outlined in #11147 (comment) CJS can’t use |
I have seen a lot of the docs, and I don't remember us saying this or something similar... I did a search for the string We do have a section in our FAQ, which Renovate versions are officially supported that says:
|
We didn't document the internal API because it's not meant to be used by other users. 😉 So not documented means unstable for us. I've discussed this alot with rarkins. Otherwise we would need a major update on nearly every refactoring. So users should only depend on the cli or the official hosted app. |
good call. i was reading the comment about exporting both cjs and esm for a while as suggesting otherwise, so it seemed worth suggesting caution. sounds like you have your plan sorted out, so feel free to not pay much attention to the suggestion :)
yep, i'm aware from an external consumer perspective, but have also seen that it is consumed internally, so i figured mentioning was worthwhile to save internal pain too
you're right that it is possible. however, at least in my experience, when exporting both cjs and esm, the cjs export tends to be the result of transpilation. as mentioned above for transpiling from typescript, it can be difficult to target it seems my comments caused a bit of disruption here, which wasnt my intent. since it didnt move things forward in a positive direction, please feel free to ignore. i'm working through similar complexity on a number of my projects, so i'm interested in your progress in this area and will keep an eye on the other issue. |
Changes:
Makes use of
await import()
unblock the update of ESM-only modules like eg.p-map
and thus enabling it to be removed from #2958 (comment) and no longer be blocked by #9890.Context:
As more and more modules are becoming ESM-only, and since Jest is still blocking #9890 from being solved, the challenge of not being able to use ESM-only modules is getting increasingly larger and often the possibility of using
await import()
is easy to miss.Documentation (please check one with an [x])
How I've tested my work (please tick one)
I have verified these changes via: