Giter Site home page Giter Site logo

Comments (6)

marvinhagemeister avatar marvinhagemeister commented on June 14, 2024 1

@littledivy Fair point: I've published the snippet as an npm package and updated the reproduction steps accordingly.

from deno.

marvinhagemeister avatar marvinhagemeister commented on June 14, 2024

The process global isn't available either. We're likely not setting up the node context.

from deno.

bartlomieju avatar bartlomieju commented on June 14, 2024

I don't think that's the problem. Most likely it's related to https://github.com/denoland/deno/blob/main/ext/node/global.rs not recognizing that we're running inside node:vm.

from deno.

littledivy avatar littledivy commented on June 14, 2024

runInThisContext runs the code in the current context i.e Deno. By running it with Node globals we will change that definition.

This code should work when in a Node context i.e node_modules

from deno.

littledivy avatar littledivy commented on June 14, 2024

Also blocking the Docusaurus upgrade in denoland/deno-docs#412

from deno.

marvinhagemeister avatar marvinhagemeister commented on June 14, 2024

Took a look at this, and I can get it to work with this patch, but I'm not sure if this is the right fix.

diff --git a/ext/node/global.rs b/ext/node/global.rs
index 0aaa6ed8b..a3722641d 100644
--- a/ext/node/global.rs
+++ b/ext/node/global.rs
@@ -267,7 +267,9 @@ fn current_mode(scope: &mut v8::HandleScope) -> Mode {
   let Some(v8_string) =
     v8::StackTrace::current_script_name_or_source_url(scope)
   else {
-    return Mode::Deno;
+    // TODO: Add a flag to scope for inline scripts created
+    // via node:vm
+    return Mode::Node;
   };
   let op_state = deno_core::JsRuntime::op_state_from(scope);
   let op_state = op_state.borrow();
@@ -276,7 +278,7 @@ fn current_mode(scope: &mut v8::HandleScope) -> Mode {
   };
   let mut buffer = [MaybeUninit::uninit(); 2048];
   let str = v8_string.to_rust_cow_lossy(scope, &mut buffer);
-  if node_resolver.in_npm_package_with_cache(str) {
+  if str.starts_with("node:") || node_resolver.in_npm_package_with_cache(str) {
     Mode::Node
   } else {
     Mode::Deno

The first change isn't necessary for this particular reproduction case, but it is necessary to get vitest to work. Will try next week to find a proper test case that covers that.

from deno.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.