Update dependency esbuild to v0.18.0 #7

Closed
inhji wants to merge 1 commits from renovate/esbuild-0.x into devel
Owner

This PR contains the following updates:

Package Type Update Change
esbuild devDependencies minor 0.14.47 -> 0.18.0

Release Notes

evanw/esbuild

v0.18.0

Compare 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 esbuild in your package.json file (recommended) or be using a version range syntax that only accepts patch upgrades such as ^0.17.0 or ~0.17.0. See npm's documentation about semver for more information.

The breaking changes in this release mainly focus on fixing some long-standing issues with esbuild's handling of tsconfig.json files. Here are all the changes in this release, in detail:

  • Add a way to try esbuild online (#​797)

    There is now a way to try esbuild live on esbuild's website without installing it: https://esbuild.github.io/try/. In addition to being able to more easily evaluate esbuild, this should also make it more efficient to generate esbuild bug reports. For example, you can use it to compare the behavior of different versions of esbuild on the same input. The state of the page is stored in the URL for easy sharing. Many thanks to @​hyrious for creating https://hyrious.me/esbuild-repl/, which was the main inspiration for this addition to esbuild's website.

    Two forms of build options are supported: either CLI-style (example) or JS-style (example). Both are converted into a JS object that's passed to esbuild's WebAssembly API. The CLI-style argument parser is a custom one that simulates shell quoting rules, and the JS-style argument parser is also custom and parses a superset of JSON (basically JSON5 + regular expressions). So argument parsing is an approximate simulation of what happens for real but hopefully it should be close enough.

  • Changes to esbuild's tsconfig.json support (#​3019):

    This release makes the following changes to esbuild's tsconfig.json support:

    • Using experimental decorators now requires "experimentalDecorators": true (#​104)

      Previously esbuild would always compile decorators in TypeScript code using TypeScript's experimental decorator transform. Now that standard JavaScript decorators are close to being finalized, esbuild will now require you to use "experimentalDecorators": true to do this. This new requirement makes it possible for esbuild to introduce a transform for standard JavaScript decorators in TypeScript code in the future. Such a transform has not been implemented yet, however.

    • TypeScript's target no longer affects esbuild's target (#​2628)

      Some people requested that esbuild support TypeScript's target setting, so support for it was added (in version 0.12.4). However, esbuild supports reading from multiple tsconfig.json files within a single build, which opens up the possibility that different files in the build have different language targets configured. There isn't really any reason to do this and it can lead to unexpected results. So with this release, the target setting in tsconfig.json will no longer affect esbuild's own target setting. You will have to use esbuild's own target setting instead (which is a single, global value).

    • TypeScript's jsx setting no longer causes esbuild to preserve JSX syntax (#​2634)

      TypeScript has a setting called jsx that controls how to transform JSX into JS. The tool-agnostic transform is called react, and the React-specific transform is called react-jsx (or react-jsxdev). There is also a setting called preserve which indicates JSX should be passed through untransformed. Previously people would run esbuild with "jsx": "preserve" in their tsconfig.json files and then be surprised when esbuild preserved their JSX. So with this release, esbuild will now ignore "jsx": "preserve" in tsconfig.json files. If you want to preserve JSX syntax with esbuild, you now have to use --jsx=preserve.

      Note: Some people have suggested that esbuild's equivalent jsx setting override the one in tsconfig.json. However, some projects need to legitimately have different files within the same build use different transforms (i.e. react vs. react-jsx) and having esbuild's global jsx setting override tsconfig.json would prevent this from working. This release ignores "jsx": "preserve" but still allows other jsx values in tsconfig.json files to override esbuild's global jsx setting to keep the ability for multiple files within the same build to use different transforms.

    • useDefineForClassFields behavior has changed (#​2584, #​2993)

      Class fields in TypeScript look like this (x is a class field):

      class Foo {
        x = 123
      }
      

      TypeScript has legacy behavior that uses assignment semantics instead of define semantics for class fields when useDefineForClassFields is enabled (in which case class fields in TypeScript behave differently than they do in JavaScript, which is arguably "wrong").

      This legacy behavior exists because TypeScript added class fields to TypeScript before they were added to JavaScript. The TypeScript team decided to go with assignment semantics and shipped their implementation. Much later on TC39 decided to go with define semantics for class fields in JavaScript instead. This behaves differently if the base class has a setter with the same name:

      class Base {
        set x(_) {
          console.log('x:', _)
        }
      }
      
      // useDefineForClassFields: false
      class AssignSemantics extends Base {
        constructor() {
          super()
          this.x = 123
        }
      }
      
      // useDefineForClassFields: true
      class DefineSemantics extends Base {
        constructor() {
          super()
          Object.defineProperty(this, 'x', { value: 123 })
        }
      }
      
      console.log(
        new AssignSemantics().x, // Calls the setter
        new DefineSemantics().x // Doesn't call the setter
      )
      

      When you run tsc, the value of useDefineForClassFields defaults to false when it's not specified and the target in tsconfig.json is present but earlier than ES2022. This sort of makes sense because the class field language feature was added in ES2022, so before ES2022 class fields didn't exist (and thus TypeScript's legacy behavior is active). However, TypeScript's target setting currently defaults to ES3 which unfortunately means that the useDefineForClassFields setting currently defaults to false (i.e. to "wrong"). In other words if you run tsc with all default settings, class fields will behave incorrectly.

      Previously esbuild tried to do what tsc did. That meant esbuild's version of useDefineForClassFields was false by default, and was also false if esbuild's --target= was present but earlier than es2022. However, TypeScript's legacy class field behavior is becoming increasingly irrelevant and people who expect class fields in TypeScript to work like they do in JavaScript are confused when they use esbuild with default settings. It's also confusing that the behavior of class fields would change if you changed the language target (even though that's exactly how TypeScript works).

      So with this release, esbuild will now only use the information in tsconfig.json to determine whether useDefineForClassFields is true or not. Specifically useDefineForClassFields will be respected if present, otherwise it will be false if target is present in tsconfig.json and is ES2021 or earlier, otherwise it will be true. Targets passed to esbuild's --target= setting will no longer affect useDefineForClassFields.

      Note that this means different directories in your build can have different values for this setting since esbuild allows different directories to have different tsconfig.json files within the same build. This should let you migrate your code one directory at a time without esbuild's --target= setting affecting the semantics of your code.

    • Add support for verbatimModuleSyntax from TypeScript 5.0

      TypeScript 5.0 added a new option called verbatimModuleSyntax that deprecates and replaces two older options, preserveValueImports and importsNotUsedAsValues. Setting verbatimModuleSyntax to true in tsconfig.json tells esbuild to not drop unused import statements. Specifically esbuild now treats "verbatimModuleSyntax": true as if you had specified both "preserveValueImports": true and "importsNotUsedAsValues": "preserve".

    • Add multiple inheritance for tsconfig.json from TypeScript 5.0

      TypeScript 5.0 now allows multiple inheritance for tsconfig.json files. You can now pass an array of filenames via the extends parameter and your tsconfig.json will start off containing properties from all of those configuration files, in order. This release of esbuild adds support for this new TypeScript feature.

    • Remove support for moduleSuffixes (#​2395)

      The community has requested that esbuild remove support for TypeScript's moduleSuffixes feature, so it has been removed in this release. Instead you can use esbuild's --resolve-extensions= feature to select which module suffix you want to build with.

    • Apply --tsconfig= overrides to stdin and virtual files (#​385, #​2543)

      When you override esbuild's automatic tsconfig.json file detection with --tsconfig= to pass a specific tsconfig.json file, esbuild previously didn't apply these settings to source code passed via the stdin API option or to TypeScript files from plugins that weren't in the file namespace. This release changes esbuild's behavior so that settings from tsconfig.json also apply to these source code files as well.

    • Support --tsconfig-raw= in build API calls (#​943, #​2440)

      Previously if you wanted to override esbuild's automatic tsconfig.json file detection, you had to create a new tsconfig.json file and pass the file name to esbuild via the --tsconfig= flag. With this release, you can now optionally use --tsconfig-raw= instead to pass the contents of tsconfig.json to esbuild directly instead of passing the file name. For example, you can now use --tsconfig-raw={"compilerOptions":{"experimentalDecorators":true}} to enable TypeScript experimental decorators directly using a command-line flag (assuming you escape the quotes correctly using your current shell's quoting rules). The --tsconfig-raw= flag previously only worked with transform API calls but with this release, it now works with build API calls too.

    • Ignore all tsconfig.json files in node_modules (#​276, #​2386)

      This changes esbuild's behavior that applies tsconfig.json to all files in the subtree of the directory containing tsconfig.json. In version 0.12.7, esbuild started ignoring tsconfig.json files inside node_modules folders. The rationale is that people typically do this by mistake and that doing this intentionally is a rare use case that doesn't need to be supported. However, this change only applied to certain syntax-specific settings (e.g. jsxFactory) but did not apply to path resolution settings (e.g. paths). With this release, esbuild will now ignore all tsconfig.json files in node_modules instead of only ignoring certain settings.

    • Ignore tsconfig.json when resolving paths within node_modules (#​2481)

      Previously fields in tsconfig.json related to path resolution (e.g. paths) were respected for all files in the subtree containing that tsconfig.json file, even within a nested node_modules subdirectory. This meant that a project's paths settings could potentially affect any bundled packages. With this release, esbuild will no longer use tsconfig.json settings during path resolution inside nested node_modules subdirectories.

    • Prefer .js over .ts within node_modules (#​3019)

      The default list of implicit extensions that esbuild will try appending to import paths contains .ts before .js. This makes it possible to bundle TypeScript projects that reference other files in the project using extension-less imports (e.g. ./some-file to load ./some-file.ts instead of ./some-file.js). However, this behavior is undesirable within node_modules directories. Some package authors publish both their original TypeScript code and their compiled JavaScript code side-by-side. In these cases, esbuild should arguably be using the compiled JavaScript files instead of the original TypeScript files because the TypeScript compilation settings for files within the package should be determined by the package author, not the user of esbuild. So with this release, esbuild will now prefer implicit .js extensions over .ts when searching for import paths within node_modules.

    These changes are intended to improve esbuild's compatibility with tsc and reduce the number of unfortunate behaviors regarding tsconfig.json and esbuild.

  • Add a workaround for bugs in Safari 16.2 and earlier (#​3072)

    Safari's JavaScript parser had a bug (which has now been fixed) where at least something about unary/binary operators nested inside default arguments nested inside either a function or class expression was incorrectly considered a syntax error if that expression was the target of a property assignment. Here are some examples that trigger this Safari bug:

    ❱ x(function (y = -1) {}.z = 2)
    SyntaxError: Left hand side of operator '=' must be a reference.
    
    ❱ x(class { f(y = -1) {} }.z = 2)
    SyntaxError: Left hand side of operator '=' must be a reference.
    

    It's not clear what the exact conditions are that trigger this bug. However, a workaround for this bug appears to be to post-process your JavaScript to wrap any in function and class declarations that are the direct target of a property access expression in parentheses. That's the workaround that UglifyJS applies for this issue: mishoo/UglifyJS#​2056. So that's what esbuild now does starting with this release:

    // Original code
    x(function (y = -1) {}.z = 2, class { f(y = -1) {} }.z = 2)
    
    // Old output (with --minify --target=safari16.2)
    x(function(c=-1){}.z=2,class{f(c=-1){}}.z=2);
    
    // New output (with --minify --target=safari16.2)
    x((function(c=-1){}).z=2,(class{f(c=-1){}}).z=2);
    

    This fix is not enabled by default. It's only enabled when --target= contains Safari 16.2 or earlier, such as with --target=safari16.2. You can also explicitly enable or disable this specific transform (called function-or-class-property-access) with --supported:function-or-class-property-access=false.

  • Fix esbuild's TypeScript type declarations to forbid unknown properties (#​3089)

    Version 0.17.0 of esbuild introduced a specific form of function overloads in the TypeScript type definitions for esbuild's API calls that looks like this:

    interface TransformOptions {
      legalComments?: 'none' | 'inline' | 'eof' | 'external'
    }
    
    interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> {
      legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined)
    }
    
    declare function transformSync<ProvidedOptions extends TransformOptions>(input: string, options?: ProvidedOptions): TransformResult<ProvidedOptions>
    declare function transformSync(input: string, options?: TransformOptions): TransformResult
    

    This more accurately reflects how esbuild's JavaScript API behaves. The result object returned by transformSync only has the legalComments property if you pass legalComments: 'external':

    // These have type "string | undefined"
    transformSync('').legalComments
    transformSync('', { legalComments: 'eof' }).legalComments
    
    // This has type "string"
    transformSync('', { legalComments: 'external' }).legalComments
    

    However, this form of function overloads unfortunately allows typos (e.g. egalComments) to pass the type checker without generating an error as TypeScript allows all objects with unknown properties to extend TransformOptions. These typos result in esbuild's API throwing an error at run-time.

    To prevent typos during type checking, esbuild's TypeScript type definitions will now use a different form that looks like this:

    type SameShape<Out, In extends Out> = In & { [Key in Exclude<keyof In, keyof Out>]: never }
    
    interface TransformOptions {
      legalComments?: 'none' | 'inline' | 'eof' | 'external'
    }
    
    interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> {
      legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined)
    }
    
    declare function transformSync<T extends TransformOptions>(input: string, options?: SameShape<TransformOptions, T>): TransformResult<T>
    

    This change should hopefully not affect correct code. It should hopefully introduce type errors only for incorrect code.

  • Fix CSS nesting transform for pseudo-elements (#​3119)

    This release fixes esbuild's CSS nesting transform for pseudo-elements (e.g. ::before and ::after). The CSS nesting specification says that the nesting selector does not work with pseudo-elements. This can be seen in the example below: esbuild does not carry the parent pseudo-element ::before through the nesting selector &. However, that doesn't apply to pseudo-elements that are within the same selector. Previously esbuild had a bug where it considered pseudo-elements in both locations as invalid. This release changes esbuild to only consider those from the parent selector invalid, which should align with the specification:

    /* Original code */
    a, b::before {
      &.c, &::after {
        content: 'd';
      }
    }
    
    /* Old output (with --target=chrome90) */
    a:is(.c, ::after) {
      content: "d";
    }
    
    /* New output (with --target=chrome90) */
    a.c,
    a::after {
      content: "d";
    }
    
  • Forbid & before a type selector in nested CSS

    The people behind the work-in-progress CSS nesting specification have very recently decided to forbid nested CSS that looks like &div. You will have to use either div& or &:is(div) instead. This release of esbuild has been updated to take this new change into consideration. Doing this now generates a warning. The suggested fix is slightly different depending on where in the overall selector it happened:

    ▲ [WARNING] Cannot use type selector "input" directly after nesting selector "&" [css-syntax-error]
    
        example.css:2:3:
          2 │   &input {
            │    ~~~~~
            ╵    :is(input)
    
      CSS nesting syntax does not allow the "&" selector to come before a type selector. You can wrap
      this selector in ":is()" as a workaround. This restriction exists to avoid problems with SASS
      nesting, where the same syntax means something very different that has no equivalent in real CSS
      (appending a suffix to the parent selector).
    
    ▲ [WARNING] Cannot use type selector "input" directly after nesting selector "&" [css-syntax-error]
    
        example.css:6:8:
          6 │   .form &input {
            │         ~~~~~~
            ╵         input&
    
      CSS nesting syntax does not allow the "&" selector to come before a type selector. You can move
      the "&" to the end of this selector as a workaround. This restriction exists to avoid problems
      with SASS nesting, where the same syntax means something very different that has no equivalent in
      real CSS (appending a suffix to the parent selector).
    

v0.17.19

Compare Source

  • Fix CSS transform bugs with nested selectors that start with a combinator (#​3096)

    This release fixes several bugs regarding transforming nested CSS into non-nested CSS for older browsers. The bugs were due to lack of test coverage for nested selectors with more than one compound selector where they all start with the same combinator. Here's what some problematic cases look like before and after these fixes:

    /* Original code */
    .foo {
      > &a,
      > &b {
        color: red;
      }
    }
    .bar {
      > &a,
      + &b {
        color: green;
      }
    }
    
    /* Old output (with --target=chrome90) */
    .foo :is(> .fooa, > .foob) {
      color: red;
    }
    .bar :is(> .bara, + .barb) {
      color: green;
    }
    
    /* New output (with --target=chrome90) */
    .foo > :is(a.foo, b.foo) {
      color: red;
    }
    .bar > a.bar,
    .bar + b.bar {
      color: green;
    }
    
  • Fix bug with TypeScript parsing of instantiation expressions followed by = (#​3111)

    This release fixes esbuild's TypeScript-to-JavaScript conversion code in the case where a potential instantiation expression is followed immediately by a = token (such that the trailing > becomes a >= token). Previously esbuild considered that to still be an instantiation expression, but the official TypeScript compiler considered it to be a >= operator instead. This release changes esbuild's interpretation to match TypeScript. This edge case currently appears to be problematic for other TypeScript-to-JavaScript converters as well:

    Original code TypeScript esbuild 0.17.18 esbuild 0.17.19 Sucrase Babel
    x<y>=a<b<c>>() x<y>=a(); x=a(); x<y>=a(); x=a() Invalid left-hand side in assignment expression
  • Avoid removing unrecognized directives from the directive prologue when minifying (#​3115)

    The directive prologue in JavaScript is a sequence of top-level string expressions that come before your code. The only directives that JavaScript engines currently recognize are use strict and sometimes use asm. However, the people behind React have made up their own directive for their own custom dialect of JavaScript. Previously esbuild only preserved the use strict directive when minifying, although you could still write React JavaScript with esbuild using something like --banner:js="'your directive here';". With this release, you can now put arbitrary directives in the entry point and esbuild will preserve them in its minified output:

    // Original code
    'use wtf'; console.log(123)
    
    // Old output (with --minify)
    console.log(123);
    
    // New output (with --minify)
    "use wtf";console.log(123);
    

    Note that this means esbuild will no longer remove certain stray top-level strings when minifying. This behavior is an intentional change because these stray top-level strings are actually part of the directive prologue, and could potentially have semantics assigned to them (as was the case with React).

  • Improved minification of binary shift operators

    With this release, esbuild's minifier will now evaluate the << and >>> operators if the resulting code would be shorter:

    // Original code
    console.log(10 << 10, 10 << 20, -123 >>> 5, -123 >>> 10);
    
    // Old output (with --minify)
    console.log(10<<10,10<<20,-123>>>5,-123>>>10);
    
    // New output (with --minify)
    console.log(10240,10<<20,-123>>>5,4194303);
    

v0.17.18

Compare Source

  • Fix non-default JSON import error with export {} from (#​3070)

    This release fixes a bug where esbuild incorrectly identified statements of the form export { default as x } from "y" assert { type: "json" } as a non-default import. The bug did not affect code of the form import { default as x } from ... (only code that used the export keyword).

  • Fix a crash with an invalid subpath import (#​3067)

    Previously esbuild could crash when attempting to generate a friendly error message for an invalid subpath import (i.e. an import starting with #). This happened because esbuild originally only supported the exports field and the code for that error message was not updated when esbuild later added support for the imports field. This crash has been fixed.

v0.17.17

Compare Source

  • Fix CSS nesting transform for top-level & (#​3052)

    Previously esbuild could crash with a stack overflow when lowering CSS nesting rules with a top-level &, such as in the code below. This happened because esbuild's CSS nesting transform didn't handle top-level &, causing esbuild to inline the top-level selector into itself. This release handles top-level & by replacing it with the :scope pseudo-class:

    /* Original code */
    &,
    a {
      .b {
        color: red;
      }
    }
    
    /* New output (with --target=chrome90) */
    :is(:scope, a) .b {
      color: red;
    }
    
  • Support exports in package.json for extends in tsconfig.json (#​3058)

    TypeScript 5.0 added the ability to use extends in tsconfig.json to reference a path in a package whose package.json file contains an exports map that points to the correct location. This doesn't automatically work in esbuild because tsconfig.json affects esbuild's path resolution, so esbuild's normal path resolution logic doesn't apply.

    This release adds support for doing this by adding some additional code that attempts to resolve the extends path using the exports field. The behavior should be similar enough to esbuild's main path resolution logic to work as expected.

    Note that esbuild always treats this extends import as a require() import since that's what TypeScript appears to do. Specifically the require condition will be active and the import condition will be inactive.

  • Fix watch mode with NODE_PATH (#​3062)

    Node has a rarely-used feature where you can extend the set of directories that node searches for packages using the NODE_PATH environment variable. While esbuild supports this too, previously a bug prevented esbuild's watch mode from picking up changes to imported files that were contained directly in a NODE_PATH directory. You're supposed to use NODE_PATH for packages, but some people abuse this feature by putting files in that directory instead (e.g. node_modules/some-file.js instead of node_modules/some-pkg/some-file.js). The watch mode bug happens when you do this because esbuild first tries to read some-file.js as a directory and then as a file. Watch mode was incorrectly waiting for some-file.js to become a valid directory. This release fixes this edge case bug by changing watch mode to watch some-file.js as a file when this happens.

v0.17.16

Compare Source

  • Fix CSS nesting transform for triple-nested rules that start with a combinator (#​3046)

    This release fixes a bug with esbuild where triple-nested CSS rules that start with a combinator were not transformed correctly for older browsers. Here's an example of such a case before and after this bug fix:

    /* Original input */
    .a {
      color: red;
      > .b {
        color: green;
        > .c {
          color: blue;
        }
      }
    }
    
    /* Old output (with --target=chrome90) */
    .a {
      color: red;
    }
    .a > .b {
      color: green;
    }
    .a .b > .c {
      color: blue;
    }
    
    /* New output (with --target=chrome90) */
    .a {
      color: red;
    }
    .a > .b {
      color: green;
    }
    .a > .b > .c {
      color: blue;
    }
    
  • Support --inject with a file loaded using the copy loader (#​3041)

    This release now allows you to use --inject with a file that is loaded using the copy loader. The copy loader copies the imported file to the output directory verbatim and rewrites the path in the import statement to point to the copied output file. When used with --inject, this means the injected file will be copied to the output directory as-is and a bare import statement for that file will be inserted in any non-copy output files that esbuild generates.

    Note that since esbuild doesn't parse the contents of copied files, esbuild will not expose any of the export names as usable imports when you do this (in the way that esbuild's --inject feature is typically used). However, any side-effects that the injected file has will still occur.

v0.17.15

Compare Source

  • Allow keywords as type parameter names in mapped types (#​3033)

    TypeScript allows type keywords to be used as parameter names in mapped types. Previously esbuild incorrectly treated this as an error. Code that does this is now supported:

    type Foo = 'a' | 'b' | 'c'
    type A = { [keyof in Foo]: number }
    type B = { [infer in Foo]: number }
    type C = { [readonly in Foo]: number }
    
  • Add annotations for re-exported modules in node (#​2486, #​3029)

    Node lets you import named imports from a CommonJS module using ESM import syntax. However, the allowed names aren't derived from the properties of the CommonJS module. Instead they are derived from an arbitrary syntax-only analysis of the CommonJS module's JavaScript AST.

    To accommodate node doing this, esbuild's ESM-to-CommonJS conversion adds a special non-executable "annotation" for node that describes the exports that node should expose in this scenario. It takes the form 0 && (module.exports = { ... }) and comes at the end of the file (0 && expr means expr is never evaluated).

    Previously esbuild didn't do this for modules re-exported using the export * from syntax. Annotations for these re-exports will now be added starting with this release:

    // Original input
    export { foo } from './foo'
    export * from './bar'
    
    // Old output (with --format=cjs --platform=node)
    ...
    0 && (module.exports = {
      foo
    });
    
    // New output (with --format=cjs --platform=node)
    ...
    0 && (module.exports = {
      foo,
      ...require("./bar")
    });
    

    Note that you need to specify both --format=cjs and --platform=node to get these node-specific annotations.

  • Avoid printing an unnecessary space in between a number and a . (#​3026)

    JavaScript typically requires a space in between a number token and a . token to avoid the . being interpreted as a decimal point instead of a member expression. However, this space is not required if the number token itself contains a decimal point, an exponent, or uses a base other than 10. This release of esbuild now avoids printing the unnecessary space in these cases:

    // Original input
    foo(1000 .x, 0 .x, 0.1 .x, 0.0001 .x, 0xFFFF_0000_FFFF_0000 .x)
    
    // Old output (with --minify)
    foo(1e3 .x,0 .x,.1 .x,1e-4 .x,0xffff0000ffff0000 .x);
    
    // New output (with --minify)
    foo(1e3.x,0 .x,.1.x,1e-4.x,0xffff0000ffff0000.x);
    
  • Fix server-sent events with live reload when writing to the file system root (#​3027)

    This release fixes a bug where esbuild previously failed to emit server-sent events for live reload when outdir was the file system root, such as /. This happened because / is the only path on Unix that cannot have a trailing slash trimmed from it, which was fixed by improved path handling.

v0.17.14

Compare Source

  • Allow the TypeScript 5.0 const modifier in object type declarations (#​3021)

    The new TypeScript 5.0 const modifier was added to esbuild in version 0.17.5, and works with classes, functions, and arrow expressions. However, support for it wasn't added to object type declarations (e.g. interfaces) due to an oversight. This release adds support for these cases, so the following TypeScript 5.0 code can now be built with esbuild:

    interface Foo { <const T>(): T }
    type Bar = { new <const T>(): T }
    
  • Implement preliminary lowering for CSS nesting (#​1945)

    Chrome has implemented the new CSS nesting specification in version 112, which is currently in beta but will become stable very soon. So CSS nesting is now a part of the web platform!

    This release of esbuild can now transform nested CSS syntax into non-nested CSS syntax for older browsers. The transformation relies on the :is() pseudo-class in many cases, so the transformation is only guaranteed to work when targeting browsers that support :is() (e.g. Chrome 88+). You'll need to set esbuild's target to the browsers you intend to support to tell esbuild to do this transformation. You will get a warning if you use CSS nesting syntax with a target which includes older browsers that don't support :is().

    The lowering transformation looks like this:

    /* Original input */
    a.btn {
      color: #&#8203;333;
      &:hover { color: #&#8203;444 }
      &:active { color: #&#8203;555 }
    }
    
    /* New output (with --target=chrome88) */
    a.btn {
      color: #&#8203;333;
    }
    a.btn:hover {
      color: #&#8203;444;
    }
    a.btn:active {
      color: #&#8203;555;
    }
    

    More complex cases may generate the :is() pseudo-class:

    /* Original input */
    div, p {
      .warning, .error {
        padding: 20px;
      }
    }
    
    /* New output (with --target=chrome88) */
    :is(div, p) :is(.warning, .error) {
      padding: 20px;
    }
    

    In addition, esbuild now has a special warning message for nested style rules that start with an identifier. This isn't allowed in CSS because the syntax would be ambiguous with the existing declaration syntax. The new warning message looks like this:

    ▲ [WARNING] A nested style rule cannot start with "p" because it looks like the start of a declaration [css-syntax-error]
    
        <stdin>:1:7:
          1 │ main { p { margin: auto } }
            │        ^
            ╵        :is(p)
    
      To start a nested style rule with an identifier, you need to wrap the identifier in ":is(...)" to
      prevent the rule from being parsed as a declaration.
    

    Keep in mind that the transformation in this release is a preliminary implementation. CSS has many features that interact in complex ways, and there may be some edge cases that don't work correctly yet.

  • Minification now removes unnecessary & CSS nesting selectors

    This release introduces the following CSS minification optimizations:

    /* Original input */
    a {
      font-weight: bold;
      & {
        color: blue;
      }
      & :hover {
        text-decoration: underline;
      }
    }
    
    /* Old output (with --minify) */
    a{font-weight:700;&{color:#&#8203;00f}& :hover{text-decoration:underline}}
    
    /* New output (with --minify) */
    a{font-weight:700;:hover{text-decoration:underline}color:#&#8203;00f}
    
  • Minification now removes duplicates from CSS selector lists

    This release introduces the following CSS minification optimization:

    /* Original input */
    div, div { color: red }
    
    /* Old output (with --minify) */
    div,div{color:red}
    
    /* New output (with --minify) */
    div{color:red}
    

v0.17.13

Compare Source

  • Work around an issue with NODE_PATH and Go's WebAssembly internals (#​3001)

    Go's WebAssembly implementation returns EINVAL instead of ENOTDIR when using the readdir syscall on a file. This messes up esbuild's implementation of node's module resolution algorithm since encountering ENOTDIR causes esbuild to continue its search (since it's a normal condition) while other encountering other errors causes esbuild to fail with an I/O error (since it's an unexpected condition). You can encounter this issue in practice if you use node's legacy NODE_PATH feature to tell esbuild to resolve node modules in a custom directory that was not installed by npm. This release works around this problem by converting EINVAL into ENOTDIR for the readdir syscall.

  • Fix a minification bug with CSS @layer rules that have parsing errors (#​3016)

    CSS at-rules require either a {} block or a semicolon at the end. Omitting both of these causes esbuild to treat the rule as an unknown at-rule. Previous releases of esbuild had a bug that incorrectly removed unknown at-rules without any children during minification if the at-rule token matched an at-rule that esbuild can handle. Specifically cssnano can generate @layer rules with parsing errors, and empty @layer rules cannot be removed because they have side effects (@layer didn't exist when esbuild's CSS support was added, so esbuild wasn't written to handle this). This release changes esbuild to no longer discard @layer rules with parsing errors when minifying (the rule @layer c has a parsing error):

    /* Original input */
    @&#8203;layer a {
      @&#8203;layer b {
        @&#8203;layer c
      }
    }
    
    /* Old output (with --minify) */
    @&#8203;layer a.b;
    
    /* New output (with --minify) */
    @&#8203;layer a.b.c;
    
  • Unterminated strings in CSS are no longer an error

    The CSS specification provides rules for handling parsing errors. One of those rules is that user agents must close strings upon reaching the end of a line (i.e., before an unescaped line feed, carriage return or form feed character), but then drop the construct (declaration or rule) in which the string was found. For example:

    p {
      color: green;
      font-family: 'Courier New Times
      color: red;
      color: green;
    }
    

    ...would be treated the same as:

    p { color: green; color: green; }
    

    ...because the second declaration (from font-family to the semicolon after color: red) is invalid and is dropped.

    Previously using this CSS with esbuild failed to build due to a syntax error, even though the code can be interpreted by a browser. With this release, the code now produces a warning instead of an error, and esbuild prints the invalid CSS such that it stays invalid in the output:

    /* esbuild's new non-minified output: */
    p {
      color: green;
      font-family: 'Courier New Times
      color: red;
      color: green;
    }
    
    /* esbuild's new minified output: */
    p{font-family:'Courier New Times
    color: red;color:green}
    

v0.17.12

Compare Source

  • Fix a crash when parsing inline TypeScript decorators (#​2991)

    Previously esbuild's TypeScript parser crashed when parsing TypeScript decorators if the definition of the decorator was inlined into the decorator itself:

    @&#8203;(function sealed(constructor: Function) {
      Object.seal(constructor);
      Object.seal(constructor.prototype);
    })
    class Foo {}
    

    This crash was not noticed earlier because this edge case did not have test coverage. The crash is fixed in this release.

v0.17.11

Compare Source

  • Fix the alias feature to always prefer the longest match (#​2963)

    It's possible to configure conflicting aliases such as --alias:a=b and --alias:a/c=d, which is ambiguous for the import path a/c/x (since it could map to either b/c/x or d/x). Previously esbuild would pick the first matching alias, which would non-deterministically pick between one of the possible matches. This release fixes esbuild to always deterministically pick the longest possible match.

  • Minify calls to some global primitive constructors (#​2962)

    With this release, esbuild's minifier now replaces calls to Boolean/Number/String/BigInt with equivalent shorter code when relevant:

    // Original code
    console.log(
      Boolean(a ? (b | c) !== 0 : (c & d) !== 0),
      Number(e ? '1' : '2'),
      String(e ? '1' : '2'),
      BigInt(e ? 1n : 2n),
    )
    
    // Old output (with --minify)
    console.log(Boolean(a?(b|c)!==0:(c&d)!==0),Number(e?"1":"2"),String(e?"1":"2"),BigInt(e?1n:2n));
    
    // New output (with --minify)
    console.log(!!(a?b|c:c&d),+(e?"1":"2"),e?"1":"2",e?1n:2n);
    
  • Adjust some feature compatibility tables for node (#​2940)

    This release makes the following adjustments to esbuild's internal feature compatibility tables for node, which tell esbuild which versions of node are known to support all aspects of that feature:

    • class-private-brand-checks: node v16.9+ => node v16.4+ (a decrease)
    • hashbang: node v12.0+ => node v12.5+ (an increase)
    • optional-chain: node v16.9+ => node v16.1+ (a decrease)
    • template-literal: node v4+ => node v10+ (an increase)

    Each of these adjustments was identified by comparing against data from the node-compat-table package and was manually verified using old node executables downloaded from https://nodejs.org/download/release/.

v0.17.10

Compare Source

  • Update esbuild's handling of CSS nesting to match the latest specification changes (#​1945)

    The syntax for the upcoming CSS nesting feature has recently changed. The @nest prefix that was previously required in some cases is now gone, and nested rules no longer have to start with & (as long as they don't start with an identifier or function token).

    This release updates esbuild's pass-through handling of CSS nesting syntax to match the latest specification changes. So you can now use esbuild to bundle CSS containing nested rules and try them out in a browser that supports CSS nesting (which includes nightly builds of both Chrome and Safari).

    However, I'm not implementing lowering of nested CSS to non-nested CSS for older browsers yet. While the syntax has been decided, the semantics are still in flux. In particular, there is still some debate about changing the fundamental way that CSS nesting works. For example, you might think that the following CSS is equivalent to a .outer .inner button { ... } rule:

    .inner button {
      .outer & {
        color: red;
      }
    }
    

    But instead it's actually equivalent to a .outer :is(.inner button) { ... } rule which unintuitively also matches the following DOM structure:

    <div class="inner">
      <div class="outer">
        <button></button>
      </div>
    </div>
    

    The :is() behavior is preferred by browser implementers because it's more memory-efficient, but the straightforward translation into a .outer .inner button { ... } rule is preferred by developers used to the existing CSS preprocessing ecosystem (e.g. SASS). It seems premature to commit esbuild to specific semantics for this syntax at this time given the ongoing debate.

  • Fix cross-file CSS rule deduplication involving url() tokens (#​2936)

    Previously cross-file CSS rule deduplication didn't handle url() tokens correctly. These tokens contain references to import paths which may be internal (i.e. in the bundle) or external (i.e. not in the bundle). When comparing two url() tokens for equality, the underlying import paths should be compared instead of their references. This release of esbuild fixes url() token comparisons. One side effect is that @font-face rules should now be deduplicated correctly across files:

    /* Original code */
    @&#8203;import "data:text/css, \
      @&#8203;import 'http://example.com/style.css'; \
      @&#8203;font-face { src: url(http://example.com/font.ttf) }";
    @&#8203;import "data:text/css, \
      @&#8203;font-face { src: url(http://example.com/font.ttf) }";
    
    /* Old output (with --bundle --minify) */
    @&#8203;import"http://example.com/style.css";@&#8203;font-face{src:url(http://example.com/font.ttf)}@&#8203;font-face{src:url(http://example.com/font.ttf)}
    
    /* New output (with --bundle --minify) */
    @&#8203;import"http://example.com/style.css";@&#8203;font-face{src:url(http://example.com/font.ttf)}
    

v0.17.9

Compare Source

  • Parse rest bindings in TypeScript types (#​2937)

    Previously esbuild was unable to parse the following valid TypeScript code:

    let tuple: (...[e1, e2, ...es]: any) => any
    

    This release includes support for parsing code like this.

  • Fix TypeScript code translation for certain computed declare class fields (#​2914)

    In TypeScript, the key of a computed declare class field should only be preserved if there are no decorators for that field. Previously esbuild always preserved the key, but esbuild will now remove the key to match the output of the TypeScript compiler:

    // Original code
    declare function dec(a: any, b: any): any
    declare const removeMe: unique symbol
    declare const keepMe: unique symbol
    class X {
        declare [removeMe]: any
        @&#8203;dec declare [keepMe]: any
    }
    
    // Old output
    var _a;
    class X {
    }
    removeMe, _a = keepMe;
    __decorateClass([
      dec
    ], X.prototype, _a, 2);
    
    // New output
    var _a;
    class X {
    }
    _a = keepMe;
    __decorateClass([
      dec
    ], X.prototype, _a, 2);
    
  • Fix a crash with path resolution error generation (#​2913)

    In certain situations, a module containing an invalid import path could previously cause esbuild to crash when it attempts to generate a more helpful error message. This crash has been fixed.

v0.17.8

Compare Source

  • Fix a minification bug with non-ASCII identifiers (#​2910)

    This release fixes a bug with esbuild where non-ASCII identifiers followed by a keyword were incorrectly not separated by a space. This bug affected both the in and instanceof keywords. Here's an example of the fix:

    // Original code
    π in a
    
    // Old output (with --minify --charset=utf8)
    πin a;
    
    // New output (with --minify --charset=utf8)
    π in a;
    
  • Fix a regression with esbuild's WebAssembly API in version 0.17.6 (#​2911)

    Version 0.17.6 of esbuild updated the Go toolchain to version 1.20.0. This had the unfortunate side effect of increasing the amount of stack space that esbuild uses (presumably due to some changes to Go's WebAssembly implementation) which could cause esbuild's WebAssembly-based API to crash with a stack overflow in cases where it previously didn't crash. One such case is the package grapheme-splitter which contains code that looks like this:

    if (
      (0x0300 <= code && code <= 0x036F) ||
      (0x0483 <= code && code <= 0x0487) ||
      (0x0488 <= code && code <= 0x0489) ||
      (0x0591 <= code && code <= 0x05BD) ||
      // ... many hundreds of lines later ...
    ) {
      return;
    }
    

    This edge case involves a chain of binary operators that results in an AST over 400 nodes deep. Normally this wouldn't be a problem because Go has growable call stacks, so the call stack would just grow to be as large as needed. However, WebAssembly byte code deliberately doesn't expose the ability to manipulate the stack pointer, so Go's WebAssembly translation is forced to use the fixed-size WebAssembly call stack. So esbuild's WebAssembly implementation is vulnerable to stack overflow in cases like these.

    It's not unreasonable for this to cause a stack overflow, and for esbuild's answer to this problem to be "don't write code like this." That's how many other AST-manipulation tools handle this problem. However, it's possible to implement AST traversal using iteration instead of recursion to work around limited call stack space. This version of esbuild implements this code transformation for esbuild's JavaScript parser and printer, so esbuild's WebAssembly implementation is now able to process the grapheme-splitter package (at least when compiled with Go 1.20.0 and run with node's WebAssembly implementation).

v0.17.7

Compare Source

  • Change esbuild's parsing of TypeScript instantiation expressions to match TypeScript 4.8+ (#​2907)

    This release updates esbuild's implementation of instantiation expression erasure to match microsoft/TypeScript#​49353. The new rules are as follows (copied from TypeScript's PR description):

    When a potential type argument list is followed by

    • a line break,
    • an ( token,
    • a template literal string, or
    • any token except < or > that isn't the start of an expression,

    we consider that construct to be a type argument list. Otherwise we consider the construct to be a < relational expression followed by a > relational expression.

  • Ignore sideEffects: false for imported CSS files (#​1370, #​1458, #​2905)

    This release ignores the sideEffects annotation in package.json for CSS files that are imported into JS files using esbuild's css loader. This means that these CSS files are no longer be tree-shaken.

    Importing CSS into JS causes esbuild to automatically create a CSS entry point next to the JS entry point containing the bundled CSS. Previously packages that specified some form of "sideEffects": false could potentially cause esbuild to consider one or more of the JS files on the import path to the CSS file to be side-effect free, which would result in esbuild removing that CSS file from the bundle. This was problematic because the removal of that CSS is outwardly observable, since all CSS is global, so it was incorrect for previous versions of esbuild to tree-shake CSS files imported into JS files.

  • Add constant folding for certain additional equality cases (#​2394, #​2895)

    This release adds constant folding for expressions similar to the following:

    // Original input
    console.log(
      null === 'foo',
      null === undefined,
      null == undefined,
      false === 0,
      false == 0,
      1 === true,
      1 == true,
    )
    
    // Old output
    console.log(
      null === "foo",
      null === void 0,
      null == void 0,
      false === 0,
      false == 0,
      1 === true,
      1 == true
    );
    
    // New output
    console.log(
      false,
      false,
      true,
      false,
      true,
      false,
      true
    );
    

v0.17.6

Compare Source

  • Fix a CSS parser crash on invalid CSS (#​2892)

    Previously the following invalid CSS caused esbuild's parser to crash:

    @&#8203;media screen
    

    The crash was caused by trying to construct a helpful error message assuming that there was an opening { token, which is not the case here. This release fixes the crash.

  • Inline TypeScript enums that are referenced before their declaration

    Previously esbuild inlined enums within a TypeScript file from top to bottom, which meant that references to TypeScript enum members were only inlined within the same file if they came after the enum declaration. With this release, esbuild will now inline enums even when they are referenced before they are declared:

    // Original input
    export const foo = () => Foo.FOO
    const enum Foo { FOO = 0 }
    
    // Old output (with --tree-shaking=true)
    export const foo = () => Foo.FOO;
    var Foo = /* @&#8203;__PURE__ */ ((Foo2) => {
      Foo2[Foo2["FOO"] = 0] = "FOO";
      return Foo2;
    })(Foo || {});
    
    // New output (with --tree-shaking=true)
    export const foo = () => 0 /* FOO */;
    

    This makes esbuild's TypeScript output smaller and faster when processing code that does this. I noticed this issue when I ran the TypeScript compiler's source code through esbuild's bundler. Now that the TypeScript compiler is going to be bundled with esbuild in the upcoming TypeScript 5.0 release, improvements like this will also improve the TypeScript compiler itself!

  • Fix esbuild installation on Arch Linux (#​2785, #​2812, #​2865)

    Someone made an unofficial esbuild package for Linux that adds the ESBUILD_BINARY_PATH=/usr/bin/esbuild environment variable to the user's default environment. This breaks all npm installations of esbuild for users with this unofficial Linux package installed, which has affected many people. Most (all?) people who encounter this problem haven't even installed this unofficial package themselves; instead it was installed for them as a dependency of another Linux package. The problematic change to add the ESBUILD_BINARY_PATH environment variable was reverted in the latest version of this unofficial package. However, old versions of this unofficial package are still there and will be around forever. With this release, ESBUILD_BINARY_PATH is now ignored by esbuild's install script when it's set to the value /usr/bin/esbuild. This should unbreak using npm to install esbuild in these problematic Linux environments.

    Note: The ESBUILD_BINARY_PATH variable is an undocumented way to override the location of esbuild's binary when esbuild's npm package is installed, which is necessary to substitute your own locally-built esbuild binary when debugging esbuild's npm package. It's only meant for very custom situations and should absolutely not be forced on others by default, especially without their knowledge. I may remove the code in esbuild's installer that reads ESBUILD_BINARY_PATH in the future to prevent these kinds of issues. It will unfortunately make debugging esbuild harder. If ESBUILD_BINARY_PATH is ever removed, it will be done in a "breaking change" release.

v0.17.5

Compare Source

  • Parse const type parameters from TypeScript 5.0

    The TypeScript 5.0 beta announcement adds const type parameters to the language. You can now add the const modifier on a type parameter of a function, method, or class like this:

    type HasNames = { names: readonly string[] };
    const getNamesExactly = <const T extends HasNames>(arg: T): T["names"] => arg.names;
    const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] });
    

    The type of names in the above example is readonly ["Alice", "Bob", "Eve"]. Marking the type parameter as const behaves as if you had written as const at every use instead. The above code is equivalent to the following TypeScript, which was the only option before TypeScript 5.0:

    type HasNames = { names: readonly string[] };
    const getNamesExactly = <T extends HasNames>(arg: T): T["names"] => arg.names;
    const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] } as const);
    

    You can read the announcement for more information.

  • Make parsing generic async arrow functions more strict in .tsx files

    Previously esbuild's TypeScript parser incorrectly accepted the following code as valid:

    let fn = async <T> () => {};
    

    The official TypeScript parser rejects this code because it thinks it's the identifier async followed by a JSX element starting with <T>. So with this release, esbuild will now reject this syntax in .tsx files too. You'll now have to add a comma after the type parameter to get generic arrow functions like this to parse in .tsx files:

    let fn = async <T,> () => {};
    
  • Allow the in and out type parameter modifiers on class expressions

    TypeScript 4.7 added the in and out modifiers on the type parameters of classes, interfaces, and type aliases. However, while TypeScript supported them on both class expressions and class statements, previously esbuild only supported them on class statements due to an oversight. This release now allows these modifiers on class expressions too:

    declare let Foo: any;
    Foo = class <in T> { };
    Foo = class <out T> { };
    
  • Update enum constant folding for TypeScript 5.0

    TypeScript 5.0 contains an updated definition of what it considers a constant expression:

    An expression is considered a constant expression if it is

    • a number or string literal,
    • a unary +, -, or ~ applied to a numeric constant expression,
    • a binary +, -, *, /, %, **, <<, >>, >>>, |, &, ^ applied to two numeric constant expressions,
    • a binary + applied to two constant expressions whereof at least one is a string,
    • a template expression where each substitution expression is a constant expression,
    • a parenthesized constant expression,
    • a dotted name (e.g. x.y.z) that references a const variable with a constant expression initializer and no type annotation,
    • a dotted name that references an enum member with an enum literal type, or
    • a dotted name indexed by a string literal (e.g. x.y["z"]) that references an enum member with an enum literal type.

    This impacts esbuild's implementation of TypeScript's const enum feature. With this release, esbuild will now attempt to follow these new rules. For example, you can now initialize an enum member with a template literal expression that contains a numeric constant:

    // Original input
    const enum Example {
      COUNT = 100,
      ERROR = `Expected ${COUNT} items`,
    }
    console.log(
      Example.COUNT,
      Example.ERROR,
    )
    
    // Old output (with --tree-shaking=true)
    var Example = /* @&#8203;__PURE__ */ ((Example2) => {
      Example2[Example2["COUNT"] = 100] = "COUNT";
      Example2[Example2["ERROR"] = `Expected ${100 /* COUNT */} items`] = "ERROR";
      return Example2;
    })(Example || {});
    console.log(
      100 /* COUNT */,
      Example.ERROR
    );
    
    // New output (with --tree-shaking=true)
    console.log(
      100 /* COUNT */,
      "Expected 100 items" /* ERROR */
    );
    

    These rules are not followed exactly due to esbuild's limitations. The rule about dotted references to const variables is not followed both because esbuild's enum processing is done in an isolated module setting and because doing so would potentially require esbuild to use a type system, which it doesn't have. For example:

    // The TypeScript compiler inlines this but esbuild doesn't:
    declare const x = 'foo'
    const enum Foo { X = x }
    console.log(Foo.X)
    

    Also, the rule that requires converting numbers to a string currently only followed for 32-bit signed integers and non-finite numbers. This is done to avoid accidentally introducing a bug if esbuild's number-to-string operation doesn't exactly match the behavior of a real JavaScript VM. Currently esbuild's number-to-string constant folding is conservative for safety.

  • Forbid definite assignment assertion operators on class methods

    In TypeScript, class methods can use the ? optional property operator but not the ! definite assignment assertion operator (while class fields can use both):

    class Foo {
      // These are valid TypeScript
      a?
      b!
      x?() {}
    
      // This is invalid TypeScript
      y!() {}
    }
    

    Previously esbuild incorrectly allowed the definite assignment assertion operator with class methods. This will no longer be allowed starting with this release.

v0.17.4

Compare Source

  • Implement HTTP HEAD requests in serve mode (#​2851)

    Previously esbuild's serve mode only responded to HTTP GET requests. With this release, esbuild's serve mode will also respond to HTTP HEAD requests, which are just like HTTP GET requests except that the body of the response is omitted.

  • Permit top-level await in dead code branches (#​2853)

    Adding top-level await to a file has a few consequences with esbuild:

    1. It causes esbuild to assume that the input module format is ESM, since top-level await is only syntactically valid in ESM. That prevents you from using module and exports for exports and also enables strict mode, which disables certain syntax and changes how function hoisting works (among other things).
    2. This will cause esbuild to fail the build if either top-level await isn't supported by your language target (e.g. it's not supported in ES2021) or if top-level await isn't supported by the chosen output format (e.g. it's not supported with CommonJS).
    3. Doing this will prevent you from using require() on this file or on any file that imports this file (even indirectly), since the require() function doesn't return a promise and so can't represent top-level await.

    This release relaxes these rules slightly: rules 2 and 3 will now no longer apply when esbuild has identified the code branch as dead code, such as when it's behind an if (false) check. This should make it possible to use esbuild to convert code into different output formats that only uses top-level await conditionally. This release does not relax rule 1. Top-level await will still cause esbuild to unconditionally consider the input module format to be ESM, even when the top-level await is in a dead code branch. This is necessary because whether the input format is ESM or not affects the whole file, not just the dead code branch.

  • Fix entry points where the entire file name is the extension (#​2861)

    Previously if you passed esbuild an entry point where the file extension is the entire file name, esbuild would use the parent directory name to derive the name of the output file. For example, if you passed esbuild a file ./src/.ts then the output name would be src.js. This bug happened because esbuild first strips the file extension to get ./src/ and then joins the path with the working directory to get the absolute path (e.g. join("/working/dir", "./src/") gives /working/dir/src). However, the join operation also canonicalizes the path which strips the trailing /. Later esbuild uses the "base name" operation to extract the name of the output file. Since there is no trailing /, esbuild returns "src" as the base name instead of "", which causes esbuild to incorrectly include the directory name in the output file name. This release fixes this bug by deferring the stripping of the file extension until after all path manipulations have been completed. So now the file ./src/.ts will generate an output file named .js.

  • Support replacing property access expressions with inject

    At a high level, this change means the inject feature can now replace all of the same kinds of names as the define feature. So inject is basically now a more powerful version of define, instead of previously only being able to do some of the things that define could do.

    Soem background is necessary to understand this change if you aren't already familiar with the inject feature. The inject feature lets you replace references to global variable with a shim. It works like this:

    1. Put the shim in its own file
    2. Export the shim as the name of the global variable you intend to replace
    3. Pass the file to esbuild using the inject feature

    For example, if you inject the following file using --inject:./injected.js:

    // injected.js
    let processShim = { cwd: () => '/' }
    export { processShim as process }
    

    Then esbuild will replace all references to process with the processShim variable, which will cause process.cwd() to return '/'. This feature is sort of abusing the ESM export alias syntax to specify the mapping of global variables to shims. But esbuild works this way because using this syntax for that purpose is convenient and terse.

    However, if you wanted to replace a property access expression, the process was more complicated and not as nice. You would have to:

    1. Put the shim in its own file
    2. Export the shim as some random name
    3. Pass the file to esbuild using the inject feature
    4. Use esbuild's define feature to map the property access expression to the random name you made in step 2

    For example, if you inject the following file using --inject:./injected2.js --define:process.cwd=someRandomName:

    // injected2.js
    let cwdShim = () => '/'
    export { cwdShim as someRandomName }
    

    Then esbuild will replace all references to process.cwd with the cwdShim variable, which will also cause process.cwd() to return '/' (but which this time will not mess with other references to process, which might be desirable).

    With this release, using the inject feature to replace a property access expression is now as simple as using it to replace an identifier. You can now use JavaScript's "arbitrary module namespace identifier names" feature to specify the property access expression directly using a string literal. For example, if you inject the following file using --inject:./injected3.js:

    // injected3.js
    let cwdShim = () => '/'
    export { cwdShim as 'process.cwd' }
    

    Then esbuild will now replace all references to process.cwd with the cwdShim variable, which will also cause process.cwd() to return '/' (but which will also not mess with other references to process).

    In addition to inserting a shim for a global variable that doesn't exist, another use case is replacing references to static methods on global objects with cached versions to both minify them better and to make access to them potentially faster. For example:

    // Injected file
    let cachedMin = Math.min
    let cachedMax = Math.max
    export {
      cachedMin as 'Math.min',
      cachedMax as 'Math.max',
    }
    
    // Original input
    function clampRGB(r, g, b) {
      return {
        r: Math.max(0, Math.min(1, r)),
        g: Math.max(0, Math.min(1, g)),
        b: Math.max(0, Math.min(1, b)),
      }
    }
    
    // Old output (with --minify)
    function clampRGB(a,t,m){return{r:Math.max(0,Math.min(1,a)),g:Math.max(0,Math.min(1,t)),b:Math.max(0,Math.min(1,m))}}
    
    // New output (with --minify)
    var a=Math.min,t=Math.max;function clampRGB(h,M,m){return{r:t(0,a(1,h)),g:t(0,a(1,M)),b:t(0,a(1,m))}}
    

v0.17.3

Compare Source

  • Fix incorrect CSS minification for certain rules (#​2838)

    Certain rules such as @media could previously be minified incorrectly. Due to a typo in the duplicate rule checker, two known @-rules that share the same hash code were incorrectly considered to be equal. This problem was made worse by the rule hashing code considering two unknown declarations (such as CSS variables) to have the same hash code, which also isn't optimal from a performance perspective. Both of these issues have been fixed:

    /* Original input */
    @&#8203;media (prefers-color-scheme: dark) { body { --VAR-1: #&#8203;000; } }
    @&#8203;media (prefers-color-scheme: dark) { body { --VAR-2: #&#8203;000; } }
    
    /* Old output (with --minify) */
    @&#8203;media (prefers-color-scheme: dark){body{--VAR-2: #&#8203;000}}
    
    /* New output (with --minify) */
    @&#8203;media (prefers-color-scheme: dark){body{--VAR-1: #&#8203;000}}@&#8203;media (prefers-color-scheme: dark){body{--VAR-2: #&#8203;000}}
    

v0.17.2

Compare Source

  • Add onDispose to the plugin API (#​2140, #​2205)

    If your plugin wants to perform some cleanup after it's no longer going to be used, you can now use the onDispose API to register a callback for cleanup-related tasks. For example, if a plugin starts a long-running child process then it may want to terminate that process when the plugin is discarded. Previously there was no way to do this. Here's an example:

    let examplePlugin = {
      name: 'example',
      setup(build) {
        build.onDispose(() => {
          console.log('This plugin is no longer used')
        })
      },
    }
    

    These onDispose callbacks will be called after every build() call regardless of whether the build failed or not as well as after the first dispose() call on a given build context.

v0.17.1

Compare Source

  • Fix CSS transform bugs with nested selectors that start with a combinator (#​3096)

    This release fixes several bugs regarding transforming nested CSS into non-nested CSS for older browsers. The bugs were due to lack of test coverage for nested selectors with more than one compound selector where they all start with the same combinator. Here's what some problematic cases look like before and after these fixes:

    /* Original code */
    .foo {
      > &a,
      > &b {
        color: red;
      }
    }
    .bar {
      > &a,
      + &b {
        color: green;
      }
    }
    
    /* Old output (with --target=chrome90) */
    .foo :is(> .fooa, > .foob) {
      color: red;
    }
    .bar :is(> .bara, + .barb) {
      color: green;
    }
    
    /* New output (with --target=chrome90) */
    .foo > :is(a.foo, b.foo) {
      color: red;
    }
    .bar > a.bar,
    .bar + b.bar {
      color: green;
    }
    
  • Fix bug with TypeScript parsing of instantiation expressions followed by = (#​3111)

    This release fixes esbuild's TypeScript-to-JavaScript conversion code in the case where a potential instantiation expression is followed immediately by a = token (such that the trailing > becomes a >= token). Previously esbuild considered that to still be an instantiation expression, but the official TypeScript compiler considered it to be a >= operator instead. This release changes esbuild's interpretation to match TypeScript. This edge case currently appears to be problematic for other TypeScript-to-JavaScript converters as well:

    Original code TypeScript esbuild 0.17.18 esbuild 0.17.19 Sucrase Babel
    x<y>=a<b<c>>() x<y>=a(); x=a(); x<y>=a(); x=a() Invalid left-hand side in assignment expression
  • Avoid removing unrecognized directives from the directive prologue when minifying (#​3115)

    The directive prologue in JavaScript is a sequence of top-level string expressions that come before your code. The only directives that JavaScript engines currently recognize are use strict and sometimes use asm. However, the people behind React have made up their own directive for their own custom dialect of JavaScript. Previously esbuild only preserved the use strict directive when minifying, although you could still write React JavaScript with esbuild using something like --banner:js="'your directive here';". With this release, you can now put arbitrary directives in the entry point and esbuild will preserve them in its minified output:

    // Original code
    'use wtf'; console.log(123)
    
    // Old output (with --minify)
    console.log(123);
    
    // New output (with --minify)
    "use wtf";console.log(123);
    

    Note that this means esbuild will no longer remove certain stray top-level strings when minifying. This behavior is an intentional change because these stray top-level strings are actually part of the directive prologue, and could potentially have semantics assigned to them (as was the case with React).

  • Improved minification of binary shift operators

    With this release, esbuild's minifier will now evaluate the << and >>> operators if the resulting code would be shorter:

    // Original code
    console.log(10 << 10, 10 << 20, -123 >>> 5, -123 >>> 10);
    
    // Old output (with --minify)
    console.log(10<<10,10<<20,-123>>>5,-123>>>10);
    
    // New output (with --minify)
    console.log(10240,10<<20,-123>>>5,4194303);
    

v0.17.0

Compare 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 esbuild in your package.json file (recommended) or be using a version range syntax that only accepts patch upgrades such as ^0.16.0 or ~0.16.0. See npm's documentation about semver for more information.

At a high level, the breaking changes in this release fix some long-standing issues with the design of esbuild's incremental, watch, and serve APIs. This release also introduces some exciting new features such as live reloading. In detail:

  • Move everything related to incremental builds to a new context API (#​1037, #​1606, #​2280, #​2418)

    This change removes the incremental and watch options as well as the serve() method, and introduces a new context() method. The context method takes the same arguments as the build() method but only validates its arguments and does not do an initial build. Instead, builds can be triggered using the rebuild(), watch(), and serve() methods on the returned context object. The new context API looks like this:

    // Create a context for incremental builds
    const context = await esbuild.context({
      entryPoints: ['app.ts'],
      bundle: true,
    })
    
    // Manually do an incremental build
    const result = await context.rebuild()
    
    // Enable watch mode
    await context.watch()
    
    // Enable serve mode
    await context.serve()
    
    // Dispose of the context
    context.dispose()
    

    The switch to the context API solves a major issue with the previous API which is that if the initial build fails, a promise is thrown in JavaScript which prevents you from accessing the returned result object. That prevented you from setting up long-running operations such as watch mode when the initial build contained errors. It also makes tearing down incremental builds simpler as there is now a single way to do it instead of three separate ways.

    In addition, this release also makes some subtle changes to how incremental builds work. Previously every call to rebuild() started a new build. If you weren't careful, then builds could actually overlap. This doesn't cause any problems with esbuild itself, but could potentially cause problems with plugins (esbuild doesn't even give you a way to identify which overlapping build a given plugin callback is running on). Overlapping builds also arguably aren't useful, or at least aren't useful enough to justify the confusion and complexity that they bring. With this release, there is now only ever a single active build per context. Calling rebuild() before the previous rebuild has finished now "merges" with the existing rebuild instead of starting a new build.

  • Allow using watch and serve together (#​805, #​1650, #​2576)

    Previously it was not possible to use watch mode and serve mode together. The rationale was that watch mode is one way of automatically rebuilding your project and serve mode is another (since serve mode automatically rebuilds on every request). However, people want to combine these two features to make "live reloading" where the browser automatically reloads the page when files are changed on the file system.

    This release now allows you to use these two features together. You can only call the watch() and serve() APIs once each per context, but if you call them together on the same context then esbuild will automatically rebuild both when files on the file system are changed and when the server serves a request.

  • Support "live reloading" through server-sent events (#​802)

    Server-sent events are a simple way to pass one-directional messages asynchronously from the server to the client. Serve mode now provides a /esbuild endpoint with an change event that triggers every time esbuild's output changes. So you can now implement simple "live reloading" (i.e. reloading the page when a file is edited and saved) like this:

    new EventSource('/esbuild').addEventListener('change', () => location.reload())
    

    The event payload is a JSON object with the following shape:

    interface ChangeEvent {
      added: string[]
      removed: string[]
      updated: string[]
    }
    

    This JSON should also enable more complex live reloading scenarios. For example, the following code hot-swaps changed CSS <link> tags in place without reloading the page (but still reloads when there are other types of changes):

    new EventSource('/esbuild').addEventListener('change', e => {
      const { added, removed, updated } = JSON.parse(e.data)
      if (!added.length && !removed.length && updated.length === 1) {
        for (const link of document.getElementsByTagName("link")) {
          const url = new URL(link.href)
          if (url.host === location.host && url.pathname === updated[0]) {
            const next = link.cloneNode()
            next.href = updated[0] + '?' + Math.random().toString(36).slice(2)
            next.onload = () => link.remove()
            link.parentNode.insertBefore(next, link.nextSibling)
            return
          }
        }
      }
      location.reload()
    })
    

    Implementing live reloading like this has a few known caveats:

    • These events only trigger when esbuild's output changes. They do not trigger when files unrelated to the build being watched are changed. If your HTML file references other files that esbuild doesn't know about and those files are changed, you can either manually reload the page or you can implement your own live reloading infrastructure instead of using esbuild's built-in behavior.

    • The EventSource API is supposed to automatically reconnect for you. However, there's a bug in Firefox that breaks this if the server is ever temporarily unreachable: https://bugzilla.mozilla.org/show_bug.cgi?id=1809332. Workarounds are to use any other browser, to manually reload the page if this happens, or to write more complicated code that manually closes and re-creates the EventSource object if there is a connection error. I'm hopeful that this bug will be fixed.

    • Browser vendors have decided to not implement HTTP/2 without TLS. This means that each /esbuild event source will take up one of your precious 6 simultaneous per-domain HTTP/1.1 connections. So if you open more than six HTTP tabs that use this live-reloading technique, you will be unable to use live reloading in some of those tabs (and other things will likely also break). The workaround is to enable HTTPS, which is now possible to do in esbuild itself (see below).

  • Add built-in support for HTTPS (#​2169)

    You can now tell esbuild's built-in development server to use HTTPS instead of HTTP. This is sometimes necessary because browser vendors have started making modern web features unavailable to HTTP websites. Previously you had to put a proxy in front of esbuild to enable HTTPS since esbuild's development server only supported HTTP. But with this release, you can now enable HTTPS with esbuild without an additional proxy.

    To enable HTTPS with esbuild:

    1. Generate a self-signed certificate. There are many ways to do this. Here's one way, assuming you have openssl installed:

      openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 9999 -nodes -subj /CN=127.0.0.1
      
    2. Add --keyfile=key.pem and --certfile=cert.pem to your esbuild development server command

    3. Click past the scary warning in your browser when you load your page

    If you have more complex needs than this, you can still put a proxy in front of esbuild and use that for HTTPS instead. Note that if you see the message "Client sent an HTTP request to an HTTPS server" when you load your page, then you are using the incorrect protocol. Replace http:// with https:// in your browser's URL bar.

    Keep in mind that esbuild's HTTPS support has nothing to do with security. The only reason esbuild now supports HTTPS is because browsers have made it impossible to do local development with certain modern web features without jumping through these extra hoops. Please do not use esbuild's development server for anything that needs to be secure. It's only intended for local development and no considerations have been made for production environments whatsoever.

  • Better support copying index.html into the output directory (#​621, #​1771)

    Right now esbuild only supports JavaScript and CSS as first-class content types. Previously this meant that if you were building a website with a HTML file, a JavaScript file, and a CSS file, you could use esbuild to build the JavaScript file and the CSS file into the output directory but not to copy the HTML file into the output directory. You needed a separate cp command for that.

    Or so I thought. It turns out that the copy loader added in version 0.14.44 of esbuild is sufficient to have esbuild copy the HTML file into the output directory as well. You can add something like index.html --loader:.html=copy and esbuild will copy index.html into the output directory for you. The benefits of this are a) you don't need a separate cp command and b) the index.html file will automatically be re-copied when esbuild is in watch mode and the contents of index.html are edited. This also goes for other non-HTML file types that you might want to copy.

    This pretty much already worked. The one thing that didn't work was that esbuild's built-in development server previously only supported implicitly loading index.html (e.g. loading /about/index.html when you visit /about/) when index.html existed on the file system. Previously esbuild didn't support implicitly loading index.html if it was a build result. That bug has been fixed with this release so it should now be practical to use the copy loader to do this.

  • Fix onEnd not being called in serve mode (#​1384)

    Previous releases had a bug where plugin onEnd callbacks weren't called when using the top-level serve() API. This API no longer exists and the internals have been reimplemented such that onEnd callbacks should now always be called at the end of every build.

  • Incremental builds now write out build results differently (#​2104)

    Previously build results were always written out after every build. However, this could cause the output directory to fill up with files from old builds if code splitting was enabled, since the file names for code splitting chunks contain content hashes and old files were not deleted.

    With this release, incremental builds in esbuild will now delete old output files from previous builds that are no longer relevant. Subsequent incremental builds will also no longer overwrite output files whose contents haven't changed since the previous incremental build.

  • The onRebuild watch mode callback was removed (#​980, #​2499)

    Previously watch mode accepted an onRebuild callback which was called whenever watch mode rebuilt something. This was not great in practice because if you are running code after a build, you likely want that code to run after every build, not just after the second and subsequent builds. This release removes option to provide an onRebuild callback. You can create a plugin with an onEnd callback instead. The onEnd plugin API already exists, and is a way to run some code after every build.

  • You can now return errors from onEnd (#​2625)

    It's now possible to add additional build errors and/or warnings to the current build from within your onEnd callback by returning them in an array. This is identical to how the onStart callback already works. The evaluation of onEnd callbacks have been moved around a bit internally to make this possible.

    Note that the build will only fail (i.e. reject the promise) if the additional errors are returned from onEnd. Adding additional errors to the result object that's passed to onEnd won't affect esbuild's behavior at all.

  • Print URLs and ports from the Go and JS APIs (#​2393)

    Previously esbuild's CLI printed out something like this when serve mode is active:

     > Local:   http://127.0.0.1:8000/
     > Network: http://192.168.0.1:8000/
    

    The CLI still does this, but now the JS and Go serve mode APIs will do this too. This only happens when the log level is set to verbose, debug, or info but not when it's set to warning, error, or silent.

Upgrade guide for existing code:
  • Rebuild (a.k.a. incremental build):

    Before:

    const result = await esbuild.build({ ...buildOptions, incremental: true });
    builds.push(result);
    for (let i = 0; i < 4; i++) builds.push(await result.rebuild());
    await result.rebuild.dispose(); // To free resources
    

    After:

    const ctx = await esbuild.context(buildOptions);
    for (let i = 0; i < 5; i++) builds.push(await ctx.rebuild());
    await ctx.dispose(); // To free resources
    

    Previously the first build was done differently than subsequent builds. Now both the first build and subsequent builds are done using the same API.

  • Serve:

    Before:

    const serveResult = await esbuild.serve(serveOptions, buildOptions);
    ...
    serveResult.stop(); await serveResult.wait; // To free resources
    

    After:

    const ctx = await esbuild.context(buildOptions);
    const serveResult = await ctx.serve(serveOptions);
    ...
    await ctx.dispose(); // To free resources
    
  • Watch:

    Before:

    const result = await esbuild.build({ ...buildOptions, watch: true });
    ...
    result.stop(); // To free resources
    

    After:

    const ctx = await esbuild.context(buildOptions);
    await ctx.watch();
    ...
    await ctx.dispose(); // To free resources
    
  • Watch with onRebuild:

    Before:

    const onRebuild = (error, result) => {
      if (error) console.log('subsequent build:', error);
      else console.log('subsequent build:', result);
    };
    try {
      const result = await esbuild.build({ ...buildOptions, watch: { onRebuild } });
      console.log('first build:', result);
      ...
      result.stop(); // To free resources
    } catch (error) {
      console.log('first build:', error);
    }
    

    After:

    const plugins = [{
      name: 'my-plugin',
      setup(build) {
        let count = 0;
        build.onEnd(result => {
          if (count++ === 0) console.log('first build:', result);
          else console.log('subsequent build:', result);
        });
      },
    }];
    const ctx = await esbuild.context({ ...buildOptions, plugins });
    await ctx.watch();
    ...
    await ctx.dispose(); // To free resources
    

    The onRebuild function has now been removed. The replacement is to make a plugin with an onEnd callback.

    Previously onRebuild did not fire for the first build (only for subsequent builds). This was usually problematic, so using onEnd instead of onRebuild is likely less error-prone. But if you need to emulate the old behavior of onRebuild that ignores the first build, then you'll need to manually count and ignore the first build in your plugin (as demonstrated above).

Notice how all of these API calls are now done off the new context object. You should now be able to use all three kinds of incremental builds (rebuild, serve, and watch) together on the same context object. Also notice how calling dispose on the context is now the common way to discard the context and free resources in all of these situations.

v0.16.17

Compare Source

  • Fix additional comment-related regressions (#​2814)

    This release fixes more edge cases where the new comment preservation behavior that was added in 0.16.14 could introduce syntax errors. Specifically:

    x = () => (/* comment */ {})
    for ((/* comment */ let).x of y) ;
    function *f() { yield (/* comment */class {}) }
    

    These cases caused esbuild to generate code with a syntax error in version 0.16.14 or above. These bugs have now been fixed.

v0.16.16

Compare Source

  • Fix a regression caused by comment preservation (#​2805)

    The new comment preservation behavior that was added in 0.16.14 introduced a regression where comments in certain locations could cause esbuild to omit certain necessary parentheses in the output. The outermost parentheses were incorrectly removed for the following syntax forms, which then introduced syntax errors:

    (/* comment */ { x: 0 }).x;
    (/* comment */ function () { })();
    (/* comment */ class { }).prototype;
    

    This regression has been fixed.

v0.16.15

Compare Source

  • Add format to input files in the JSON metafile data

    When --metafile is enabled, input files may now have an additional format field that indicates the export format used by this file. When present, the value will either be cjs for CommonJS-style exports or esm for ESM-style exports. This can be useful in bundle analysis.

    For example, esbuild's new Bundle Size Analyzer now uses this information to visualize whether ESM or CommonJS was used for each directory and file of source code (click on the CJS/ESM bar at the top).

    This information is helpful when trying to reduce the size of your bundle. Using the ESM variant of a dependency instead of the CommonJS variant always results in a faster and smaller bundle because it omits CommonJS wrappers, and also may result in better tree-shaking as it allows esbuild to perform tree-shaking at the statement level instead of the module level.

  • Fix a bundling edge case with dynamic import (#​2793)

    This release fixes a bug where esbuild's bundler could produce incorrect output. The problematic edge case involves the entry point importing itself using a dynamic import() expression in an imported file, like this:

    // src/a.js
    export const A = 42;
    
    // src/b.js
    export const B = async () => (await import(".")).A
    
    // src/index.js
    export * from "./a"
    export * from "./b"
    
  • Remove new type syntax from type declarations in the esbuild package (#​2798)

    Previously you needed to use TypeScript 4.3 or newer when using the esbuild package from TypeScript code due to the use of a getter in an interface in node_modules/esbuild/lib/main.d.ts. This release removes this newer syntax to allow people with versions of TypeScript as far back as TypeScript 3.5 to use this latest version of the esbuild package. Here is change that was made to esbuild's type declarations:

     export interface OutputFile {
       /** "text" as bytes */
       contents: Uint8Array;
       /** "contents" as text (changes automatically with "contents") */
    -  get text(): string;
    +  readonly text: string;
     }
    

v0.16.14

Compare Source

  • Preserve some comments in expressions (#​2721)

    Various tools give semantic meaning to comments embedded inside of expressions. For example, Webpack and Vite have special "magic comments" that can be used to affect code splitting behavior:

    import(/* webpackChunkName: "foo" */ '../foo');
    import(/* @&#8203;vite-ignore */ dynamicVar);
    new Worker(/* webpackChunkName: "bar" */ new URL("../bar.ts", import.meta.url));
    new Worker(new URL('./path', import.meta.url), /* @&#8203;vite-ignore */ dynamicOptions);
    

    Since esbuild can be used as a preprocessor for these tools (e.g. to strip TypeScript types), it can be problematic if esbuild doesn't do additional work to try to retain these comments. Previously esbuild special-cased Webpack comments in these specific locations in the AST. But Vite would now like to use similar comments, and likely other tools as well.

    So with this release, esbuild now will attempt to preserve some comments inside of expressions in more situations than before. This behavior is mainly intended to preserve these special "magic comments" that are meant for other tools to consume, although esbuild will no longer only preserve Webpack-specific comments so it should now be tool-agnostic. There is no guarantee that all such comments will be preserved (especially when --minify-syntax is enabled). So this change does not mean that esbuild is now usable as a code formatter. In particular comment preservation is more likely to happen with leading comments than with trailing comments. You should put comments that you want to be preserved before the relevant expression instead of after it. Also note that this change does not retain any more statement-level comments than before (i.e. comments not embedded inside of expressions). Comment preservation is not enabled when --minify-whitespace is enabled (which is automatically enabled when you use --minify).

v0.16.13

Compare Source

  • Publish a new bundle visualization tool

    While esbuild provides bundle metadata via the --metafile flag, previously esbuild left analysis of it completely up to third-party tools (well, outside of the rudimentary --analyze flag). However, the esbuild website now has a built-in bundle visualization tool:

    You can pass --metafile to esbuild to output bundle metadata, then upload that JSON file to this tool to visualize your bundle. This is helpful for answering questions such as:

    • Which packages are included in my bundle?
    • How did a specific file get included?
    • How small did a specific file compress to?
    • Was a specific file tree-shaken or not?

    I'm publishing this tool because I think esbuild should provide some answer to "how do I visualize my bundle" without requiring people to reach for third-party tools. At the moment the tool offers two types of visualizations: a radial "sunburst chart" and a linear "flame chart". They serve slightly different but overlapping use cases (e.g. the sunburst chart is more keyboard-accessible while the flame chart is easier with the mouse). This tool may continue to evolve over time.

  • Fix --metafile and --mangle-cache with --watch (#​1357)

    The CLI calls the Go API and then also writes out the metafile and/or mangle cache JSON files if those features are enabled. This extra step is necessary because these files are returned by the Go API as in-memory strings. However, this extra step accidentally didn't happen for all builds after the initial build when watch mode was enabled. This behavior used to work but it was broken in version 0.14.18 by the introduction of the mangle cache feature. This release fixes the combination of these features, so the metafile and mangle cache features should now work with watch mode. This behavior was only broken for the CLI, not for the JS or Go APIs.

  • Add an original field to the metafile

    The metadata file JSON now has an additional field: each import in an input file now contains the pre-resolved path in the original field in addition to the post-resolved path in the path field. This means it's now possible to run certain additional analysis over your bundle. For example, you should be able to use this to detect when the same package subpath is represented multiple times in the bundle, either because multiple versions of a package were bundled or because a package is experiencing the dual-package hazard.

v0.16.12

Compare Source

  • Loader defaults to js for extensionless files (#​2776)

    Certain packages contain files without an extension. For example, the yargs package contains the file yargs/yargs which has no extension. Node, Webpack, and Parcel can all understand code that imports yargs/yargs because they assume that the file is JavaScript. However, esbuild was previously unable to understand this code because it relies on the file extension to tell it how to interpret the file. With this release, esbuild will now assume files without an extension are JavaScript files. This can be customized by setting the loader for "" (the empty string, representing files without an extension) to another loader. For example, if you want files without an extension to be treated as CSS instead, you can do that like this:

    • CLI:

      esbuild --bundle --loader:=css
      
    • JS:

      esbuild.build({
        bundle: true,
        loader: { '': 'css' },
      })
      
    • Go:

      api.Build(api.BuildOptions{
        Bundle: true,
        Loader: map[string]api.Loader{"": api.LoaderCSS},
      })
      

    In addition, the "type" field in package.json files now only applies to files with an explicit .js, .jsx, .ts, or .tsx extension. Previously it was incorrectly applied by esbuild to all files that had an extension other than .mjs, .mts, .cjs, or .cts including extensionless files. So for example an extensionless file in a "type": "module" package is now treated as CommonJS instead of ESM.

v0.16.11

Compare Source

  • Avoid a syntax error in the presence of direct eval (#​2761)

    The behavior of nested function declarations in JavaScript depends on whether the code is run in strict mode or not. It would be problematic if esbuild preserved nested function declarations in its output because then the behavior would depend on whether the output was run in strict mode or not instead of respecting the strict mode behavior of the original source code. To avoid this, esbuild transforms nested function declarations to preserve the intended behavior of the original source code regardless of whether the output is run in strict mode or not:

    // Original code
    if (true) {
      function foo() {}
      console.log(!!foo)
      foo = null
      console.log(!!foo)
    }
    console.log(!!foo)
    
    // Transformed code
    if (true) {
      let foo2 = function() {
      };
      var foo = foo2;
      console.log(!!foo2);
      foo2 = null;
      console.log(!!foo2);
    }
    console.log(!!foo);
    

    In the above example, the original code should print true false true because it's not run in strict mode (it doesn't contain "use strict" and is not an ES module). The code that esbuild generates has been transformed such that it prints true false true regardless of whether it's run in strict mode or not.

    However, this transformation is impossible if the code contains direct eval because direct eval "poisons" all containing scopes by preventing anything in those scopes from being renamed. That prevents esbuild from splitting up accesses to foo into two separate variables with different names. Previously esbuild still did this transformation but with two variables both named foo, which is a syntax error. With this release esbuild will now skip doing this transformation when direct eval is present to avoid generating code with a syntax error. This means that the generated code may no longer behave as intended since the behavior depends on the run-time strict mode setting instead of the strict mode setting present in the original source code. To fix this problem, you will need to remove the use of direct eval.

  • Fix a bundling scenario involving multiple symlinks (#​2773, #​2774)

    This release contains a fix for a bundling scenario involving an import path where multiple path segments are symlinks. Previously esbuild was unable to resolve certain import paths in this scenario, but these import paths should now work starting with this release. This fix was contributed by @​onebytegone.

v0.16.10

Compare Source

  • Change the default "legal comment" behavior again (#​2745)

    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). 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:

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of the
    License at http://www.apache.org/licenses/LICENSE-2.0
    
    THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
    MERCHANTABLITY OR NON-INFRINGEMENT.
    
    See the Apache Version 2.0 License for specific language governing permissions
    and limitations under the License.
    ***************************************************************************** */
    

    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:

    /*! Bundled license information:
    
    typescript/lib/typescript.js:
      (*! *****************************************************************************
      Copyright (c) Microsoft Corporation. All rights reserved.
      Licensed under the Apache License, Version 2.0 (the "License"); you may not use
      this file except in compliance with the License. You may obtain a copy of the
      License at http://www.apache.org/licenses/LICENSE-2.0
    
      THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
      KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
      WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
      MERCHANTABLITY OR NON-INFRINGEMENT.
    
      See the Apache Version 2.0 License for specific language governing permissions
      and limitations under the License.
      ***************************************************************************** *)
    */
    

    Note that you can still customize this behavior with the --legal-comments= flag. For example, you can use --legal-comments=none to turn this off, or you can use --legal-comments=linked to put these comments in a separate .LEGAL.txt file instead.

  • Enable external legal comments with the transform API (#​2390)

    Previously esbuild's transform API only supported none, inline, or eof legal comments. With this release, external legal 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:

      const { code, legalComments } = await esbuild.transform(input, {
        legalComments: 'external',
      })
      
    • Go:

      result := api.Transform(input, api.TransformOptions{
        LegalComments: api.LegalCommentsEndOfFile,
      })
      code := result.Code
      legalComments := result.LegalComments
      
  • 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 alias feature had to be the name of a package (with or without a package scope). With this release, you can now also use the alias feature with package subpaths. So for example you can now create an alias that substitutes @org/pkg/lib with something else.

v0.16.9

Compare 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 function declarations or all var declarations. However, esbuild was overly permissive and allowed this when duplicate entries were either function declarations or var declarations (even if they were mixed). This check has now been made more restrictive to match the JavaScript specification:

    // JavaScript allows this
    var a
    function a() {}
    {
      var b
      var b
      function c() {}
      function c() {}
    }
    
    // JavaScript doesn't allow this
    {
      var d
      function d() {}
    }
    
  • Add a type declaration for the new empty loader (#​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 v flag in regular expression literals

    People are currently working on adding a v flag 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 than esnext, esbuild will transform regular expression literals containing this flag into a new RegExp() constructor call so the resulting code doesn't have a syntax error. This enables you to provide a polyfill for RegExp that implements the v flag 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 name properties

    The --keep-names property attempts to preserve the original value of the name property 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 the name property on the function or class object. However, this should not be done for classes with a static name property since in that case the explicitly-defined name property overwrites the automatically-generated class name. With this release, esbuild will now no longer attempt to preserve the name property for classes with a static name property.

v0.16.8

Compare Source

  • Allow plugins to resolve injected files (#​2754)

    Previously paths passed to the inject feature were always interpreted as file system paths. This meant that onResolve plugins would not be run for them and esbuild's default path resolver would always be used. This meant that the inject feature couldn't be used in the browser since the browser doesn't have access to a file system. This release runs paths passed to inject through esbuild's full path resolution pipeline so plugins now have a chance to handle them using onResolve callbacks. This makes it possible to write a plugin that makes esbuild's inject work in the browser.

  • Add the empty loader (#​1541, #​2753)

    The new empty loader tells esbuild to pretend that a file is empty. So for example --loader:.css=empty effectively skips all imports of .css files in JavaScript so that they aren't included in the bundle, since import "./some-empty-file" in JavaScript doesn't bundle anything. You can also use the empty loader to remove asset references in CSS files. For example --loader:.png=empty causes esbuild to replace asset references such as url(image.png) with url() 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=false or --supported:inline-script=true accidentally broke automatic escaping of </script> when an explicit target setting is specified. This release restores the correct automatic escaping of </script> (which should not depend on what target is set to).

  • Enable the exports field with NODE_PATHS (#​2752)

    Node has a rarely-used feature where you can extend the set of directories that node searches for packages using the NODE_PATHS environment variable. While esbuild supports this too, previously it only supported the old main field path resolution but did not support the new exports field package resolution. This release makes the path resolution rules the same again for both node_modules directories and NODE_PATHS directories.

v0.16.7

Compare Source

  • Include file loader strings in metafile imports (#​2731)

    Bundling a file with the file loader copies that file to the output directory and imports a module with the path to the copied file in the default export. Previously when bundling with the file loader, 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 the imports array with the kind file-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.js imports image.png using the file loader and esbuild generates out.js and image-LSAMBFUD.png, the metadata for how many bytes of out.js are from app.js was slightly off (the metadata for the byte count of out.js was 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 the bytesInOutput values).

  • 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 util imports node's built-in module called util but importing util/ tries to find a package called util on the file system. Previously attempting to use esbuild's package alias feature to replace imports to util with a specific file would fail because the file path would also gain a trailing slash (e.g. mapping util to ./file.js turned util/ 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.6

Compare 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 the imports field in the package.json file of the enclosing package. The intent of the newly-added --packages=external setting 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=external no 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:

    • Legacy octal literals (non-zero integers starting with 0)
    • The 0b, 0o, and 0x numeric prefixes
    • Numbers containing _ such as 1_000
    • Leading and trailing . such as 0. and .0
    • Numbers with a space after the - such as - 1
  • Add external imports to metafile (#​905, #​1768, #​1933, #​1939)

    External imports now appear in imports arrays in the metafile (which is present when bundling with metafile: true) next to normal imports, but additionally have external: true to set them apart. This applies both to files in the inputs section and the outputs section. 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 imports array is now populated when bundling is disabled. So you can now use esbuild with bundling disabled to inspect a file's imports.

v0.16.5

Compare 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 __dirname and run-time file system calls to load files, which doesn't work after bundling with esbuild. Or they may compile a native .node extension that has similar expectations about the layout of the file system that are no longer true after bundling (even if the .node extension is copied next to the bundle).

    The way to get this to work with esbuild is to use the --external: flag. For example, the fsevents package contains a native .node extension and shouldn't be bundled. To bundle code that uses it, you can pass --external:fsevents to esbuild to exclude it from your bundle. You will then need to ensure that the fsevents package is still present when you run your bundle (e.g. by publishing your bundle to npm as a package with a dependency on fsevents).

    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.json file and passed the keys of the dependencies, devDependencies, peerDependencies, and/or optionalDependencies maps 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:

      esbuild --bundle --packages=external
      
    • JS:

      esbuild.build({
        bundle: true,
        packages: 'external',
      })
      
    • Go:

      api.Build(api.BuildOptions{
        Bundle:   true,
        Packages: api.PackagesExternal,
      })
      

    Doing --external:./node_modules/* is still possible and still has the same behavior, but is no longer recommended. I recommend that you use the new packages feature instead.

  • Fix some subtle bugs with tagged template literals

    This release fixes a bug where minification could incorrectly change the value of this within tagged template literal function calls:

    // Original code
    function f(x) {
      let z = y.z
      return z``
    }
    
    // Old output (with --minify)
    function f(n){return y.z``}
    
    // New output (with --minify)
    function f(n){return(0,y.z)``}
    

    This release also fixes a bug where using optional chaining with --target=es2019 or earlier could incorrectly change the value of this within tagged template literal function calls:

    // Original code
    var obj = {
      foo: function() {
        console.log(this === obj);
      }
    };
    (obj?.foo)``;
    
    // Old output (with --target=es6)
    var obj = {
      foo: function() {
        console.log(this === obj);
      }
    };
    (obj == null ? void 0 : obj.foo)``;
    
    // New output (with --target=es6)
    var __freeze = Object.freeze;
    var __defProp = Object.defineProperty;
    var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
    var _a;
    var obj = {
      foo: function() {
        console.log(this === obj);
      }
    };
    (obj == null ? void 0 : obj.foo).call(obj, _a || (_a = __template([""])));
    
  • 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.4

Compare 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.3

Compare 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 stderr stream set to pipe instead of inherit, in the child process you call esbuild's JS API and pass incremental: true but do not call dispose() on the returned rebuild object, and then call process.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's sync.WaitGroup API 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 the sync.WaitGroup API for esbuild to use instead.

v0.16.2

Compare Source

  • Fix process.env.NODE_ENV substitution when transforming (#​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 </script> 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)

    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 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)

    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

Compare Source

  • Fix additional comment-related regressions (#​2814)

    This release fixes more edge cases where the new comment preservation behavior that was added in 0.16.14 could introduce syntax errors. Specifically:

    x = () => (/* comment */ {})
    for ((/* comment */ let).x of y) ;
    function *f() { yield (/* comment */class {}) }
    

    These cases caused esbuild to generate code with a syntax error in version 0.16.14 or above. These bugs have now been fixed.

v0.16.0

Compare 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 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 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:

    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:

    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)

    Loading a file with esbuild's dataurl loader 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'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)

    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:

    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:

    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 </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:

    <script>
      console.log("</script>");
    </script>
    

    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 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)

    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. 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)

    Package authors want to be able to use the new 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 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)

    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 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 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.

v0.15.18

Compare Source

  • 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

Compare Source

  • Search for missing source map code on the file system (#​2711)

    Source maps 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)

    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:

    type A<T> = {};
    type B = {} extends infer T extends {} ? A<T> : never;
    

    TypeScript code that does this should now be parsed correctly.

  • Use WebAssembly.instantiateStreaming if available (#​1036, #​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.

  • Preserve Webpack comments inside constructor calls (#​2439)

    This improves the use of esbuild as a faster TypeScript-to-JavaScript frontend for Webpack, which has special magic comments inside new Worker() expressions that affect Webpack's behavior.

v0.15.16

Compare Source

  • Add a package alias feature (#​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)

    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 <x y />, y is a string) or an object spread (e.g. in <x {...y} />, 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 <x {...{ [y]: z }} />. When minification is enabled, esbuild's internal representation of this is something like <x [y]={z} /> 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 <x {...{[y]:z}}/> in this scenario instead of crashing.

v0.15.15

Compare Source

  • Remove duplicate CSS rules across files (#​2688)

    When two or more CSS rules are exactly the same (even if they are not adjacent), all but the last one can safely be removed:

    /* Before */
    a { color: red; }
    span { font-weight: bold; }
    a { color: red; }
    
    /* After */
    span { font-weight: bold; }
    a { color: red; }
    

    Previously esbuild only did this transformation within a single source file. But with this release, esbuild will now do this transformation across source files, which may lead to smaller CSS output if the same rules are repeated across multiple CSS source files in the same bundle. This transformation is only enabled when minifying (specifically when syntax minification is enabled).

  • Add deno as a valid value for target (#​2686)

    The target setting in esbuild allows you to enable or disable JavaScript syntax features for a given version of a set of target JavaScript VMs. Previously Deno was not one of the JavaScript VMs that esbuild supported with target, but it will now be supported starting from this release. For example, versions of Deno older than v1.2 don't support the new ||= operator, so adding e.g. --target=deno1.0 to esbuild now lets you tell esbuild to transpile ||= to older JavaScript.

  • Fix the esbuild-wasm package in Node v19 (#​2683)

    A recent change to Node v19 added a non-writable crypto property to the global object: https://github.com/nodejs/node/pull/44897. This conflicts with Go's WebAssembly shim code, which overwrites the global crypto property. As a result, all Go-based WebAssembly code that uses the built-in shim (including esbuild) is now broken on Node v19. This release of esbuild fixes the issue by reconfiguring the global crypto property to be writable before invoking Go's WebAssembly shim code.

  • Fix CSS dimension printing exponent confusion edge case (#​2677)

    In CSS, a dimension token has a numeric "value" part and an identifier "unit" part. For example, the dimension token 32px has a value of 32 and a unit of px. The unit can be any valid CSS identifier. The value can be any number in floating-point format including an optional exponent (e.g. -3.14e-0 has an exponent of e-0). The full details of this syntax are here: https://www.w3.org/TR/css-syntax-3/.

    To maintain the integrity of the dimension token through the printing process, esbuild must handle the edge case where the unit looks like an exponent. One such case is the dimension 1e\32 which has the value 1 and the unit e2. It would be bad if this dimension token was printed such that a CSS parser would parse it as a number token with the value 1e2 instead of a dimension token. The way esbuild currently does this is to escape the leading e in the dimension unit, so esbuild would parse 1e\32 but print 1\65 2 (both 1e\32 and 1\65 2 represent a dimension token with a value of 1 and a unit of e2).

    However, there is an even narrower edge case regarding this edge case. If the value part of the dimension token itself has an e, then it's not necessary to escape the e in the dimension unit because a CSS parser won't confuse the unit with the exponent even though it looks like one (since a number can only have at most one exponent). This came up because the grammar for the CSS unicode-range property uses a hack that lets you specify a hexadecimal range without quotes even though CSS has no token for a hexadecimal range. The hack is to allow the hexadecimal range to be parsed as a dimension token and optionally also a number token. Here is the grammar for unicode-range:

    unicode-range =
      <urange>#
    
    <urange> =
      u '+' <ident-token> '?'*            |
      u <dimension-token> '?'*            |
      u <number-token> '?'*               |
      u <number-token> <dimension-token>  |
      u <number-token> <number-token>     |
      u '+' '?'+
    

    and here is an example unicode-range declaration that was problematic for esbuild:

    @&#8203;font-face {
      unicode-range: U+0e2e-0e2f;
    }
    

    This is parsed as a dimension with a value of +0e2 and a unit of e-0e2f. This was problematic for esbuild because the unit starts with e-0 which could be confused with an exponent when appended after a number, so esbuild was escaping the e character in the unit. However, this escaping is unnecessary because in this case the dimension value already has an exponent in it. With this release, esbuild will no longer unnecessarily escape the e in the dimension unit in these cases, which should fix the printing of unicode-range declarations.

    An aside: You may be wondering why esbuild is trying to escape the e at all and why it doesn't just pass through the original source code unmodified. The reason why esbuild does this is that, for robustness, esbuild's AST generally tries to omit semantically-unrelated information and esbuild's code printers always try to preserve the semantics of the underlying AST. That way the rest of esbuild's internals can just deal with semantics instead of presentation. They don't have to think about how the AST will be printed when changing the AST. This is the same reason that esbuild's JavaScript AST doesn't have a "parentheses" node (e.g. a * (b + c) is represented by the AST multiply(a, add(b, c)) instead of multiply(a, parentheses(add(b, c)))). Instead, the printer automatically inserts parentheses as necessary to maintain the semantics of the AST, which means all of the optimizations that run over the AST don't have to worry about keeping the parentheses up to date. Similarly, the CSS AST for the dimension token stores the actual unit and the printer makes sure the unit is properly escaped depending on what value it's placed after. All of the other code operating on CSS ASTs doesn't have to worry about parsing escapes to compare units or about keeping escapes up to date when the AST is modified. Hopefully that makes sense.

  • Attempt to avoid creating the node_modules/.cache directory for people that use Yarn 2+ in Plug'n'Play mode (#​2685)

    When Yarn's PnP mode is enabled, packages installed by Yarn may or may not be put inside .zip files. The specific heuristics for when this happens change over time in between Yarn versions. This is problematic for esbuild because esbuild's JavaScript package needs to execute a binary file inside the package. Yarn makes extensive modifications to Node's file system APIs at run time to pretend that .zip files are normal directories and to make it hard to tell whether a file is real or not (since in theory it doesn't matter). But they haven't modified Node's child_process.execFileSync API so attempting to execute a file inside a zip file fails. To get around this, esbuild previously used Node's file system APIs to copy the binary executable to another location before invoking execFileSync. Under the hood this caused Yarn to extract the file from the zip file into a real file that can then be run.

    However, esbuild copied its executable into node_modules/.cache/esbuild. This is the official recommendation from the Yarn team for where packages are supposed to put these types of files when Yarn PnP is being used. However, users of Yarn PnP with esbuild find this really annoying because they don't like looking at the node_modules directory. With this release, esbuild now sets "preferUnplugged": true in its package.json files, which tells newer versions of Yarn to not put esbuild's packages in a zip file. There may exist older versions of Yarn that don't support preferUnplugged. In that case esbuild should still copy the executable to a cache directory, so it should still run (hopefully, since I haven't tested this myself). Note that esbuild setting "preferUnplugged": true may have the side effect of esbuild taking up more space on the file system in the event that multiple platforms are installed simultaneously, or that you're using an older version of Yarn that always installs packages for all platforms. In that case you may want to update to a newer version of Yarn since Yarn has recently changed to only install packages for the current platform.

v0.15.14

Compare Source

  • Fix parsing of TypeScript infer inside a conditional extends (#​2675)

    Unlike JavaScript, parsing TypeScript sometimes requires backtracking. The infer A type operator can take an optional constraint of the form infer A extends B. However, this syntax conflicts with the similar conditional type operator A extends B ? C : D in cases where the syntax is combined, such as infer A extends B ? C : D. This is supposed to be parsed as (infer A) extends B ? C : D. Previously esbuild incorrectly parsed this as (infer A extends B) ? C : D instead, which is a parse error since the ?: conditional operator requires the extends keyword as part of the conditional type. TypeScript disambiguates by speculatively parsing the extends after the infer, but backtracking if a ? token is encountered afterward. With this release, esbuild should now do the same thing, so esbuild should now correctly parse these types. Here's a real-world example of such a type:

    type Normalized<T> = T extends Array<infer A extends object ? infer A : never>
      ? Dictionary<Normalized<A>>
      : {
          [P in keyof T]: T[P] extends Array<infer A extends object ? infer A : never>
            ? Dictionary<Normalized<A>>
            : Normalized<T[P]>
        }
    
  • Avoid unnecessary watch mode rebuilds when debug logging is enabled (#​2661)

    When debug-level logs are enabled (such as with --log-level=debug), esbuild's path resolution subsystem generates debug log messages that say something like "Read 20 entries for directory /home/user" to help you debug what esbuild's path resolution is doing. This caused esbuild's watch mode subsystem to add a dependency on the full list of entries in that directory since if that changes, the generated log message would also have to be updated. However, meant that on systems where a parent directory undergoes constant directory entry churn, esbuild's watch mode would continue to rebuild if --log-level=debug was passed.

    With this release, these debug log messages are now generated by "peeking" at the file system state while bypassing esbuild's watch mode dependency tracking. So now watch mode doesn't consider the count of directory entries in these debug log messages to be a part of the build that needs to be kept up to date when the file system state changes.

v0.15.13

Compare Source

  • Add support for the TypeScript 4.9 satisfies operator (#​2509)

    TypeScript 4.9 introduces a new operator called satisfies that lets you check that a given value satisfies a less specific type without casting it to that less specific type and without generating any additional code at run-time. It looks like this:

    const value = { foo: 1, bar: false } satisfies Record<string, number | boolean>
    console.log(value.foo.toFixed(1)) // TypeScript knows that "foo" is a number here
    

    Before this existed, you could use a cast with as to check that a value satisfies a less specific type, but that removes any additional knowledge that TypeScript has about that specific value:

    const value = { foo: 1, bar: false } as Record<string, number | boolean>
    console.log(value.foo.toFixed(1)) // TypeScript no longer knows that "foo" is a number
    

    You can read more about this feature in TypeScript's blog post for 4.9 as well as the associated TypeScript issue for this feature.

    This feature was implemented in esbuild by @​magic-akari.

  • Fix watch mode constantly rebuilding if the parent directory is inaccessible (#​2640)

    Android is unusual in that it has an inaccessible directory in the path to the root, which esbuild was not originally built to handle. To handle cases like this, the path resolution layer in esbuild has a hack where it treats inaccessible directories as empty. However, esbuild's watch implementation currently triggers a rebuild if a directory previously encountered an error but the directory now exists. The assumption is that the previous error was caused by the directory not existing. Although that's usually the case, it's not the case for this particular parent directory on Android. Instead the error is that the directory previously existed but was inaccessible.

    This discrepancy between esbuild's path resolution layer and its watch mode was causing watch mode to rebuild continuously on Android. With this release, esbuild's watch mode instead checks for an error status change in the readdir file system call, so watch mode should no longer rebuild continuously on Android.

  • Apply a fix for a rare deadlock with the JavaScript API (#​1842, #​2485)

    There have been reports of esbuild sometimes exiting with an "all goroutines are asleep" deadlock message from the Go language runtime. This issue hasn't made much progress until recently, where a possible cause was discovered (thanks to @​jfirebaugh for the investigation). This release contains a possible fix for that possible cause, so this deadlock may have been fixed. The fix cannot be easily verified because the deadlock is non-deterministic and rare. If this was indeed the cause, then this issue only affected the JavaScript API in situations where esbuild was already in the process of exiting.

    In detail: The underlying cause is that Go's sync.WaitGroup API for waiting for a set of goroutines to finish is not fully thread-safe. Specifically it's not safe to call Add() concurrently with Wait() when the wait group counter is zero due to a data race. This situation could come up with esbuild's JavaScript API when the host JavaScript process closes the child process's stdin and the child process (with no active tasks) calls Wait() to check that there are no active tasks, at the same time as esbuild's watchdog timer calls Add() to add an active task (that pings the host to see if it's still there). The fix in this release is to avoid calling Add() once we learn that stdin has been closed but before we call Wait().

v0.15.12

Compare Source

  • Fix minifier correctness bug with single-use substitutions (#​2619)

    When minification is enabled, esbuild will attempt to eliminate variables that are only used once in certain cases. For example, esbuild minifies this code:

    function getEmailForUser(name) {
      let users = db.table('users');
      let user = users.find({ name });
      let email = user?.get('email');
      return email;
    }
    

    into this code:

    function getEmailForUser(e){return db.table("users").find({name:e})?.get("email")}
    

    However, this transformation had a bug where esbuild did not correctly consider the "read" part of binary read-modify-write assignment operators. For example, it's incorrect to minify the following code into bar += fn() because the call to fn() might modify bar:

    const foo = fn();
    bar += foo;
    

    In addition to fixing this correctness bug, this release also improves esbuild's output in the case where all values being skipped over are primitives:

    function toneMapLuminance(r, g, b) {
      let hdr = luminance(r, g, b)
      let decay = 1 / (1 + hdr)
      return 1 - decay
    }
    

    Previous releases of esbuild didn't substitute these single-use variables here, but esbuild will now minify this to the following code starting with this release:

    function toneMapLuminance(e,n,a){return 1-1/(1+luminance(e,n,a))}
    

v0.15.11

Compare Source

  • Fix various edge cases regarding template tags and this (#​2610)

    This release fixes some bugs where the value of this wasn't correctly preserved when evaluating template tags in a few edge cases. These edge cases are listed below:

    async function test() {
      class Foo { foo() { return this } }
      class Bar extends Foo {
        a = async () => super.foo``
        b = async () => super['foo']``
        c = async (foo) => super[foo]``
      }
      function foo() { return this }
      const obj = { foo }
      const bar = new Bar
      console.log(
        (await bar.a()) === bar,
        (await bar.b()) === bar,
        (await bar.c('foo')) === bar,
        { foo }.foo``.foo === foo,
        (true && obj.foo)`` !== obj,
        (false || obj.foo)`` !== obj,
        (null ?? obj.foo)`` !== obj,
      )
    }
    test()
    

    Each edge case in the code above previously incorrectly printed false when run through esbuild with --minify --target=es6 but now correctly prints true. These edge cases are unlikely to have affected real-world code.

v0.15.10

Compare Source

  • Add support for node's "pattern trailers" syntax (#​2569)

    After esbuild implemented node's exports feature in package.json, node changed the feature to also allow text after * wildcards in patterns. Previously the * was required to be at the end of the pattern. It lets you do something like this:

    {
      "exports": {
        "./features/*": "./features/*.js",
        "./features/*.js": "./features/*.js"
      }
    }
    

    With this release, esbuild now supports these types of patterns too.

  • Fix subpath imports with Yarn PnP (#​2545)

    Node has a little-used feature called subpath imports which are package-internal imports that start with # and that go through the imports map in package.json. Previously esbuild had a bug that caused esbuild to not handle these correctly in packages installed via Yarn's "Plug'n'Play" installation strategy. The problem was that subpath imports were being checked after Yarn PnP instead of before. This release reorders these checks, which should allow subpath imports to work in this case.

  • Link from JS to CSS in the metafile (#​1861, #​2565)

    When you import CSS into a bundled JS file, esbuild creates a parallel CSS bundle next to your JS bundle. So if app.ts imports some CSS files and you bundle it, esbuild will give you app.js and app.css. You would then add both <script src="app.js"></script> and <link href="app.css" rel="stylesheet"> to your HTML to include everything in the page. This approach is more efficient than having esbuild insert additional JavaScript into app.js that downloads and includes app.css because it means the browser can download and parse both the CSS and the JS in parallel (and potentially apply the CSS before the JS has even finished downloading).

    However, sometimes it's difficult to generate the <link> tag. One case is when you've added [hash] to the entry names setting to include a content hash in the file name. Then the file name will look something like app-GX7G2SBE.css and may change across subsequent builds. You can tell esbuild to generate build metadata using the metafile API option but the metadata only tells you which generated JS bundle corresponds to a JS entry point (via the entryPoint property), not which file corresponds to the associated CSS bundle. Working around this was hacky and involved string manipulation.

    This release adds the cssBundle property to the metafile to make this easier. It's present on the metadata for the generated JS bundle and points to the associated CSS bundle. So to generate the HTML tags for a given JS entry point, you first find the output file with the entryPoint you are looking for (and put that in a <script> tag), then check for the cssBundle property to find the associated CSS bundle (and put that in a <link> tag).

    One thing to note is that there is deliberately no jsBundle property mapping the other way because it's not a 1:1 relationship. Two JS bundles can share the same CSS bundle in the case where the associated CSS bundles have the same name and content. In that case there would be no one value for a hypothetical jsBundle property to have.

v0.15.9

Compare Source

  • Fix an obscure npm package installation issue with --omit=optional (#​2558)

    The previous release introduced a regression with npm install esbuild --omit=optional where the file node_modules/.bin/esbuild would no longer be present after installation. That could cause any package scripts which used the esbuild command to no longer work. This release fixes the regression so node_modules/.bin/esbuild should now be present again after installation. This regression only affected people installing esbuild using npm with either the --omit=optional or --no-optional flag, which is a somewhat unusual situation.

    More details:

    The reason for this regression is due to some obscure npm implementation details. Since the Go compiler doesn't support trivial cross-compiling on certain Android platforms, esbuild's installer installs a WebAssembly shim on those platforms instead. In the previous release I attempted to simplify esbuild's WebAssembly shims to depend on the esbuild-wasm package instead of including another whole copy of the WebAssembly binary (to make publishing faster and to save on file system space after installation). However, both the esbuild package and the esbuild-wasm package provide a binary called esbuild and it turns out that adding esbuild-wasm as a nested dependency of the esbuild package (specifically esbuild optionally depends on @esbuild/android-arm which depends on esbuild-wasm) caused npm to be confused about what node_modules/.bin/esbuild is supposed to be.

    It's pretty strange and unexpected that disabling the installation of optional dependencies altogether would suddenly cause an optional dependency's dependency to conflict with the top-level package. What happens under the hood is that if --omit=optional is present, npm attempts to uninstall the esbuild-wasm nested dependency at the end of npm install (even though the esbuild-wasm package was never installed due to --omit=optional). This uninstallation causes node_modules/.bin/esbuild to be deleted.

    After doing a full investigation, I discovered that npm's handling of the .bin directory is deliberately very brittle. When multiple packages in the dependency tree put something in .bin with the same name, the end result is non-deterministic/random. What you get in .bin might be from one package, from the other package, or might be missing entirely. The workaround suggested by npm is to just avoid having two packages that put something in .bin with the same name. So this was fixed by making the @esbuild/android-arm and esbuild-android-64 packages each include another whole copy of the WebAssembly binary, which works because these packages don't put anything in .bin.

v0.15.8

Compare Source

  • Fix JSX name collision edge case (#​2534)

    Code generated by esbuild could have a name collision in the following edge case:

    • The JSX transformation mode is set to automatic, which causes import statements to be inserted
    • An element uses a {...spread} followed by a key={...}, which uses the legacy createElement fallback imported from react
    • Another import uses a name that ends with react such as @remix-run/react
    • The output format has been set to CommonJS so that import statements are converted into require calls

    In this case, esbuild previously generated two variables with the same name import_react, like this:

    var import_react = require("react");
    var import_react2 = require("@&#8203;remix-run/react");
    

    That bug is fixed in this release. The code generated by esbuild no longer contains a name collision.

  • Fall back to WebAssembly on Android ARM (#​1556, #​1578, #​2335, #​2526)

    Go's compiler supports trivial cross-compiling to almost all platforms without installing any additional software other than the Go compiler itself. This has made it very easy for esbuild to publish native binary executables for many platforms. However, it strangely doesn't support cross-compiling to Android ARM without installing the Android build tools.

    So instead of publishing a native esbuild binary executable to npm, this release publishes a WebAssembly fallback build. This is essentially the same as the esbuild-wasm package but it's installed automatically when you install the esbuild package on Android ARM. So packages that depend on the esbuild package should now work on Android ARM. This change has not yet been tested end-to-end because I don't have a 32-bit Android ARM device myself, but in theory it should work.

    This inherits the drawbacks of WebAssembly including significantly slower performance than native as well as potentially also more severe memory usage limitations and lack of certain features (e.g. --serve). If you want to use a native binary executable of esbuild on Android ARM, you may be able to build it yourself from source after installing the Android build tools.

  • Attempt to better support Yarn's ignorePatternData feature (#​2495)

    Part of resolving paths in a project using Yarn's Plug'n'Play feature involves evaluating a regular expression in the ignorePatternData property of .pnp.data.json. However, it turns out that the particular regular expressions generated by Yarn use some syntax that works with JavaScript regular expressions but that does not work with Go regular expressions.

    In this release, esbuild will now strip some of the the problematic syntax from the regular expression before compiling it, which should hopefully allow it to be compiled by Go's regular expression engine. The specific character sequences that esbuild currently strips are as follows:

    • (?!\.)
    • (?!(?:^|\/)\.)
    • (?!\.{1,2}(?:\/|$))
    • (?!(?:^|\/)\.{1,2}(?:\/|$))

    These seem to be used by Yarn to avoid the . and .. path segments in the middle of relative paths. The removal of these character sequences seems relatively harmless in this case since esbuild shouldn't ever generate such path segments. This change should add support to esbuild for Yarn's pnpIgnorePatterns feature.

  • Fix non-determinism issue with legacy block-level function declarations and strict mode (#​2537)

    When function declaration statements are nested inside a block in strict mode, they are supposed to only be available within that block's scope. But in "sloppy mode" (which is what non-strict mode is commonly called), they are supposed to be available within the whole function's scope:

    // This returns 1 due to strict mode
    function test1() {
      'use strict'
      function fn() { return 1 }
      if (true) { function fn() { return 2 } }
      return fn()
    }
    
    // This returns 2 due to sloppy mode
    function test2() {
      function fn() { return 1 }
      if (true) { function fn() { return 2 } }
      return fn()
    }
    

    To implement this, esbuild compiles these two functions differently to reflect their different semantics:

    function test1() {
      "use strict";
      function fn() {
        return 1;
      }
      if (true) {
        let fn2 = function() {
          return 2;
        };
      }
      return fn();
    }
    function test2() {
      function fn() {
        return 1;
      }
      if (true) {
        let fn2 = function() {
          return 2;
        };
        var fn = fn2;
      }
      return fn();
    }
    

    However, the compilation had a subtle bug where the automatically-generated function-level symbols for multible hoisted block-level function declarations in the same block a sloppy-mode context were generated in a random order if the output was in strict mode, which could be the case if TypeScript's alwaysStrict setting was set to true. This lead to non-determinism in the output as the minifier would randomly exchange the generated names for these symbols on different runs. This bug has been fixed by sorting the keys of the unordered map before iterating over them.

  • Fix parsing of @keyframes with string identifiers (#​2555)

    Firefox supports @keyframes with string identifier names. Previously this was treated as a syntax error by esbuild as it doesn't work in any other browser. The specification allows for this however, so it's technically not a syntax error (even though it would be unwise to use this feature at the moment). There was also a bug where esbuild would remove the identifier name in this case as the syntax wasn't recognized.

    This release changes esbuild's parsing of @keyframes to now consider this case to be an unrecognized CSS rule. That means it will be passed through unmodified (so you can now use esbuild to bundle this Firefox-specific CSS) but the CSS will not be pretty-printed or minified. I don't think it makes sense for esbuild to have special code to handle this Firefox-specific syntax at this time. This decision can be revisited in the future if other browsers add support for this feature.

  • Add the --jsx-side-effects API option (#​2539, #​2546)

    By default esbuild assumes that JSX expressions are side-effect free, which means they are annoated with /* @&#8203;__PURE__ */ comments and are removed during bundling when they are unused. This follows the common use of JSX for virtual DOM and applies to the vast majority of JSX libraries. However, some people have written JSX libraries that don't have this property. JSX expressions can have arbitrary side effects and can't be removed. If you are using such a library, you can now pass --jsx-side-effects to tell esbuild that JSX expressions have side effects so it won't remove them when they are unused.

    This feature was contributed by @​rtsao.

v0.15.7

Compare Source

  • Add --watch=forever to allow esbuild to never terminate (#​1511, #​1885)

    Currently using esbuild's watch mode via --watch from the CLI will stop watching if stdin is closed. The rationale is that stdin is automatically closed by the OS when the parent process exits, so stopping watch mode when stdin is closed ensures that esbuild's watch mode doesn't keep running forever after the parent process has been closed. For example, it would be bad if you wrote a shell script that did esbuild --watch & to run esbuild's watch mode in the background, and every time you run the script it creates a new esbuild process that runs forever.

    However, there are cases when it makes sense for esbuild's watch mode to never exit. One such case is within a short-lived VM where the lifetime of all processes inside the VM is expected to be the lifetime of the VM. Previously you could easily do this by piping the output of a long-lived command into esbuild's stdin such as sleep 999999999 | esbuild --watch &. However, this possibility often doesn't occur to people, and it also doesn't work on Windows. People also sometimes attempt to keep esbuild open by piping an infinite stream of data to esbuild such as with esbuild --watch </dev/zero & which causes esbuild to spin at 100% CPU. So with this release, esbuild now has a --watch=forever flag that will not stop watch mode when stdin is closed.

  • Work around PATH without node in install script (#​2519)

    Some people install esbuild's npm package in an environment without the node command in their PATH. This fails on Windows because esbuild's install script runs the esbuild command before exiting as a sanity check, and on Windows the esbuild command has to be a JavaScript file because of some internal details about how npm handles the bin folder (specifically the esbuild command lacks the .exe extension, which is required on Windows). This release attempts to work around this problem by using process.execPath instead of "node" as the command for running node. In theory this means the installer can now still function on Windows if something is wrong with PATH.

v0.15.6

Compare Source

  • Lower for await loops (#​1930)

    This release lowers for await loops to the equivalent for loop containing await when esbuild is configured such that for await loops are unsupported. This transform still requires at least generator functions to be supported since esbuild's lowering of await currently relies on generators. This new transformation is mostly modeled after what the TypeScript compiler does. Here's an example:

    async function f() {
      for await (let x of y)
        x()
    }
    

    The code above will now become the following code with --target=es2017 (omitting the code for the __forAwait helper function):

    async function f() {
      try {
        for (var iter = __forAwait(y), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
          let x = temp.value;
          x();
        }
      } catch (temp) {
        error = [temp];
      } finally {
        try {
          more && (temp = iter.return) && await temp.call(iter);
        } finally {
          if (error)
            throw error[0];
        }
      }
    }
    
  • Automatically fix invalid supported configurations (#​2497)

    The --target= setting lets you tell esbuild to target a specific version of one or more JavaScript runtimes such as chrome80,node14 and esbuild will restrict its output to only those features supported by all targeted JavaScript runtimes. More recently, esbuild introduced the --supported: setting that lets you override which features are supported on a per-feature basis. However, this now lets you configure nonsensical things such as --supported:async-await=false --supported:async-generator=true. Previously doing this could result in esbuild building successfully but producing invalid output.

    Starting with this release, esbuild will now attempt to automatically fix nonsensical feature override configurations by introducing more overrides until the configuration makes sense. So now the configuration from previous example will be changed such that async-await=false implies async-generator=false. The full list of implications that were introduced is below:

    • async-await=false implies:

      • async-generator=false
      • for-await=false
      • top-level-await=false
    • generator=false implies:

      • async-generator=false
    • object-accessors=false implies:

      • class-private-accessor=false
      • class-private-static-accessor=false
    • class-field=false implies:

      • class-private-field=false
    • class-static-field=false implies:

      • class-private-static-field=false
    • class=false implies:

      • class-field=false
      • class-private-accessor=false
      • class-private-brand-check=false
      • class-private-field=false
      • class-private-method=false
      • class-private-static-accessor=false
      • class-private-static-field=false
      • class-private-static-method=false
      • class-static-blocks=false
      • class-static-field=false
  • Implement a small minification improvement (#​2496)

    Some people write code that contains a label with an immediate break such as x: break x. Previously this code was not removed during minification but it will now be removed during minification starting with this release.

  • Fix installing esbuild via Yarn with enableScripts: false configured (#​2457)

    If esbuild is installed with Yarn with the enableScripts: false setting configured, then Yarn will not "unplug" the esbuild package (i.e. it will keep the entire package inside a .zip file). This messes with esbuild's library code that extracts the platform-specific binary executable because that code copies the binary executable into the esbuild package directory, and Yarn's .zip file system shim doesn't let you write to a directory inside of a .zip file. This release fixes this problem by writing to the node_modules/.cache/esbuild directory instead in this case. So you should now be able to use esbuild with Yarn when enableScripts: false is configured.

    This fix was contributed by @​jonaskuske.

v0.15.5

Compare Source

  • Fix issues with Yarn PnP and Yarn's workspaces feature (#​2476)

    This release makes sure esbuild works with a Yarn feature called workspaces. Previously esbuild wasn't tested in this scenario, but this scenario now has test coverage. Getting this to work involved further tweaks to esbuild's custom code for what happens after Yarn PnP's path resolution algorithm runs, which is not currently covered by Yarn's PnP specification. These tweaks also fix exports map resolution with Yarn PnP for non-empty subpaths, which wasn't previously working.

v0.15.4

Compare Source

  • Consider TypeScript import assignments to be side-effect free (#​2468)

    TypeScript has a legacy import syntax for working with TypeScript namespaces that looks like this:

    import { someNamespace } from './some-file'
    import bar = someNamespace.foo;
    
    // some-file.ts
    export namespace someNamespace {
      export let foo = 123
    }
    

    Since esbuild converts TypeScript into JavaScript one file at a time, it doesn't know if bar is supposed to be a value or a type (or both, which TypeScript actually allows in this case). This is problematic because values are supposed to be kept during the conversion but types are supposed to be removed during the conversion. Currently esbuild keeps bar in the output, which is done because someNamespace.foo is a property access and property accesses run code that could potentially have a side effect (although there is no side effect in this case).

    With this release, esbuild will now consider someNamespace.foo to have no side effects. This means bar will now be removed when bundling and when tree shaking is enabled. Note that it will still not be removed when tree shaking is disabled. This is because in this mode, esbuild supports adding additional code to the end of the generated output that's in the same scope as the module. That code could potentially make use of bar, so it would be incorrect to remove it. If you want bar to be removed, you'll have to enable tree shaking (which tells esbuild that nothing else depends on the unexported top-level symbols in the generated output).

  • Change the order of the banner and the "use strict" directive (#​2467)

    Previously the top of the file contained the following things in order:

    1. The hashbang comment (see below) from the source code, if present
    2. The "use strict" directive from the source code, if present
    3. The content of esbuild's banner API option, if specified

    This was problematic for people that used the banner API option to insert the hashbang comment instead of using esbuild's hashbang comment preservation feature. So with this release, the order has now been changed to:

    1. The hashbang comment (see below) from the source code, if present
    2. The content of esbuild's banner API option, if specified
    3. The "use strict" directive from the source code, if present

    I'm considering this change to be a bug fix instead of a breaking change because esbuild's documentation states that the banner API option can be used to "insert an arbitrary string at the beginning of generated JavaScript files". While this isn't technically true because esbuild may still insert the original hashbang comment before the banner, it's at least more correct now because the banner will now come before the "use strict" directive.

    For context: JavaScript files recently allowed using a hashbang comment, which starts with #! and which must start at the very first character of the file. It allows Unix systems to execute the file directly as a script without needing to prefix it by the node command. This comment typically has the value #!/usr/bin/env node. Hashbang comments will be a part of ES2023 when it's released next year.

  • Fix exports maps with Yarn PnP path resolution (#​2473)

    The Yarn PnP specification says that to resolve a package path, you first resolve it to the absolute path of a directory, and then you run node's module resolution algorithm on it. Previously esbuild followed this part of the specification. However, doing this means that exports in package.json is not respected because node's module resolution algorithm doesn't interpret exports for absolute paths. So with this release, esbuild will now use a modified algorithm that deviates from both specifications but that should hopefully behave more similar to what Yarn actually does: node's module resolution algorithm is run with the original import path but starting from the directory returned by Yarn PnP.

v0.15.3

Compare Source

  • Change the Yarn PnP manifest to a singleton (#​2463)

    Previously esbuild searched for the Yarn PnP manifest in the parent directories of each file. But with Yarn's enableGlobalCache setting it's possible to configure Yarn PnP's implementation to reach outside of the directory subtree containing the Yarn PnP manifest. This was causing esbuild to fail to bundle projects with the enableGlobalCache setting enabled.

    To handle this case, esbuild will now only search for the Yarn PnP manifest in the current working directory of the esbuild process. If you're using esbuild's CLI, this means you will now have to cd into the appropriate directory first. If you're using esbuild's API, you can override esbuild's value for the current working directory with the absWorkingDir API option.

  • Fix Yarn PnP resolution failures due to backslashes in paths on Windows (#​2462)

    Previously dependencies of a Yarn PnP virtual dependency failed to resolve on Windows. This was because Windows uses \ instead of / as a path separator, and the path manipulation algorithms used for Yarn PnP expected /. This release converts \ into / in Windows paths, which fixes this issue.

  • Fix sideEffects patterns containing slashes on Windows (#​2465)

    The sideEffects field in package.json lets you specify an array of patterns to mark which files have side effects (which causes all other files to be considered to not have side effects by exclusion). That looks like this:

    "sideEffects": [
      "**/index.js",
      "**/index.prod.js"
    ]
    

    However, the presence of the / character in the pattern meant that the pattern failed to match Windows-style paths, which broke sideEffects on Windows in this case. This release fixes this problem by adding additional code to handle Windows-style paths.

v0.15.2

Compare Source

  • Fix Yarn PnP issue with packages containing index.js (#​2455, #​2461)

    Yarn PnP's tests require the resolved paths to end in /. That's not how the rest of esbuild's internals work, however, and doing this messed up esbuild's node module path resolution regarding automatically-detected index.js files. Previously packages that relied on implicit index.js resolution rules didn't work with esbuild under Yarn PnP. Removing this slash has fixed esbuild's path resolution behavior regarding index.js, which should now the same both with and without Yarn PnP.

  • Fix Yarn PnP support for extends in tsconfig.json (#​2456)

    Previously using extends in tsconfig.json with a path in a Yarn PnP package didn't work. This is because the process of setting up package path resolution rules requires parsing tsconfig.json files (due to the baseUrl and paths features) and resolving extends to a package path requires package path resolution rules to already be set up, which is a circular dependency. This cycle is broken by using special rules for extends in tsconfig.json that bypasses esbuild's normal package path resolution process. This is why using extends with a Yarn PnP package didn't automatically work. With this release, these special rules have been modified to check for a Yarn PnP manifest so this case should work now.

  • Fix Yarn PnP support in esbuild-wasm (#​2458)

    When running esbuild via WebAssembly, Yarn PnP support previously failed because Go's file system internals return EINVAL when trying to read a .zip file as a directory when run with WebAssembly. This was unexpected because Go's file system internals return ENOTDIR for this case on native. This release updates esbuild to treat EINVAL like ENOTDIR in this case, which fixes using esbuild-wasm to bundle a Yarn PnP project.

    Note that to be able to use esbuild-wasm for Yarn PnP successfully, you currently have to run it using node instead of yarn node. This is because the file system shim that Yarn overwrites node's native file system API with currently generates invalid file descriptors with negative values when inside a .zip file. This prevents esbuild from working correctly because Go's file system internals don't expect syscalls that succeed without an error to return an invalid file descriptor. Yarn is working on fixing their use of invalid file descriptors.

v0.15.1

Compare Source

  • Update esbuild's Yarn Plug'n'Play implementation to match the latest specification changes (#​2452, #​2453)

    This release updates esbuild's implementation of Yarn Plug'n'Play to match some changes to Yarn's specification that just landed. The changes are as follows:

    • Check for platform-specific absolute paths instead of always for the / prefix

      The specification previously said that Yarn Plug'n'Play path resolution rules should not apply for paths that start with /. The intent was to avoid accidentally processing absolute paths. However, absolute paths on Windows such as C:\project start with drive letters instead of with /. So the specification was changed to instead explicitly avoid processing absolute paths.

    • Make $$virtual an alias for __virtual__

      Supporting Yarn-style path resolution requires implementing a custom Yarn-specific path traversal scheme where certain path segments are considered no-ops. Specifically any path containing segments of the form __virtual__/<whatever>/<n> where <n> is an integer must be treated as if they were n times the .. operator instead (the <whatever> path segment is ignored). So /path/to/project/__virtual__/xyz/2/foo.js maps to the underlying file /path/to/project/../../foo.js. This scheme makes it possible for Yarn to get node (and esbuild) to load the same file multiple times (which is sometimes required for correctness) without actually duplicating the file on the file system.

      However, old versions of Yarn used to use $$virtual instead of __virtual__. This was changed because $$virtual was error-prone due to the use of the $ character, which can cause bugs when it's not correctly escaped within regular expressions. Now that esbuild makes $$virtual an alias for __virtual__, esbuild should now work with manifests from these old Yarn versions.

    • Ignore PnP manifests in virtual directories

      The specification describes the algorithm for how to find the Plug'n'Play manifest when starting from a certain point in the file system: search through all parent directories in reverse order until the manifest is found. However, this interacts poorly with virtual paths since it can end up finding a virtual copy of the manifest instead of the original. To avoid this, esbuild now ignores manifests in virtual directories so that the search for the manifest will continue and find the original manifest in another parent directory later on.

    These fixes mean that esbuild's implementation of Plug'n'Play now matches Yarn's implementation more closely, and esbuild can now correctly build more projects that use Plug'n'Play.

v0.15.0

Compare Source

This release contains backwards-incompatible changes. Since esbuild is before version 1.0.0, these changes have been released as a new minor version to reflect this (as recommended by npm). You should either be pinning the exact version of esbuild in your package.json file or be using a version range syntax that only accepts patch upgrades such as ~0.14.0. See the documentation about semver for more information.

  • Implement the Yarn Plug'n'Play module resolution algorithm (#​154, #​237, #​1263, #​2451)

    Node comes with a package manager called npm, which installs packages into a node_modules folder. Node and esbuild both come with built-in rules for resolving import paths to packages within node_modules, so packages installed via npm work automatically without any configuration. However, many people use an alternative package manager called Yarn. While Yarn can install packages using node_modules, it also offers a different package installation strategy called Plug'n'Play, which is often shortened to "PnP" (not to be confused with pnpm, which is an entirely different unrelated package manager).

    Plug'n'Play installs packages as .zip files on your file system. The packages are never actually unzipped. Since Node doesn't know anything about Yarn's package installation strategy, this means you can no longer run your code with Node as it won't be able to find your packages. Instead, you need to run your code with Yarn, which applies patches to Node's file system APIs before running your code. These patches attempt to make zip files seem like normal directories. When running under Yarn, using Node's file system API to read ./some.zip/lib/file.js actually automatically extracts lib/file.js from ./some.zip at run-time as if it was a normal file. Other file system APIs behave similarly. However, these patches don't work with esbuild because esbuild is not written in JavaScript; it's a native binary executable that interacts with the file system directly through the operating system.

    Previously the workaround for using esbuild with Plug'n'Play was to use the @yarnpkg/esbuild-plugin-pnp plugin with esbuild's JavaScript API. However, this wasn't great because the plugin needed to potentially intercept every single import path and file load to check whether it was a Plug'n'Play package, which has an unusually high performance cost. It also meant that certain subtleties of path resolution rules within a .zip file could differ slightly from the way esbuild normally works since path resolution inside .zip files was implemented by Yarn, not by esbuild (which is due to a limitation of esbuild's plugin API).

    With this release, esbuild now contains an independent implementation of Yarn's Plug'n'Play algorithm (which is used when esbuild finds a .pnp.js, .pnp.cjs, or .pnp.data.json file in the directory tree). Creating additional implementations of this algorithm recently became possible because Yarn's package manifest format was recently documented: https://yarnpkg.com/advanced/pnp-spec/. This should mean that you can now use esbuild to bundle Plug'n'Play projects without any additional configuration (so you shouldn't need @yarnpkg/esbuild-plugin-pnp anymore). Bundling these projects should now happen much faster as Yarn no longer even needs to be run at all. Bundling the Yarn codebase itself with esbuild before and after this change seems to demonstrate over a 10x speedup (3.4s to 0.24s). And path resolution rules within Yarn packages should now be consistent with how esbuild handles regular Node packages. For example, fields such as module and browser in package.json files within .zip files should now be respected.

    Keep in mind that this is brand new code and there may be some initial issues to work through before esbuild's implementation is solid. Yarn's Plug'n'Play specification is also brand new and may need some follow-up edits to guide new implementations to match Yarn's exact behavior. If you try this out, make sure to test it before committing to using it, and let me know if anything isn't working as expected. Should you need to debug esbuild's path resolution, you may find --log-level=verbose helpful.

v0.14.54

Compare Source

  • Fix optimizations for calls containing spread arguments (#​2445)

    This release fixes the handling of spread arguments in the optimization of /* @&#8203;__PURE__ */ comments, empty functions, and identity functions:

    // Original code
    function empty() {}
    function identity(x) { return x }
    /* @&#8203;__PURE__ */ a(...x)
    /* @&#8203;__PURE__ */ new b(...x)
    empty(...x)
    identity(...x)
    
    // Old output (with --minify --tree-shaking=true)
    ...x;...x;...x;...x;
    
    // New output (with --minify --tree-shaking=true)
    function identity(n){return n}[...x];[...x];[...x];identity(...x);
    

    Previously esbuild assumed arguments with side effects could be directly inlined. This is almost always true except for spread arguments, which are not syntactically valid on their own and which have the side effect of causing iteration, which might have further side effects. Now esbuild will wrap these elements in an unused array so that they are syntactically valid and so that the iteration side effects are preserved.

v0.14.53

Compare Source

This release fixes a minor issue with the previous release: I had to rename the package esbuild-linux-loong64 to @esbuild/linux-loong64 in the contributed PR because someone registered the package name before I could claim it, and I missed a spot. Hopefully everything is working after this release. I plan to change all platform-specific package names to use the @esbuild/ scope at some point to avoid this problem in the future.

v0.14.52

Compare Source

  • Allow binary data as input to the JS transform and build APIs (#​2424)

    Previously esbuild's transform and build APIs could only take a string. However, some people want to use esbuild to convert binary data to base64 text. This is problematic because JavaScript strings represent UTF-16 text and esbuild internally operates on arrays of bytes, so all strings coming from JavaScript undergo UTF-16 to UTF-8 conversion before use. This meant that using esbuild in this way was doing base64 encoding of the UTF-8 encoding of the text, which was undesired.

    With this release, esbuild now accepts Uint8Array in addition to string as an input format for the transform and build APIs. Now you can use esbuild to convert binary data to base64 text:

    // Original code
    import esbuild from 'esbuild'
    console.log([
      (await esbuild.transform('\xFF', { loader: 'base64' })).code,
      (await esbuild.build({ stdin: { contents: '\xFF', loader: 'base64' }, write: false })).outputFiles[0].text,
    ])
    console.log([
      (await esbuild.transform(new Uint8Array([0xFF]), { loader: 'base64' })).code,
      (await esbuild.build({ stdin: { contents: new Uint8Array([0xFF]), loader: 'base64' }, write: false })).outputFiles[0].text,
    ])
    
    // Old output
    [ 'module.exports = "w78=";\n', 'module.exports = "w78=";\n' ]
    /* ERROR: The input to "transform" must be a string */
    
    // New output
    [ 'module.exports = "w78=";\n', 'module.exports = "w78=";\n' ]
    [ 'module.exports = "/w==";\n', 'module.exports = "/w==";\n' ]
    
  • Update the getter for text in build results (#​2423)

    Output files in build results returned from esbuild's JavaScript API have both a contents and a text property to return the contents of the output file. The contents property is a binary UTF-8 Uint8Array and the text property is a JavaScript UTF-16 string. The text property is a getter that does the UTF-8 to UTF-16 conversion only if it's needed for better performance.

    Previously if you mutate the build results object, you had to overwrite both contents and text since the value returned from the text getter is the original text returned by esbuild. Some people find this confusing so with this release, the getter for text has been updated to do the UTF-8 to UTF-16 conversion on the current value of the contents property instead of the original value.

  • Publish builds for Linux LoongArch 64-bit (#​1804, #​2373)

    This release upgrades to Go 1.19, which now includes support for LoongArch 64-bit processors. LoongArch 64-bit builds of esbuild will now be published to npm, which means that in theory they can now be installed with npm install esbuild. This was contributed by @​beyond-1234.

v0.14.51

Compare Source

  • Add support for React 17's automatic JSX transform (#​334, #​718, #​1172, #​2318, #​2349)

    This adds support for the new "automatic" JSX runtime from React 17+ to esbuild for both the build and transform APIs.

    New CLI flags and API options:

    • --jsx, jsx — Set this to "automatic" to opt in to this new transform
    • --jsx-dev, jsxDev — Toggles development mode for the automatic runtime
    • --jsx-import-source, jsxImportSource — Overrides the root import for runtime functions (default "react")

    New JSX pragma comments:

    • @jsxRuntime — Sets the runtime (automatic or classic)
    • @jsxImportSource — Sets the import source (only valid with automatic runtime)

    The existing @jsxFragment and @jsxFactory pragma comments are only valid with "classic" runtime.

    TSConfig resolving:
    Along with accepting the new options directly via CLI or API, option inference from tsconfig.json compiler options was also implemented:

    • "jsx": "preserve" or "jsx": "react-native" → Same as --jsx=preserve in esbuild
    • "jsx": "react" → Same as --jsx=transform in esbuild (which is the default behavior)
    • "jsx": "react-jsx" → Same as --jsx=automatic in esbuild
    • "jsx": "react-jsxdev" → Same as --jsx=automatic --jsx-dev in esbuild

    It also reads the value of "jsxImportSource" from tsconfig.json if specified.

    For react-jsx it's important to note that it doesn't implicitly disable --jsx-dev. This is to support the case where a user sets "react-jsx" in their tsconfig.json but then toggles development mode directly in esbuild.

    esbuild vs Babel vs TS vs...

    There are a few differences between the various technologies that implement automatic JSX runtimes. The JSX transform in esbuild follows a mix of Babel's and TypeScript's behavior:

    • When an element has __source or __self props:

      • Babel: Print an error about a deprecated transform plugin
      • TypeScript: Allow the props
      • swc: Hard crash
      • esbuild: Print an error — Following Babel was chosen for this one because this might help people catch configuration issues where JSX files are being parsed by multiple tools
    • Element has an "implicit true" key prop, e.g. <a key />:

      • Babel: Print an error indicating that "key" props require an explicit value
      • TypeScript: Silently omit the "key" prop
      • swc: Hard crash
      • esbuild: Print an error like Babel — This might help catch legitimate programming mistakes
    • Element has spread children, e.g. <a>{...children}</a>

      • Babel: Print an error stating that React doesn't support spread children
      • TypeScript: Use static jsx function and pass children as-is, including spread operator
      • swc: same as Babel
      • esbuild: Same as TypeScript

    Also note that TypeScript has some bugs regarding JSX development mode and the generation of lineNumber and columnNumber values. Babel's values are accurate though, so esbuild's line and column numbers match Babel. Both numbers are 1-based and columns are counted in terms of UTF-16 code units.

    This feature was contributed by @​jgoz.

v0.14.50

Compare Source

  • Emit names in source maps (#​1296)

    The source map specification includes an optional names field that can associate an identifier with a mapping entry. This can be used to record the original name for an identifier, which is useful if the identifier was renamed to something else in the generated code. When esbuild was originally written, this field wasn't widely used, but now there are some debuggers that make use of it to provide better debugging of minified code. With this release, esbuild now includes a names field in the source maps that it generates. To save space, the original name is only recorded when it's different from the final name.

  • Update parser for arrow functions with initial default type parameters in .tsx files (#​2410)

    TypeScript 4.6 introduced a change to the parsing of JSX syntax in .tsx files. Now a < token followed by an identifier and then a = token is parsed as an arrow function with a default type parameter instead of as a JSX element. This release updates esbuild's parser to match TypeScript's parser.

  • Fix an accidental infinite loop with --define substitution (#​2407)

    This is a fix for a regression that was introduced in esbuild version 0.14.44 where certain --define substitutions could result in esbuild crashing with a stack overflow. The problem was an incorrect fix for #​2292. The fix merged the code paths for --define and --jsx-factory rewriting since the value substitution is now the same for both. However, doing this accidentally made --define substitution recursive since the JSX factory needs to be able to match against --define substitutions to integrate with the --inject feature. The fix is to only do one additional level of matching against define substitutions, and to only do this for JSX factories. Now these cases are able to build successfully without a stack overflow.

  • Include the "public path" value in hashes (#​2403)

    The --public-path= configuration value affects the paths that esbuild uses to reference files from other files and is used in various situations such as cross-chunk imports in JS and references to asset files from CSS files. However, it wasn't included in the hash calculations used for file names due to an oversight. This meant that changing the public path setting incorrectly didn't result in the hashes in file names changing even though the contents of the files changed. This release fixes the issue by including a hash of the public path in all non-asset output files.

  • Fix a cross-platform consistency bug (#​2383)

    Previously esbuild would minify 0xFFFF_FFFF_FFFF_FFFF as 0xffffffffffffffff (18 bytes) on arm64 chips and as 18446744073709552e3 (19 bytes) on x86_64 chips. The reason was that the number was converted to a 64-bit unsigned integer internally for printing as hexadecimal, the 64-bit floating-point number 0xFFFF_FFFF_FFFF_FFFF is actually 0x1_0000_0000_0000_0180 (i.e. it's rounded up, not down), and converting float64 to uint64 is implementation-dependent in Go when the input is out of bounds. This was fixed by changing the upper limit for which esbuild uses hexadecimal numbers during minification to 0xFFFF_FFFF_FFFF_F800, which is the next representable 64-bit floating-point number below 0x1_0000_0000_0000_0180, and which fits in a uint64. As a result, esbuild will now consistently never minify 0xFFFF_FFFF_FFFF_FFFF as 0xffffffffffffffff anymore, which means the output should now be consistent across platforms.

  • Fix a hang with the synchronous API when the package is corrupted (#​2396)

    An error message is already thrown when the esbuild package is corrupted and esbuild can't be run. However, if you are using a synchronous call in the JavaScript API in worker mode, esbuild will use a child worker to initialize esbuild once so that the overhead of initializing esbuild can be amortized across multiple synchronous API calls. However, errors thrown during initialization weren't being propagated correctly which resulted in a hang while the main thread waited forever for the child worker to finish initializing. With this release, initialization errors are now propagated correctly so calling a synchronous API call when the package is corrupted should now result in an error instead of a hang.

  • Fix tsconfig.json files that collide with directory names (#​2411)

    TypeScript lets you write tsconfig.json files with extends clauses that refer to another config file using an implicit .json file extension. However, if the config file without the .json extension existed as a directory name, esbuild and TypeScript had different behavior. TypeScript ignores the directory and continues looking for the config file by adding the .json extension while esbuild previously terminated the search and then failed to load the config file (because it's a directory). With this release, esbuild will now ignore exact matches when resolving extends fields in tsconfig.json files if the exact match results in a directory.

  • Add platform to the transform API (#​2362)

    The platform option is mainly relevant for bundling because it mostly affects path resolution (e.g. activating the "browser" field in package.json files), so it was previously only available for the build API. With this release, it has additionally be made available for the transform API for a single reason: you can now set --platform=node when transforming a string so that esbuild will add export annotations for node, which is only relevant when --format=cjs is also present.

    This has to do with an implementation detail of node that parses the AST of CommonJS files to discover named exports when importing CommonJS from ESM. However, this new addition to esbuild's API is of questionable usefulness. Node's loader API (the main use case for using esbuild's transform API like this) actually bypasses the content returned from the loader and parses the AST that's present on the file system, so you won't actually be able to use esbuild's API for this. See the linked issue for more information.

v0.14.49

Compare Source

  • Keep inlined constants when direct eval is present (#​2361)

    Version 0.14.19 of esbuild added inlining of certain const variables during minification, which replaces all references to the variable with the initializer and then removes the variable declaration. However, this could generate incorrect code when direct eval is present because the direct eval could reference the constant by name. This release fixes the problem by preserving the const variable declaration in this case:

    // Original code
    console.log((() => { const x = 123; return x + eval('x') }))
    
    // Old output (with --minify)
    console.log(()=>123+eval("x"));
    
    // New output (with --minify)
    console.log(()=>{const x=123;return 123+eval("x")});
    
  • Fix an incorrect error in TypeScript when targeting ES5 (#​2375)

    Previously when compiling TypeScript code to ES5, esbuild could incorrectly consider the following syntax forms as a transformation error:

    0 ? ([]) : 1 ? ({}) : 2;
    

    The error messages looked like this:

    ✘ [ERROR] Transforming destructuring to the configured target environment ("es5") is not supported yet
    
        example.ts:1:5:
          1 │ 0 ? ([]) : 1 ? ({}) : 2;
            ╵      ^
    
    ✘ [ERROR] Transforming destructuring to the configured target environment ("es5") is not supported yet
    
        example.ts:1:16:
          1 │ 0 ? ([]) : 1 ? ({}) : 2;
            ╵                 ^
    

    These parenthesized literals followed by a colon look like the start of an arrow function expression followed by a TypeScript return type (e.g. ([]) : 1 could be the start of the TypeScript arrow function ([]): 1 => 1). Unlike in JavaScript, parsing arrow functions in TypeScript requires backtracking. In this case esbuild correctly determined that this expression wasn't an arrow function after all but the check for destructuring was incorrectly not covered under the backtracking process. With this release, the error message is now only reported if the parser successfully parses an arrow function without backtracking.

  • Fix generated TypeScript enum comments containing */ (#​2369, #​2371)

    TypeScript enum values that are equal to a number or string literal are inlined (references to the enum are replaced with the literal value) and have a /* ... */ comment after them with the original enum name to improve readability. However, this comment is omitted if the enum name contains the character sequence */ because that would end the comment early and cause a syntax error:

    // Original TypeScript
    enum Foo { '/*' = 1, '*/' = 2 }
    console.log(Foo['/*'], Foo['*/'])
    
    // Generated JavaScript
    console.log(1 /* /* */, 2);
    

    This was originally handled correctly when TypeScript enum inlining was initially implemented since it was only supported within a single file. However, when esbuild was later extended to support TypeScript enum inlining across files, this special case where the enum name contains */ was not handled in that new code. Starting with this release, esbuild will now handle enums with names containing */ correctly when they are inlined across files:

    // foo.ts
    export enum Foo { '/*' = 1, '*/' = 2 }
    
    // bar.ts
    import { Foo } from './foo'
    console.log(Foo['/*'], Foo['*/'])
    
    // Old output (with --bundle --format=esm)
    console.log(1 /* /* */, 2 /* */ */);
    
    // New output (with --bundle --format=esm)
    console.log(1 /* /* */, 2);
    

    This fix was contributed by @​magic-akari.

  • Allow declare class fields to be initialized (#​2380)

    This release fixes an oversight in the TypeScript parser that disallowed initializers for declare class fields. TypeScript actually allows the following limited initializer expressions for readonly fields:

    declare const enum a { b = 0 }
    
    class Foo {
      // These are allowed by TypeScript
      declare readonly a = 0
      declare readonly b = -0
      declare readonly c = 0n
      declare readonly d = -0n
      declare readonly e = 'x'
      declare readonly f = `x`
      declare readonly g = a.b
      declare readonly h = a['b']
    
      // These are not allowed by TypeScript
      declare readonly x = (0)
      declare readonly y = null
      declare readonly z = -a.b
    }
    

    So with this release, esbuild now allows initializers for declare class fields too. To future-proof this in case TypeScript allows more expressions as initializers in the future (such as null), esbuild will allow any expression as an initializer and will leave the specifics of TypeScript's special-casing here to the TypeScript type checker.

  • Fix a bug in esbuild's feature compatibility table generator (#​2365)

    Passing specific JavaScript engines to esbuild's --target flag restricts esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates. The data for this feature is automatically derived from this compatibility table with a script: https://kangax.github.io/compat-table/.

    However, the script had a bug that could incorrectly consider a JavaScript syntax feature to be supported in a given engine even when it doesn't actually work in that engine. Specifically this bug happened when a certain aspect of JavaScript syntax has always worked incorrectly in that engine and the bug in that engine has never been fixed. This situation hasn't really come up before because previously esbuild pretty much only targeted JavaScript engines that always fix their bugs, but the two new JavaScript engines that were added in the previous release (Hermes and Rhino) have many aspects of the JavaScript specification that have never been implemented, and may never be implemented. For example, the let and const keywords are not implemented correctly in those engines.

    With this release, esbuild's compatibility table generator script has been fixed and as a result, esbuild will now correctly consider a JavaScript syntax feature to be unsupported in a given engine if there is some aspect of that syntax that is broken in all known versions of that engine. This means that the following JavaScript syntax features are no longer considered to be supported by these engines (represented using esbuild's internal names for these syntax features):

    Hermes:

    • arrow
    • const-and-let
    • default-argument
    • generator
    • optional-catch-binding
    • optional-chain
    • rest-argument
    • template-literal

    Rhino:

    • arrow
    • const-and-let
    • destructuring
    • for-of
    • generator
    • object-extensions
    • template-literal

    IE:

    • const-and-let

v0.14.48

Compare Source

  • Enable using esbuild in Deno via WebAssembly (#​2323)

    The native implementation of esbuild is much faster than the WebAssembly version, but some people don't want to give Deno the --allow-run permission necessary to run esbuild and are ok waiting longer for their builds to finish when using the WebAssembly backend. With this release, you can now use esbuild via WebAssembly in Deno. To do this you will need to import from wasm.js instead of mod.js:

    import * as esbuild from 'https://deno.land/x/esbuild@v0.14.48/wasm.js'
    const ts = 'let test: boolean = true'
    const result = await esbuild.transform(ts, { loader: 'ts' })
    console.log('result:', result)
    

    Make sure you run Deno with --allow-net so esbuild can download the WebAssembly module. Using esbuild like this starts up a worker thread that runs esbuild in parallel (unless you call esbuild.initialize({ worker: false }) to tell esbuild to run on the main thread). If you want to, you can call esbuild.stop() to terminate the worker if you won't be using esbuild anymore and you want to reclaim the memory.

    Note that Deno appears to have a bug where background WebAssembly optimization can prevent the process from exiting for many seconds. If you are trying to use Deno and WebAssembly to run esbuild quickly, you may need to manually call Deno.exit(0) after your code has finished running.

  • Add support for font file MIME types (#​2337)

    This release adds support for font file MIME types to esbuild, which means they are now recognized by the built-in local web server and they are now used when a font file is loaded using the dataurl loader. The full set of newly-added file extension MIME type mappings is as follows:

    • .eot => application/vnd.ms-fontobject
    • .otf => font/otf
    • .sfnt => font/sfnt
    • .ttf => font/ttf
    • .woff => font/woff
    • .woff2 => font/woff2
  • Remove "use strict"; when targeting ESM (#​2347)

    All ES module code is automatically in strict mode, so a "use strict"; directive is unnecessary. With this release, esbuild will now remove the "use strict"; directive if the output format is ESM. This change makes the generated output file a few bytes smaller:

    // Original code
    'use strict'
    export let foo = 123
    
    // Old output (with --format=esm --minify)
    "use strict";let t=123;export{t as foo};
    
    // New output (with --format=esm --minify)
    let t=123;export{t as foo};
    
  • Attempt to have esbuild work with Deno on FreeBSD (#​2356)

    Deno doesn't support FreeBSD, but it's possible to build Deno for FreeBSD with some additional patches on top. This release of esbuild changes esbuild's Deno installer to download esbuild's FreeBSD binary in this situation. This configuration is unsupported although in theory everything should work.

  • Add some more target JavaScript engines (#​2357)

    This release adds the Rhino and Hermes JavaScript engines to the set of engine identifiers that can be passed to the --target flag. You can use this to restrict esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates.


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 becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [esbuild](https://github.com/evanw/esbuild) | devDependencies | minor | [`0.14.47` -> `0.18.0`](https://renovatebot.com/diffs/npm/esbuild/0.14.47/0.18.0) | --- ### Release Notes <details> <summary>evanw/esbuild</summary> ### [`v0.18.0`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0180) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.19...v0.18.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.17.0` or `~0.17.0`. See npm's documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. The breaking changes in this release mainly focus on fixing some long-standing issues with esbuild's handling of `tsconfig.json` files. Here are all the changes in this release, in detail: - Add a way to try esbuild online ([#&#8203;797](https://github.com/evanw/esbuild/issues/797)) There is now a way to try esbuild live on esbuild's website without installing it: https://esbuild.github.io/try/. In addition to being able to more easily evaluate esbuild, this should also make it more efficient to generate esbuild bug reports. For example, you can use it to compare the behavior of different versions of esbuild on the same input. The state of the page is stored in the URL for easy sharing. Many thanks to [@&#8203;hyrious](https://github.com/hyrious) for creating https://hyrious.me/esbuild-repl/, which was the main inspiration for this addition to esbuild's website. Two forms of build options are supported: either CLI-style ([example](https://esbuild.github.io/try/#dAAwLjE3LjE5AC0tbG9hZGVyPXRzeCAtLW1pbmlmeSAtLXNvdXJjZW1hcABsZXQgZWw6IEpTWC5FbGVtZW50ID0gPGRpdiAvPg)) or JS-style ([example](https://esbuild.github.io/try/#dAAwLjE3LjE5AHsKICBsb2FkZXI6ICd0c3gnLAogIG1pbmlmeTogdHJ1ZSwKICBzb3VyY2VtYXA6IHRydWUsCn0AbGV0IGVsOiBKU1guRWxlbWVudCA9IDxkaXYgLz4)). Both are converted into a JS object that's passed to esbuild's WebAssembly API. The CLI-style argument parser is a custom one that simulates shell quoting rules, and the JS-style argument parser is also custom and parses a superset of JSON (basically JSON5 + regular expressions). So argument parsing is an approximate simulation of what happens for real but hopefully it should be close enough. - Changes to esbuild's `tsconfig.json` support ([#&#8203;3019](https://github.com/evanw/esbuild/issues/3019)): This release makes the following changes to esbuild's `tsconfig.json` support: - Using experimental decorators now requires `"experimentalDecorators": true` ([#&#8203;104](https://github.com/evanw/esbuild/issues/104)) Previously esbuild would always compile decorators in TypeScript code using TypeScript's experimental decorator transform. Now that standard JavaScript decorators are close to being finalized, esbuild will now require you to use `"experimentalDecorators": true` to do this. This new requirement makes it possible for esbuild to introduce a transform for standard JavaScript decorators in TypeScript code in the future. Such a transform has not been implemented yet, however. - TypeScript's `target` no longer affects esbuild's `target` ([#&#8203;2628](https://github.com/evanw/esbuild/issues/2628)) Some people requested that esbuild support TypeScript's `target` setting, so support for it was added (in [version 0.12.4](https://github.com/evanw/esbuild/releases/v0.12.4)). However, esbuild supports reading from multiple `tsconfig.json` files within a single build, which opens up the possibility that different files in the build have different language targets configured. There isn't really any reason to do this and it can lead to unexpected results. So with this release, the `target` setting in `tsconfig.json` will no longer affect esbuild's own `target` setting. You will have to use esbuild's own target setting instead (which is a single, global value). - TypeScript's `jsx` setting no longer causes esbuild to preserve JSX syntax ([#&#8203;2634](https://github.com/evanw/esbuild/issues/2634)) TypeScript has a setting called [`jsx`](https://www.typescriptlang.org/tsconfig#jsx) that controls how to transform JSX into JS. The tool-agnostic transform is called `react`, and the React-specific transform is called `react-jsx` (or `react-jsxdev`). There is also a setting called `preserve` which indicates JSX should be passed through untransformed. Previously people would run esbuild with `"jsx": "preserve"` in their `tsconfig.json` files and then be surprised when esbuild preserved their JSX. So with this release, esbuild will now ignore `"jsx": "preserve"` in `tsconfig.json` files. If you want to preserve JSX syntax with esbuild, you now have to use `--jsx=preserve`. Note: Some people have suggested that esbuild's equivalent `jsx` setting override the one in `tsconfig.json`. However, some projects need to legitimately have different files within the same build use different transforms (i.e. `react` vs. `react-jsx`) and having esbuild's global `jsx` setting override `tsconfig.json` would prevent this from working. This release ignores `"jsx": "preserve"` but still allows other `jsx` values in `tsconfig.json` files to override esbuild's global `jsx` setting to keep the ability for multiple files within the same build to use different transforms. - `useDefineForClassFields` behavior has changed ([#&#8203;2584](https://github.com/evanw/esbuild/issues/2584), [#&#8203;2993](https://github.com/evanw/esbuild/issues/2993)) Class fields in TypeScript look like this (`x` is a class field): ```js class Foo { x = 123 } ``` TypeScript has legacy behavior that uses assignment semantics instead of define semantics for class fields when [`useDefineForClassFields`](https://www.typescriptlang.org/tsconfig#useDefineForClassFields) is enabled (in which case class fields in TypeScript behave differently than they do in JavaScript, which is arguably "wrong"). This legacy behavior exists because TypeScript added class fields to TypeScript before they were added to JavaScript. The TypeScript team decided to go with assignment semantics and shipped their implementation. Much later on TC39 decided to go with define semantics for class fields in JavaScript instead. This behaves differently if the base class has a setter with the same name: ```js class Base { set x(_) { console.log('x:', _) } } // useDefineForClassFields: false class AssignSemantics extends Base { constructor() { super() this.x = 123 } } // useDefineForClassFields: true class DefineSemantics extends Base { constructor() { super() Object.defineProperty(this, 'x', { value: 123 }) } } console.log( new AssignSemantics().x, // Calls the setter new DefineSemantics().x // Doesn't call the setter ) ``` When you run `tsc`, the value of `useDefineForClassFields` defaults to `false` when it's not specified and the `target` in `tsconfig.json` is present but earlier than `ES2022`. This sort of makes sense because the class field language feature was added in ES2022, so before ES2022 class fields didn't exist (and thus TypeScript's legacy behavior is active). However, TypeScript's `target` setting currently defaults to `ES3` which unfortunately means that the `useDefineForClassFields` setting currently defaults to false (i.e. to "wrong"). In other words if you run `tsc` with all default settings, class fields will behave incorrectly. Previously esbuild tried to do what `tsc` did. That meant esbuild's version of `useDefineForClassFields` was `false` by default, and was also `false` if esbuild's `--target=` was present but earlier than `es2022`. However, TypeScript's legacy class field behavior is becoming increasingly irrelevant and people who expect class fields in TypeScript to work like they do in JavaScript are confused when they use esbuild with default settings. It's also confusing that the behavior of class fields would change if you changed the language target (even though that's exactly how TypeScript works). So with this release, esbuild will now only use the information in `tsconfig.json` to determine whether `useDefineForClassFields` is true or not. Specifically `useDefineForClassFields` will be respected if present, otherwise it will be `false` if `target` is present in `tsconfig.json` and is `ES2021` or earlier, otherwise it will be `true`. Targets passed to esbuild's `--target=` setting will no longer affect `useDefineForClassFields`. Note that this means different directories in your build can have different values for this setting since esbuild allows different directories to have different `tsconfig.json` files within the same build. This should let you migrate your code one directory at a time without esbuild's `--target=` setting affecting the semantics of your code. - Add support for `verbatimModuleSyntax` from TypeScript 5.0 TypeScript 5.0 added a new option called [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax) that deprecates and replaces two older options, `preserveValueImports` and `importsNotUsedAsValues`. Setting `verbatimModuleSyntax` to true in `tsconfig.json` tells esbuild to not drop unused import statements. Specifically esbuild now treats `"verbatimModuleSyntax": true` as if you had specified both `"preserveValueImports": true` and `"importsNotUsedAsValues": "preserve"`. - Add multiple inheritance for `tsconfig.json` from TypeScript 5.0 TypeScript 5.0 now allows [multiple inheritance for `tsconfig.json` files](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#supporting-multiple-configuration-files-in-extends). You can now pass an array of filenames via the `extends` parameter and your `tsconfig.json` will start off containing properties from all of those configuration files, in order. This release of esbuild adds support for this new TypeScript feature. - Remove support for `moduleSuffixes` ([#&#8203;2395](https://github.com/evanw/esbuild/issues/2395)) The community has requested that esbuild remove support for TypeScript's `moduleSuffixes` feature, so it has been removed in this release. Instead you can use esbuild's `--resolve-extensions=` feature to select which module suffix you want to build with. - Apply `--tsconfig=` overrides to `stdin` and virtual files ([#&#8203;385](https://github.com/evanw/esbuild/issues/385), [#&#8203;2543](https://github.com/evanw/esbuild/issues/2543)) When you override esbuild's automatic `tsconfig.json` file detection with `--tsconfig=` to pass a specific `tsconfig.json` file, esbuild previously didn't apply these settings to source code passed via the `stdin` API option or to TypeScript files from plugins that weren't in the `file` namespace. This release changes esbuild's behavior so that settings from `tsconfig.json` also apply to these source code files as well. - Support `--tsconfig-raw=` in build API calls ([#&#8203;943](https://github.com/evanw/esbuild/issues/943), [#&#8203;2440](https://github.com/evanw/esbuild/issues/2440)) Previously if you wanted to override esbuild's automatic `tsconfig.json` file detection, you had to create a new `tsconfig.json` file and pass the file name to esbuild via the `--tsconfig=` flag. With this release, you can now optionally use `--tsconfig-raw=` instead to pass the contents of `tsconfig.json` to esbuild directly instead of passing the file name. For example, you can now use `--tsconfig-raw={"compilerOptions":{"experimentalDecorators":true}}` to enable TypeScript experimental decorators directly using a command-line flag (assuming you escape the quotes correctly using your current shell's quoting rules). The `--tsconfig-raw=` flag previously only worked with transform API calls but with this release, it now works with build API calls too. - Ignore all `tsconfig.json` files in `node_modules` ([#&#8203;276](https://github.com/evanw/esbuild/issues/276), [#&#8203;2386](https://github.com/evanw/esbuild/issues/2386)) This changes esbuild's behavior that applies `tsconfig.json` to all files in the subtree of the directory containing `tsconfig.json`. In version 0.12.7, esbuild started ignoring `tsconfig.json` files inside `node_modules` folders. The rationale is that people typically do this by mistake and that doing this intentionally is a rare use case that doesn't need to be supported. However, this change only applied to certain syntax-specific settings (e.g. `jsxFactory`) but did not apply to path resolution settings (e.g. `paths`). With this release, esbuild will now ignore all `tsconfig.json` files in `node_modules` instead of only ignoring certain settings. - Ignore `tsconfig.json` when resolving paths within `node_modules` ([#&#8203;2481](https://github.com/evanw/esbuild/issues/2481)) Previously fields in `tsconfig.json` related to path resolution (e.g. `paths`) were respected for all files in the subtree containing that `tsconfig.json` file, even within a nested `node_modules` subdirectory. This meant that a project's `paths` settings could potentially affect any bundled packages. With this release, esbuild will no longer use `tsconfig.json` settings during path resolution inside nested `node_modules` subdirectories. - Prefer `.js` over `.ts` within `node_modules` ([#&#8203;3019](https://github.com/evanw/esbuild/issues/3019)) The default list of implicit extensions that esbuild will try appending to import paths contains `.ts` before `.js`. This makes it possible to bundle TypeScript projects that reference other files in the project using extension-less imports (e.g. `./some-file` to load `./some-file.ts` instead of `./some-file.js`). However, this behavior is undesirable within `node_modules` directories. Some package authors publish both their original TypeScript code and their compiled JavaScript code side-by-side. In these cases, esbuild should arguably be using the compiled JavaScript files instead of the original TypeScript files because the TypeScript compilation settings for files within the package should be determined by the package author, not the user of esbuild. So with this release, esbuild will now prefer implicit `.js` extensions over `.ts` when searching for import paths within `node_modules`. These changes are intended to improve esbuild's compatibility with `tsc` and reduce the number of unfortunate behaviors regarding `tsconfig.json` and esbuild. - Add a workaround for bugs in Safari 16.2 and earlier ([#&#8203;3072](https://github.com/evanw/esbuild/issues/3072)) Safari's JavaScript parser had a bug (which has now been fixed) where at least something about unary/binary operators nested inside default arguments nested inside either a function or class expression was incorrectly considered a syntax error if that expression was the target of a property assignment. Here are some examples that trigger this Safari bug: ❱ x(function (y = -1) {}.z = 2) SyntaxError: Left hand side of operator '=' must be a reference. ❱ x(class { f(y = -1) {} }.z = 2) SyntaxError: Left hand side of operator '=' must be a reference. It's not clear what the exact conditions are that trigger this bug. However, a workaround for this bug appears to be to post-process your JavaScript to wrap any in function and class declarations that are the direct target of a property access expression in parentheses. That's the workaround that UglifyJS applies for this issue: [mishoo/UglifyJS#&#8203;2056](https://github.com/mishoo/UglifyJS/pull/2056). So that's what esbuild now does starting with this release: ```js // Original code x(function (y = -1) {}.z = 2, class { f(y = -1) {} }.z = 2) // Old output (with --minify --target=safari16.2) x(function(c=-1){}.z=2,class{f(c=-1){}}.z=2); // New output (with --minify --target=safari16.2) x((function(c=-1){}).z=2,(class{f(c=-1){}}).z=2); ``` This fix is not enabled by default. It's only enabled when `--target=` contains Safari 16.2 or earlier, such as with `--target=safari16.2`. You can also explicitly enable or disable this specific transform (called `function-or-class-property-access`) with `--supported:function-or-class-property-access=false`. - Fix esbuild's TypeScript type declarations to forbid unknown properties ([#&#8203;3089](https://github.com/evanw/esbuild/issues/3089)) Version 0.17.0 of esbuild introduced a specific form of function overloads in the TypeScript type definitions for esbuild's API calls that looks like this: ```ts interface TransformOptions { legalComments?: 'none' | 'inline' | 'eof' | 'external' } interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> { legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined) } declare function transformSync<ProvidedOptions extends TransformOptions>(input: string, options?: ProvidedOptions): TransformResult<ProvidedOptions> declare function transformSync(input: string, options?: TransformOptions): TransformResult ``` This more accurately reflects how esbuild's JavaScript API behaves. The result object returned by `transformSync` only has the `legalComments` property if you pass `legalComments: 'external'`: ```ts // These have type "string | undefined" transformSync('').legalComments transformSync('', { legalComments: 'eof' }).legalComments // This has type "string" transformSync('', { legalComments: 'external' }).legalComments ``` However, this form of function overloads unfortunately allows typos (e.g. `egalComments`) to pass the type checker without generating an error as TypeScript allows all objects with unknown properties to extend `TransformOptions`. These typos result in esbuild's API throwing an error at run-time. To prevent typos during type checking, esbuild's TypeScript type definitions will now use a different form that looks like this: ```ts type SameShape<Out, In extends Out> = In & { [Key in Exclude<keyof In, keyof Out>]: never } interface TransformOptions { legalComments?: 'none' | 'inline' | 'eof' | 'external' } interface TransformResult<ProvidedOptions extends TransformOptions = TransformOptions> { legalComments: string | (ProvidedOptions['legalComments'] extends 'external' ? never : undefined) } declare function transformSync<T extends TransformOptions>(input: string, options?: SameShape<TransformOptions, T>): TransformResult<T> ``` This change should hopefully not affect correct code. It should hopefully introduce type errors only for incorrect code. - Fix CSS nesting transform for pseudo-elements ([#&#8203;3119](https://github.com/evanw/esbuild/issues/3119)) This release fixes esbuild's CSS nesting transform for pseudo-elements (e.g. `::before` and `::after`). The CSS nesting specification says that [the nesting selector does not work with pseudo-elements](https://www.w3.org/TR/css-nesting-1/#ref-for-matches-pseudo%E2%91%A0). This can be seen in the example below: esbuild does not carry the parent pseudo-element `::before` through the nesting selector `&`. However, that doesn't apply to pseudo-elements that are within the same selector. Previously esbuild had a bug where it considered pseudo-elements in both locations as invalid. This release changes esbuild to only consider those from the parent selector invalid, which should align with the specification: ```css /* Original code */ a, b::before { &.c, &::after { content: 'd'; } } /* Old output (with --target=chrome90) */ a:is(.c, ::after) { content: "d"; } /* New output (with --target=chrome90) */ a.c, a::after { content: "d"; } ``` - Forbid `&` before a type selector in nested CSS The people behind the work-in-progress CSS nesting specification have very recently [decided to forbid nested CSS that looks like `&div`](https://github.com/w3c/csswg-drafts/issues/8662#issuecomment-1514977935). You will have to use either `div&` or `&:is(div)` instead. This release of esbuild has been updated to take this new change into consideration. Doing this now generates a warning. The suggested fix is slightly different depending on where in the overall selector it happened: ▲ [WARNING] Cannot use type selector "input" directly after nesting selector "&" [css-syntax-error] example.css:2:3: 2 │ &input { │ ~~~~~ ╵ :is(input) CSS nesting syntax does not allow the "&" selector to come before a type selector. You can wrap this selector in ":is()" as a workaround. This restriction exists to avoid problems with SASS nesting, where the same syntax means something very different that has no equivalent in real CSS (appending a suffix to the parent selector). ▲ [WARNING] Cannot use type selector "input" directly after nesting selector "&" [css-syntax-error] example.css:6:8: 6 │ .form &input { │ ~~~~~~ ╵ input& CSS nesting syntax does not allow the "&" selector to come before a type selector. You can move the "&" to the end of this selector as a workaround. This restriction exists to avoid problems with SASS nesting, where the same syntax means something very different that has no equivalent in real CSS (appending a suffix to the parent selector). ### [`v0.17.19`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01719) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.18...v0.17.19) - Fix CSS transform bugs with nested selectors that start with a combinator ([#&#8203;3096](https://github.com/evanw/esbuild/issues/3096)) This release fixes several bugs regarding transforming nested CSS into non-nested CSS for older browsers. The bugs were due to lack of test coverage for nested selectors with more than one compound selector where they all start with the same combinator. Here's what some problematic cases look like before and after these fixes: ```css /* Original code */ .foo { > &a, > &b { color: red; } } .bar { > &a, + &b { color: green; } } /* Old output (with --target=chrome90) */ .foo :is(> .fooa, > .foob) { color: red; } .bar :is(> .bara, + .barb) { color: green; } /* New output (with --target=chrome90) */ .foo > :is(a.foo, b.foo) { color: red; } .bar > a.bar, .bar + b.bar { color: green; } ``` - Fix bug with TypeScript parsing of instantiation expressions followed by `=` ([#&#8203;3111](https://github.com/evanw/esbuild/issues/3111)) This release fixes esbuild's TypeScript-to-JavaScript conversion code in the case where a potential instantiation expression is followed immediately by a `=` token (such that the trailing `>` becomes a `>=` token). Previously esbuild considered that to still be an instantiation expression, but the official TypeScript compiler considered it to be a `>=` operator instead. This release changes esbuild's interpretation to match TypeScript. This edge case currently [appears to be problematic](https://sucrase.io/#transforms=typescript\&compareWithTypeScript=true\&code=x%3Cy%3E%3Da%3Cb%3Cc%3E%3E\(\)) for other TypeScript-to-JavaScript converters as well: | Original code | TypeScript | esbuild 0.17.18 | esbuild 0.17.19 | Sucrase | Babel | |---|---|---|---|---|---| | `x<y>=a<b<c>>()` | `x<y>=a();` | `x=a();` | `x<y>=a();` | `x=a()` | Invalid left-hand side in assignment expression | - Avoid removing unrecognized directives from the directive prologue when minifying ([#&#8203;3115](https://github.com/evanw/esbuild/issues/3115)) The [directive prologue](https://262.ecma-international.org/6.0/#sec-directive-prologues-and-the-use-strict-directive) in JavaScript is a sequence of top-level string expressions that come before your code. The only directives that JavaScript engines currently recognize are `use strict` and sometimes `use asm`. However, the people behind React have made up their own directive for their own custom dialect of JavaScript. Previously esbuild only preserved the `use strict` directive when minifying, although you could still write React JavaScript with esbuild using something like `--banner:js="'your directive here';"`. With this release, you can now put arbitrary directives in the entry point and esbuild will preserve them in its minified output: ```js // Original code 'use wtf'; console.log(123) // Old output (with --minify) console.log(123); // New output (with --minify) "use wtf";console.log(123); ``` Note that this means esbuild will no longer remove certain stray top-level strings when minifying. This behavior is an intentional change because these stray top-level strings are actually part of the directive prologue, and could potentially have semantics assigned to them (as was the case with React). - Improved minification of binary shift operators With this release, esbuild's minifier will now evaluate the `<<` and `>>>` operators if the resulting code would be shorter: ```js // Original code console.log(10 << 10, 10 << 20, -123 >>> 5, -123 >>> 10); // Old output (with --minify) console.log(10<<10,10<<20,-123>>>5,-123>>>10); // New output (with --minify) console.log(10240,10<<20,-123>>>5,4194303); ``` ### [`v0.17.18`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01718) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.17...v0.17.18) - Fix non-default JSON import error with `export {} from` ([#&#8203;3070](https://github.com/evanw/esbuild/issues/3070)) This release fixes a bug where esbuild incorrectly identified statements of the form `export { default as x } from "y" assert { type: "json" }` as a non-default import. The bug did not affect code of the form `import { default as x } from ...` (only code that used the `export` keyword). - Fix a crash with an invalid subpath import ([#&#8203;3067](https://github.com/evanw/esbuild/issues/3067)) Previously esbuild could crash when attempting to generate a friendly error message for an invalid [subpath import](https://nodejs.org/api/packages.html#subpath-imports) (i.e. an import starting with `#`). This happened because esbuild originally only supported the `exports` field and the code for that error message was not updated when esbuild later added support for the `imports` field. This crash has been fixed. ### [`v0.17.17`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01717) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.16...v0.17.17) - Fix CSS nesting transform for top-level `&` ([#&#8203;3052](https://github.com/evanw/esbuild/issues/3052)) Previously esbuild could crash with a stack overflow when lowering CSS nesting rules with a top-level `&`, such as in the code below. This happened because esbuild's CSS nesting transform didn't handle top-level `&`, causing esbuild to inline the top-level selector into itself. This release handles top-level `&` by replacing it with [the `:scope` pseudo-class](https://drafts.csswg.org/selectors-4/#the-scope-pseudo): ```css /* Original code */ &, a { .b { color: red; } } /* New output (with --target=chrome90) */ :is(:scope, a) .b { color: red; } ``` - Support `exports` in `package.json` for `extends` in `tsconfig.json` ([#&#8203;3058](https://github.com/evanw/esbuild/issues/3058)) TypeScript 5.0 added the ability to use `extends` in `tsconfig.json` to reference a path in a package whose `package.json` file contains an `exports` map that points to the correct location. This doesn't automatically work in esbuild because `tsconfig.json` affects esbuild's path resolution, so esbuild's normal path resolution logic doesn't apply. This release adds support for doing this by adding some additional code that attempts to resolve the `extends` path using the `exports` field. The behavior should be similar enough to esbuild's main path resolution logic to work as expected. Note that esbuild always treats this `extends` import as a `require()` import since that's what TypeScript appears to do. Specifically the `require` condition will be active and the `import` condition will be inactive. - Fix watch mode with `NODE_PATH` ([#&#8203;3062](https://github.com/evanw/esbuild/issues/3062)) Node has a rarely-used feature where you can extend the set of directories that node searches for packages using the `NODE_PATH` environment variable. While esbuild supports this too, previously a bug prevented esbuild's watch mode from picking up changes to imported files that were contained directly in a `NODE_PATH` directory. You're supposed to use `NODE_PATH` for packages, but some people abuse this feature by putting files in that directory instead (e.g. `node_modules/some-file.js` instead of `node_modules/some-pkg/some-file.js`). The watch mode bug happens when you do this because esbuild first tries to read `some-file.js` as a directory and then as a file. Watch mode was incorrectly waiting for `some-file.js` to become a valid directory. This release fixes this edge case bug by changing watch mode to watch `some-file.js` as a file when this happens. ### [`v0.17.16`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01716) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.15...v0.17.16) - Fix CSS nesting transform for triple-nested rules that start with a combinator ([#&#8203;3046](https://github.com/evanw/esbuild/issues/3046)) This release fixes a bug with esbuild where triple-nested CSS rules that start with a combinator were not transformed correctly for older browsers. Here's an example of such a case before and after this bug fix: ```css /* Original input */ .a { color: red; > .b { color: green; > .c { color: blue; } } } /* Old output (with --target=chrome90) */ .a { color: red; } .a > .b { color: green; } .a .b > .c { color: blue; } /* New output (with --target=chrome90) */ .a { color: red; } .a > .b { color: green; } .a > .b > .c { color: blue; } ``` - Support `--inject` with a file loaded using the `copy` loader ([#&#8203;3041](https://github.com/evanw/esbuild/issues/3041)) This release now allows you to use `--inject` with a file that is loaded using the `copy` loader. The `copy` loader copies the imported file to the output directory verbatim and rewrites the path in the `import` statement to point to the copied output file. When used with `--inject`, this means the injected file will be copied to the output directory as-is and a bare `import` statement for that file will be inserted in any non-copy output files that esbuild generates. Note that since esbuild doesn't parse the contents of copied files, esbuild will not expose any of the export names as usable imports when you do this (in the way that esbuild's `--inject` feature is typically used). However, any side-effects that the injected file has will still occur. ### [`v0.17.15`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01715) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.14...v0.17.15) - Allow keywords as type parameter names in mapped types ([#&#8203;3033](https://github.com/evanw/esbuild/issues/3033)) TypeScript allows type keywords to be used as parameter names in mapped types. Previously esbuild incorrectly treated this as an error. Code that does this is now supported: ```ts type Foo = 'a' | 'b' | 'c' type A = { [keyof in Foo]: number } type B = { [infer in Foo]: number } type C = { [readonly in Foo]: number } ``` - Add annotations for re-exported modules in node ([#&#8203;2486](https://github.com/evanw/esbuild/issues/2486), [#&#8203;3029](https://github.com/evanw/esbuild/issues/3029)) Node lets you import named imports from a CommonJS module using ESM import syntax. However, the allowed names aren't derived from the properties of the CommonJS module. Instead they are derived from an arbitrary syntax-only analysis of the CommonJS module's JavaScript AST. To accommodate node doing this, esbuild's ESM-to-CommonJS conversion adds a special non-executable "annotation" for node that describes the exports that node should expose in this scenario. It takes the form `0 && (module.exports = { ... })` and comes at the end of the file (`0 && expr` means `expr` is never evaluated). Previously esbuild didn't do this for modules re-exported using the `export * from` syntax. Annotations for these re-exports will now be added starting with this release: ```js // Original input export { foo } from './foo' export * from './bar' // Old output (with --format=cjs --platform=node) ... 0 && (module.exports = { foo }); // New output (with --format=cjs --platform=node) ... 0 && (module.exports = { foo, ...require("./bar") }); ``` Note that you need to specify both `--format=cjs` and `--platform=node` to get these node-specific annotations. - Avoid printing an unnecessary space in between a number and a `.` ([#&#8203;3026](https://github.com/evanw/esbuild/pull/3026)) JavaScript typically requires a space in between a number token and a `.` token to avoid the `.` being interpreted as a decimal point instead of a member expression. However, this space is not required if the number token itself contains a decimal point, an exponent, or uses a base other than 10. This release of esbuild now avoids printing the unnecessary space in these cases: ```js // Original input foo(1000 .x, 0 .x, 0.1 .x, 0.0001 .x, 0xFFFF_0000_FFFF_0000 .x) // Old output (with --minify) foo(1e3 .x,0 .x,.1 .x,1e-4 .x,0xffff0000ffff0000 .x); // New output (with --minify) foo(1e3.x,0 .x,.1.x,1e-4.x,0xffff0000ffff0000.x); ``` - Fix server-sent events with live reload when writing to the file system root ([#&#8203;3027](https://github.com/evanw/esbuild/issues/3027)) This release fixes a bug where esbuild previously failed to emit server-sent events for live reload when `outdir` was the file system root, such as `/`. This happened because `/` is the only path on Unix that cannot have a trailing slash trimmed from it, which was fixed by improved path handling. ### [`v0.17.14`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01714) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.13...v0.17.14) - Allow the TypeScript 5.0 `const` modifier in object type declarations ([#&#8203;3021](https://github.com/evanw/esbuild/issues/3021)) The new TypeScript 5.0 `const` modifier was added to esbuild in version 0.17.5, and works with classes, functions, and arrow expressions. However, support for it wasn't added to object type declarations (e.g. interfaces) due to an oversight. This release adds support for these cases, so the following TypeScript 5.0 code can now be built with esbuild: ```ts interface Foo { <const T>(): T } type Bar = { new <const T>(): T } ``` - Implement preliminary lowering for CSS nesting ([#&#8203;1945](https://github.com/evanw/esbuild/issues/1945)) Chrome has [implemented the new CSS nesting specification](https://developer.chrome.com/articles/css-nesting/) in version 112, which is currently in beta but will become stable very soon. So CSS nesting is now a part of the web platform! This release of esbuild can now transform nested CSS syntax into non-nested CSS syntax for older browsers. The transformation relies on the `:is()` pseudo-class in many cases, so the transformation is only guaranteed to work when targeting browsers that support `:is()` (e.g. Chrome 88+). You'll need to set esbuild's [`target`](https://esbuild.github.io/api/#target) to the browsers you intend to support to tell esbuild to do this transformation. You will get a warning if you use CSS nesting syntax with a `target` which includes older browsers that don't support `:is()`. The lowering transformation looks like this: ```css /* Original input */ a.btn { color: #&#8203;333; &:hover { color: #&#8203;444 } &:active { color: #&#8203;555 } } /* New output (with --target=chrome88) */ a.btn { color: #&#8203;333; } a.btn:hover { color: #&#8203;444; } a.btn:active { color: #&#8203;555; } ``` More complex cases may generate the `:is()` pseudo-class: ```css /* Original input */ div, p { .warning, .error { padding: 20px; } } /* New output (with --target=chrome88) */ :is(div, p) :is(.warning, .error) { padding: 20px; } ``` In addition, esbuild now has a special warning message for nested style rules that start with an identifier. This isn't allowed in CSS because the syntax would be ambiguous with the existing declaration syntax. The new warning message looks like this: ▲ [WARNING] A nested style rule cannot start with "p" because it looks like the start of a declaration [css-syntax-error] <stdin>:1:7: 1 │ main { p { margin: auto } } │ ^ ╵ :is(p) To start a nested style rule with an identifier, you need to wrap the identifier in ":is(...)" to prevent the rule from being parsed as a declaration. Keep in mind that the transformation in this release is a preliminary implementation. CSS has many features that interact in complex ways, and there may be some edge cases that don't work correctly yet. - Minification now removes unnecessary `&` CSS nesting selectors This release introduces the following CSS minification optimizations: ```css /* Original input */ a { font-weight: bold; & { color: blue; } & :hover { text-decoration: underline; } } /* Old output (with --minify) */ a{font-weight:700;&{color:#&#8203;00f}& :hover{text-decoration:underline}} /* New output (with --minify) */ a{font-weight:700;:hover{text-decoration:underline}color:#&#8203;00f} ``` - Minification now removes duplicates from CSS selector lists This release introduces the following CSS minification optimization: ```css /* Original input */ div, div { color: red } /* Old output (with --minify) */ div,div{color:red} /* New output (with --minify) */ div{color:red} ``` ### [`v0.17.13`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01713) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.12...v0.17.13) - Work around an issue with `NODE_PATH` and Go's WebAssembly internals ([#&#8203;3001](https://github.com/evanw/esbuild/issues/3001)) Go's WebAssembly implementation returns `EINVAL` instead of `ENOTDIR` when using the `readdir` syscall on a file. This messes up esbuild's implementation of node's module resolution algorithm since encountering `ENOTDIR` causes esbuild to continue its search (since it's a normal condition) while other encountering other errors causes esbuild to fail with an I/O error (since it's an unexpected condition). You can encounter this issue in practice if you use node's legacy `NODE_PATH` feature to tell esbuild to resolve node modules in a custom directory that was not installed by npm. This release works around this problem by converting `EINVAL` into `ENOTDIR` for the `readdir` syscall. - Fix a minification bug with CSS `@layer` rules that have parsing errors ([#&#8203;3016](https://github.com/evanw/esbuild/issues/3016)) CSS at-rules [require either a `{}` block or a semicolon at the end](https://www.w3.org/TR/css-syntax-3/#consume-at-rule). Omitting both of these causes esbuild to treat the rule as an unknown at-rule. Previous releases of esbuild had a bug that incorrectly removed unknown at-rules without any children during minification if the at-rule token matched an at-rule that esbuild can handle. Specifically [cssnano](https://cssnano.co/) can generate `@layer` rules with parsing errors, and empty `@layer` rules cannot be removed because they have side effects (`@layer` didn't exist when esbuild's CSS support was added, so esbuild wasn't written to handle this). This release changes esbuild to no longer discard `@layer` rules with parsing errors when minifying (the rule `@layer c` has a parsing error): ```css /* Original input */ @&#8203;layer a { @&#8203;layer b { @&#8203;layer c } } /* Old output (with --minify) */ @&#8203;layer a.b; /* New output (with --minify) */ @&#8203;layer a.b.c; ``` - Unterminated strings in CSS are no longer an error The CSS specification provides [rules for handling parsing errors](https://www.w3.org/TR/CSS22/syndata.html#parsing-errors). One of those rules is that user agents must close strings upon reaching the end of a line (i.e., before an unescaped line feed, carriage return or form feed character), but then drop the construct (declaration or rule) in which the string was found. For example: ```css p { color: green; font-family: 'Courier New Times color: red; color: green; } ``` ...would be treated the same as: ```css p { color: green; color: green; } ``` ...because the second declaration (from `font-family` to the semicolon after `color: red`) is invalid and is dropped. Previously using this CSS with esbuild failed to build due to a syntax error, even though the code can be interpreted by a browser. With this release, the code now produces a warning instead of an error, and esbuild prints the invalid CSS such that it stays invalid in the output: ```css /* esbuild's new non-minified output: */ p { color: green; font-family: 'Courier New Times color: red; color: green; } ``` ```css /* esbuild's new minified output: */ p{font-family:'Courier New Times color: red;color:green} ``` ### [`v0.17.12`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01712) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.11...v0.17.12) - Fix a crash when parsing inline TypeScript decorators ([#&#8203;2991](https://github.com/evanw/esbuild/issues/2991)) Previously esbuild's TypeScript parser crashed when parsing TypeScript decorators if the definition of the decorator was inlined into the decorator itself: ```ts @&#8203;(function sealed(constructor: Function) { Object.seal(constructor); Object.seal(constructor.prototype); }) class Foo {} ``` This crash was not noticed earlier because this edge case did not have test coverage. The crash is fixed in this release. ### [`v0.17.11`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01711) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.10...v0.17.11) - Fix the `alias` feature to always prefer the longest match ([#&#8203;2963](https://github.com/evanw/esbuild/issues/2963)) It's possible to configure conflicting aliases such as `--alias:a=b` and `--alias:a/c=d`, which is ambiguous for the import path `a/c/x` (since it could map to either `b/c/x` or `d/x`). Previously esbuild would pick the first matching `alias`, which would non-deterministically pick between one of the possible matches. This release fixes esbuild to always deterministically pick the longest possible match. - Minify calls to some global primitive constructors ([#&#8203;2962](https://github.com/evanw/esbuild/issues/2962)) With this release, esbuild's minifier now replaces calls to `Boolean`/`Number`/`String`/`BigInt` with equivalent shorter code when relevant: ```js // Original code console.log( Boolean(a ? (b | c) !== 0 : (c & d) !== 0), Number(e ? '1' : '2'), String(e ? '1' : '2'), BigInt(e ? 1n : 2n), ) // Old output (with --minify) console.log(Boolean(a?(b|c)!==0:(c&d)!==0),Number(e?"1":"2"),String(e?"1":"2"),BigInt(e?1n:2n)); // New output (with --minify) console.log(!!(a?b|c:c&d),+(e?"1":"2"),e?"1":"2",e?1n:2n); ``` - Adjust some feature compatibility tables for node ([#&#8203;2940](https://github.com/evanw/esbuild/issues/2940)) This release makes the following adjustments to esbuild's internal feature compatibility tables for node, which tell esbuild which versions of node are known to support all aspects of that feature: - `class-private-brand-checks`: node v16.9+ => node v16.4+ (a decrease) - `hashbang`: node v12.0+ => node v12.5+ (an increase) - `optional-chain`: node v16.9+ => node v16.1+ (a decrease) - `template-literal`: node v4+ => node v10+ (an increase) Each of these adjustments was identified by comparing against data from the `node-compat-table` package and was manually verified using old node executables downloaded from https://nodejs.org/download/release/. ### [`v0.17.10`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01710) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.9...v0.17.10) - Update esbuild's handling of CSS nesting to match the latest specification changes ([#&#8203;1945](https://github.com/evanw/esbuild/issues/1945)) The syntax for the upcoming CSS nesting feature has [recently changed](https://webkit.org/blog/13813/try-css-nesting-today-in-safari-technology-preview/). The `@nest` prefix that was previously required in some cases is now gone, and nested rules no longer have to start with `&` (as long as they don't start with an identifier or function token). This release updates esbuild's pass-through handling of CSS nesting syntax to match the latest specification changes. So you can now use esbuild to bundle CSS containing nested rules and try them out in a browser that supports CSS nesting (which includes nightly builds of both Chrome and Safari). However, I'm not implementing lowering of nested CSS to non-nested CSS for older browsers yet. While the syntax has been decided, the semantics are still in flux. In particular, there is still some debate about changing the fundamental way that CSS nesting works. For example, you might think that the following CSS is equivalent to a `.outer .inner button { ... }` rule: ```css .inner button { .outer & { color: red; } } ``` But instead it's actually equivalent to a `.outer :is(.inner button) { ... }` rule which unintuitively also matches the following DOM structure: ```html <div class="inner"> <div class="outer"> <button></button> </div> </div> ``` The `:is()` behavior is preferred by browser implementers because it's more memory-efficient, but the straightforward translation into a `.outer .inner button { ... }` rule is preferred by developers used to the existing CSS preprocessing ecosystem (e.g. SASS). It seems premature to commit esbuild to specific semantics for this syntax at this time given the ongoing debate. - Fix cross-file CSS rule deduplication involving `url()` tokens ([#&#8203;2936](https://github.com/evanw/esbuild/issues/2936)) Previously cross-file CSS rule deduplication didn't handle `url()` tokens correctly. These tokens contain references to import paths which may be internal (i.e. in the bundle) or external (i.e. not in the bundle). When comparing two `url()` tokens for equality, the underlying import paths should be compared instead of their references. This release of esbuild fixes `url()` token comparisons. One side effect is that `@font-face` rules should now be deduplicated correctly across files: ```css /* Original code */ @&#8203;import "data:text/css, \ @&#8203;import 'http://example.com/style.css'; \ @&#8203;font-face { src: url(http://example.com/font.ttf) }"; @&#8203;import "data:text/css, \ @&#8203;font-face { src: url(http://example.com/font.ttf) }"; /* Old output (with --bundle --minify) */ @&#8203;import"http://example.com/style.css";@&#8203;font-face{src:url(http://example.com/font.ttf)}@&#8203;font-face{src:url(http://example.com/font.ttf)} /* New output (with --bundle --minify) */ @&#8203;import"http://example.com/style.css";@&#8203;font-face{src:url(http://example.com/font.ttf)} ``` ### [`v0.17.9`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0179) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.8...v0.17.9) - Parse rest bindings in TypeScript types ([#&#8203;2937](https://github.com/evanw/esbuild/issues/2937)) Previously esbuild was unable to parse the following valid TypeScript code: ```ts let tuple: (...[e1, e2, ...es]: any) => any ``` This release includes support for parsing code like this. - Fix TypeScript code translation for certain computed `declare` class fields ([#&#8203;2914](https://github.com/evanw/esbuild/issues/2914)) In TypeScript, the key of a computed `declare` class field should only be preserved if there are no decorators for that field. Previously esbuild always preserved the key, but esbuild will now remove the key to match the output of the TypeScript compiler: ```ts // Original code declare function dec(a: any, b: any): any declare const removeMe: unique symbol declare const keepMe: unique symbol class X { declare [removeMe]: any @&#8203;dec declare [keepMe]: any } // Old output var _a; class X { } removeMe, _a = keepMe; __decorateClass([ dec ], X.prototype, _a, 2); // New output var _a; class X { } _a = keepMe; __decorateClass([ dec ], X.prototype, _a, 2); ``` - Fix a crash with path resolution error generation ([#&#8203;2913](https://github.com/evanw/esbuild/issues/2913)) In certain situations, a module containing an invalid import path could previously cause esbuild to crash when it attempts to generate a more helpful error message. This crash has been fixed. ### [`v0.17.8`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0178) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.7...v0.17.8) - Fix a minification bug with non-ASCII identifiers ([#&#8203;2910](https://github.com/evanw/esbuild/issues/2910)) This release fixes a bug with esbuild where non-ASCII identifiers followed by a keyword were incorrectly not separated by a space. This bug affected both the `in` and `instanceof` keywords. Here's an example of the fix: ```js // Original code π in a // Old output (with --minify --charset=utf8) πin a; // New output (with --minify --charset=utf8) π in a; ``` - Fix a regression with esbuild's WebAssembly API in version 0.17.6 ([#&#8203;2911](https://github.com/evanw/esbuild/issues/2911)) Version 0.17.6 of esbuild updated the Go toolchain to version 1.20.0. This had the unfortunate side effect of increasing the amount of stack space that esbuild uses (presumably due to some changes to Go's WebAssembly implementation) which could cause esbuild's WebAssembly-based API to crash with a stack overflow in cases where it previously didn't crash. One such case is the package `grapheme-splitter` which contains code that looks like this: ```js if ( (0x0300 <= code && code <= 0x036F) || (0x0483 <= code && code <= 0x0487) || (0x0488 <= code && code <= 0x0489) || (0x0591 <= code && code <= 0x05BD) || // ... many hundreds of lines later ... ) { return; } ``` This edge case involves a chain of binary operators that results in an AST over 400 nodes deep. Normally this wouldn't be a problem because Go has growable call stacks, so the call stack would just grow to be as large as needed. However, WebAssembly byte code deliberately doesn't expose the ability to manipulate the stack pointer, so Go's WebAssembly translation is forced to use the fixed-size WebAssembly call stack. So esbuild's WebAssembly implementation is vulnerable to stack overflow in cases like these. It's not unreasonable for this to cause a stack overflow, and for esbuild's answer to this problem to be "don't write code like this." That's how many other AST-manipulation tools handle this problem. However, it's possible to implement AST traversal using iteration instead of recursion to work around limited call stack space. This version of esbuild implements this code transformation for esbuild's JavaScript parser and printer, so esbuild's WebAssembly implementation is now able to process the `grapheme-splitter` package (at least when compiled with Go 1.20.0 and run with node's WebAssembly implementation). ### [`v0.17.7`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0177) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.6...v0.17.7) - Change esbuild's parsing of TypeScript instantiation expressions to match TypeScript 4.8+ ([#&#8203;2907](https://github.com/evanw/esbuild/issues/2907)) This release updates esbuild's implementation of instantiation expression erasure to match [microsoft/TypeScript#&#8203;49353](https://github.com/microsoft/TypeScript/pull/49353). The new rules are as follows (copied from TypeScript's PR description): > When a potential type argument list is followed by > > - a line break, > - an `(` token, > - a template literal string, or > - any token except `<` or `>` that isn't the start of an expression, > > we consider that construct to be a type argument list. Otherwise we consider the construct to be a `<` relational expression followed by a `>` relational expression. - Ignore `sideEffects: false` for imported CSS files ([#&#8203;1370](https://github.com/evanw/esbuild/issues/1370), [#&#8203;1458](https://github.com/evanw/esbuild/pull/1458), [#&#8203;2905](https://github.com/evanw/esbuild/issues/2905)) This release ignores the `sideEffects` annotation in `package.json` for CSS files that are imported into JS files using esbuild's `css` loader. This means that these CSS files are no longer be tree-shaken. Importing CSS into JS causes esbuild to automatically create a CSS entry point next to the JS entry point containing the bundled CSS. Previously packages that specified some form of `"sideEffects": false` could potentially cause esbuild to consider one or more of the JS files on the import path to the CSS file to be side-effect free, which would result in esbuild removing that CSS file from the bundle. This was problematic because the removal of that CSS is outwardly observable, since all CSS is global, so it was incorrect for previous versions of esbuild to tree-shake CSS files imported into JS files. - Add constant folding for certain additional equality cases ([#&#8203;2394](https://github.com/evanw/esbuild/issues/2394), [#&#8203;2895](https://github.com/evanw/esbuild/issues/2895)) This release adds constant folding for expressions similar to the following: ```js // Original input console.log( null === 'foo', null === undefined, null == undefined, false === 0, false == 0, 1 === true, 1 == true, ) // Old output console.log( null === "foo", null === void 0, null == void 0, false === 0, false == 0, 1 === true, 1 == true ); // New output console.log( false, false, true, false, true, false, true ); ``` ### [`v0.17.6`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0176) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.5...v0.17.6) - Fix a CSS parser crash on invalid CSS ([#&#8203;2892](https://github.com/evanw/esbuild/issues/2892)) Previously the following invalid CSS caused esbuild's parser to crash: ```css @&#8203;media screen ``` The crash was caused by trying to construct a helpful error message assuming that there was an opening `{` token, which is not the case here. This release fixes the crash. - Inline TypeScript enums that are referenced before their declaration Previously esbuild inlined enums within a TypeScript file from top to bottom, which meant that references to TypeScript enum members were only inlined within the same file if they came after the enum declaration. With this release, esbuild will now inline enums even when they are referenced before they are declared: ```ts // Original input export const foo = () => Foo.FOO const enum Foo { FOO = 0 } // Old output (with --tree-shaking=true) export const foo = () => Foo.FOO; var Foo = /* @&#8203;__PURE__ */ ((Foo2) => { Foo2[Foo2["FOO"] = 0] = "FOO"; return Foo2; })(Foo || {}); // New output (with --tree-shaking=true) export const foo = () => 0 /* FOO */; ``` This makes esbuild's TypeScript output smaller and faster when processing code that does this. I noticed this issue when I ran the TypeScript compiler's source code through esbuild's bundler. Now that the TypeScript compiler is going to be bundled with esbuild in the upcoming TypeScript 5.0 release, improvements like this will also improve the TypeScript compiler itself! - Fix esbuild installation on Arch Linux ([#&#8203;2785](https://github.com/evanw/esbuild/issues/2785), [#&#8203;2812](https://github.com/evanw/esbuild/issues/2812), [#&#8203;2865](https://github.com/evanw/esbuild/issues/2865)) Someone made an unofficial `esbuild` package for Linux that adds the `ESBUILD_BINARY_PATH=/usr/bin/esbuild` environment variable to the user's default environment. This breaks all npm installations of esbuild for users with this unofficial Linux package installed, which has affected many people. Most (all?) people who encounter this problem haven't even installed this unofficial package themselves; instead it was installed for them as a dependency of another Linux package. The problematic change to add the `ESBUILD_BINARY_PATH` environment variable was reverted in the latest version of this unofficial package. However, old versions of this unofficial package are still there and will be around forever. With this release, `ESBUILD_BINARY_PATH` is now ignored by esbuild's install script when it's set to the value `/usr/bin/esbuild`. This should unbreak using npm to install `esbuild` in these problematic Linux environments. Note: The `ESBUILD_BINARY_PATH` variable is an undocumented way to override the location of esbuild's binary when esbuild's npm package is installed, which is necessary to substitute your own locally-built esbuild binary when debugging esbuild's npm package. It's only meant for very custom situations and should absolutely not be forced on others by default, especially without their knowledge. I may remove the code in esbuild's installer that reads `ESBUILD_BINARY_PATH` in the future to prevent these kinds of issues. It will unfortunately make debugging esbuild harder. If `ESBUILD_BINARY_PATH` is ever removed, it will be done in a "breaking change" release. ### [`v0.17.5`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0175) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.4...v0.17.5) - Parse `const` type parameters from TypeScript 5.0 The TypeScript 5.0 beta announcement adds [`const` type parameters](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#const-type-parameters) to the language. You can now add the `const` modifier on a type parameter of a function, method, or class like this: ```ts type HasNames = { names: readonly string[] }; const getNamesExactly = <const T extends HasNames>(arg: T): T["names"] => arg.names; const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] }); ``` The type of `names` in the above example is `readonly ["Alice", "Bob", "Eve"]`. Marking the type parameter as `const` behaves as if you had written `as const` at every use instead. The above code is equivalent to the following TypeScript, which was the only option before TypeScript 5.0: ```ts type HasNames = { names: readonly string[] }; const getNamesExactly = <T extends HasNames>(arg: T): T["names"] => arg.names; const names = getNamesExactly({ names: ["Alice", "Bob", "Eve"] } as const); ``` You can read [the announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#const-type-parameters) for more information. - Make parsing generic `async` arrow functions more strict in `.tsx` files Previously esbuild's TypeScript parser incorrectly accepted the following code as valid: ```tsx let fn = async <T> () => {}; ``` The official TypeScript parser rejects this code because it thinks it's the identifier `async` followed by a JSX element starting with `<T>`. So with this release, esbuild will now reject this syntax in `.tsx` files too. You'll now have to add a comma after the type parameter to get generic arrow functions like this to parse in `.tsx` files: ```tsx let fn = async <T,> () => {}; ``` - Allow the `in` and `out` type parameter modifiers on class expressions TypeScript 4.7 added the `in` and `out` modifiers on the type parameters of classes, interfaces, and type aliases. However, while TypeScript supported them on both class expressions and class statements, previously esbuild only supported them on class statements due to an oversight. This release now allows these modifiers on class expressions too: ```ts declare let Foo: any; Foo = class <in T> { }; Foo = class <out T> { }; ``` - Update `enum` constant folding for TypeScript 5.0 TypeScript 5.0 contains an [updated definition of what it considers a constant expression](https://github.com/microsoft/TypeScript/pull/50528): > An expression is considered a *constant expression* if it is > > - a number or string literal, > - a unary `+`, `-`, or `~` applied to a numeric constant expression, > - a binary `+`, `-`, `*`, `/`, `%`, `**`, `<<`, `>>`, `>>>`, `|`, `&`, `^` applied to two numeric constant expressions, > - a binary `+` applied to two constant expressions whereof at least one is a string, > - a template expression where each substitution expression is a constant expression, > - a parenthesized constant expression, > - a dotted name (e.g. `x.y.z`) that references a `const` variable with a constant expression initializer and no type annotation, > - a dotted name that references an enum member with an enum literal type, or > - a dotted name indexed by a string literal (e.g. `x.y["z"]`) that references an enum member with an enum literal type. This impacts esbuild's implementation of TypeScript's `const enum` feature. With this release, esbuild will now attempt to follow these new rules. For example, you can now initialize an `enum` member with a template literal expression that contains a numeric constant: ```ts // Original input const enum Example { COUNT = 100, ERROR = `Expected ${COUNT} items`, } console.log( Example.COUNT, Example.ERROR, ) // Old output (with --tree-shaking=true) var Example = /* @&#8203;__PURE__ */ ((Example2) => { Example2[Example2["COUNT"] = 100] = "COUNT"; Example2[Example2["ERROR"] = `Expected ${100 /* COUNT */} items`] = "ERROR"; return Example2; })(Example || {}); console.log( 100 /* COUNT */, Example.ERROR ); // New output (with --tree-shaking=true) console.log( 100 /* COUNT */, "Expected 100 items" /* ERROR */ ); ``` These rules are not followed exactly due to esbuild's limitations. The rule about dotted references to `const` variables is not followed both because esbuild's enum processing is done in an isolated module setting and because doing so would potentially require esbuild to use a type system, which it doesn't have. For example: ```ts // The TypeScript compiler inlines this but esbuild doesn't: declare const x = 'foo' const enum Foo { X = x } console.log(Foo.X) ``` Also, the rule that requires converting numbers to a string currently only followed for 32-bit signed integers and non-finite numbers. This is done to avoid accidentally introducing a bug if esbuild's number-to-string operation doesn't exactly match the behavior of a real JavaScript VM. Currently esbuild's number-to-string constant folding is conservative for safety. - Forbid definite assignment assertion operators on class methods In TypeScript, class methods can use the `?` optional property operator but not the `!` definite assignment assertion operator (while class fields can use both): ```ts class Foo { // These are valid TypeScript a? b! x?() {} // This is invalid TypeScript y!() {} } ``` Previously esbuild incorrectly allowed the definite assignment assertion operator with class methods. This will no longer be allowed starting with this release. ### [`v0.17.4`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0174) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.3...v0.17.4) - Implement HTTP `HEAD` requests in serve mode ([#&#8203;2851](https://github.com/evanw/esbuild/issues/2851)) Previously esbuild's serve mode only responded to HTTP `GET` requests. With this release, esbuild's serve mode will also respond to HTTP `HEAD` requests, which are just like HTTP `GET` requests except that the body of the response is omitted. - Permit top-level await in dead code branches ([#&#8203;2853](https://github.com/evanw/esbuild/issues/2853)) Adding top-level await to a file has a few consequences with esbuild: 1. It causes esbuild to assume that the input module format is ESM, since top-level await is only syntactically valid in ESM. That prevents you from using `module` and `exports` for exports and also enables strict mode, which disables certain syntax and changes how function hoisting works (among other things). 2. This will cause esbuild to fail the build if either top-level await isn't supported by your language target (e.g. it's not supported in ES2021) or if top-level await isn't supported by the chosen output format (e.g. it's not supported with CommonJS). 3. Doing this will prevent you from using `require()` on this file or on any file that imports this file (even indirectly), since the `require()` function doesn't return a promise and so can't represent top-level await. This release relaxes these rules slightly: rules 2 and 3 will now no longer apply when esbuild has identified the code branch as dead code, such as when it's behind an `if (false)` check. This should make it possible to use esbuild to convert code into different output formats that only uses top-level await conditionally. This release does not relax rule 1. Top-level await will still cause esbuild to unconditionally consider the input module format to be ESM, even when the top-level `await` is in a dead code branch. This is necessary because whether the input format is ESM or not affects the whole file, not just the dead code branch. - Fix entry points where the entire file name is the extension ([#&#8203;2861](https://github.com/evanw/esbuild/issues/2861)) Previously if you passed esbuild an entry point where the file extension is the entire file name, esbuild would use the parent directory name to derive the name of the output file. For example, if you passed esbuild a file `./src/.ts` then the output name would be `src.js`. This bug happened because esbuild first strips the file extension to get `./src/` and then joins the path with the working directory to get the absolute path (e.g. `join("/working/dir", "./src/")` gives `/working/dir/src`). However, the join operation also canonicalizes the path which strips the trailing `/`. Later esbuild uses the "base name" operation to extract the name of the output file. Since there is no trailing `/`, esbuild returns `"src"` as the base name instead of `""`, which causes esbuild to incorrectly include the directory name in the output file name. This release fixes this bug by deferring the stripping of the file extension until after all path manipulations have been completed. So now the file `./src/.ts` will generate an output file named `.js`. - Support replacing property access expressions with inject At a high level, this change means the `inject` feature can now replace all of the same kinds of names as the `define` feature. So `inject` is basically now a more powerful version of `define`, instead of previously only being able to do some of the things that `define` could do. Soem background is necessary to understand this change if you aren't already familiar with the `inject` feature. The `inject` feature lets you replace references to global variable with a shim. It works like this: 1. Put the shim in its own file 2. Export the shim as the name of the global variable you intend to replace 3. Pass the file to esbuild using the `inject` feature For example, if you inject the following file using `--inject:./injected.js`: ```js // injected.js let processShim = { cwd: () => '/' } export { processShim as process } ``` Then esbuild will replace all references to `process` with the `processShim` variable, which will cause `process.cwd()` to return `'/'`. This feature is sort of abusing the ESM export alias syntax to specify the mapping of global variables to shims. But esbuild works this way because using this syntax for that purpose is convenient and terse. However, if you wanted to replace a property access expression, the process was more complicated and not as nice. You would have to: 1. Put the shim in its own file 2. Export the shim as some random name 3. Pass the file to esbuild using the `inject` feature 4. Use esbuild's `define` feature to map the property access expression to the random name you made in step 2 For example, if you inject the following file using `--inject:./injected2.js --define:process.cwd=someRandomName`: ```js // injected2.js let cwdShim = () => '/' export { cwdShim as someRandomName } ``` Then esbuild will replace all references to `process.cwd` with the `cwdShim` variable, which will also cause `process.cwd()` to return `'/'` (but which this time will not mess with other references to `process`, which might be desirable). With this release, using the inject feature to replace a property access expression is now as simple as using it to replace an identifier. You can now use JavaScript's ["arbitrary module namespace identifier names"](https://github.com/tc39/ecma262/pull/2154) feature to specify the property access expression directly using a string literal. For example, if you inject the following file using `--inject:./injected3.js`: ```js // injected3.js let cwdShim = () => '/' export { cwdShim as 'process.cwd' } ``` Then esbuild will now replace all references to `process.cwd` with the `cwdShim` variable, which will also cause `process.cwd()` to return `'/'` (but which will also not mess with other references to `process`). In addition to inserting a shim for a global variable that doesn't exist, another use case is replacing references to static methods on global objects with cached versions to both minify them better and to make access to them potentially faster. For example: ```js // Injected file let cachedMin = Math.min let cachedMax = Math.max export { cachedMin as 'Math.min', cachedMax as 'Math.max', } // Original input function clampRGB(r, g, b) { return { r: Math.max(0, Math.min(1, r)), g: Math.max(0, Math.min(1, g)), b: Math.max(0, Math.min(1, b)), } } // Old output (with --minify) function clampRGB(a,t,m){return{r:Math.max(0,Math.min(1,a)),g:Math.max(0,Math.min(1,t)),b:Math.max(0,Math.min(1,m))}} // New output (with --minify) var a=Math.min,t=Math.max;function clampRGB(h,M,m){return{r:t(0,a(1,h)),g:t(0,a(1,M)),b:t(0,a(1,m))}} ``` ### [`v0.17.3`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0173) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.2...v0.17.3) - Fix incorrect CSS minification for certain rules ([#&#8203;2838](https://github.com/evanw/esbuild/issues/2838)) Certain rules such as `@media` could previously be minified incorrectly. Due to a typo in the duplicate rule checker, two known `@`-rules that share the same hash code were incorrectly considered to be equal. This problem was made worse by the rule hashing code considering two unknown declarations (such as CSS variables) to have the same hash code, which also isn't optimal from a performance perspective. Both of these issues have been fixed: ```css /* Original input */ @&#8203;media (prefers-color-scheme: dark) { body { --VAR-1: #&#8203;000; } } @&#8203;media (prefers-color-scheme: dark) { body { --VAR-2: #&#8203;000; } } /* Old output (with --minify) */ @&#8203;media (prefers-color-scheme: dark){body{--VAR-2: #&#8203;000}} /* New output (with --minify) */ @&#8203;media (prefers-color-scheme: dark){body{--VAR-1: #&#8203;000}}@&#8203;media (prefers-color-scheme: dark){body{--VAR-2: #&#8203;000}} ``` ### [`v0.17.2`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0172) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.1...v0.17.2) - Add `onDispose` to the plugin API ([#&#8203;2140](https://github.com/evanw/esbuild/issues/2140), [#&#8203;2205](https://github.com/evanw/esbuild/issues/2205)) If your plugin wants to perform some cleanup after it's no longer going to be used, you can now use the `onDispose` API to register a callback for cleanup-related tasks. For example, if a plugin starts a long-running child process then it may want to terminate that process when the plugin is discarded. Previously there was no way to do this. Here's an example: ```js let examplePlugin = { name: 'example', setup(build) { build.onDispose(() => { console.log('This plugin is no longer used') }) }, } ``` These `onDispose` callbacks will be called after every `build()` call regardless of whether the build failed or not as well as after the first `dispose()` call on a given build context. ### [`v0.17.1`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01719) [Compare Source](https://github.com/evanw/esbuild/compare/v0.17.0...v0.17.1) - Fix CSS transform bugs with nested selectors that start with a combinator ([#&#8203;3096](https://github.com/evanw/esbuild/issues/3096)) This release fixes several bugs regarding transforming nested CSS into non-nested CSS for older browsers. The bugs were due to lack of test coverage for nested selectors with more than one compound selector where they all start with the same combinator. Here's what some problematic cases look like before and after these fixes: ```css /* Original code */ .foo { > &a, > &b { color: red; } } .bar { > &a, + &b { color: green; } } /* Old output (with --target=chrome90) */ .foo :is(> .fooa, > .foob) { color: red; } .bar :is(> .bara, + .barb) { color: green; } /* New output (with --target=chrome90) */ .foo > :is(a.foo, b.foo) { color: red; } .bar > a.bar, .bar + b.bar { color: green; } ``` - Fix bug with TypeScript parsing of instantiation expressions followed by `=` ([#&#8203;3111](https://github.com/evanw/esbuild/issues/3111)) This release fixes esbuild's TypeScript-to-JavaScript conversion code in the case where a potential instantiation expression is followed immediately by a `=` token (such that the trailing `>` becomes a `>=` token). Previously esbuild considered that to still be an instantiation expression, but the official TypeScript compiler considered it to be a `>=` operator instead. This release changes esbuild's interpretation to match TypeScript. This edge case currently [appears to be problematic](https://sucrase.io/#transforms=typescript\&compareWithTypeScript=true\&code=x%3Cy%3E%3Da%3Cb%3Cc%3E%3E\(\)) for other TypeScript-to-JavaScript converters as well: | Original code | TypeScript | esbuild 0.17.18 | esbuild 0.17.19 | Sucrase | Babel | |---|---|---|---|---|---| | `x<y>=a<b<c>>()` | `x<y>=a();` | `x=a();` | `x<y>=a();` | `x=a()` | Invalid left-hand side in assignment expression | - Avoid removing unrecognized directives from the directive prologue when minifying ([#&#8203;3115](https://github.com/evanw/esbuild/issues/3115)) The [directive prologue](https://262.ecma-international.org/6.0/#sec-directive-prologues-and-the-use-strict-directive) in JavaScript is a sequence of top-level string expressions that come before your code. The only directives that JavaScript engines currently recognize are `use strict` and sometimes `use asm`. However, the people behind React have made up their own directive for their own custom dialect of JavaScript. Previously esbuild only preserved the `use strict` directive when minifying, although you could still write React JavaScript with esbuild using something like `--banner:js="'your directive here';"`. With this release, you can now put arbitrary directives in the entry point and esbuild will preserve them in its minified output: ```js // Original code 'use wtf'; console.log(123) // Old output (with --minify) console.log(123); // New output (with --minify) "use wtf";console.log(123); ``` Note that this means esbuild will no longer remove certain stray top-level strings when minifying. This behavior is an intentional change because these stray top-level strings are actually part of the directive prologue, and could potentially have semantics assigned to them (as was the case with React). - Improved minification of binary shift operators With this release, esbuild's minifier will now evaluate the `<<` and `>>>` operators if the resulting code would be shorter: ```js // Original code console.log(10 << 10, 10 << 20, -123 >>> 5, -123 >>> 10); // Old output (with --minify) console.log(10<<10,10<<20,-123>>>5,-123>>>10); // New output (with --minify) console.log(10240,10<<20,-123>>>5,4194303); ``` ### [`v0.17.0`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;0170) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.17...v0.17.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.16.0` or `~0.16.0`. See npm's documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. At a high level, the breaking changes in this release fix some long-standing issues with the design of esbuild's incremental, watch, and serve APIs. This release also introduces some exciting new features such as live reloading. In detail: - Move everything related to incremental builds to a new `context` API ([#&#8203;1037](https://github.com/evanw/esbuild/issues/1037), [#&#8203;1606](https://github.com/evanw/esbuild/issues/1606), [#&#8203;2280](https://github.com/evanw/esbuild/issues/2280), [#&#8203;2418](https://github.com/evanw/esbuild/issues/2418)) This change removes the `incremental` and `watch` options as well as the `serve()` method, and introduces a new `context()` method. The context method takes the same arguments as the `build()` method but only validates its arguments and does not do an initial build. Instead, builds can be triggered using the `rebuild()`, `watch()`, and `serve()` methods on the returned context object. The new context API looks like this: ```js // Create a context for incremental builds const context = await esbuild.context({ entryPoints: ['app.ts'], bundle: true, }) // Manually do an incremental build const result = await context.rebuild() // Enable watch mode await context.watch() // Enable serve mode await context.serve() // Dispose of the context context.dispose() ``` The switch to the context API solves a major issue with the previous API which is that if the initial build fails, a promise is thrown in JavaScript which prevents you from accessing the returned result object. That prevented you from setting up long-running operations such as watch mode when the initial build contained errors. It also makes tearing down incremental builds simpler as there is now a single way to do it instead of three separate ways. In addition, this release also makes some subtle changes to how incremental builds work. Previously every call to `rebuild()` started a new build. If you weren't careful, then builds could actually overlap. This doesn't cause any problems with esbuild itself, but could potentially cause problems with plugins (esbuild doesn't even give you a way to identify which overlapping build a given plugin callback is running on). Overlapping builds also arguably aren't useful, or at least aren't useful enough to justify the confusion and complexity that they bring. With this release, there is now only ever a single active build per context. Calling `rebuild()` before the previous rebuild has finished now "merges" with the existing rebuild instead of starting a new build. - Allow using `watch` and `serve` together ([#&#8203;805](https://github.com/evanw/esbuild/issues/805), [#&#8203;1650](https://github.com/evanw/esbuild/issues/1650), [#&#8203;2576](https://github.com/evanw/esbuild/issues/2576)) Previously it was not possible to use watch mode and serve mode together. The rationale was that watch mode is one way of automatically rebuilding your project and serve mode is another (since serve mode automatically rebuilds on every request). However, people want to combine these two features to make "live reloading" where the browser automatically reloads the page when files are changed on the file system. This release now allows you to use these two features together. You can only call the `watch()` and `serve()` APIs once each per context, but if you call them together on the same context then esbuild will automatically rebuild both when files on the file system are changed *and* when the server serves a request. - Support "live reloading" through server-sent events ([#&#8203;802](https://github.com/evanw/esbuild/issues/802)) [Server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) are a simple way to pass one-directional messages asynchronously from the server to the client. Serve mode now provides a `/esbuild` endpoint with an `change` event that triggers every time esbuild's output changes. So you can now implement simple "live reloading" (i.e. reloading the page when a file is edited and saved) like this: ```js new EventSource('/esbuild').addEventListener('change', () => location.reload()) ``` The event payload is a JSON object with the following shape: ```ts interface ChangeEvent { added: string[] removed: string[] updated: string[] } ``` This JSON should also enable more complex live reloading scenarios. For example, the following code hot-swaps changed CSS `<link>` tags in place without reloading the page (but still reloads when there are other types of changes): ```js new EventSource('/esbuild').addEventListener('change', e => { const { added, removed, updated } = JSON.parse(e.data) if (!added.length && !removed.length && updated.length === 1) { for (const link of document.getElementsByTagName("link")) { const url = new URL(link.href) if (url.host === location.host && url.pathname === updated[0]) { const next = link.cloneNode() next.href = updated[0] + '?' + Math.random().toString(36).slice(2) next.onload = () => link.remove() link.parentNode.insertBefore(next, link.nextSibling) return } } } location.reload() }) ``` Implementing live reloading like this has a few known caveats: - These events only trigger when esbuild's output changes. They do not trigger when files unrelated to the build being watched are changed. If your HTML file references other files that esbuild doesn't know about and those files are changed, you can either manually reload the page or you can implement your own live reloading infrastructure instead of using esbuild's built-in behavior. - The `EventSource` API is supposed to automatically reconnect for you. However, there's a bug in Firefox that breaks this if the server is ever temporarily unreachable: https://bugzilla.mozilla.org/show_bug.cgi?id=1809332. Workarounds are to use any other browser, to manually reload the page if this happens, or to write more complicated code that manually closes and re-creates the `EventSource` object if there is a connection error. I'm hopeful that this bug will be fixed. - Browser vendors have decided to not implement HTTP/2 without TLS. This means that each `/esbuild` event source will take up one of your precious 6 simultaneous per-domain HTTP/1.1 connections. So if you open more than six HTTP tabs that use this live-reloading technique, you will be unable to use live reloading in some of those tabs (and other things will likely also break). The workaround is to enable HTTPS, which is now possible to do in esbuild itself (see below). - Add built-in support for HTTPS ([#&#8203;2169](https://github.com/evanw/esbuild/issues/2169)) You can now tell esbuild's built-in development server to use HTTPS instead of HTTP. This is sometimes necessary because browser vendors have started making modern web features unavailable to HTTP websites. Previously you had to put a proxy in front of esbuild to enable HTTPS since esbuild's development server only supported HTTP. But with this release, you can now enable HTTPS with esbuild without an additional proxy. To enable HTTPS with esbuild: 1. Generate a self-signed certificate. There are many ways to do this. Here's one way, assuming you have `openssl` installed: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 9999 -nodes -subj /CN=127.0.0.1 2. Add `--keyfile=key.pem` and `--certfile=cert.pem` to your esbuild development server command 3. Click past the scary warning in your browser when you load your page If you have more complex needs than this, you can still put a proxy in front of esbuild and use that for HTTPS instead. Note that if you see the message "Client sent an HTTP request to an HTTPS server" when you load your page, then you are using the incorrect protocol. Replace `http://` with `https://` in your browser's URL bar. Keep in mind that esbuild's HTTPS support has nothing to do with security. The only reason esbuild now supports HTTPS is because browsers have made it impossible to do local development with certain modern web features without jumping through these extra hoops. *Please do not use esbuild's development server for anything that needs to be secure.* It's only intended for local development and no considerations have been made for production environments whatsoever. - Better support copying `index.html` into the output directory ([#&#8203;621](https://github.com/evanw/esbuild/issues/621), [#&#8203;1771](https://github.com/evanw/esbuild/issues/1771)) Right now esbuild only supports JavaScript and CSS as first-class content types. Previously this meant that if you were building a website with a HTML file, a JavaScript file, and a CSS file, you could use esbuild to build the JavaScript file and the CSS file into the output directory but not to copy the HTML file into the output directory. You needed a separate `cp` command for that. Or so I thought. It turns out that the `copy` loader added in version 0.14.44 of esbuild is sufficient to have esbuild copy the HTML file into the output directory as well. You can add something like `index.html --loader:.html=copy` and esbuild will copy `index.html` into the output directory for you. The benefits of this are a) you don't need a separate `cp` command and b) the `index.html` file will automatically be re-copied when esbuild is in watch mode and the contents of `index.html` are edited. This also goes for other non-HTML file types that you might want to copy. This pretty much already worked. The one thing that didn't work was that esbuild's built-in development server previously only supported implicitly loading `index.html` (e.g. loading `/about/index.html` when you visit `/about/`) when `index.html` existed on the file system. Previously esbuild didn't support implicitly loading `index.html` if it was a build result. That bug has been fixed with this release so it should now be practical to use the `copy` loader to do this. - Fix `onEnd` not being called in serve mode ([#&#8203;1384](https://github.com/evanw/esbuild/issues/1384)) Previous releases had a bug where plugin `onEnd` callbacks weren't called when using the top-level `serve()` API. This API no longer exists and the internals have been reimplemented such that `onEnd` callbacks should now always be called at the end of every build. - Incremental builds now write out build results differently ([#&#8203;2104](https://github.com/evanw/esbuild/issues/2104)) Previously build results were always written out after every build. However, this could cause the output directory to fill up with files from old builds if code splitting was enabled, since the file names for code splitting chunks contain content hashes and old files were not deleted. With this release, incremental builds in esbuild will now delete old output files from previous builds that are no longer relevant. Subsequent incremental builds will also no longer overwrite output files whose contents haven't changed since the previous incremental build. - The `onRebuild` watch mode callback was removed ([#&#8203;980](https://github.com/evanw/esbuild/issues/980), [#&#8203;2499](https://github.com/evanw/esbuild/issues/2499)) Previously watch mode accepted an `onRebuild` callback which was called whenever watch mode rebuilt something. This was not great in practice because if you are running code after a build, you likely want that code to run after every build, not just after the second and subsequent builds. This release removes option to provide an `onRebuild` callback. You can create a plugin with an `onEnd` callback instead. The `onEnd` plugin API already exists, and is a way to run some code after every build. - You can now return errors from `onEnd` ([#&#8203;2625](https://github.com/evanw/esbuild/issues/2625)) It's now possible to add additional build errors and/or warnings to the current build from within your `onEnd` callback by returning them in an array. This is identical to how the `onStart` callback already works. The evaluation of `onEnd` callbacks have been moved around a bit internally to make this possible. Note that the build will only fail (i.e. reject the promise) if the additional errors are returned from `onEnd`. Adding additional errors to the result object that's passed to `onEnd` won't affect esbuild's behavior at all. - Print URLs and ports from the Go and JS APIs ([#&#8203;2393](https://github.com/evanw/esbuild/issues/2393)) Previously esbuild's CLI printed out something like this when serve mode is active: > Local: http://127.0.0.1:8000/ > Network: http://192.168.0.1:8000/ The CLI still does this, but now the JS and Go serve mode APIs will do this too. This only happens when the log level is set to `verbose`, `debug`, or `info` but not when it's set to `warning`, `error`, or `silent`. ##### Upgrade guide for existing code: - Rebuild (a.k.a. incremental build): Before: ```js const result = await esbuild.build({ ...buildOptions, incremental: true }); builds.push(result); for (let i = 0; i < 4; i++) builds.push(await result.rebuild()); await result.rebuild.dispose(); // To free resources ``` After: ```js const ctx = await esbuild.context(buildOptions); for (let i = 0; i < 5; i++) builds.push(await ctx.rebuild()); await ctx.dispose(); // To free resources ``` Previously the first build was done differently than subsequent builds. Now both the first build and subsequent builds are done using the same API. - Serve: Before: ```js const serveResult = await esbuild.serve(serveOptions, buildOptions); ... serveResult.stop(); await serveResult.wait; // To free resources ``` After: ```js const ctx = await esbuild.context(buildOptions); const serveResult = await ctx.serve(serveOptions); ... await ctx.dispose(); // To free resources ``` - Watch: Before: ```js const result = await esbuild.build({ ...buildOptions, watch: true }); ... result.stop(); // To free resources ``` After: ```js const ctx = await esbuild.context(buildOptions); await ctx.watch(); ... await ctx.dispose(); // To free resources ``` - Watch with `onRebuild`: Before: ```js const onRebuild = (error, result) => { if (error) console.log('subsequent build:', error); else console.log('subsequent build:', result); }; try { const result = await esbuild.build({ ...buildOptions, watch: { onRebuild } }); console.log('first build:', result); ... result.stop(); // To free resources } catch (error) { console.log('first build:', error); } ``` After: ```js const plugins = [{ name: 'my-plugin', setup(build) { let count = 0; build.onEnd(result => { if (count++ === 0) console.log('first build:', result); else console.log('subsequent build:', result); }); }, }]; const ctx = await esbuild.context({ ...buildOptions, plugins }); await ctx.watch(); ... await ctx.dispose(); // To free resources ``` The `onRebuild` function has now been removed. The replacement is to make a plugin with an `onEnd` callback. Previously `onRebuild` did not fire for the first build (only for subsequent builds). This was usually problematic, so using `onEnd` instead of `onRebuild` is likely less error-prone. But if you need to emulate the old behavior of `onRebuild` that ignores the first build, then you'll need to manually count and ignore the first build in your plugin (as demonstrated above). Notice how all of these API calls are now done off the new context object. You should now be able to use all three kinds of incremental builds (`rebuild`, `serve`, and `watch`) together on the same context object. Also notice how calling `dispose` on the context is now the common way to discard the context and free resources in all of these situations. ### [`v0.16.17`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01617) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.16...v0.16.17) - Fix additional comment-related regressions ([#&#8203;2814](https://github.com/evanw/esbuild/issues/2814)) This release fixes more edge cases where the new comment preservation behavior that was added in 0.16.14 could introduce syntax errors. Specifically: ```js x = () => (/* comment */ {}) for ((/* comment */ let).x of y) ; function *f() { yield (/* comment */class {}) } ``` These cases caused esbuild to generate code with a syntax error in version 0.16.14 or above. These bugs have now been fixed. ### [`v0.16.16`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01616) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.15...v0.16.16) - Fix a regression caused by comment preservation ([#&#8203;2805](https://github.com/evanw/esbuild/issues/2805)) The new comment preservation behavior that was added in 0.16.14 introduced a regression where comments in certain locations could cause esbuild to omit certain necessary parentheses in the output. The outermost parentheses were incorrectly removed for the following syntax forms, which then introduced syntax errors: ```js (/* comment */ { x: 0 }).x; (/* comment */ function () { })(); (/* comment */ class { }).prototype; ``` This regression has been fixed. ### [`v0.16.15`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01615) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.14...v0.16.15) - Add `format` to input files in the JSON metafile data When `--metafile` is enabled, input files may now have an additional `format` field that indicates the export format used by this file. When present, the value will either be `cjs` for CommonJS-style exports or `esm` for ESM-style exports. This can be useful in bundle analysis. For example, esbuild's new [Bundle Size Analyzer](https://esbuild.github.io/analyze/) now uses this information to visualize whether ESM or CommonJS was used for each directory and file of source code (click on the CJS/ESM bar at the top). This information is helpful when trying to reduce the size of your bundle. Using the ESM variant of a dependency instead of the CommonJS variant always results in a faster and smaller bundle because it omits CommonJS wrappers, and also may result in better tree-shaking as it allows esbuild to perform tree-shaking at the statement level instead of the module level. - Fix a bundling edge case with dynamic import ([#&#8203;2793](https://github.com/evanw/esbuild/issues/2793)) This release fixes a bug where esbuild's bundler could produce incorrect output. The problematic edge case involves the entry point importing itself using a dynamic `import()` expression in an imported file, like this: ```js // src/a.js export const A = 42; // src/b.js export const B = async () => (await import(".")).A // src/index.js export * from "./a" export * from "./b" ``` - Remove new type syntax from type declarations in the `esbuild` package ([#&#8203;2798](https://github.com/evanw/esbuild/issues/2798)) Previously you needed to use TypeScript 4.3 or newer when using the `esbuild` package from TypeScript code due to the use of a getter in an interface in `node_modules/esbuild/lib/main.d.ts`. This release removes this newer syntax to allow people with versions of TypeScript as far back as TypeScript 3.5 to use this latest version of the `esbuild` package. Here is change that was made to esbuild's type declarations: ```diff export interface OutputFile { /** "text" as bytes */ contents: Uint8Array; /** "contents" as text (changes automatically with "contents") */ - get text(): string; + readonly text: string; } ``` ### [`v0.16.14`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01614) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.13...v0.16.14) - Preserve some comments in expressions ([#&#8203;2721](https://github.com/evanw/esbuild/issues/2721)) Various tools give semantic meaning to comments embedded inside of expressions. For example, Webpack and Vite have special "magic comments" that can be used to affect code splitting behavior: ```js import(/* webpackChunkName: "foo" */ '../foo'); import(/* @&#8203;vite-ignore */ dynamicVar); new Worker(/* webpackChunkName: "bar" */ new URL("../bar.ts", import.meta.url)); new Worker(new URL('./path', import.meta.url), /* @&#8203;vite-ignore */ dynamicOptions); ``` Since esbuild can be used as a preprocessor for these tools (e.g. to strip TypeScript types), it can be problematic if esbuild doesn't do additional work to try to retain these comments. Previously esbuild special-cased Webpack comments in these specific locations in the AST. But Vite would now like to use similar comments, and likely other tools as well. So with this release, esbuild now will attempt to preserve some comments inside of expressions in more situations than before. This behavior is mainly intended to preserve these special "magic comments" that are meant for other tools to consume, although esbuild will no longer only preserve Webpack-specific comments so it should now be tool-agnostic. There is no guarantee that all such comments will be preserved (especially when `--minify-syntax` is enabled). So this change does *not* mean that esbuild is now usable as a code formatter. In particular comment preservation is more likely to happen with leading comments than with trailing comments. You should put comments that you want to be preserved *before* the relevant expression instead of after it. Also note that this change does not retain any more statement-level comments than before (i.e. comments not embedded inside of expressions). Comment preservation is not enabled when `--minify-whitespace` is enabled (which is automatically enabled when you use `--minify`). ### [`v0.16.13`](https://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01613) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.12...v0.16.13) - Publish a new bundle visualization tool While esbuild provides bundle metadata via the `--metafile` flag, previously esbuild left analysis of it completely up to third-party tools (well, outside of the rudimentary `--analyze` flag). However, the esbuild website now has a built-in bundle visualization tool: - https://esbuild.github.io/analyze/ You can pass `--metafile` to esbuild to output bundle metadata, then upload that JSON file to this tool to visualize your bundle. This is helpful for answering questions such as: - Which packages are included in my bundle? - How did a specific file get included? - How small did a specific file compress to? - Was a specific file tree-shaken or not? I'm publishing this tool because I think esbuild should provide *some* answer to "how do I visualize my bundle" without requiring people to reach for third-party tools. At the moment the tool offers two types of visualizations: a radial "sunburst chart" and a linear "flame chart". They serve slightly different but overlapping use cases (e.g. the sunburst chart is more keyboard-accessible while the flame chart is easier with the mouse). This tool may continue to evolve over time. - Fix `--metafile` and `--mangle-cache` with `--watch` ([#&#8203;1357](https://github.com/evanw/esbuild/issues/1357)) The CLI calls the Go API and then also writes out the metafile and/or mangle cache JSON files if those features are enabled. This extra step is necessary because these files are returned by the Go API as in-memory strings. However, this extra step accidentally didn't happen for all builds after the initial build when watch mode was enabled. This behavior used to work but it was broken in version 0.14.18 by the introduction of the mangle cache feature. This release fixes the combination of these features, so the metafile and mangle cache features should now work with watch mode. This behavior was only broken for the CLI, not for the JS or Go APIs. - Add an `original` field to the metafile The metadata file JSON now has an additional field: each import in an input file now contains the pre-resolved path in the `original` field in addition to the post-resolved path in the `path` field. This means it's now possible to run certain additional analysis over your bundle. For example, you should be able to use this to detect when the same package subpath is represented multiple times in the bundle, either because multiple versions of a package were bundled or because a package is experiencing the [dual-package hazard](https://nodejs.org/api/packages.html#dual-package-hazard). ### [`v0.16.12`](https://github.com/evanw/esbuild/releases/tag/v0.16.12) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.11...v0.16.12) - Loader defaults to `js` for extensionless files ([#&#8203;2776](https://github.com/evanw/esbuild/issues/2776)) Certain packages contain files without an extension. For example, the `yargs` package contains the file `yargs/yargs` which has no extension. Node, Webpack, and Parcel can all understand code that imports `yargs/yargs` because they assume that the file is JavaScript. However, esbuild was previously unable to understand this code because it relies on the file extension to tell it how to interpret the file. With this release, esbuild will now assume files without an extension are JavaScript files. This can be customized by setting the loader for `""` (the empty string, representing files without an extension) to another loader. For example, if you want files without an extension to be treated as CSS instead, you can do that like this: - CLI: esbuild --bundle --loader:=css - JS: ```js esbuild.build({ bundle: true, loader: { '': 'css' }, }) ``` - Go: ```go api.Build(api.BuildOptions{ Bundle: true, Loader: map[string]api.Loader{"": api.LoaderCSS}, }) ``` In addition, the `"type"` field in `package.json` files now only applies to files with an explicit `.js`, `.jsx`, `.ts`, or `.tsx` extension. Previously it was incorrectly applied by esbuild to all files that had an extension other than `.mjs`, `.mts`, `.cjs`, or `.cts` including extensionless files. So for example an extensionless file in a `"type": "module"` package is now treated as CommonJS instead of ESM. ### [`v0.16.11`](https://github.com/evanw/esbuild/releases/tag/v0.16.11) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.10...v0.16.11) - Avoid a syntax error in the presence of direct `eval` ([#&#8203;2761](https://github.com/evanw/esbuild/issues/2761)) The behavior of nested `function` declarations in JavaScript depends on whether the code is run in strict mode or not. It would be problematic if esbuild preserved nested `function` declarations in its output because then the behavior would depend on whether the output was run in strict mode or not instead of respecting the strict mode behavior of the original source code. To avoid this, esbuild transforms nested `function` declarations to preserve the intended behavior of the original source code regardless of whether the output is run in strict mode or not: ```js // Original code if (true) { function foo() {} console.log(!!foo) foo = null console.log(!!foo) } console.log(!!foo) // Transformed code if (true) { let foo2 = function() { }; var foo = foo2; console.log(!!foo2); foo2 = null; console.log(!!foo2); } console.log(!!foo); ``` In the above example, the original code should print `true false true` because it's not run in strict mode (it doesn't contain `"use strict"` and is not an ES module). The code that esbuild generates has been transformed such that it prints `true false true` regardless of whether it's run in strict mode or not. However, this transformation is impossible if the code contains direct `eval` because direct `eval` "poisons" all containing scopes by preventing anything in those scopes from being renamed. That prevents esbuild from splitting up accesses to `foo` into two separate variables with different names. Previously esbuild still did this transformation but with two variables both named `foo`, which is a syntax error. With this release esbuild will now skip doing this transformation when direct `eval` is present to avoid generating code with a syntax error. This means that the generated code may no longer behave as intended since the behavior depends on the run-time strict mode setting instead of the strict mode setting present in the original source code. To fix this problem, you will need to remove the use of direct `eval`. - Fix a bundling scenario involving multiple symlinks ([#&#8203;2773](https://github.com/evanw/esbuild/issues/2773), [#&#8203;2774](https://github.com/evanw/esbuild/issues/2774)) This release contains a fix for a bundling scenario involving an import path where multiple path segments are symlinks. Previously esbuild was unable to resolve certain import paths in this scenario, but these import paths should now work starting with this release. This fix was contributed by [@&#8203;onebytegone](https://github.com/onebytegone). ### [`v0.16.10`](https://github.com/evanw/esbuild/releases/tag/v0.16.10) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.9...v0.16.10) - Change the default "legal comment" behavior again ([#&#8203;2745](https://github.com/evanw/esbuild/issues/2745)) 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). 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: ```js /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ ``` 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: ```js /*! Bundled license information: typescript/lib/typescript.js: (*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** *) */ ``` Note that you can still customize this behavior with the `--legal-comments=` flag. For example, you can use `--legal-comments=none` to turn this off, or you can use `--legal-comments=linked` to put these comments in a separate `.LEGAL.txt` file instead. - Enable `external` legal comments with the transform API ([#&#8203;2390](https://github.com/evanw/esbuild/issues/2390)) Previously esbuild's transform API only supported `none`, `inline`, or `eof` legal comments. With this release, `external` legal 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: ```js const { code, legalComments } = await esbuild.transform(input, { legalComments: 'external', }) ``` - Go: ```go result := api.Transform(input, api.TransformOptions{ LegalComments: api.LegalCommentsEndOfFile, }) code := result.Code legalComments := result.LegalComments ``` - Fix duplicate function declaration edge cases ([#&#8203;2757](https://github.com/evanw/esbuild/issues/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` ([#&#8203;2715](https://github.com/evanw/esbuild/issues/2715)) Previously the names passed to the `alias` feature had to be the name of a package (with or without a package scope). With this release, you can now also use the `alias` feature with package subpaths. So for example you can now create an alias that substitutes `@org/pkg/lib` with something else. ### [`v0.16.9`](https://github.com/evanw/esbuild/releases/tag/v0.16.9) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.8...v0.16.9) - 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 `function` declarations or all `var` declarations. However, esbuild was overly permissive and allowed this when duplicate entries were either `function` declarations or `var` declarations (even if they were mixed). This check has now been made more restrictive to match the JavaScript specification: ```js // JavaScript allows this var a function a() {} { var b var b function c() {} function c() {} } // JavaScript doesn't allow this { var d function d() {} } ``` - Add a type declaration for the new `empty` loader ([#&#8203;2755](https://github.com/evanw/esbuild/pull/2755)) I forgot to add this in the previous release. It has now been added. This fix was contributed by [@&#8203;fz6m](https://github.com/fz6m). - Add support for the `v` flag in regular expression literals People are currently working on adding a `v` flag 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 than `esnext`, esbuild will transform regular expression literals containing this flag into a `new RegExp()` constructor call so the resulting code doesn't have a syntax error. This enables you to provide a polyfill for `RegExp` that implements the `v` flag 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 `name` properties The `--keep-names` property attempts to preserve the original value of the `name` property 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 the `name` property on the function or class object. However, this should not be done for classes with a static `name` property since in that case the explicitly-defined `name` property overwrites the automatically-generated class name. With this release, esbuild will now no longer attempt to preserve the `name` property for classes with a static `name` property. ### [`v0.16.8`](https://github.com/evanw/esbuild/releases/tag/v0.16.8) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.7...v0.16.8) - Allow plugins to resolve injected files ([#&#8203;2754](https://github.com/evanw/esbuild/issues/2754)) Previously paths passed to the `inject` feature were always interpreted as file system paths. This meant that `onResolve` plugins would not be run for them and esbuild's default path resolver would always be used. This meant that the `inject` feature couldn't be used in the browser since the browser doesn't have access to a file system. This release runs paths passed to `inject` through esbuild's full path resolution pipeline so plugins now have a chance to handle them using `onResolve` callbacks. This makes it possible to write a plugin that makes esbuild's `inject` work in the browser. - Add the `empty` loader ([#&#8203;1541](https://github.com/evanw/esbuild/issues/1541), [#&#8203;2753](https://github.com/evanw/esbuild/issues/2753)) The new `empty` loader tells esbuild to pretend that a file is empty. So for example `--loader:.css=empty` effectively skips all imports of `.css` files in JavaScript so that they aren't included in the bundle, since `import "./some-empty-file"` in JavaScript doesn't bundle anything. You can also use the `empty` loader to remove asset references in CSS files. For example `--loader:.png=empty` causes esbuild to replace asset references such as `url(image.png)` with `url()` so that they are no longer included in the resulting style sheet. - Fix `</script>` and `</style>` escaping for non-default targets ([#&#8203;2748](https://github.com/evanw/esbuild/issues/2748)) The change in version 0.16.0 to give control over `</script>` escaping via `--supported:inline-script=false` or `--supported:inline-script=true` accidentally broke automatic escaping of `</script>` when an explicit `target` setting is specified. This release restores the correct automatic escaping of `</script>` (which should not depend on what `target` is set to). - Enable the `exports` field with `NODE_PATHS` ([#&#8203;2752](https://github.com/evanw/esbuild/issues/2752)) Node has a rarely-used feature where you can extend the set of directories that node searches for packages using the `NODE_PATHS` environment variable. While esbuild supports this too, previously it only supported the old `main` field path resolution but did not support the new `exports` field package resolution. This release makes the path resolution rules the same again for both `node_modules` directories and `NODE_PATHS` directories. ### [`v0.16.7`](https://github.com/evanw/esbuild/releases/tag/v0.16.7) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.6...v0.16.7) - Include `file` loader strings in metafile imports ([#&#8203;2731](https://github.com/evanw/esbuild/issues/2731)) Bundling a file with the `file` loader copies that file to the output directory and imports a module with the path to the copied file in the `default` export. Previously when bundling with the `file` loader, 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 the `imports` array with the kind `file-loader`: ```diff { ... "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 ([#&#8203;2071](https://github.com/evanw/esbuild/issues/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.js` imports `image.png` using the file loader and esbuild generates `out.js` and `image-LSAMBFUD.png`, the metadata for how many bytes of `out.js` are from `app.js` was slightly off (the metadata for the byte count of `out.js` was 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 the `bytesInOutput` values). - The alias feature now strips a trailing slash ([#&#8203;2730](https://github.com/evanw/esbuild/issues/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 `util` imports node's built-in module called `util` but importing `util/` tries to find a package called `util` on the file system. Previously attempting to use esbuild's package alias feature to replace imports to `util` with a specific file would fail because the file path would also gain a trailing slash (e.g. mapping `util` to `./file.js` turned `util/` 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.6`](https://github.com/evanw/esbuild/releases/tag/v0.16.6) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.5...v0.16.6) - Do not mark subpath imports as external with `--packages=external` ([#&#8203;2741](https://github.com/evanw/esbuild/issues/2741)) Node has a feature called [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) where special import paths that start with `#` are resolved using the `imports` field in the `package.json` file of the enclosing package. The intent of the newly-added `--packages=external` setting 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=external` no 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: - Legacy octal literals (non-zero integers starting with `0`) - The `0b`, `0o`, and `0x` numeric prefixes - Numbers containing `_` such as `1_000` - Leading and trailing `.` such as `0.` and `.0` - Numbers with a space after the `-` such as `- 1` - Add external imports to metafile ([#&#8203;905](https://github.com/evanw/esbuild/issues/905), [#&#8203;1768](https://github.com/evanw/esbuild/issues/1768), [#&#8203;1933](https://github.com/evanw/esbuild/issues/1933), [#&#8203;1939](https://github.com/evanw/esbuild/issues/1939)) External imports now appear in `imports` arrays in the metafile (which is present when bundling with `metafile: true`) next to normal imports, but additionally have `external: true` to set them apart. This applies both to files in the `inputs` section and the `outputs` section. Here's an example: ```diff { "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 `imports` array is now populated when bundling is disabled. So you can now use esbuild with bundling disabled to inspect a file's imports. ### [`v0.16.5`](https://github.com/evanw/esbuild/releases/tag/v0.16.5) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.4...v0.16.5) - Make it easy to exclude all packages from a bundle ([#&#8203;1958](https://github.com/evanw/esbuild/issues/1958), [#&#8203;1975](https://github.com/evanw/esbuild/issues/1975), [#&#8203;2164](https://github.com/evanw/esbuild/issues/2164), [#&#8203;2246](https://github.com/evanw/esbuild/issues/2246), [#&#8203;2542](https://github.com/evanw/esbuild/issues/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 `__dirname` and run-time file system calls to load files, which doesn't work after bundling with esbuild. Or they may compile a native `.node` extension that has similar expectations about the layout of the file system that are no longer true after bundling (even if the `.node` extension is copied next to the bundle). The way to get this to work with esbuild is to use the `--external:` flag. For example, the [`fsevents`](https://www.npmjs.com/package/fsevents) package contains a native `.node` extension and shouldn't be bundled. To bundle code that uses it, you can pass `--external:fsevents` to esbuild to exclude it from your bundle. You will then need to ensure that the `fsevents` package is still present when you run your bundle (e.g. by publishing your bundle to npm as a package with a dependency on `fsevents`). 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.json` file and passed the keys of the `dependencies`, `devDependencies`, `peerDependencies`, and/or `optionalDependencies` maps 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: esbuild --bundle --packages=external - JS: ```js esbuild.build({ bundle: true, packages: 'external', }) ``` - Go: ```go api.Build(api.BuildOptions{ Bundle: true, Packages: api.PackagesExternal, }) ``` Doing `--external:./node_modules/*` is still possible and still has the same behavior, but is no longer recommended. I recommend that you use the new `packages` feature instead. - Fix some subtle bugs with tagged template literals This release fixes a bug where minification could incorrectly change the value of `this` within tagged template literal function calls: ```js // Original code function f(x) { let z = y.z return z`` } // Old output (with --minify) function f(n){return y.z``} // New output (with --minify) function f(n){return(0,y.z)``} ``` This release also fixes a bug where using optional chaining with `--target=es2019` or earlier could incorrectly change the value of `this` within tagged template literal function calls: ```js // Original code var obj = { foo: function() { console.log(this === obj); } }; (obj?.foo)``; // Old output (with --target=es6) var obj = { foo: function() { console.log(this === obj); } }; (obj == null ? void 0 : obj.foo)``; // New output (with --target=es6) var __freeze = Object.freeze; var __defProp = Object.defineProperty; var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) })); var _a; var obj = { foo: function() { console.log(this === obj); } }; (obj == null ? void 0 : obj.foo).call(obj, _a || (_a = __template([""]))); ``` - 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.4`](https://github.com/evanw/esbuild/releases/tag/v0.16.4) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.3...v0.16.4) - Fix binary downloads from the `@esbuild/` scope for Deno ([#&#8203;2729](https://github.com/evanw/esbuild/issues/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.3`](https://github.com/evanw/esbuild/releases/tag/v0.16.3) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.2...v0.16.3) - Fix a hang with the JS API in certain cases ([#&#8203;2727](https://github.com/evanw/esbuild/issues/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 `stderr` stream set to `pipe` instead of `inherit`, in the child process you call esbuild's JS API and pass `incremental: true` but do not call `dispose()` on the returned `rebuild` object, and then call `process.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's `sync.WaitGroup` API 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 the `sync.WaitGroup` API for esbuild to use instead. ### [`v0.16.2`](https://github.com/evanw/esbuild/releases/tag/v0.16.2) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.1...v0.16.2) - Fix `process.env.NODE_ENV` substitution when transforming ([#&#8203;2718](https://github.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 `</script>` 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 ([#&#8203;2719](https://github.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` ([#&#8203;2720](https://github.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://github.com/evanw/esbuild/blob/HEAD/CHANGELOG.md#&#8203;01617) [Compare Source](https://github.com/evanw/esbuild/compare/v0.16.0...v0.16.1) - Fix additional comment-related regressions ([#&#8203;2814](https://github.com/evanw/esbuild/issues/2814)) This release fixes more edge cases where the new comment preservation behavior that was added in 0.16.14 could introduce syntax errors. Specifically: ```js x = () => (/* comment */ {}) for ((/* comment */ let).x of y) ; function *f() { yield (/* comment */class {}) } ``` These cases caused esbuild to generate code with a syntax error in version 0.16.14 or above. These bugs have now been fixed. ### [`v0.16.0`](https://github.com/evanw/esbuild/releases/tag/v0.16.0) [Compare Source](https://github.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 ([#&#8203;1843](https://github.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 ([#&#8203;2382](https://github.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 `</script>` ([#&#8203;2649](https://github.com/evanw/esbuild/issues/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: ```html <script> console.log("</script>"); </script> ``` 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 `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` ([#&#8203;2532](https://github.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 ([#&#8203;2417](https://github.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 ([#&#8203;714](https://github.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. 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://github.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://github.com/evanw/esbuild/releases/tag/v0.15.18) [Compare Source](https://github.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://github.com/evanw/esbuild/releases/tag/v0.15.17) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.16...v0.15.17) - Search for missing source map code on the file system ([#&#8203;2711](https://github.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` ([#&#8203;2712](https://github.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<T> = {}; type B = {} extends infer T extends {} ? A<T> : never; ``` TypeScript code that does this should now be parsed correctly. - Use `WebAssembly.instantiateStreaming` if available ([#&#8203;1036](https://github.com/evanw/esbuild/pull/1036), [#&#8203;1900](https://github.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 [@&#8203;lbwa](https://github.com/lbwa). - Preserve Webpack comments inside constructor calls ([#&#8203;2439](https://github.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://github.com/evanw/esbuild/releases/tag/v0.15.16) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.15...v0.15.16) - Add a package alias feature ([#&#8203;2191](https://github.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 ([#&#8203;2697](https://github.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 `<x y />`, `y` is a string) or an object spread (e.g. in `<x {...y} />`, `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 `<x {...{ [y]: z }} />`. When minification is enabled, esbuild's internal representation of this is something like `<x [y]={z} />` 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 `<x {...{[y]:z}}/>` in this scenario instead of crashing. ### [`v0.15.15`](https://github.com/evanw/esbuild/releases/tag/v0.15.15) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.14...v0.15.15) - Remove duplicate CSS rules across files ([#&#8203;2688](https://github.com/evanw/esbuild/issues/2688)) When two or more CSS rules are exactly the same (even if they are not adjacent), all but the last one can safely be removed: ```css /* Before */ a { color: red; } span { font-weight: bold; } a { color: red; } /* After */ span { font-weight: bold; } a { color: red; } ``` Previously esbuild only did this transformation within a single source file. But with this release, esbuild will now do this transformation across source files, which may lead to smaller CSS output if the same rules are repeated across multiple CSS source files in the same bundle. This transformation is only enabled when minifying (specifically when syntax minification is enabled). - Add `deno` as a valid value for `target` ([#&#8203;2686](https://github.com/evanw/esbuild/issues/2686)) The `target` setting in esbuild allows you to enable or disable JavaScript syntax features for a given version of a set of target JavaScript VMs. Previously [Deno](https://deno.land/) was not one of the JavaScript VMs that esbuild supported with `target`, but it will now be supported starting from this release. For example, versions of Deno older than v1.2 don't support the new `||=` operator, so adding e.g. `--target=deno1.0` to esbuild now lets you tell esbuild to transpile `||=` to older JavaScript. - Fix the `esbuild-wasm` package in Node v19 ([#&#8203;2683](https://github.com/evanw/esbuild/issues/2683)) A recent change to Node v19 added a non-writable `crypto` property to the global object: https://github.com/nodejs/node/pull/44897. This conflicts with Go's WebAssembly shim code, which overwrites the global `crypto` property. As a result, all Go-based WebAssembly code that uses the built-in shim (including esbuild) is now broken on Node v19. This release of esbuild fixes the issue by reconfiguring the global `crypto` property to be writable before invoking Go's WebAssembly shim code. - Fix CSS dimension printing exponent confusion edge case ([#&#8203;2677](https://github.com/evanw/esbuild/issues/2677)) In CSS, a dimension token has a numeric "value" part and an identifier "unit" part. For example, the dimension token `32px` has a value of `32` and a unit of `px`. The unit can be any valid CSS identifier. The value can be any number in floating-point format including an optional exponent (e.g. `-3.14e-0` has an exponent of `e-0`). The full details of this syntax are here: https://www.w3.org/TR/css-syntax-3/. To maintain the integrity of the dimension token through the printing process, esbuild must handle the edge case where the unit looks like an exponent. One such case is the dimension `1e\32` which has the value `1` and the unit `e2`. It would be bad if this dimension token was printed such that a CSS parser would parse it as a number token with the value `1e2` instead of a dimension token. The way esbuild currently does this is to escape the leading `e` in the dimension unit, so esbuild would parse `1e\32` but print `1\65 2` (both `1e\32` and `1\65 2` represent a dimension token with a value of `1` and a unit of `e2`). However, there is an even narrower edge case regarding this edge case. If the value part of the dimension token itself has an `e`, then it's not necessary to escape the `e` in the dimension unit because a CSS parser won't confuse the unit with the exponent even though it looks like one (since a number can only have at most one exponent). This came up because the grammar for the CSS `unicode-range` property uses a hack that lets you specify a hexadecimal range without quotes even though CSS has no token for a hexadecimal range. The hack is to allow the hexadecimal range to be parsed as a dimension token and optionally also a number token. Here is the grammar for `unicode-range`: unicode-range = <urange># <urange> = u '+' <ident-token> '?'* | u <dimension-token> '?'* | u <number-token> '?'* | u <number-token> <dimension-token> | u <number-token> <number-token> | u '+' '?'+ and here is an example `unicode-range` declaration that was problematic for esbuild: ```css @&#8203;font-face { unicode-range: U+0e2e-0e2f; } ``` This is parsed as a dimension with a value of `+0e2` and a unit of `e-0e2f`. This was problematic for esbuild because the unit starts with `e-0` which could be confused with an exponent when appended after a number, so esbuild was escaping the `e` character in the unit. However, this escaping is unnecessary because in this case the dimension value already has an exponent in it. With this release, esbuild will no longer unnecessarily escape the `e` in the dimension unit in these cases, which should fix the printing of `unicode-range` declarations. An aside: You may be wondering why esbuild is trying to escape the `e` at all and why it doesn't just pass through the original source code unmodified. The reason why esbuild does this is that, for robustness, esbuild's AST generally tries to omit semantically-unrelated information and esbuild's code printers always try to preserve the semantics of the underlying AST. That way the rest of esbuild's internals can just deal with semantics instead of presentation. They don't have to think about how the AST will be printed when changing the AST. This is the same reason that esbuild's JavaScript AST doesn't have a "parentheses" node (e.g. `a * (b + c)` is represented by the AST `multiply(a, add(b, c))` instead of `multiply(a, parentheses(add(b, c)))`). Instead, the printer automatically inserts parentheses as necessary to maintain the semantics of the AST, which means all of the optimizations that run over the AST don't have to worry about keeping the parentheses up to date. Similarly, the CSS AST for the dimension token stores the actual unit and the printer makes sure the unit is properly escaped depending on what value it's placed after. All of the other code operating on CSS ASTs doesn't have to worry about parsing escapes to compare units or about keeping escapes up to date when the AST is modified. Hopefully that makes sense. - Attempt to avoid creating the `node_modules/.cache` directory for people that use Yarn 2+ in Plug'n'Play mode ([#&#8203;2685](https://github.com/evanw/esbuild/issues/2685)) When Yarn's PnP mode is enabled, packages installed by Yarn may or may not be put inside `.zip` files. The specific heuristics for when this happens change over time in between Yarn versions. This is problematic for esbuild because esbuild's JavaScript package needs to execute a binary file inside the package. Yarn makes extensive modifications to Node's file system APIs at run time to pretend that `.zip` files are normal directories and to make it hard to tell whether a file is real or not (since in theory it doesn't matter). But they haven't modified Node's `child_process.execFileSync` API so attempting to execute a file inside a zip file fails. To get around this, esbuild previously used Node's file system APIs to copy the binary executable to another location before invoking `execFileSync`. Under the hood this caused Yarn to extract the file from the zip file into a real file that can then be run. However, esbuild copied its executable into `node_modules/.cache/esbuild`. This is the [official recommendation from the Yarn team](https://yarnpkg.com/advanced/rulebook/#packages-should-never-write-inside-their-own-folder-outside-of-postinstall) for where packages are supposed to put these types of files when Yarn PnP is being used. However, users of Yarn PnP with esbuild find this really annoying because they don't like looking at the `node_modules` directory. With this release, esbuild now sets `"preferUnplugged": true` in its `package.json` files, which tells newer versions of Yarn to not put esbuild's packages in a zip file. There may exist older versions of Yarn that don't support `preferUnplugged`. In that case esbuild should still copy the executable to a cache directory, so it should still run (hopefully, since I haven't tested this myself). Note that esbuild setting `"preferUnplugged": true` may have the side effect of esbuild taking up more space on the file system in the event that multiple platforms are installed simultaneously, or that you're using an older version of Yarn that always installs packages for all platforms. In that case you may want to update to a newer version of Yarn since Yarn has recently changed to only install packages for the current platform. ### [`v0.15.14`](https://github.com/evanw/esbuild/releases/tag/v0.15.14) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.13...v0.15.14) - Fix parsing of TypeScript `infer` inside a conditional `extends` ([#&#8203;2675](https://github.com/evanw/esbuild/issues/2675)) Unlike JavaScript, parsing TypeScript sometimes requires backtracking. The `infer A` type operator can take an optional constraint of the form `infer A extends B`. However, this syntax conflicts with the similar conditional type operator `A extends B ? C : D` in cases where the syntax is combined, such as `infer A extends B ? C : D`. This is supposed to be parsed as `(infer A) extends B ? C : D`. Previously esbuild incorrectly parsed this as `(infer A extends B) ? C : D` instead, which is a parse error since the `?:` conditional operator requires the `extends` keyword as part of the conditional type. TypeScript disambiguates by speculatively parsing the `extends` after the `infer`, but backtracking if a `?` token is encountered afterward. With this release, esbuild should now do the same thing, so esbuild should now correctly parse these types. Here's a real-world example of such a type: ```ts type Normalized<T> = T extends Array<infer A extends object ? infer A : never> ? Dictionary<Normalized<A>> : { [P in keyof T]: T[P] extends Array<infer A extends object ? infer A : never> ? Dictionary<Normalized<A>> : Normalized<T[P]> } ``` - Avoid unnecessary watch mode rebuilds when debug logging is enabled ([#&#8203;2661](https://github.com/evanw/esbuild/issues/2661)) When debug-level logs are enabled (such as with `--log-level=debug`), esbuild's path resolution subsystem generates debug log messages that say something like "Read 20 entries for directory /home/user" to help you debug what esbuild's path resolution is doing. This caused esbuild's watch mode subsystem to add a dependency on the full list of entries in that directory since if that changes, the generated log message would also have to be updated. However, meant that on systems where a parent directory undergoes constant directory entry churn, esbuild's watch mode would continue to rebuild if `--log-level=debug` was passed. With this release, these debug log messages are now generated by "peeking" at the file system state while bypassing esbuild's watch mode dependency tracking. So now watch mode doesn't consider the count of directory entries in these debug log messages to be a part of the build that needs to be kept up to date when the file system state changes. ### [`v0.15.13`](https://github.com/evanw/esbuild/releases/tag/v0.15.13) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.12...v0.15.13) - Add support for the TypeScript 4.9 `satisfies` operator ([#&#8203;2509](https://github.com/evanw/esbuild/pull/2509)) TypeScript 4.9 introduces a new operator called `satisfies` that lets you check that a given value satisfies a less specific type without casting it to that less specific type and without generating any additional code at run-time. It looks like this: ```ts const value = { foo: 1, bar: false } satisfies Record<string, number | boolean> console.log(value.foo.toFixed(1)) // TypeScript knows that "foo" is a number here ``` Before this existed, you could use a cast with `as` to check that a value satisfies a less specific type, but that removes any additional knowledge that TypeScript has about that specific value: ```ts const value = { foo: 1, bar: false } as Record<string, number | boolean> console.log(value.foo.toFixed(1)) // TypeScript no longer knows that "foo" is a number ``` You can read more about this feature in [TypeScript's blog post for 4.9](https://devblogs.microsoft.com/typescript/announcing-typescript-4-9-rc/#the-satisfies-operator) as well as [the associated TypeScript issue for this feature](https://github.com/microsoft/TypeScript/issues/47920). This feature was implemented in esbuild by [@&#8203;magic-akari](https://github.com/magic-akari). - Fix watch mode constantly rebuilding if the parent directory is inaccessible ([#&#8203;2640](https://github.com/evanw/esbuild/issues/2640)) Android is unusual in that it has an inaccessible directory in the path to the root, which esbuild was not originally built to handle. To handle cases like this, the path resolution layer in esbuild has a hack where it treats inaccessible directories as empty. However, esbuild's watch implementation currently triggers a rebuild if a directory previously encountered an error but the directory now exists. The assumption is that the previous error was caused by the directory not existing. Although that's usually the case, it's not the case for this particular parent directory on Android. Instead the error is that the directory previously existed but was inaccessible. This discrepancy between esbuild's path resolution layer and its watch mode was causing watch mode to rebuild continuously on Android. With this release, esbuild's watch mode instead checks for an error status change in the `readdir` file system call, so watch mode should no longer rebuild continuously on Android. - Apply a fix for a rare deadlock with the JavaScript API ([#&#8203;1842](https://github.com/evanw/esbuild/issues/1842), [#&#8203;2485](https://github.com/evanw/esbuild/issues/2485)) There have been reports of esbuild sometimes exiting with an "all goroutines are asleep" deadlock message from the Go language runtime. This issue hasn't made much progress until recently, where a possible cause was discovered (thanks to [@&#8203;jfirebaugh](https://github.com/jfirebaugh) for the investigation). This release contains a possible fix for that possible cause, so this deadlock may have been fixed. The fix cannot be easily verified because the deadlock is non-deterministic and rare. If this was indeed the cause, then this issue only affected the JavaScript API in situations where esbuild was already in the process of exiting. In detail: The underlying cause is that Go's [`sync.WaitGroup`](https://pkg.go.dev/sync#WaitGroup) API for waiting for a set of goroutines to finish is not fully thread-safe. Specifically it's not safe to call `Add()` concurrently with `Wait()` when the wait group counter is zero due to a data race. This situation could come up with esbuild's JavaScript API when the host JavaScript process closes the child process's stdin and the child process (with no active tasks) calls `Wait()` to check that there are no active tasks, at the same time as esbuild's watchdog timer calls `Add()` to add an active task (that pings the host to see if it's still there). The fix in this release is to avoid calling `Add()` once we learn that stdin has been closed but before we call `Wait()`. ### [`v0.15.12`](https://github.com/evanw/esbuild/releases/tag/v0.15.12) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.11...v0.15.12) - Fix minifier correctness bug with single-use substitutions ([#&#8203;2619](https://github.com/evanw/esbuild/issues/2619)) When minification is enabled, esbuild will attempt to eliminate variables that are only used once in certain cases. For example, esbuild minifies this code: ```js function getEmailForUser(name) { let users = db.table('users'); let user = users.find({ name }); let email = user?.get('email'); return email; } ``` into this code: ```js function getEmailForUser(e){return db.table("users").find({name:e})?.get("email")} ``` However, this transformation had a bug where esbuild did not correctly consider the "read" part of binary read-modify-write assignment operators. For example, it's incorrect to minify the following code into `bar += fn()` because the call to `fn()` might modify `bar`: ```js const foo = fn(); bar += foo; ``` In addition to fixing this correctness bug, this release also improves esbuild's output in the case where all values being skipped over are primitives: ```js function toneMapLuminance(r, g, b) { let hdr = luminance(r, g, b) let decay = 1 / (1 + hdr) return 1 - decay } ``` Previous releases of esbuild didn't substitute these single-use variables here, but esbuild will now minify this to the following code starting with this release: ```js function toneMapLuminance(e,n,a){return 1-1/(1+luminance(e,n,a))} ``` ### [`v0.15.11`](https://github.com/evanw/esbuild/releases/tag/v0.15.11) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.10...v0.15.11) - Fix various edge cases regarding template tags and `this` ([#&#8203;2610](https://github.com/evanw/esbuild/issues/2610)) This release fixes some bugs where the value of `this` wasn't correctly preserved when evaluating template tags in a few edge cases. These edge cases are listed below: ```js async function test() { class Foo { foo() { return this } } class Bar extends Foo { a = async () => super.foo`` b = async () => super['foo']`` c = async (foo) => super[foo]`` } function foo() { return this } const obj = { foo } const bar = new Bar console.log( (await bar.a()) === bar, (await bar.b()) === bar, (await bar.c('foo')) === bar, { foo }.foo``.foo === foo, (true && obj.foo)`` !== obj, (false || obj.foo)`` !== obj, (null ?? obj.foo)`` !== obj, ) } test() ``` Each edge case in the code above previously incorrectly printed `false` when run through esbuild with `--minify --target=es6` but now correctly prints `true`. These edge cases are unlikely to have affected real-world code. ### [`v0.15.10`](https://github.com/evanw/esbuild/releases/tag/v0.15.10) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.9...v0.15.10) - Add support for node's "pattern trailers" syntax ([#&#8203;2569](https://github.com/evanw/esbuild/issues/2569)) After esbuild implemented node's `exports` feature in `package.json`, node changed the feature to also allow text after `*` wildcards in patterns. Previously the `*` was required to be at the end of the pattern. It lets you do something like this: ```json { "exports": { "./features/*": "./features/*.js", "./features/*.js": "./features/*.js" } } ``` With this release, esbuild now supports these types of patterns too. - Fix subpath imports with Yarn PnP ([#&#8203;2545](https://github.com/evanw/esbuild/issues/2545)) Node has a little-used feature called [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) which are package-internal imports that start with `#` and that go through the `imports` map in `package.json`. Previously esbuild had a bug that caused esbuild to not handle these correctly in packages installed via Yarn's "Plug'n'Play" installation strategy. The problem was that subpath imports were being checked after Yarn PnP instead of before. This release reorders these checks, which should allow subpath imports to work in this case. - Link from JS to CSS in the metafile ([#&#8203;1861](https://github.com/evanw/esbuild/issues/1861), [#&#8203;2565](https://github.com/evanw/esbuild/issues/2565)) When you import CSS into a bundled JS file, esbuild creates a parallel CSS bundle next to your JS bundle. So if `app.ts` imports some CSS files and you bundle it, esbuild will give you `app.js` and `app.css`. You would then add both `<script src="app.js"></script>` and `<link href="app.css" rel="stylesheet">` to your HTML to include everything in the page. This approach is more efficient than having esbuild insert additional JavaScript into `app.js` that downloads and includes `app.css` because it means the browser can download and parse both the CSS and the JS in parallel (and potentially apply the CSS before the JS has even finished downloading). However, sometimes it's difficult to generate the `<link>` tag. One case is when you've added `[hash]` to the [entry names](https://esbuild.github.io/api/#entry-names) setting to include a content hash in the file name. Then the file name will look something like `app-GX7G2SBE.css` and may change across subsequent builds. You can tell esbuild to generate build metadata using the `metafile` API option but the metadata only tells you which generated JS bundle corresponds to a JS entry point (via the `entryPoint` property), not which file corresponds to the associated CSS bundle. Working around this was hacky and involved string manipulation. This release adds the `cssBundle` property to the metafile to make this easier. It's present on the metadata for the generated JS bundle and points to the associated CSS bundle. So to generate the HTML tags for a given JS entry point, you first find the output file with the `entryPoint` you are looking for (and put that in a `<script>` tag), then check for the `cssBundle` property to find the associated CSS bundle (and put that in a `<link>` tag). One thing to note is that there is deliberately no `jsBundle` property mapping the other way because it's not a 1:1 relationship. Two JS bundles can share the same CSS bundle in the case where the associated CSS bundles have the same name and content. In that case there would be no one value for a hypothetical `jsBundle` property to have. ### [`v0.15.9`](https://github.com/evanw/esbuild/releases/tag/v0.15.9) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.8...v0.15.9) - Fix an obscure npm package installation issue with `--omit=optional` ([#&#8203;2558](https://github.com/evanw/esbuild/issues/2558)) The previous release introduced a regression with `npm install esbuild --omit=optional` where the file `node_modules/.bin/esbuild` would no longer be present after installation. That could cause any package scripts which used the `esbuild` command to no longer work. This release fixes the regression so `node_modules/.bin/esbuild` should now be present again after installation. This regression only affected people installing esbuild using `npm` with either the `--omit=optional` or `--no-optional` flag, which is a somewhat unusual situation. **More details:** The reason for this regression is due to some obscure npm implementation details. Since the Go compiler doesn't support trivial cross-compiling on certain Android platforms, esbuild's installer installs a WebAssembly shim on those platforms instead. In the previous release I attempted to simplify esbuild's WebAssembly shims to depend on the `esbuild-wasm` package instead of including another whole copy of the WebAssembly binary (to make publishing faster and to save on file system space after installation). However, both the `esbuild` package and the `esbuild-wasm` package provide a binary called `esbuild` and it turns out that adding `esbuild-wasm` as a nested dependency of the `esbuild` package (specifically `esbuild` optionally depends on `@esbuild/android-arm` which depends on `esbuild-wasm`) caused npm to be confused about what `node_modules/.bin/esbuild` is supposed to be. It's pretty strange and unexpected that disabling the installation of optional dependencies altogether would suddenly cause an optional dependency's dependency to conflict with the top-level package. What happens under the hood is that if `--omit=optional` is present, npm attempts to uninstall the `esbuild-wasm` nested dependency at the end of `npm install` (even though the `esbuild-wasm` package was never installed due to `--omit=optional`). This uninstallation causes `node_modules/.bin/esbuild` to be deleted. After doing a full investigation, I discovered that npm's handling of the `.bin` directory is deliberately very brittle. When multiple packages in the dependency tree put something in `.bin` with the same name, the end result is non-deterministic/random. What you get in `.bin` might be from one package, from the other package, or might be missing entirely. The workaround suggested by npm is to just avoid having two packages that put something in `.bin` with the same name. So this was fixed by making the `@esbuild/android-arm` and `esbuild-android-64` packages each include another whole copy of the WebAssembly binary, which works because these packages don't put anything in `.bin`. ### [`v0.15.8`](https://github.com/evanw/esbuild/releases/tag/v0.15.8) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.7...v0.15.8) - Fix JSX name collision edge case ([#&#8203;2534](https://github.com/evanw/esbuild/issues/2534)) Code generated by esbuild could have a name collision in the following edge case: - The JSX transformation mode is set to `automatic`, which causes `import` statements to be inserted - An element uses a `{...spread}` followed by a `key={...}`, which uses the legacy `createElement` fallback imported from `react` - Another import uses a name that ends with `react` such as `@remix-run/react` - The output format has been set to CommonJS so that `import` statements are converted into require calls In this case, esbuild previously generated two variables with the same name `import_react`, like this: ```js var import_react = require("react"); var import_react2 = require("@&#8203;remix-run/react"); ``` That bug is fixed in this release. The code generated by esbuild no longer contains a name collision. - Fall back to WebAssembly on Android ARM ([#&#8203;1556](https://github.com/evanw/esbuild/issues/1556), [#&#8203;1578](https://github.com/evanw/esbuild/issues/1578), [#&#8203;2335](https://github.com/evanw/esbuild/issues/2335), [#&#8203;2526](https://github.com/evanw/esbuild/issues/2526)) Go's compiler supports trivial cross-compiling to almost all platforms without installing any additional software other than the Go compiler itself. This has made it very easy for esbuild to publish native binary executables for many platforms. However, it strangely doesn't support cross-compiling to Android ARM without installing the Android build tools. So instead of publishing a native esbuild binary executable to npm, this release publishes a WebAssembly fallback build. This is essentially the same as the `esbuild-wasm` package but it's installed automatically when you install the `esbuild` package on Android ARM. So packages that depend on the `esbuild` package should now work on Android ARM. This change has not yet been tested end-to-end because I don't have a 32-bit Android ARM device myself, but in theory it should work. This inherits the drawbacks of WebAssembly including significantly slower performance than native as well as potentially also more severe memory usage limitations and lack of certain features (e.g. `--serve`). If you want to use a native binary executable of esbuild on Android ARM, you may be able to build it yourself from source after installing the Android build tools. - Attempt to better support Yarn's `ignorePatternData` feature ([#&#8203;2495](https://github.com/evanw/esbuild/issues/2495)) Part of resolving paths in a project using Yarn's Plug'n'Play feature involves evaluating a regular expression in the `ignorePatternData` property of `.pnp.data.json`. However, it turns out that the particular regular expressions generated by Yarn use some syntax that works with JavaScript regular expressions but that does not work with Go regular expressions. In this release, esbuild will now strip some of the the problematic syntax from the regular expression before compiling it, which should hopefully allow it to be compiled by Go's regular expression engine. The specific character sequences that esbuild currently strips are as follows: - `(?!\.)` - `(?!(?:^|\/)\.)` - `(?!\.{1,2}(?:\/|$))` - `(?!(?:^|\/)\.{1,2}(?:\/|$))` These seem to be used by Yarn to avoid the `.` and `..` path segments in the middle of relative paths. The removal of these character sequences seems relatively harmless in this case since esbuild shouldn't ever generate such path segments. This change should add support to esbuild for Yarn's [`pnpIgnorePatterns`](https://yarnpkg.com/configuration/yarnrc/#pnpIgnorePatterns) feature. - Fix non-determinism issue with legacy block-level function declarations and strict mode ([#&#8203;2537](https://github.com/evanw/esbuild/issues/2537)) When function declaration statements are nested inside a block in strict mode, they are supposed to only be available within that block's scope. But in "sloppy mode" (which is what non-strict mode is commonly called), they are supposed to be available within the whole function's scope: ```js // This returns 1 due to strict mode function test1() { 'use strict' function fn() { return 1 } if (true) { function fn() { return 2 } } return fn() } // This returns 2 due to sloppy mode function test2() { function fn() { return 1 } if (true) { function fn() { return 2 } } return fn() } ``` To implement this, esbuild compiles these two functions differently to reflect their different semantics: ```js function test1() { "use strict"; function fn() { return 1; } if (true) { let fn2 = function() { return 2; }; } return fn(); } function test2() { function fn() { return 1; } if (true) { let fn2 = function() { return 2; }; var fn = fn2; } return fn(); } ``` However, the compilation had a subtle bug where the automatically-generated function-level symbols for multible hoisted block-level function declarations in the same block a sloppy-mode context were generated in a random order if the output was in strict mode, which could be the case if TypeScript's `alwaysStrict` setting was set to true. This lead to non-determinism in the output as the minifier would randomly exchange the generated names for these symbols on different runs. This bug has been fixed by sorting the keys of the unordered map before iterating over them. - Fix parsing of `@keyframes` with string identifiers ([#&#8203;2555](https://github.com/evanw/esbuild/issues/2555)) Firefox supports `@keyframes` with string identifier names. Previously this was treated as a syntax error by esbuild as it doesn't work in any other browser. The specification allows for this however, so it's technically not a syntax error (even though it would be unwise to use this feature at the moment). There was also a bug where esbuild would remove the identifier name in this case as the syntax wasn't recognized. This release changes esbuild's parsing of `@keyframes` to now consider this case to be an unrecognized CSS rule. That means it will be passed through unmodified (so you can now use esbuild to bundle this Firefox-specific CSS) but the CSS will not be pretty-printed or minified. I don't think it makes sense for esbuild to have special code to handle this Firefox-specific syntax at this time. This decision can be revisited in the future if other browsers add support for this feature. - Add the `--jsx-side-effects` API option ([#&#8203;2539](https://github.com/evanw/esbuild/issues/2539), [#&#8203;2546](https://github.com/evanw/esbuild/pull/2546)) By default esbuild assumes that JSX expressions are side-effect free, which means they are annoated with `/* @&#8203;__PURE__ */` comments and are removed during bundling when they are unused. This follows the common use of JSX for virtual DOM and applies to the vast majority of JSX libraries. However, some people have written JSX libraries that don't have this property. JSX expressions can have arbitrary side effects and can't be removed. If you are using such a library, you can now pass `--jsx-side-effects` to tell esbuild that JSX expressions have side effects so it won't remove them when they are unused. This feature was contributed by [@&#8203;rtsao](https://github.com/rtsao). ### [`v0.15.7`](https://github.com/evanw/esbuild/releases/tag/v0.15.7) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.6...v0.15.7) - Add `--watch=forever` to allow esbuild to never terminate ([#&#8203;1511](https://github.com/evanw/esbuild/issues/1511), [#&#8203;1885](https://github.com/evanw/esbuild/issues/1885)) Currently using esbuild's watch mode via `--watch` from the CLI will stop watching if stdin is closed. The rationale is that stdin is automatically closed by the OS when the parent process exits, so stopping watch mode when stdin is closed ensures that esbuild's watch mode doesn't keep running forever after the parent process has been closed. For example, it would be bad if you wrote a shell script that did `esbuild --watch &` to run esbuild's watch mode in the background, and every time you run the script it creates a new `esbuild` process that runs forever. However, there are cases when it makes sense for esbuild's watch mode to never exit. One such case is within a short-lived VM where the lifetime of all processes inside the VM is expected to be the lifetime of the VM. Previously you could easily do this by piping the output of a long-lived command into esbuild's stdin such as `sleep 999999999 | esbuild --watch &`. However, this possibility often doesn't occur to people, and it also doesn't work on Windows. People also sometimes attempt to keep esbuild open by piping an infinite stream of data to esbuild such as with `esbuild --watch </dev/zero &` which causes esbuild to spin at 100% CPU. So with this release, esbuild now has a `--watch=forever` flag that will not stop watch mode when stdin is closed. - Work around `PATH` without `node` in install script ([#&#8203;2519](https://github.com/evanw/esbuild/issues/2519)) Some people install esbuild's npm package in an environment without the `node` command in their `PATH`. This fails on Windows because esbuild's install script runs the `esbuild` command before exiting as a sanity check, and on Windows the `esbuild` command has to be a JavaScript file because of some internal details about how npm handles the `bin` folder (specifically the `esbuild` command lacks the `.exe` extension, which is required on Windows). This release attempts to work around this problem by using `process.execPath` instead of `"node"` as the command for running node. In theory this means the installer can now still function on Windows if something is wrong with `PATH`. ### [`v0.15.6`](https://github.com/evanw/esbuild/releases/tag/v0.15.6) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.5...v0.15.6) - Lower `for await` loops ([#&#8203;1930](https://github.com/evanw/esbuild/issues/1930)) This release lowers `for await` loops to the equivalent `for` loop containing `await` when esbuild is configured such that `for await` loops are unsupported. This transform still requires at least generator functions to be supported since esbuild's lowering of `await` currently relies on generators. This new transformation is mostly modeled after what the TypeScript compiler does. Here's an example: ```js async function f() { for await (let x of y) x() } ``` The code above will now become the following code with `--target=es2017` (omitting the code for the `__forAwait` helper function): ```js async function f() { try { for (var iter = __forAwait(y), more, temp, error; more = !(temp = await iter.next()).done; more = false) { let x = temp.value; x(); } } catch (temp) { error = [temp]; } finally { try { more && (temp = iter.return) && await temp.call(iter); } finally { if (error) throw error[0]; } } } ``` - Automatically fix invalid `supported` configurations ([#&#8203;2497](https://github.com/evanw/esbuild/issues/2497)) The `--target=` setting lets you tell esbuild to target a specific version of one or more JavaScript runtimes such as `chrome80,node14` and esbuild will restrict its output to only those features supported by all targeted JavaScript runtimes. More recently, esbuild introduced the `--supported:` setting that lets you override which features are supported on a per-feature basis. However, this now lets you configure nonsensical things such as `--supported:async-await=false --supported:async-generator=true`. Previously doing this could result in esbuild building successfully but producing invalid output. Starting with this release, esbuild will now attempt to automatically fix nonsensical feature override configurations by introducing more overrides until the configuration makes sense. So now the configuration from previous example will be changed such that `async-await=false` implies `async-generator=false`. The full list of implications that were introduced is below: - `async-await=false` implies: - `async-generator=false` - `for-await=false` - `top-level-await=false` - `generator=false` implies: - `async-generator=false` - `object-accessors=false` implies: - `class-private-accessor=false` - `class-private-static-accessor=false` - `class-field=false` implies: - `class-private-field=false` - `class-static-field=false` implies: - `class-private-static-field=false` - `class=false` implies: - `class-field=false` - `class-private-accessor=false` - `class-private-brand-check=false` - `class-private-field=false` - `class-private-method=false` - `class-private-static-accessor=false` - `class-private-static-field=false` - `class-private-static-method=false` - `class-static-blocks=false` - `class-static-field=false` - Implement a small minification improvement ([#&#8203;2496](https://github.com/evanw/esbuild/issues/2496)) Some people write code that contains a label with an immediate break such as `x: break x`. Previously this code was not removed during minification but it will now be removed during minification starting with this release. - Fix installing esbuild via Yarn with `enableScripts: false` configured ([#&#8203;2457](https://github.com/evanw/esbuild/pull/2457)) If esbuild is installed with Yarn with the `enableScripts: false` setting configured, then Yarn will not "unplug" the `esbuild` package (i.e. it will keep the entire package inside a `.zip` file). This messes with esbuild's library code that extracts the platform-specific binary executable because that code copies the binary executable into the esbuild package directory, and Yarn's `.zip` file system shim doesn't let you write to a directory inside of a `.zip` file. This release fixes this problem by writing to the `node_modules/.cache/esbuild` directory instead in this case. So you should now be able to use esbuild with Yarn when `enableScripts: false` is configured. This fix was contributed by [@&#8203;jonaskuske](https://github.com/jonaskuske). ### [`v0.15.5`](https://github.com/evanw/esbuild/releases/tag/v0.15.5) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.4...v0.15.5) - Fix issues with Yarn PnP and Yarn's workspaces feature ([#&#8203;2476](https://github.com/evanw/esbuild/issues/2476)) This release makes sure esbuild works with a Yarn feature called [workspaces](https://yarnpkg.com/features/workspaces/). Previously esbuild wasn't tested in this scenario, but this scenario now has test coverage. Getting this to work involved further tweaks to esbuild's custom code for what happens after Yarn PnP's path resolution algorithm runs, which is not currently covered by Yarn's PnP specification. These tweaks also fix `exports` map resolution with Yarn PnP for non-empty subpaths, which wasn't previously working. ### [`v0.15.4`](https://github.com/evanw/esbuild/releases/tag/v0.15.4) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.3...v0.15.4) - Consider TypeScript import assignments to be side-effect free ([#&#8203;2468](https://github.com/evanw/esbuild/issues/2468)) TypeScript has a [legacy import syntax](https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases) for working with TypeScript namespaces that looks like this: ```ts import { someNamespace } from './some-file' import bar = someNamespace.foo; // some-file.ts export namespace someNamespace { export let foo = 123 } ``` Since esbuild converts TypeScript into JavaScript one file at a time, it doesn't know if `bar` is supposed to be a value or a type (or both, which TypeScript actually allows in this case). This is problematic because values are supposed to be kept during the conversion but types are supposed to be removed during the conversion. Currently esbuild keeps `bar` in the output, which is done because `someNamespace.foo` is a property access and property accesses run code that could potentially have a side effect (although there is no side effect in this case). With this release, esbuild will now consider `someNamespace.foo` to have no side effects. This means `bar` will now be removed when bundling and when tree shaking is enabled. Note that it will still not be removed when tree shaking is disabled. This is because in this mode, esbuild supports adding additional code to the end of the generated output that's in the same scope as the module. That code could potentially make use of `bar`, so it would be incorrect to remove it. If you want `bar` to be removed, you'll have to enable tree shaking (which tells esbuild that nothing else depends on the unexported top-level symbols in the generated output). - Change the order of the banner and the `"use strict"` directive ([#&#8203;2467](https://github.com/evanw/esbuild/issues/2467)) Previously the top of the file contained the following things in order: 1. The hashbang comment (see below) from the source code, if present 2. The `"use strict"` directive from the source code, if present 3. The content of esbuild's `banner` API option, if specified This was problematic for people that used the `banner` API option to insert the hashbang comment instead of using esbuild's hashbang comment preservation feature. So with this release, the order has now been changed to: 1. The hashbang comment (see below) from the source code, if present 2. The content of esbuild's `banner` API option, if specified 3. The `"use strict"` directive from the source code, if present I'm considering this change to be a bug fix instead of a breaking change because esbuild's documentation states that the `banner` API option can be used to "insert an arbitrary string at the beginning of generated JavaScript files". While this isn't technically true because esbuild may still insert the original hashbang comment before the banner, it's at least more correct now because the banner will now come before the `"use strict"` directive. For context: JavaScript files recently allowed using a [hashbang comment](https://github.com/tc39/proposal-hashbang), which starts with `#!` and which must start at the very first character of the file. It allows Unix systems to execute the file directly as a script without needing to prefix it by the `node` command. This comment typically has the value `#!/usr/bin/env node`. Hashbang comments will be a part of ES2023 when it's released next year. - Fix `exports` maps with Yarn PnP path resolution ([#&#8203;2473](https://github.com/evanw/esbuild/issues/2473)) The Yarn PnP specification says that to resolve a package path, you first resolve it to the absolute path of a directory, and then you run node's module resolution algorithm on it. Previously esbuild followed this part of the specification. However, doing this means that `exports` in `package.json` is not respected because node's module resolution algorithm doesn't interpret `exports` for absolute paths. So with this release, esbuild will now use a modified algorithm that deviates from both specifications but that should hopefully behave more similar to what Yarn actually does: node's module resolution algorithm is run with the original import path but starting from the directory returned by Yarn PnP. ### [`v0.15.3`](https://github.com/evanw/esbuild/releases/tag/v0.15.3) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.2...v0.15.3) - Change the Yarn PnP manifest to a singleton ([#&#8203;2463](https://github.com/evanw/esbuild/issues/2463)) Previously esbuild searched for the Yarn PnP manifest in the parent directories of each file. But with Yarn's `enableGlobalCache` setting it's possible to configure Yarn PnP's implementation to reach outside of the directory subtree containing the Yarn PnP manifest. This was causing esbuild to fail to bundle projects with the `enableGlobalCache` setting enabled. To handle this case, *esbuild will now only search for the Yarn PnP manifest in the current working directory of the esbuild process*. If you're using esbuild's CLI, this means you will now have to `cd` into the appropriate directory first. If you're using esbuild's API, you can override esbuild's value for the current working directory with the `absWorkingDir` API option. - Fix Yarn PnP resolution failures due to backslashes in paths on Windows ([#&#8203;2462](https://github.com/evanw/esbuild/issues/2462)) Previously dependencies of a Yarn PnP virtual dependency failed to resolve on Windows. This was because Windows uses `\` instead of `/` as a path separator, and the path manipulation algorithms used for Yarn PnP expected `/`. This release converts `\` into `/` in Windows paths, which fixes this issue. - Fix `sideEffects` patterns containing slashes on Windows ([#&#8203;2465](https://github.com/evanw/esbuild/issues/2465)) The `sideEffects` field in `package.json` lets you specify an array of patterns to mark which files have side effects (which causes all other files to be considered to not have side effects by exclusion). That looks like this: ```json "sideEffects": [ "**/index.js", "**/index.prod.js" ] ``` However, the presence of the `/` character in the pattern meant that the pattern failed to match Windows-style paths, which broke `sideEffects` on Windows in this case. This release fixes this problem by adding additional code to handle Windows-style paths. ### [`v0.15.2`](https://github.com/evanw/esbuild/releases/tag/v0.15.2) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.1...v0.15.2) - Fix Yarn PnP issue with packages containing `index.js` ([#&#8203;2455](https://github.com/evanw/esbuild/issues/2455), [#&#8203;2461](https://github.com/evanw/esbuild/issues/2461)) Yarn PnP's tests require the resolved paths to end in `/`. That's not how the rest of esbuild's internals work, however, and doing this messed up esbuild's node module path resolution regarding automatically-detected `index.js` files. Previously packages that relied on implicit `index.js` resolution rules didn't work with esbuild under Yarn PnP. Removing this slash has fixed esbuild's path resolution behavior regarding `index.js`, which should now the same both with and without Yarn PnP. - Fix Yarn PnP support for `extends` in `tsconfig.json` ([#&#8203;2456](https://github.com/evanw/esbuild/issues/2456)) Previously using `extends` in `tsconfig.json` with a path in a Yarn PnP package didn't work. This is because the process of setting up package path resolution rules requires parsing `tsconfig.json` files (due to the `baseUrl` and `paths` features) and resolving `extends` to a package path requires package path resolution rules to already be set up, which is a circular dependency. This cycle is broken by using special rules for `extends` in `tsconfig.json` that bypasses esbuild's normal package path resolution process. This is why using `extends` with a Yarn PnP package didn't automatically work. With this release, these special rules have been modified to check for a Yarn PnP manifest so this case should work now. - Fix Yarn PnP support in `esbuild-wasm` ([#&#8203;2458](https://github.com/evanw/esbuild/issues/2458)) When running esbuild via WebAssembly, Yarn PnP support previously failed because Go's file system internals return `EINVAL` when trying to read a `.zip` file as a directory when run with WebAssembly. This was unexpected because Go's file system internals return `ENOTDIR` for this case on native. This release updates esbuild to treat `EINVAL` like `ENOTDIR` in this case, which fixes using `esbuild-wasm` to bundle a Yarn PnP project. Note that to be able to use `esbuild-wasm` for Yarn PnP successfully, you currently have to run it using `node` instead of `yarn node`. This is because the file system shim that Yarn overwrites node's native file system API with currently generates invalid file descriptors with negative values when inside a `.zip` file. This prevents esbuild from working correctly because Go's file system internals don't expect syscalls that succeed without an error to return an invalid file descriptor. Yarn is working on fixing their use of invalid file descriptors. ### [`v0.15.1`](https://github.com/evanw/esbuild/releases/tag/v0.15.1) [Compare Source](https://github.com/evanw/esbuild/compare/v0.15.0...v0.15.1) - Update esbuild's Yarn Plug'n'Play implementation to match the latest specification changes ([#&#8203;2452](https://github.com/evanw/esbuild/issues/2452), [#&#8203;2453](https://github.com/evanw/esbuild/pull/2453)) This release updates esbuild's implementation of Yarn Plug'n'Play to match some changes to Yarn's specification that just landed. The changes are as follows: - Check for platform-specific absolute paths instead of always for the `/` prefix The specification previously said that Yarn Plug'n'Play path resolution rules should not apply for paths that start with `/`. The intent was to avoid accidentally processing absolute paths. However, absolute paths on Windows such as `C:\project` start with drive letters instead of with `/`. So the specification was changed to instead explicitly avoid processing absolute paths. - Make `$$virtual` an alias for `__virtual__` Supporting Yarn-style path resolution requires implementing a custom Yarn-specific path traversal scheme where certain path segments are considered no-ops. Specifically any path containing segments of the form `__virtual__/<whatever>/<n>` where `<n>` is an integer must be treated as if they were `n` times the `..` operator instead (the `<whatever>` path segment is ignored). So `/path/to/project/__virtual__/xyz/2/foo.js` maps to the underlying file `/path/to/project/../../foo.js`. This scheme makes it possible for Yarn to get node (and esbuild) to load the same file multiple times (which is sometimes required for correctness) without actually duplicating the file on the file system. However, old versions of Yarn used to use `$$virtual` instead of `__virtual__`. This was changed because `$$virtual` was error-prone due to the use of the `$` character, which can cause bugs when it's not correctly escaped within regular expressions. Now that esbuild makes `$$virtual` an alias for `__virtual__`, esbuild should now work with manifests from these old Yarn versions. - Ignore PnP manifests in virtual directories The specification describes the algorithm for how to find the Plug'n'Play manifest when starting from a certain point in the file system: search through all parent directories in reverse order until the manifest is found. However, this interacts poorly with virtual paths since it can end up finding a virtual copy of the manifest instead of the original. To avoid this, esbuild now ignores manifests in virtual directories so that the search for the manifest will continue and find the original manifest in another parent directory later on. These fixes mean that esbuild's implementation of Plug'n'Play now matches Yarn's implementation more closely, and esbuild can now correctly build more projects that use Plug'n'Play. ### [`v0.15.0`](https://github.com/evanw/esbuild/releases/tag/v0.15.0) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.54...v0.15.0) **This release contains backwards-incompatible changes.** Since esbuild is before version 1.0.0, these changes have been released as a new minor version to reflect this (as [recommended by npm](https://docs.npmjs.com/cli/v6/using-npm/semver/)). You should either be pinning the exact version of `esbuild` in your `package.json` file or be using a version range syntax that only accepts patch upgrades such as `~0.14.0`. See the documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. - Implement the Yarn Plug'n'Play module resolution algorithm ([#&#8203;154](https://github.com/evanw/esbuild/issues/154), [#&#8203;237](https://github.com/evanw/esbuild/issues/237), [#&#8203;1263](https://github.com/evanw/esbuild/issues/1263), [#&#8203;2451](https://github.com/evanw/esbuild/pull/2451)) [Node](https://nodejs.org/) comes with a package manager called [npm](https://www.npmjs.com/), which installs packages into a `node_modules` folder. Node and esbuild both come with built-in rules for resolving import paths to packages within `node_modules`, so packages installed via npm work automatically without any configuration. However, many people use an alternative package manager called [Yarn](https://yarnpkg.com/). While Yarn can install packages using `node_modules`, it also offers a different package installation strategy called [Plug'n'Play](https://yarnpkg.com/features/pnp/), which is often shortened to "PnP" (not to be confused with [pnpm](https://pnpm.io/), which is an entirely different unrelated package manager). Plug'n'Play installs packages as `.zip` files on your file system. The packages are never actually unzipped. Since Node doesn't know anything about Yarn's package installation strategy, this means you can no longer run your code with Node as it won't be able to find your packages. Instead, you need to run your code with Yarn, which applies patches to Node's file system APIs before running your code. These patches attempt to make zip files seem like normal directories. When running under Yarn, using Node's file system API to read `./some.zip/lib/file.js` actually automatically extracts `lib/file.js` from `./some.zip` at run-time as if it was a normal file. Other file system APIs behave similarly. However, these patches don't work with esbuild because esbuild is not written in JavaScript; it's a native binary executable that interacts with the file system directly through the operating system. Previously the workaround for using esbuild with Plug'n'Play was to use the [`@yarnpkg/esbuild-plugin-pnp`](https://www.npmjs.com/package/@&#8203;yarnpkg/esbuild-plugin-pnp) plugin with esbuild's JavaScript API. However, this wasn't great because the plugin needed to potentially intercept every single import path and file load to check whether it was a Plug'n'Play package, which has an unusually high performance cost. It also meant that certain subtleties of path resolution rules within a `.zip` file could differ slightly from the way esbuild normally works since path resolution inside `.zip` files was implemented by Yarn, not by esbuild (which is due to a limitation of esbuild's plugin API). With this release, esbuild now contains an independent implementation of Yarn's Plug'n'Play algorithm (which is used when esbuild finds a `.pnp.js`, `.pnp.cjs`, or `.pnp.data.json` file in the directory tree). Creating additional implementations of this algorithm recently became possible because Yarn's package manifest format was recently documented: https://yarnpkg.com/advanced/pnp-spec/. This should mean that you can now use esbuild to bundle Plug'n'Play projects without any additional configuration (so you shouldn't need `@yarnpkg/esbuild-plugin-pnp` anymore). Bundling these projects should now happen much faster as Yarn no longer even needs to be run at all. Bundling the Yarn codebase itself with esbuild before and after this change seems to demonstrate over a 10x speedup (3.4s to 0.24s). And path resolution rules within Yarn packages should now be consistent with how esbuild handles regular Node packages. For example, fields such as `module` and `browser` in `package.json` files within `.zip` files should now be respected. Keep in mind that this is brand new code and there may be some initial issues to work through before esbuild's implementation is solid. Yarn's Plug'n'Play specification is also brand new and may need some follow-up edits to guide new implementations to match Yarn's exact behavior. If you try this out, make sure to test it before committing to using it, and let me know if anything isn't working as expected. Should you need to debug esbuild's path resolution, you may find `--log-level=verbose` helpful. ### [`v0.14.54`](https://github.com/evanw/esbuild/releases/tag/v0.14.54) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.53...v0.14.54) - Fix optimizations for calls containing spread arguments ([#&#8203;2445](https://github.com/evanw/esbuild/issues/2445)) This release fixes the handling of spread arguments in the optimization of `/* @&#8203;__PURE__ */` comments, empty functions, and identity functions: ```js // Original code function empty() {} function identity(x) { return x } /* @&#8203;__PURE__ */ a(...x) /* @&#8203;__PURE__ */ new b(...x) empty(...x) identity(...x) // Old output (with --minify --tree-shaking=true) ...x;...x;...x;...x; // New output (with --minify --tree-shaking=true) function identity(n){return n}[...x];[...x];[...x];identity(...x); ``` Previously esbuild assumed arguments with side effects could be directly inlined. This is almost always true except for spread arguments, which are not syntactically valid on their own and which have the side effect of causing iteration, which might have further side effects. Now esbuild will wrap these elements in an unused array so that they are syntactically valid and so that the iteration side effects are preserved. ### [`v0.14.53`](https://github.com/evanw/esbuild/releases/tag/v0.14.53) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.52...v0.14.53) This release fixes a minor issue with the previous release: I had to rename the package `esbuild-linux-loong64` to `@esbuild/linux-loong64` in the contributed PR because someone registered the package name before I could claim it, and I missed a spot. Hopefully everything is working after this release. I plan to change all platform-specific package names to use the `@esbuild/` scope at some point to avoid this problem in the future. ### [`v0.14.52`](https://github.com/evanw/esbuild/releases/tag/v0.14.52) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.51...v0.14.52) - Allow binary data as input to the JS `transform` and `build` APIs ([#&#8203;2424](https://github.com/evanw/esbuild/issues/2424)) Previously esbuild's `transform` and `build` APIs could only take a string. However, some people want to use esbuild to convert binary data to base64 text. This is problematic because JavaScript strings represent UTF-16 text and esbuild internally operates on arrays of bytes, so all strings coming from JavaScript undergo UTF-16 to UTF-8 conversion before use. This meant that using esbuild in this way was doing base64 encoding of the UTF-8 encoding of the text, which was undesired. With this release, esbuild now accepts `Uint8Array` in addition to string as an input format for the `transform` and `build` APIs. Now you can use esbuild to convert binary data to base64 text: ```js // Original code import esbuild from 'esbuild' console.log([ (await esbuild.transform('\xFF', { loader: 'base64' })).code, (await esbuild.build({ stdin: { contents: '\xFF', loader: 'base64' }, write: false })).outputFiles[0].text, ]) console.log([ (await esbuild.transform(new Uint8Array([0xFF]), { loader: 'base64' })).code, (await esbuild.build({ stdin: { contents: new Uint8Array([0xFF]), loader: 'base64' }, write: false })).outputFiles[0].text, ]) // Old output [ 'module.exports = "w78=";\n', 'module.exports = "w78=";\n' ] /* ERROR: The input to "transform" must be a string */ // New output [ 'module.exports = "w78=";\n', 'module.exports = "w78=";\n' ] [ 'module.exports = "/w==";\n', 'module.exports = "/w==";\n' ] ``` - Update the getter for `text` in build results ([#&#8203;2423](https://github.com/evanw/esbuild/issues/2423)) Output files in build results returned from esbuild's JavaScript API have both a `contents` and a `text` property to return the contents of the output file. The `contents` property is a binary UTF-8 Uint8Array and the `text` property is a JavaScript UTF-16 string. The `text` property is a getter that does the UTF-8 to UTF-16 conversion only if it's needed for better performance. Previously if you mutate the build results object, you had to overwrite both `contents` and `text` since the value returned from the `text` getter is the original text returned by esbuild. Some people find this confusing so with this release, the getter for `text` has been updated to do the UTF-8 to UTF-16 conversion on the current value of the `contents` property instead of the original value. - Publish builds for Linux LoongArch 64-bit ([#&#8203;1804](https://github.com/evanw/esbuild/issues/1804), [#&#8203;2373](https://github.com/evanw/esbuild/pull/2373)) This release upgrades to [Go 1.19](https://go.dev/doc/go1.19), which now includes support for LoongArch 64-bit processors. LoongArch 64-bit builds of esbuild will now be published to npm, which means that in theory they can now be installed with `npm install esbuild`. This was contributed by [@&#8203;beyond-1234](https://github.com/beyond-1234). ### [`v0.14.51`](https://github.com/evanw/esbuild/releases/tag/v0.14.51) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.50...v0.14.51) - Add support for React 17's `automatic` JSX transform ([#&#8203;334](https://github.com/evanw/esbuild/issues/334), [#&#8203;718](https://github.com/evanw/esbuild/issues/718), [#&#8203;1172](https://github.com/evanw/esbuild/issues/1172), [#&#8203;2318](https://github.com/evanw/esbuild/issues/2318), [#&#8203;2349](https://github.com/evanw/esbuild/pull/2349)) This adds support for the [new "automatic" JSX runtime from React 17+](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) to esbuild for both the build and transform APIs. **New CLI flags and API options:** - `--jsx`, `jsx` — Set this to `"automatic"` to opt in to this new transform - `--jsx-dev`, `jsxDev` — Toggles development mode for the automatic runtime - `--jsx-import-source`, `jsxImportSource` — Overrides the root import for runtime functions (default `"react"`) **New JSX pragma comments:** - `@jsxRuntime` — Sets the runtime (`automatic` or `classic`) - `@jsxImportSource` — Sets the import source (only valid with automatic runtime) The existing `@jsxFragment` and `@jsxFactory` pragma comments are only valid with "classic" runtime. **TSConfig resolving:** Along with accepting the new options directly via CLI or API, option inference from `tsconfig.json` compiler options was also implemented: - `"jsx": "preserve"` or `"jsx": "react-native"` → Same as `--jsx=preserve` in esbuild - `"jsx": "react"` → Same as `--jsx=transform` in esbuild (which is the default behavior) - `"jsx": "react-jsx"` → Same as `--jsx=automatic` in esbuild - `"jsx": "react-jsxdev"` → Same as `--jsx=automatic --jsx-dev` in esbuild It also reads the value of `"jsxImportSource"` from `tsconfig.json` if specified. For `react-jsx` it's important to note that it doesn't implicitly disable `--jsx-dev`. This is to support the case where a user sets `"react-jsx"` in their `tsconfig.json` but then toggles development mode directly in esbuild. **esbuild vs Babel vs TS vs...** There are a few differences between the various technologies that implement automatic JSX runtimes. The JSX transform in esbuild follows a mix of Babel's and TypeScript's behavior: - When an element has `__source` or `__self` props: - Babel: Print an error about a deprecated transform plugin - TypeScript: Allow the props - swc: Hard crash - **esbuild**: Print an error — Following Babel was chosen for this one because this might help people catch configuration issues where JSX files are being parsed by multiple tools - Element has an "implicit true" key prop, e.g. `<a key />`: - Babel: Print an error indicating that "key" props require an explicit value - TypeScript: Silently omit the "key" prop - swc: Hard crash - **esbuild**: Print an error like Babel — This might help catch legitimate programming mistakes - Element has spread children, e.g. `<a>{...children}</a>` - Babel: Print an error stating that React doesn't support spread children - TypeScript: Use static jsx function and pass children as-is, including spread operator - swc: same as Babel - **esbuild**: Same as TypeScript Also note that TypeScript has some bugs regarding JSX development mode and the generation of `lineNumber` and `columnNumber` values. Babel's values are accurate though, so esbuild's line and column numbers match Babel. Both numbers are 1-based and columns are counted in terms of UTF-16 code units. This feature was contributed by [@&#8203;jgoz](https://github.com/jgoz). ### [`v0.14.50`](https://github.com/evanw/esbuild/releases/tag/v0.14.50) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.49...v0.14.50) - Emit `names` in source maps ([#&#8203;1296](https://github.com/evanw/esbuild/issues/1296)) The [source map specification](https://sourcemaps.info/spec.html) includes an optional `names` field that can associate an identifier with a mapping entry. This can be used to record the original name for an identifier, which is useful if the identifier was renamed to something else in the generated code. When esbuild was originally written, this field wasn't widely used, but now there are some debuggers that make use of it to provide better debugging of minified code. With this release, esbuild now includes a `names` field in the source maps that it generates. To save space, the original name is only recorded when it's different from the final name. - Update parser for arrow functions with initial default type parameters in `.tsx` files ([#&#8203;2410](https://github.com/evanw/esbuild/issues/2410)) TypeScript 4.6 introduced a [change to the parsing of JSX syntax in `.tsx` files](https://github.com/microsoft/TypeScript/issues/47062). Now a `<` token followed by an identifier and then a `=` token is parsed as an arrow function with a default type parameter instead of as a JSX element. This release updates esbuild's parser to match TypeScript's parser. - Fix an accidental infinite loop with `--define` substitution ([#&#8203;2407](https://github.com/evanw/esbuild/issues/2407)) This is a fix for a regression that was introduced in esbuild version 0.14.44 where certain `--define` substitutions could result in esbuild crashing with a stack overflow. The problem was an incorrect fix for [#&#8203;2292](https://github.com/evanw/esbuild/issues/2292). The fix merged the code paths for `--define` and `--jsx-factory` rewriting since the value substitution is now the same for both. However, doing this accidentally made `--define` substitution recursive since the JSX factory needs to be able to match against `--define` substitutions to integrate with the `--inject` feature. The fix is to only do one additional level of matching against define substitutions, and to only do this for JSX factories. Now these cases are able to build successfully without a stack overflow. - Include the "public path" value in hashes ([#&#8203;2403](https://github.com/evanw/esbuild/issues/2403)) The `--public-path=` configuration value affects the paths that esbuild uses to reference files from other files and is used in various situations such as cross-chunk imports in JS and references to asset files from CSS files. However, it wasn't included in the hash calculations used for file names due to an oversight. This meant that changing the public path setting incorrectly didn't result in the hashes in file names changing even though the contents of the files changed. This release fixes the issue by including a hash of the public path in all non-asset output files. - Fix a cross-platform consistency bug ([#&#8203;2383](https://github.com/evanw/esbuild/issues/2383)) Previously esbuild would minify `0xFFFF_FFFF_FFFF_FFFF` as `0xffffffffffffffff` (18 bytes) on arm64 chips and as `18446744073709552e3` (19 bytes) on x86\_64 chips. The reason was that the number was converted to a 64-bit unsigned integer internally for printing as hexadecimal, the 64-bit floating-point number `0xFFFF_FFFF_FFFF_FFFF` is actually `0x1_0000_0000_0000_0180` (i.e. it's rounded up, not down), and converting `float64` to `uint64` is implementation-dependent in Go when the input is out of bounds. This was fixed by changing the upper limit for which esbuild uses hexadecimal numbers during minification to `0xFFFF_FFFF_FFFF_F800`, which is the next representable 64-bit floating-point number below `0x1_0000_0000_0000_0180`, and which fits in a `uint64`. As a result, esbuild will now consistently never minify `0xFFFF_FFFF_FFFF_FFFF` as `0xffffffffffffffff` anymore, which means the output should now be consistent across platforms. - Fix a hang with the synchronous API when the package is corrupted ([#&#8203;2396](https://github.com/evanw/esbuild/issues/2396)) An error message is already thrown when the esbuild package is corrupted and esbuild can't be run. However, if you are using a synchronous call in the JavaScript API in worker mode, esbuild will use a child worker to initialize esbuild once so that the overhead of initializing esbuild can be amortized across multiple synchronous API calls. However, errors thrown during initialization weren't being propagated correctly which resulted in a hang while the main thread waited forever for the child worker to finish initializing. With this release, initialization errors are now propagated correctly so calling a synchronous API call when the package is corrupted should now result in an error instead of a hang. - Fix `tsconfig.json` files that collide with directory names ([#&#8203;2411](https://github.com/evanw/esbuild/issues/2411)) TypeScript lets you write `tsconfig.json` files with `extends` clauses that refer to another config file using an implicit `.json` file extension. However, if the config file without the `.json` extension existed as a directory name, esbuild and TypeScript had different behavior. TypeScript ignores the directory and continues looking for the config file by adding the `.json` extension while esbuild previously terminated the search and then failed to load the config file (because it's a directory). With this release, esbuild will now ignore exact matches when resolving `extends` fields in `tsconfig.json` files if the exact match results in a directory. - Add `platform` to the transform API ([#&#8203;2362](https://github.com/evanw/esbuild/issues/2362)) The `platform` option is mainly relevant for bundling because it mostly affects path resolution (e.g. activating the `"browser"` field in `package.json` files), so it was previously only available for the build API. With this release, it has additionally be made available for the transform API for a single reason: you can now set `--platform=node` when transforming a string so that esbuild will add export annotations for node, which is only relevant when `--format=cjs` is also present. This has to do with an implementation detail of node that parses the AST of CommonJS files to discover named exports when importing CommonJS from ESM. However, this new addition to esbuild's API is of questionable usefulness. Node's loader API (the main use case for using esbuild's transform API like this) actually bypasses the content returned from the loader and parses the AST that's present on the file system, so you won't actually be able to use esbuild's API for this. See the linked issue for more information. ### [`v0.14.49`](https://github.com/evanw/esbuild/releases/tag/v0.14.49) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.48...v0.14.49) - Keep inlined constants when direct `eval` is present ([#&#8203;2361](https://github.com/evanw/esbuild/issues/2361)) Version 0.14.19 of esbuild added inlining of certain `const` variables during minification, which replaces all references to the variable with the initializer and then removes the variable declaration. However, this could generate incorrect code when direct `eval` is present because the direct `eval` could reference the constant by name. This release fixes the problem by preserving the `const` variable declaration in this case: ```js // Original code console.log((() => { const x = 123; return x + eval('x') })) // Old output (with --minify) console.log(()=>123+eval("x")); // New output (with --minify) console.log(()=>{const x=123;return 123+eval("x")}); ``` - Fix an incorrect error in TypeScript when targeting ES5 ([#&#8203;2375](https://github.com/evanw/esbuild/issues/2375)) Previously when compiling TypeScript code to ES5, esbuild could incorrectly consider the following syntax forms as a transformation error: ```ts 0 ? ([]) : 1 ? ({}) : 2; ``` The error messages looked like this: ✘ [ERROR] Transforming destructuring to the configured target environment ("es5") is not supported yet example.ts:1:5: 1 │ 0 ? ([]) : 1 ? ({}) : 2; ╵ ^ ✘ [ERROR] Transforming destructuring to the configured target environment ("es5") is not supported yet example.ts:1:16: 1 │ 0 ? ([]) : 1 ? ({}) : 2; ╵ ^ These parenthesized literals followed by a colon look like the start of an arrow function expression followed by a TypeScript return type (e.g. `([]) : 1` could be the start of the TypeScript arrow function `([]): 1 => 1`). Unlike in JavaScript, parsing arrow functions in TypeScript requires backtracking. In this case esbuild correctly determined that this expression wasn't an arrow function after all but the check for destructuring was incorrectly not covered under the backtracking process. With this release, the error message is now only reported if the parser successfully parses an arrow function without backtracking. - Fix generated TypeScript `enum` comments containing `*/` ([#&#8203;2369](https://github.com/evanw/esbuild/issues/2369), [#&#8203;2371](https://github.com/evanw/esbuild/pull/2371)) TypeScript `enum` values that are equal to a number or string literal are inlined (references to the enum are replaced with the literal value) and have a `/* ... */` comment after them with the original enum name to improve readability. However, this comment is omitted if the enum name contains the character sequence `*/` because that would end the comment early and cause a syntax error: ```ts // Original TypeScript enum Foo { '/*' = 1, '*/' = 2 } console.log(Foo['/*'], Foo['*/']) // Generated JavaScript console.log(1 /* /* */, 2); ``` This was originally handled correctly when TypeScript `enum` inlining was initially implemented since it was only supported within a single file. However, when esbuild was later extended to support TypeScript `enum` inlining across files, this special case where the enum name contains `*/` was not handled in that new code. Starting with this release, esbuild will now handle enums with names containing `*/` correctly when they are inlined across files: ```ts // foo.ts export enum Foo { '/*' = 1, '*/' = 2 } // bar.ts import { Foo } from './foo' console.log(Foo['/*'], Foo['*/']) // Old output (with --bundle --format=esm) console.log(1 /* /* */, 2 /* */ */); // New output (with --bundle --format=esm) console.log(1 /* /* */, 2); ``` This fix was contributed by [@&#8203;magic-akari](https://github.com/magic-akari). - Allow `declare` class fields to be initialized ([#&#8203;2380](https://github.com/evanw/esbuild/issues/2380)) This release fixes an oversight in the TypeScript parser that disallowed initializers for `declare` class fields. TypeScript actually allows the following limited initializer expressions for `readonly` fields: ```ts declare const enum a { b = 0 } class Foo { // These are allowed by TypeScript declare readonly a = 0 declare readonly b = -0 declare readonly c = 0n declare readonly d = -0n declare readonly e = 'x' declare readonly f = `x` declare readonly g = a.b declare readonly h = a['b'] // These are not allowed by TypeScript declare readonly x = (0) declare readonly y = null declare readonly z = -a.b } ``` So with this release, esbuild now allows initializers for `declare` class fields too. To future-proof this in case TypeScript allows more expressions as initializers in the future (such as `null`), esbuild will allow any expression as an initializer and will leave the specifics of TypeScript's special-casing here to the TypeScript type checker. - Fix a bug in esbuild's feature compatibility table generator ([#&#8203;2365](https://github.com/evanw/esbuild/issues/2365)) Passing specific JavaScript engines to esbuild's `--target` flag restricts esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates. The data for this feature is automatically derived from this compatibility table with a script: https://kangax.github.io/compat-table/. However, the script had a bug that could incorrectly consider a JavaScript syntax feature to be supported in a given engine even when it doesn't actually work in that engine. Specifically this bug happened when a certain aspect of JavaScript syntax has always worked incorrectly in that engine and the bug in that engine has never been fixed. This situation hasn't really come up before because previously esbuild pretty much only targeted JavaScript engines that always fix their bugs, but the two new JavaScript engines that were added in the previous release ([Hermes](https://hermesengine.dev/) and [Rhino](https://github.com/mozilla/rhino)) have many aspects of the JavaScript specification that have never been implemented, and may never be implemented. For example, the `let` and `const` keywords are not implemented correctly in those engines. With this release, esbuild's compatibility table generator script has been fixed and as a result, esbuild will now correctly consider a JavaScript syntax feature to be unsupported in a given engine if there is some aspect of that syntax that is broken in all known versions of that engine. This means that the following JavaScript syntax features are no longer considered to be supported by these engines (represented using esbuild's internal names for these syntax features): Hermes: - `arrow` - `const-and-let` - `default-argument` - `generator` - `optional-catch-binding` - `optional-chain` - `rest-argument` - `template-literal` Rhino: - `arrow` - `const-and-let` - `destructuring` - `for-of` - `generator` - `object-extensions` - `template-literal` IE: - `const-and-let` ### [`v0.14.48`](https://github.com/evanw/esbuild/releases/tag/v0.14.48) [Compare Source](https://github.com/evanw/esbuild/compare/v0.14.47...v0.14.48) - Enable using esbuild in Deno via WebAssembly ([#&#8203;2323](https://github.com/evanw/esbuild/issues/2323)) The native implementation of esbuild is much faster than the WebAssembly version, but some people don't want to give Deno the `--allow-run` permission necessary to run esbuild and are ok waiting longer for their builds to finish when using the WebAssembly backend. With this release, you can now use esbuild via WebAssembly in Deno. To do this you will need to import from `wasm.js` instead of `mod.js`: ```js import * as esbuild from 'https://deno.land/x/esbuild@v0.14.48/wasm.js' const ts = 'let test: boolean = true' const result = await esbuild.transform(ts, { loader: 'ts' }) console.log('result:', result) ``` Make sure you run Deno with `--allow-net` so esbuild can download the WebAssembly module. Using esbuild like this starts up a worker thread that runs esbuild in parallel (unless you call `esbuild.initialize({ worker: false })` to tell esbuild to run on the main thread). If you want to, you can call `esbuild.stop()` to terminate the worker if you won't be using esbuild anymore and you want to reclaim the memory. Note that Deno appears to have a bug where background WebAssembly optimization can prevent the process from exiting for many seconds. If you are trying to use Deno and WebAssembly to run esbuild quickly, you may need to manually call `Deno.exit(0)` after your code has finished running. - Add support for font file MIME types ([#&#8203;2337](https://github.com/evanw/esbuild/issues/2337)) This release adds support for font file MIME types to esbuild, which means they are now recognized by the built-in local web server and they are now used when a font file is loaded using the `dataurl` loader. The full set of newly-added file extension MIME type mappings is as follows: - `.eot` => `application/vnd.ms-fontobject` - `.otf` => `font/otf` - `.sfnt` => `font/sfnt` - `.ttf` => `font/ttf` - `.woff` => `font/woff` - `.woff2` => `font/woff2` - Remove `"use strict";` when targeting ESM ([#&#8203;2347](https://github.com/evanw/esbuild/issues/2347)) All ES module code is automatically in strict mode, so a `"use strict";` directive is unnecessary. With this release, esbuild will now remove the `"use strict";` directive if the output format is ESM. This change makes the generated output file a few bytes smaller: ```js // Original code 'use strict' export let foo = 123 // Old output (with --format=esm --minify) "use strict";let t=123;export{t as foo}; // New output (with --format=esm --minify) let t=123;export{t as foo}; ``` - Attempt to have esbuild work with Deno on FreeBSD ([#&#8203;2356](https://github.com/evanw/esbuild/issues/2356)) Deno doesn't support FreeBSD, but it's possible to build Deno for FreeBSD with some additional patches on top. This release of esbuild changes esbuild's Deno installer to download esbuild's FreeBSD binary in this situation. This configuration is unsupported although in theory everything should work. - Add some more target JavaScript engines ([#&#8203;2357](https://github.com/evanw/esbuild/issues/2357)) This release adds the [Rhino](https://github.com/mozilla/rhino) and [Hermes](https://hermesengine.dev/) JavaScript engines to the set of engine identifiers that can be passed to the `--target` flag. You can use this to restrict esbuild to only using JavaScript features that are supported on those engines in the output files that esbuild generates. </details> --- ### 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 becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMDUuMSIsInVwZGF0ZWRJblZlciI6IjM1LjEwNS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWwifQ==-->
inhji added 1 commit 2023-06-10 09:25:39 +02:00
inhji closed this pull request 2023-06-11 20:54:19 +02:00
inhji reopened this pull request 2023-06-11 20:55:12 +02:00
inhji closed this pull request 2023-08-09 19:44:40 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: inhji/obsidian-micropub#7
No description provided.