Skip to content

Commit d5511c3

Browse files
authored
feat(cli): add migration from 2.0.0-beta to 2.0.0-rc (#10395)
* refactor(cli): check tauri version on migration * rc migration * license headers * fix tests * add path * update schema
1 parent 426d14b commit d5511c3

File tree

19 files changed

+621
-314
lines changed

19 files changed

+621
-314
lines changed

.changes/rc-migration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:feat
3+
"@tauri-apps/cli": patch:feat
4+
---
5+
6+
Added migration from `2.0.0-beta` to `2.0.0-rc`.

core/tauri-config-schema/schema.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@
25512551
]
25522552
},
25532553
"changelog": {
2554-
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See\n https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes",
2554+
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See\n <https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes>",
25552555
"type": [
25562556
"string",
25572557
"null"
@@ -2565,28 +2565,28 @@
25652565
]
25662566
},
25672567
"preInstallScript": {
2568-
"description": "Path to script that will be executed before the package is unpacked. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2568+
"description": "Path to script that will be executed before the package is unpacked. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25692569
"type": [
25702570
"string",
25712571
"null"
25722572
]
25732573
},
25742574
"postInstallScript": {
2575-
"description": "Path to script that will be executed after the package is unpacked. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2575+
"description": "Path to script that will be executed after the package is unpacked. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25762576
"type": [
25772577
"string",
25782578
"null"
25792579
]
25802580
},
25812581
"preRemoveScript": {
2582-
"description": "Path to script that will be executed before the package is removed. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2582+
"description": "Path to script that will be executed before the package is removed. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25832583
"type": [
25842584
"string",
25852585
"null"
25862586
]
25872587
},
25882588
"postRemoveScript": {
2589-
"description": "Path to script that will be executed after the package is removed. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2589+
"description": "Path to script that will be executed after the package is removed. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25902590
"type": [
25912591
"string",
25922592
"null"
@@ -2667,28 +2667,28 @@
26672667
]
26682668
},
26692669
"preInstallScript": {
2670-
"description": "Path to script that will be executed before the package is unpacked. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2670+
"description": "Path to script that will be executed before the package is unpacked. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26712671
"type": [
26722672
"string",
26732673
"null"
26742674
]
26752675
},
26762676
"postInstallScript": {
2677-
"description": "Path to script that will be executed after the package is unpacked. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2677+
"description": "Path to script that will be executed after the package is unpacked. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26782678
"type": [
26792679
"string",
26802680
"null"
26812681
]
26822682
},
26832683
"preRemoveScript": {
2684-
"description": "Path to script that will be executed before the package is removed. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2684+
"description": "Path to script that will be executed before the package is removed. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26852685
"type": [
26862686
"string",
26872687
"null"
26882688
]
26892689
},
26902690
"postRemoveScript": {
2691-
"description": "Path to script that will be executed after the package is removed. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2691+
"description": "Path to script that will be executed after the package is removed. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26922692
"type": [
26932693
"string",
26942694
"null"

tooling/cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ oxc_allocator = "0.16"
9898
oxc_ast = "0.16"
9999
magic_string = "0.3"
100100
phf = { version = "0.11", features = ["macros"] }
101+
walkdir = "2"
101102

102103
[target."cfg(windows)".dependencies.windows-sys]
103104
version = "0.52"

tooling/cli/schema.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@
25512551
]
25522552
},
25532553
"changelog": {
2554-
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See\n https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes",
2554+
"description": "Path of the uncompressed Changelog file, to be stored at /usr/share/doc/package-name/changelog.gz. See\n <https://www.debian.org/doc/debian-policy/ch-docs.html#changelog-files-and-release-notes>",
25552555
"type": [
25562556
"string",
25572557
"null"
@@ -2565,28 +2565,28 @@
25652565
]
25662566
},
25672567
"preInstallScript": {
2568-
"description": "Path to script that will be executed before the package is unpacked. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2568+
"description": "Path to script that will be executed before the package is unpacked. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25692569
"type": [
25702570
"string",
25712571
"null"
25722572
]
25732573
},
25742574
"postInstallScript": {
2575-
"description": "Path to script that will be executed after the package is unpacked. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2575+
"description": "Path to script that will be executed after the package is unpacked. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25762576
"type": [
25772577
"string",
25782578
"null"
25792579
]
25802580
},
25812581
"preRemoveScript": {
2582-
"description": "Path to script that will be executed before the package is removed. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2582+
"description": "Path to script that will be executed before the package is removed. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25832583
"type": [
25842584
"string",
25852585
"null"
25862586
]
25872587
},
25882588
"postRemoveScript": {
2589-
"description": "Path to script that will be executed after the package is removed. See\n https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html",
2589+
"description": "Path to script that will be executed after the package is removed. See\n <https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html>",
25902590
"type": [
25912591
"string",
25922592
"null"
@@ -2667,28 +2667,28 @@
26672667
]
26682668
},
26692669
"preInstallScript": {
2670-
"description": "Path to script that will be executed before the package is unpacked. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2670+
"description": "Path to script that will be executed before the package is unpacked. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26712671
"type": [
26722672
"string",
26732673
"null"
26742674
]
26752675
},
26762676
"postInstallScript": {
2677-
"description": "Path to script that will be executed after the package is unpacked. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2677+
"description": "Path to script that will be executed after the package is unpacked. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26782678
"type": [
26792679
"string",
26802680
"null"
26812681
]
26822682
},
26832683
"preRemoveScript": {
2684-
"description": "Path to script that will be executed before the package is removed. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2684+
"description": "Path to script that will be executed before the package is removed. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26852685
"type": [
26862686
"string",
26872687
"null"
26882688
]
26892689
},
26902690
"postRemoveScript": {
2691-
"description": "Path to script that will be executed after the package is removed. See\n http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html",
2691+
"description": "Path to script that will be executed after the package is removed. See\n <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>",
26922692
"type": [
26932693
"string",
26942694
"null"

tooling/cli/src/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn command(options: Options) -> Result<()> {
146146
(None, None, None, None) => npm_name,
147147
_ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"),
148148
};
149-
manager.install(&[npm_spec])?;
149+
manager.install(&[npm_spec], &tauri_dir)?;
150150
}
151151

152152
let _ = acl::permission::add::command(acl::permission::add::Options {
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use serde::Deserialize;
6+
7+
use std::{
8+
collections::HashMap,
9+
fmt::Write,
10+
fs::read_to_string,
11+
path::{Path, PathBuf},
12+
};
13+
14+
#[derive(Clone, Deserialize)]
15+
pub struct CargoLockPackage {
16+
pub name: String,
17+
pub version: String,
18+
pub source: Option<String>,
19+
}
20+
21+
#[derive(Deserialize)]
22+
pub struct CargoLock {
23+
pub package: Vec<CargoLockPackage>,
24+
}
25+
26+
#[derive(Clone, Deserialize)]
27+
pub struct CargoManifestDependencyPackage {
28+
pub version: Option<String>,
29+
pub git: Option<String>,
30+
pub branch: Option<String>,
31+
pub rev: Option<String>,
32+
pub path: Option<PathBuf>,
33+
}
34+
35+
#[derive(Clone, Deserialize)]
36+
#[serde(untagged)]
37+
pub enum CargoManifestDependency {
38+
Version(String),
39+
Package(CargoManifestDependencyPackage),
40+
}
41+
42+
#[derive(Deserialize)]
43+
pub struct CargoManifestPackage {
44+
pub version: String,
45+
}
46+
47+
#[derive(Deserialize)]
48+
pub struct CargoManifest {
49+
pub package: CargoManifestPackage,
50+
pub dependencies: HashMap<String, CargoManifestDependency>,
51+
}
52+
53+
pub struct CrateVersion {
54+
pub version: String,
55+
pub found_crate_versions: Vec<String>,
56+
}
57+
58+
pub fn crate_version(
59+
tauri_dir: &Path,
60+
manifest: Option<&CargoManifest>,
61+
lock: Option<&CargoLock>,
62+
name: &str,
63+
) -> CrateVersion {
64+
let crate_lock_packages: Vec<CargoLockPackage> = lock
65+
.as_ref()
66+
.map(|lock| {
67+
lock
68+
.package
69+
.iter()
70+
.filter(|p| p.name == name)
71+
.cloned()
72+
.collect()
73+
})
74+
.unwrap_or_default();
75+
let (crate_version_string, found_crate_versions) =
76+
match (&manifest, &lock, crate_lock_packages.len()) {
77+
(Some(_manifest), Some(_lock), 1) => {
78+
let crate_lock_package = crate_lock_packages.first().unwrap();
79+
let version_string = if let Some(s) = &crate_lock_package.source {
80+
if s.starts_with("git") {
81+
format!("{} ({})", s, crate_lock_package.version)
82+
} else {
83+
crate_lock_package.version.clone()
84+
}
85+
} else {
86+
crate_lock_package.version.clone()
87+
};
88+
(version_string, vec![crate_lock_package.version.clone()])
89+
}
90+
(None, Some(_lock), 1) => {
91+
let crate_lock_package = crate_lock_packages.first().unwrap();
92+
let version_string = if let Some(s) = &crate_lock_package.source {
93+
if s.starts_with("git") {
94+
format!("{} ({})", s, crate_lock_package.version)
95+
} else {
96+
crate_lock_package.version.clone()
97+
}
98+
} else {
99+
crate_lock_package.version.clone()
100+
};
101+
(
102+
format!("{version_string} (no manifest)"),
103+
vec![crate_lock_package.version.clone()],
104+
)
105+
}
106+
_ => {
107+
let mut found_crate_versions = Vec::new();
108+
let mut is_git = false;
109+
let manifest_version = match manifest.and_then(|m| m.dependencies.get(name).cloned()) {
110+
Some(tauri) => match tauri {
111+
CargoManifestDependency::Version(v) => {
112+
found_crate_versions.push(v.clone());
113+
v
114+
}
115+
CargoManifestDependency::Package(p) => {
116+
if let Some(v) = p.version {
117+
found_crate_versions.push(v.clone());
118+
v
119+
} else if let Some(p) = p.path {
120+
let manifest_path = tauri_dir.join(&p).join("Cargo.toml");
121+
let v = match read_to_string(manifest_path)
122+
.map_err(|_| ())
123+
.and_then(|m| toml::from_str::<CargoManifest>(&m).map_err(|_| ()))
124+
{
125+
Ok(manifest) => manifest.package.version,
126+
Err(_) => "unknown version".to_string(),
127+
};
128+
format!("path:{p:?} [{v}]")
129+
} else if let Some(g) = p.git {
130+
is_git = true;
131+
let mut v = format!("git:{g}");
132+
if let Some(branch) = p.branch {
133+
let _ = write!(v, "&branch={branch}");
134+
} else if let Some(rev) = p.rev {
135+
let _ = write!(v, "#{rev}");
136+
}
137+
v
138+
} else {
139+
"unknown manifest".to_string()
140+
}
141+
}
142+
},
143+
None => "no manifest".to_string(),
144+
};
145+
146+
let lock_version = match (lock, crate_lock_packages.is_empty()) {
147+
(Some(_lock), false) => crate_lock_packages
148+
.iter()
149+
.map(|p| p.version.clone())
150+
.collect::<Vec<String>>()
151+
.join(", "),
152+
(Some(_lock), true) => "unknown lockfile".to_string(),
153+
_ => "no lockfile".to_string(),
154+
};
155+
156+
(
157+
format!(
158+
"{} {}({})",
159+
manifest_version,
160+
if is_git { "(git manifest)" } else { "" },
161+
lock_version
162+
),
163+
found_crate_versions,
164+
)
165+
}
166+
};
167+
168+
CrateVersion {
169+
found_crate_versions,
170+
version: crate_version_string,
171+
}
172+
}

tooling/cli/src/helpers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
pub mod app_paths;
66
pub mod cargo;
7+
pub mod cargo_manifest;
78
pub mod config;
89
pub mod flock;
910
pub mod framework;

0 commit comments

Comments
 (0)