-
Allow binary data as input to the JS
transform
andbuild
APIs (#2424)Previously esbuild's
transform
andbuild
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 thetransform
andbuild
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 atext
property to return the contents of the output file. Thecontents
property is a binary UTF-8 Uint8Array and thetext
property is a JavaScript UTF-16 string. Thetext
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
andtext
since the value returned from thetext
getter is the original text returned by esbuild. Some people find this confusing so with this release, the getter fortext
has been updated to do the UTF-8 to UTF-16 conversion on the current value of thecontents
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.