From 5513ef41a3f76c32f3abd55317019a08a4305c73 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:33:39 +0100 Subject: [PATCH] fix: do not require -- in bin executables on unix --- CHANGELOG.md | 1 + src/cli/commands/install.rs | 33 ++++++++++++++++++++++----------- src/main.rs | 7 ++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a58df..b3c513d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Link dependencies before type extraction to support more use cases by @daimond113 - Strip `.luau` extension from linker modules' require paths to comply with Luau by @daimond113 - Correctly handle graph paths for resolving overriden packages by @daimond113 +- Do not require `--` in bin package executables on Unix by @daimond113 ## [0.5.0-rc.14] - 2024-11-30 ### Fixed diff --git a/src/cli/commands/install.rs b/src/cli/commands/install.rs index 0adf539..7126171 100644 --- a/src/cli/commands/install.rs +++ b/src/cli/commands/install.rs @@ -45,12 +45,8 @@ fn bin_link_file(alias: &str) -> String { .collect::>() .join(", "); - #[cfg(not(unix))] - let prefix = String::new(); - #[cfg(unix)] - let prefix = "#!/usr/bin/env -S lune run\n"; format!( - r#"{prefix}local process = require("@lune/process") + r#"local process = require("@lune/process") local fs = require("@lune/fs") local stdio = require("@lune/stdio") @@ -234,27 +230,42 @@ impl InstallCommand { .map(|alias| { let bin_folder = bin_folder.clone(); async move { - let bin_file = bin_folder.join(alias); + let bin_exec_file = bin_folder.join(alias).with_extension(std::env::consts::EXE_EXTENSION); + + let impl_folder = bin_folder.join(".impl"); + fs::create_dir_all(&impl_folder).await.context("failed to create bin link folder")?; + + let bin_file = impl_folder.join(alias).with_extension("luau"); fs::write(&bin_file, bin_link_file(alias)) .await .context("failed to write bin link file")?; - make_executable(&bin_file) - .await - .context("failed to make bin link executable")?; #[cfg(windows)] { - let bin_file = bin_file.with_extension(std::env::consts::EXE_EXTENSION); fs::copy( std::env::current_exe() .context("failed to get current executable path")?, - &bin_file, + &bin_exec_file, ) .await .context("failed to copy bin link file")?; } + #[cfg(not(windows))] + { + fs::write( + &bin_exec_file, + format!(r#"#!/bin/sh +lune run "$(dirname "$0")/.impl/{alias}.luau" -- "$@""# + ), + ) + .await + .context("failed to link bin link file")?; + } + + make_executable(&bin_exec_file).await.context("failed to make bin link file executable")?; + Ok::<_, CallbackError>(()) } }), diff --git a/src/main.rs b/src/main.rs index e686093..f8eec30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,12 @@ async fn run() -> anyhow::Result<()> { // on unix systems let status = std::process::Command::new("lune") .arg("run") - .arg(exe.with_extension("")) + .arg( + exe.parent() + .map(|p| p.join(".impl").join(exe.file_name().unwrap())) + .unwrap_or(exe) + .with_extension("luau"), + ) .arg("--") .args(std::env::args_os().skip(1)) .current_dir(cwd)