Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Node's import.meta.url is written into each module, as import.meta.main is: macOS 15's JavaScriptCore left it undefined

shinyobjectz6d8623ca9be5
diff --git a/engine/native/src/js.rs b/engine/native/src/js.rs
index b7ca3400..e1a1eb0b 100644
--- a/engine/native/src/js.rs
+++ b/engine/native/src/js.rs
@@ -121,7 +121,7 @@ fn rewrite_node(url: &str, js: &str) -> String {
if SOURCES.with(|s| s.borrow().contains_key(&u)) {
return Some(u);
}
- match crate::node::load(&path) {
+ match crate::node::load(&path, false) {
Ok(src) => {
SOURCES.with(|s| s.borrow_mut().insert(u.clone(), src));
Some(u)
@@ -208,7 +208,7 @@ fn run_here(root: &Path, cwd: &Path, entry: Entry, argv: Vec<String>, env: serde
// the entry module
let (url, js) = match &entry {
// import.meta.main (Bun's and Node 24's): true in the entry, false in the modules it imports (node.rs)
- Entry::File(p) if node => crate::node::load_entry(p).map(|src| (format!("file://{}", p.display()), src)),
+ Entry::File(p) if node => crate::node::load(p, true).map(|src| (format!("file://{}", p.display()), src)),
Entry::File(p) => LOADER.with(|l| {
let mut l = l.borrow_mut();
let l = l.as_mut().unwrap();
diff --git a/engine/native/src/node.rs b/engine/native/src/node.rs
index 400dc0fa..31fd774c 100644
--- a/engine/native/src/node.rs
+++ b/engine/native/src/node.rs
@@ -174,16 +174,15 @@ fn js_string(s: &str) -> String {
}
/// A file's ES module source: TypeScript transpiled, JSON as its default export, an ES module as it is, a CommonJS
-/// file through node.js's require (its module.exports the default export)
-pub fn load(path: &Path) -> Result<String, String> {
- // import.meta.main (Bun's and Node 24's): false in an imported module (js::run_node makes it true in the entry);
- // JavaScriptCore's embedding API has no hook for import.meta, so it's written into the text
- load_module(path).map(|s| s.replace("import.meta.main", "false"))
-}
-
-/// The entry's source: import.meta.main true
-pub fn load_entry(path: &Path) -> Result<String, String> {
- load_module(path).map(|s| s.replace("import.meta.main", "true"))
+/// file through node.js's require (its module.exports the default export). JavaScriptCore's embedding API has no hook
+/// for import.meta, so two of its fields are written into the text: import.meta.main (Bun's and Node 24's), true in
+/// the entry (`entry`, js::run_node's) and false in what it imports, and import.meta.url, the file's own URL, which
+/// macOS 15's JavaScriptCore left undefined (a newer one gives the module's key): createRequire(import.meta.url) then
+/// looked for packages from "."
+pub fn load(path: &Path, entry: bool) -> Result<String, String> {
+ let abs = std::path::absolute(path).unwrap_or_else(|_| path.to_path_buf());
+ let url = js_string(&format!("file://{}", abs.display()));
+ load_module(path).map(|s| s.replace("import.meta.main", if entry { "true" } else { "false" }).replace("import.meta.url", &url))
}
fn load_module(path: &Path) -> Result<String, String> {
diff --git a/tools/dupes.max b/tools/dupes.max
index 016992b6..7646c7b0 100644
--- a/tools/dupes.max
+++ b/tools/dupes.max
@@ -19,5 +19,5 @@
# io/capcut store.rs:67 (tasklist's stdout, lower-cased; sdk/ui/parity main.rs:88 trims a command's stdout),
# io/capcut build.rs:24 parse (serde_json::from_str + expect; engine/native node.rs:172 js_string, to_string), and
# apps/capcut plan.rs:67 (a box moved more than 1 px; systems/layout mod.rs:406, within 1.5 px)
-exact=294
+exact=293
near=59