evanw/esbuild
### [`v0.16.2`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0162)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.16.1...v0.16.2)
- Fix `process.env.NODE_ENV` substitution when transforming ([#2718](https://togithub.com/evanw/esbuild/issues/2718))
Version 0.16.0 introduced an unintentional regression that caused `process.env.NODE_ENV` to be automatically substituted with either `"development"` or `"production"` when using esbuild's `transform` API. This substitution is a necessary feature of esbuild's `build` API because the React framework crashes when you bundle it without doing this. But the `transform` API 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 `platform` setting for the `transform` API from `neutral` to `browser`, both to align it with esbuild's documentation (which says `browser` is the default value) and because escaping the `` character sequence is now tied to the `browser` platform (see the release notes for version 0.16.0 for details). That accidentally enabled automatic substitution of `process.env.NODE_ENV` because esbuild always did that for code meant for the browser. To fix this regression, esbuild will now only automatically substitute `process.env.NODE_ENV` when using the `build` API.
- Prevent `define` from substituting constants into assignment position ([#2719](https://togithub.com/evanw/esbuild/issues/2719))
The `define` feature lets you replace certain expressions with constants. For example, you could use it to replace references to the global property reference `window.DEBUG` with `false` at compile time, which can then potentially help esbuild remove unused code from your bundle. It's similar to [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) in Webpack.
However, if you write code such as `window.DEBUG = true` and then defined `window.DEBUG` to `false`, esbuild previously generated the output `false = true` which is a syntax error in JavaScript. This behavior is not typically a problem because it doesn't make sense to substitute `window.DEBUG` with a constant if its value changes at run-time (Webpack's `DefinePlugin` also generates `false = true` in 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 `define` constants into assignment position to avoid generating code with a syntax error. Instead esbuild will generate a warning, which currently looks like this:
▲ [WARNING] Suspicious assignment to defined constant "window.DEBUG" [assign-to-define]
example.js:1:0:
1 │ window.DEBUG = true
╵ ~~~~~~~~~~~~
The expression "window.DEBUG" has been configured to be replaced with a constant using the
"define" feature. If this expression is supposed to be a compile-time constant, then it doesn't
make sense to assign to it here. Or if this expression is supposed to change at run-time, this
"define" substitution should be removed.
- Fix a regression with `npm install --no-optional` ([#2720](https://togithub.com/evanw/esbuild/issues/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's `optionalDependencies` feature. However, if you deliberately disable this with `npm install --no-optional` then 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.1`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0161)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.16.0...v0.16.1)
This is a hotfix for the previous release.
- Re-allow importing JSON with the `copy` loader using an import assertion
The previous release made it so when `assert { type: 'json' }` is present on an import statement, esbuild validated that the `json` loader was used. This is what an import assertion is supposed to do. However, I forgot about the relatively new `copy` loader, which sort of behaves as if the import path was marked as external (and thus not loaded at all) except that the file is copied to the output directory and the import path is rewritten to point to the copy. In this case whatever JavaScript runtime ends up running the code is the one to evaluate the import assertion. So esbuild should really allow this case as well. With this release, esbuild now allows both the `json` and `copy` loaders when an `assert { type: 'json' }` import assertion is present.
### [`v0.16.0`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0160)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.18...v0.16.0)
**This release deliberately contains backwards-incompatible changes.** To avoid automatically picking up releases like this, you should either be pinning the exact version of `esbuild` in your `package.json` file (recommended) or be using a version range syntax that only accepts patch upgrades such as `^0.15.0` or `~0.15.0`. See npm's documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information.
- Move all binary executable packages to the `@esbuild/` scope
Binary package executables for esbuild are published as individual packages separate from the main `esbuild` package 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 the `os` and `cpu` names from node.
The package name changes are as follows:
- `@esbuild/linux-loong64` => `@esbuild/linux-loong64` (no change)
- `esbuild-android-64` => `@esbuild/android-x64`
- `esbuild-android-arm64` => `@esbuild/android-arm64`
- `esbuild-darwin-64` => `@esbuild/darwin-x64`
- `esbuild-darwin-arm64` => `@esbuild/darwin-arm64`
- `esbuild-freebsd-64` => `@esbuild/freebsd-x64`
- `esbuild-freebsd-arm64` => `@esbuild/freebsd-arm64`
- `esbuild-linux-32` => `@esbuild/linux-ia32`
- `esbuild-linux-64` => `@esbuild/linux-x64`
- `esbuild-linux-arm` => `@esbuild/linux-arm`
- `esbuild-linux-arm64` => `@esbuild/linux-arm64`
- `esbuild-linux-mips64le` => `@esbuild/linux-mips64el`
- `esbuild-linux-ppc64le` => `@esbuild/linux-ppc64`
- `esbuild-linux-riscv64` => `@esbuild/linux-riscv64`
- `esbuild-linux-s390x` => `@esbuild/linux-s390x`
- `esbuild-netbsd-64` => `@esbuild/netbsd-x64`
- `esbuild-openbsd-64` => `@esbuild/openbsd-x64`
- `esbuild-sunos-64` => `@esbuild/sunos-x64`
- `esbuild-wasm` => `esbuild-wasm` (no change)
- `esbuild-windows-32` => `@esbuild/win32-ia32`
- `esbuild-windows-64` => `@esbuild/win32-x64`
- `esbuild-windows-arm64` => `@esbuild/win32-arm64`
- `esbuild` => `esbuild` (no change)
Normal usage of the `esbuild` and `esbuild-wasm` packages 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:
```sh
curl -fsSL https://esbuild.github.io/dl/latest | sh
```
This runs a small shell script that downloads the latest `esbuild` binary executable to the current directory. This can be convenient on systems that don't have `npm` installed 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 of `latest`:
```sh
curl -fsSL https://esbuild.github.io/dl/v0.16.0 | sh
```
Note 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` => `OutExtension`
- `JSXMode` => `JSX`
- Add 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 `define` parameter. 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 `define` parameter appears at first glance to take a JSON object if you aren't paying close attention, but this actually isn't true. Values for `define` are instead strings of JavaScript code. This means you have to use `define: { foo: '"bar"' }` to replace `foo` with the string `"bar"`. Using `define: { foo: 'bar' }` actually replaces `foo` with the identifier `bar`. Previously esbuild allowed you to pass `define: { foo: false }` and `false` was automatically converted into a string, which made it more confusing to understand what `define` actually represents. Starting with this release, passing non-string values such as with `define: { foo: false }` will no longer be allowed. You will now have to write `define: { foo: 'false' }` instead.
- Generate shorter data URLs if possible ([#1843](https://togithub.com/evanw/esbuild/issues/1843))
Loading a file with esbuild's `dataurl` loader generates a JavaScript module with a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs) for that file in a string as a single default export. Previously the data URLs generated by esbuild all used [base64 encoding](https://en.wikipedia.org/wiki/Base64). However, this is unnecessarily long for most textual data (e.g. SVG images). So with this release, esbuild's `dataurl` loader 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 the `base64` loader instead and then construct the data URL yourself.
- Avoid marking entry points as external ([#2382](https://togithub.com/evanw/esbuild/issues/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's `external` API parameter no longer applies to entry points so using `--external:*` is now possible.
One additional consequence of this change is that the `kind` parameter is now required when calling the `resolve()` function in esbuild's plugin API. Previously the `kind` parameter defaulted to `entry-point`, but that no longer interacts with `external` so it didn't seem wise for this to continue to be the default. You now have to specify `kind` so that the path resolution mode is explicit.
- Disallow non-`default` imports when `assert { type: 'json' }` is present
There is now standard behavior for importing a JSON file into an ES module using an `import` statement. However, it requires you to place the `assert { 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 the `Content-Type` HTTP header instead of by the file extension. The import assertion prevents security problems on the web where a `.json` file 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:
```js
import { version } from './package.json'
```
This is useful for tree-shaking when bundling because it means esbuild will only include the the `version` field of `package.json` in 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 adding `assert { type: 'json' }`). In a real JavaScript runtime the only thing you can import is the `default` import. So with this release, esbuild will now prevent you from importing non-`default` import names if `assert { type: 'json' }` is present. This ensures that code containing `assert { 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:
```js
import { version } from './package.json' assert { type: 'json' }
```
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 than `json`, which is required by the import assertion specification.
- Provide a way to disable automatic escaping of `` ([#2649](https://togithub.com/evanw/esbuild/issues/2649))
If you inject esbuild's output into a script tag in an HTML file, code containing the literal characters `` will cause the tag to be ended early which will break the code:
```html
");
```
To avoid this, esbuild automatically escapes these strings in generated JavaScript files (e.g. `""` becomes `"<\/script>"` instead). This also applies to `` 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 `platform` setting is set to `browser` (the default value). Setting `platform` to `node` or `neutral` will 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](https://togithub.com/evanw/esbuild/issues/2532))
If you run esbuild's JavaScript API in a broken JavaScript environment where `new TextEncoder().encode("") instanceof Uint8Array` is 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](https://jestjs.io/). 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 `@license` or `@preserve` and 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 `module` condition by default ([#2417](https://togithub.com/evanw/esbuild/issues/2417))
Package authors want to be able to use the new [`exports`](https://nodejs.org/api/packages.html#conditional-exports) field in `package.json` to 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 `import` and `require` export 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](https://nodejs.org/api/packages.html#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 `module` that 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=module` but 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 `module` condition when there aren't any custom `conditions` already configured. You can disable this with `--conditions=` or `conditions: []` (i.e. explicitly clearing all custom conditions).
- Rename the `master` branch to `main`
The primary branch for this repository was previously called `master` but is now called `main`. This change mirrors a similar change in many other projects.
- Remove esbuild's `_exit(0)` hack for WebAssembly ([#714](https://togithub.com/evanw/esbuild/issues/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](https://togithub.com/nodejs/node/issues/36616). This means cases where running `esbuild` should 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 `esbuild` command could just call `process.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's `exit(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-wasm` and you don't want the `esbuild` command 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](https://togithub.com/v8/v8/commit/bfe12807c14c91714c7db1485e6b265439375e16) enabled [dynamic tiering for WebAssembly](https://v8.dev/blog/wasm-dynamic-tiering) 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.
### [`v0.15.18`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#01518)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.17...v0.15.18)
- Performance improvements for both JS and CSS
This release brings noticeable performance improvements for JS parsing and for CSS parsing and printing. Here's an example benchmark for using esbuild to pretty-print a single large minified CSS file and JS file:
| Test case | Previous release | This release |
|----------------|------------------|--------------------|
| 4.8mb CSS file | 19ms | 11ms (1.7x faster) |
| 5.8mb JS file | 36ms | 32ms (1.1x faster) |
The performance improvements were very straightforward:
- Identifiers were being scanned using a generic character advancement function instead of using custom inline code. Advancing past each character involved UTF-8 decoding as well as updating multiple member variables. This was sped up using loop that skips UTF-8 decoding entirely and that only updates member variables once at the end. This is faster because identifiers are plain ASCII in the vast majority of cases, so Unicode decoding is almost always unnecessary.
- CSS identifiers and CSS strings were still being printed one character at a time. Apparently I forgot to move this part of esbuild's CSS infrastructure beyond the proof-of-concept stage. These were both very obvious in the profiler, so I think maybe I have just never profiled esbuild's CSS printing before?
- There was unnecessary work being done that was related to source maps when source map output was disabled. I likely haven't observed this before because esbuild's benchmarks always have source maps enabled. This work is now disabled when it's not going to be used.
I definitely should have caught these performance issues earlier. Better late than never I suppose.
### [`v0.15.17`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#01517)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.16...v0.15.17)
- Search for missing source map code on the file system ([#2711](https://togithub.com/evanw/esbuild/issues/2711))
[Source maps](https://sourcemaps.info/spec.html) are JSON files that map from compiled code back to the original code. They provide the original source code using two arrays: `sources` (required) and `sourcesContent` (optional). When bundling is enabled, esbuild is able to bundle code with source maps that was compiled by other tools (e.g. with Webpack) and emit source maps that map all the way back to the original code (e.g. before Webpack compiled it).
Previously if the input source maps omitted the optional `sourcesContent` array, esbuild would use `null` for the source content in the source map that it generates (since the source content isn't available). However, sometimes the original source code is actually still present on the file system. With this release, esbuild will now try to find the original source code using the path in the `sources` array and will use that instead of `null` if it was found.
- Fix parsing bug with TypeScript `infer` and `extends` ([#2712](https://togithub.com/evanw/esbuild/issues/2712))
This release fixes a bug where esbuild incorrectly failed to parse valid TypeScript code that nests `extends` inside `infer` inside `extends`, such as in the example below:
```ts
type A = {};
type B = {} extends infer T extends {} ? A : never;
```
TypeScript code that does this should now be parsed correctly.
- Use `WebAssembly.instantiateStreaming` if available ([#1036](https://togithub.com/evanw/esbuild/pull/1036), [#1900](https://togithub.com/evanw/esbuild/pull/1900))
Currently the WebAssembly version of esbuild uses `fetch` to download `esbuild.wasm` and then `WebAssembly.instantiate` to compile it. There is a newer API called `WebAssembly.instantiateStreaming` that both downloads and compiles at the same time, which can be a performance improvement if both downloading and compiling are slow. With this release, esbuild now attempts to use `WebAssembly.instantiateStreaming` and falls back to the original approach if that fails.
The implementation for this builds on a PR by [@lbwa](https://togithub.com/lbwa).
- Preserve Webpack comments inside constructor calls ([#2439](https://togithub.com/evanw/esbuild/issues/2439))
This improves the use of esbuild as a faster TypeScript-to-JavaScript frontend for Webpack, which has special [magic comments](https://webpack.js.org/api/module-methods/#magic-comments) inside `new Worker()` expressions that affect Webpack's behavior.
### [`v0.15.16`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#01516)
[Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.15...v0.15.16)
- Add a package alias feature ([#2191](https://togithub.com/evanw/esbuild/issues/2191))
With this release, you can now easily substitute one package for another at build time with the new `alias` feature. For example, `--alias:oldpkg=newpkg` replaces all imports of `oldpkg` with `newpkg`. One use case for this is easily replacing a node-only package with a browser-friendly package in 3rd-party code that you don't control. These new substitutions happen first before all of esbuild's existing path resolution logic.
Note that when an import path is substituted using an alias, the resulting import path is resolved in the working directory instead of in the directory containing the source file with the import path. If needed, the working directory can be set with the `cd` command when using the CLI or with the `absWorkingDir` setting when using the JS or Go APIs.
- Fix crash when pretty-printing minified JSX with object spread of object literal with computed property ([#2697](https://togithub.com/evanw/esbuild/issues/2697))
JSX elements are translated to JavaScript function calls and JSX element attributes are translated to properties on a JavaScript object literal. These properties are always either strings (e.g. in ``, `y` is a string) or an object spread (e.g. in ``, `y` is an object spread) because JSX doesn't provide syntax for directly passing a computed property as a JSX attribute. However, esbuild's minifier has a rule that tries to inline object spread with an inline object literal in JavaScript. For example, `x = { ...{ y } }` is minified to `x={y}` when minification is enabled. This means that there is a way to generate a non-string non-spread JSX attribute in esbuild's internal representation. One example is with ``. When minification is enabled, esbuild's internal representation of this is something like `` due to object spread inlining, which is not valid JSX syntax. If this internal representation is then pretty-printed as JSX using `--minify --jsx=preserve`, esbuild previously crashed when trying to print this invalid syntax. With this release, esbuild will now print `` in this scenario instead of crashing.
Microsoft/TypeScript
### [`v4.9.4`](https://togithub.com/microsoft/TypeScript/releases/tag/v4.9.4): TypeScript 4.9.4
[Compare Source](https://togithub.com/Microsoft/TypeScript/compare/v4.9.3...v4.9.4)
For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-4-9).
For the complete list of fixed issues, check out the
- [fixed issues query for Typescript v4.9.4](https://togithub.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+4.9.4%22+is%3Aclosed+).
Downloads are available on:
- [npm](https://www.npmjs.com/package/typescript)
- [NuGet package](https://www.nuget.org/packages/Microsoft.TypeScript.MSBuild)
##### Changes:
- [`e286821`](https://togithub.com/Microsoft/TypeScript/commit/e2868216f637e875a74c675845625eb15dcfe9a2) Bump version to 4.9.4 and LKG.
- [`eb5419f`](https://togithub.com/Microsoft/TypeScript/commit/eb5419fc8d980859b98553586dfb5f40d811a745) Cherry-pick [#51704](https://togithub.com/Microsoft/TypeScript/issues/51704) to release 4.9 ([#51712](https://togithub.com/Microsoft/TypeScript/issues/51712))
- [`b4d382b`](https://togithub.com/Microsoft/TypeScript/commit/b4d382b9b12460adf2da4cc0d1429cf19f8dc8be) Cherry-pick changes for narrowing to tagged literal types.
- [`e7a02f4`](https://togithub.com/Microsoft/TypeScript/commit/e7a02f43fce47e1a39259ada5460bcc33c8e98b5) Port of [#51626](https://togithub.com/Microsoft/TypeScript/issues/51626) and [#51689](https://togithub.com/Microsoft/TypeScript/issues/51689) to release-4.9 ([#51627](https://togithub.com/Microsoft/TypeScript/issues/51627))
- [`1727912`](https://togithub.com/Microsoft/TypeScript/commit/1727912f0437a7f367d90040fc4b0b4f3efd017a) Cherry-pick fix around `visitEachChild` to release-4.9. ([#51544](https://togithub.com/Microsoft/TypeScript/issues/51544))
This list of changes was [auto generated](https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/\_release?releaseId=117&\_a=release-summary).
Configuration
📅 Schedule: Branch creation - "before 3am on Monday" (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.
[ ] If you want to rebase/retry this PR, check this box
This PR has been generated by Mend Renovate. View repository job log here.
This PR contains the following updates:
4.3.0
->4.3.1
16.18.3
->16.18.6
0.15.15
->0.16.2
4.9.3
->4.9.4
Release Notes
evanw/esbuild
### [`v0.16.2`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0162) [Compare Source](https://togithub.com/evanw/esbuild/compare/v0.16.1...v0.16.2) - Fix `process.env.NODE_ENV` substitution when transforming ([#2718](https://togithub.com/evanw/esbuild/issues/2718)) Version 0.16.0 introduced an unintentional regression that caused `process.env.NODE_ENV` to be automatically substituted with either `"development"` or `"production"` when using esbuild's `transform` API. This substitution is a necessary feature of esbuild's `build` API because the React framework crashes when you bundle it without doing this. But the `transform` API 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 `platform` setting for the `transform` API from `neutral` to `browser`, both to align it with esbuild's documentation (which says `browser` is the default value) and because escaping the `` character sequence is now tied to the `browser` platform (see the release notes for version 0.16.0 for details). That accidentally enabled automatic substitution of `process.env.NODE_ENV` because esbuild always did that for code meant for the browser. To fix this regression, esbuild will now only automatically substitute `process.env.NODE_ENV` when using the `build` API. - Prevent `define` from substituting constants into assignment position ([#2719](https://togithub.com/evanw/esbuild/issues/2719)) The `define` feature lets you replace certain expressions with constants. For example, you could use it to replace references to the global property reference `window.DEBUG` with `false` at compile time, which can then potentially help esbuild remove unused code from your bundle. It's similar to [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) in Webpack. However, if you write code such as `window.DEBUG = true` and then defined `window.DEBUG` to `false`, esbuild previously generated the output `false = true` which is a syntax error in JavaScript. This behavior is not typically a problem because it doesn't make sense to substitute `window.DEBUG` with a constant if its value changes at run-time (Webpack's `DefinePlugin` also generates `false = true` in 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 `define` constants into assignment position to avoid generating code with a syntax error. Instead esbuild will generate a warning, which currently looks like this: ▲ [WARNING] Suspicious assignment to defined constant "window.DEBUG" [assign-to-define] example.js:1:0: 1 │ window.DEBUG = true ╵ ~~~~~~~~~~~~ The expression "window.DEBUG" has been configured to be replaced with a constant using the "define" feature. If this expression is supposed to be a compile-time constant, then it doesn't make sense to assign to it here. Or if this expression is supposed to change at run-time, this "define" substitution should be removed. - Fix a regression with `npm install --no-optional` ([#2720](https://togithub.com/evanw/esbuild/issues/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's `optionalDependencies` feature. However, if you deliberately disable this with `npm install --no-optional` then 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.1`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0161) [Compare Source](https://togithub.com/evanw/esbuild/compare/v0.16.0...v0.16.1) This is a hotfix for the previous release. - Re-allow importing JSON with the `copy` loader using an import assertion The previous release made it so when `assert { type: 'json' }` is present on an import statement, esbuild validated that the `json` loader was used. This is what an import assertion is supposed to do. However, I forgot about the relatively new `copy` loader, which sort of behaves as if the import path was marked as external (and thus not loaded at all) except that the file is copied to the output directory and the import path is rewritten to point to the copy. In this case whatever JavaScript runtime ends up running the code is the one to evaluate the import assertion. So esbuild should really allow this case as well. With this release, esbuild now allows both the `json` and `copy` loaders when an `assert { type: 'json' }` import assertion is present. ### [`v0.16.0`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#0160) [Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.18...v0.16.0) **This release deliberately contains backwards-incompatible changes.** To avoid automatically picking up releases like this, you should either be pinning the exact version of `esbuild` in your `package.json` file (recommended) or be using a version range syntax that only accepts patch upgrades such as `^0.15.0` or `~0.15.0`. See npm's documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. - Move all binary executable packages to the `@esbuild/` scope Binary package executables for esbuild are published as individual packages separate from the main `esbuild` package 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 the `os` and `cpu` names from node. The package name changes are as follows: - `@esbuild/linux-loong64` => `@esbuild/linux-loong64` (no change) - `esbuild-android-64` => `@esbuild/android-x64` - `esbuild-android-arm64` => `@esbuild/android-arm64` - `esbuild-darwin-64` => `@esbuild/darwin-x64` - `esbuild-darwin-arm64` => `@esbuild/darwin-arm64` - `esbuild-freebsd-64` => `@esbuild/freebsd-x64` - `esbuild-freebsd-arm64` => `@esbuild/freebsd-arm64` - `esbuild-linux-32` => `@esbuild/linux-ia32` - `esbuild-linux-64` => `@esbuild/linux-x64` - `esbuild-linux-arm` => `@esbuild/linux-arm` - `esbuild-linux-arm64` => `@esbuild/linux-arm64` - `esbuild-linux-mips64le` => `@esbuild/linux-mips64el` - `esbuild-linux-ppc64le` => `@esbuild/linux-ppc64` - `esbuild-linux-riscv64` => `@esbuild/linux-riscv64` - `esbuild-linux-s390x` => `@esbuild/linux-s390x` - `esbuild-netbsd-64` => `@esbuild/netbsd-x64` - `esbuild-openbsd-64` => `@esbuild/openbsd-x64` - `esbuild-sunos-64` => `@esbuild/sunos-x64` - `esbuild-wasm` => `esbuild-wasm` (no change) - `esbuild-windows-32` => `@esbuild/win32-ia32` - `esbuild-windows-64` => `@esbuild/win32-x64` - `esbuild-windows-arm64` => `@esbuild/win32-arm64` - `esbuild` => `esbuild` (no change) Normal usage of the `esbuild` and `esbuild-wasm` packages 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: ```sh curl -fsSL https://esbuild.github.io/dl/latest | sh ``` This runs a small shell script that downloads the latest `esbuild` binary executable to the current directory. This can be convenient on systems that don't have `npm` installed 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 of `latest`: ```sh curl -fsSL https://esbuild.github.io/dl/v0.16.0 | sh ``` Note 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` => `OutExtension` - `JSXMode` => `JSX` - Add 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 `define` parameter. 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 `define` parameter appears at first glance to take a JSON object if you aren't paying close attention, but this actually isn't true. Values for `define` are instead strings of JavaScript code. This means you have to use `define: { foo: '"bar"' }` to replace `foo` with the string `"bar"`. Using `define: { foo: 'bar' }` actually replaces `foo` with the identifier `bar`. Previously esbuild allowed you to pass `define: { foo: false }` and `false` was automatically converted into a string, which made it more confusing to understand what `define` actually represents. Starting with this release, passing non-string values such as with `define: { foo: false }` will no longer be allowed. You will now have to write `define: { foo: 'false' }` instead. - Generate shorter data URLs if possible ([#1843](https://togithub.com/evanw/esbuild/issues/1843)) Loading a file with esbuild's `dataurl` loader generates a JavaScript module with a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs) for that file in a string as a single default export. Previously the data URLs generated by esbuild all used [base64 encoding](https://en.wikipedia.org/wiki/Base64). However, this is unnecessarily long for most textual data (e.g. SVG images). So with this release, esbuild's `dataurl` loader 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 the `base64` loader instead and then construct the data URL yourself. - Avoid marking entry points as external ([#2382](https://togithub.com/evanw/esbuild/issues/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's `external` API parameter no longer applies to entry points so using `--external:*` is now possible. One additional consequence of this change is that the `kind` parameter is now required when calling the `resolve()` function in esbuild's plugin API. Previously the `kind` parameter defaulted to `entry-point`, but that no longer interacts with `external` so it didn't seem wise for this to continue to be the default. You now have to specify `kind` so that the path resolution mode is explicit. - Disallow non-`default` imports when `assert { type: 'json' }` is present There is now standard behavior for importing a JSON file into an ES module using an `import` statement. However, it requires you to place the `assert { 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 the `Content-Type` HTTP header instead of by the file extension. The import assertion prevents security problems on the web where a `.json` file 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: ```js import { version } from './package.json' ``` This is useful for tree-shaking when bundling because it means esbuild will only include the the `version` field of `package.json` in 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 adding `assert { type: 'json' }`). In a real JavaScript runtime the only thing you can import is the `default` import. So with this release, esbuild will now prevent you from importing non-`default` import names if `assert { type: 'json' }` is present. This ensures that code containing `assert { 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: ```js import { version } from './package.json' assert { type: 'json' } ``` 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 than `json`, which is required by the import assertion specification. - Provide a way to disable automatic escaping of `` ([#2649](https://togithub.com/evanw/esbuild/issues/2649)) If you inject esbuild's output into a script tag in an HTML file, code containing the literal characters `` will cause the tag to be ended early which will break the code: ```html "); ``` To avoid this, esbuild automatically escapes these strings in generated JavaScript files (e.g. `""` becomes `"<\/script>"` instead). This also applies to `` 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 `platform` setting is set to `browser` (the default value). Setting `platform` to `node` or `neutral` will 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](https://togithub.com/evanw/esbuild/issues/2532)) If you run esbuild's JavaScript API in a broken JavaScript environment where `new TextEncoder().encode("") instanceof Uint8Array` is 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](https://jestjs.io/). 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 `@license` or `@preserve` and 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 `module` condition by default ([#2417](https://togithub.com/evanw/esbuild/issues/2417)) Package authors want to be able to use the new [`exports`](https://nodejs.org/api/packages.html#conditional-exports) field in `package.json` to 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 `import` and `require` export 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](https://nodejs.org/api/packages.html#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 `module` that 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=module` but 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 `module` condition when there aren't any custom `conditions` already configured. You can disable this with `--conditions=` or `conditions: []` (i.e. explicitly clearing all custom conditions). - Rename the `master` branch to `main` The primary branch for this repository was previously called `master` but is now called `main`. This change mirrors a similar change in many other projects. - Remove esbuild's `_exit(0)` hack for WebAssembly ([#714](https://togithub.com/evanw/esbuild/issues/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](https://togithub.com/nodejs/node/issues/36616). This means cases where running `esbuild` should 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 `esbuild` command could just call `process.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's `exit(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-wasm` and you don't want the `esbuild` command 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](https://togithub.com/v8/v8/commit/bfe12807c14c91714c7db1485e6b265439375e16) enabled [dynamic tiering for WebAssembly](https://v8.dev/blog/wasm-dynamic-tiering) 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. ### [`v0.15.18`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#01518) [Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.17...v0.15.18) - Performance improvements for both JS and CSS This release brings noticeable performance improvements for JS parsing and for CSS parsing and printing. Here's an example benchmark for using esbuild to pretty-print a single large minified CSS file and JS file: | Test case | Previous release | This release | |----------------|------------------|--------------------| | 4.8mb CSS file | 19ms | 11ms (1.7x faster) | | 5.8mb JS file | 36ms | 32ms (1.1x faster) | The performance improvements were very straightforward: - Identifiers were being scanned using a generic character advancement function instead of using custom inline code. Advancing past each character involved UTF-8 decoding as well as updating multiple member variables. This was sped up using loop that skips UTF-8 decoding entirely and that only updates member variables once at the end. This is faster because identifiers are plain ASCII in the vast majority of cases, so Unicode decoding is almost always unnecessary. - CSS identifiers and CSS strings were still being printed one character at a time. Apparently I forgot to move this part of esbuild's CSS infrastructure beyond the proof-of-concept stage. These were both very obvious in the profiler, so I think maybe I have just never profiled esbuild's CSS printing before? - There was unnecessary work being done that was related to source maps when source map output was disabled. I likely haven't observed this before because esbuild's benchmarks always have source maps enabled. This work is now disabled when it's not going to be used. I definitely should have caught these performance issues earlier. Better late than never I suppose. ### [`v0.15.17`](https://togithub.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#01517) [Compare Source](https://togithub.com/evanw/esbuild/compare/v0.15.16...v0.15.17) - Search for missing source map code on the file system ([#2711](https://togithub.com/evanw/esbuild/issues/2711)) [Source maps](https://sourcemaps.info/spec.html) are JSON files that map from compiled code back to the original code. They provide the original source code using two arrays: `sources` (required) and `sourcesContent` (optional). When bundling is enabled, esbuild is able to bundle code with source maps that was compiled by other tools (e.g. with Webpack) and emit source maps that map all the way back to the original code (e.g. before Webpack compiled it). Previously if the input source maps omitted the optional `sourcesContent` array, esbuild would use `null` for the source content in the source map that it generates (since the source content isn't available). However, sometimes the original source code is actually still present on the file system. With this release, esbuild will now try to find the original source code using the path in the `sources` array and will use that instead of `null` if it was found. - Fix parsing bug with TypeScript `infer` and `extends` ([#2712](https://togithub.com/evanw/esbuild/issues/2712)) This release fixes a bug where esbuild incorrectly failed to parse valid TypeScript code that nests `extends` inside `infer` inside `extends`, such as in the example below: ```ts type AMicrosoft/TypeScript
### [`v4.9.4`](https://togithub.com/microsoft/TypeScript/releases/tag/v4.9.4): TypeScript 4.9.4 [Compare Source](https://togithub.com/Microsoft/TypeScript/compare/v4.9.3...v4.9.4) For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-4-9). For the complete list of fixed issues, check out the - [fixed issues query for Typescript v4.9.4](https://togithub.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+4.9.4%22+is%3Aclosed+). Downloads are available on: - [npm](https://www.npmjs.com/package/typescript) - [NuGet package](https://www.nuget.org/packages/Microsoft.TypeScript.MSBuild) ##### Changes: - [`e286821`](https://togithub.com/Microsoft/TypeScript/commit/e2868216f637e875a74c675845625eb15dcfe9a2) Bump version to 4.9.4 and LKG. - [`eb5419f`](https://togithub.com/Microsoft/TypeScript/commit/eb5419fc8d980859b98553586dfb5f40d811a745) Cherry-pick [#51704](https://togithub.com/Microsoft/TypeScript/issues/51704) to release 4.9 ([#51712](https://togithub.com/Microsoft/TypeScript/issues/51712)) - [`b4d382b`](https://togithub.com/Microsoft/TypeScript/commit/b4d382b9b12460adf2da4cc0d1429cf19f8dc8be) Cherry-pick changes for narrowing to tagged literal types. - [`e7a02f4`](https://togithub.com/Microsoft/TypeScript/commit/e7a02f43fce47e1a39259ada5460bcc33c8e98b5) Port of [#51626](https://togithub.com/Microsoft/TypeScript/issues/51626) and [#51689](https://togithub.com/Microsoft/TypeScript/issues/51689) to release-4.9 ([#51627](https://togithub.com/Microsoft/TypeScript/issues/51627)) - [`1727912`](https://togithub.com/Microsoft/TypeScript/commit/1727912f0437a7f367d90040fc4b0b4f3efd017a) Cherry-pick fix around `visitEachChild` to release-4.9. ([#51544](https://togithub.com/Microsoft/TypeScript/issues/51544)) This list of changes was [auto generated](https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/\_release?releaseId=117&\_a=release-summary).Configuration
📅 Schedule: Branch creation - "before 3am on Monday" (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.
This PR has been generated by Mend Renovate. View repository job log here.