Skip to content

Commit

Permalink
fix: artifactName is not work as expected for zip/appimage
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 3, 2017
1 parent a224d67 commit 48f5036
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:8.5.0
- image: circleci/node:8.9.0
steps:
- checkout
- restore_cache:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"7zip-bin": "^2.2.7",
"archiver": "^2.1.0",
"async-exit-hook": "^2.0.1",
"aws-sdk": "^2.141.0",
"aws-sdk": "^2.143.0",
"bluebird-lst": "^1.0.5",
"chalk": "^2.3.0",
"chromium-pickle-js": "^0.2.0",
Expand Down Expand Up @@ -104,7 +104,7 @@
"jsdoc-to-markdown": "^3.0.0",
"path-sort": "^0.1.0",
"serve-static": "^1.13.1",
"ts-babel": "^4.1.7",
"ts-babel": "^4.1.8",
"ts-jsdoc": "^2.0.6",
"tslint": "^5.8.0",
"typescript": "^2.6.1",
Expand Down
18 changes: 7 additions & 11 deletions packages/electron-builder/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export interface BuildOptions extends PackagerOptions, PublishOptions {
}

export interface CliOptions extends PackagerOptions, PublishOptions {
mac?: Array<string>
linux?: Array<string>
win?: Array<string>

arch?: string

x64?: boolean
Expand All @@ -31,8 +27,6 @@ export interface CliOptions extends PackagerOptions, PublishOptions {
platform?: string

project?: string

extraMetadata?: any
}

/** @internal */
Expand Down Expand Up @@ -157,8 +151,10 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
delete result.project

let config = result.config
const extraMetadata = result.extraMetadata
delete result.extraMetadata
const deprecatedExtraMetadata = r.extraMetadata
if (deprecatedExtraMetadata != null) {
delete r.extraMetadata
}

// config is array when combining dot-notation values with a config file value (#2016)
if (Array.isArray(config)) {
Expand All @@ -177,20 +173,20 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
result.config = newConfig
}

if (extraMetadata != null) {
if (deprecatedExtraMetadata != null) {
if (typeof config === "string") {
// transform to object and specify path to config as extends
config = {
extends: config,
extraMetadata,
extraMetadata: deprecatedExtraMetadata,
};
(result as any).config = config
}
else if (config == null) {
config = {};
(result as any).config = config
}
(config as any).extraMetadata = extraMetadata
(config as any).extraMetadata = deprecatedExtraMetadata
}

if (config != null && typeof config !== "string") {
Expand Down
53 changes: 52 additions & 1 deletion packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, AsyncTaskManager, debug, DebugLogger, exec, log, safeStringifyJson, TmpDir, use, serializeToYaml } from "builder-util"
import { Arch, AsyncTaskManager, debug, DebugLogger, exec, log, safeStringifyJson, TmpDir, use, serializeToYaml, addValue, archFromString } from "builder-util"
import { CancellationToken } from "builder-util-runtime"
import { executeFinally, orNullIfFileNotExist } from "builder-util/out/promise"
import { EventEmitter } from "events"
Expand Down Expand Up @@ -90,6 +90,57 @@ export class Packager {
throw new Error("extraMetadata in the options is deprecated, please use config.extraMetadata instead")
}

const targets = options.targets || new Map<Platform, Map<Arch, Array<string>>>()
if (options.targets == null) {
options.targets = targets
}

function processTargets(platform: Platform, types: Array<string>) {
function commonArch(currentIfNotSpecified: boolean): Array<Arch> {
if (platform === Platform.MAC) {
return currentIfNotSpecified ? [Arch.x64] : []
}

const result = Array<Arch>()
return result.length === 0 && currentIfNotSpecified ? [archFromString(process.arch)] : result
}

let archToType = targets.get(platform)
if (archToType == null) {
archToType = new Map<Arch, Array<string>>()
targets.set(platform, archToType)
}

if (types.length === 0) {
for (const arch of commonArch(false)) {
archToType.set(arch, [])
}
return
}

for (const type of types) {
const suffixPos = type.lastIndexOf(":")
if (suffixPos > 0) {
addValue(archToType, archFromString(type.substring(suffixPos + 1)), type.substring(0, suffixPos))
}
else {
for (const arch of commonArch(true)) {
addValue(archToType, arch, type)
}
}
}
}

if (options.mac != null) {
processTargets(Platform.MAC, options.mac)
}
if (options.linux != null) {
processTargets(Platform.LINUX, options.linux)
}
if (options.win != null) {
processTargets(Platform.WINDOWS, options.win)
}

this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir)
this.options = {
...options,
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/packagerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { UploadTask } from "electron-publish"
export interface PackagerOptions {
targets?: Map<Platform, Map<Arch, Array<string>>>

mac?: Array<string>
linux?: Array<string>
win?: Array<string>

projectDir?: string | null

cscLink?: string | null
Expand Down
13 changes: 7 additions & 6 deletions packages/electron-builder/src/targets/AppImageTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export default class AppImageTarget extends Target {

// https://github.com/electron-userland/electron-builder/issues/775
// https://github.com/electron-userland/electron-builder/issues/1726
const artifactName = this.options.artifactName == null ? packager.computeSafeArtifactName(null, "AppImage", arch, false)!! : packager.expandArtifactNamePattern(this.options, "AppImage", arch)
const resultFile = path.join(this.outDir, artifactName)
// tslint:disable-next-line:no-invalid-template-strings
const artifactName = packager.expandArtifactNamePattern(this.options, "AppImage", arch, "${name}-${version}-${arch}.${ext}", false)
const artifactPath = path.join(this.outDir, artifactName)

// pax doesn't like dir with leading dot (e.g. `.__appimage`)
const stageDir = path.join(this.outDir, `__appimage-${Arch[arch]}`)
Expand All @@ -55,7 +56,7 @@ export default class AppImageTarget extends Target {

const finalDesktopFilename = `${this.packager.executableName}.desktop`
await BluebirdPromise.all([
unlinkIfExists(resultFile),
unlinkIfExists(artifactPath),
writeFile(path.join(stageDir, "/AppRun"), (await appRunTemplate.value)({
systemIntegration: this.options.systemIntegration || "ask",
desktopFileName: finalDesktopFilename,
Expand Down Expand Up @@ -101,7 +102,7 @@ export default class AppImageTarget extends Target {
if (packager.compression === "maximum") {
args.push("--comp", "xz")
}
args.push(stageDir, resultFile)
args.push(stageDir, artifactPath)
await exec(path.join(vendorToolDir, "appimagetool"), args, {
env: {
...process.env,
Expand All @@ -114,15 +115,15 @@ export default class AppImageTarget extends Target {
await remove(stageDir)
}

const blockMapInfo = await createDifferentialPackage(resultFile)
const blockMapInfo = await createDifferentialPackage(artifactPath)
const updateInfo: BlockMapDataHolder = {
size: blockMapInfo.size,
blockMapSize: blockMapInfo.blockMapSize,
sha512: blockMapInfo.sha512,
}

packager.info.dispatchArtifactCreated({
file: resultFile,
file: artifactPath,
safeArtifactName: packager.computeSafeArtifactName(artifactName, "AppImage", arch, false),
target: this,
arch,
Expand Down
17 changes: 12 additions & 5 deletions packages/electron-builder/src/targets/ArchiveTarget.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Arch, log } from "builder-util"
import * as path from "path"
import { Platform, Target } from "../core"
import { Platform, Target, TargetSpecificOptions } from "../core"
import { PlatformPackager } from "../platformPackager"
import { archive, tar } from "./archive"

export class ArchiveTarget extends Target {
readonly options = (this.packager.config as any)[this.name]
readonly options: TargetSpecificOptions = (this.packager.config as any)[this.name]

constructor(name: string, readonly outDir: string, private readonly packager: PlatformPackager<any>, private readonly isWriteUpdateInfo = false) {
super(name)
Expand All @@ -17,9 +17,16 @@ export class ArchiveTarget extends Target {
const format = this.name
log(`Building ${isMac ? "macOS " : ""}${format}`)

// do not specify arch if x64
// tslint:disable:no-invalid-template-strings
const artifactPath = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, format, arch, packager.platform === Platform.LINUX ? "${name}-${version}-${arch}.${ext}" : "${productName}-${version}-${arch}-${os}.${ext}"))
let defaultPattern: string
if (packager.platform === Platform.LINUX) {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${name}-${version}" + (arch === Arch.x64 ? "" : "-${arch}") + ".${ext}"
}
else {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${productName}-${version}" + (arch === Arch.x64 ? "" : "-${arch}") + "-${os}.${ext}"
}
const artifactPath = path.join(this.outDir, packager.expandArtifactNamePattern(this.options, format, arch, defaultPattern, false))
if (format.startsWith("tar.")) {
await tar(packager.compression, format, artifactPath, appOutDir, isMac, packager.info.tempDirManager)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.4.4",
"aws-sdk": "^2.141.0",
"aws-sdk": "^2.143.0",
"mime": "^2.0.3",
"electron-publish": "~0.0.0-semantic-release",
"builder-util": "^0.0.0-semantic-release",
Expand Down
24 changes: 24 additions & 0 deletions test/out/windows/__snapshots__/winPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,27 @@ Object {
],
}
`;
exports[`zip artifactName 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "Test App ßW-1.1.0-linux-x86_64.AppImage",
"safeArtifactName": "TestApp-1.1.0-x86_64.AppImage",
"updateInfo": Object {
"blockMapSize": "@blockMapSize",
"sha512": "@sha512",
"size": "@size",
},
},
],
"win": Array [
Object {
"arch": "x64",
"file": "Test App ßW-1.1.0-win-x64.zip",
"safeArtifactName": "TestApp-1.1.0-win.zip",
},
],
}
`;
13 changes: 11 additions & 2 deletions test/src/windows/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ test.ifWinCi("beta version", app({
}))

test.ifNotCiMac("win zip", app({
targets: Platform.WINDOWS.createTarget(["zip", ]),
targets: Platform.WINDOWS.createTarget(["zip"]),
}))

test.ifNotCiMac.ifAll("zip artifactName", app({
linux: ["appimage"],
win: ["zip"],
config: {
//tslint:disable-next-line:no-invalid-template-strings
artifactName: "${productName}-${version}-${os}-${arch}.${ext}",
},
}))

test.ifNotCiMac("icon < 256", appThrows(platform(Platform.WINDOWS), {
Expand All @@ -34,7 +43,7 @@ test.ifMac("custom icon", () => {
let platformPackager: CheckingWinPackager | null = null
return assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget("squirrel"),
platformPackagerFactory: (packager, platform) => platformPackager = new CheckingWinPackager(packager),
platformPackagerFactory: packager => platformPackager = new CheckingWinPackager(packager),
config: {
win: {
icon: "customIcon",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"

aws-sdk@^2.141.0:
version "2.142.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.142.0.tgz#efdf69d2be3132aa51d4e7abb2c28fe42771e3ec"
aws-sdk@^2.143.0:
version "2.143.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.143.0.tgz#751068bd4cf13d3265f6da1b0254903be4bac8ee"
dependencies:
buffer "4.9.1"
crypto-browserify "1.0.9"
Expand Down Expand Up @@ -4783,12 +4783,12 @@ truncate-utf8-bytes@^1.0.0:
dependencies:
utf8-byte-length "^1.0.1"

ts-babel@^4.1.7:
version "4.1.7"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-4.1.7.tgz#b95fe9bbafa43ea18c494777a3011270ebd9f8a3"
ts-babel@^4.1.8:
version "4.1.8"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-4.1.8.tgz#9900be30a153d36a7fe6c465d5d3f9611a3bb655"
dependencies:
babel-core "^6.26.0"
bluebird-lst "^1.0.4"
bluebird-lst "^1.0.5"
fs-extra-p "^4.4.4"
source-map-support "^0.5.0"
v8-compile-cache "^1.1.0"
Expand Down

0 comments on commit 48f5036

Please sign in to comment.