Skip to content

feat(es/transforms): Add module.outFileExtension#9784

Merged
kdy1 merged 9 commits into
swc-project:mainfrom
hanseltime:feat-out-file-extension-resolution
Dec 9, 2024
Merged

feat(es/transforms): Add module.outFileExtension#9784
kdy1 merged 9 commits into
swc-project:mainfrom
hanseltime:feat-out-file-extension-resolution

Conversation

@hanseltime

@hanseltime hanseltime commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

Description:

Summary of Changes:

  1. Adds an outFileExtension property to every module configuration option struct
  2. passes this configuration through to the resolver function and changes all hard-coded "js" checks to use the new parameter
  3. As a matter of backwards compatibility, structures default to "js" if nothing is provided
  4. @swc/core snapshot tests for each module using resolveFully and outFileExtension (Please check the rendered output of the snapshots to make sure you don't have any issues with it).
  5. QOL - updates @swc/core jest config to use explicit module names (this was because the mapping util in jest was exploding when it would try to load in the .node files that were over 512MB)
  6. QOL - updates the test script to pass through any existing NODE_OPTIONS - this allows debugging tools to add their own inspect configurations while preserving our esm module flag

Note

This is a rudimentary fix to: #3067 (comment). I had to implement it locally since I could not find a workaround in my timeline.

I do know that @kdy1 said they would work on it a few days ago, so I am opening this to either provide some visibility to a solution that works for me if they haven't started or to let them switch to PR critique if that feels more valuable for their time on this issue. Let me know if this should be closed due to a better implementation already being in the works.

Related issue:

@hanseltime hanseltime requested review from a team as code owners December 6, 2024 02:38
@changeset-bot

changeset-bot Bot commented Dec 6, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4eb8ad0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

CLAassistant commented Dec 6, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hanseltime hanseltime force-pushed the feat-out-file-extension-resolution branch from 3ef730f to 9a35817 Compare December 6, 2024 02:44
@codspeed-hq

codspeed-hq Bot commented Dec 6, 2024

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #9784 will degrade performances by 4.89%

Comparing hanseltime:feat-out-file-extension-resolution (4eb8ad0) with main (5a44c6b)

Summary

❌ 1 regressions
✅ 193 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main hanseltime:feat-out-file-extension-resolution Change
es/visitor/base-perf/boxing_boxed_clone 2.3 µs 2.4 µs -4.89%

@socket-security

socket-security Bot commented Dec 6, 2024

Copy link
Copy Markdown

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@hanseltime

Copy link
Copy Markdown
Contributor Author

Noting here a few things that I'm unsure on:

  1. The Miri tests are failing, but they seem to fail on things like test_fixtures macro, and "unimplemented functions". If someone could set me straight on it, I can sit down and debug it if asked.
  2. If I should be submitting a documentation change to the website in tandem with this

Thanks in advance!

@kdy1 kdy1 added this to the Planned milestone Dec 9, 2024
Comment thread crates/swc/src/config/mod.rs Outdated
mut base_url: PathBuf,
paths: CompiledPaths,
resolve_fully: bool,
file_extension: &String,

@kdy1 kdy1 Dec 9, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think clippy will be angry at this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
file_extension: &String,
file_extension: &str,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks. I have updated it!

@@ -21,6 +22,9 @@ pub struct Config {

#[serde(default)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you should remove this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kdy1 - I didn't add this attribute. Did you mean the inner Config attribute below it or were you hoping I would clean this up? Also, I'm assuming you would want this changed across all Module Shapes or just this one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean the whole resolve_fully: bool. It's now duplicated as you added a field below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. Thanks for clarifying. Okay, I've updated that for the ESModuleConfig and the SystemJS Config.

Comment on lines 54 to 56
pub fn default_js_ext() -> String {
"js".to_string()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn default_js_ext() -> String {
"js".to_string()
}
impl Config {
pub fn default_js_ext() -> String {
"js".to_string()
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've switched the function to an impl on Config and all calls to the function to use the Config::default_js_ext() as well.

@kdy1 kdy1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@hanseltime hanseltime force-pushed the feat-out-file-extension-resolution branch from 252afff to 258b834 Compare December 9, 2024 04:05
@hanseltime hanseltime force-pushed the feat-out-file-extension-resolution branch from 258b834 to efe8f77 Compare December 9, 2024 04:09
@socket-security

Copy link
Copy Markdown

@kdy1 kdy1 changed the title Feat out file extension resolution feat(es/transforms): Add module.outFileExtension Dec 9, 2024
@kdy1 kdy1 merged commit e04c7b3 into swc-project:main Dec 9, 2024
@kdy1 kdy1 removed this from the Planned milestone Dec 9, 2024
@kdy1 kdy1 added this to the v1.10.1 milestone Dec 9, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Output mjs file extension

3 participants