From 2531204a3476b0f49bd4ecec68a94efb2908412a Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 21 Aug 2024 20:33:52 -0700 Subject: [PATCH] fix(ext/node): register `node:wasi` built-in (#25134) Fixes https://github.com/denoland/deno/issues/23531 --- ext/node/lib.rs | 2 +- ext/node/polyfill.rs | 1 + ext/node/polyfills/01_require.js | 2 +- tests/integration/lsp_tests.rs | 1 + tests/integration/node_unit_tests.rs | 1 + tests/unit_node/wasi_test.ts | 7 +++++++ tools/core_import_map.json | 2 +- 7 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/unit_node/wasi_test.ts diff --git a/ext/node/lib.rs b/ext/node/lib.rs index a820c4476f2d13..56eb292aecf7cb 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -594,7 +594,6 @@ deno_core::extension!(deno_node, "path/mod.ts", "path/separator.ts", "readline/promises.ts", - "wasi.ts", "node:assert" = "assert.ts", "node:assert/strict" = "assert/strict.ts", "node:async_hooks" = "async_hooks.ts", @@ -645,6 +644,7 @@ deno_core::extension!(deno_node, "node:util/types" = "util/types.ts", "node:v8" = "v8.ts", "node:vm" = "vm.js", + "node:wasi" = "wasi.ts", "node:worker_threads" = "worker_threads.ts", "node:zlib" = "zlib.ts", ], diff --git a/ext/node/polyfill.rs b/ext/node/polyfill.rs index 175228a258ab64..a14b75bac00e2c 100644 --- a/ext/node/polyfill.rs +++ b/ext/node/polyfill.rs @@ -75,6 +75,7 @@ generate_builtin_node_module_lists! { "util/types", "v8", "vm", + "wasi", "worker_threads", "zlib", } diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index 40bb7f2963ee40..7eb549134fe599 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -151,7 +151,7 @@ import util from "node:util"; import v8 from "node:v8"; import vm from "node:vm"; import workerThreads from "node:worker_threads"; -import wasi from "ext:deno_node/wasi.ts"; +import wasi from "node:wasi"; import zlib from "node:zlib"; const nativeModuleExports = ObjectCreate(null); diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index fd6f7e484b09db..a0d12da3a93158 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -7663,6 +7663,7 @@ fn lsp_completions_node_specifier() { "node:util/types", "node:v8", "node:vm", + "node:wasi", "node:worker_threads", "node:zlib", ], diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 74ed293e3c72f1..22c0f811075e23 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -96,6 +96,7 @@ util::unit_test_factory!( util_test, v8_test, vm_test, + wasi_test, worker_threads_test, zlib_test ] diff --git a/tests/unit_node/wasi_test.ts b/tests/unit_node/wasi_test.ts new file mode 100644 index 00000000000000..6af2d4b1db5880 --- /dev/null +++ b/tests/unit_node/wasi_test.ts @@ -0,0 +1,7 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import wasi from "node:wasi"; +import { assertThrows } from "@std/assert"; + +Deno.test("[node/wasi] - WASI should throw (not implemented)", () => { + assertThrows(() => new wasi.WASI()); +}); diff --git a/tools/core_import_map.json b/tools/core_import_map.json index ba4cd105d96cb2..2d8631d87ec455 100644 --- a/tools/core_import_map.json +++ b/tools/core_import_map.json @@ -206,7 +206,7 @@ "node:util/types": "../ext/node/polyfills/util/types.ts", "node:v8": "../ext/node/polyfills/v8.ts", "node:vm": "../ext/node/polyfills/vm.js", - "ext:deno_node/wasi.ts": "../ext/node/polyfills/wasi.ts", + "node:wasi": "../ext/node/polyfills/wasi.ts", "node:worker_threads": "../ext/node/polyfills/worker_threads.ts", "node:zlib": "../ext/node/polyfills/zlib.ts", "ext:deno_url/00_url.js": "../ext/url/00_url.js",