Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._devMetadata = devMetadata
if (repositoryInfo != null) {
this._repositoryInfo.value = Promise.resolve(repositoryInfo)
}
this._appInfo = new AppInfo(this, null)
this._framework = await createFrameworkInfo(this.config, this)
const commonOutDirWithoutPossibleOsMacro = path.resolve(this.projectDir, expandMacro(configuration.directories!!.output!!, null, this._appInfo, {
os: "",
}))
if (!isCI && (process.stdout as any).isTTY) {
const effectiveConfigFile = path.join(commonOutDirWithoutPossibleOsMacro, "builder-effective-config.yaml")
log.info({file: log.filePath(effectiveConfigFile)}, "writing effective config")
await outputFile(effectiveConfigFile, getSafeEffectiveConfig(configuration))
}
// because artifact event maybe dispatched several times for different publish providers
const artifactPaths = new Set()
this.artifactCreated(event => {
if (event.file != null) {
artifactPaths.add(event.file)
}
})
this.disposeOnBuildFinish(() => this.tempDirManager.cleanup())
const platformToTargets = await executeFinally(this.doBuild(), async () => {
if (this.debugLogger.isEnabled) {
await this.debugLogger.save(path.join(commonOutDirWithoutPossibleOsMacro, "builder-debug.yml"))
}
type,
platform: isMas ? "mas" : "darwin",
version: this.config.electronVersion,
app: appPath,
keychain: keychainFile || undefined,
binaries: options.binaries || undefined,
requirements: isMas || this.platformSpecificBuildOptions.requirements == null ? undefined : await this.getResource(this.platformSpecificBuildOptions.requirements),
// https://github.com/electron-userland/electron-osx-sign/issues/196
// will fail on 10.14.5+ because a signed but unnotarized app is also rejected.
"gatekeeper-assess": options.gatekeeperAssess === true,
hardenedRuntime: options.hardenedRuntime !== false,
}
await this.adjustSignOptions(signOptions, masOptions)
log.info({
file: log.filePath(appPath),
identityName: identity.name,
identityHash: identity.hash,
provisioningProfile: signOptions["provisioning-profile"] || "none",
}, "signing")
await this.doSign(signOptions)
// https://github.com/electron-userland/electron-builder/issues/1196#issuecomment-312310209
if (masOptions != null && !isDevelopment) {
const certType = isDevelopment ? "Mac Developer" : "3rd Party Mac Developer Installer"
const masInstallerIdentity = await findIdentity(certType, masOptions.identity, keychainFile)
if (masInstallerIdentity == null) {
throw new InvalidConfigurationError(`Cannot find valid "${certType}" identity to sign MAS installer, please see https://electron.build/code-signing`)
}
// mas uploaded to AppStore, so, use "-" instead of space for name
const artifactName = this.expandArtifactNamePattern(masOptions, "pkg")
export async function appendBlockmap(file: string): Promise {
log.info({file: log.filePath(file)}, "building embedded block map")
return await executeAppBuilderAsJson(["blockmap", "--input", file, "--compression", "deflate"])
}
if (this.platformSpecificBuildOptions.sign != null) {
await sign(signOptions, this)
}
else if (this.forceCodeSigning) {
throw new InvalidConfigurationError(`App is not signed and "forceCodeSigning" is set to true, please ensure that code signing configuration is correct, please see https://electron.build/code-signing`)
}
return
}
if (logMessagePrefix == null) {
logMessagePrefix = "signing"
}
if ("file" in cscInfo) {
log.info({
file: log.filePath(file),
certificateFile: (cscInfo as FileCodeSigningInfo).file,
}, logMessagePrefix)
}
else {
const info = cscInfo as CertificateFromStoreInfo
log.info({
file: log.filePath(file),
subject: info.subject,
thumbprint: info.thumbprint,
store: info.store,
user: info.isLocalMachineStore ? "local machine" : "current user",
}, logMessagePrefix)
}
await this.doSign({
...signOptions,
}
if (logMessagePrefix == null) {
logMessagePrefix = "signing"
}
if ("file" in cscInfo) {
log.info({
file: log.filePath(file),
certificateFile: (cscInfo as FileCodeSigningInfo).file,
}, logMessagePrefix)
}
else {
const info = cscInfo as CertificateFromStoreInfo
log.info({
file: log.filePath(file),
subject: info.subject,
thumbprint: info.thumbprint,
store: info.store,
user: info.isLocalMachineStore ? "local machine" : "current user",
}, logMessagePrefix)
}
await this.doSign({
...signOptions,
cscInfo,
options: {
...this.platformSpecificBuildOptions,
},
})
}
export async function createBlockmap(file: string, target: Target, packager: PlatformPackager, safeArtifactName: string | null): Promise {
const blockMapFile = `${file}${BLOCK_MAP_FILE_SUFFIX}`
log.info({blockMapFile: log.filePath(blockMapFile)}, "building block map")
const updateInfo = await executeAppBuilderAsJson(["blockmap", "--input", file, "--output", blockMapFile])
await packager.info.callArtifactBuildCompleted({
file: blockMapFile,
safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${BLOCK_MAP_FILE_SUFFIX}`,
target,
arch: null,
packager,
updateInfo,
})
return updateInfo
}
async callArtifactBuildStarted(event: ArtifactBuildStarted, logFields?: any): Promise {
log.info(logFields || {
target: event.targetPresentableName,
arch: event.arch == null ? null : Arch[event.arch],
file: log.filePath(event.file),
}, "building")
const handler = resolveFunction(this.config.artifactBuildStarted, "artifactBuildStarted")
if (handler != null) {
await Promise.resolve(handler(event))
}
}
private async buildInstaller(): Promise {
const packager = this.packager
const appInfo = packager.appInfo
const options = this.options
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, this.installerFilenamePattern)
const oneClick = options.oneClick !== false
const installerPath = path.join(this.outDir, installerFilename)
const logFields: any = {
target: this.name,
file: log.filePath(installerPath),
archs: Array.from(this.archs.keys()).map(it => Arch[it]).join(", "),
}
const isPerMachine = options.perMachine === true
if (!this.isPortable) {
logFields.oneClick = oneClick
logFields.perMachine = isPerMachine
}
await packager.info.callArtifactBuildStarted({
targetPresentableName: this.name,
file: installerPath,
arch: null,
}, logFields)
const guid = options.guid || UUID.v5(appInfo.id, ELECTRON_BUILDER_NS_UUID)
const uninstallAppKey = guid.replace(/\\/g, " - ")