summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/node/analyze.rs11
-rw-r--r--ext/node/build.rs10
-rw-r--r--ext/node/lib.rs14
3 files changed, 17 insertions, 18 deletions
diff --git a/ext/node/analyze.rs b/ext/node/analyze.rs
index c7181c4ac..2622ce8da 100644
--- a/ext/node/analyze.rs
+++ b/ext/node/analyze.rs
@@ -341,7 +341,7 @@ fn esm_code_from_top_level_decls(
}
let mut result = String::new();
- let global_this_expr = NODE_GLOBAL_THIS_NAME.as_str();
+ let global_this_expr = NODE_GLOBAL_THIS_NAME;
let global_this_expr = if has_global_this {
global_this_expr
} else {
@@ -506,10 +506,9 @@ mod tests {
"export const x = 1;",
&HashSet::from(["x".to_string()]),
);
- assert!(r.contains(&format!(
- "var globalThis = {};",
- NODE_GLOBAL_THIS_NAME.as_str()
- )));
+ assert!(
+ r.contains(&format!("var globalThis = {};", NODE_GLOBAL_THIS_NAME,))
+ );
assert!(r.contains("var process = globalThis.process;"));
assert!(r.contains("export const x = 1;"));
}
@@ -533,7 +532,7 @@ mod tests {
"var setTimeout = globalThis.setTimeout;\n",
"export const x = 1;"
),
- NODE_GLOBAL_THIS_NAME.as_str(),
+ NODE_GLOBAL_THIS_NAME,
)
);
}
diff --git a/ext/node/build.rs b/ext/node/build.rs
new file mode 100644
index 000000000..e9b960cab
--- /dev/null
+++ b/ext/node/build.rs
@@ -0,0 +1,10 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+fn main() {
+ // we use a changing variable name to make it harder to depend on this
+ let crate_version = env!("CARGO_PKG_VERSION");
+ println!(
+ "cargo:rustc-env=NODE_GLOBAL_THIS_NAME=__DENO_NODE_GLOBAL_THIS_{}__",
+ crate_version.replace('.', "_")
+ );
+}
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 84530423f..cc4afb2b8 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -169,15 +169,7 @@ pub trait NpmResolver: std::fmt::Debug + Send + Sync {
) -> Result<(), AnyError>;
}
-pub static NODE_GLOBAL_THIS_NAME: Lazy<String> = Lazy::new(|| {
- let now = std::time::SystemTime::now();
- let seconds = now
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
- .unwrap()
- .as_secs();
- // use a changing variable name to make it hard to depend on this
- format!("__DENO_NODE_GLOBAL_THIS_{seconds}__")
-});
+pub const NODE_GLOBAL_THIS_NAME: &str = env!("NODE_GLOBAL_THIS_NAME");
pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
// The full list of environment variables supported by Node.js is available
@@ -557,9 +549,7 @@ pub fn initialize_runtime(
argv0
);
}})('{}', {}, {});"#,
- NODE_GLOBAL_THIS_NAME.as_str(),
- uses_local_node_modules_dir,
- argv0
+ NODE_GLOBAL_THIS_NAME, uses_local_node_modules_dir, argv0
);
js_runtime.execute_script(located_script_name!(), source_code.into())?;