From daccf02ac13399de6378838801e683e7cce365e6 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sun, 20 Nov 2022 15:10:57 -0500 Subject: [PATCH] fix #2683: `esbuild-wasm` broken in node v19 --- CHANGELOG.md | 4 ++++ npm/esbuild-wasm/bin/esbuild | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 234a73515d9..24614cbb36f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +* Fix the `esbuild-wasm` package in Node v19 ([#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 ([#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/. diff --git a/npm/esbuild-wasm/bin/esbuild b/npm/esbuild-wasm/bin/esbuild index 7587ceaea4e..14b5e4a3470 100755 --- a/npm/esbuild-wasm/bin/esbuild +++ b/npm/esbuild-wasm/bin/esbuild @@ -129,5 +129,15 @@ for (let key in process.env) { } } +// Node v19 introduced "globalThis.crypto" https://github.com/nodejs/node/pull/44897. +// This broke Go's WebAssembly shim: https://github.com/golang/go/issues/56860. +// Hack around this breakage by resetting "globalThis.crypto" to "writable". +// Just to be safe, also make it "configurable" in case Go updates their +// compiler such that it tries to reconfigure "globalThis.crypto" itself. +Object.defineProperty(globalThis, 'crypto', { + writable: true, + configurable: true, +}); + process.argv.splice(2, 0, esbuild_wasm); wrapper(module_.createRequire(wasm_exec_node), Object.assign(Object.create(WebAssembly), { instantiate }));