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

pkgx +yarnpkg.com yarn works #1084

Merged
merged 1 commit into from
Jan 17, 2025
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
38 changes: 19 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
- run: cargo fmt --all -- --check

clippy:
needs: test
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand Down Expand Up @@ -61,7 +60,7 @@ jobs:
RUSTFLAGS: "-D warnings"

coverage-unit:
needs: [test, clippy, fmt]
needs: fmt
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -78,7 +77,7 @@ jobs:
flag-name: ${{ matrix.os }}

coverage-integration:
needs: [test, clippy, fmt]
needs: fmt
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -92,22 +91,23 @@ jobs:
RUSTFLAGS="-C instrument-coverage" cargo build
echo "$PWD/target/debug" >> $GITHUB_PATH

- name: run integrations
run: |
pkgx --help
pkgx --version
pkgx +git
pkgx +git --json
pkgx +git --json=v1
pkgx git --version
pkgx --silent +git
pkgx --quiet +git
pkgx +git -- git --version # lib/utils.rs:find_program
pkgx --shellcode || true
pkgx -qq git --version
pkgx -s git --version
pkgx -j +git
pkgx /usr/bin/awk --version
- run: pkgx --help
- run: pkgx --version
- run: pkgx +git
- run: pkgx +git --json
- run: pkgx +git --json=v1
- run: pkgx git --version
- run: pkgx --silent +git
- run: pkgx --quiet +git
- run: pkgx +git -- git --version # lib/utils.rs:find_program
- run: pkgx --shellcode || true
- run: pkgx -qq git --version
- run: pkgx -s git --version
- run: pkgx -j +git
- run: pkgx /usr/bin/awk --version
- run: pkgx +yarnpkg.com yarn --version
- run: pkgx +yarnpkg.com -- yarn --version
- run: '! pkgx yarn --version'

- name: generate coverage
run: |
Expand Down
72 changes: 43 additions & 29 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ async fn main() -> Result<(), Box<dyn Error>> {

let mut pkgs = vec![];

for pkgspec in plus {
let PackageReq {
project: project_or_cmd,
constraint,
} = PackageReq::parse(&pkgspec)?;
if config
.pantry_dir
.join("projects")
.join(project_or_cmd.clone())
.is_dir()
{
pkgs.push(PackageReq {
project: project_or_cmd,
constraint,
});
} else {
let project = which(&project_or_cmd, &conn, &pkgs).await?;
pkgs.push(PackageReq {
project,
constraint,
});
}
}

if find_program {
let PackageReq {
constraint,
Expand All @@ -75,7 +99,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

args[0] = cmd.clone(); // invoke eg. `node` rather than eg. `node@20`

let project = match which(&cmd, &conn).await {
let project = match which(&cmd, &conn, &pkgs).await {
Err(WhichError::CmdNotFound(cmd)) => {
if !did_sync {
if let Some(spinner) = &spinner {
Expand All @@ -87,7 +111,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
if let Some(spinner) = &spinner {
spinner.set_message("resolving pkg graph…");
}
which(&cmd, &conn).await
which(&cmd, &conn, &pkgs).await
} else {
Err(WhichError::CmdNotFound(cmd))
}
Expand All @@ -102,30 +126,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
});
}

for pkgspec in plus {
let PackageReq {
project: project_or_cmd,
constraint,
} = PackageReq::parse(&pkgspec)?;
if config
.pantry_dir
.join("projects")
.join(project_or_cmd.clone())
.is_dir()
{
pkgs.push(PackageReq {
project: project_or_cmd,
constraint,
});
} else {
let project = which(&project_or_cmd, &conn).await?;
pkgs.push(PackageReq {
project,
constraint,
});
}
}

let companions = pantry_db::companions_for_projects(
&pkgs
.iter()
Expand Down Expand Up @@ -262,14 +262,28 @@ impl std::fmt::Display for WhichError {

impl std::error::Error for WhichError {}

async fn which(cmd: &String, conn: &Connection) -> Result<String, WhichError> {
async fn which(cmd: &String, conn: &Connection, pkgs: &[PackageReq]) -> Result<String, WhichError> {
let candidates = pantry_db::which(cmd, conn).map_err(WhichError::DbError)?;
if candidates.len() == 1 {
Ok(candidates[0].clone())
} else if candidates.is_empty() {
return Err(WhichError::CmdNotFound(cmd.clone()));
Err(WhichError::CmdNotFound(cmd.clone()))
} else {
return Err(WhichError::MultipleProjects(cmd.clone(), candidates));
let selected_pkgs = candidates
.clone()
.into_iter()
.filter(|candidate| {
pkgs.iter().any(|pkg| {
let PackageReq { project, .. } = pkg;
project == candidate
})
})
.collect::<Vec<String>>();
if selected_pkgs.len() == 1 {
Ok(selected_pkgs[0].clone())
} else {
Err(WhichError::MultipleProjects(cmd.clone(), candidates))
}
}
}

Expand Down
Loading