Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Use a PATH based approach for task execution. #1208

Merged
merged 36 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ed4591d
new: Rework `moon init` command. (#1204)
milesj Nov 26, 2023
9723863
Add paths.
milesj Nov 27, 2023
496821c
Add new methods.
milesj Nov 27, 2023
e0fd05e
Update deno.
milesj Nov 27, 2023
f6f3bef
Update bun.
milesj Nov 27, 2023
876057c
Update deno.
milesj Nov 27, 2023
1c06de1
Update rust.
milesj Nov 27, 2023
ae3ec94
Update node.
milesj Nov 27, 2023
102da33
Add target paths.
milesj Nov 27, 2023
7ed0d2f
Add env vars.
milesj Nov 27, 2023
4b4cbcd
Update bin.
milesj Nov 27, 2023
caa882f
Rework vars.
milesj Nov 27, 2023
04be376
Avoid latest version.
milesj Nov 27, 2023
bb608c6
Fix tests.
milesj Nov 28, 2023
09add02
Update docs.
milesj Nov 28, 2023
6f11fd2
Install proto.
milesj Nov 28, 2023
a155947
Polish consts.
milesj Nov 28, 2023
c56538f
Update lookup paths.
milesj Nov 28, 2023
fae001f
Always use a shell.
milesj Nov 28, 2023
b43d28d
Remove shell from vcs.
milesj Nov 28, 2023
320c750
Copy bin.
milesj Nov 28, 2023
4d82f85
Polish.
milesj Dec 8, 2023
dbecad5
Fix workspace.
milesj Dec 8, 2023
6f1d6f7
Fixes.
milesj Dec 8, 2023
739aa9a
Disable proto for tests.
milesj Dec 8, 2023
33bdbc3
Only run on linux.
milesj Dec 8, 2023
579d40c
Start on blog post.
milesj Dec 8, 2023
1ce1fac
Fix windows shell.
milesj Dec 8, 2023
77b0a03
Fix tests.
milesj Dec 8, 2023
507c21c
More fixes.
milesj Dec 8, 2023
4e44706
More fixes.
milesj Dec 9, 2023
b23d291
Fix format.
milesj Dec 9, 2023
896eb94
Update docs.
milesj Dec 9, 2023
8e3ca18
Fallback to a version.
milesj Dec 9, 2023
10598ab
Remove snapshot.
milesj Dec 9, 2023
04ea54f
Update proto config.
milesj Dec 9, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: PR
on:
pull_request:
env:
MOON_DEBUG: 'true'
PROTO_DEBUG: 'true'
# env:
# MOON_DEBUG: 'true'
# PROTO_DEBUG: 'true'
jobs:
version:
name: Version check
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ jobs:
bins: cargo-make, cargo-nextest, cargo-llvm-cov
cache-base: '^(master|develop-)'
components: llvm-tools-preview
# Required for "global bins" tests
- uses: moonrepo/setup-toolchain@v0
if: ${{ runner.os == 'Linux' }}
- run: proto install bun 1.0.0 --pin
if: ${{ runner.os == 'Linux' }}
with:
auto-install: true
proto-version: '0.24.2' # Keep in sync
- uses: mozilla-actions/[email protected]
- name: Run tests
if: ${{ env.WITH_COVERAGE == 'false' }}
Expand Down
2 changes: 1 addition & 1 deletion .moon/workspace.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Trigger CI: 23
# Trigger CI: 24

$schema: '../website/static/schemas/workspace.json'

Expand Down
4 changes: 4 additions & 0 deletions .prototools
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are used by tests that require the tools
# to exist in the environment!
bun = "1.0.15"
node = "20.8.0"
21 changes: 12 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pathdiff = "0.2.1"
petgraph = { version = "0.6.4", default-features = false, features = [
"serde-1",
] }
proto_core = "0.24.2"
proto_core = "0.24.4"
relative-path = { version = "1.9.0", features = ["serde"] }
regex = "1.10.2"
reqwest = { version = "0.11.22", default-features = false, features = [
Expand All @@ -60,7 +60,7 @@ serde = { version = "1.0.193", features = ["derive", "rc"] }
serde_json = "1.0.108"
serde_yaml = "0.9.27"
starbase = "0.2.10"
starbase_archive = { version = "0.2.4", default-features = false, features = [
starbase_archive = { version = "0.2.5", default-features = false, features = [
"tar-gz",
] }
starbase_events = { version = "0.2.2" }
Expand Down
110 changes: 2 additions & 108 deletions crates/bun/platform/src/actions/run_target.rs
Original file line number Diff line number Diff line change
@@ -1,118 +1,12 @@
use crate::target_hash::BunTargetHash;
use moon_bun_tool::BunTool;
use moon_config::{HasherConfig, HasherOptimization};
use moon_node_lang::{
node::{self, BinFile},
PackageJson,
};
use moon_process::Command;
use moon_node_lang::PackageJson;
use moon_project::Project;
use moon_task::Task;
use moon_tool::{prepend_path_env_var, DependencyManager, Tool, ToolError};
use moon_utils::path;
use moon_tool::DependencyManager;
use rustc_hash::FxHashMap;
use std::path::Path;

fn find_package_bin(
command: &mut Command,
starting_dir: &Path,
working_dir: &Path,
bin_name: &str,
) -> miette::Result<Option<Command>> {
let possible_bin_path = match node::find_package_bin(starting_dir, bin_name)? {
Some(bin) => bin,
None => {
// moon isn't installed as a node module, but probably
// exists globally, so let's go with that instead of failing
if bin_name == "moon" {
return Ok(Some(Command::new(bin_name)));
}

return Err(ToolError::MissingBinary("node module".into(), bin_name.to_owned()).into());
}
};

match possible_bin_path {
// Rust, Go
BinFile::Binary(bin_path) => {
return Ok(Some(Command::new(bin_path)));
}
// JavaScript
BinFile::Script(bin_path) => {
command.arg(path::to_string(
path::relative_from(bin_path, working_dir).unwrap(),
)?);
}
// Other (Bash)
BinFile::Other(bin_path, parent_cmd) => {
let mut cmd = Command::new(parent_cmd);
cmd.arg(bin_path);

return Ok(Some(cmd));
}
};

Ok(None)
}

pub fn create_target_command(
bun: &BunTool,
project: &Project,
task: &Task,
working_dir: &Path,
) -> miette::Result<Command> {
let mut command = Command::new(bun.get_bin_path()?);

match task.command.as_str() {
"bun" | "bunx" => {
if task.command == "bunx" {
command.arg("x");
}
}
bin => {
if let Some(new_command) =
find_package_bin(&mut command, &project.root, working_dir, bin)?
{
command = new_command;
}
}
};

if !bun.global {
command.env(
"PATH",
prepend_path_env_var([bun.tool.get_exe_path()?.parent().unwrap()]),
);
}

command.args(&task.args).envs(&task.env);

Ok(command)
}

// This is like the function above, but is for situations where the tool
// has not been configured, and should default to the global "bun" found
// in the user's shell.
pub fn create_target_command_without_tool(
project: &Project,
task: &Task,
working_dir: &Path,
) -> miette::Result<Command> {
let mut command = Command::new(&task.command);

if task.command != "bun" && task.command != "bunx" {
if let Some(new_command) =
find_package_bin(&mut command, &project.root, working_dir, &task.command)?
{
command = new_command;
}
}

command.args(&task.args).envs(&task.env);

Ok(command)
}

pub async fn create_target_hasher(
bun: Option<&BunTool>,
project: &Project,
Expand Down
57 changes: 41 additions & 16 deletions crates/bun/platform/src/bun_platform.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::actions;
use moon_action_context::ActionContext;
use moon_bun_lang::BUNPM;
use moon_bun_tool::BunTool;
use moon_bun_tool::{get_bun_env_paths, BunTool};
use moon_common::Id;
use moon_config::{
BunConfig, DependencyConfig, DependencyScope, DependencySource, HasherConfig, PlatformType,
Expand All @@ -14,7 +14,7 @@ use moon_platform::{Platform, Runtime, RuntimeReq};
use moon_process::Command;
use moon_project::Project;
use moon_task::Task;
use moon_tool::{Tool, ToolManager};
use moon_tool::{get_proto_version_env, prepend_path_env_var, Tool, ToolManager};
use moon_typescript_platform::TypeScriptTargetHash;
use moon_utils::{async_trait, path};
use proto_core::ProtoEnvironment;
Expand Down Expand Up @@ -266,7 +266,7 @@ impl Platform for BunPlatform {
if !self.toolchain.has(&req) {
self.toolchain.register(
&req,
BunTool::new(&self.proto_env, &self.config, &req).await?,
BunTool::new(Arc::clone(&self.proto_env), &self.config, &req).await?,
);
}

Expand All @@ -292,8 +292,10 @@ impl Platform for BunPlatform {
let req = &runtime.requirement;

if !self.toolchain.has(req) {
self.toolchain
.register(req, BunTool::new(&self.proto_env, &self.config, req).await?);
self.toolchain.register(
req,
BunTool::new(Arc::clone(&self.proto_env), &self.config, req).await?,
);
}

Ok(self.toolchain.setup(req, last_versions).await?)
Expand Down Expand Up @@ -395,18 +397,41 @@ impl Platform for BunPlatform {
project: &Project,
task: &Task,
runtime: &Runtime,
working_dir: &Path,
_working_dir: &Path,
) -> miette::Result<Command> {
let command = if self.is_toolchain_enabled()? {
actions::create_target_command(
self.toolchain.get_for_version(&runtime.requirement)?,
project,
task,
working_dir,
)?
} else {
actions::create_target_command_without_tool(project, task, working_dir)?
};
let mut command = Command::new(&task.command);
command.args(&task.args);
command.envs(&task.env);

if let Ok(bun) = self.toolchain.get_for_version(&runtime.requirement) {
if let Some(version) = get_proto_version_env(&bun.tool) {
command.env("PROTO_BUN_VERSION", version);
}
}

let mut paths = vec![];
let mut current_dir = project.root.as_path();

loop {
paths.push(current_dir.join("node_modules").join(".bin"));

if current_dir == self.workspace_root {
break;
}

match current_dir.parent() {
Some(dir) => {
current_dir = dir;
}
None => break,
};
}

if !runtime.requirement.is_global() {
paths.extend(get_bun_env_paths(&self.proto_env));
}

command.env("PATH", prepend_path_env_var(paths));

Ok(command)
}
Expand Down
Loading
Loading