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

feat(compat): CJS/ESM interoperability #13553

Merged
merged 38 commits into from
Feb 27, 2022

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Jan 31, 2022

This commit adds CJS/ESM interoperability when running in --compat mode.

Before executing files, they are analyzed and all CommonJS modules are
transformed on the fly to a ES modules. This is done by utilizing analyze_cjs()
functionality from deno_ast. After discovering exports and reexports, an ES
module is rendered and saved in memory for later use.

There's a caveat that all files ending with ".js" extension are considered as
CommonJS modules (unless there's a related "package.json" with "type": "module").

Closes #12648
Closes #13200

@bartlomieju bartlomieju changed the title [WIP] compat: CJS/ESM interoperability feat(compat): CJS/ESM interoperability Feb 26, 2022
@bartlomieju bartlomieju requested a review from ry February 26, 2022 14:08
cli/proc_state.rs Outdated Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM!

@bartlomieju bartlomieju merged commit a65ce33 into denoland:main Feb 27, 2022
@bartlomieju bartlomieju deleted the cjs_esm_integration branch February 27, 2022 13:39
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.

compat: failed to import "react" from ESM module compat: imported scripts are always handled as ESM
3 participants