-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: integrate @electron/universal #1346
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b2d2888
feat: integrate @electron/universal
MarshallOfSound 55a52d6
chore: fix platform typo
MarshallOfSound 50017ef
spec: add universal generation tests
MarshallOfSound 2d9f436
spec: fix tests
MarshallOfSound 62487c9
fix: add universal to supported list for mas
MarshallOfSound a8a7591
spec: fix tests
MarshallOfSound c1fe691
spec: fix tests
MarshallOfSound 097d0f1
docs: update usage
MarshallOfSound 2ca6578
Update README.md
erickzhao 469cbd7
Update usage.txt
erickzhao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ import { | |
TransporterOptions | ||
} from 'electron-notarize/lib/types'; | ||
import { SignOptions } from 'electron-osx-sign'; | ||
import type { makeUniversalApp } from '@electron/universal'; | ||
|
||
type MakeUniversalOpts = Parameters<typeof makeUniversalApp>[0] | ||
|
||
type NotarizeLegacyOptions = LegacyNotarizeCredentials & TransporterOptions; | ||
|
||
|
@@ -128,6 +131,12 @@ declare namespace electronPackager { | |
| ({ tool?: 'legacy' } & NotarizeLegacyOptions) | ||
| ({ tool: 'notarytool' } & NotaryToolCredentials); | ||
|
||
/** | ||
* See the documentation for [`@electron/universal`](https://github.com/electron/universal) | ||
* for details. | ||
*/ | ||
type OsxUniversalOptions = Omit<MakeUniversalOpts, 'x64AppPath' | 'arm64AppPath' | 'outAppPath' | 'force'> | ||
|
||
/** | ||
* Defines URL protocol schemes to be used on macOS. | ||
*/ | ||
|
@@ -444,6 +453,12 @@ declare namespace electronPackager { | |
* @category macOS | ||
*/ | ||
osxSign?: true | OsxSignOptions; | ||
/** | ||
* Used to provide custom options to the internal call to `@electron/universal` when building a macOS | ||
* app with the target architecture of "universal". Unused otherwise, providing a value does not imply | ||
* a universal app is built. | ||
*/ | ||
osxUniversal?: OsxUniversalOptions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: not exposed via CLI |
||
/** | ||
* The base directory where the finished package(s) are created. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict' | ||
|
||
const universal = require('@electron/universal') | ||
const common = require('./common') | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
|
||
async function packageUniversalMac (packageForPlatformAndArchWithOpts, buildDir, comboOpts, downloadOpts, tempBase) { | ||
// In order to generate a universal macOS build we actually need to build the x64 and the arm64 app | ||
// and then glue them together | ||
common.info(`Packaging app for platform ${comboOpts.platform} universal using electron v${comboOpts.electronVersion} - Building x64 and arm64 slices now`, comboOpts.quiet) | ||
await fs.mkdirp(tempBase) | ||
const tempDir = await fs.mkdtemp(path.resolve(tempBase, 'electron-packager-universal-')) | ||
|
||
const { App } = require('./mac') | ||
const app = new App(comboOpts, buildDir) | ||
const universalStagingPath = app.stagingPath | ||
const finalUniversalPath = common.generateFinalPath(app.opts) | ||
|
||
if (await fs.pathExists(finalUniversalPath)) { | ||
if (comboOpts.overwrite) { | ||
await fs.remove(finalUniversalPath) | ||
} else { | ||
common.info(`Skipping ${comboOpts.platform} ${comboOpts.arch} (output dir already exists, use --overwrite to force)`, comboOpts.quiet) | ||
return true | ||
} | ||
} | ||
|
||
const [x64AppPath, arm64AppPath] = await Promise.all(['x64', 'arm64'].map((tempArch) => { | ||
const tempOpts = { | ||
...comboOpts, | ||
arch: tempArch, | ||
out: tempDir | ||
} | ||
const tempDownloadOpts = { | ||
...downloadOpts, | ||
arch: tempArch | ||
} | ||
// Do not sign or notarize the individual slices, we sign and notarize the merged app later | ||
delete tempOpts.osxSign | ||
delete tempOpts.osxNotarize | ||
|
||
return packageForPlatformAndArchWithOpts(tempOpts, tempDownloadOpts) | ||
})) | ||
|
||
common.info(`Stitching universal app for platform ${comboOpts.platform}`, comboOpts.quiet) | ||
|
||
const generatedFiles = await fs.readdir(x64AppPath) | ||
const appName = generatedFiles.filter(file => path.extname(file) === '.app')[0] | ||
|
||
await universal.makeUniversalApp({ | ||
...comboOpts.osxUniversal, | ||
x64AppPath: path.resolve(x64AppPath, appName), | ||
arm64AppPath: path.resolve(arm64AppPath, appName), | ||
outAppPath: path.resolve(universalStagingPath, appName) | ||
}) | ||
|
||
await app.signAppIfSpecified() | ||
await app.notarizeAppIfSpecified() | ||
await app.move() | ||
|
||
for (const generatedFile of generatedFiles) { | ||
if (path.extname(generatedFile) === '.app') continue | ||
|
||
await fs.copy(path.resolve(x64AppPath, generatedFile), path.resolve(finalUniversalPath, generatedFile)) | ||
} | ||
|
||
await fs.remove(tempDir) | ||
|
||
return finalUniversalPath | ||
} | ||
|
||
module.exports = { | ||
packageUniversalMac | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: this leverages
Parameters
in TS to get the args formakeUniversalApp
since@electron/universal
doesn't expose them.