Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 38 additions & 7 deletions crates/aube/src/commands/install/node_gyp_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ fn node_gyp_on_path() -> bool {
/// (sometimes `.exe` alongside), so a bare-string check would always
/// miss the bootstrapped shim and the fast-path would never fire.
pub(crate) fn node_gyp_bin_exists(bin_dir: &Path) -> bool {
BINARY_NAMES.iter().any(|name| bin_dir.join(name).exists())
node_gyp_binary(bin_dir).is_some()
}

fn primary_binary_name() -> &'static str {
BINARY_NAMES[0]
fn node_gyp_binary(bin_dir: &Path) -> Option<PathBuf> {
BINARY_NAMES
.iter()
.map(|name| bin_dir.join(name))
.find(|path| path.is_file())
}

fn tool_root() -> miette::Result<PathBuf> {
Expand All @@ -79,7 +82,7 @@ fn tool_root() -> miette::Result<PathBuf> {
Ok(cache.join("tools").join("node-gyp"))
}

pub async fn ensure_cached(project_dir: &Path) -> miette::Result<PathBuf> {
pub(crate) async fn ensure_cached(project_dir: &Path) -> miette::Result<PathBuf> {
let root = tool_root()?;
let tool_dir = root.join(BUCKET);
let bin_dir = tool_dir.join("node_modules").join(".bin");
Expand Down Expand Up @@ -160,10 +163,26 @@ pub(crate) fn lazy_js_shim_path() -> miette::Result<PathBuf> {
Ok(shim_dir.join("node-gyp.js"))
}

pub(crate) async fn print_bootstrapped_binary(project_dir: &Path) -> miette::Result<()> {
/// Materialize aube's cached node-gyp installation and return its executable.
///
/// Aube's lazy `node-gyp` shims invoke the current executable with the private
/// `__node-gyp-bootstrap <project-dir>` command. For a standalone aube process
/// that executable is aube itself. An embedding host must intercept that
/// command before its own argument parser, call this function, and print the
/// returned path to stdout.
///
/// The bootstrap stays fully in-process and inherits the outer project's
/// registry configuration. Aube owns the cache layout, version selection, and
/// cross-process locking; the host does not need an `aube` or `npm` executable.
pub async fn bootstrap_node_gyp(project_dir: &Path) -> miette::Result<PathBuf> {
let bin_dir = ensure_cached(project_dir).await?;
println!("{}", bin_dir.join(primary_binary_name()).display());
Ok(())
node_gyp_binary(&bin_dir).ok_or_else(|| {
miette!(
code = aube_codes::errors::ERR_AUBE_EMBED_INSTALL_FAILED,
"node-gyp bootstrap completed but no executable exists in {}",
bin_dir.display()
)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
})
}

/// The `node-gyp` shell shim: resolves the real binary through the
Expand Down Expand Up @@ -483,4 +502,16 @@ mod tests {
assert!(!shim_is_current(&path, SH_SHIM));
let _ = std::fs::remove_dir_all(dir);
}

#[cfg(windows)]
#[test]
fn resolves_exe_only_cache() {
let dir = tempdir();
let exe = dir.join("node-gyp.exe");
std::fs::write(&exe, b"").unwrap();

assert_eq!(node_gyp_binary(&dir), Some(exe.clone()));
assert!(exe.is_file());
let _ = std::fs::remove_dir_all(dir);
}
}
1 change: 1 addition & 0 deletions crates/aube/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use std::path::{Path, PathBuf};

pub use crate::commands::add::AddToProjectOptions;
pub use crate::commands::install::node_gyp_bootstrap::bootstrap_node_gyp;
pub use crate::commands::install::{
DepSelection, EmbedderInstallOverrides, FrozenMode, INSTALL_OUTPUT_CODE_LIFECYCLE_SCRIPT,
InstallControl, InstallEvent, InstallOutputLevel, InstallOutputMode, InstallPhase,
Expand Down
3 changes: 2 additions & 1 deletion crates/aube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,8 @@ async fn async_main(cli: Cli, invoked_as_aubr: bool) -> miette::Result<Option<i3

match cli.command {
Some(Commands::NodeGypBootstrap { project_dir }) => {
commands::install::node_gyp_bootstrap::print_bootstrapped_binary(&project_dir).await?
let binary = embed::bootstrap_node_gyp(&project_dir).await?;
println!("{}", binary.display());
}
Some(Commands::Access(args)) => commands::access::run(args).await?,
Some(Commands::Activate(args)) => commands::activate::run(args)?,
Expand Down
Loading