From de34c7ed29bcce8b46a65f5effe45090b8493ba5 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 14 Nov 2024 14:11:29 +0100 Subject: feat(cli): add `--unstable-node-globals` flag (#26617) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds a new `--unstable-node-globals` flag to expose Node globals by default. Fixes https://github.com/denoland/deno/issues/26611 --------- Co-authored-by: Bartek IwaƄczuk --- runtime/fmt_errors.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'runtime/fmt_errors.rs') diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 28cd70296..6c05fbc63 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -339,28 +339,40 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> 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\";.")), + FixSuggestion::hint_multiline(&[ + cstr!("Import it explicitly with import { Buffer } from \"node:buffer\";,"), + cstr!("or run again with --unstable-node-globals flag to add this global."), + ]), ]; } 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\";.")), + FixSuggestion::hint_multiline(&[ + cstr!("Import it explicitly with import { clearImmediate } from \"node:timers\";,"), + cstr!("or run again with --unstable-node-globals flag to add this global."), + ]), ]; } 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\";.")), + FixSuggestion::hint_multiline( + &[cstr!("Import it explicitly with import { setImmediate } from \"node:timers\";,"), + cstr!("or run again with --unstable-node-globals flag to add this global."), + ]), ]; } 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.")), + FixSuggestion::hint_multiline(&[ + cstr!("Use globalThis instead, or assign globalThis.global = globalThis,"), + cstr!("or run again with --unstable-node-globals flag to add this global."), + ]), ]; } else if msg.contains("openKv is not a function") { return vec![ -- cgit v1.2.3