From 3a306c450ce99067c4322720792d909afaf78841 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 27 Oct 2024 22:03:30 -0400 Subject: [PATCH 1/8] fix: do not panic when failing to write to http cache (#26591) Closes https://github.com/denoland/deno/issues/26189 Closes https://github.com/denoland/deno/issues/26575 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 623d028ce6..2c8028a1e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1356,9 +1356,9 @@ dependencies = [ [[package]] name = "deno_cache_dir" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186a102b13b4512841f5f40784cd25822042d22954afe3b5b070d406d15eb4f2" +checksum = "693ca429aebf945de5fef30df232044f9f80be4cc5a5e7c8d767226c43880f5a" dependencies = [ "base32", "deno_media_type", diff --git a/Cargo.toml b/Cargo.toml index 37fed81681..b622cbe443 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,7 +111,7 @@ console_static_text = "=0.8.1" dashmap = "5.5.3" data-encoding = "2.3.3" data-url = "=0.3.0" -deno_cache_dir = "=0.13.0" +deno_cache_dir = "=0.13.1" deno_package_json = { version = "0.1.2", default-features = false } dlopen2 = "0.6.1" ecb = "=0.1.2" From 5389972ba5037b1ed48da11506f6798deec2b48e Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 28 Oct 2024 12:08:51 +0100 Subject: [PATCH 2/8] fix(npm): match npm bearer token generation (#26544) Spend some time stepping through the npm client code and noticed that the bearer token was different from ours. They do some double encoding and @dsherret helped me in matching the encoding behavior. Fixes https://github.com/denoland/deno/issues/26033 --- cli/npm/common.rs | 23 +++++++++++-------- .../specs/npm/npmrc_username_password/.npmrc | 6 +++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/cli/npm/common.rs b/cli/npm/common.rs index de282310a1..55f1bc086d 100644 --- a/cli/npm/common.rs +++ b/cli/npm/common.rs @@ -3,6 +3,7 @@ use base64::prelude::BASE64_STANDARD; use base64::Engine; use deno_core::anyhow::bail; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_npm::npm_rc::RegistryConfig; use http::header; @@ -36,17 +37,21 @@ pub fn maybe_auth_header_for_npm_registry( } if username.is_some() && password.is_some() { + // The npm client does some double encoding when generating the + // bearer token value, see + // https://github.com/npm/cli/blob/780afc50e3a345feb1871a28e33fa48235bc3bd5/workspaces/config/lib/index.js#L846-L851 + let pw_base64 = BASE64_STANDARD + .decode(password.unwrap()) + .with_context(|| "The password in npmrc is an invalid base64 string")?; + let bearer = BASE64_STANDARD.encode(format!( + "{}:{}", + username.unwrap(), + String::from_utf8_lossy(&pw_base64) + )); + return Ok(Some(( header::AUTHORIZATION, - header::HeaderValue::from_str(&format!( - "Basic {}", - BASE64_STANDARD.encode(format!( - "{}:{}", - username.unwrap(), - password.unwrap() - )) - )) - .unwrap(), + header::HeaderValue::from_str(&format!("Basic {}", bearer)).unwrap(), ))); } diff --git a/tests/specs/npm/npmrc_username_password/.npmrc b/tests/specs/npm/npmrc_username_password/.npmrc index c318678aea..9e1ded96a3 100644 --- a/tests/specs/npm/npmrc_username_password/.npmrc +++ b/tests/specs/npm/npmrc_username_password/.npmrc @@ -1,6 +1,8 @@ @denotest:registry=http://localhost:4261/ //localhost:4261/:username=deno -//localhost:4261/:_password=land +# base64 of land +//localhost:4261/:_password=bGFuZA== @denotest2:registry=http://localhost:4262/ //localhost:4262/:username=deno -//localhost:4262/:_password=land2 +# base64 of land2 +//localhost:4262/:_password=bGFuZDI= From f61af864df4d7a2513f738ddf2d5fddf79c878af Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 28 Oct 2024 09:31:58 -0400 Subject: [PATCH 3/8] fix(compile): regression handling redirects (#26586) Closes https://github.com/denoland/deno/issues/26583 --- cli/standalone/serialization.rs | 12 ++++++----- tests/specs/compile/redirects/__test__.jsonc | 22 ++++++++++++++++++++ tests/specs/compile/redirects/main.out | 1 + tests/specs/compile/redirects/main.ts | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/specs/compile/redirects/__test__.jsonc create mode 100644 tests/specs/compile/redirects/main.out create mode 100644 tests/specs/compile/redirects/main.ts diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 12927845bc..7b63c584e7 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -173,6 +173,7 @@ pub struct RemoteModulesStoreBuilder { impl RemoteModulesStoreBuilder { pub fn add(&mut self, specifier: &Url, media_type: MediaType, data: Vec) { + log::debug!("Adding '{}' ({})", specifier, media_type); let specifier = specifier.to_string(); self.specifiers.push((specifier, self.data_byte_len)); self.data_byte_len += 1 + 8 + data.len() as u64; // media type (1 byte), data length (8 bytes), data @@ -182,6 +183,7 @@ impl RemoteModulesStoreBuilder { pub fn add_redirects(&mut self, redirects: &BTreeMap) { self.redirects.reserve(redirects.len()); for (from, to) in redirects { + log::debug!("Adding redirect '{}' -> '{}'", from, to); let from = from.to_string(); let to = to.to_string(); self.redirects_len += (4 + from.len() + 4 + to.len()) as u64; @@ -354,17 +356,17 @@ impl RemoteModulesStore { pub fn read<'a>( &'a self, - specifier: &'a Url, + original_specifier: &'a Url, ) -> Result>, AnyError> { let mut count = 0; - let mut current = specifier; + let mut specifier = original_specifier; loop { if count > 10 { - bail!("Too many redirects resolving '{}'", specifier); + bail!("Too many redirects resolving '{}'", original_specifier); } - match self.specifiers.get(current) { + match self.specifiers.get(specifier) { Some(RemoteModulesStoreSpecifierValue::Redirect(to)) => { - current = to; + specifier = to; count += 1; } Some(RemoteModulesStoreSpecifierValue::Data(offset)) => { diff --git a/tests/specs/compile/redirects/__test__.jsonc b/tests/specs/compile/redirects/__test__.jsonc new file mode 100644 index 0000000000..07ce693999 --- /dev/null +++ b/tests/specs/compile/redirects/__test__.jsonc @@ -0,0 +1,22 @@ +{ + "tempDir": true, + "steps": [{ + "if": "unix", + "args": "compile -A --output main main.ts", + "output": "[WILDCARD]" + }, { + "if": "unix", + "commandName": "./main", + "args": [], + "output": "main.out" + }, { + "if": "windows", + "args": "compile -A --output main.exe main.ts", + "output": "[WILDCARD]" + }, { + "if": "windows", + "commandName": "./main.exe", + "args": [], + "output": "main.out" + }] +} diff --git a/tests/specs/compile/redirects/main.out b/tests/specs/compile/redirects/main.out new file mode 100644 index 0000000000..e965047ad7 --- /dev/null +++ b/tests/specs/compile/redirects/main.out @@ -0,0 +1 @@ +Hello diff --git a/tests/specs/compile/redirects/main.ts b/tests/specs/compile/redirects/main.ts new file mode 100644 index 0000000000..4396319014 --- /dev/null +++ b/tests/specs/compile/redirects/main.ts @@ -0,0 +1 @@ +import "http://localhost:4546/run/003_relative_import.ts"; From 4e38fbd0a3e0ca139314e503494a8d4795007d8a Mon Sep 17 00:00:00 2001 From: snek Date: Mon, 28 Oct 2024 18:16:43 +0100 Subject: [PATCH 4/8] fix: report exceptions from nextTick (#26579) Fixes: https://github.com/denoland/deno/issues/24713 Fixes: https://github.com/denoland/deno/issues/25855 --- ext/node/polyfills/_next_tick.ts | 2 + tests/integration/node_unit_tests.rs | 4 ++ tests/node_compat/config.jsonc | 4 +- tests/node_compat/runner/TODO.md | 1 - .../test-child-process-ipc-next-tick.js | 46 +++++++++++++++++++ .../__test__.jsonc | 4 ++ .../next_tick_uncaught_exception/main.out | 2 + .../node/next_tick_uncaught_exception/main.ts | 13 ++++++ 8 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js create mode 100644 tests/specs/node/next_tick_uncaught_exception/__test__.jsonc create mode 100644 tests/specs/node/next_tick_uncaught_exception/main.out create mode 100644 tests/specs/node/next_tick_uncaught_exception/main.ts diff --git a/ext/node/polyfills/_next_tick.ts b/ext/node/polyfills/_next_tick.ts index 62470c564e..af306a29c8 100644 --- a/ext/node/polyfills/_next_tick.ts +++ b/ext/node/polyfills/_next_tick.ts @@ -62,6 +62,8 @@ export function processTicksAndRejections() { callback(...args); } } + } catch (e) { + reportError(e); } finally { // FIXME(bartlomieju): Deno currently doesn't support async hooks // if (destroyHooksExist()) diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index d66db5a40e..40bd7b2fbb 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -212,3 +212,7 @@ itest!(unhandled_rejection_web_process { envs: env_vars_for_npm_tests(), http_server: true, }); + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// The itest macro is deprecated. Please move your new test to ~/tests/specs. +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index 75f463342e..a99a427900 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -43,9 +43,6 @@ // TODO(littledivy): windows ipc streams not yet implemented "test-child-process-fork-ref.js", "test-child-process-fork-ref2.js", - // TODO(bartlomieju): this test is very flaky on CI - // https://github.com/denoland/deno/issues/25855 - // "test-child-process-ipc-next-tick.js", "test-child-process-ipc.js", "test-child-process-spawnsync-env.js", "test-child-process-stdio-inherit.js", @@ -240,6 +237,7 @@ "test-child-process-execfilesync-maxbuf.js", "test-child-process-execsync-maxbuf.js", "test-child-process-flush-stdio.js", + "test-child-process-ipc-next-tick.js", "test-child-process-kill.js", "test-child-process-set-blocking.js", "test-child-process-spawn-args.js", diff --git a/tests/node_compat/runner/TODO.md b/tests/node_compat/runner/TODO.md index 11b5d28053..35a67e72d2 100644 --- a/tests/node_compat/runner/TODO.md +++ b/tests/node_compat/runner/TODO.md @@ -280,7 +280,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co - [parallel/test-child-process-fork3.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-fork3.js) - [parallel/test-child-process-http-socket-leak.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-http-socket-leak.js) - [parallel/test-child-process-internal.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-internal.js) -- [parallel/test-child-process-ipc-next-tick.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc-next-tick.js) - [parallel/test-child-process-ipc.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-ipc.js) - [parallel/test-child-process-no-deprecation.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-no-deprecation.js) - [parallel/test-child-process-pipe-dataflow.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-child-process-pipe-dataflow.js) diff --git a/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js b/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js new file mode 100644 index 0000000000..f511d25004 --- /dev/null +++ b/tests/node_compat/test/parallel/test-child-process-ipc-next-tick.js @@ -0,0 +1,46 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const NUM_MESSAGES = 10; +const values = []; + +for (let i = 0; i < NUM_MESSAGES; ++i) { + values[i] = i; +} + +if (process.argv[2] === 'child') { + const received = values.map(() => { return false; }); + + process.on('uncaughtException', common.mustCall((err) => { + received[err] = true; + const done = received.every((element) => { return element === true; }); + + if (done) + process.disconnect(); + }, NUM_MESSAGES)); + + process.on('message', (msg) => { + // If messages are handled synchronously, throwing should break the IPC + // message processing. + throw msg; + }); + + process.send('ready'); +} else { + const child = cp.fork(__filename, ['child']); + + child.on('message', common.mustCall((msg) => { + assert.strictEqual(msg, 'ready'); + values.forEach((value) => { + child.send(value); + }); + })); +} diff --git a/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc b/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc new file mode 100644 index 0000000000..5517e693d6 --- /dev/null +++ b/tests/specs/node/next_tick_uncaught_exception/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run main.ts", + "output": "main.out" +} diff --git a/tests/specs/node/next_tick_uncaught_exception/main.out b/tests/specs/node/next_tick_uncaught_exception/main.out new file mode 100644 index 0000000000..45b756515b --- /dev/null +++ b/tests/specs/node/next_tick_uncaught_exception/main.out @@ -0,0 +1,2 @@ +caught Error: thrown from next tick + at file:///[WILDCARD]/specs/node/next_tick_uncaught_exception/main.ts:4:15 diff --git a/tests/specs/node/next_tick_uncaught_exception/main.ts b/tests/specs/node/next_tick_uncaught_exception/main.ts new file mode 100644 index 0000000000..2679d3d54b --- /dev/null +++ b/tests/specs/node/next_tick_uncaught_exception/main.ts @@ -0,0 +1,13 @@ +import process from "node:process"; +import { strictEqual } from "node:assert"; + +const error = new Error("thrown from next tick"); + +process.on("uncaughtException", (caught) => { + strictEqual(caught, error); + console.log("caught", caught); +}); + +process.nextTick(() => { + throw error; +}); From 0e641632c38383a1d67aa610867496f64ae423ca Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 28 Oct 2024 17:43:41 -0400 Subject: [PATCH 5/8] fix(check): expose more globals from @types/node (#26603) Extracted out of https://github.com/denoland/deno/pull/26558 Closes https://github.com/denoland/deno/issues/26578 --- cli/tsc/99_main_compiler.js | 6 ------ tests/specs/npm/compare_globals/__test__.jsonc | 4 ++-- .../compare_globals/{compare_globals => }/main.out | 3 ++- .../npm/compare_globals/{compare_globals => }/main.ts | 11 +++++++++-- 4 files changed, 13 insertions(+), 11 deletions(-) rename tests/specs/npm/compare_globals/{compare_globals => }/main.out (90%) rename tests/specs/npm/compare_globals/{compare_globals => }/main.ts (84%) diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index e3a0bee597..6011dece76 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -1337,18 +1337,12 @@ delete Object.prototype.__proto__; "console", "Console", "ErrorConstructor", - "exports", "gc", "Global", "ImportMeta", "localStorage", - "module", - "NodeModule", - "NodeRequire", - "process", "queueMicrotask", "RequestInit", - "require", "ResponseInit", "sessionStorage", "setImmediate", diff --git a/tests/specs/npm/compare_globals/__test__.jsonc b/tests/specs/npm/compare_globals/__test__.jsonc index e096ddeb22..96458306a7 100644 --- a/tests/specs/npm/compare_globals/__test__.jsonc +++ b/tests/specs/npm/compare_globals/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read --check=all compare_globals/main.ts", - "output": "compare_globals/main.out" + "args": "run --allow-read --check=all main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/compare_globals/compare_globals/main.out b/tests/specs/npm/compare_globals/main.out similarity index 90% rename from tests/specs/npm/compare_globals/compare_globals/main.out rename to tests/specs/npm/compare_globals/main.out index 5be6125b08..290e9c3b23 100644 --- a/tests/specs/npm/compare_globals/compare_globals/main.out +++ b/tests/specs/npm/compare_globals/main.out @@ -8,10 +8,11 @@ Download http://localhost:4260/@denotest/globals/1.0.0.tgz Download http://localhost:4260/@types/node/node-22.5.4.tgz Download http://localhost:4260/undici-types/undici-types-6.19.8.tgz [UNORDERED_END] -Check file:///[WILDCARD]/compare_globals/main.ts +Check file:///[WILDCARD]/main.ts true true [] +process equals process true setTimeout 1 false setTimeout 2 function setTimeout 3 function diff --git a/tests/specs/npm/compare_globals/compare_globals/main.ts b/tests/specs/npm/compare_globals/main.ts similarity index 84% rename from tests/specs/npm/compare_globals/compare_globals/main.ts rename to tests/specs/npm/compare_globals/main.ts index 9482798d8c..308ce9b23f 100644 --- a/tests/specs/npm/compare_globals/compare_globals/main.ts +++ b/tests/specs/npm/compare_globals/main.ts @@ -5,10 +5,17 @@ console.log(globals.global === globals.globalThis); // @ts-expect-error even though these are the same object, they have different types console.log(globals.globalThis === globalThis); console.log(globals.process.execArgv); +console.log("process equals process", process === globals.process); type AssertTrue = never; -type _TestNoProcessGlobal = AssertTrue< - typeof globalThis extends { process: any } ? false : true +type _TestHasProcessGlobal = AssertTrue< + typeof globalThis extends { process: any } ? true : false +>; +type _TestProcessGlobalVersion = AssertTrue< + typeof process.versions.node extends string ? true : false +>; +type _TestNoBufferGlogal = AssertTrue< + typeof globalThis extends { Buffer: any } ? false : true >; type _TestHasNodeJsGlobal = NodeJS.Architecture; From 484f8ca9c30909914eb3348b2df10d44e2753248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 28 Oct 2024 23:55:51 +0000 Subject: [PATCH 6/8] fix: provide hints in terminal errors for Node.js globals (#26610) Add info/hint for terminal errors related to Node.js globals: - __filename - __dirname - Buffer - global - setImmediate - clearImmediate Closes https://github.com/denoland/deno/issues/17494 --- runtime/fmt_errors.rs | 42 +++++++++++++++++++ .../main.out | 3 ++ .../run/node_globals_hints/__test__.jsonc | 34 +++++++++++++++ tests/specs/run/node_globals_hints/buffer.js | 1 + tests/specs/run/node_globals_hints/buffer.out | 7 ++++ .../run/node_globals_hints/clear_immediate.js | 1 + .../node_globals_hints/clear_immediate.out | 7 ++++ tests/specs/run/node_globals_hints/dirname.js | 1 + .../specs/run/node_globals_hints/dirname.out | 7 ++++ .../specs/run/node_globals_hints/filename.js | 1 + .../specs/run/node_globals_hints/filename.out | 7 ++++ tests/specs/run/node_globals_hints/global.js | 1 + tests/specs/run/node_globals_hints/global.out | 7 ++++ .../run/node_globals_hints/set_immediate.js | 1 + .../run/node_globals_hints/set_immediate.out | 7 ++++ 15 files changed, 127 insertions(+) create mode 100644 tests/specs/run/node_globals_hints/__test__.jsonc create mode 100644 tests/specs/run/node_globals_hints/buffer.js create mode 100644 tests/specs/run/node_globals_hints/buffer.out create mode 100644 tests/specs/run/node_globals_hints/clear_immediate.js create mode 100644 tests/specs/run/node_globals_hints/clear_immediate.out create mode 100644 tests/specs/run/node_globals_hints/dirname.js create mode 100644 tests/specs/run/node_globals_hints/dirname.out create mode 100644 tests/specs/run/node_globals_hints/filename.js create mode 100644 tests/specs/run/node_globals_hints/filename.out create mode 100644 tests/specs/run/node_globals_hints/global.js create mode 100644 tests/specs/run/node_globals_hints/global.out create mode 100644 tests/specs/run/node_globals_hints/set_immediate.js create mode 100644 tests/specs/run/node_globals_hints/set_immediate.out diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 7c6cf6d397..4cd8a06345 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -321,6 +321,48 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { ]), FixSuggestion::docs("https://docs.deno.com/go/commonjs"), ]; + } else if msg.contains("__filename is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "__filename global is not available in ES modules." + )), + FixSuggestion::hint(cstr!("Use import.meta.filename instead.")), + ]; + } else if msg.contains("__dirname is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "__dirname global is not available in ES modules." + )), + FixSuggestion::hint(cstr!("Use import.meta.dirname instead.")), + ]; + } else if msg.contains("Buffer is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "Buffer is not available in the global scope in Deno." + )), + FixSuggestion::hint(cstr!("Import it explicitly with import { Buffer } from \"node:buffer\";.")), + ]; + } else if msg.contains("clearImmediate is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "clearImmediate is not available in the global scope in Deno." + )), + FixSuggestion::hint(cstr!("Import it explicitly with import { clearImmediate } from \"node:timers\";.")), + ]; + } else if msg.contains("setImmediate is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "setImmediate is not available in the global scope in Deno." + )), + FixSuggestion::hint(cstr!("Import it explicitly with import { setImmediate } from \"node:timers\";.")), + ]; + } else if msg.contains("global is not defined") { + return vec![ + FixSuggestion::info(cstr!( + "global is not available in the global scope in Deno." + )), + FixSuggestion::hint(cstr!("Use globalThis instead, or assign globalThis.global = globalThis.")), + ]; } else if msg.contains("openKv is not a function") { return vec![ FixSuggestion::info("Deno.openKv() is an unstable API."), diff --git a/tests/specs/lint/node_globals_no_duplicate_imports/main.out b/tests/specs/lint/node_globals_no_duplicate_imports/main.out index 56df10eba4..058b80795d 100644 --- a/tests/specs/lint/node_globals_no_duplicate_imports/main.out +++ b/tests/specs/lint/node_globals_no_duplicate_imports/main.out @@ -2,3 +2,6 @@ error: Uncaught (in promise) ReferenceError: setImmediate is not defined const _foo = setImmediate; ^ at [WILDCARD]main.ts:3:14 + + info: setImmediate is not available in the global scope in Deno. + hint: Import it explicitly with import { setImmediate } from "node:timers";. diff --git a/tests/specs/run/node_globals_hints/__test__.jsonc b/tests/specs/run/node_globals_hints/__test__.jsonc new file mode 100644 index 0000000000..c5c5d6e42e --- /dev/null +++ b/tests/specs/run/node_globals_hints/__test__.jsonc @@ -0,0 +1,34 @@ +{ + "tests": { + "__dirname": { + "args": "run dirname.js", + "output": "dirname.out", + "exitCode": 1 + }, + "__filename": { + "args": "run filename.js", + "output": "filename.out", + "exitCode": 1 + }, + "clearImmediate": { + "args": "run clear_immediate.js", + "output": "clear_immediate.out", + "exitCode": 1 + }, + "buffer": { + "args": "run buffer.js", + "output": "buffer.out", + "exitCode": 1 + }, + "global": { + "args": "run global.js", + "output": "global.out", + "exitCode": 1 + }, + "setImmediate": { + "args": "run set_immediate.js", + "output": "set_immediate.out", + "exitCode": 1 + } + } +} diff --git a/tests/specs/run/node_globals_hints/buffer.js b/tests/specs/run/node_globals_hints/buffer.js new file mode 100644 index 0000000000..9809e1656e --- /dev/null +++ b/tests/specs/run/node_globals_hints/buffer.js @@ -0,0 +1 @@ +Buffer; diff --git a/tests/specs/run/node_globals_hints/buffer.out b/tests/specs/run/node_globals_hints/buffer.out new file mode 100644 index 0000000000..4980e6d129 --- /dev/null +++ b/tests/specs/run/node_globals_hints/buffer.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: Buffer is not defined +Buffer; +^ + at [WILDCARD]buffer.js:1:1 + + info: Buffer is not available in the global scope in Deno. + hint: Import it explicitly with import { Buffer } from "node:buffer";. diff --git a/tests/specs/run/node_globals_hints/clear_immediate.js b/tests/specs/run/node_globals_hints/clear_immediate.js new file mode 100644 index 0000000000..94b26ae682 --- /dev/null +++ b/tests/specs/run/node_globals_hints/clear_immediate.js @@ -0,0 +1 @@ +clearImmediate; diff --git a/tests/specs/run/node_globals_hints/clear_immediate.out b/tests/specs/run/node_globals_hints/clear_immediate.out new file mode 100644 index 0000000000..ecd34babef --- /dev/null +++ b/tests/specs/run/node_globals_hints/clear_immediate.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: clearImmediate is not defined +clearImmediate; +^ + at [WILDCARD]clear_immediate.js:1:1 + + info: clearImmediate is not available in the global scope in Deno. + hint: Import it explicitly with import { clearImmediate } from "node:timers";. diff --git a/tests/specs/run/node_globals_hints/dirname.js b/tests/specs/run/node_globals_hints/dirname.js new file mode 100644 index 0000000000..58d9e93794 --- /dev/null +++ b/tests/specs/run/node_globals_hints/dirname.js @@ -0,0 +1 @@ +__dirname; diff --git a/tests/specs/run/node_globals_hints/dirname.out b/tests/specs/run/node_globals_hints/dirname.out new file mode 100644 index 0000000000..0aa3e4f51b --- /dev/null +++ b/tests/specs/run/node_globals_hints/dirname.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: __dirname is not defined +__dirname; +^ + at [WILDCARD]dirname.js:1:1 + + info: __dirname global is not available in ES modules. + hint: Use import.meta.dirname instead. diff --git a/tests/specs/run/node_globals_hints/filename.js b/tests/specs/run/node_globals_hints/filename.js new file mode 100644 index 0000000000..31770bb141 --- /dev/null +++ b/tests/specs/run/node_globals_hints/filename.js @@ -0,0 +1 @@ +__filename; diff --git a/tests/specs/run/node_globals_hints/filename.out b/tests/specs/run/node_globals_hints/filename.out new file mode 100644 index 0000000000..47b4264fbd --- /dev/null +++ b/tests/specs/run/node_globals_hints/filename.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: __filename is not defined +__filename; +^ + at [WILDCARD]filename.js:1:1 + + info: __filename global is not available in ES modules. + hint: Use import.meta.filename instead. diff --git a/tests/specs/run/node_globals_hints/global.js b/tests/specs/run/node_globals_hints/global.js new file mode 100644 index 0000000000..56676d726a --- /dev/null +++ b/tests/specs/run/node_globals_hints/global.js @@ -0,0 +1 @@ +global; diff --git a/tests/specs/run/node_globals_hints/global.out b/tests/specs/run/node_globals_hints/global.out new file mode 100644 index 0000000000..e090d32e29 --- /dev/null +++ b/tests/specs/run/node_globals_hints/global.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: global is not defined +global; +^ + at [WILDCARD]global.js:1:1 + + info: global is not available in the global scope in Deno. + hint: Use globalThis instead, or assign globalThis.global = globalThis. diff --git a/tests/specs/run/node_globals_hints/set_immediate.js b/tests/specs/run/node_globals_hints/set_immediate.js new file mode 100644 index 0000000000..fa29d1e714 --- /dev/null +++ b/tests/specs/run/node_globals_hints/set_immediate.js @@ -0,0 +1 @@ +setImmediate; diff --git a/tests/specs/run/node_globals_hints/set_immediate.out b/tests/specs/run/node_globals_hints/set_immediate.out new file mode 100644 index 0000000000..38859ff5d7 --- /dev/null +++ b/tests/specs/run/node_globals_hints/set_immediate.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: setImmediate is not defined +setImmediate; +^ + at [WILDCARD]set_immediate.js:1:1 + + info: setImmediate is not available in the global scope in Deno. + hint: Import it explicitly with import { setImmediate } from "node:timers";. From 46e5ed1a642edcd998d1e22c9b37e0c4aa298e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 29 Oct 2024 00:41:02 +0000 Subject: [PATCH 7/8] Revert "fix(ext/node): use primordials in `ext/node/polyfills/https.ts` (#26323)" (#26613) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …s` (#26323)" This reverts commit afb33b3c2597c9ec943f71218b236486fbc86e23. Reverting because it caused a regression - https://github.com/denoland/deno/issues/26612. Closes https://github.com/denoland/deno/issues/26612. --- ext/node/polyfills/https.ts | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/ext/node/polyfills/https.ts b/ext/node/polyfills/https.ts index dd24cf048c..f60c5e471a 100644 --- a/ext/node/polyfills/https.ts +++ b/ext/node/polyfills/https.ts @@ -1,6 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright Joyent and Node contributors. All rights reserved. MIT license. +// TODO(petamoriken): enable prefer-primordials for node polyfills +// deno-lint-ignore-file prefer-primordials + import { notImplemented } from "ext:deno_node/_utils.ts"; import { urlToHttpOptions } from "ext:deno_node/internal/url.ts"; import { @@ -14,14 +17,6 @@ import { type ServerHandler, ServerImpl as HttpServer } from "node:http"; import { validateObject } from "ext:deno_node/internal/validators.mjs"; import { kEmptyObject } from "ext:deno_node/internal/util.mjs"; import { Buffer } from "node:buffer"; -import { primordials } from "ext:core/mod.js"; -const { - ArrayPrototypeShift, - ArrayPrototypeUnshift, - ArrayIsArray, - ObjectPrototypeIsPrototypeOf, - ObjectAssign, -} = primordials; export class Server extends HttpServer { constructor(opts, requestListener?: ServerHandler) { @@ -34,11 +29,11 @@ export class Server extends HttpServer { validateObject(opts, "options"); } - if (opts.cert && ArrayIsArray(opts.cert)) { + if (opts.cert && Array.isArray(opts.cert)) { notImplemented("https.Server.opts.cert array type"); } - if (opts.key && ArrayIsArray(opts.key)) { + if (opts.key && Array.isArray(opts.key)) { notImplemented("https.Server.opts.key array type"); } @@ -47,12 +42,10 @@ export class Server extends HttpServer { _additionalServeOptions() { return { - cert: ObjectPrototypeIsPrototypeOf(Buffer, this._opts.cert) - // deno-lint-ignore prefer-primordials + cert: this._opts.cert instanceof Buffer ? this._opts.cert.toString() : this._opts.cert, - key: ObjectPrototypeIsPrototypeOf(Buffer, this._opts.key) - // deno-lint-ignore prefer-primordials + key: this._opts.key instanceof Buffer ? this._opts.key.toString() : this._opts.key, }; @@ -166,18 +159,18 @@ export function request(...args: any[]) { let options = {}; if (typeof args[0] === "string") { - const urlStr = ArrayPrototypeShift(args); + const urlStr = args.shift(); options = urlToHttpOptions(new URL(urlStr)); - } else if (ObjectPrototypeIsPrototypeOf(URL, args[0])) { - options = urlToHttpOptions(ArrayPrototypeShift(args)); + } else if (args[0] instanceof URL) { + options = urlToHttpOptions(args.shift()); } if (args[0] && typeof args[0] !== "function") { - ObjectAssign(options, ArrayPrototypeShift(args)); + Object.assign(options, args.shift()); } options._defaultAgent = globalAgent; - ArrayPrototypeUnshift(args, options); + args.unshift(options); return new HttpsClientRequest(args[0], args[1]); } From aa2a354190f15645a7db0563eebe49255a083ff9 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 29 Oct 2024 14:37:21 +0900 Subject: [PATCH 8/8] refactor(init): inline routing in deno init --serve template (#26595) --- cli/tools/init/mod.rs | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index 2d6a894e13..4e4a686c5f 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -24,32 +24,29 @@ pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { create_file( &dir, "main.ts", - r#"import { type Route, route, serveDir } from "@std/http"; + r#"import { serveDir } from "@std/http"; -const routes: Route[] = [ - { - pattern: new URLPattern({ pathname: "/" }), - handler: () => new Response("Home page"), - }, - { - pattern: new URLPattern({ pathname: "/users/:id" }), - handler: (_req, _info, params) => new Response(params?.pathname.groups.id), - }, - { - pattern: new URLPattern({ pathname: "/static/*" }), - handler: (req) => serveDir(req), - }, -]; - -function defaultHandler(_req: Request) { - return new Response("Not found", { status: 404 }); -} - -const handler = route(routes, defaultHandler); +const userPagePattern = new URLPattern({ pathname: "/users/:id" }); +const staticPathPattern = new URLPattern({ pathname: "/static/*" }); export default { fetch(req) { - return handler(req); + const url = new URL(req.url); + + if (url.pathname === "/") { + return new Response("Home page"); + } + + const userPageMatch = userPagePattern.exec(url); + if (userPageMatch) { + return new Response(userPageMatch.pathname.groups.id); + } + + if (staticPathPattern.test(url)) { + return serveDir(req); + } + + return new Response("Not found", { status: 404 }); }, } satisfies Deno.ServeDefaultExport; "#,