-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.py
More file actions
147 lines (125 loc) · 5.61 KB
/
Copy pathruntime.py
File metadata and controls
147 lines (125 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from __future__ import annotations
from typing import Literal
from .package_storage import PackageStorage, unzip
import sublime
import os
from Mir import LoaderInStatusBar
from pathlib import Path
runtime_storage_path = PackageStorage(tag='runtime')
class Yarn:
def __init__(self) -> None:
self.package_storage = runtime_storage_path / 'yarn'
@property
def path(self) -> str:
return self.package_storage / 'yarn.js'
async def setup(self):
with LoaderInStatusBar(f'Downloading Yarn'):
yarn_url = 'https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js'
save_to = self.package_storage / 'yarn.js'
await runtime_storage_path.download(yarn_url, save_to)
DenoVersion = Literal['2.2',]
deno_versions: list[DenoVersion] = ['2.2']
class Deno:
def __init__(self, deno_version: DenoVersion) -> None:
if deno_version not in deno_versions:
raise Exception(f'{deno_version} is not supported, please specify one of f{deno_versions}')
self.deno_version = deno_version
self.package_storage = runtime_storage_path / 'deno' / self.deno_version
@property
def path(self) -> str:
return str(self.package_storage / 'deno' / 'deno')
async def setup(self):
with LoaderInStatusBar(f'Downloading Deno {self.deno_version}'):
fetch_url, archive_filename = self._archive_on_github()
if not Path(self.path).exists():
save_to = self.package_storage / archive_filename
await runtime_storage_path.download(fetch_url, save_to)
unzip(save_to, new_name='deno')
def _archive_on_github(self) -> tuple[str, str]:
platform = sublime.platform()
arch = sublime.arch()
if platform == 'windows':
platform_code = 'pc-windows-msvc'
elif platform == 'linux':
platform_code = 'unknown-linux-gnu'
elif platform == 'osx':
platform_code = 'apple-darwin'
else:
raise Exception('{} {} is not supported'.format(arch, platform))
if arch == 'x32':
arch_code = 'x86_64' # GitHub doesn't seem to have explicit x32 builds, using x64 as a fallback or error case
elif arch == 'x64':
arch_code = 'x86_64'
elif arch == 'arm64':
arch_code = 'aarch64'
else:
raise Exception('Unsupported architecture: {}'.format(arch))
archive_filename = 'deno-{}-{}.zip'.format(arch_code, platform_code) # Using 'deno-' prefix
release_version = {
'2.2': 'v2.2.12',
}
fetch_url = 'https://github.com/denoland/deno/releases/download/{version}/{filename}'.format( # Changed URL to denoland/deno
version=release_version[self.deno_version], # Assuming self.deno_version holds the correct version tag
filename=archive_filename
)
return fetch_url, archive_filename
NodeVersion = Literal['22', '20', '18']
node_versions: list[NodeVersion] = ['22', '20', '18']
# https://www.electronjs.org/docs/latest/tutorial/electron-timelines#timeline
node_version_to_electron_version = {
'22': '35.2.0', # NodeJS 22.14
'20': '34.4.0', # NodeJS 20.18
'18': '28.0.0', # NodeJS 18.18
}
class Electron:
def __init__(self, node_version: NodeVersion) -> None:
if node_version not in node_versions:
raise Exception(f'{node_version} is not supported, please specify one of f{node_versions}')
self.node_version = node_version
self.package_storage = runtime_storage_path / 'electron_node' / self.node_version
@property
def path(self) -> str:
binary_path: str | None = None
platform = sublime.platform()
if platform == 'osx':
binary_path = str(self.package_storage / 'electron' / 'Electron.app' / 'Contents' / 'MacOS' / 'Electron')
elif platform == 'windows':
binary_path = str(self.package_storage / 'electron' / 'electron.exe')
else:
binary_path = str(self.package_storage / 'electron' / 'electron')
return binary_path
async def setup(self):
with LoaderInStatusBar(f'Downloading Node.js {self.node_version}'):
fetch_url, archive_filename = self._archive_on_github()
if not Path(self.path).exists():
save_to = self.package_storage / archive_filename
await runtime_storage_path.download(fetch_url, save_to)
unzip(save_to, new_name='electron')
def _archive_on_github(self) -> tuple[str, str]:
platform = sublime.platform()
arch = sublime.arch()
if platform == 'windows':
platform_code = 'win32'
elif platform == 'linux':
platform_code = 'linux'
elif platform == 'osx':
platform_code = 'darwin'
else:
raise Exception('{} {} is not supported'.format(arch, platform))
electron_version = node_version_to_electron_version[self.node_version]
archive_filename = 'electron-v{}-{}-{}.zip'.format(electron_version, platform_code, arch)
fetch_url = 'https://github.com/electron/electron/releases/download/v{version}/{filename}'.format(
version=electron_version,
filename=archive_filename
)
return fetch_url, archive_filename
os.environ.update({'ELECTRON_RUN_AS_NODE': 'true'})
electron_node_22 = Electron('22')
electron_node_20 = Electron('20')
electron_node_18 = Electron('18')
# electron_node is always latest
electron_node = electron_node_22
deno2_2 = Deno('2.2')
# deno is always latest
deno = deno2_2
yarn = Yarn()