Skip to content

Commit

Permalink
feat: muon support
Browse files Browse the repository at this point in the history
Close #1394
  • Loading branch information
develar committed Mar 22, 2017
1 parent 16bc53c commit 4f555da
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 39 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"debug": "^2.6.3",
"electron-download-tf": "4.0.0",
"electron-download-tf": "4.1.1",
"electron-macos-sign": "~1.6.0",
"fs-extra-p": "^4.1.0",
"hosted-git-info": "^2.4.1",
Expand Down Expand Up @@ -80,7 +80,6 @@
"convert-source-map": "^1.4.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
"electron-download-tf": "4.0.0",
"globby": "^6.1.0",
"jest-cli": "^19.0.2",
"jest-environment-node-debug": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"electron-builder-core": "0.0.0-semantic-release",
"electron-builder-http": "0.0.0-semantic-release",
"electron-builder-util": "0.0.0-semantic-release",
"electron-download-tf": "4.0.0",
"electron-download-tf": "4.1.1",
"electron-macos-sign": "~1.6.0",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
}

protected postInitApp(appOutDir: string): Promise<any> {
return rename(path.join(appOutDir, "electron"), path.join(appOutDir, this.executableName))
return rename(path.join(appOutDir, this.electronDistExecutableName), path.join(appOutDir, this.executableName))
}
}
5 changes: 5 additions & 0 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ export interface Config extends PlatformSpecificBuildOptions {
* The version of electron you are packaging for. Defaults to version of `electron`, `electron-prebuilt` or `electron-prebuilt-compile` dependency.
*/
readonly electronVersion?: string | null

/**
* The version of muon you are packaging for.
*/
readonly muonVersion?: string | null

/**
* The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName}-${version}.${ext}` (some target can have another defaults, see corresponding options).
Expand Down
2 changes: 2 additions & 0 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class Packager implements BuildInfo {
isTwoPackageJsonProjectLayoutUsed = true

electronVersion: string
muonVersion?: string | null

readonly eventEmitter = new EventEmitter()

Expand Down Expand Up @@ -159,6 +160,7 @@ export class Packager implements BuildInfo {
checkConflictingOptions(this.config)

this.electronVersion = await getElectronVersion(this.config, projectDir, this.isPrepackedAppAsar ? this.metadata : null)
this.muonVersion = this.config.muonVersion

this.appInfo = new AppInfo(this.metadata, this)
const cleanupTasks: Array<() => Promise<any>> = []
Expand Down
22 changes: 17 additions & 5 deletions packages/electron-builder/src/packager/dirPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,31 @@ function subOptionWarning (properties: any, optionName: any, parameter: any, val
properties[parameter] = value
}

export async function unpackElectron(packager: PlatformPackager<any>, out: string, platform: string, arch: string, electronVersion: string) {
const electronDist = packager.config.electronDist
if (electronDist == null) {
export function unpackElectron(packager: PlatformPackager<any>, out: string, platform: string, arch: string, version: string) {
return unpack(packager, out, platform, createDownloadOpts(packager.config, platform, arch, version))
}

export function unpackMuon(packager: PlatformPackager<any>, out: string, platform: string, arch: string, version: string) {
return unpack(packager, out, platform, Object.assign({
mirror: "https://github.com/brave/muon/releases/download/v",
customFilename: `brave-v${version}-${platform}-${arch}.zip`,
verifyChecksum: false,
}, createDownloadOpts(packager.config, platform, arch, version)))
}

async function unpack(packager: PlatformPackager<any>, out: string, platform: string, options: any) {
const dist = packager.config.electronDist
if (dist == null) {
const zipPath = (await BluebirdPromise.all<any>([
downloadElectron(createDownloadOpts(packager.config, platform, arch, electronVersion)),
downloadElectron(options),
emptyDir(out)
]))[0]

await spawn(path7za, debug7zArgs("x").concat(zipPath, `-o${out}`))
}
else {
await emptyDir(out)
await copyDir(path.resolve(packager.info.projectDir, electronDist, "Electron.app"), path.join(out, "Electron.app"))
await copyDir(path.resolve(packager.info.projectDir, dist, "Electron.app"), path.join(out, "Electron.app"))
}

if (platform === "linux") {
Expand Down
20 changes: 10 additions & 10 deletions packages/electron-builder/src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function doRename(basePath: string, oldName: string, newName: string) {
return rename(path.join(basePath, oldName), path.join(basePath, newName))
}

function moveHelpers(frameworksPath: string, appName: string) {
function moveHelpers(frameworksPath: string, appName: string, prefix: string) {
return BluebirdPromise.map([" Helper", " Helper EH", " Helper NP"], suffix => {
const executableBasePath = path.join(frameworksPath, `Electron${suffix}.app`, "Contents", "MacOS")
return doRename(executableBasePath, `Electron${suffix}`, appName + suffix)
.then(() => doRename(frameworksPath, `Electron${suffix}.app`, `${appName}${suffix}.app`))
const executableBasePath = path.join(frameworksPath, `${prefix}${suffix}.app`, "Contents", "MacOS")
return doRename(executableBasePath, `${prefix}${suffix}`, appName + suffix)
.then(() => doRename(frameworksPath, `${prefix}${suffix}.app`, `${appName}${suffix}.app`))
})
}

Expand All @@ -29,13 +29,13 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
const appInfo = packager.appInfo
const appFilename = appInfo.productFilename

const contentsPath = path.join(appOutDir, "Electron.app", "Contents")
const contentsPath = path.join(appOutDir, packager.electronDistMacOsAppName, "Contents")
const frameworksPath = path.join(contentsPath, "Frameworks")

const appPlistFilename = path.join(contentsPath, "Info.plist")
const helperPlistFilename = path.join(frameworksPath, "Electron Helper.app", "Contents", "Info.plist")
const helperEHPlistFilename = path.join(frameworksPath, "Electron Helper EH.app", "Contents", "Info.plist")
const helperNPPlistFilename = path.join(frameworksPath, "Electron Helper NP.app", "Contents", "Info.plist")
const helperPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper.app`, "Contents", "Info.plist")
const helperEHPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper EH.app`, "Contents", "Info.plist")
const helperNPPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper NP.app`, "Contents", "Info.plist")

const buildMetadata = packager.config!
const fileContents: Array<string> = await BluebirdPromise.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, (<any>buildMetadata)["extend-info"]], it => it == null ? it : readFile(it, "utf8"))
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
writeFile(helperPlistFilename, buildPlist(helperPlist)),
writeFile(helperEHPlistFilename, buildPlist(helperEHPlist)),
writeFile(helperNPPlistFilename, buildPlist(helperNPPlist)),
doRename(path.join(contentsPath, "MacOS"), "Electron", appPlist.CFBundleExecutable),
doRename(path.join(contentsPath, "MacOS"), packager.electronDistMacOsExecutableName, appPlist.CFBundleExecutable),
unlinkIfExists(path.join(appOutDir, "LICENSE")),
unlinkIfExists(path.join(appOutDir, "LICENSES.chromium.html")),
]
Expand All @@ -152,7 +152,7 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri

await BluebirdPromise.all(promises)

await moveHelpers(frameworksPath, appFilename)
await moveHelpers(frameworksPath, appFilename, packager.electronDistMacOsExecutableName)
const appPath = path.join(appOutDir, `${appFilename}.app`)
await rename(path.dirname(contentsPath), appPath)
// https://github.com/electron-userland/electron-builder/issues/840
Expand Down
1 change: 1 addition & 0 deletions packages/electron-builder/src/packagerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface BuildInfo {
readonly appDir: string

readonly electronVersion: string
readonly muonVersion?: string | null

readonly isTwoPackageJsonProjectLayoutUsed: boolean

Expand Down
19 changes: 16 additions & 3 deletions packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AsarPackager, checkFileInArchive } from "./asarUtil"
import { copyFiles, FileMatcher } from "./fileMatcher"
import { createTransformer } from "./fileTransformer"
import { Config } from "./metadata"
import { unpackElectron } from "./packager/dirPackager"
import { unpackElectron, unpackMuon } from "./packager/dirPackager"
import { BuildInfo, PackagerOptions } from "./packagerApi"
import { readInstalled } from "./readInstalled"

Expand Down Expand Up @@ -139,6 +139,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

return matcher
}

get electronDistMacOsAppName() {
return this.info.muonVersion == null ? "Electron.app" : "Brave.app"
}

get electronDistExecutableName() {
return this.info.muonVersion == null ? "electron" : "brave"
}

get electronDistMacOsExecutableName() {
return this.info.muonVersion == null ? "Electron" : "Brave"
}

protected async doPack(outDir: string, appOutDir: string, platformName: string, arch: Arch, platformSpecificBuildOptions: DC, targets: Array<Target>) {
if (this.info.prepackaged != null) {
Expand All @@ -150,7 +162,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const extraResourceMatchers = this.getExtraFileMatchers(true, appOutDir, macroExpander, platformSpecificBuildOptions)
const extraFileMatchers = this.getExtraFileMatchers(false, appOutDir, macroExpander, platformSpecificBuildOptions)

const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, "Electron.app", "Contents", "Resources") : path.join(appOutDir, "resources")
const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, this.electronDistMacOsAppName, "Contents", "Resources") : path.join(appOutDir, "resources")

log(`Packaging for ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`)

Expand All @@ -165,9 +177,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
else {
// prune dev or not listed dependencies
const muonVersion = this.info.muonVersion
await BluebirdPromise.all([
dependencies(appDir, ignoreFiles),
unpackElectron(this, appOutDir, platformName, Arch[arch], this.info.electronVersion),
muonVersion == null ? unpackElectron(this, appOutDir, platformName, Arch[arch], this.info.electronVersion) : unpackMuon(this, appOutDir, platformName, Arch[arch], muonVersion),
])

if (debug.enabled) {
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {

protected async postInitApp(appOutDir: string) {
const executable = path.join(appOutDir, `${this.appInfo.productFilename}.exe`)
await rename(path.join(appOutDir, "electron.exe"), executable)
await rename(path.join(appOutDir, `${this.electronDistExecutableName}.exe`), executable)
await this.signAndEditResources(executable)
}
}

async function checkIcon(file: string): Promise<void> {
async function checkIcon(file: string): Promise<void> {
const fd = await open(file, "r")
const buffer = new Buffer(512)
try {
Expand Down
19 changes: 19 additions & 0 deletions test/out/__snapshots__/muon.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`muon linux 1`] = `
Object {
"linux": Array [],
}
`;

exports[`muon mac 1`] = `
Object {
"mac": Array [],
}
`;

exports[`muon win 1`] = `
Object {
"win": Array [],
}
`;
2 changes: 1 addition & 1 deletion test/src/ExtraBuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ test.ifAll.ifDevOrLinuxCi("scheme validation extraFiles", app({
}
],
},
}))
}))
23 changes: 23 additions & 0 deletions test/src/muon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DIR_TARGET, Platform } from "electron-builder-core"
import { app } from "./helpers/packTester"

test.ifAll.ifDevOrLinuxCi("muon linux", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
config: {
muonVersion: "2.56.9",
},
}))

test.ifAll.ifMac("muon mac", app({
targets: Platform.MAC.createTarget(DIR_TARGET),
config: {
muonVersion: "2.56.9",
},
}))

test.ifAll.ifMac("muon win", app({
targets: Platform.WINDOWS.createTarget(DIR_TARGET),
config: {
muonVersion: "2.56.9",
},
}))
24 changes: 10 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.6.0, debug@^2.6.1, debug@^2.6.3:
debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.6.0, debug@^2.6.3:
version "2.6.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
dependencies:
Expand Down Expand Up @@ -1055,18 +1055,18 @@ ecc-jsbn@~0.1.1:
dependencies:
jsbn "~0.1.0"

electron-download-tf@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/electron-download-tf/-/electron-download-tf-4.0.0.tgz#b2cd6af916ea94cc3723d8931961cb537fb2efff"
electron-download-tf@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/electron-download-tf/-/electron-download-tf-4.1.1.tgz#127aaa6a10ccf598bc15ed6ae83390348ebb3b4b"
dependencies:
debug "^2.6.1"
fs-extra "^2.0.0"
debug "^2.6.3"
fs-extra "^2.1.2"
minimist "^1.2.0"
nugget "^2.0.1"
path-exists "^3.0.0"
rc "^1.1.7"
semver "^5.3.0"
sumchecker "^2.0.1"
sumchecker "^2.0.2"

electron-macos-sign@~1.6.0:
version "1.6.0"
Expand Down Expand Up @@ -1282,7 +1282,7 @@ fs-extra-p@^4.0.2, fs-extra-p@^4.1.0:
bluebird-lst "^1.0.2"
fs-extra "^2.1.2"

fs-extra@^2.0.0, fs-extra@^2.1.2:
fs-extra@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
dependencies:
Expand Down Expand Up @@ -2255,18 +2255,14 @@ mime@^1.3.4:
dependencies:
brace-expansion "^1.0.0"

[email protected]:
[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
Expand Down Expand Up @@ -3021,7 +3017,7 @@ strip-json-comments@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

sumchecker@^2.0.1:
sumchecker@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-2.0.2.tgz#0f42c10e5d05da5d42eea3e56c3399a37d6c5b3e"
dependencies:
Expand Down

0 comments on commit 4f555da

Please sign in to comment.