Skip to content

Commit

Permalink
fix: forbid name in the build
Browse files Browse the repository at this point in the history
Close #360
  • Loading branch information
develar committed May 23, 2016
1 parent 50d31f1 commit e4eefb2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
`
8 changes: 6 additions & 2 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ export class Packager implements BuildInfo {
else if (this.options.dist && <any>author.email == null && platforms.includes(Platform.LINUX)) {
throw new Error(util.format(errorMessages.authorEmailIsMissed, appPackageFile))
}

if ((<any>this.devMetadata.build).name != null) {
throw new Error(util.format(errorMessages.nameInBuildSpecified, appPackageFile))
}
}
}

Expand Down Expand Up @@ -215,8 +219,8 @@ export function normalizePlatforms(rawPlatforms: Array<string | Platform> | 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.`)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
dir: this.info.appDir,
out: outDir,
name: this.appName,
productName: this.appName,
platform: this.platform.nodeName,
arch: arch,
version: this.info.electronVersion,
Expand Down
51 changes: 29 additions & 22 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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"
Expand All @@ -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 => {
Expand All @@ -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")),
Expand All @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit e4eefb2

Please sign in to comment.