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

PoC ESM support #2563

Closed
wants to merge 1 commit into from
Closed

PoC ESM support #2563

wants to merge 1 commit into from

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Jun 13, 2022

This is not a final PR it is here mostly to discuss whether the changes presented here are satisfying our needs.

This PR will need to be merged after the goja PR (to be done) with the ESM support is merged.

TODO:

  • A lot more tests especially with multiple commonjs and not commonjs modules
  • Support go modules that are Cyclic Module Records and them requesting (at least) other go modules. This is needed for k6/ws -> k6/http.CookieJar
  • Support import.meta and dynamic import - the later likely will not be enabled by default in k6 at least for now.
  • Cleaning up and fixing require and open as they need GetActiveScriptOrModule from the specification to be written correctly ;(.

@mstoykov mstoykov added this to the v0.40.0 milestone Jun 13, 2022
@mstoykov mstoykov marked this pull request as ready for review July 28, 2022 14:38
@mstoykov mstoykov requested review from na--, codebien and imiric and removed request for na-- and codebien July 28, 2022 14:38
@github-actions github-actions bot requested a review from codebien July 28, 2022 14:38
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Some basic comments for starting the discussion. If possible I would drop the wrap prefixes and rename things like wrappedCommonJSInstance in just commonJSInstance.

}

// This goja.ModuleRecord wrapper for go/js module which does not conform to modules.Module interface
type wrappedBasicGoModule struct {
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
type wrappedBasicGoModule struct {
type uncompliantModule struct {

Just as a suggestion for searching a better name.

}

// This goja.ModuleRecord wrapper for go/js module which conforms to modules.Module interface
type wrappedGoModule struct {
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
type wrappedGoModule struct {
type esModule struct {

"go.k6.io/k6/js/modules"
)

func wrapGoModule(mod interface{}) goja.ModuleRecord {
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
func wrapGoModule(mod interface{}) goja.ModuleRecord {
func resolveModuleRecord(mod interface{}) goja.ModuleRecord {

}

// TODO use the first argument
func (b *Bundle) resolveModule(ref interface{}, specifier string) (goja.ModuleRecord, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a very long method and a bit difficult to follow/review, can we split it a bit?

mstoykov added a commit that referenced this pull request Jan 27, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

This changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extend.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along this changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Jan 27, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Jan 27, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Feb 2, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Feb 2, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Feb 8, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
mstoykov added a commit that referenced this pull request Mar 7, 2023
This refactor tries to simplify the implementation of `require` and
connected code by splitting it heavily into different parts.

These changes are similar to what will be needed for native ESM support
as shown in #2563 , but without any of
the native parts and without doing anything that isn't currently needed.
This will hopefully make ESM PR much smaller and less intrusive.

This includes still keeping the wrong relativity of `require` as
explained in #2674.

It also tries to simplify connected code, but due to this being very
sensitive code and the changes already being quite big, this is done
only to an extent.

The lack of new tests is mostly due to there not being really any new
code and the tests that were created along these changes already being
merged months ago with #2782.

Future changes will try to address the above as well as potentially
moving the whole module types and logic in separate package to be reused
in tests.
@na-- na-- removed their request for review April 19, 2023 13:49
@mstoykov mstoykov mentioned this pull request Aug 14, 2023
@mstoykov
Copy link
Contributor Author

Superseeded by #3456

@mstoykov mstoykov closed this Nov 15, 2023
@mstoykov mstoykov deleted the ESMSupport branch November 17, 2023 09:00
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.

3 participants