app-builder-lib 26.12.0 → 26.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/out/asar/asarFileChecker.d.ts +2 -2
  2. package/out/asar/asarFileChecker.js +3 -2
  3. package/out/asar/asarFileChecker.js.map +1 -1
  4. package/out/asar/asarUtil.js +3 -2
  5. package/out/asar/asarUtil.js.map +1 -1
  6. package/out/binDownload.js +36 -9
  7. package/out/binDownload.js.map +1 -1
  8. package/out/codeSign/certInfo.d.ts +54 -0
  9. package/out/codeSign/certInfo.js +466 -0
  10. package/out/codeSign/certInfo.js.map +1 -0
  11. package/out/codeSign/macCodeSign.d.ts +1 -1
  12. package/out/codeSign/macCodeSign.js +10 -9
  13. package/out/codeSign/macCodeSign.js.map +1 -1
  14. package/out/codeSign/windowsSignToolManager.js +3 -9
  15. package/out/codeSign/windowsSignToolManager.js.map +1 -1
  16. package/out/configuration.d.ts +5 -0
  17. package/out/configuration.js.map +1 -1
  18. package/out/electron/ElectronFramework.js +4 -1
  19. package/out/electron/ElectronFramework.js.map +1 -1
  20. package/out/electron/electronVersion.js +9 -4
  21. package/out/electron/electronVersion.js.map +1 -1
  22. package/out/fileTransformer.js +2 -1
  23. package/out/fileTransformer.js.map +1 -1
  24. package/out/forge-maker.js +6 -2
  25. package/out/forge-maker.js.map +1 -1
  26. package/out/mac/MacTargetHelper.d.ts +24 -0
  27. package/out/mac/MacTargetHelper.js +269 -0
  28. package/out/mac/MacTargetHelper.js.map +1 -0
  29. package/out/macPackager.d.ts +21 -7
  30. package/out/macPackager.js +219 -346
  31. package/out/macPackager.js.map +1 -1
  32. package/out/node-module-collector/moduleManager.d.ts +12 -2
  33. package/out/node-module-collector/moduleManager.js +3 -0
  34. package/out/node-module-collector/moduleManager.js.map +1 -1
  35. package/out/options/linuxOptions.d.ts +4 -3
  36. package/out/options/linuxOptions.js.map +1 -1
  37. package/out/options/macOptions.d.ts +6 -0
  38. package/out/options/macOptions.js.map +1 -1
  39. package/out/options/metadata.d.ts +2 -0
  40. package/out/options/metadata.js.map +1 -1
  41. package/out/packager.js +4 -4
  42. package/out/packager.js.map +1 -1
  43. package/out/platformPackager.d.ts +1 -1
  44. package/out/platformPackager.js +27 -21
  45. package/out/platformPackager.js.map +1 -1
  46. package/out/targets/AppxTarget.js +2 -1
  47. package/out/targets/AppxTarget.js.map +1 -1
  48. package/out/targets/FlatpakTarget.js +2 -4
  49. package/out/targets/FlatpakTarget.js.map +1 -1
  50. package/out/targets/FpmTarget.js +30 -6
  51. package/out/targets/FpmTarget.js.map +1 -1
  52. package/out/targets/LinuxTargetHelper.d.ts +1 -1
  53. package/out/targets/LinuxTargetHelper.js +79 -14
  54. package/out/targets/LinuxTargetHelper.js.map +1 -1
  55. package/out/targets/MsiTarget.js +1 -1
  56. package/out/targets/MsiTarget.js.map +1 -1
  57. package/out/targets/MsiWrappedTarget.js +1 -1
  58. package/out/targets/MsiWrappedTarget.js.map +1 -1
  59. package/out/targets/appimage/AppImageTarget.d.ts +0 -2
  60. package/out/targets/appimage/AppImageTarget.js +27 -42
  61. package/out/targets/appimage/AppImageTarget.js.map +1 -1
  62. package/out/targets/appimage/appImageUtil.d.ts +3 -1
  63. package/out/targets/appimage/appImageUtil.js +33 -0
  64. package/out/targets/appimage/appImageUtil.js.map +1 -1
  65. package/out/targets/nsis/NsisTarget.js +15 -5
  66. package/out/targets/nsis/NsisTarget.js.map +1 -1
  67. package/out/targets/nsis/WebInstallerTarget.js +2 -2
  68. package/out/targets/nsis/WebInstallerTarget.js.map +1 -1
  69. package/out/targets/nsis/nsisScriptGenerator.js +2 -3
  70. package/out/targets/nsis/nsisScriptGenerator.js.map +1 -1
  71. package/out/targets/pkg.js +1 -1
  72. package/out/targets/pkg.js.map +1 -1
  73. package/out/targets/snap/SnapTarget.js +2 -1
  74. package/out/targets/snap/SnapTarget.js.map +1 -1
  75. package/out/targets/snap/core24.js +5 -4
  76. package/out/targets/snap/core24.js.map +1 -1
  77. package/out/targets/snap/coreLegacy.js +5 -5
  78. package/out/targets/snap/coreLegacy.js.map +1 -1
  79. package/out/targets/snap/snapcraftBuilder.js +4 -3
  80. package/out/targets/snap/snapcraftBuilder.js.map +1 -1
  81. package/out/toolsets/linux.d.ts +3 -1
  82. package/out/toolsets/linux.js +49 -21
  83. package/out/toolsets/linux.js.map +1 -1
  84. package/out/toolsets/windows.js +7 -17
  85. package/out/toolsets/windows.js.map +1 -1
  86. package/out/util/bundledTool.js +2 -1
  87. package/out/util/bundledTool.js.map +1 -1
  88. package/out/util/config/config.js +4 -3
  89. package/out/util/config/config.js.map +1 -1
  90. package/out/util/dynamicImport.d.ts +1 -0
  91. package/out/util/dynamicImport.js +14 -0
  92. package/out/util/dynamicImport.js.map +1 -0
  93. package/out/util/electronGet.d.ts +2 -0
  94. package/out/util/electronGet.js +38 -2
  95. package/out/util/electronGet.js.map +1 -1
  96. package/out/util/packageMetadata.js +2 -1
  97. package/out/util/packageMetadata.js.map +1 -1
  98. package/out/util/rebuild.d.ts +1 -1
  99. package/out/util/rebuild.js.map +1 -1
  100. package/out/util/yarn.js +1 -1
  101. package/out/util/yarn.js.map +1 -1
  102. package/out/version.d.ts +1 -1
  103. package/out/version.js +1 -1
  104. package/out/version.js.map +1 -1
  105. package/package.json +11 -8
  106. package/scheme.json +22 -1
  107. package/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +5 -5
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MacPackager = void 0;
4
- const notarize_1 = require("@electron/notarize");
5
- const util_identities_1 = require("@electron/osx-sign/dist/cjs/util-identities");
6
4
  const builder_util_1 = require("builder-util");
7
5
  const builder_util_runtime_1 = require("builder-util-runtime");
8
6
  const fs = require("fs/promises");
@@ -12,15 +10,15 @@ const path = require("path");
12
10
  const appInfo_1 = require("./appInfo");
13
11
  const macCodeSign_1 = require("./codeSign/macCodeSign");
14
12
  const core_1 = require("./core");
13
+ const MacTargetHelper_1 = require("./mac/MacTargetHelper");
15
14
  const platformPackager_1 = require("./platformPackager");
16
15
  const ArchiveTarget_1 = require("./targets/ArchiveTarget");
17
16
  const pkg_1 = require("./targets/pkg");
18
17
  const targetFactory_1 = require("./targets/targetFactory");
18
+ const dynamicImport_1 = require("./util/dynamicImport");
19
19
  const macosVersion_1 = require("./util/macosVersion");
20
- const pathManager_1 = require("./util/pathManager");
21
- const resolve_1 = require("./util/resolve");
22
20
  const macroExpander_1 = require("./util/macroExpander");
23
- const universal_1 = require("@electron/universal");
21
+ const resolve_1 = require("./util/resolve");
24
22
  class MacPackager extends platformPackager_1.PlatformPackager {
25
23
  constructor(info) {
26
24
  super(info, core_1.Platform.MAC);
@@ -51,10 +49,43 @@ class MacPackager extends platformPackager_1.PlatformPackager {
51
49
  return Promise.resolve({ keychainFile: process.env.CSC_KEYCHAIN || null });
52
50
  });
53
51
  this._iconPath = new lazy_val_1.Lazy(() => this.getOrConvertIcon("icns"));
52
+ // Set/cleared in doPack so applyCommonInfo can read the per-pack platformSpecificBuildOptions
53
+ // (the framework call chain doesn't thread it through to applyCommonInfo). Fixes #8909.
54
+ this._activePackConfig = null;
55
+ this.helper = new MacTargetHelper_1.MacTargetHelper(this);
54
56
  }
55
57
  get defaultTarget() {
56
58
  return this.info.framework.macOsDefaultTargets;
57
59
  }
60
+ /**
61
+ * Get the merged configuration for a specific platform type
62
+ */
63
+ getPlatformConfig(platformType) {
64
+ let config;
65
+ let isDevelopment = false;
66
+ let platformName;
67
+ switch (platformType) {
68
+ case "mas":
69
+ config = (0, builder_util_1.deepAssign)({}, this.platformSpecificBuildOptions, this.config.mas);
70
+ isDevelopment = false;
71
+ platformName = "mas";
72
+ break;
73
+ case "mas-dev":
74
+ config = (0, builder_util_1.deepAssign)({}, this.platformSpecificBuildOptions, this.config.mas, this.config.masDev, {
75
+ type: "development",
76
+ });
77
+ isDevelopment = true;
78
+ platformName = "mas";
79
+ break;
80
+ case "mac":
81
+ default:
82
+ config = this.platformSpecificBuildOptions;
83
+ isDevelopment = false;
84
+ platformName = this.platform.nodeName;
85
+ break;
86
+ }
87
+ return { type: platformType, config, isDevelopment, platformName };
88
+ }
58
89
  expandArch(pattern, arch) {
59
90
  if (arch === builder_util_1.Arch.universal) {
60
91
  // Universal build has `app-x64.asar.unpacked` & `app-arm64.asar.unpacked`
@@ -89,318 +120,206 @@ class MacPackager extends platformPackager_1.PlatformPackager {
89
120
  mapper(name, outDir => new pkg_1.PkgTarget(this, outDir));
90
121
  break;
91
122
  default:
92
- mapper(name, outDir => (name === "mas" || name === "mas-dev" ? new targetFactory_1.NoOpTarget(name) : (0, targetFactory_1.createCommonTarget)(name, outDir, this)));
123
+ mapper(name, outDir => (MacTargetHelper_1.MacTargetHelper.isMasTarget(name) ? new targetFactory_1.NoOpTarget(name) : (0, targetFactory_1.createCommonTarget)(name, outDir, this)));
93
124
  break;
94
125
  }
95
126
  }
96
127
  }
97
128
  async doPack(config) {
98
- var _a;
99
- const { outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets } = config;
100
- switch (arch) {
101
- default: {
102
- return super.doPack(config);
103
- }
104
- case builder_util_1.Arch.universal: {
105
- const outDirName = (arch) => `${appOutDir}-${builder_util_1.Arch[arch]}-temp`;
106
- const options = {
107
- ...config,
108
- options: {
109
- sign: false,
110
- disableAsarIntegrity: true,
111
- disableFuses: true,
112
- },
113
- };
114
- const x64Arch = builder_util_1.Arch.x64;
115
- const x64AppOutDir = outDirName(x64Arch);
116
- await super.doPack({ ...options, appOutDir: x64AppOutDir, arch: x64Arch });
117
- if (this.info.cancellationToken.cancelled) {
118
- return;
119
- }
120
- const arm64Arch = builder_util_1.Arch.arm64;
121
- const arm64AppOutPath = outDirName(arm64Arch);
122
- await super.doPack({ ...options, appOutDir: arm64AppOutPath, arch: arm64Arch });
123
- if (this.info.cancellationToken.cancelled) {
124
- return;
125
- }
126
- const framework = this.info.framework;
127
- builder_util_1.log.info({
128
- platform: platformName,
129
- arch: builder_util_1.Arch[arch],
130
- [`${framework.name}`]: framework.version,
131
- appOutDir: builder_util_1.log.filePath(appOutDir),
132
- }, `packaging`);
133
- const appFile = `${this.appInfo.productFilename}.app`;
134
- // Make sure the Assets.car file is the same for both architectures
135
- const sourceCatalogPath = path.join(x64AppOutDir, appFile, "Contents/Resources/Assets.car");
136
- if (await (0, builder_util_1.exists)(sourceCatalogPath)) {
137
- const targetCatalogPath = path.join(arm64AppOutPath, appFile, "Contents/Resources/Assets.car");
138
- await fs.copyFile(sourceCatalogPath, targetCatalogPath);
139
- }
140
- await (0, universal_1.makeUniversalApp)({
141
- x64AppPath: path.join(x64AppOutDir, appFile),
142
- arm64AppPath: path.join(arm64AppOutPath, appFile),
143
- outAppPath: path.join(appOutDir, appFile),
144
- force: true,
145
- mergeASARs: (_a = platformSpecificBuildOptions.mergeASARs) !== null && _a !== void 0 ? _a : true, // must be ?? to allow false
146
- singleArchFiles: platformSpecificBuildOptions.singleArchFiles || undefined,
147
- x64ArchFiles: platformSpecificBuildOptions.x64ArchFiles || undefined,
148
- });
149
- await fs.rm(x64AppOutDir, { recursive: true, force: true });
150
- await fs.rm(arm64AppOutPath, { recursive: true, force: true });
151
- // Give users a final opportunity to perform things on the combined universal package before signing
152
- const packContext = {
153
- appOutDir,
154
- outDir,
155
- arch,
156
- targets,
157
- packager: this,
158
- electronPlatformName: platformName,
159
- };
160
- await this.info.emitAfterPack(packContext);
161
- if (this.info.cancellationToken.cancelled) {
162
- return;
163
- }
164
- await this.doAddElectronFuses(packContext);
129
+ if (config.arch === builder_util_1.Arch.universal) {
130
+ return this.doUniversalPack(config);
131
+ }
132
+ // Bridge the per-pack platformSpecificBuildOptions to applyCommonInfo, which is called deep in the
133
+ // framework stack (doPack → beforeCopyExtraFiles → createMacApp → applyCommonInfo) without it.
134
+ this._activePackConfig = config.platformSpecificBuildOptions;
135
+ try {
136
+ return await super.doPack(config);
137
+ }
138
+ finally {
139
+ this._activePackConfig = null;
140
+ }
141
+ }
142
+ /**
143
+ * Handle universal build packing
144
+ */
145
+ async doUniversalPack(config) {
146
+ var _a, _b, _c;
147
+ this._activePackConfig = config.platformSpecificBuildOptions;
148
+ try {
149
+ const { outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets } = config;
150
+ const outDirName = (arch) => `${appOutDir}-${builder_util_1.Arch[arch]}-temp`;
151
+ const options = {
152
+ ...config,
153
+ options: {
154
+ sign: false,
155
+ disableAsarIntegrity: true,
156
+ disableFuses: true,
157
+ },
158
+ };
159
+ const x64Arch = builder_util_1.Arch.x64;
160
+ const x64AppOutDir = outDirName(x64Arch);
161
+ await super.doPack({ ...options, appOutDir: x64AppOutDir, arch: x64Arch });
162
+ if (this.info.cancellationToken.cancelled) {
163
+ return;
164
+ }
165
+ const arm64Arch = builder_util_1.Arch.arm64;
166
+ const arm64AppOutPath = outDirName(arm64Arch);
167
+ await super.doPack({ ...options, appOutDir: arm64AppOutPath, arch: arm64Arch });
168
+ if (this.info.cancellationToken.cancelled) {
169
+ return;
170
+ }
171
+ const framework = this.info.framework;
172
+ builder_util_1.log.info({
173
+ platform: platformName,
174
+ arch: builder_util_1.Arch[arch],
175
+ [`${framework.name}`]: framework.version,
176
+ appOutDir: builder_util_1.log.filePath(appOutDir),
177
+ }, `packaging`);
178
+ const appFile = `${this.appInfo.productFilename}.app`;
179
+ // Make sure the Assets.car file is the same for both architectures
180
+ const safeX64AppOutDir = (0, builder_util_1.sanitizeDirPath)(x64AppOutDir);
181
+ const safeArm64AppOutPath = (0, builder_util_1.sanitizeDirPath)(arm64AppOutPath);
182
+ const safeAppOutDir = (0, builder_util_1.sanitizeDirPath)(appOutDir);
183
+ const sourceCatalogPath = path.join(safeX64AppOutDir, appFile, "Contents/Resources/Assets.car");
184
+ if (await (0, builder_util_1.exists)(sourceCatalogPath)) {
185
+ const targetCatalogPath = path.join(safeArm64AppOutPath, appFile, "Contents/Resources/Assets.car");
186
+ await fs.copyFile(sourceCatalogPath, targetCatalogPath);
187
+ }
188
+ const { makeUniversalApp } = await (0, dynamicImport_1.dynamicImport)("@electron/universal");
189
+ await makeUniversalApp({
190
+ x64AppPath: path.join(safeX64AppOutDir, appFile),
191
+ arm64AppPath: path.join(safeArm64AppOutPath, appFile),
192
+ outAppPath: path.join(safeAppOutDir, appFile),
193
+ force: true,
194
+ mergeASARs: (_a = platformSpecificBuildOptions.mergeASARs) !== null && _a !== void 0 ? _a : true, // must be ?? to allow false
195
+ singleArchFiles: platformSpecificBuildOptions.singleArchFiles || undefined,
196
+ x64ArchFiles: platformSpecificBuildOptions.x64ArchFiles || undefined,
197
+ });
198
+ await fs.rm(x64AppOutDir, { recursive: true, force: true });
199
+ await fs.rm(arm64AppOutPath, { recursive: true, force: true });
200
+ // Give users a final opportunity to perform things on the combined universal package before signing
201
+ const packContext = {
202
+ appOutDir,
203
+ outDir,
204
+ arch,
205
+ targets,
206
+ packager: this,
207
+ electronPlatformName: platformName,
208
+ };
209
+ await this.info.emitAfterPack(packContext);
210
+ if (this.info.cancellationToken.cancelled) {
211
+ return;
212
+ }
213
+ await this.doAddElectronFuses(packContext);
214
+ // Mirror the base-class guard: skip signing when the caller explicitly set sign:false
215
+ // (e.g. packMasTargets passes sign:false so that signMas() is the sole signing step).
216
+ if ((_c = (_b = config.options) === null || _b === void 0 ? void 0 : _b.sign) !== null && _c !== void 0 ? _c : true) {
165
217
  await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets);
166
- break;
167
218
  }
168
219
  }
220
+ finally {
221
+ this._activePackConfig = null;
222
+ }
169
223
  }
170
224
  async pack(outDir, arch, targets, taskManager) {
171
- const hasMas = targets.length !== 0 && targets.some(it => it.name === "mas" || it.name === "mas-dev");
225
+ const masTargets = targets.filter(it => MacTargetHelper_1.MacTargetHelper.isMasTarget(it.name));
226
+ const nonMasTargets = targets.filter(it => !MacTargetHelper_1.MacTargetHelper.isMasTarget(it.name));
172
227
  const prepackaged = this.packagerOptions.prepackaged;
228
+ const hasMas = masTargets.length > 0;
229
+ // mas always first
230
+ await this.packMasTargets(outDir, arch, masTargets, prepackaged);
231
+ // Mirror master's condition: skip the non-MAS darwin pack only when there are exclusively MAS
232
+ // targets (hasMas=true, targets.length=1). DIR_TARGET passes targets=[] to pack() because
233
+ // MacPackager.createTargets() doesn't call mapper() for it, so hasMas=false and doPack still runs.
234
+ if (!hasMas || targets.length > 1) {
235
+ await this.packMacTargets(outDir, arch, nonMasTargets, prepackaged, taskManager);
236
+ }
237
+ }
238
+ async packMasTargets(outDir, arch, targets, prepackaged) {
239
+ const resolvedOutDir = path.resolve(outDir);
240
+ MacTargetHelper_1.MacTargetHelper.assertSafePathForCommandUsage(resolvedOutDir, "output directory");
173
241
  for (const target of targets) {
174
- const targetName = target.name;
175
- if (!(targetName === "mas" || targetName === "mas-dev")) {
176
- continue;
177
- }
178
- const masBuildOptions = (0, builder_util_1.deepAssign)({}, this.platformSpecificBuildOptions, this.config.mas);
179
- if (targetName === "mas-dev") {
180
- (0, builder_util_1.deepAssign)(masBuildOptions, this.config.masDev, {
181
- type: "development",
182
- });
242
+ const platformType = MacTargetHelper_1.MacTargetHelper.getPlatformTypeFromTarget(target.name);
243
+ const platformConfig = this.getPlatformConfig(platformType);
244
+ const targetOutDir = path.resolve(resolvedOutDir, `${target.name}${(0, builder_util_1.getArchSuffix)(arch, this.platformSpecificBuildOptions.defaultArch)}`);
245
+ MacTargetHelper_1.MacTargetHelper.assertSafePathForCommandUsage(targetOutDir, "target output directory");
246
+ const relativeTargetOutDir = path.relative(resolvedOutDir, targetOutDir);
247
+ if (relativeTargetOutDir.startsWith("..") || path.isAbsolute(relativeTargetOutDir)) {
248
+ throw new builder_util_1.InvalidConfigurationError(`Invalid target output directory: ${targetOutDir}`);
183
249
  }
184
- const targetOutDir = path.join(outDir, `${targetName}${(0, builder_util_1.getArchSuffix)(arch, this.platformSpecificBuildOptions.defaultArch)}`);
185
- if (prepackaged == null) {
186
- await this.doPack({ outDir, appOutDir: targetOutDir, platformName: "mas", arch, platformSpecificBuildOptions: masBuildOptions, targets: [target] });
187
- await this.sign(path.join(targetOutDir, `${this.appInfo.productFilename}.app`), targetOutDir, masBuildOptions, arch);
188
- }
189
- else {
190
- await this.sign(prepackaged, targetOutDir, masBuildOptions, arch);
191
- }
192
- }
193
- if (!hasMas || targets.length > 1) {
194
- const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${this.appInfo.productFilename}.app`) : prepackaged;
195
250
  if (prepackaged == null) {
196
251
  await this.doPack({
197
- outDir,
198
- appOutDir: path.dirname(appPath),
199
- platformName: this.platform.nodeName,
252
+ outDir: resolvedOutDir,
253
+ appOutDir: targetOutDir,
254
+ platformName: platformConfig.platformName,
200
255
  arch,
201
- platformSpecificBuildOptions: this.platformSpecificBuildOptions,
202
- targets,
256
+ platformSpecificBuildOptions: platformConfig.config,
257
+ targets: [target],
258
+ options: { sign: false },
203
259
  });
260
+ MacTargetHelper_1.MacTargetHelper.assertSafePathForCommandUsage(this.appInfo.productFilename, "product filename");
261
+ await this.signMas(path.resolve(targetOutDir, `${path.basename(this.appInfo.productFilename)}.app`), targetOutDir, platformConfig, arch);
204
262
  }
205
- this.packageInDistributableFormat(appPath, arch, targets, taskManager);
263
+ else {
264
+ await this.signMas(prepackaged, targetOutDir, platformConfig, arch);
265
+ }
266
+ }
267
+ }
268
+ async packMacTargets(outDir, arch, targets, prepackaged, taskManager) {
269
+ const appPath = prepackaged == null ? path.join(this.computeAppOutDir(outDir, arch), `${path.basename(this.appInfo.productFilename)}.app`) : prepackaged;
270
+ if (prepackaged == null) {
271
+ const platformConfig = this.getPlatformConfig("mac");
272
+ await this.doPack({
273
+ outDir,
274
+ appOutDir: path.dirname(appPath),
275
+ platformName: platformConfig.platformName,
276
+ arch,
277
+ platformSpecificBuildOptions: platformConfig.config,
278
+ targets,
279
+ });
206
280
  }
281
+ this.packageInDistributableFormat(appPath, arch, targets, taskManager);
282
+ }
283
+ async signMas(appPath, outDir, platformConfig, arch) {
284
+ const signed = await this.sign(appPath, outDir, platformConfig.config, arch, true);
285
+ return signed;
207
286
  }
208
- async sign(appPath, outDir, masOptions, arch) {
287
+ /**
288
+ * Main signing method with platform awareness
289
+ */
290
+ async sign(appPath, outDir, options, arch, isMas = false) {
209
291
  if (!(0, macCodeSign_1.isSignAllowed)()) {
210
292
  return false;
211
293
  }
212
- const isMas = masOptions != null;
213
- const options = masOptions == null ? this.platformSpecificBuildOptions : masOptions;
214
- const qualifier = options.identity;
294
+ const config = options !== null && options !== void 0 ? options : this.platformSpecificBuildOptions;
295
+ const qualifier = config.identity;
215
296
  const fallBackToAdhoc = (arch === builder_util_1.Arch.arm64 || arch === builder_util_1.Arch.universal) && !this.forceCodeSigning;
216
297
  if (qualifier === null) {
217
- if (this.forceCodeSigning) {
218
- throw new builder_util_1.InvalidConfigurationError("identity explicitly is set to null, but forceCodeSigning is set to true");
219
- }
220
- builder_util_1.log.info({ reason: "identity explicitly is set to null" }, "skipped macOS code signing");
221
- if (fallBackToAdhoc) {
222
- builder_util_1.log.warn("arm64 requires signing, but identity is set to null and signing is being skipped");
223
- }
224
- return false;
298
+ return this.helper.handleNullIdentity(fallBackToAdhoc);
225
299
  }
226
300
  const keychainFile = (await this.codeSigningInfo.value).keychainFile;
227
- const explicitType = options.type;
301
+ const explicitType = config.type;
228
302
  const type = explicitType || "distribution";
229
303
  const isDevelopment = type === "development";
230
- const certificateTypes = getCertificateTypes(isMas, isDevelopment);
231
- let identity = null;
232
- for (const certificateType of certificateTypes) {
233
- identity = await (0, macCodeSign_1.findIdentity)(certificateType, qualifier, keychainFile);
234
- if (identity != null) {
235
- break;
236
- }
237
- }
238
- if (identity == null) {
239
- if (!isMas && !isDevelopment && explicitType !== "distribution") {
240
- identity = await (0, macCodeSign_1.findIdentity)("Mac Developer", qualifier, keychainFile);
241
- if (identity != null) {
242
- builder_util_1.log.warn("Mac Developer is used to sign app — it is only for development and testing, not for production");
243
- }
244
- }
245
- const noIdentity = !options.sign && identity == null;
246
- if (qualifier === "-") {
247
- identity = new util_identities_1.Identity("-", undefined);
248
- }
249
- else if (noIdentity && fallBackToAdhoc) {
250
- builder_util_1.log.warn(null, "falling back to ad-hoc signature for macOS application code signing");
251
- identity = new util_identities_1.Identity("-", undefined);
252
- }
253
- else if (noIdentity) {
254
- await (0, macCodeSign_1.reportError)(isMas, certificateTypes, qualifier, keychainFile, this.forceCodeSigning);
255
- return false;
256
- }
304
+ const identity = await this.helper.findSigningIdentity(isMas, isDevelopment, qualifier, keychainFile, config, fallBackToAdhoc);
305
+ if (!identity) {
306
+ return false;
257
307
  }
258
308
  if (!(0, macosVersion_1.isMacOsHighSierra)()) {
259
309
  throw new builder_util_1.InvalidConfigurationError("macOS High Sierra 10.13.6 is required to sign");
260
310
  }
261
- let filter = options.signIgnore;
262
- if (Array.isArray(filter)) {
263
- if (filter.length == 0) {
264
- filter = null;
265
- }
266
- }
267
- else if (filter != null) {
268
- filter = filter.length === 0 ? null : [filter];
269
- }
270
- const filterRe = filter == null
271
- ? null
272
- : filter.map(it => {
273
- try {
274
- return new RegExp(it);
275
- }
276
- catch (e) {
277
- throw new builder_util_1.InvalidConfigurationError(`Invalid regex filter pattern: ${it}. ${e.message}`);
278
- }
279
- });
280
- let binaries = options.binaries || undefined;
281
- if (binaries) {
282
- // Accept absolute paths for external binaries, else resolve relative paths from the artifact's app Contents path.
283
- binaries = (await Promise.all(binaries.flatMap(async (destination) => {
284
- const expandedDestination = this.expandArch(destination, arch);
285
- return await Promise.all(expandedDestination.map(async (d) => {
286
- if (await (0, builder_util_1.statOrNull)(d)) {
287
- return d;
288
- }
289
- return path.resolve(appPath, d);
290
- }));
291
- }))).flat();
292
- builder_util_1.log.info({ binaries, arch: arch == null ? null : builder_util_1.Arch[arch] }, "signing additional user-defined binaries for arch");
293
- }
294
- const customSignOptions = (isMas ? masOptions : this.platformSpecificBuildOptions) || this.platformSpecificBuildOptions;
295
- const signOptions = {
296
- identityValidation: false,
297
- // https://github.com/electron-userland/electron-builder/issues/1699
298
- // kext are signed by the chipset manufacturers. You need a special certificate (only available on request) from Apple to be able to sign kext.
299
- ignore: (file) => {
300
- if (filterRe != null) {
301
- for (const regExp of filterRe) {
302
- if (regExp.test(file)) {
303
- return true;
304
- }
305
- }
306
- }
307
- return (file.endsWith(".kext") ||
308
- file.startsWith("/Contents/PlugIns", appPath.length) ||
309
- file.includes("/node_modules/puppeteer/.local-chromium") ||
310
- file.includes("/node_modules/playwright-firefox/.local-browsers") ||
311
- file.includes("/node_modules/playwright/.local-browsers"));
312
- /* Those are browser automating modules, browser (chromium, nightly) cannot be signed
313
- https://github.com/electron-userland/electron-builder/issues/2010
314
- https://github.com/electron-userland/electron-builder/issues/5383
315
- */
316
- },
317
- identity: identity ? identity.hash || identity.name : undefined,
318
- type,
319
- platform: isMas ? "mas" : "darwin",
320
- version: this.config.electronVersion || undefined,
321
- app: appPath,
322
- keychain: keychainFile || undefined,
323
- binaries,
324
- // https://github.com/electron-userland/electron-builder/issues/1480
325
- strictVerify: options.strictVerify,
326
- preAutoEntitlements: options.preAutoEntitlements,
327
- optionsForFile: await this.getOptionsForFile(appPath, isMas, customSignOptions),
328
- provisioningProfile: customSignOptions.provisioningProfile || undefined,
329
- };
330
- await this.doSign(signOptions, customSignOptions, identity);
331
- // https://github.com/electron-userland/electron-builder/issues/1196#issuecomment-312310209
332
- if (masOptions != null && !isDevelopment) {
333
- const certType = isDevelopment ? "Mac Developer" : "3rd Party Mac Developer Installer";
334
- const masInstallerIdentity = await (0, macCodeSign_1.findIdentity)(certType, masOptions.identity, keychainFile);
335
- if (masInstallerIdentity == null) {
336
- throw new builder_util_1.InvalidConfigurationError(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://electron.build/code-signing`);
337
- }
338
- // mas uploaded to AppStore, so, use "-" instead of space for name
339
- const artifactName = this.expandArtifactNamePattern(masOptions, "pkg", arch);
340
- const artifactPath = path.join(outDir, artifactName);
341
- await this.doFlat(appPath, artifactPath, masInstallerIdentity, keychainFile);
342
- await this.info.emitArtifactBuildCompleted({
343
- file: artifactPath,
344
- target: null,
345
- arch: builder_util_1.Arch.x64,
346
- safeArtifactName: this.computeSafeArtifactName(artifactName, "pkg", arch, true, this.platformSpecificBuildOptions.defaultArch),
347
- packager: this,
348
- });
311
+ const signOptions = await this.helper.buildSignOptions(appPath, identity, type, isMas, config, keychainFile, arch);
312
+ await this.doSign(signOptions, config, identity);
313
+ // Handle MAS installer creation
314
+ if (isMas && !isDevelopment && outDir) {
315
+ await this.helper.createMasInstaller(appPath, outDir, config, keychainFile, isDevelopment, arch);
349
316
  }
317
+ // Handle notarization for non-MAS builds
350
318
  if (!isMas) {
351
- await this.notarizeIfProvided(appPath);
319
+ await this.helper.notarizeIfProvided(appPath);
352
320
  }
353
321
  return true;
354
322
  }
355
- async getOptionsForFile(appPath, isMas, customSignOptions) {
356
- const resourceList = await this.resourceList;
357
- const entitlementsSuffix = isMas ? "mas" : "mac";
358
- const getEntitlements = (filePath) => {
359
- // check if root app, then use main entitlements
360
- if (filePath === appPath) {
361
- if (customSignOptions.entitlements) {
362
- return customSignOptions.entitlements;
363
- }
364
- const p = `entitlements.${entitlementsSuffix}.plist`;
365
- if (resourceList.includes(p)) {
366
- return path.join(this.info.buildResourcesDir, p);
367
- }
368
- else {
369
- return (0, pathManager_1.getTemplatePath)("entitlements.mac.plist");
370
- }
371
- }
372
- // It's a login helper...
373
- if (filePath.includes("Library/LoginItems")) {
374
- return customSignOptions.entitlementsLoginHelper;
375
- }
376
- // Only remaining option is that it's inherited entitlements
377
- if (customSignOptions.entitlementsInherit) {
378
- return customSignOptions.entitlementsInherit;
379
- }
380
- const p = `entitlements.${entitlementsSuffix}.inherit.plist`;
381
- if (resourceList.includes(p)) {
382
- return path.join(this.info.buildResourcesDir, p);
383
- }
384
- else {
385
- return (0, pathManager_1.getTemplatePath)("entitlements.mac.plist");
386
- }
387
- };
388
- const requirements = isMas || this.platformSpecificBuildOptions.requirements == null ? undefined : await this.getResource(this.platformSpecificBuildOptions.requirements);
389
- // harden by default for mac builds. Only harden mas builds if explicitly true (backward compatibility)
390
- const hardenedRuntime = isMas ? customSignOptions.hardenedRuntime === true : customSignOptions.hardenedRuntime !== false;
391
- const optionsForFile = filePath => {
392
- const entitlements = getEntitlements(filePath);
393
- const args = {
394
- entitlements: entitlements || undefined,
395
- hardenedRuntime: hardenedRuntime !== null && hardenedRuntime !== void 0 ? hardenedRuntime : undefined,
396
- timestamp: customSignOptions.timestamp || undefined,
397
- requirements: requirements || undefined,
398
- additionalArguments: customSignOptions.additionalArguments || [],
399
- };
400
- return args;
401
- };
402
- return optionsForFile;
403
- }
404
323
  //noinspection JSMethodCanBeStatic
405
324
  async doSign(opts, customSignOptions, identity) {
406
325
  const customSign = await (0, resolve_1.resolveFunction)(this.appInfo.type, customSignOptions.sign, "sign", await this.info.getWorkspaceRoot());
@@ -417,11 +336,13 @@ class MacPackager extends platformPackager_1.PlatformPackager {
417
336
  }
418
337
  //noinspection JSMethodCanBeStatic
419
338
  async doFlat(appPath, outFile, identity, keychain) {
339
+ const safeAppPath = (0, builder_util_1.sanitizeDirPath)(appPath);
340
+ const safeOutFile = (0, builder_util_1.sanitizeDirPath)(outFile);
420
341
  // productbuild doesn't created directory for out file
421
- await (0, promises_1.mkdir)(path.dirname(outFile), { recursive: true });
342
+ await (0, promises_1.mkdir)(path.dirname(safeOutFile), { recursive: true });
422
343
  const args = (0, pkg_1.prepareProductBuildArgs)(identity, keychain);
423
- args.push("--component", appPath, "/Applications");
424
- args.push(outFile);
344
+ args.push("--component", safeAppPath, "/Applications");
345
+ args.push(safeOutFile);
425
346
  return await (0, builder_util_1.exec)("productbuild", args);
426
347
  }
427
348
  getElectronSrcDir(dist) {
@@ -432,6 +353,7 @@ class MacPackager extends platformPackager_1.PlatformPackager {
432
353
  }
433
354
  // todo fileAssociations
434
355
  async applyCommonInfo(appPlist, contentsPath) {
356
+ var _a;
435
357
  const appInfo = this.appInfo;
436
358
  const appFilename = appInfo.productFilename;
437
359
  // https://github.com/electron-userland/electron-builder/issues/1278
@@ -472,8 +394,9 @@ class MacPackager extends platformPackager_1.PlatformPackager {
472
394
  if (minimumSystemVersion != null) {
473
395
  appPlist.LSMinimumSystemVersion = minimumSystemVersion;
474
396
  }
475
- appPlist.CFBundleShortVersionString = this.platformSpecificBuildOptions.bundleShortVersion || appInfo.version;
476
- appPlist.CFBundleVersion = appInfo.buildVersion;
397
+ const activeOpts = (_a = this._activePackConfig) !== null && _a !== void 0 ? _a : this.platformSpecificBuildOptions;
398
+ appPlist.CFBundleShortVersionString = activeOpts.bundleShortVersion || appInfo.version;
399
+ appPlist.CFBundleVersion = activeOpts.bundleVersion || appInfo.buildVersion;
477
400
  (0, builder_util_1.use)(this.platformSpecificBuildOptions.category || this.config.category, it => (appPlist.LSApplicationCategoryType = it));
478
401
  appPlist.NSHumanReadableCopyright = appInfo.copyright;
479
402
  if (this.platformSpecificBuildOptions.darkModeSupport) {
@@ -490,10 +413,21 @@ class MacPackager extends platformPackager_1.PlatformPackager {
490
413
  }
491
414
  }
492
415
  async signApp(packContext, isAsar) {
416
+ var _a;
417
+ const isMas = packContext.electronPlatformName === "mas";
418
+ const activeConfig = (_a = this._activePackConfig) !== null && _a !== void 0 ? _a : this.platformSpecificBuildOptions;
493
419
  const readDirectoryAndSign = async (sourceDirectory, directories, shouldSign) => {
420
+ const normalizedSourceDirectory = path.resolve(sourceDirectory);
421
+ MacTargetHelper_1.MacTargetHelper.assertSafePathForCommandUsage(normalizedSourceDirectory, "application output directory");
494
422
  await Promise.all(directories.map(async (file) => {
495
423
  if (shouldSign(file)) {
496
- await this.sign(path.join(sourceDirectory, file), null, null, packContext.arch);
424
+ const entryName = path.basename(file);
425
+ if (file !== entryName) {
426
+ throw new builder_util_1.InvalidConfigurationError(`Invalid entry name in source directory: ${file}`);
427
+ }
428
+ const signTarget = path.resolve(normalizedSourceDirectory, entryName);
429
+ const safeSignTarget = (0, builder_util_1.sanitizeDirPath)(signTarget, normalizedSourceDirectory);
430
+ await this.sign(safeSignTarget, null, isMas ? activeConfig : null, packContext.arch, isMas);
497
431
  }
498
432
  }));
499
433
  return true;
@@ -507,67 +441,6 @@ class MacPackager extends platformPackager_1.PlatformPackager {
507
441
  await readDirectoryAndSign(outResourcesDir, await (0, builder_util_1.orIfFileNotExist)((0, promises_1.readdir)(outResourcesDir), []), file => file.endsWith(".app"));
508
442
  return true;
509
443
  }
510
- async notarizeIfProvided(appPath) {
511
- const notarizeOptions = this.platformSpecificBuildOptions.notarize;
512
- if (notarizeOptions === false) {
513
- builder_util_1.log.info({ reason: "`notarize` options were set explicitly `false`" }, "skipped macOS notarization");
514
- return;
515
- }
516
- const options = this.getNotarizeOptions(appPath);
517
- if (!options) {
518
- builder_util_1.log.warn({ reason: "`notarize` options were unable to be generated" }, "skipped macOS notarization");
519
- return;
520
- }
521
- await (0, notarize_1.notarize)(options);
522
- builder_util_1.log.info(null, "notarization successful");
523
- }
524
- getNotarizeOptions(appPath) {
525
- const teamId = process.env.APPLE_TEAM_ID;
526
- const appleId = process.env.APPLE_ID;
527
- const appleIdPassword = process.env.APPLE_APP_SPECIFIC_PASSWORD;
528
- const tool = "notarytool";
529
- // option 1: app specific password
530
- if (appleId || appleIdPassword) {
531
- if (!appleId) {
532
- throw new builder_util_1.InvalidConfigurationError(`APPLE_ID env var needs to be set`);
533
- }
534
- if (!appleIdPassword) {
535
- throw new builder_util_1.InvalidConfigurationError(`APPLE_APP_SPECIFIC_PASSWORD env var needs to be set`);
536
- }
537
- if (!teamId) {
538
- throw new builder_util_1.InvalidConfigurationError(`APPLE_TEAM_ID env var needs to be set`);
539
- }
540
- return { tool, appPath, appleId, appleIdPassword, teamId };
541
- }
542
- // option 2: API key
543
- const appleApiKey = process.env.APPLE_API_KEY;
544
- const appleApiKeyId = process.env.APPLE_API_KEY_ID;
545
- const appleApiIssuer = process.env.APPLE_API_ISSUER;
546
- if (appleApiKey || appleApiKeyId || appleApiIssuer) {
547
- if (!appleApiKey || !appleApiKeyId || !appleApiIssuer) {
548
- throw new builder_util_1.InvalidConfigurationError(`Env vars APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER need to be set`);
549
- }
550
- return { tool, appPath, appleApiKey, appleApiKeyId, appleApiIssuer };
551
- }
552
- // option 3: keychain
553
- const keychain = process.env.APPLE_KEYCHAIN;
554
- const keychainProfile = process.env.APPLE_KEYCHAIN_PROFILE;
555
- if (keychainProfile) {
556
- let args = { keychainProfile };
557
- if (keychain) {
558
- args = { ...args, keychain };
559
- }
560
- return { tool, appPath, ...args };
561
- }
562
- // if no credentials provided, skip silently
563
- return undefined;
564
- }
565
444
  }
566
445
  exports.MacPackager = MacPackager;
567
- function getCertificateTypes(isMas, isDevelopment) {
568
- if (isDevelopment) {
569
- return isMas ? ["Mac Developer", "Apple Development"] : ["Mac Developer", "Developer ID Application"];
570
- }
571
- return isMas ? ["Apple Distribution", "3rd Party Mac Developer Application"] : ["Developer ID Application"];
572
- }
573
446
  //# sourceMappingURL=macPackager.js.map