fix(cli.js): force version update on Cargo manifest (#2419)

This commit is contained in:
Lucas Fernandes Nogueira 2021-08-13 11:41:06 -03:00 committed by GitHub
parent b85775911d
commit c544cea8c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 17 deletions

View 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.

View 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`)