-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Contain main module within it's own scope as well #2571
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5941d5
Add to showcase how currently options is accessible everywhere
mstoykov 35146ca
Contain main module within it's own scope as well
mstoykov 42bf5d6
Drop TestBundleInstantiate/SetAndRun
mstoykov 3e52cb8
Better panic message
mstoykov a614cfe
Extract main commonjs module initialization
mstoykov 6b77bfc
Improve compiler readability around commonjs wrapping parameters
mstoykov 7e289a5
Add a comment about main script map lookup
mstoykov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm it would be relatively easy to make this in a
DynamicObject
that prints a warning if anyone tries to access any of the properties, right? 🤔 Telling people (with async.Once
, to limit spam) to usetest.options
fromk6/execution
forGet()
, Keys() andHas
() operations, and telling (with anothersync.Once
) them that modifying theoptions
during the script runtime is useless and won't actually affect anything?Not in this PR, of course, but should I open an issue about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible - not certain how well it will play once we have ESM, but it should work 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried during the
test.options
implementation, there was an issue in the case of options exported asconst
, where IIRC it isn't compatible with dynamic solutions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2601 please comment/edit if I've missed something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this in practice will not work ... all that well even with just this cchanges as we already can not change the original
options
. This here only setsexports.options
in case they are empty.even before that again we were just setting something globally.
This won't work with ESM as well as in that case just as now we don't have access to change waht
options
is in hte scope of the module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. In the case of commonjs transpiled by babel the actual code is something like
In this case we can resset
exports.options
but nothing will be using it. What we have done so far (and what this PR changes) is basically settingglobalThis.options
which just so happens to be the same as havinglet options
in the global scope.In ESM
is more or less
And then we get access to
options
and can set it's fields (just as before) but AFAIK there is no way to just change whatoptions
is supposed to be.You can think of it as modules are supposed to encapsulate stuff so that the outside world can't mangle them and what you want is basically what modules are kind of trying to prevent. (They also prevent spilling stuff from inside modules in the global scope which is the other side of the coin - arguably the one that is more commonly cited)
So it seems like this isn't really a thing we can do 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I think... Then this whole logic of updating the script
options
with the consolidated values won't work at all? 😕There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe it will, since we're going item by item and updating individual keys of the object? 🤔 In which case, we might be able to add the usage warnings at the key level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this:
k6/js/bundle.go
Lines 297 to 299 in 6b77bfc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work for all varitants 🤔