UNPKG

15.5 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8function _bluebirdLst() {
9 const data = require("bluebird-lst");
10
11 _bluebirdLst = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _builderUtil() {
19 const data = require("builder-util");
20
21 _builderUtil = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _electronOsxSign() {
29 const data = require("electron-osx-sign");
30
31 _electronOsxSign = function () {
32 return data;
33 };
34
35 return data;
36}
37
38function _fsExtraP() {
39 const data = require("fs-extra-p");
40
41 _fsExtraP = function () {
42 return data;
43 };
44
45 return data;
46}
47
48function _lazyVal() {
49 const data = require("lazy-val");
50
51 _lazyVal = function () {
52 return data;
53 };
54
55 return data;
56}
57
58var path = _interopRequireWildcard(require("path"));
59
60function _fs() {
61 const data = require("builder-util/out/fs");
62
63 _fs = function () {
64 return data;
65 };
66
67 return data;
68}
69
70function _appInfo() {
71 const data = require("./appInfo");
72
73 _appInfo = function () {
74 return data;
75 };
76
77 return data;
78}
79
80function _codeSign() {
81 const data = require("./codeSign");
82
83 _codeSign = function () {
84 return data;
85 };
86
87 return data;
88}
89
90function _core() {
91 const data = require("./core");
92
93 _core = function () {
94 return data;
95 };
96
97 return data;
98}
99
100function _platformPackager() {
101 const data = require("./platformPackager");
102
103 _platformPackager = function () {
104 return data;
105 };
106
107 return data;
108}
109
110function _ArchiveTarget() {
111 const data = require("./targets/ArchiveTarget");
112
113 _ArchiveTarget = function () {
114 return data;
115 };
116
117 return data;
118}
119
120function _pkg() {
121 const data = require("./targets/pkg");
122
123 _pkg = function () {
124 return data;
125 };
126
127 return data;
128}
129
130function _targetFactory() {
131 const data = require("./targets/targetFactory");
132
133 _targetFactory = function () {
134 return data;
135 };
136
137 return data;
138}
139
140function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
141
142class MacPackager extends _platformPackager().PlatformPackager {
143 constructor(info) {
144 super(info, _core().Platform.MAC);
145 this.codeSigningInfo = new (_lazyVal().Lazy)(() => {
146 const cscLink = this.getCscLink();
147
148 if (cscLink == null || process.platform !== "darwin") {
149 return Promise.resolve({
150 keychainName: process.env.CSC_KEYCHAIN || null
151 });
152 }
153
154 return (0, _codeSign().createKeychain)({
155 tmpDir: this.info.tempDirManager,
156 cscLink,
157 cscKeyPassword: this.getCscPassword(),
158 cscILink: (0, _platformPackager().chooseNotNull)(this.platformSpecificBuildOptions.cscInstallerLink, process.env.CSC_INSTALLER_LINK),
159 cscIKeyPassword: (0, _platformPackager().chooseNotNull)(this.platformSpecificBuildOptions.cscInstallerKeyPassword, process.env.CSC_INSTALLER_KEY_PASSWORD),
160 currentDir: this.projectDir
161 });
162 });
163 this._iconPath = new (_lazyVal().Lazy)(() => this.getOrConvertIcon("icns"));
164 }
165
166 get defaultTarget() {
167 return this.info.framework.macOsDefaultTargets;
168 }
169
170 prepareAppInfo(appInfo) {
171 return new (_appInfo().AppInfo)(this.info, this.platformSpecificBuildOptions.bundleVersion);
172 }
173
174 getIconPath() {
175 var _this = this;
176
177 return (0, _bluebirdLst().coroutine)(function* () {
178 return _this._iconPath.value;
179 })();
180 }
181
182 createTargets(targets, mapper) {
183 for (const name of targets) {
184 switch (name) {
185 case _core().DIR_TARGET:
186 break;
187
188 case "dmg":
189 const {
190 DmgTarget
191 } = require("dmg-builder");
192
193 mapper(name, outDir => new DmgTarget(this, outDir));
194 break;
195
196 case "zip":
197 // https://github.com/electron-userland/electron-builder/issues/2313
198 mapper(name, outDir => new (_ArchiveTarget().ArchiveTarget)(name, outDir, this, true));
199 break;
200
201 case "pkg":
202 mapper(name, outDir => new (_pkg().PkgTarget)(this, outDir));
203 break;
204
205 default:
206 mapper(name, outDir => name === "mas" || name === "mas-dev" ? new (_targetFactory().NoOpTarget)(name) : (0, _targetFactory().createCommonTarget)(name, outDir, this));
207 break;
208 }
209 }
210 }
211
212 pack(outDir, arch, targets, taskManager) {
213 var _this2 = this;
214
215 return (0, _bluebirdLst().coroutine)(function* () {
216 let nonMasPromise = null;
217 const hasMas = targets.length !== 0 && targets.some(it => it.name === "mas" || it.name === "mas-dev");
218 const prepackaged = _this2.packagerOptions.prepackaged;
219
220 if (!hasMas || targets.length > 1) {
221 const appPath = prepackaged == null ? path.join(_this2.computeAppOutDir(outDir, arch), `${_this2.appInfo.productFilename}.app`) : prepackaged;
222 nonMasPromise = (prepackaged ? Promise.resolve() : _this2.doPack(outDir, path.dirname(appPath), _this2.platform.nodeName, arch, _this2.platformSpecificBuildOptions, targets)).then(() => _this2.sign(appPath, null, null)).then(() => _this2.packageInDistributableFormat(appPath, _builderUtil().Arch.x64, targets, taskManager));
223 }
224
225 for (const target of targets) {
226 const targetName = target.name;
227
228 if (!(targetName === "mas" || targetName === "mas-dev")) {
229 continue;
230 }
231
232 const masBuildOptions = (0, _builderUtil().deepAssign)({}, _this2.platformSpecificBuildOptions, _this2.config.mas);
233
234 if (targetName === "mas-dev") {
235 (0, _builderUtil().deepAssign)(masBuildOptions, _this2.config[targetName], {
236 type: "development"
237 });
238 }
239
240 const targetOutDir = path.join(outDir, targetName);
241
242 if (prepackaged == null) {
243 yield _this2.doPack(outDir, targetOutDir, "mas", arch, masBuildOptions, [target]);
244 yield _this2.sign(path.join(targetOutDir, `${_this2.appInfo.productFilename}.app`), targetOutDir, masBuildOptions);
245 } else {
246 yield _this2.sign(prepackaged, targetOutDir, masBuildOptions);
247 }
248 }
249
250 if (nonMasPromise != null) {
251 yield nonMasPromise;
252 }
253 })();
254 }
255
256 sign(appPath, outDir, masOptions) {
257 var _this3 = this;
258
259 return (0, _bluebirdLst().coroutine)(function* () {
260 if (!(0, _codeSign().isSignAllowed)()) {
261 return;
262 }
263
264 const isMas = masOptions != null;
265 const macOptions = _this3.platformSpecificBuildOptions;
266 const qualifier = (isMas ? masOptions.identity : null) || macOptions.identity;
267
268 if (!isMas && qualifier === null) {
269 if (_this3.forceCodeSigning) {
270 throw new (_builderUtil().InvalidConfigurationError)("identity explicitly is set to null, but forceCodeSigning is set to true");
271 }
272
273 _builderUtil().log.info({
274 reason: "identity explicitly is set to null"
275 }, "skipped macOS code signing");
276
277 return;
278 }
279
280 const keychainName = (yield _this3.codeSigningInfo.value).keychainName;
281 const explicitType = isMas ? masOptions.type : macOptions.type;
282 const type = explicitType || "distribution";
283 const isDevelopment = type === "development";
284 const certificateType = getCertificateType(isMas, isDevelopment);
285 let identity = yield (0, _codeSign().findIdentity)(certificateType, qualifier, keychainName);
286
287 if (identity == null) {
288 if (!isMas && !isDevelopment && explicitType !== "distribution") {
289 identity = yield (0, _codeSign().findIdentity)("Mac Developer", qualifier, keychainName);
290
291 if (identity != null) {
292 _builderUtil().log.warn("Mac Developer is used to sign app — it is only for development and testing, not for production");
293 }
294 }
295
296 if (identity == null) {
297 yield (0, _codeSign().reportError)(isMas, certificateType, qualifier, keychainName, _this3.forceCodeSigning);
298 return;
299 }
300 }
301
302 const signOptions = {
303 "identity-validation": false,
304 // https://github.com/electron-userland/electron-builder/issues/1699
305 // kext are signed by the chipset manufacturers. You need a special certificate (only available on request) from Apple to be able to sign kext.
306 ignore: file => {
307 return file.endsWith(".kext") || file.startsWith("/Contents/PlugIns", appPath.length) || // https://github.com/electron-userland/electron-builder/issues/2010
308 file.includes("/node_modules/puppeteer/.local-chromium");
309 },
310 identity: identity,
311 type,
312 platform: isMas ? "mas" : "darwin",
313 version: _this3.config.electronVersion,
314 app: appPath,
315 keychain: keychainName || undefined,
316 binaries: (isMas && masOptions != null ? masOptions.binaries : macOptions.binaries) || undefined,
317 requirements: isMas || macOptions.requirements == null ? undefined : yield _this3.getResource(macOptions.requirements),
318 "gatekeeper-assess": _codeSign().appleCertificatePrefixes.find(it => identity.name.startsWith(it)) != null
319 };
320 yield _this3.adjustSignOptions(signOptions, masOptions);
321
322 _builderUtil().log.info({
323 file: _builderUtil().log.filePath(appPath),
324 identityName: identity.name,
325 identityHash: identity.hash,
326 provisioningProfile: signOptions["provisioning-profile"] || "none"
327 }, "signing");
328
329 yield _this3.doSign(signOptions); // https://github.com/electron-userland/electron-builder/issues/1196#issuecomment-312310209
330
331 if (masOptions != null && !isDevelopment) {
332 const certType = isDevelopment ? "Mac Developer" : "3rd Party Mac Developer Installer";
333 const masInstallerIdentity = yield (0, _codeSign().findIdentity)(certType, masOptions.identity, keychainName);
334
335 if (masInstallerIdentity == null) {
336 throw new (_builderUtil().InvalidConfigurationError)(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://electron.build/code-signing`);
337 }
338
339 const artifactName = _this3.expandArtifactNamePattern(masOptions, "pkg");
340
341 const artifactPath = path.join(outDir, artifactName);
342 yield _this3.doFlat(appPath, artifactPath, masInstallerIdentity, keychainName);
343
344 _this3.dispatchArtifactCreated(artifactPath, null, _builderUtil().Arch.x64, _this3.computeSafeArtifactName(artifactName, "pkg"));
345 }
346 })();
347 }
348
349 adjustSignOptions(signOptions, masOptions) {
350 var _this4 = this;
351
352 return (0, _bluebirdLst().coroutine)(function* () {
353 const resourceList = yield _this4.resourceList;
354
355 if (resourceList.includes(`entitlements.osx.plist`)) {
356 throw new (_builderUtil().InvalidConfigurationError)("entitlements.osx.plist is deprecated name, please use entitlements.mac.plist");
357 }
358
359 if (resourceList.includes(`entitlements.osx.inherit.plist`)) {
360 throw new (_builderUtil().InvalidConfigurationError)("entitlements.osx.inherit.plist is deprecated name, please use entitlements.mac.inherit.plist");
361 }
362
363 const customSignOptions = masOptions || _this4.platformSpecificBuildOptions;
364 const entitlementsSuffix = masOptions == null ? "mac" : "mas";
365
366 if (customSignOptions.entitlements == null) {
367 const p = `entitlements.${entitlementsSuffix}.plist`;
368
369 if (resourceList.includes(p)) {
370 signOptions.entitlements = path.join(_this4.info.buildResourcesDir, p);
371 }
372 } else {
373 signOptions.entitlements = customSignOptions.entitlements;
374 }
375
376 if (customSignOptions.entitlementsInherit == null) {
377 const p = `entitlements.${entitlementsSuffix}.inherit.plist`;
378
379 if (resourceList.includes(p)) {
380 signOptions["entitlements-inherit"] = path.join(_this4.info.buildResourcesDir, p);
381 }
382 } else {
383 signOptions["entitlements-inherit"] = customSignOptions.entitlementsInherit;
384 }
385
386 if (customSignOptions.provisioningProfile != null) {
387 signOptions["provisioning-profile"] = customSignOptions.provisioningProfile;
388 }
389 })();
390 } //noinspection JSMethodCanBeStatic
391
392
393 doSign(opts) {
394 return (0, _bluebirdLst().coroutine)(function* () {
395 return (0, _electronOsxSign().signAsync)(opts);
396 })();
397 } //noinspection JSMethodCanBeStatic
398
399
400 doFlat(appPath, outFile, identity, keychain) {
401 return (0, _bluebirdLst().coroutine)(function* () {
402 // productbuild doesn't created directory for out file
403 yield (0, _fsExtraP().ensureDir)(path.dirname(outFile));
404 const args = (0, _pkg().prepareProductBuildArgs)(identity, keychain);
405 args.push("--component", appPath, "/Applications");
406 args.push(outFile);
407 return yield (0, _builderUtil().exec)("productbuild", args);
408 })();
409 }
410
411 getElectronSrcDir(dist) {
412 return path.resolve(this.projectDir, dist, this.info.framework.distMacOsAppName);
413 }
414
415 getElectronDestinationDir(appOutDir) {
416 return path.join(appOutDir, this.info.framework.distMacOsAppName);
417 } // todo fileAssociations
418
419
420 applyCommonInfo(appPlist, contentsPath) {
421 var _this5 = this;
422
423 return (0, _bluebirdLst().coroutine)(function* () {
424 const appInfo = _this5.appInfo;
425 const appFilename = appInfo.productFilename; // https://github.com/electron-userland/electron-builder/issues/1278
426
427 appPlist.CFBundleExecutable = appFilename.endsWith(" Helper") ? appFilename.substring(0, appFilename.length - " Helper".length) : appFilename;
428 const icon = yield _this5.getIconPath();
429
430 if (icon != null) {
431 const oldIcon = appPlist.CFBundleIconFile;
432 const resourcesPath = path.join(contentsPath, "Resources");
433
434 if (oldIcon != null) {
435 yield (0, _fs().unlinkIfExists)(path.join(resourcesPath, oldIcon));
436 }
437
438 const iconFileName = `${appFilename}.icns`;
439 appPlist.CFBundleIconFile = iconFileName;
440 yield (0, _fs().copyFile)(icon, path.join(resourcesPath, iconFileName));
441 }
442
443 appPlist.CFBundleName = appInfo.productName;
444 appPlist.CFBundleDisplayName = appInfo.productName;
445 const minimumSystemVersion = _this5.platformSpecificBuildOptions.minimumSystemVersion;
446
447 if (minimumSystemVersion != null) {
448 appPlist.LSMinimumSystemVersion = minimumSystemVersion;
449 }
450
451 appPlist.CFBundleIdentifier = appInfo.macBundleIdentifier;
452 appPlist.CFBundleShortVersionString = _this5.platformSpecificBuildOptions.bundleShortVersion || appInfo.version;
453 appPlist.CFBundleVersion = appInfo.buildVersion;
454 (0, _builderUtil().use)(_this5.platformSpecificBuildOptions.category || _this5.config.category, it => appPlist.LSApplicationCategoryType = it);
455 appPlist.NSHumanReadableCopyright = appInfo.copyright;
456 const extendInfo = _this5.platformSpecificBuildOptions.extendInfo;
457
458 if (extendInfo != null) {
459 Object.assign(appPlist, extendInfo);
460 }
461 })();
462 }
463
464}
465
466exports.default = MacPackager;
467
468function getCertificateType(isMas, isDevelopment) {
469 if (isDevelopment) {
470 return "Mac Developer";
471 }
472
473 return isMas ? "3rd Party Mac Developer Application" : "Developer ID Application";
474}
475//# sourceMappingURL=macPackager.js.map
\No newline at end of file