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(unstable): repurpose --unstable-detect-cjs to attempt loading more modules as cjs #27094

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 26, 2024

This resurrects the --unstable-detect-cjs flag (which became stable), and repurposes it to attempt loading .js/.jsx/.ts/.tsx files as CJS in the following additional scenarios:

  1. There is no package.json
  2. There is a package.json without a "type" field

Also cleans up the implementation of this in the LSP a lot by hanging resolution_mode() off Document (didn't think about doing that until now).

Related issues:

@dsherret dsherret marked this pull request as ready for review November 26, 2024 19:52
@unimonkiez
Copy link

unimonkiez commented Nov 26, 2024

I actually much prefer using a package.json with type commonjs than this flag but that doesn't seem to work with relative import

@@ -4373,7 +4374,7 @@ impl CommandExt for Command {
).arg(
Arg::new("unstable-detect-cjs")
.long("unstable-detect-cjs")
.help("Reads the package.json type field in a project to treat .js files as .cjs")
.help("Treats ambiguous .js, .jsx, .ts, .tsx files as CommonJS modules in more cases")
.value_parser(FalseyValueParser::new())
.action(ArgAction::SetTrue)
.hide(true)
Copy link
Member

Choose a reason for hiding this comment

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

Unhide?

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 thought so too, but all of the unstable flags seem hidden

Copy link
Member

Choose a reason for hiding this comment

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

Oh, just make sure it's shown when you do deno run --help=unstable

Copy link
Collaborator

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants