mirror of https://github.com/tauri-apps/tauri
parent
c43d5df158
commit
3e36d71df5
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
"tauri-cli": "patch:bug"
|
||||||
|
"@tauri-apps/cli": "patch:bug"
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix detecting yarn berry (v2 and higher) in various tauri cli commands.
|
|
@ -81,10 +81,7 @@ pub fn run(options: Options) -> Result<()> {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !metadata.rust_only {
|
if !metadata.rust_only {
|
||||||
if let Some(manager) = frontend_dir
|
if let Some(manager) = frontend_dir.map(PackageManager::from_project) {
|
||||||
.map(PackageManager::from_project)
|
|
||||||
.and_then(|managers| managers.into_iter().next())
|
|
||||||
{
|
|
||||||
let npm_version_req = version
|
let npm_version_req = version
|
||||||
.map(ToString::to_string)
|
.map(ToString::to_string)
|
||||||
.or(metadata.version_req.as_ref().map(|v| match manager {
|
.or(metadata.version_req.as_ref().map(|v| match manager {
|
||||||
|
|
|
@ -7,6 +7,22 @@ use anyhow::Context;
|
||||||
use crate::helpers::cross_command;
|
use crate::helpers::cross_command;
|
||||||
use std::{fmt::Display, path::Path, process::Command};
|
use std::{fmt::Display, path::Path, process::Command};
|
||||||
|
|
||||||
|
pub fn manager_version(package_manager: &str) -> Option<String> {
|
||||||
|
cross_command(package_manager)
|
||||||
|
.arg("-v")
|
||||||
|
.output()
|
||||||
|
.map(|o| {
|
||||||
|
if o.status.success() {
|
||||||
|
let v = String::from_utf8_lossy(o.stdout.as_slice()).to_string();
|
||||||
|
Some(v.split('\n').next().unwrap().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum PackageManager {
|
pub enum PackageManager {
|
||||||
Npm,
|
Npm,
|
||||||
|
@ -35,7 +51,16 @@ impl Display for PackageManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PackageManager {
|
impl PackageManager {
|
||||||
pub fn from_project<P: AsRef<Path>>(path: P) -> Vec<Self> {
|
/// Detects package manager from the given directory, falls back to [`PackageManager::Npm`].
|
||||||
|
pub fn from_project<P: AsRef<Path>>(path: P) -> Self {
|
||||||
|
Self::all_from_project(path)
|
||||||
|
.first()
|
||||||
|
.copied()
|
||||||
|
.unwrap_or(Self::Npm)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detects all possible package managers from the given directory.
|
||||||
|
pub fn all_from_project<P: AsRef<Path>>(path: P) -> Vec<Self> {
|
||||||
let mut found = Vec::new();
|
let mut found = Vec::new();
|
||||||
|
|
||||||
if let Ok(entries) = std::fs::read_dir(path) {
|
if let Ok(entries) = std::fs::read_dir(path) {
|
||||||
|
@ -47,7 +72,15 @@ impl PackageManager {
|
||||||
} else if name.as_ref() == "pnpm-lock.yaml" {
|
} else if name.as_ref() == "pnpm-lock.yaml" {
|
||||||
found.push(PackageManager::Pnpm);
|
found.push(PackageManager::Pnpm);
|
||||||
} else if name.as_ref() == "yarn.lock" {
|
} else if name.as_ref() == "yarn.lock" {
|
||||||
found.push(PackageManager::Yarn);
|
let yarn = if manager_version("yarn")
|
||||||
|
.map(|v| v.chars().next().map(|c| c > '1').unwrap_or_default())
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
PackageManager::YarnBerry
|
||||||
|
} else {
|
||||||
|
PackageManager::Yarn
|
||||||
|
};
|
||||||
|
found.push(yarn);
|
||||||
} else if name.as_ref() == "bun.lockb" {
|
} else if name.as_ref() == "bun.lockb" {
|
||||||
found.push(PackageManager::Bun);
|
found.push(PackageManager::Bun);
|
||||||
} else if name.as_ref() == "deno.lock" {
|
} else if name.as_ref() == "deno.lock" {
|
||||||
|
|
|
@ -5,23 +5,7 @@
|
||||||
use super::{ActionResult, SectionItem, VersionMetadata};
|
use super::{ActionResult, SectionItem, VersionMetadata};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
use crate::helpers::cross_command;
|
use crate::helpers::{cross_command, npm::manager_version};
|
||||||
|
|
||||||
pub fn manager_version(package_manager: &str) -> Option<String> {
|
|
||||||
cross_command(package_manager)
|
|
||||||
.arg("-v")
|
|
||||||
.output()
|
|
||||||
.map(|o| {
|
|
||||||
if o.status.success() {
|
|
||||||
let v = String::from_utf8_lossy(o.stdout.as_slice()).to_string();
|
|
||||||
Some(v.split('\n').next().unwrap().to_string())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.ok()
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn items(metadata: &VersionMetadata) -> Vec<SectionItem> {
|
pub fn items(metadata: &VersionMetadata) -> Vec<SectionItem> {
|
||||||
let node_target_ver = metadata.js_cli.node.replace(">= ", "");
|
let node_target_ver = metadata.js_cli.node.replace(">= ", "");
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
use super::SectionItem;
|
use super::SectionItem;
|
||||||
use super::{env_nodejs::manager_version, VersionMetadata};
|
use super::VersionMetadata;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -77,7 +77,7 @@ pub fn npm_latest_version(pm: &PackageManager, name: &str) -> crate::Result<Opti
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn package_manager(frontend_dir: &PathBuf) -> PackageManager {
|
pub fn package_manager(frontend_dir: &PathBuf) -> PackageManager {
|
||||||
let found = PackageManager::from_project(frontend_dir);
|
let found = PackageManager::all_from_project(frontend_dir);
|
||||||
|
|
||||||
if found.is_empty() {
|
if found.is_empty() {
|
||||||
println!(
|
println!(
|
||||||
|
@ -98,15 +98,7 @@ pub fn package_manager(frontend_dir: &PathBuf) -> PackageManager {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkg_manager == PackageManager::Yarn
|
pkg_manager
|
||||||
&& manager_version("yarn")
|
|
||||||
.map(|v| v.chars().next().map(|c| c > '1').unwrap_or_default())
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
PackageManager::YarnBerry
|
|
||||||
} else {
|
|
||||||
pkg_manager
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn items(
|
pub fn items(
|
||||||
|
|
|
@ -131,10 +131,7 @@ impl Options {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let detected_package_manager = match PackageManager::from_project(&self.directory).first() {
|
let detected_package_manager = PackageManager::from_project(&self.directory);
|
||||||
Some(&package_manager) => package_manager,
|
|
||||||
None => PackageManager::Npm,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.before_dev_command = self
|
self.before_dev_command = self
|
||||||
.before_dev_command
|
.before_dev_command
|
||||||
|
|
|
@ -84,10 +84,7 @@ pub fn migrate(frontend_dir: &Path) -> Result<Vec<String>> {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let pm = PackageManager::from_project(frontend_dir)
|
let pm = PackageManager::from_project(frontend_dir);
|
||||||
.into_iter()
|
|
||||||
.next()
|
|
||||||
.unwrap_or(PackageManager::Npm);
|
|
||||||
|
|
||||||
for pkg in ["@tauri-apps/cli", "@tauri-apps/api"] {
|
for pkg in ["@tauri-apps/cli", "@tauri-apps/api"] {
|
||||||
let version = pm
|
let version = pm
|
||||||
|
|
|
@ -35,10 +35,7 @@ pub fn run() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrate_npm_dependencies(frontend_dir: &Path) -> Result<()> {
|
fn migrate_npm_dependencies(frontend_dir: &Path) -> Result<()> {
|
||||||
let pm = PackageManager::from_project(frontend_dir)
|
let pm = PackageManager::from_project(frontend_dir);
|
||||||
.into_iter()
|
|
||||||
.next()
|
|
||||||
.unwrap_or(PackageManager::Npm);
|
|
||||||
|
|
||||||
let mut install_deps = Vec::new();
|
let mut install_deps = Vec::new();
|
||||||
for pkg in [
|
for pkg in [
|
||||||
|
|
Loading…
Reference in New Issue