Skip to content

Commit

Permalink
fix: add MemoLazy class to fix codeSigningInfo and cscInfo not …
Browse files Browse the repository at this point in the history
…responding to changed args (#8291)
  • Loading branch information
IsaacAderogba authored Jul 6, 2024
1 parent 2b80b01 commit ad668ae
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 184 deletions.
6 changes: 6 additions & 0 deletions .changeset/fluffy-dryers-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"builder-util-runtime": patch
---

fix: add MemoLazy to fix codeSigningInfo not responding to changed args
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
testFiles:
- ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configurationValidationTest,filenameUtilTest,filesTest,globTest,ignoreTest,macroExpanderTest,mainEntryTest,urlUtilTest,extraMetadataTest,linuxArchiveTest,linuxPackagerTest,HoistedNodeModuleTest
- ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configurationValidationTest,filenameUtilTest,filesTest,globTest,ignoreTest,macroExpanderTest,mainEntryTest,urlUtilTest,extraMetadataTest,linuxArchiveTest,linuxPackagerTest,HoistedNodeModuleTest,MemoLazyTest
- snapTest,debTest,fpmTest,protonTest
steps:
- name: Checkout code repository
Expand Down
242 changes: 143 additions & 99 deletions docs/api/electron-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -927,45 +927,69 @@ Developer API only. See [Configuration](../configuration/configuration.md) for u
<strong>Properties</strong></p>
<ul>
<li>
<p>**&lt;code id=&quot;MacPackager-[codeSigningInfo=new Lazy<CodeSigningInfo>(() =&gt; {
<p>**&lt;code id=&quot;MacPackager-[codeSigningInfo=new MemoLazy&lt;CreateKeychainOptions | null, CodeSigningInfo&gt;(
() =&gt; {
const cscLink = this.getCscLink()
if (cscLink == null || process.platform !== “darwin”) {
return Promise.resolve({ keychainFile: process.env.CSC_KEYCHAIN || null })
return null
}</p>
<p>return createKeychain({
tmpDir: this.info.tempDirManager,
cscLink,
cscKeyPassword: this.getCscPassword(),
cscILink: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerLink, process.env.CSC_INSTALLER_LINK),
cscIKeyPassword: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerKeyPassword, process.env.CSC_INSTALLER_KEY_PASSWORD),
currentDir: this.projectDir,
}).then(result =&gt; {
<pre><code class="hljs">const selected = {
tmpDir: this.info.tempDirManager,
cscLink,
cscKeyPassword: this.getCscPassword(),
cscILink: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerLink, process.env.CSC_INSTALLER_LINK),
cscIKeyPassword: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerKeyPassword, process.env.CSC_INSTALLER_KEY_PASSWORD),
currentDir: this.projectDir,
}

return selected
</code></pre>
<p>},
async selected =&gt; {
if (selected) {
return createKeychain(selected).then(result =&gt; {
const keychainFile = result.keychainFile
if (keychainFile != null) {
this.info.disposeOnBuildFinish(() =&gt; removeKeychain(keychainFile))
}
return result
})
})]&quot;&gt;[codeSigningInfo=new Lazy<CodeSigningInfo>(() =&gt; {
}</p>
<pre><code class="hljs">return Promise.resolve({ keychainFile: process.env.CSC_KEYCHAIN || null })
</code></pre>
<p>}
)]&quot;&gt;[codeSigningInfo=new MemoLazy&lt;CreateKeychainOptions | null, CodeSigningInfo&gt;(
() =&gt; {
const cscLink = this.getCscLink()
if (cscLink == null || process.platform !== “darwin”) {
return Promise.resolve({ keychainFile: process.env.CSC_KEYCHAIN || null })
return null
}</p>
<p>return createKeychain({
tmpDir: this.info.tempDirManager,
cscLink,
cscKeyPassword: this.getCscPassword(),
cscILink: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerLink, process.env.CSC_INSTALLER_LINK),
cscIKeyPassword: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerKeyPassword, process.env.CSC_INSTALLER_KEY_PASSWORD),
currentDir: this.projectDir,
}).then(result =&gt; {
<pre><code class="hljs">const selected = {
tmpDir: this.info.tempDirManager,
cscLink,
cscKeyPassword: this.getCscPassword(),
cscILink: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerLink, process.env.CSC_INSTALLER_LINK),
cscIKeyPassword: chooseNotNull(this.platformSpecificBuildOptions.cscInstallerKeyPassword, process.env.CSC_INSTALLER_KEY_PASSWORD),
currentDir: this.projectDir,
}

return selected
</code></pre>
<p>},
async selected =&gt; {
if (selected) {
return createKeychain(selected).then(result =&gt; {
const keychainFile = result.keychainFile
if (keychainFile != null) {
this.info.disposeOnBuildFinish(() =&gt; removeKeychain(keychainFile))
}
return result
})
})]</code>** Lazy&lt;module:app-builder-lib/out/codeSign/macCodeSign.CodeSigningInfo&gt;</p>
}</p>
<pre><code class="hljs">return Promise.resolve({ keychainFile: process.env.CSC_KEYCHAIN || null })
</code></pre>
<p>}
)]</code>** MemoLazy&lt; | module:app-builder-lib/out/codeSign/macCodeSign.CreateKeychainOptions | module:app-builder-lib/out/codeSign/macCodeSign.CodeSigningInfo&gt;</p>
</li>
<li>
<p><strong><code id="MacPackager-defaultTarget">defaultTarget</code></strong> Array&lt;String&gt;</p>
Expand Down Expand Up @@ -2217,8 +2241,9 @@ return path.join(target.outDir, <code>__${target.name}-${getArtifactArchName(arc
<strong>Properties</strong></p>
<ul>
<li>
<p>**&lt;code id=&quot;WinPackager-[cscInfo=new Lazy&lt;FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;(() =&gt; {
const platformSpecificBuildOptions = this.platformSpecificBuildOptions
<p>**&lt;code id=&quot;WinPackager-[cscInfo=new MemoLazy&lt;WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;(
() =&gt; this.platformSpecificBuildOptions,
platformSpecificBuildOptions =&gt; {
if (platformSpecificBuildOptions.certificateSubjectName != null || platformSpecificBuildOptions.certificateSha1 != null) {
return this.vm.value
.then(vm =&gt; getCertificateFromStoreInfo(platformSpecificBuildOptions, vm))
Expand All @@ -2232,37 +2257,42 @@ return null
}
})
}</p>
<p>const certificateFile = platformSpecificBuildOptions.certificateFile
<pre><code class="hljs">const certificateFile = platformSpecificBuildOptions.certificateFile
if (certificateFile != null) {
const certificatePassword = this.getCscPassword()
return Promise.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim(),
})
}</p>
<p>const cscLink = this.getCscLink(“WIN_CSC_LINK”)
if (cscLink == null || cscLink === “”) {
return Promise.resolve(null)
}</p>
<p>return (
importCertificate(cscLink, this.info.tempDirManager, this.projectDir)
// before then
.catch((e: any) =&gt; {
if (e instanceof InvalidConfigurationError) {
throw new InvalidConfigurationError(<code>Env WIN_CSC_LINK is not correct, cannot resolve: ${e.message}</code>)
} else {
throw e
const certificatePassword = this.getCscPassword()
return Promise.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim(),
})
}
})
.then(path =&gt; {
return {
file: path,
password: this.getCscPassword(),

const cscLink = this.getCscLink(&quot;WIN_CSC_LINK&quot;)
if (cscLink == null || cscLink === &quot;&quot;) {
return Promise.resolve(null)
}
})

return (
importCertificate(cscLink, this.info.tempDirManager, this.projectDir)
// before then
.catch((e: any) =&gt; {
if (e instanceof InvalidConfigurationError) {
throw new InvalidConfigurationError(`Env WIN_CSC_LINK is not correct, cannot resolve: ${e.message}`)
} else {
throw e
}
})
.then(path =&gt; {
return {
file: path,
password: this.getCscPassword(),
}
})
)
})]&quot;&gt;[cscInfo=new Lazy&lt;FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;(() =&gt; {
const platformSpecificBuildOptions = this.platformSpecificBuildOptions
</code></pre>
<p>}
)]&quot;&gt;[cscInfo=new MemoLazy&lt;WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;(
() =&gt; this.platformSpecificBuildOptions,
platformSpecificBuildOptions =&gt; {
if (platformSpecificBuildOptions.certificateSubjectName != null || platformSpecificBuildOptions.certificateSha1 != null) {
return this.vm.value
.then(vm =&gt; getCertificateFromStoreInfo(platformSpecificBuildOptions, vm))
Expand All @@ -2276,36 +2306,40 @@ return null
}
})
}</p>
<p>const certificateFile = platformSpecificBuildOptions.certificateFile
<pre><code class="hljs">const certificateFile = platformSpecificBuildOptions.certificateFile
if (certificateFile != null) {
const certificatePassword = this.getCscPassword()
return Promise.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim(),
})
}</p>
<p>const cscLink = this.getCscLink(“WIN_CSC_LINK”)
if (cscLink == null || cscLink === “”) {
return Promise.resolve(null)
}</p>
<p>return (
importCertificate(cscLink, this.info.tempDirManager, this.projectDir)
// before then
.catch((e: any) =&gt; {
if (e instanceof InvalidConfigurationError) {
throw new InvalidConfigurationError(<code>Env WIN_CSC_LINK is not correct, cannot resolve: ${e.message}</code>)
} else {
throw e
const certificatePassword = this.getCscPassword()
return Promise.resolve({
file: certificateFile,
password: certificatePassword == null ? null : certificatePassword.trim(),
})
}
})
.then(path =&gt; {
return {
file: path,
password: this.getCscPassword(),

const cscLink = this.getCscLink(&quot;WIN_CSC_LINK&quot;)
if (cscLink == null || cscLink === &quot;&quot;) {
return Promise.resolve(null)
}
})

return (
importCertificate(cscLink, this.info.tempDirManager, this.projectDir)
// before then
.catch((e: any) =&gt; {
if (e instanceof InvalidConfigurationError) {
throw new InvalidConfigurationError(`Env WIN_CSC_LINK is not correct, cannot resolve: ${e.message}`)
} else {
throw e
}
})
.then(path =&gt; {
return {
file: path,
password: this.getCscPassword(),
}
})
)
})]</code>** Lazy&lt; | <a href="#FileCodeSigningInfo">FileCodeSigningInfo</a> | <a href="#CertificateFromStoreInfo">CertificateFromStoreInfo</a>&gt;</p>
</code></pre>
<p>}
)]</code>** MemoLazy&lt;<a href="#WindowsConfiguration">WindowsConfiguration</a> | | <a href="#FileCodeSigningInfo">FileCodeSigningInfo</a> | <a href="#CertificateFromStoreInfo">CertificateFromStoreInfo</a>&gt;</p>
</li>
<li>
<p><code id="WinPackager-vm">vm</code> = <code>new Lazy&lt;VmManager&gt;(() =&gt; (process.platform === &quot;win32&quot; ? Promise.resolve(new VmManager()) : getWindowsVm(this.debugLogger)))</code> Lazy&lt;module:app-builder-lib/out/vm/vm.VmManager&gt;</p>
Expand All @@ -2332,41 +2366,51 @@ return certInfo == null ? null : [certInfo.commonName]
})]</code>** Lazy&lt; | Array&gt;</p>
</li>
<li>
<p>**&lt;code id=&quot;WinPackager-[lazyCertInfo=new Lazy&lt;CertificateInfo | null&gt;(async () =&gt; {
const cscInfo = await this.cscInfo.value
<p>**&lt;code id=&quot;WinPackager-[lazyCertInfo=new MemoLazy&lt;MemoLazy&lt;WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;, CertificateInfo | null&gt;(
() =&gt; this.cscInfo,
async csc =&gt; {
const cscInfo = await csc.value
if (cscInfo == null) {
return null
}</p>
<p>if (“subject” in cscInfo) {
const bloodyMicrosoftSubjectDn = cscInfo.subject
return {
commonName: parseDn(bloodyMicrosoftSubjectDn).get(“CN”)!,
bloodyMicrosoftSubjectDn,
<pre><code class="hljs">if (&quot;subject&quot; in cscInfo) {
const bloodyMicrosoftSubjectDn = cscInfo.subject
return {
commonName: parseDn(bloodyMicrosoftSubjectDn).get(&quot;CN&quot;)!,
bloodyMicrosoftSubjectDn,
}
}
}</p>
<p>const cscFile = cscInfo.file

const cscFile = cscInfo.file
if (cscFile == null) {
return null
return null
}
return await getCertInfo(cscFile, cscInfo.password || “”)
})]&quot;&gt;[lazyCertInfo=new Lazy&lt;CertificateInfo | null&gt;(async () =&gt; {
const cscInfo = await this.cscInfo.value
return await getCertInfo(cscFile, cscInfo.password || &quot;&quot;)
</code></pre>
<p>}
)]&quot;&gt;[lazyCertInfo=new MemoLazy&lt;MemoLazy&lt;WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null&gt;, CertificateInfo | null&gt;(
() =&gt; this.cscInfo,
async csc =&gt; {
const cscInfo = await csc.value
if (cscInfo == null) {
return null
}</p>
<p>if (“subject” in cscInfo) {
const bloodyMicrosoftSubjectDn = cscInfo.subject
return {
commonName: parseDn(bloodyMicrosoftSubjectDn).get(“CN”)!,
bloodyMicrosoftSubjectDn,
<pre><code class="hljs">if (&quot;subject&quot; in cscInfo) {
const bloodyMicrosoftSubjectDn = cscInfo.subject
return {
commonName: parseDn(bloodyMicrosoftSubjectDn).get(&quot;CN&quot;)!,
bloodyMicrosoftSubjectDn,
}
}
}</p>
<p>const cscFile = cscInfo.file

const cscFile = cscInfo.file
if (cscFile == null) {
return null
return null
}
return await getCertInfo(cscFile, cscInfo.password || “”)
})]</code>** Lazy&lt; | module:app-builder-lib/out/codeSign/windowsCodeSign.CertificateInfo&gt;</p>
return await getCertInfo(cscFile, cscInfo.password || &quot;&quot;)
</code></pre>
<p>}
)]</code>** MemoLazy&lt;MemoLazy&lt;<a href="#WindowsConfiguration">WindowsConfiguration</a> | | <a href="#FileCodeSigningInfo">FileCodeSigningInfo</a> | <a href="#CertificateFromStoreInfo">CertificateFromStoreInfo</a>&gt; | | module:app-builder-lib/out/codeSign/windowsCodeSign.CertificateInfo&gt;</p>
</li>
<li>
<p><strong><code id="WinPackager-isForceCodeSigningVerification">isForceCodeSigningVerification</code></strong> Boolean</p>
Expand Down
Loading

0 comments on commit ad668ae

Please sign in to comment.