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