-
Notifications
You must be signed in to change notification settings - Fork 0
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
Migrate to ESM (and get dynamic await) #32
Comments
It would be nice if changing to this didn't involve changing all of our import paths. |
Solving this will enable MatrixAI/js-id#2 |
Pkg doesn't currently support ES modules. But it should soon: vercel/pkg#782. Currently it may require us to use The It may also help with doing some optimisation work like tree-shaking. But of course it doesn't make sense to put it all into one single file like we were doing in webpack. Library modules should be able to imported separately. |
Note that dynamic imports already work. Right now they are just translated to |
With #37 merged, we are one step closer. Before working with ES modules and dynamic imports that use ES modules, it must be tested that it works in vercel pkg. Keep track of this issue: vercel/pkg#1603 Also important that it works with ts-node too. |
Experimental support for ESM in ts-node is now available: TypeStrong/ts-node#1007 (comment) |
Moving to ESM is a big task, there are other tools we need support for: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
This would be necessary to support usage of WASM libraries: MatrixAI/Polykey#422 (comment) We also have to decide whether to use the |
PKE is going to be on ESM. If we move the rest of PK ecosystem to ESM, we have to deal with:
|
Note that:
What is doable is vercel/pkg#1291 (comment) - which uses a bundler to convert ESM to CJS, then uses Furthermore any bundler to convert ESM to CJS does not support top-level await. Which means you often need refactor any usages of top level await like in this library Offroaders123/NBTify#30 (comment). This is quite annoying, other bundlers like webpack focus on more a web-like environment and so has features that isn't really needed. Node is coming out with its own single file executables too, but currently only supports CJS. Deno is probably the only one that cleanly creates a single file executable with full ESM support but involves bunch of migration that can be difficult to do with all the existing assumptions. |
Should keep track of this project too https://github.com/nodejs/single-executable and https://dev.to/chad_r_stewart/compile-a-single-executable-from-your-node-app-with-nodejs-20-and-esbuild-210j |
If top-level await is a necessary construct, then we will not be able to use Subsequently we can then use |
This issue has become more important since PKE has gone ES native and right now importing our CJS modules is kind of broken. https://gitlab.com/MatrixAI/Engineering/Polykey/Polykey-Enterprise/-/merge_requests/2#note_1472206322 |
ESM support will be in js-async-cancellable, js-resources already and will be merged to staging and master soon. I was waiting on them first before pushing All of this means all our packages will be ESM native by default. It's still possible to use regular CJS packages but you have to pattern match off from a default import. The true test is going to be After the main changes are good, I believe that can just be replicated. @amydevs can you start helping out on the other packages following |
Note that top-level await does work in esbuild now. It was a later comment. Especially since Should also investigate https://github.com/privatenumber/pkgroll for bundling as it uses esbuild too. This will be important for the pkg optimisation for Polykey-CLI. |
|
Small blocker on MatrixAI/js-workers#12. The threadsjs types aren't properly exported and we are making use of 3 types.
Currently none of the types work because they aren't properly exported by the upstream package. Additionally a recent commit made |
Can confirm that decorator usage is fine. |
The
This is blocking js-db migration since it has tests that rely on it. We can try swapping out threadsjs for this https://github.com/piscinajs/piscina. Maybe that can enable it, and we can then proceed with It's possible we may have to change the way we create workers a bit. |
Due to jestjs/jest#2549, vm isolation can introduce problems when testing and expecting errors to throw or certain types to be instances of something. Basically the globals inside nodejs isn't the same as globals in jest. Thus This doesn't just affect tests, but it could also affect internal code that has to do There's no good solutions, the workaround on tests is to do The good thing is that most of the native globals that come out of nodejs should have checking functions like And exceptions wise... we usually wrap it in our own error tree. |
I've been using toHaveProperty in js-ws so far |
@amydevs let's make the top level issue for ESM migration into Polykey Core Library. We could also create a Project for it - as it will end up grouping multiple ESM migration related issues. |
Convert this to a project, and then group all relevant ESM issues under this for all repos. Make sure to link the background context of why you're patching the jest fastcheck problem, as well as then notes on how we are going to deal with the mocking issue - probably by not mocking at all where we can. |
@tegefaulkes mentions that in MatrixAI/Polykey-CLI#257, there is issues with using However in relation to ESM migration, relying on things like Either way, it means for the benefit of testing, and fast-checking, we should avoid using There are workarounds mentioned like using So...
|
@amydevs get your js-ws issue here too. And identify what is blocking here. |
Someone needs to take this over now that Amy has left the company. |
Should this just be backlogged for the time being as this is not really being worked upon by anyone, and isn't on anyone's recent priority list either. |
I'm moving this to backlog for now. |
PKE requires this to be worked on. This is general issue across all repos and we should move to ESM for js-rpc to simplify PKE. I created an issue for this there ENG-504 |
What is your research hypothesis/question?
There is a conjunction of 4 features:
That enables some nifty capabilities:
import x from 'a/b/c';
- this can allow us to flexibly export things without having to go down thedist/...
route all the timeThese features are all coming online in various forms, however some initial experiments show that they involve alot of changes.
Review existing ideas, literature and prior work
Research conclusion
See the notes in MatrixAI/js-logger#29
The text was updated successfully, but these errors were encountered: