This repository was archived by the owner on Dec 20, 2022. It is now read-only.
chore(deps): update dependency esbuild to v0.16.10#354
Open
renovate[bot] wants to merge 1 commit into
Open
Conversation
16ea2ca to
25867a7
Compare
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR contains the following updates:
0.15.18->0.16.10Release Notes
evanw/esbuild
v0.16.10Compare Source
Change the default "legal comment" behavior again (#2745)
The legal comments feature automatically gathers comments containing
@licenseor@preserveand puts the comments somewhere (either in the generated code or in a separate file). This behavior used to be on by default but was disabled by default in version 0.16.0 because automatically inserting comments is potentially confusing and misleading. These comments can appear to be assigning the copyright of your code to another entity. And this behavior can be especially problematic if it happens automatically by default since you may not even be aware of it happening. For example, if you bundle the TypeScript compiler the preserving legal comments means your source code would contain this comment, which appears to be assigning the copyright of all of your code to Microsoft:However, people have asked for this feature to be re-enabled by default. To resolve the confusion about what these comments are applying to, esbuild's default behavior will now be to attempt to describe which package the comments are coming from. So while this feature has been re-enabled by default, the output will now look something like this instead:
Note that you can still customize this behavior with the
--legal-comments=flag. For example, you can use--legal-comments=noneto turn this off, or you can use--legal-comments=linkedto put these comments in a separate.LEGAL.txtfile instead.Enable
externallegal comments with the transform API (#2390)Previously esbuild's transform API only supported
none,inline, oreoflegal comments. With this release,externallegal comments are now also supported with the transform API. This only applies to the JS and Go APIs, not to the CLI, and looks like this:JS:
Go:
Fix duplicate function declaration edge cases (#2757)
The change in the previous release to forbid duplicate function declarations in certain cases accidentally forbid some edge cases that should have been allowed. Specifically duplicate function declarations are forbidden in nested blocks in strict mode and at the top level of modules, but are allowed when they are declared at the top level of function bodies. This release fixes the regression by re-allowing the last case.
Allow package subpaths with
alias(#2715)Previously the names passed to the
aliasfeature had to be the name of a package (with or without a package scope). With this release, you can now also use thealiasfeature with package subpaths. So for example you can now create an alias that substitutes@org/pkg/libwith something else.v0.16.9Compare Source
Update to Unicode 15.0.0
The character tables that determine which characters form valid JavaScript identifiers have been updated from Unicode version 14.0.0 to the newly-released Unicode version 15.0.0. I'm not putting an example in the release notes because all of the new characters will likely just show up as little squares since fonts haven't been updated yet. But you can read https://www.unicode.org/versions/Unicode15.0.0/#Summary for more information about the changes.
Disallow duplicate lexically-declared names in nested blocks and in strict mode
In strict mode or in a nested block, it's supposed to be a syntax error to declare two symbols with the same name unless all duplicate entries are either
functiondeclarations or allvardeclarations. However, esbuild was overly permissive and allowed this when duplicate entries were eitherfunctiondeclarations orvardeclarations (even if they were mixed). This check has now been made more restrictive to match the JavaScript specification:Add a type declaration for the new
emptyloader (#2755)I forgot to add this in the previous release. It has now been added.
This fix was contributed by @fz6m.
Add support for the
vflag in regular expression literalsPeople are currently working on adding a
vflag to JavaScript regular expresions. You can read more about this flag here: https://v8.dev/features/regexp-v-flag. This release adds support for parsing this flag, so esbuild will now no longer consider regular expression literals with this flag to be a syntax error. If the target is set to something other thanesnext, esbuild will transform regular expression literals containing this flag into anew RegExp()constructor call so the resulting code doesn't have a syntax error. This enables you to provide a polyfill forRegExpthat implements thevflag to get your code to work at run-time. While esbuild doesn't typically adopt proposals until they're already shipping in a real JavaScript run-time, I'm adding it now because a) esbuild's implementation doesn't need to change as the proposal evolves, b) this isn't really new syntax since regular expression literals already have flags, and c) esbuild's implementation is a trivial pass-through anyway.Avoid keeping the name of classes with static
namepropertiesThe
--keep-namesproperty attempts to preserve the original value of thenameproperty for functions and classes even when identifiers are renamed by the minifier or to avoid a name collision. This is currently done by generating code to assign a string to thenameproperty on the function or class object. However, this should not be done for classes with a staticnameproperty since in that case the explicitly-definednameproperty overwrites the automatically-generated class name. With this release, esbuild will now no longer attempt to preserve thenameproperty for classes with a staticnameproperty.v0.16.8Compare Source
Allow plugins to resolve injected files (#2754)
Previously paths passed to the
injectfeature were always interpreted as file system paths. This meant thatonResolveplugins would not be run for them and esbuild's default path resolver would always be used. This meant that theinjectfeature couldn't be used in the browser since the browser doesn't have access to a file system. This release runs paths passed toinjectthrough esbuild's full path resolution pipeline so plugins now have a chance to handle them usingonResolvecallbacks. This makes it possible to write a plugin that makes esbuild'sinjectwork in the browser.Add the
emptyloader (#1541, #2753)The new
emptyloader tells esbuild to pretend that a file is empty. So for example--loader:.css=emptyeffectively skips all imports of.cssfiles in JavaScript so that they aren't included in the bundle, sinceimport "./some-empty-file"in JavaScript doesn't bundle anything. You can also use theemptyloader to remove asset references in CSS files. For example--loader:.png=emptycauses esbuild to replace asset references such asurl(image.png)withurl()so that they are no longer included in the resulting style sheet.Fix
</script>and</style>escaping for non-default targets (#2748)The change in version 0.16.0 to give control over
</script>escaping via--supported:inline-script=falseor--supported:inline-script=trueaccidentally broke automatic escaping of</script>when an explicittargetsetting is specified. This release restores the correct automatic escaping of</script>(which should not depend on whattargetis set to).Enable the
exportsfield withNODE_PATHS(#2752)Node has a rarely-used feature where you can extend the set of directories that node searches for packages using the
NODE_PATHSenvironment variable. While esbuild supports this too, previously it only supported the oldmainfield path resolution but did not support the newexportsfield package resolution. This release makes the path resolution rules the same again for bothnode_modulesdirectories andNODE_PATHSdirectories.v0.16.7Compare Source
Include
fileloader strings in metafile imports (#2731)Bundling a file with the
fileloader copies that file to the output directory and imports a module with the path to the copied file in thedefaultexport. Previously when bundling with thefileloader, there was no reference in the metafile from the JavaScript file containing the path string to the copied file. With this release, there will now be a reference in the metafile in theimportsarray with the kindfile-loader:{ ... "outputs": { "out/image-55CCFTCE.svg": { ... }, "out/entry.js": { "imports": [ + { + "path": "out/image-55CCFTCE.svg", + "kind": "file-loader" + } ], ... } } }Fix byte counts in metafile regarding references to other output files (#2071)
Previously files that contained references to other output files had slightly incorrect metadata for the byte counts of input files which contributed to that output file. So for example if
app.jsimportsimage.pngusing the file loader and esbuild generatesout.jsandimage-LSAMBFUD.png, the metadata for how many bytes ofout.jsare fromapp.jswas slightly off (the metadata for the byte count ofout.jswas still correct). The reason is because esbuild substitutes the final paths for references between output files toward the end of the build to handle cyclic references, and the byte counts needed to be adjusted as well during the path substitution. This release fixes these byte counts (specifically thebytesInOutputvalues).The alias feature now strips a trailing slash (#2730)
People sometimes add a trailing slash to the name of one of node's built-in modules to force node to import from the file system instead of importing the built-in module. For example, importing
utilimports node's built-in module calledutilbut importingutil/tries to find a package calledutilon the file system. Previously attempting to use esbuild's package alias feature to replace imports toutilwith a specific file would fail because the file path would also gain a trailing slash (e.g. mappingutilto./file.jsturnedutil/into./file.js/). With this release, esbuild will now omit the path suffix if it's a single trailing slash, which should now allow you to successfully apply aliases to these import paths.v0.16.6Compare Source
Do not mark subpath imports as external with
--packages=external(#2741)Node has a feature called subpath imports where special import paths that start with
#are resolved using theimportsfield in thepackage.jsonfile of the enclosing package. The intent of the newly-added--packages=externalsetting is to exclude a package's dependencies from the bundle. Since a package's subpath imports are only accessible within that package, it's wrong for them to be affected by--packages=external. This release changes esbuild so that--packages=externalno longer affects subpath imports.Forbid invalid numbers in JSON files
Previously esbuild parsed numbers in JSON files using the same syntax as JavaScript. But starting from this release, esbuild will now parse them with JSON syntax instead. This means the following numbers are no longer allowed by esbuild in JSON files:
0)0b,0o, and0xnumeric prefixes_such as1_000.such as0.and.0-such as- 1Add external imports to metafile (#905, #1768, #1933, #1939)
External imports now appear in
importsarrays in the metafile (which is present when bundling withmetafile: true) next to normal imports, but additionally haveexternal: trueto set them apart. This applies both to files in theinputssection and theoutputssection. Here's an example:{ "inputs": { "style.css": { "bytes": 83, "imports": [ + { + "path": "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css", + "kind": "import-rule", + "external": true + } ] }, "app.js": { "bytes": 100, "imports": [ + { + "path": "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js", + "kind": "import-statement", + "external": true + }, { "path": "style.css", "kind": "import-statement" } ] } }, "outputs": { "out/app.js": { "imports": [ + { + "path": "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js", + "kind": "require-call", + "external": true + } ], "exports": [], "entryPoint": "app.js", "cssBundle": "out/app.css", "inputs": { "app.js": { "bytesInOutput": 113 }, "style.css": { "bytesInOutput": 0 } }, "bytes": 528 }, "out/app.css": { "imports": [ + { + "path": "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css", + "kind": "import-rule", + "external": true + } ], "inputs": { "style.css": { "bytesInOutput": 0 } }, "bytes": 100 } } }One additional useful consequence of this is that the
importsarray is now populated when bundling is disabled. So you can now use esbuild with bundling disabled to inspect a file's imports.v0.16.5Compare Source
Make it easy to exclude all packages from a bundle (#1958, #1975, #2164, #2246, #2542)
When bundling for node, it's often necessary to exclude npm packages from the bundle since they weren't designed with esbuild bundling in mind and don't work correctly after being bundled. For example, they may use
__dirnameand run-time file system calls to load files, which doesn't work after bundling with esbuild. Or they may compile a native.nodeextension that has similar expectations about the layout of the file system that are no longer true after bundling (even if the.nodeextension is copied next to the bundle).The way to get this to work with esbuild is to use the
--external:flag. For example, thefseventspackage contains a native.nodeextension and shouldn't be bundled. To bundle code that uses it, you can pass--external:fseventsto esbuild to exclude it from your bundle. You will then need to ensure that thefseventspackage is still present when you run your bundle (e.g. by publishing your bundle to npm as a package with a dependency onfsevents).It was possible to automatically do this for all of your dependencies, but it was inconvenient. You had to write some code that read your
package.jsonfile and passed the keys of thedependencies,devDependencies,peerDependencies, and/oroptionalDependenciesmaps to esbuild as external packages (either that or write a plugin to mark all package paths as external). Previously esbuild's recommendation for making this easier was to do--external:./node_modules/*(added in version 0.14.13). However, this was a bad idea because it caused compatibility problems with many node packages as it caused esbuild to mark the post-resolve path as external instead of the pre-resolve path. Doing that could break packages that are published as both CommonJS and ESM if esbuild's bundler is also used to do a module format conversion.With this release, you can now do the following to automatically exclude all packages from your bundle:
CLI:
JS:
Go:
Doing
--external:./node_modules/*is still possible and still has the same behavior, but is no longer recommended. I recommend that you use the newpackagesfeature instead.Fix some subtle bugs with tagged template literals
This release fixes a bug where minification could incorrectly change the value of
thiswithin tagged template literal function calls:This release also fixes a bug where using optional chaining with
--target=es2019or earlier could incorrectly change the value ofthiswithin tagged template literal function calls:Some slight minification improvements
The following minification improvements were implemented:
if (~a !== 0) throw x;=>if (~a) throw x;if ((a | b) !== 0) throw x;=>if (a | b) throw x;if ((a & b) !== 0) throw x;=>if (a & b) throw x;if ((a ^ b) !== 0) throw x;=>if (a ^ b) throw x;if ((a << b) !== 0) throw x;=>if (a << b) throw x;if ((a >> b) !== 0) throw x;=>if (a >> b) throw x;if ((a >>> b) !== 0) throw x;=>if (a >>> b) throw x;if (!!a || !!b) throw x;=>if (a || b) throw x;if (!!a && !!b) throw x;=>if (a && b) throw x;if (a ? !!b : !!c) throw x;=>if (a ? b : c) throw x;v0.16.4Compare Source
Fix binary downloads from the
@esbuild/scope for Deno (#2729)Version 0.16.0 of esbuild moved esbuild's binary executables into npm packages under the
@esbuild/scope, which accidentally broke the binary downloader script for Deno. This release fixes this script so it should now be possible to use esbuild version 0.16.4+ with Deno.v0.16.3Compare Source
Fix a hang with the JS API in certain cases (#2727)
A change that was made in version 0.15.13 accidentally introduced a case when using esbuild's JS API could cause the node process to fail to exit. The change broke esbuild's watchdog timer, which detects if the parent process no longer exists and then automatically exits esbuild. This hang happened when you ran node as a child process with the
stderrstream set topipeinstead ofinherit, in the child process you call esbuild's JS API and passincremental: truebut do not calldispose()on the returnedrebuildobject, and then callprocess.exit(). In that case the parent node process was still waiting for the esbuild process that was created by the child node process to exit. The change made in version 0.15.13 was trying to avoid using Go'ssync.WaitGroupAPI incorrectly because the API is not thread-safe. Instead of doing this, I have now reverted that change and implemented a thread-safe version of thesync.WaitGroupAPI for esbuild to use instead.v0.16.2Compare Source
Fix
process.env.NODE_ENVsubstitution when transforming (#2718)Version 0.16.0 introduced an unintentional regression that caused
process.env.NODE_ENVto be automatically substituted with either"development"or"production"when using esbuild'stransformAPI. This substitution is a necessary feature of esbuild'sbuildAPI because the React framework crashes when you bundle it without doing this. But thetransformAPI is typically used as part of a larger build pipeline so the benefit of esbuild doing this automatically is not as clear, and esbuild previously didn't do this.However, version 0.16.0 switched the default value of the
platformsetting for thetransformAPI fromneutraltobrowser, both to align it with esbuild's documentation (which saysbrowseris the default value) and because escaping the</script>character sequence is now tied to thebrowserplatform (see the release notes for version 0.16.0 for details). That accidentally enabled automatic substitution ofprocess.env.NODE_ENVbecause esbuild always did that for code meant for the browser. To fix this regression, esbuild will now only automatically substituteprocess.env.NODE_ENVwhen using thebuildAPI.Prevent
definefrom substituting constants into assignment position (#2719)The
definefeature lets you replace certain expressions with constants. For example, you could use it to replace references to the global property referencewindow.DEBUGwithfalseat compile time, which can then potentially help esbuild remove unused code from your bundle. It's similar to DefinePlugin in Webpack.However, if you write code such as
window.DEBUG = trueand then definedwindow.DEBUGtofalse, esbuild previously generated the outputfalse = truewhich is a syntax error in JavaScript. This behavior is not typically a problem because it doesn't make sense to substitutewindow.DEBUGwith a constant if its value changes at run-time (Webpack'sDefinePluginalso generatesfalse = truein this case). But it can be alarming to have esbuild generate code with a syntax error.So with this release, esbuild will no longer substitute
defineconstants into assignment position to avoid generating code with a syntax error. Instead esbuild will generate a warning, which currently looks like this:Fix a regression with
npm install --no-optional(#2720)Normally when you install esbuild with
npm install, npm itself is the tool that downloads the correct binary executable for the current platform. This happens because of how esbuild's primary package uses npm'soptionalDependenciesfeature. However, if you deliberately disable this withnpm install --no-optionalthen esbuild's install script will attempt to repair the installation by manually downloading and extracting the binary executable from the package that was supposed to be installed.The change in version 0.16.0 to move esbuild's nested packages into the
@esbuild/scope unintentionally broke this logic because of how npm's URL structure is different for scoped packages vs. normal packages. It was actually already broken for a few platforms earlier because esbuild already had packages for some platforms in the@esbuild/scope, but I didn't discover this then because esbuild's integration tests aren't run on all platforms. Anyway, this release contains some changes to the install script that should hopefully get this scenario working again.v0.16.1Compare Source
Change the default "legal comment" behavior again (#2745)
The legal comments feature automatically gathers comments containing
@licenseor@preserveand puts the comments somewhere (either in the generated code or in a separate file). This behavior used to be on by default but was disabled by default in version 0.16.0 because automatically inserting comments is potentially confusing and misleading. These comments can appear to be assigning the copyright of your code to another entity. And this behavior can be especially problematic if it happens automatically by default since you may not even be aware of it happening. For example, if you bundle the TypeScript compiler the preserving legal comments means your source code would contain this comment, which appears to be assigning the copyright of all of your code to Microsoft:However, people have asked for this feature to be re-enabled by default. To resolve the confusion about what these comments are applying to, esbuild's default behavior will now be to attempt to describe which package the comments are coming from. So while this feature has been re-enabled by default, the output will now look something like this instead:
Note that you can still customize this behavior with the
--legal-comments=flag. For example, you can use--legal-comments=noneto turn this off, or you can use--legal-comments=linkedto put these comments in a separate.LEGAL.txtfile instead.Enable
externallegal comments with the transform API (#2390)Previously esbuild's transform API only supported
none,inline, oreoflegal comments. With this release,externallegal comments are now also supported with the transform API. This only applies to the JS and Go APIs, not to the CLI, and looks like this:JS:
Go:
Fix duplicate function declaration edge cases (#2757)
The change in the previous release to forbid duplicate function declarations in certain cases accidentally forbid some edge cases that should have been allowed. Specifically duplicate function declarations are forbidden in nested blocks in strict mode and at the top level of modules, but are allowed when they are declared at the top level of function bodies. This release fixes the regression by re-allowing the last case.
Allow package subpaths with
alias(#2715)Previously the names passed to the
aliasfeature had to be the name of a package (with or without a package scope). With this release, you can now also use thealiasfeature with package subpaths. So for example you can now create an alias that substitutes@org/pkg/libwith something else.v0.16.0Compare Source
This release deliberately contains backwards-incompatible changes. To avoid automatically picking up releases like this, you should either be pinning the exact version of
esbuildin yourpackage.jsonfile (recommended) or be using a version range syntax that only accepts patch upgrades such as^0.15.0or~0.15.0. See npm's documentation about semver for more information.Move all binary executable packages to the
@esbuild/scopeBinary package executables for esbuild are published as individual packages separate from the main
esbuildpackage so you only have to download the relevant one for the current platform when you install esbuild. This release moves all of these packages under the@esbuild/scope to avoid collisions with 3rd-party packages. It also changes them to a consistent naming scheme that uses theosandcpunames from node.The package name changes are as follows:
@esbuild/linux-loong64=>@esbuild/linux-loong64(no change)esbuild-android-64=>@esbuild/android-x64esbuild-android-arm64=>@esbuild/android-arm64esbuild-darwin-64=>@esbuild/darwin-x64esbuild-darwin-arm64=>@esbuild/darwin-arm64esbuild-freebsd-64=>@esbuild/freebsd-x64esbuild-freebsd-arm64=>@esbuild/freebsd-arm64esbuild-linux-32=>@esbuild/linux-ia32esbuild-linux-64=>@esbuild/linux-x64esbuild-linux-arm=>@esbuild/linux-armesbuild-linux-arm64=>@esbuild/linux-arm64esbuild-linux-mips64le=>@esbuild/linux-mips64elesbuild-linux-ppc64le=>@esbuild/linux-ppc64esbuild-linux-riscv64=>@esbuild/linux-riscv64esbuild-linux-s390x=>@esbuild/linux-s390xesbuild-netbsd-64=>@esbuild/netbsd-x64esbuild-openbsd-64=>@esbuild/openbsd-x64esbuild-sunos-64=>@esbuild/sunos-x64esbuild-wasm=>esbuild-wasm(no change)esbuild-windows-32=>@esbuild/win32-ia32esbuild-windows-64=>@esbuild/win32-x64esbuild-windows-arm64=>@esbuild/win32-arm64esbuild=>esbuild(no change)Normal usage of the
esbuildandesbuild-wasmpackages should not be affected. These name changes should only affect tools that hard-coded the individual binary executable package names into custom esbuild downloader scripts.This change was not made with performance in mind. But as a bonus, installing esbuild with npm may potentially happen faster now. This is because npm's package installation protocol is inefficient: it always downloads metadata for all past versions of each package even when it only needs metadata about a single version. This makes npm package downloads O(n) in the number of published versions, which penalizes packages like esbuild that are updated regularly. Since most of esbuild's package names have now changed, npm will now need to download much less data when installing esbuild (8.72mb of package manifests before this change → 0.06mb of package manifests after this change). However, this is only a temporary improvement. Installing esbuild will gradually get slower again as further versions of esbuild are published.
Publish a shell script that downloads esbuild directly
In addition to all of the existing ways to install esbuild, you can now also download esbuild directly like this:
curl -fsSL https://esbuild.github.io/dl/latest | shThis runs a small shell script that downloads the latest
esbuildbinary executable to the current directory. This can be convenient on systems that don't havenpminstalled or when you just want to get a copy of esbuild quickly without any extra steps. If you want a specific version of esbuild (starting with this version onward), you can provide that version in the URL instead oflatest:curl -fsSL https://esbuild.github.io/dl/v0.16.0 | shNote that the download script needs to be able to access registry.npmjs.org to be able to complete the download. This download script doesn't yet support all of the platforms that esbuild supports because I lack the necessary testing environments. If the download script doesn't work for you because you're on an unsupported platform, please file an issue on the esbuild repo so we can add support for it.
Fix some parameter names for the Go API
This release changes some parameter names for the Go API to be consistent with the JavaScript and CLI APIs:
OutExtensions=>OutExtensionJSXMode=>JSXAdd additional validation of API parameters
The JavaScript API now does some additional validation of API parameters to catch incorrect uses of esbuild's API. The biggest impact of this is likely that esbuild now strictly only accepts strings with the
defineparameter. This would already have been a type error with esbuild's TypeScript type definitions, but it was previously not enforced for people using esbuild's API JavaScript without TypeScript.The
defineparameter appears at first glance to take a JSON object if you aren't paying close attention, but this actually isn't true. Values fordefineare instead strings of JavaScript code. This means you have to usedefine: { foo: '"bar"' }to replacefoowith the string"bar". Usingdefine: { foo: 'bar' }actually replacesfoowith the identifierbar. Previously esbuild allowed you to passdefine: { foo: false }andfalsewas automatically converted into a string, which made it more confusing to understand whatdefineactually represents. Starting with this release, passing non-string values such as withdefine: { foo: false }will no longer be allowed. You will now have to writedefine: { foo: 'false' }instead.Generate shorter data URLs if possible (#1843)
Loading a file with esbuild's
dataurlloader generates a JavaScript module with a data URL for that file in a string as a single default export. Previously the data URLs generated by esbuild all used base64 encoding. However, this is unnecessarily long for most textual data (e.g. SVG images). So with this release, esbuild'sdataurlloader will now use percent encoding instead of base64 encoding if the result will be shorter. This can result in ~25% smaller data URLs for large SVGs. If you want the old behavior, you can use thebase64loader instead and then construct the data URL yourself.Avoid marking entry points as external (#2382)
Previously you couldn't specify
--external:*to mark all import paths as external because that also ended up making the entry point itself external, which caused the build to fail. With this release, esbuild'sexternalAPI parameter no longer applies to entry points so using--external:*is now possible.One additional consequence of this change is that the
kindparameter is now required when calling theresolve()function in esbuild's plugin API. Previously thekindparameter defaulted toentry-point, but that no longer interacts withexternalso it didn't seem wise for this to continue to be the default. You now have to specifykindso that the path resolution mode is explicit.Disallow non-
defaultimports whenassert { type: 'json' }is presentThere is now standard behavior for importing a JSON file into an ES module using an
importstatement. However, it requires you to place theassert { type: 'json' }import assertion after the import path. This import assertion tells the JavaScript runtime to throw an error if the import does not end up resolving to a JSON file. On the web, the type of a file is determined by theContent-TypeHTTP header instead of by the file extension. The import assertion prevents security problems on the web where a.jsonfile may actually resolve to a JavaScript file containing malicious code, which is likely not expected for an import that is supposed to only contain pure side-effect free data.By default, esbuild uses the file extension to determine the type of a file, so this import assertion is unnecessary with esbuild. However, esbuild's JSON import feature has a non-standard extension that allows you to import top-level properties of the JSON object as named imports. For example, esbuild lets you do this:
This is useful for tree-shaking when bundling because it means esbuild will only include the the
versionfield ofpackage.jsonin your bundle. This is non-standard behavior though and doesn't match the behavior of what happens when you import JSON in a real JavaScript runtime (after addingassert { type: 'json' }). In a real JavaScript runtime the only thing you can import is thedefaultimport. So with this release, esbuild will now prevent you from importing non-defaultimport names ifassert { type: 'json' }is present. This ensures that code containingassert { type: 'json' }isn't relying on non-standard behavior that won't work everywhere. So the following code is now an error with esbuild when bundling:In addition, adding
assert { type: 'json' }to an import statement now means esbuild will generate an error if the loader for the file is anything other thanjson, which is required by the import assertion specification.Provide a way to disable automatic escaping of
</script>(#2649)If you inject esbuild's output into a script tag in an HTML file, code containing the literal characters
</script>will cause the tag to be ended early which will break the code:To avoid this, esbuild automatically escapes these strings in generated JavaScript files (e.g.
"</script>"becomes"<\/script>"instead). This also applies to</style>in generated CSS files. Previously this always happened and there wasn't a way to turn this off.With this release, esbuild will now only do this if the
platformsetting is set tobrowser(the default value). Settingplatformtonodeorneutralwill disable this behavior. This behavior can also now be disabled with--supported:inline-script=false(for JS) and--supported:inline-style=false(for CSS).Throw an early error if decoded UTF-8 text isn't a
Uint8Array(#2532)If you run esbuild's JavaScript API in a broken JavaScript environment where
new TextEncoder().encode("") instanceof Uint8Arrayis false, then esbuild's API will fail with a confusing serialization error message that makes it seem like esbuild has a bug even though the real problem is that the JavaScript environment itself is broken. This can happen when using the test framework called Jest. With this release, esbuild's API will now throw earlier when it detects that the environment is unable to encode UTF-8 text correctly with an error message that makes it more clear that this is not a problem with esbuild.Change the default "legal comment" behavior
The legal comments feature automatically gathers comments containing
@licenseor@preserveand puts the comments somewhere (either in the generated code or in a separate file). People sometimes want this to happen so that the their dependencies' software licenses are retained in the generated output code. By default esbuild puts these comments at the end of the file when bundling. However, people sometimes find this confusing because these comments can be very generic and may not mention which library they come from. So with this release, esbuild will now discard legal comments by default. You now have to opt-in to preserving them if you want this behavior.Enable the
modulecondition by default (#2417)Package authors want to be able to use the new
exportsfield inpackage.jsonto provide tree-shakable ESM code for ESM-aware bundlers while simultaneously providing fallback CommonJS code for other cases.Node's proposed way to do this involves using the
importandrequireexport conditions so that you get the ESM code if you use an import statement and the CommonJS code if you use a require call. However, this has a major drawback: if some code in the bundle uses an import statement and other code in the bundle uses a require call, then you'll get two copies of the same package in the bundle. This is known as the dual package hazard and can lead to bloated bundles or even worse to subtle logic bugs.Webpack supports an alternate solution: an export condition called
modulethat takes effect regardless of whether the package was imported using an import statement or a require call. This works because bundlers such as Webpack support importing a ESM using a require call (something node doesn't support). You could already do this with esbuild using--conditions=modulebut you previously had to explicitly enable this. Package authors are concerned that esbuild users won't know to do this and will get suboptimal output with their package, so they have requested for esbuild to do this automatically.So with this release, esbuild will now automatically add the
modulecondition when there aren't any customconditionsalready configured. You can disable this with--conditions=orconditions: [](i.e. explicitly clearing all custom conditions).Rename the
masterbranch tomainThe primary branch for this repository was previously called
masterbut is now calledmain. This change mirrors a similar change in many other projects.Remove esbuild's
_exit(0)hack for WebAssembly (#714)Node had an unfortunate bug where the node process is unnecessarily kept open while a WebAssembly module is being optimized: https://github.com/nodejs/node/issues/36616. This means cases where running
esbuildshould take a few milliseconds can end up taking many seconds instead.The workaround was to force node to exit by ending the process early. This was done by esbuild in one of two ways depending on the exit code. For non-zero exit codes (i.e. when there is a build error), the
esbuildcommand could just callprocess.kill(process.pid)to avoid the hang. But for zero exit codes, esbuild had to load a N-API native node extension that calls the operating system'sexit(0)function.However, this problem has essentially been fixed in node starting with version 18.3.0. So I have removed this hack from esbuild. If you are using an earlier version of node with
esbuild-wasmand you don't want theesbuildcommand to hang for a while when exiting, you can upgrade to node 18.3.0 or higher to remove the hang.The fix came from a V8 upgrade: this commit enabled dynamic tiering for WebAssembly by default for all projects that use V8's WebAssembly implementation. Previously all functions in the WebAssembly module were optimized in a single batch job but with dynamic tiering, V8 now optimizes individual WebAssembly functions as needed. This avoids unnecessary WebAssembly compilation which allows node to exit on time.
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.