diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a660fd..2a253d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.0.12 -* Adds skipping version mismatch handling when using force or running with a custom fvm version. +* Adds skipping version mismatch handling when using force or running with a custom fvm version. [#653](https://github.com/leoafarias/fvm/issues/653) +* Fixes parsing error of vscode settings when there are commas [#656](https://github.com/leoafarias/fvm/issues/656) ## 3.0.11 diff --git a/lib/src/commands/doctor_command.dart b/lib/src/commands/doctor_command.dart index 52179a52..883057c8 100644 --- a/lib/src/commands/doctor_command.dart +++ b/lib/src/commands/doctor_command.dart @@ -1,8 +1,8 @@ -import 'dart:convert'; import 'dart:io'; import 'package:dart_console/dart_console.dart'; import 'package:io/io.dart'; +import 'package:jsonc/jsonc.dart'; import 'package:path/path.dart'; import '../models/config_model.dart'; @@ -76,7 +76,7 @@ class DoctorCommand extends BaseCommand { if (vscodeDir.existsSync()) { if (settingsFile.existsSync()) { try { - final settings = jsonDecode(settingsFile.readAsStringSync()); + final settings = jsonc.decode(settingsFile.readAsStringSync()); final relativeSymlinkPath = relative( project.localVersionSymlinkPath, diff --git a/lib/src/models/config_model.dart b/lib/src/models/config_model.dart index c580ca21..25cc4581 100644 --- a/lib/src/models/config_model.dart +++ b/lib/src/models/config_model.dart @@ -1,9 +1,9 @@ // Use just for reference, should not change -import 'dart:convert'; import 'dart:io'; import 'package:args/args.dart'; +import 'package:jsonc/jsonc.dart'; import '../utils/change_case.dart'; import '../utils/constants.dart'; @@ -204,7 +204,7 @@ class AppConfig extends Config { } factory AppConfig.fromJson(String source) { - return AppConfig.fromMap(json.decode(source) as Map); + return AppConfig.fromMap(jsonc.decode(source) as Map); } static AppConfig? loadFromPath(String path) { @@ -321,7 +321,7 @@ class ProjectConfig extends Config { /// Returns ConfigDto from a json string factory ProjectConfig.fromJson(String source) => - ProjectConfig.fromMap(json.decode(source) as Map); + ProjectConfig.fromMap(jsonc.decode(source) as Map); static ProjectConfig? loadFromPath(String path) { final configFile = File(path); diff --git a/lib/src/utils/deprecation_util.dart b/lib/src/utils/deprecation_util.dart index 6fb21ab8..6deada26 100644 --- a/lib/src/utils/deprecation_util.dart +++ b/lib/src/utils/deprecation_util.dart @@ -13,13 +13,13 @@ import 'context.dart'; void deprecationWorkflow() { _warnDeprecatedEnvVars(); final fvmDir = ctx.fvmDir; - final settingsFile = File(join(fvmDir, '.settings')); + final legacySettingsFile = File(join(fvmDir, '.settings')); - if (!settingsFile.existsSync()) { + if (!legacySettingsFile.existsSync()) { return; } - final payload = settingsFile.readAsStringSync(); + final payload = legacySettingsFile.readAsStringSync(); try { final settings = jsonDecode(payload); final settingsCachePath = settings['cachePath'] as String?; @@ -27,9 +27,9 @@ void deprecationWorkflow() { var appConfig = ConfigRepository.loadFile(); appConfig = appConfig.copyWith(cachePath: fvmDir); ConfigRepository.save(appConfig); - settingsFile.deleteSync(recursive: true); + legacySettingsFile.deleteSync(recursive: true); logger.success( - 'We have moved the settings file ${settingsFile.path}' + 'We have moved the settings file ${legacySettingsFile.path}' 'Your settings have been migrated to $kAppConfigFile' 'Your cachePath is now $settingsCachePath. FVM will exit now. Please run the command again.', ); @@ -37,7 +37,8 @@ void deprecationWorkflow() { exit(ExitCode.success.code); } } catch (_) { - logger.warn('Could not parse legact settings file'); + logger.warn('Could not parse legacy settings file'); + legacySettingsFile.deleteSync(recursive: true); } } diff --git a/tool/homebrew.dart b/tool/homebrew.dart index b033f376..09686fe5 100644 --- a/tool/homebrew.dart +++ b/tool/homebrew.dart @@ -1,10 +1,10 @@ -import 'dart:convert'; import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:fvm/src/utils/http.dart'; import 'package:grinder/grinder.dart'; import 'package:http/http.dart' as http; +import 'package:jsonc/jsonc.dart'; import 'package:path/path.dart' as path; import 'grind.dart'; @@ -33,7 +33,7 @@ Future _homebrewFormula() async { final response = await fetch(url.toString(), headers: headers); - final Map release = json.decode(response); + final Map release = jsonc.decode(response); final List assets = release['assets']; final Map assetData = {};