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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Architecture] Switch package.json to module #7330

Closed
LeoDog896 opened this issue Dec 29, 2023 · 3 comments · Fixed by #7331
Closed

[Architecture] Switch package.json to module #7330

LeoDog896 opened this issue Dec 29, 2023 · 3 comments · Fixed by #7331
Labels
type:maintenance tests, chores, or project maintenance verified Tested or intentionally closed
Milestone

Comments

@LeoDog896
Copy link
Contributor

LeoDog896 commented Dec 29, 2023

Summary

After trying to implement #7329, Jest's ESM requires that every module file be moved to .mjs or switch the package to a module. So, moving to Vite/Jest may be split into three different PRs, with the first one switching this repo to a module (which should help with bundle sizes). Using Karma + ESM relies on a (small CJS workaround). This should also unblock #6591 and #6592

@unlikelyzero
Copy link
Collaborator

@LeoDog896 Would you be capable of providing a quick guide for folks on how you went through this process? We'd like to ensure that the consumers of Open MCT as a dependency (we know of at least 20) follow your established practices of migrating to ESM

@LeoDog896
Copy link
Contributor Author

@LeoDog896 Would you be capable of providing a quick guide for folks on how you went through this process? We'd like to ensure that the consumers of Open MCT as a dependency (we know of at least 20) follow your established practices of migrating to ESM

Sure! Generally, the steps I followed went like this:

  • Break everything first by establishing "type": "module" in package.json
  • Add .js to all js/ts imports (you can use codemods for this; I used a regex that matched some form of from './*'
  • Begin moving all files to not use require (vscode has code mods for this); to track them down, find all mentions of require( in your IDE
  • Do the same with all module. calls
  • Note: Dynamic imports are quite finicky, since ESM requires the use of await import instead of require; Optimally, dynamic imports should be avoided and moved to the top level.

@unlikelyzero
Copy link
Collaborator

@LeoDog896 this is great! We'll add it to our Github Discussions so that the consumers of Open MCT can make changes.

I'm wondering what your thoughts are on the errors we were seeing on akhenry/openmct-yamcs#411 when we tried to do import installYamcsPlugin from 'openmct-yamcs'; Did we miss a step by not defining a default export for ESM and CJS users of Open MCT?

@unlikelyzero unlikelyzero added this to the Target:4.0.0 milestone Jan 31, 2024
@unlikelyzero unlikelyzero added the verified Tested or intentionally closed label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:maintenance tests, chores, or project maintenance verified Tested or intentionally closed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants