Skip to content

Commit a3bbb3f

Browse files
committed
fix: check that description is not empty
Closes #392
1 parent b2ab07f commit a3bbb3f

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"deep-assign": "^2.0.0",
6868
"electron-osx-sign-tf": "0.4.0-beta.0",
6969
"electron-packager-tf": "~7.1.0",
70-
"electron-winstaller-fixed": "~2.8.3",
70+
"electron-winstaller-fixed": "~2.9.0",
7171
"fs-extra-p": "^1.0.1",
7272
"globby": "^4.1.0",
7373
"hosted-git-info": "^2.1.5",

src/packager.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,22 @@ export class Packager implements BuildInfo {
126126

127127
private checkMetadata(appPackageFile: string, devAppPackageFile: string, platforms: Array<Platform>): void {
128128
const reportError = (missedFieldName: string) => {
129-
throw new Error("Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')")
129+
throw new Error(`Please specify '${missedFieldName}' in the application package.json ('${appPackageFile}')`)
130130
}
131131

132-
const appMetadata = this.metadata
133-
if (<any>appMetadata.name == null) {
134-
reportError("name")
135-
}
136-
else if (<any>appMetadata.description == null) {
137-
reportError("description")
138-
}
139-
else if (<any>appMetadata.version == null) {
140-
reportError("version")
132+
const checkNotEmpty = (name: string, value: string) => {
133+
if (isEmptyOrSpaces(value)) {
134+
reportError(name)
135+
}
141136
}
142-
else if ((<any>appMetadata) !== this.devMetadata) {
137+
138+
const appMetadata = this.metadata
139+
140+
checkNotEmpty("name", appMetadata.name)
141+
checkNotEmpty("description", appMetadata.description)
142+
checkNotEmpty("version", appMetadata.version)
143+
144+
if ((<any>appMetadata) !== this.devMetadata) {
143145
if ((<any>appMetadata).build != null) {
144146
throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile))
145147
}
@@ -251,4 +253,8 @@ async function checkWineVersion(checkPromise: Promise<Buffer[]>) {
251253
if (compareVersions(wineVersion, "1.8") === -1) {
252254
throw new Error(wineError(`wine 1.8+ is required, but your version is ${wineVersion}`))
253255
}
256+
}
257+
258+
function isEmptyOrSpaces(s: string | n) {
259+
return s == null || s.trim().length === 0
254260
}

test/src/BuildTest.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ test("name in the build", t => t.throws(assertPack("test-app-one", currentPlatfo
5555
})
5656
}), /'name' in the 'build' is forbidden/))
5757

58+
test("empty description", t => t.throws(assertPack("test-app-one", {
59+
platform: [Platform.LINUX],
60+
devMetadata: <any>{
61+
description: "",
62+
}
63+
}), /Please specify 'description'/))
64+
5865
test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatforms(false), {
5966
tempDirCreated: projectDir => modifyPackageJson(projectDir, data => {
6067
data.main = "main.js"

0 commit comments

Comments
 (0)