From e4eefb2001782c0e8f4e82301838fd446b5af792 Mon Sep 17 00:00:00 2001 From: develar Date: Mon, 23 May 2016 08:48:06 +0200 Subject: [PATCH] fix: forbid name in the build Close #360 --- package.json | 2 +- src/errorMessages.ts | 5 ++++ src/packager.ts | 8 +++++-- src/platformPackager.ts | 1 + test/src/BuildTest.ts | 51 +++++++++++++++++++++++------------------ 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 577da77fe52..96f67649669 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "install-app-deps": "./out/install-app-deps.js" }, "scripts": { - "compile": "npm run whitespace && npm run compile-production && npm run compile-test", + "compile": "npm run compile-production && npm run compile-test", "compile-production": "tsconfig -i 2 && ts-babel", "compile-test": "tsconfig -i 2 test && ts-babel test", "lint": "tslint src/*.ts test/src/*.ts", diff --git a/src/errorMessages.ts b/src/errorMessages.ts index 4b0cc7720c6..d28db3b7bc0 100644 --- a/src/errorMessages.ts +++ b/src/errorMessages.ts @@ -21,4 +21,9 @@ It is required to set Linux .deb package maintainer. Or you can set maintainer i export const buildInAppSpecified = `'build' in the application package.json ('%s') is not supported since 3.0 anymore Please move 'build' into the development package.json ('%s') +` + +export const nameInBuildSpecified = `'name' in the 'build' is forbidden + +Please move 'name' from 'build' into the application package.json ('%s') ` \ No newline at end of file diff --git a/src/packager.ts b/src/packager.ts index 158fe2d7793..ca4dd75c3f7 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -163,6 +163,10 @@ export class Packager implements BuildInfo { else if (this.options.dist && author.email == null && platforms.includes(Platform.LINUX)) { throw new Error(util.format(errorMessages.authorEmailIsMissed, appPackageFile)) } + + if ((this.devMetadata.build).name != null) { + throw new Error(util.format(errorMessages.nameInBuildSpecified, appPackageFile)) + } } } @@ -215,8 +219,8 @@ export function normalizePlatforms(rawPlatforms: Array | stri } function checkConflictingOptions(options: any) { - for (let name of ["all", "out", "tmpdir", "version", "platform", "dir", "arch"]) { - if (name! in options) { + for (let name of ["all", "out", "tmpdir", "version", "platform", "dir", "arch", "name"]) { + if (name in options) { throw new Error(`Option ${name} is ignored, do not specify it.`) } } diff --git a/src/platformPackager.ts b/src/platformPackager.ts index 2a3257111a9..7bb04caf0f0 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -152,6 +152,7 @@ export abstract class PlatformPackager dir: this.info.appDir, out: outDir, name: this.appName, + productName: this.appName, platform: this.platform.nodeName, arch: arch, version: this.info.electronVersion, diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index fc8c45cad64..f573ffc6be1 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -11,7 +11,7 @@ import pathSorter = require("path-sort") //noinspection JSUnusedLocalSymbols const __awaiter = require("out/awaiter") -test("custom buildResources dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), { +test("custom buildResources dir", () => assertPack("test-app-one", allPlatforms(), { tempDirCreated: projectDir => BluebirdPromise.all([ modifyPackageJson(projectDir, data => { data.directories = { @@ -22,7 +22,7 @@ test("custom buildResources dir", () => assertPack("test-app-one", allPlatformsA ]) })) -test("custom output dir", () => assertPack("test-app-one", allPlatformsAndCurrentArch(false), { +test("custom output dir", () => assertPack("test-app-one", allPlatforms(false), { tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { data.directories = { output: "customDist" @@ -33,27 +33,35 @@ test("custom output dir", () => assertPack("test-app-one", allPlatformsAndCurren } })) -test("productName with space", () => assertPack("test-app-one", allPlatformsAndCurrentArch(), { +test("productName with space", () => assertPack("test-app-one", allPlatforms(), { tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { - data.productName = "Test App" + data.productName = "Test App Cool" }) })) -test("build in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(), { - tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { +test("build in the app package.json", t => t.throws(assertPack("test-app", allPlatforms(), { + tempDirCreated: it => modifyPackageJson(it, data => { data.build = { "iconUrl": "bar", } }, true) }), /'build' in the application package\.json .+/)) -test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), { +test("name in the build", t => t.throws(assertPack("test-app-one", currentPlatform(), { + tempDirCreated: it => modifyPackageJson(it, data => { + data.build = { + "name": "Cool App", + } + }) +}), /'name' in the 'build' is forbidden/)) + +test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatforms(false), { tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { data.main = "main.js" }, true) }), "Application entry file main.js could not be found in package. Seems like a wrong configuration.")) -test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), { +test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", allPlatforms(false), { tempDirCreated: projectDir => { return BluebirdPromise.all([ modifyPackageJson(projectDir, data => { @@ -66,7 +74,7 @@ test("invalid main in the app package.json (no asar)", t => t.throws(assertPack( } }), "Application entry file main.js could not be found in package. Seems like a wrong configuration.")) -test("main in the app package.json (no asar)", () => assertPack("test-app", allPlatformsAndCurrentArch(false), { +test("main in the app package.json (no asar)", () => assertPack("test-app", allPlatforms(false), { tempDirCreated: projectDir => { return BluebirdPromise.all([ move(path.join(projectDir, "app", "index.js"), path.join(projectDir, "app", "main.js")), @@ -80,16 +88,13 @@ test("main in the app package.json (no asar)", () => assertPack("test-app", allP } })) -test("relative index", () => assertPack("test-app", allPlatformsAndCurrentArch(false), { +test("relative index", () => assertPack("test-app", allPlatforms(false), { tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { data.main = "./index.js" }, true) })) -test("version from electron-prebuilt dependency", () => assertPack("test-app-one", { - platform: [Platform.fromString(process.platform)], - dist: false -}, { +test("version from electron-prebuilt dependency", () => assertPack("test-app-one", currentPlatform(false), { tempDirCreated: projectDir => BluebirdPromise.all([ outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), { version: "0.37.8" @@ -100,15 +105,13 @@ test("version from electron-prebuilt dependency", () => assertPack("test-app-one ]) })) -test("www as default dir", () => assertPack("test-app", { - platform: [Platform.fromString(process.platform)], -}, { +test("www as default dir", () => assertPack("test-app", currentPlatform(), { tempDirCreated: projectDir => move(path.join(projectDir, "app"), path.join(projectDir, "www")) })) test("afterPack", t => { let called = false - return assertPack("test-app", { + return assertPack("test-app-one", { // linux pack is very fast, so, we use it :) platform: [Platform.LINUX], dist: true, @@ -199,13 +202,17 @@ test("invalid platform", t => t.throws(assertPack("test-app-one", { dist: false }), "Unknown platform: null")) -function allPlatformsAndCurrentArch(dist: boolean = true): PackagerOptions { +function allPlatforms(dist: boolean = true): PackagerOptions { return { platform: getPossiblePlatforms(), dist: dist, - // speed up tests - cscLink: null, - cscInstallerLink: null, + } +} + +function currentPlatform(dist: boolean = true): PackagerOptions { + return { + platform: [Platform.fromString(process.platform)], + dist: dist, } }