-
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
Disable sourcemaps support in babel if input is big #2345
Changes from 4 commits
dc402ee
958e724
a55ce60
b3f4323
3fb01e0
6222b68
ad6e7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import ( | |
_ "embed" // we need this for embedding Babel | ||
"encoding/json" | ||
"errors" | ||
"os" | ||
"strconv" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -81,14 +83,20 @@ var ( | |
"highlightCode": false, | ||
} | ||
|
||
maxSrcLenForBabelSourceMap = 250 * 1024 //nolint:gochecknoglobals | ||
maxSrcLenForBabelSourceMapOnce sync.Once //nolint:gochecknoglobals | ||
|
||
onceBabelCode sync.Once // nolint:gochecknoglobals | ||
globalBabelCode *goja.Program // nolint:gochecknoglobals | ||
globalBabelCodeErr error // nolint:gochecknoglobals | ||
onceBabel sync.Once // nolint:gochecknoglobals | ||
globalBabel *babel // nolint:gochecknoglobals | ||
) | ||
|
||
const sourceMapURLFromBabel = "k6://internal-should-not-leak/file.map" | ||
const ( | ||
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 goja.Program | ||
type Compiler struct { | ||
|
@@ -124,7 +132,28 @@ func (c *Compiler) Transform(src, filename string, inputSrcMap []byte) (code str | |
return | ||
} | ||
|
||
code, srcMap, err = c.babel.transformImpl(c.logger, src, filename, c.Options.SourceMapLoader != nil, inputSrcMap) | ||
sourceMapEnabled := c.Options.SourceMapLoader != nil | ||
maxSrcLenForBabelSourceMapOnce.Do(func() { | ||
// TODO: drop this code and everything it's connected to when babel is dropped | ||
v := os.Getenv(maxSrcLenForBabelSourceMapVarName) | ||
if len(v) > 0 { | ||
i, err := strconv.Atoi(v) | ||
if err != nil { | ||
c.logger.Warnf("Tried to parse %q from %s as integer but couldn't %s\n", | ||
v, maxSrcLenForBabelSourceMapVarName, err) | ||
return | ||
} | ||
maxSrcLenForBabelSourceMap = i | ||
} | ||
}) | ||
if sourceMapEnabled && len(src) > maxSrcLenForBabelSourceMap { | ||
sourceMapEnabled = false | ||
c.logger.Warnf("the source for `%s` needs to go through babel but is over %d bytes. "+ | ||
mstoykov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"For performance reasons sourcemaps support will be disabled for this particular file.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we shouldn't mention this, for a couple of reasons:
So we shouldn't really document this. It's a temporary option until we get rid of Babel. We can always mention it and the caveats if someone asks in the forum.
mstoykov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filename, maxSrcLenForBabelSourceMap) | ||
} | ||
|
||
code, srcMap, err = c.babel.transformImpl(c.logger, src, filename, sourceMapEnabled, inputSrcMap) | ||
return | ||
} | ||
|
||
|
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.
Do we have an issue to link?
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.
#2296 (comment) maybe? 🤔
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.
mmm...if we don't have one yet, I'm for creating one dedicated with the steps we plan for dropping babel. For example, it would be useful to have somewhere a link to dop251/goja#348 and this potential new issue could be a good candidate, IMHO.It's mentioned in your comment, sorry, my fault.