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

package output as esm + cjs #1314

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

package output as esm + cjs #1314

wants to merge 4 commits into from

Conversation

ivanhofer
Copy link

I need this package in an esm context so I took the time to convert it.
There weren't that many things to change, so the process was straigt forward.

  • The build script now outputs cjs and esm code.
    In order to make the code run in an esm context without setting "type": "module" inside package.json all generated esm files need to end with the .mjs file extension. Therefor the fix-esm-output.js script is needed.
  • All imports were altered using the "node16" module resolution.
  • All require statements are rewritten using import statements.
    This did remove the "lazy-import" behavior as dynamic import statements must use async-await. But the only place where this affects regular runtime code is where esprima get's used. But since it is a regular dependency of recast nothing should fail.
  • Tests were left unchanged and still run sucessfully for the cjs output.

I hope this could be merged into the main project so I don't have to maintain a copy of it.
Let me know if there are still some things missing.

Copy link
Author

@ivanhofer ivanhofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some TypeScript related issues popped up when converting from require (which has no type support) to import. The issues are already present in the current master branch. I marked them with // @ts-expect-error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant