()
| 1046 | * has been installed. The enabled/disabled state remains in settings.json. |
| 1047 | */ |
| 1048 | export async function migrateFromEnabledPlugins(): Promise<void> { |
| 1049 | // Use merged settings for shouldSkipSync check |
| 1050 | const settings = getSettings_DEPRECATED() |
| 1051 | const enabledPlugins = settings.enabledPlugins || {} |
| 1052 | |
| 1053 | // No plugins in settings = nothing to sync |
| 1054 | if (Object.keys(enabledPlugins).length === 0) { |
| 1055 | return |
| 1056 | } |
| 1057 | |
| 1058 | // Check if main file exists and has V2 format |
| 1059 | const rawFileData = readInstalledPluginsFileRaw() |
| 1060 | const fileExists = rawFileData !== null |
| 1061 | const isV2Format = fileExists && rawFileData?.version === 2 |
| 1062 | |
| 1063 | // If file exists with V2 format, check if we can skip the expensive migration |
| 1064 | if (isV2Format && rawFileData) { |
| 1065 | // Check if all plugins from settings already exist |
| 1066 | // (The expensive getPluginById/getGitCommitSha only runs for missing plugins) |
| 1067 | const existingData = InstalledPluginsFileSchemaV2().safeParse( |
| 1068 | rawFileData.data, |
| 1069 | ) |
| 1070 | |
| 1071 | if (existingData?.success) { |
| 1072 | const plugins = existingData.data.plugins |
| 1073 | const allPluginsExist = Object.keys(enabledPlugins) |
| 1074 | .filter(id => id.includes('@')) |
| 1075 | .every(id => { |
| 1076 | const installations = plugins[id] |
| 1077 | return installations && installations.length > 0 |
| 1078 | }) |
| 1079 | |
| 1080 | if (allPluginsExist) { |
| 1081 | logForDebugging('All plugins already exist, skipping migration') |
| 1082 | return |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | logForDebugging( |
| 1088 | fileExists |
| 1089 | ? 'Syncing installed_plugins.json with enabledPlugins from all settings.json files' |
| 1090 | : 'Creating installed_plugins.json from settings.json files', |
| 1091 | ) |
| 1092 | |
| 1093 | const now = new Date().toISOString() |
| 1094 | const projectPath = getCwd() |
| 1095 | |
| 1096 | // Step 1: Build a map of pluginId -> scope from all settings.json files |
| 1097 | // Settings.json is the source of truth for scope |
| 1098 | const pluginScopeFromSettings = new Map< |
| 1099 | string, |
| 1100 | { |
| 1101 | scope: 'user' | 'project' | 'local' |
| 1102 | projectPath: string | undefined |
| 1103 | } |
| 1104 | >() |
| 1105 |
no test coverage detected