Skip to content
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 105 additions & 22 deletions src/plugins/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::build_time::built_info;
use crate::cache::CacheManagerBuilder;
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::settings::DEFAULT_NODE_MIRROR_URL;
use crate::config::settings::{DEFAULT_NODE_MIRROR_URL, SettingsNode};
use crate::config::{Config, Settings};
use crate::file::{TarFormat, TarOptions};
use crate::http::{HTTP, HTTP_FETCH};
Expand Down Expand Up @@ -723,29 +723,10 @@ impl Backend for NodePlugin {
fn resolve_lockfile_options(
&self,
_request: &ToolRequest,
target: &PlatformTarget,
_target: &PlatformTarget,
) -> BTreeMap<String, String> {
let mut opts = BTreeMap::new();
let settings = Settings::get();
let is_current_platform = target.is_current();

// Only include compile option if true (non-default)
let compile = if is_current_platform {
settings.node.compile.unwrap_or(false)
} else {
false
};
if compile {
opts.insert("compile".to_string(), "true".to_string());
}

// Flavor affects which binary variant is downloaded
// Apply to all platforms to avoid splitting lockfile entries (#8390)
if let Some(flavor) = settings.node.flavor.clone() {
opts.insert("flavor".to_string(), flavor);
}

opts
node_lockfile_options(&settings.node)
}

async fn resolve_lock_info(
Expand Down Expand Up @@ -904,6 +885,59 @@ fn mirror_url_for(node: &crate::config::settings::SettingsNode, filename: &str)
mirror
}

fn node_lockfile_options(node: &SettingsNode) -> BTreeMap<String, String> {
let mut opts = BTreeMap::new();

let mirror_url = node.mirror_url().to_string();
if mirror_url != DEFAULT_NODE_MIRROR_URL {
opts.insert("mirror_url".to_string(), mirror_url);
}

// Only include compile option if true (non-default)
let compile = node.compile.unwrap_or(false);
if compile {
opts.insert("compile".to_string(), "true".to_string());
if let Some(cflags) = node.cflags() {
Comment thread
risu729 marked this conversation as resolved.
Outdated
opts.insert("cflags".to_string(), cflags);
}
if let Some(configure_opts) = node
.configure_opts
.clone()
.or_else(|| env::var("NODE_CONFIGURE_OPTS").ok())
{
opts.insert("configure_opts".to_string(), configure_opts);
}
Comment thread
risu729 marked this conversation as resolved.
Outdated
if let Some(make) = node.make.clone() {
opts.insert("make".to_string(), make);
}
if let Some(make_opts) = node
.make_opts
.clone()
.or_else(|| env::var("NODE_MAKE_OPTS").ok())
{
opts.insert("make_opts".to_string(), make_opts);
}
if let Some(make_install_opts) = node
.make_install_opts
.clone()
.or_else(|| env::var("NODE_MAKE_INSTALL_OPTS").ok())
{
opts.insert("make_install_opts".to_string(), make_install_opts);
}
if let Some(ninja) = node.ninja {
opts.insert("ninja".to_string(), ninja.to_string());
}
Comment thread
risu729 marked this conversation as resolved.
Outdated
}

// Flavor affects which binary variant is downloaded.
// Apply to all platforms to avoid splitting lockfile entries (#8390).
if let Some(flavor) = node.flavor.clone() {
opts.insert("flavor".to_string(), flavor);
}

opts
}

fn os() -> &'static str {
NodePlugin::map_os(built_info::CFG_OS)
}
Expand Down Expand Up @@ -975,4 +1009,53 @@ mod tests {
assert_eq!(glibc.as_str(), "https://corp.example/node/");
assert_eq!(musl.as_str(), "https://corp.example/node/");
}

#[test]
fn test_node_lockfile_options_include_mirror_and_flavor() {
let node = SettingsNode {
mirror_url: Some("https://corp.example/node/".to_string()),
flavor: Some("musl".to_string()),
..Default::default()
};

assert_eq!(
node_lockfile_options(&node),
BTreeMap::from([
(
"mirror_url".to_string(),
"https://corp.example/node/".to_string()
),
("flavor".to_string(), "musl".to_string()),
])
);
}

#[test]
fn test_node_lockfile_options_include_source_build_inputs() {
let node = SettingsNode {
compile: Some(true),
mirror_url: Some(DEFAULT_NODE_MIRROR_URL.to_string()),
cflags: Some("-O2".to_string()),
configure_opts: Some("--openssl-no-asm".to_string()),
make: Some("gmake".to_string()),
make_opts: Some("-s".to_string()),
make_install_opts: Some("--no-strip".to_string()),
concurrency: Some(16),
ninja: Some(false),
..Default::default()
};

assert_eq!(
node_lockfile_options(&node),
BTreeMap::from([
("cflags".to_string(), "-O2".to_string()),
("compile".to_string(), "true".to_string()),
("configure_opts".to_string(), "--openssl-no-asm".to_string()),
("make".to_string(), "gmake".to_string()),
("make_install_opts".to_string(), "--no-strip".to_string()),
("make_opts".to_string(), "-s".to_string()),
("ninja".to_string(), "false".to_string()),
])
);
}
}
Loading