33 DestroyPlan ,
44 FileUtils ,
55 getPty ,
6- LinuxDistro ,
76 Resource ,
87 ResourceSettings ,
98 Utils
@@ -49,12 +48,10 @@ export class VscodeResource extends Resource<VscodeConfig> {
4948 }
5049
5150 override async create ( plan : CreatePlan < VscodeConfig > ) : Promise < void > {
52- const $ = getPty ( ) ;
53-
5451 if ( Utils . isMacOS ( ) ) {
55- await this . installMacOS ( $ , plan ) ;
52+ await this . installMacOS ( plan ) ;
5653 } else if ( Utils . isLinux ( ) ) {
57- await this . installLinux ( $ , plan ) ;
54+ await this . installLinux ( plan ) ;
5855 } else {
5956 throw new Error ( 'Unsupported operating system' ) ;
6057 }
@@ -68,27 +65,13 @@ export class VscodeResource extends Resource<VscodeConfig> {
6865 const location = path . join ( directory , `"${ VSCODE_APPLICATION_NAME } "` ) ;
6966 await $ . spawn ( `rm -rf ${ location } ` ) ;
7067 } else if ( Utils . isLinux ( ) ) {
71- const distro = await Utils . getLinuxDistro ( ) ;
72-
73- switch ( distro ) {
74- case LinuxDistro . DEBIAN :
75- case LinuxDistro . MANJARO :
76- case LinuxDistro . UBUNTU :
77- case LinuxDistro . MINT : {
78- await $ . spawnSafe ( 'apt-get remove code -y' , { requiresRoot : true } ) ;
79- return ;
80- }
81-
82- case LinuxDistro . RHEL :
83- case LinuxDistro . CENTOS :
84- case LinuxDistro . FEDORA : {
85- await $ . spawnSafe ( 'dnf remove code -y' , { requiresRoot : true } ) ;
86- return ;
87- }
88-
89- default : {
90- throw new Error ( 'Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.' ) ;
91- }
68+
69+ if ( Utils . isDebianBased ( ) ) {
70+ await $ . spawnSafe ( 'apt-get remove code -y' , { requiresRoot : true } ) ;
71+ } else if ( Utils . isRedhatBased ( ) ) {
72+ await $ . spawnSafe ( 'dnf remove code -y' , { requiresRoot : true } ) ;
73+ } else {
74+ throw new Error ( 'Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.' ) ;
9275 }
9376
9477 // Remove user data and config
@@ -119,7 +102,8 @@ export class VscodeResource extends Resource<VscodeConfig> {
119102 return false ;
120103 }
121104
122- private async installMacOS ( $ : ReturnType < typeof getPty > , plan : CreatePlan < VscodeConfig > ) : Promise < void > {
105+ private async installMacOS ( plan : CreatePlan < VscodeConfig > ) : Promise < void > {
106+ const $ = getPty ( ) ;
123107 // Create a temporary tmp dir
124108 const temporaryDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'vscode-' ) ) ;
125109
@@ -143,41 +127,31 @@ export class VscodeResource extends Resource<VscodeConfig> {
143127
144128 // Detect distribution and architecture
145129 const isArm = await Utils . isArmArch ( ) ;
146- const distro = await Utils . getLinuxDistro ( ) ;
147-
148- switch ( distro ) {
149- case LinuxDistro . DEBIAN :
150- case LinuxDistro . MANJARO :
151- case LinuxDistro . UBUNTU :
152- case LinuxDistro . MINT : {
153- const downloadLink = DOWNLOAD_URL_BASE + ( isArm ? '?build=stable&os=linux-deb-arm64' : '?build=stable&os=linux-deb-x64' ) ;
154- const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'vscode-' ) ) ;
155- const vscodeDebPath = path . join ( tmpDir , 'vscode.deb' ) ;
156-
157- try {
158- await FileUtils . downloadFile ( downloadLink , vscodeDebPath ) ;
159-
160- await $ . spawn ( 'debconf-set-selections <<< "code code/add-microsoft-repo boolean true"' , { requiresRoot : true } ) ;
161- await $ . spawn ( 'apt-get install ./vscode.deb -y' , { cwd : tmpDir , requiresRoot : true , env : { DEBIAN_FRONTEND : 'noninteractive' } } ) ;
162- } finally {
163- // await fs.rm(tmpDir, { recursive: true, force: true });
164- }
165-
166- return ;
167- }
168130
169- case LinuxDistro . RHEL :
170- case LinuxDistro . CENTOS :
171- case LinuxDistro . FEDORA : {
172- await $ . spawn ( 'rpm --import https://packages.microsoft.com/keys/microsoft.asc &&\n' +
173- 'echo -e "[code]\\nname=Visual Studio Code\\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\\nenabled=1\\nautorefresh=1\\ntype=rpm-md\\ngpgcheck=1\\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | tee /etc/yum.repos.d/vscode.repo > /dev/null' , { requiresRoot : true } ) ;
174- await $ . spawn ( 'dnf check-update && dnf install code -y' , { requiresRoot : true , env : { DEBIAN_FRONTEND : 'noninteractive' } } ) ;
175- return ;
176- }
131+ if ( Utils . isDebianBased ( ) ) {
132+ const downloadLink = DOWNLOAD_URL_BASE + ( isArm ? '?build=stable&os=linux-deb-arm64' : '?build=stable&os=linux-deb-x64' ) ;
133+ const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'vscode-' ) ) ;
134+ const vscodeDebPath = path . join ( tmpDir , 'vscode.deb' ) ;
177135
178- default : {
179- throw new Error ( 'Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.' ) ;
136+ try {
137+ await FileUtils . downloadFile ( downloadLink , vscodeDebPath ) ;
138+
139+ await $ . spawn ( 'debconf-set-selections <<< "code code/add-microsoft-repo boolean true"' , { requiresRoot : true } ) ;
140+ await $ . spawn ( 'apt-get install ./vscode.deb -y' , { cwd : tmpDir , requiresRoot : true , env : { DEBIAN_FRONTEND : 'noninteractive' } } ) ;
141+ } finally {
142+ await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
180143 }
144+
145+ return ;
181146 }
147+
148+ if ( Utils . isRedhatBased ( ) ) {
149+ await $ . spawn ( 'rpm --import https://packages.microsoft.com/keys/microsoft.asc &&\n' +
150+ 'echo -e "[code]\\nname=Visual Studio Code\\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\\nenabled=1\\nautorefresh=1\\ntype=rpm-md\\ngpgcheck=1\\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" | tee /etc/yum.repos.d/vscode.repo > /dev/null' , { requiresRoot : true } ) ;
151+ await $ . spawn ( 'dnf check-update && dnf install code -y' , { requiresRoot : true , env : { DEBIAN_FRONTEND : 'noninteractive' } } ) ;
152+ return ;
153+ }
154+
155+ throw new Error ( 'Unsupported Linux distribution. Only Debian-based (Ubuntu, Debian, Mint) and RedHat-based (RHEL, CentOS) systems are supported.' ) ;
182156 }
183157}
0 commit comments