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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "vite-task-bunx-wrapper",
"version": "1.0.0",
"private": true,
"scripts": {
"gate:test": "bun probe",
"probe": "bunx --bun probe"
},
"dependencies": {
"probe-bin": "file:./probe-bin"
},
"devEngines": {
"packageManager": {
"name": "bun",
"version": "1.3.14",
"onFail": "download"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log('probe binary ran');
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "probe-bin",
"version": "1.0.0",
"bin": {
"probe": "bin.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[case]]
name = "vite_task_bunx_wrapper"
vp = "local"
steps = [
{ argv = ["vp", "install"], snapshot = false },
{ argv = ["vp", "run", "gate:test"], comment = "managed bunx should execute the package binary without recursively invoking the matching package script" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# vite_task_bunx_wrapper

## `vp install`


## `vp run gate:test`

managed bunx should execute the package binary without recursively invoking the matching package script

```
$ bun probe ⊘ cache disabled
$ bunx --bun probe
probe binary ran
```
4 changes: 2 additions & 2 deletions crates/vp_pm_cli/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,9 +1384,9 @@ async fn create_bun_shim_files(bin_prefix: &AbsolutePath) -> Result<(), Error> {
let bun_shim = bin_prefix.join("bun");
shim::write_native_shims(&native_bin, &bun_shim).await?;

// Create bunx shim -> bun.native (bunx is just bun with different argv[0])
// Native wrappers cannot preserve bunx as argv[0], so select its equivalent x subcommand.
let bunx_shim = bin_prefix.join("bunx");
shim::write_native_shims(&native_bin, &bunx_shim).await?;
shim::write_native_shims_with_args(&native_bin, &bunx_shim, &["x"]).await?;

Ok(())
}
Expand Down
25 changes: 25 additions & 0 deletions crates/vp_pm_cli/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ pub(crate) fn pwsh_shim(relative_file: &str) -> String {
#[cfg(test)]
#[cfg(not(windows))] // FIXME
mod tests {
use std::{os::unix::fs::PermissionsExt, process::Command};

use tempfile::TempDir;
use tokio::fs::read_to_string;

Expand All @@ -226,6 +228,29 @@ mod tests {
shim.replace(' ', "·")
}

#[tokio::test]
async fn test_native_shim_forwards_subcommand() {
let temp_dir = TempDir::new().unwrap();
let source = temp_dir.path().join("bin").join("bun.native");
let target = temp_dir.path().join("bin").join("bunx");

tokio::fs::create_dir_all(source.parent().unwrap()).await.unwrap();
tokio::fs::write(&source, "#!/bin/sh\nprintf '%s\\n' \"$@\"\n").await.unwrap();
tokio::fs::set_permissions(&source, std::fs::Permissions::from_mode(0o755)).await.unwrap();

write_native_shims_with_args(&source, &target, &["x"]).await.unwrap();

let output = Command::new(&target).args(["--bun", "vitest"]).output().unwrap();
assert!(output.status.success());
assert_eq!(String::from_utf8(output.stdout).unwrap(), "x\n--bun\nvitest\n");

let cmd = read_to_string(target.with_extension("cmd")).await.unwrap();
assert!(cmd.contains("@\"%~dp0\\bun.native\" x %*"));

let pwsh = read_to_string(target.with_extension("ps1")).await.unwrap();
assert!(pwsh.contains("& \"$basedir/bun.native\" x $args"));
}

#[test]
fn test_native_shims_without_args() {
let sh = native_sh_shim("bun.native", &[]);
Expand Down
Loading