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

fix(node): change resolution mode based on import construct #545

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 25, 2024

We now say if a specific import or export resolution should definitely use ESM or CJS along with supporting "resolution-mode" in TypeScript (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#stable-support-resolution-mode-in-import-types). This information is stored in the referrer range.

It's important to know this for importing npm packages (ex. dynamic imports in cjs should load using ESM and not CJS resolution).

For denoland/deno#27059

CLI PR: denoland/deno#27071

@@ -14,7 +14,7 @@ use deno_graph::source::LoadFuture;
use deno_graph::source::LoadOptions;
use deno_graph::source::Loader;
use deno_graph::source::NullFileSystem;
use deno_graph::source::ResolutionMode;
use deno_graph::source::ResolutionKind;
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Notice in particular the changes in this file.

src/lib.rs Outdated
Copy link
Member Author

Choose a reason for hiding this comment

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

I outlined a bug with this PR in #80 (comment)

We'll have to come back and fix that later (I think it's too much to fix in this PR or deno_graph upgrade)

js/test.ts Outdated
@@ -191,6 +191,7 @@ Deno.test({
{
"specifier": "./b.js",
"code": {
"mode": "import",
Copy link
Member Author

Choose a reason for hiding this comment

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

Is "mode" ok, or should it be "resolutionMode"?

Copy link
Member

Choose a reason for hiding this comment

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

IMO resolutionMode is clearer

js/test.ts Outdated
@@ -191,6 +191,7 @@ Deno.test({
{
"specifier": "./b.js",
"code": {
"mode": "import",
Copy link
Member

Choose a reason for hiding this comment

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

IMO resolutionMode is clearer

src/ast.rs Show resolved Hide resolved
if !c.is_alphabetic() {
return Err(monch::ParseError::Backtrace);
}
// good enough for now
Copy link
Member

Choose a reason for hiding this comment

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

;)

src/graph.rs Show resolved Hide resolved
@dsherret dsherret merged commit 0c97977 into denoland:main Nov 26, 2024
16 checks passed
@dsherret dsherret deleted the fix_node_resolution_based_on_import_construct branch November 26, 2024 02:52
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.

2 participants