Skip to content

Commit 3fba451

Browse files
committed
feat: use read-package-json as a correct fix of Linux maintainer .deb package field
1 parent daacc00 commit 3fba451

17 files changed

+75
-72
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
var platforms = require( './lib/platforms' );
1111
var path = require( 'path' );
1212
var fs = require( 'fs' );
13-
var mkdirp = require( 'mkdirp' );
13+
var fse = require( 'fs-extra' );
1414

1515

1616
/**
@@ -45,7 +45,7 @@ var Builder = {
4545
// directory exists
4646
if ( !fs.existsSync( options.out ) ) {
4747
options.log( '- Ouput directory ´' + options.out + '´ does not exist ' );
48-
mkdirp.sync( options.out );
48+
fse.mkdirsSync( options.out );
4949
options.log( '- Created ´' + options.out + '´ ' );
5050
}
5151

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@
5757
"fs-extra": "^0.26.5",
5858
"gm": "^1.21.1",
5959
"hosted-git-info": "^2.1.4",
60-
"json-parse-helpfulerror": "^1.0.3",
6160
"lodash.camelcase": "^4.1.0",
6261
"lodash.template": "^4.2.0",
6362
"meow": "^3.7.0",
6463
"mime": "^1.3.4",
65-
"mkdirp": "^0.5.1",
6664
"progress": "^1.1.8",
6765
"progress-stream": "^1.2.0",
6866
"rimraf": "^2.5.1",
@@ -77,20 +75,21 @@
7775
"babel-plugin-array-includes": "^2.0.3",
7876
"babel-plugin-transform-es2015-parameters": "^6.5.0",
7977
"dts-generator-tf": "^1.7.0-beta.0",
80-
"eslint": "^2.1.0",
78+
"eslint": "^2.2.0",
8179
"path-sort": "^0.1.0",
8280
"plist": "^1.2.0",
8381
"proxyquire": "^1.7.4",
8482
"publish-please": "^1.1.0",
83+
"read-package-json": "^2.0.3",
8584
"rimraf": "^2.5.2",
8685
"should": "^8.2.2",
8786
"tap-nyan": "0.0.2",
8887
"tap-spec": "^4.1.1",
8988
"tape": "^4.4.0",
9089
"ts-babel": "^0.3.0",
9190
"tsconfig-glob": "^0.4.1",
92-
"tslint": "^3.3.0",
93-
"typescript": "^1.8.0-beta"
91+
"tslint": "^3.4.0",
92+
"typescript": "^1.8.2"
9493
},
9594
"babel": {
9695
"plugins": [

src/errorMessages.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ export const buildIsMissed = `Please specify 'build' configuration in the applic
88
}
99
1010
is required.
11+
`
12+
13+
export const authorEmailIsMissed = `Please specify author 'email' in the application package.json ('%s')
14+
15+
See https://docs.npmjs.com/files/package.json#people-fields-author-contributors
16+
17+
It is required to set Linux .deb package maintainer. Or you can set maintainer in the custom linux options.
18+
(see https://github.com/loopline-systems/electron-builder#distributable-format-configuration).
1119
`

src/install-app-deps.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#! /usr/bin/env node
22

3-
import { DEFAULT_APP_DIR_NAME, installDependencies, commonArgs, getElectronVersion } from "./util"
4-
import { parseJson } from "./promisifed-fs"
3+
import { DEFAULT_APP_DIR_NAME, installDependencies, commonArgs, getElectronVersion, readPackageJson } from "./util"
54
import { printErrorAndExit } from "./promise"
6-
import { readFileSync } from "fs"
75
import * as path from "path"
86
import cla = require("command-line-args")
97

@@ -13,7 +11,8 @@ const args = cla(commonArgs.concat({
1311
})).parse()
1412

1513
const devPackageFile = path.join(process.cwd(), "package.json")
16-
1714
const appDir = args.appDir || DEFAULT_APP_DIR_NAME
18-
installDependencies(path.join(process.cwd(), appDir), args.arch, getElectronVersion(parseJson(readFileSync(devPackageFile, "utf8"), devPackageFile), devPackageFile))
15+
16+
readPackageJson(devPackageFile)
17+
.then(it => installDependencies(path.join(process.cwd(), appDir), args.arch, getElectronVersion(it, devPackageFile)))
1918
.catch(printErrorAndExit)

src/linuxPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class LinuxPackager extends PlatformPackager<DebOptions> {
6868
version: this.metadata.version,
6969
title: this.metadata.name,
7070
comment: this.metadata.description,
71-
maintainer: this.metadata.author,
71+
maintainer: `${this.metadata.author.name} <${this.metadata.author.email}>`,
7272
arch: this.currentArch === "ia32" ? 32 : 64,
7373
target: "deb",
7474
executable: this.metadata.name,

src/macPackager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
5050
}
5151

5252
packageInDistributableFormat(outDir: string, appOutDir: string): Promise<any> {
53-
const artifactPath = path.join(outDir, this.metadata.name + "-" + this.metadata.version + ".dmg")
53+
const artifactPath = path.join(appOutDir, this.metadata.name + "-" + this.metadata.version + ".dmg")
5454
return BluebirdPromise.all([
5555
new BluebirdPromise<any>((resolve, reject) => {
5656
log("Creating DMG")
@@ -80,8 +80,7 @@ export default class MacPackager extends PlatformPackager<appdmg.Specification>
8080

8181
specification.contents[1].path = path.join(appOutDir, this.metadata.name + ".app")
8282

83-
const appDmg = require("appdmg")
84-
const emitter = appDmg({
83+
const emitter = require("appdmg")({
8584
target: artifactPath,
8685
basepath: this.projectDir,
8786
specification: specification

src/packager.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fs from "fs"
22
import * as path from "path"
3-
import { DEFAULT_APP_DIR_NAME, installDependencies, log, getElectronVersion } from "./util"
4-
import { parseJsonFile } from "./promisifed-fs"
3+
import { DEFAULT_APP_DIR_NAME, installDependencies, log, getElectronVersion, readPackageJson } from "./util"
54
import { all, executeFinally } from "./promise"
65
import { EventEmitter } from "events"
76
import { Promise as BluebirdPromise } from "bluebird"
@@ -52,22 +51,23 @@ export class Packager implements BuildInfo {
5251
async build(): Promise<any> {
5352
const buildPackageFile = this.devPackageFile
5453
const appPackageFile = this.projectDir === this.appDir ? buildPackageFile : path.join(this.appDir, "package.json")
55-
await BluebirdPromise.all(Array.from(new Set([buildPackageFile, appPackageFile]), parseJsonFile))
56-
.then((result: any[]) => {
54+
const platforms = normalizePlatforms(this.options.platform)
55+
await BluebirdPromise.all(Array.from(new Set([buildPackageFile, appPackageFile]), readPackageJson))
56+
.then(result => {
5757
this.metadata = result[result.length - 1]
5858
this.devMetadata = result[0]
59-
this.checkMetadata(appPackageFile)
59+
this.checkMetadata(appPackageFile, platforms)
6060

6161
this.electronVersion = getElectronVersion(this.devMetadata, buildPackageFile)
6262
})
6363

6464
const cleanupTasks: Array<() => Promise<any>> = []
65-
return executeFinally(this.doBuild(cleanupTasks), error => all(cleanupTasks.map(it => it())))
65+
return executeFinally(this.doBuild(platforms, cleanupTasks), error => all(cleanupTasks.map(it => it())))
6666
}
6767

68-
private async doBuild(cleanupTasks: Array<() => Promise<any>>): Promise<any> {
68+
private async doBuild(platforms: Array<string>, cleanupTasks: Array<() => Promise<any>>): Promise<any> {
6969
const distTasks: Array<Promise<any>> = []
70-
for (let platform of normalizePlatforms(this.options.platform)) {
70+
for (let platform of platforms) {
7171
const helper = this.createHelper(platform, cleanupTasks)
7272
const archs = platform === "darwin" ? ["x64"] : (this.options.arch == null || this.options.arch === "all" ? ["ia32", "x64"] : [this.options.arch])
7373
for (let arch of archs) {
@@ -136,7 +136,7 @@ export class Packager implements BuildInfo {
136136
return absoluteAppPath
137137
}
138138

139-
private checkMetadata(appPackageFile: string): void {
139+
private checkMetadata(appPackageFile: string, platforms: Array<string>): void {
140140
const reportError = (missedFieldName: string) => {
141141
throw new Error("Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')")
142142
}
@@ -154,8 +154,14 @@ export class Packager implements BuildInfo {
154154
else if (metadata.build == null) {
155155
throw new Error(util.format(errorMessages.buildIsMissed, appPackageFile))
156156
}
157-
else if (metadata.author == null) {
158-
reportError("author")
157+
else {
158+
const author = metadata.author
159+
if (author == null) {
160+
reportError("author")
161+
}
162+
else if (this.options.dist && author.email == null && platforms.includes("linux")) {
163+
throw new Error(util.format(errorMessages.authorEmailIsMissed, appPackageFile))
164+
}
159165
}
160166
}
161167

src/platformPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export abstract class PlatformPackager<DC> implements ProjectMetadataProvider {
104104
"app-version": version,
105105
"build-version": buildVersion,
106106
"version-string": {
107-
CompanyName: this.metadata.author,
107+
CompanyName: this.metadata.author.name,
108108
FileDescription: this.metadata.description,
109109
ProductVersion: version,
110110
FileVersion: buildVersion,

src/promisifed-fs.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
11
import * as fs from "fs"
2-
import { parse as _parseJson } from "json-parse-helpfulerror"
32
import { Promise as BluebirdPromise } from "bluebird"
4-
import rimraf = require("rimraf")
53

64
const readFileAsync: ((filename: string, encoding?: string) => Promise<string | Buffer>) = BluebirdPromise.promisify(fs.readFile)
7-
const writeFileAsync = BluebirdPromise.promisify(fs.writeFile)
85

96
export function readText(file: string): BluebirdPromise<string> {
107
return <BluebirdPromise<string>>readFileAsync(file, "utf8")
118
}
129

13-
export function readBytes(file: string): BluebirdPromise<Buffer> {
14-
return <BluebirdPromise<Buffer>>readFileAsync(file)
15-
}
16-
17-
export function writeFile(path: string, data: string | Buffer): BluebirdPromise<any> {
18-
return writeFileAsync(path, data)
19-
}
20-
21-
export function parseJsonFile(file: string): BluebirdPromise<any> {
22-
return readText(file).
23-
then(it => parseJson(it, file))
24-
}
25-
26-
export function parseJson(data: string, path: string): any {
27-
try {
28-
return _parseJson(data)
29-
}
30-
catch (e) {
31-
if (e instanceof SyntaxError) {
32-
throw new Error("Cannot parse '" + path + "': " + e.message)
33-
}
34-
else {
35-
throw e
36-
}
37-
}
38-
}
39-
4010
export function deleteFile(path: string, ignoreIfNotExists: boolean = false): BluebirdPromise<any> {
4111
return new BluebirdPromise<any>((resolve, reject) => {
4212
fs.unlink(path, it => it == null || (ignoreIfNotExists && it.code === "ENOENT") ? resolve(null) : reject(it))
4313
})
4414
}
4515

46-
export function deleteDirectory(path: string) {
47-
return new BluebirdPromise<any>((resolve, reject) => {
48-
rimraf(path, {glob: false}, error => error == null ? resolve(null) : reject(error))
49-
})
50-
}
51-
5216
// returns new name
5317
export function renameFile(oldPath: string, newPath: string): BluebirdPromise<string> {
5418
return new BluebirdPromise<any>((resolve, reject) => {

src/repositoryInfo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ export interface Metadata {
1414
repository: string | RepositoryInfo
1515
}
1616

17+
export interface MetadataAuthor {
18+
name: string
19+
email: string
20+
}
21+
1722
export interface AppMetadata extends Metadata {
1823
version: string
1924
name: string
2025
description: string
21-
author: string
26+
author: MetadataAuthor
2227

2328
build: BuildMetadata
2429

0 commit comments

Comments
 (0)