-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtargets.ts
209 lines (184 loc) · 5.19 KB
/
targets.ts
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import { warning } from './common';
import { getHostArch } from '@electron/get';
import semver from 'semver';
import {
IgnoreFunc,
OfficialPlatform,
Options,
SupportedArch,
SupportedPlatform,
} from './types';
export const officialArchs = [
'ia32',
'x64',
'armv7l',
'arm64',
'mips64el',
'universal',
];
export const officialPlatforms = ['darwin', 'linux', 'mas', 'win32'];
export const officialPlatformArchCombos = {
darwin: ['x64', 'arm64', 'universal'],
linux: ['ia32', 'x64', 'armv7l', 'arm64', 'mips64el'],
mas: ['x64', 'arm64', 'universal'],
win32: ['ia32', 'x64', 'arm64'],
} as Record<SupportedPlatform, SupportedArch[]>;
const buildVersions = {
darwin: {
arm64: '>= 11.0.0-beta.1',
universal: '>= 11.0.0-beta.1',
},
linux: {
arm64: '>= 1.8.0',
ia32: '<19.0.0-beta.1',
mips64el: '^1.8.2-beta.5',
},
mas: {
arm64: '>= 11.0.0-beta.1',
universal: '>= 11.0.0-beta.1',
},
win32: {
arm64: '>= 6.0.8',
},
} as Record<SupportedPlatform, Record<SupportedArch, string>>;
// Maps to module filename for each platform (lazy-required if used)
export const osModules: Record<OfficialPlatform, string> = {
darwin: './mac',
linux: './linux',
mas: './mac', // map to darwin
win32: './win32',
};
export const supported = {
arch: new Set(officialArchs),
platform: new Set(officialPlatforms),
};
export function createPlatformArchPairs(
opts: Options,
selectedPlatforms: SupportedPlatform[],
selectedArchs: SupportedArch[],
ignoreFunc?: IgnoreFunc,
) {
const combinations: Array<[SupportedPlatform, SupportedArch]> = [];
for (const arch of selectedArchs) {
for (const platform of selectedPlatforms) {
if (usingOfficialElectronPackages(opts)) {
if (!validOfficialPlatformArch(platform, arch)) {
warnIfAllNotSpecified(
opts,
`The platform/arch combination ${platform}/${arch} is not currently supported by Electron Packager`,
);
continue;
} else if (buildVersions[platform] && buildVersions[platform][arch]) {
const buildVersion = buildVersions[platform][arch];
if (buildVersion && !officialBuildExists(opts, buildVersion)) {
warnIfAllNotSpecified(
opts,
`Official ${platform}/${arch} support only exists in Electron ${buildVersion}`,
);
continue;
}
}
if (typeof ignoreFunc === 'function' && ignoreFunc(platform, arch)) {
continue;
}
}
combinations.push([platform, arch]);
}
}
return combinations;
}
function unsupportedListOption(
name: keyof typeof supported,
value: unknown,
supportedValues: Set<string>,
) {
return new Error(
`Unsupported ${name}=${value} (${typeof value}); must be a string matching: ${Array.from(
supportedValues.values(),
).join(', ')}`,
);
}
function usingOfficialElectronPackages(opts: Options) {
return (
!opts.download ||
!Object.prototype.hasOwnProperty.call(opts.download, 'mirrorOptions')
);
}
function validOfficialPlatformArch(
platform: SupportedPlatform,
arch: SupportedArch,
) {
return (
officialPlatformArchCombos[platform] &&
officialPlatformArchCombos[platform].includes(arch)
);
}
function officialBuildExists(
opts: Pick<Options, 'electronVersion'>,
buildVersion: string,
) {
return semver.satisfies(opts.electronVersion!, buildVersion, {
includePrerelease: true,
});
}
function allPlatformsOrArchsSpecified(opts: Options) {
return opts.all || opts.arch === 'all' || opts.platform === 'all';
}
function warnIfAllNotSpecified(opts: Options, message: string) {
if (!allPlatformsOrArchsSpecified(opts)) {
warning(message, opts.quiet);
}
}
export function allOfficialArchsForPlatformAndVersion(
platform: SupportedPlatform,
electronVersion: Options['electronVersion'],
) {
const archs = officialPlatformArchCombos[platform];
if (buildVersions[platform]) {
const excludedArchs = (
Object.keys(buildVersions[platform]) as SupportedArch[]
).filter(
(arch) =>
!officialBuildExists(
{ electronVersion: electronVersion },
buildVersions[platform][arch],
),
);
return archs.filter((arch) => !excludedArchs.includes(arch));
}
return archs;
}
// Validates list of architectures or platforms.
// Returns a normalized array if successful, or throws an Error.
export function validateListFromOptions(
opts: Options,
name: keyof typeof supported,
) {
if (opts.all) {
return Array.from(supported[name].values());
}
let list = opts[name];
if (!list) {
if (name === 'arch') {
list = getHostArch();
} else {
list = process[name];
}
} else if (list === 'all') {
return Array.from(supported[name].values());
}
if (!Array.isArray(list)) {
if (typeof list === 'string') {
list = list.split(/,\s*/);
} else {
return unsupportedListOption(name, list, supported[name]);
}
}
const officialElectronPackages = usingOfficialElectronPackages(opts);
for (const value of list) {
if (officialElectronPackages && !supported[name].has(value)) {
return unsupportedListOption(name, value, supported[name]);
}
}
return list;
}