These plug-ins should be able to help - https://www.figma.com/community/plugin/1271383289541400562/variable-utilities
https://www.figma.com/community/plugin/1264578192495051449/variables-pro-swap-import-export-variables
Detaching your components does not unlink the variables in them, so they should still be referencing the variables from the “old” file.