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

Native ESM support #3456

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Native ESM support #3456

merged 2 commits into from
Jul 17, 2024

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Nov 15, 2023

What?

Native support for ESM in k6

Why?

Having native ESM support both allows us to use more goja features and drops our internal babel.

This also closes a number of js-compat issues as we no longer are blocked by babel not supporting something. As well as freeing up the ability for Sobek to add support for even newer things.

The breaking change label is there as this both breaks old require behavior as part of #3534, but also now makes combining CommonJS and ESM syntax in one file a syntax error. The latter has been found to be a lot more common than the first, unfortunately. But there isn't any sane way to support that, and it also makes no sense to be mixed.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

Closes #3265

@mstoykov mstoykov mentioned this pull request Nov 15, 2023
4 tasks
@mstoykov mstoykov changed the title Esm Native ESM support Nov 15, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2023

Codecov Report

Attention: Patch coverage is 77.59104% with 80 lines in your changes missing coverage. Please review.

Project coverage is 71.93%. Comparing base (bf218a9) to head (b895801).

Current head b895801 differs from pull request most recent head 62d9682

Please upload reports for the commit 62d9682 to get more accurate results.

Files Patch % Lines
js/modules/require_impl.go 60.49% 24 Missing and 8 partials ⚠️
js/modules/resolution.go 78.26% 8 Missing and 7 partials ⚠️
js/bundle.go 85.29% 8 Missing and 2 partials ⚠️
js/compiler/compiler.go 75.00% 7 Missing and 1 partial ⚠️
js/modules/cjsmodule.go 86.66% 5 Missing and 1 partial ⚠️
js/modules/gomodule_basic.go 77.27% 3 Missing and 2 partials ⚠️
js/modules/gomodule.go 88.57% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3456      +/-   ##
==========================================
+ Coverage   71.92%   71.93%   +0.01%     
==========================================
  Files         291      290       -1     
  Lines       21277    21336      +59     
==========================================
+ Hits        15303    15349      +46     
- Misses       4915     4921       +6     
- Partials     1059     1066       +7     
Flag Coverage Δ
ubuntu 71.93% <77.59%> (+0.08%) ⬆️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mstoykov mstoykov added this to the v0.49.0 milestone Nov 16, 2023
@mstoykov mstoykov marked this pull request as ready for review December 14, 2023 13:57
@mstoykov mstoykov modified the milestones: v0.49.0, v0.50.0 Jan 11, 2024
@mstoykov mstoykov requested a review from a team as a code owner January 12, 2024 11:57
@mstoykov mstoykov modified the milestones: v0.50.0, v0.51.0 Feb 28, 2024
@codebien codebien removed the request for review from a team March 19, 2024 10:41
@mstoykov mstoykov modified the milestones: v0.51.0, v0.52.0 Apr 25, 2024
@mstoykov mstoykov modified the milestones: v0.52.0, v0.53.0 Jun 10, 2024
@mstoykov mstoykov mentioned this pull request Jul 1, 2024
5 tasks
@mstoykov mstoykov added the breaking change for PRs that need to be mentioned in the breaking changes section of the release notes label Jul 8, 2024
js/bundle.go Outdated Show resolved Hide resolved
@mstoykov mstoykov force-pushed the esm branch 2 times, most recently from bececd4 to f083187 Compare July 9, 2024 15:43
@mstoykov mstoykov requested a review from codebien July 9, 2024 15:55
js/bundle.go Outdated Show resolved Hide resolved
Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

I did an initial round of review and it looks good 🚀 I left mostly minors. Great work! 💪

js/bundle_test.go Outdated Show resolved Hide resolved
js/esm_vs_commonjs_test.go Outdated Show resolved Hide resolved
js/modules/cjsmodule.go Outdated Show resolved Hide resolved
js/modules/cjsmodule.go Show resolved Hide resolved
js/modules/gomodule.go Outdated Show resolved Hide resolved
js/modules/require_impl.go Outdated Show resolved Hide resolved
js/modules/require_impl.go Outdated Show resolved Hide resolved
js/modules/require_impl.go Outdated Show resolved Hide resolved
js/modules/require_impl.go Outdated Show resolved Hide resolved
js/modules/resolution.go Outdated Show resolved Hide resolved
This is still very hackish and tries to preserve every observable
behavior possible.

This also specifically skips adding support for:
1. dynamic import
2. Top level await - this is possible, but will require more changes
3. anything around the internal go modules having more functionality,
   which will likely require breaking changes

Which will be added later. Also let us concentrate on making this change
as not breaking as possible.
maxSrcLenForBabelSourceMapVarName = "K6_DEBUG_SOURCEMAP_FILESIZE_LIMIT"
sourceMapURLFromBabel = "k6://internal-should-not-leak/file.map"
)
// A Compiler compiles JavaScript source code (ES5.1 or ES6) into a sobek.Program
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// A Compiler compiles JavaScript source code (ES5.1 or ES6) into a sobek.Program

Looks like this comment is duplicated from the one below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already have a branch that goes and fixes this and other comments, I would prefer to not block this PR on this.

There is going to quite a lot of cleanup either way.

Copy link
Contributor

@olegbespalov olegbespalov left a comment

Choose a reason for hiding this comment

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

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change for PRs that need to be mentioned in the breaking changes section of the release notes js-compat
Projects
None yet
6 participants