summaryrefslogtreecommitdiff
path: root/cli/npm/managed/resolvers
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-09-27 12:35:37 -0700
committerGitHub <noreply@github.com>2024-09-27 12:35:37 -0700
commitfbddd5a2ebfb11dd376a751e9fc4cf09a6286ada (patch)
tree75c13ee9f26f61fe8c1d6f80df2580a523177c1b /cli/npm/managed/resolvers
parenta8d1ab52761516b7f9b6069d6e433254794ed48c (diff)
fix(node): Pass NPM_PROCESS_STATE to subprocesses via temp file instead of env var (#25896)
Fixes https://github.com/denoland/deno/issues/25401. Fixes https://github.com/denoland/deno/issues/25841. Fixes https://github.com/denoland/deno/issues/25891.
Diffstat (limited to 'cli/npm/managed/resolvers')
-rw-r--r--cli/npm/managed/resolvers/common/lifecycle_scripts.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
index f700d4bf9..b358c3585 100644
--- a/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
+++ b/cli/npm/managed/resolvers/common/lifecycle_scripts.rs
@@ -2,7 +2,9 @@
use super::bin_entries::BinEntries;
use crate::args::LifecycleScriptsConfig;
+use deno_core::anyhow::Context;
use deno_npm::resolution::NpmResolutionSnapshot;
+use deno_runtime::deno_io::FromRawIoHandle;
use deno_semver::package::PackageNv;
use deno_semver::Version;
use std::borrow::Cow;
@@ -163,9 +165,24 @@ impl<'a> LifecycleScripts<'a> {
);
let mut env_vars = crate::task_runner::real_env_vars();
+ // we want to pass the current state of npm resolution down to the deno subprocess
+ // (that may be running as part of the script). we do this with an inherited temp file
+ //
+ // SAFETY: we are sharing a single temp file across all of the scripts. the file position
+ // will be shared among these, which is okay since we run only one script at a time.
+ // However, if we concurrently run scripts in the future we will
+ // have to have multiple temp files.
+ let temp_file_fd =
+ deno_runtime::ops::process::npm_process_state_tempfile(
+ process_state.as_bytes(),
+ ).context("failed to create npm process state tempfile for running lifecycle scripts")?;
+ // SAFETY: fd/handle is valid
+ let _temp_file =
+ unsafe { std::fs::File::from_raw_io_handle(temp_file_fd) }; // make sure the file gets closed
env_vars.insert(
- crate::args::NPM_RESOLUTION_STATE_ENV_VAR_NAME.to_string(),
- process_state,
+ deno_runtime::ops::process::NPM_RESOLUTION_STATE_FD_ENV_VAR_NAME
+ .to_string(),
+ (temp_file_fd as usize).to_string(),
);
for (package, package_path) in self.packages_with_scripts {
// add custom commands for binaries from the package's dependencies. this will take precedence over the