From b8989c5c96f9695c418ac22c01d035b263b4b78a Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Mon, 26 Feb 2024 10:47:05 -0500 Subject: [PATCH 1/3] Update doctor_command.dart with jsonc package import --- lib/src/commands/doctor_command.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, From f9e8d332b7262085d2c0365ddba3115e42a3cea2 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Mon, 26 Feb 2024 10:47:24 -0500 Subject: [PATCH 2/3] Unreleased changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3710688c..0453b000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +* Fixes parsing error of vscode settings when there are commas [#656](https://github.com/leoafarias/fvm/issues/656) + ## 3.0.11 * Removed `fvm update` command. Due to issue with brew and chocolatey install. From 62e59d5417b342d267cffa6d08afb421892bbbd3 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Mon, 26 Feb 2024 11:09:50 -0500 Subject: [PATCH 3/3] Update dependencies and fix deprecation warnings --- lib/src/models/config_model.dart | 6 +++--- lib/src/utils/deprecation_util.dart | 13 +++++++------ tool/homebrew.dart | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) 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 = {};