mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
fix(cli.js): force version update on Cargo manifest (#2419)
This commit is contained in:
parent
b85775911d
commit
c544cea8c9
5
.changes/cli.js-deps-update-manifest.md
Normal file
5
.changes/cli.js-deps-update-manifest.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"cli.js": patch
|
||||
---
|
||||
|
||||
Force Cargo manifest update when running the `deps update` command and fix the version that is written to the file.
|
@ -32,8 +32,14 @@ function readToml<T>(tomlPath: string): T | null {
|
||||
return null
|
||||
}
|
||||
|
||||
function dependencyDefinition(version: string): CargoManifestDependency {
|
||||
return { version: version.substring(0, version.lastIndexOf('.')) }
|
||||
function dependencyDefinition(
|
||||
dependency: string | CargoManifestDependency,
|
||||
version: string
|
||||
): string | CargoManifestDependency {
|
||||
if (typeof dependency === 'string') {
|
||||
return version
|
||||
}
|
||||
return { ...dependency, version }
|
||||
}
|
||||
|
||||
async function manageDependencies(
|
||||
@ -73,29 +79,46 @@ async function manageDependencies(
|
||||
const latestVersion = getCrateLatestVersion(dependency)
|
||||
if (latestVersion !== null) {
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency] = dependencyDefinition(latestVersion)
|
||||
manifest.dependencies[dependency] = dependencyDefinition(
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency],
|
||||
latestVersion
|
||||
)
|
||||
}
|
||||
installedDeps.push(dependency)
|
||||
} else if (managementType === ManagementType.Update) {
|
||||
const latestVersion = getCrateLatestVersion(dependency)
|
||||
if (latestVersion !== null && semverLt(currentVersion, latestVersion)) {
|
||||
const inquired = (await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'answer',
|
||||
message: `[CRATES] "${dependency}" latest version is ${latestVersion}. Do you want to update?`,
|
||||
default: false
|
||||
if (latestVersion !== null) {
|
||||
if (semverLt(currentVersion, latestVersion)) {
|
||||
const inquired = (await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'answer',
|
||||
message: `[CRATES] "${dependency}" latest version is ${latestVersion}. Do you want to update?`,
|
||||
default: false
|
||||
}
|
||||
])) as { answer: boolean }
|
||||
if (inquired.answer) {
|
||||
log(`Updating ${dependency}...`)
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency] = dependencyDefinition(
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency],
|
||||
latestVersion
|
||||
)
|
||||
updatedDeps.push(dependency)
|
||||
}
|
||||
])) as { answer: boolean }
|
||||
if (inquired.answer) {
|
||||
log(`Updating ${dependency}...`)
|
||||
} else {
|
||||
// force update the manifest to the show the latest version even if the lockfile is up to date
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency] =
|
||||
dependencyDefinition(latestVersion)
|
||||
manifest.dependencies[dependency] = dependencyDefinition(
|
||||
// eslint-disable-next-line security/detect-object-injection
|
||||
manifest.dependencies[dependency],
|
||||
latestVersion
|
||||
)
|
||||
updatedDeps.push(dependency)
|
||||
log(`"${dependency}" is up to date`)
|
||||
}
|
||||
} else {
|
||||
log(`"${dependency}" is up to date`)
|
||||
}
|
||||
} else {
|
||||
log(`"${dependency}" is already installed`)
|
||||
|
Loading…
Reference in New Issue
Block a user