π File detail
migrations/migrateAutoUpdatesToSettings.ts
π§© .tsπ 62 linesπΎ 1,953 bytesπ text
β Back to All Filesπ― Use case
This file lives under βmigrations/β, which covers version migrations for settings or on-disk data. On the API surface it exposes migrateAutoUpdatesToSettings β mainly functions, hooks, or classes. Dependencies touch src. It composes internal code from utils (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { logEvent } from 'src/services/analytics/index.js' import { getGlobalConfig, saveGlobalConfig } from '../utils/config.js' import { logError } from '../utils/log.js' import { getSettingsForSource,
π€ Exports (heuristic)
migrateAutoUpdatesToSettings
π External import roots
Package roots from from "β¦" (relative paths omitted).
src
π₯οΈ Source preview
import { logEvent } from 'src/services/analytics/index.js'
import { getGlobalConfig, saveGlobalConfig } from '../utils/config.js'
import { logError } from '../utils/log.js'
import {
getSettingsForSource,
updateSettingsForSource,
} from '../utils/settings/settings.js'
/**
* Migration: Move user-set autoUpdates preference to settings.json env var
* Only migrates if user explicitly disabled auto-updates (not for protection)
* This preserves user intent while allowing native installations to auto-update
*/
export function migrateAutoUpdatesToSettings(): void {
const globalConfig = getGlobalConfig()
// Only migrate if autoUpdates was explicitly set to false by user preference
// (not automatically for native protection)
if (
globalConfig.autoUpdates !== false ||
globalConfig.autoUpdatesProtectedForNative === true
) {
return
}
try {
const userSettings = getSettingsForSource('userSettings') || {}
// Always set DISABLE_AUTOUPDATER to preserve user intent
// We need to overwrite even if it exists, to ensure the migration is complete
updateSettingsForSource('userSettings', {
...userSettings,
env: {
...userSettings.env,
DISABLE_AUTOUPDATER: '1',
},
})
logEvent('tengu_migrate_autoupdates_to_settings', {
was_user_preference: true,
already_had_env_var: !!userSettings.env?.DISABLE_AUTOUPDATER,
})
// explicitly set, so this takes effect immediately
process.env.DISABLE_AUTOUPDATER = '1'
// Remove autoUpdates from global config after successful migration
saveGlobalConfig(current => {
const {
autoUpdates: _,
autoUpdatesProtectedForNative: __,
...updatedConfig
} = current
return updatedConfig
})
} catch (error) {
logError(new Error(`Failed to migrate auto-updates: ${error}`))
logEvent('tengu_migrate_autoupdates_error', {
has_error: true,
})
}
}