Skip to content

Commit

Permalink
fix(deployment): warn if cannot resolve repository
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 22, 2017
1 parent 3cb5b93 commit 3fa6259
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"ajv": "^5.0.2-beta",
"ajv-keywords": "^2.0.1-beta.0",
"archiver": "^1.3.0",
"asar-electron-builder": "^0.13.5",
"asar": "~0.13.0",
"aws-sdk": "^2.17.0",
"bluebird-lst": "^1.0.1",
"chalk": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ajv": "^5.0.2-beta",
"ajv-keywords": "^2.0.1-beta.0",
"7zip-bin": "^2.0.4",
"asar-electron-builder": "^0.13.5",
"asar": "~0.13.0",
"bluebird-lst": "^1.0.1",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/asarUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsarFileInfo, listPackage, statFile } from "asar-electron-builder"
import { AsarFileInfo, listPackage, statFile } from "asar"
import BluebirdPromise from "bluebird-lst"
import { debug } from "electron-builder-util"
import { deepAssign } from "electron-builder-util/out/deepAssign"
Expand All @@ -10,7 +10,7 @@ import { AsarOptions } from "./metadata"

const isBinaryFile: any = BluebirdPromise.promisify(require("isbinaryfile"))
const pickle = require ("chromium-pickle-js")
const Filesystem = require("asar-electron-builder/lib/filesystem")
const Filesystem = require("asar/lib/filesystem")
const UINT64 = require("cuint").UINT64

const NODE_MODULES_PATTERN = `${path.sep}node_modules${path.sep}`
Expand Down
15 changes: 3 additions & 12 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Ajv from "ajv"
import { extractFile } from "asar-electron-builder"
import { extractFile } from "asar"
import BluebirdPromise from "bluebird-lst"
import { Arch, Platform, Target } from "electron-builder-core"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
Expand All @@ -9,7 +8,6 @@ import { log, warn } from "electron-builder-util/out/log"
import { all, executeFinally } from "electron-builder-util/out/promise"
import { TmpDir } from "electron-builder-util/out/tmp"
import { EventEmitter } from "events"
import { readJson } from "fs-extra-p"
import * as path from "path"
import { lt as isVersionLessThan } from "semver"
import { AppInfo } from "./appInfo"
Expand All @@ -19,7 +17,7 @@ import { ArtifactCreated, BuildInfo, PackagerOptions, SourceRepositoryInfo } fro
import { PlatformPackager } from "./platformPackager"
import { getRepositoryInfo } from "./repositoryInfo"
import { createTargets } from "./targets/targetFactory"
import { doLoadConfig, getElectronVersion, loadConfig, normaliseErrorMessages, readPackageJson } from "./util/readPackageJson"
import { doLoadConfig, getElectronVersion, loadConfig, readPackageJson, validateConfig } from "./util/readPackageJson"
import { WinPackager } from "./winPackager"
import { getGypEnv, installOrRebuild } from "./yarn"

Expand Down Expand Up @@ -130,14 +128,7 @@ export class Packager implements BuildInfo {
}
}

const ajv = new Ajv({allErrors: true})
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"))
require("ajv-keywords")(ajv, ["typeof"])
const schema = await readJson(path.join(__dirname, "..", "scheme.json"))
const validator = ajv.compile(schema)
if (!validator(config)) {
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2) + "\n\nRaw validation errors: " + JSON.stringify(validator.errors, null, 2))
}
await validateConfig(config)

this._config = config
this.appDir = await computeDefaultAppDirectory(projectDir, use(config.directories, it => it!.app))
Expand Down
7 changes: 5 additions & 2 deletions packages/electron-builder/src/publish/publisher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BintrayOptions, GenericServerOptions, GithubOptions, PublishConfiguration, S3Options } from "electron-builder-http/out/publishOptions"
import { warn } from "electron-builder-util/out/log"
import { BuildInfo } from "../packagerApi"
import { PublishConfiguration, GithubOptions, S3Options, BintrayOptions, GenericServerOptions } from "electron-builder-http/out/publishOptions"

export async function getResolvedPublishConfig(packager: BuildInfo, publishConfig: PublishConfiguration, errorIfCannot: boolean): Promise<PublishConfiguration | null> {
if (publishConfig.provider === "generic") {
Expand All @@ -22,11 +23,13 @@ export async function getResolvedPublishConfig(packager: BuildInfo, publishConfi
return info
}

const message = `Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).\nPlease see https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts`
if (!errorIfCannot) {
warn(message)
return null
}

throw new Error(`Cannot detect repository by .git/config. Please specify "repository" in the package.json (https://docs.npmjs.com/files/package.json#repository).\nPlease see https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts`)
throw new Error(message)
}

let owner = publishConfig.owner
Expand Down
26 changes: 24 additions & 2 deletions packages/electron-builder/src/util/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { extractFile } from "asar-electron-builder"
import Ajv from "ajv"
import { extractFile } from "asar"
import { log, warn } from "electron-builder-util/out/log"
import { readFile, readJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
Expand Down Expand Up @@ -130,7 +131,28 @@ function findFromElectronPrebuilt(packageData: any): any {
return null
}

export function normaliseErrorMessages(errors: Array<ErrorObject>) {
let validatorPromise: Promise<any> | null = null

async function createConfigValidator() {
const ajv = new Ajv({allErrors: true})
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"))
require("ajv-keywords")(ajv, ["typeof"])
const schema = await readJson(path.join(__dirname, "..", "..", "scheme.json"))
return ajv.compile(schema)
}

export async function validateConfig(config: Config) {
if (validatorPromise == null) {
validatorPromise = createConfigValidator()
}

const validator = await validatorPromise
if (!validator(config)) {
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2) + "\n\nRaw validation errors: " + JSON.stringify(validator.errors, null, 2))
}
}

function normaliseErrorMessages(errors: Array<ErrorObject>) {
const result: any = Object.create(null)
for (const e of errors) {
if (e.keyword === "type" && (<TypeParams>e.params).type === "null") {
Expand Down
19 changes: 0 additions & 19 deletions test/out/__snapshots__/BuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,6 @@ Array [
]
`;
exports[`name in the build 1`] = `
"Config is invalid:
{
\\"name\\": \\"Unknown option\\"
}
Raw validation errors: [
{
\\"keyword\\": \\"additionalProperties\\",
\\"dataPath\\": \\"\\",
\\"schemaPath\\": \\"#/additionalProperties\\",
\\"params\\": {
\\"additionalProperty\\": \\"name\\"
},
\\"message\\": \\"should NOT have additional properties\\"
}
]"
`;
exports[`scheme validation 1`] = `
"Config is invalid:
{
Expand Down
72 changes: 32 additions & 40 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extractFile } from "asar-electron-builder"
import { extractFile } from "asar"
import BluebirdPromise from "bluebird-lst"
import { Arch, BuildOptions, DIR_TARGET, PackagerOptions, Platform } from "electron-builder"
import { Arch, BuildOptions, DIR_TARGET, Platform } from "electron-builder"
import { build, normalizeOptions } from "electron-builder/out/builder"
import { createYargs } from "electron-builder/out/cli/cliOptions"
import { checkWineVersion } from "electron-builder/out/packager"
Expand All @@ -9,7 +9,9 @@ import isCi from "is-ci"
import * as path from "path"
import { ELECTRON_VERSION } from "./helpers/config"
import { assertThat } from "./helpers/fileAssert"
import { allPlatforms, app, appThrows, appTwoThrows, assertPack, getPossiblePlatforms, modifyPackageJson, packageJson } from "./helpers/packTester"
import { allPlatforms, app, appThrows, appTwo, appTwoThrows, assertPack, getPossiblePlatforms, modifyPackageJson, packageJson } from "./helpers/packTester"

const linuxDirTarget = Platform.LINUX.createTarget(DIR_TARGET)

test("cli", async () => {
const yargs = createYargs()
Expand Down Expand Up @@ -80,24 +82,22 @@ test.ifNotWindows("custom buildResources and output dirs: mac", createBuildResou
test.ifNotCiMac("custom buildResources and output dirs: win", createBuildResourcesTest(Platform.WINDOWS))
test.ifNotWindows("custom buildResources and output dirs: linux", createBuildResourcesTest(Platform.LINUX))

test("build in the app package.json", appTwoThrows(allPlatforms(), {
test("build in the app package.json", appTwoThrows(linuxDirTarget, {
projectDirCreated: it => modifyPackageJson(it, data => {
data.build = {
"iconUrl": "bar",
}
}, true)
}))

test("name in the build", appThrows(currentPlatform(), {projectDirCreated: packageJson(it => it.build = {"name": "Cool App"})}))

test("relative index", () => assertPack("test-app", allPlatforms(false), {
test("relative index", appTwo(allPlatforms(false), {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.main = "./index.js"
}, true)
}))

it.ifDevOrLinuxCi("electron version from electron-prebuilt dependency", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
}, {
projectDirCreated: projectDir => BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
Expand All @@ -111,7 +111,7 @@ it.ifDevOrLinuxCi("electron version from electron-prebuilt dependency", app({
}))

test.ifDevOrLinuxCi("electron version from electron dependency", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
}, {
projectDirCreated: projectDir => BluebirdPromise.all([
outputJson(path.join(projectDir, "node_modules", "electron", "package.json"), {
Expand All @@ -125,20 +125,20 @@ test.ifDevOrLinuxCi("electron version from electron dependency", app({
}))

test.ifDevOrLinuxCi("electron version from build", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
}, {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.devDependencies = {}
data.build.electronVersion = ELECTRON_VERSION
})
}))

test("www as default dir", () => assertPack("test-app", currentPlatform(), {
test("www as default dir", appTwo(Platform.current().createTarget(DIR_TARGET), {
projectDirCreated: projectDir => move(path.join(projectDir, "app"), path.join(projectDir, "www"))
}))

test("afterPack", () => {
const targets = isCi ? Platform.fromString(process.platform).createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
const targets = isCi ? Platform.current().createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
let called = 0
return assertPack("test-app-one", {
targets: targets,
Expand All @@ -156,7 +156,7 @@ test("afterPack", () => {
})

test("beforeBuild", () => {
const targets = isCi ? Platform.fromString(process.platform).createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
const targets = isCi ? Platform.current().createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
let called = 0
return assertPack("test-app-one", {
targets: targets,
Expand All @@ -174,39 +174,31 @@ test("beforeBuild", () => {
})
})

test.ifDevOrLinuxCi("smart unpack", () => {
return assertPack("test-app-one", {
targets: Platform.LINUX.createTarget(DIR_TARGET),
}, {
npmInstallBefore: true,
projectDirCreated: packageJson(it => {
it.dependencies = {
"debug": "^2.2.0",
"edge-cs": "^1.0.0"
}
}),
packed: context => {
expect(JSON.parse(extractFile(path.join(context.getResources(Platform.LINUX), "app.asar"), "node_modules/debug/package.json").toString())).toMatchObject({
name: "debug"
})
return BluebirdPromise.resolve()
test.ifDevOrLinuxCi("smart unpack", app({
targets: linuxDirTarget,
}, {
npmInstallBefore: true,
projectDirCreated: packageJson(it => {
it.dependencies = {
"debug": "^2.2.0",
"edge-cs": "^1.0.0"
}
})
})
}),
packed: context => {
expect(JSON.parse(extractFile(path.join(context.getResources(Platform.LINUX), "app.asar"), "node_modules/debug/package.json").toString())).toMatchObject({
name: "debug"
})
return BluebirdPromise.resolve()
}
}))

test("wine version", async () => {
await checkWineVersion(BluebirdPromise.resolve("1.9.23 (Staging)"))
await checkWineVersion(BluebirdPromise.resolve("2.0-rc2"))
})

function currentPlatform(): PackagerOptions {
return {
targets: Platform.fromString(process.platform).createTarget(DIR_TARGET),
}
}

test.ifDevOrLinuxCi("prepackaged", app({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
}, {
packed: async (context) => {
await build(normalizeOptions({
Expand All @@ -219,7 +211,7 @@ test.ifDevOrLinuxCi("prepackaged", app({
}))

test.ifDevOrLinuxCi("scheme validation", appThrows({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
config: <any>{
foo: 123,
mac: {
Expand All @@ -229,7 +221,7 @@ test.ifDevOrLinuxCi("scheme validation", appThrows({
}))

test.ifDevOrLinuxCi("scheme validation 2", appThrows({
targets: Platform.LINUX.createTarget(DIR_TARGET),
targets: linuxDirTarget,
config: <any>{
appId: 123,
},
Expand Down
2 changes: 1 addition & 1 deletion test/src/extraMetadataTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractFile } from "asar-electron-builder"
import { extractFile } from "asar"
import { DIR_TARGET, Platform } from "electron-builder"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
Expand Down
2 changes: 1 addition & 1 deletion test/src/globTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { statFile } from "asar-electron-builder"
import { statFile } from "asar"
import BluebirdPromise from "bluebird-lst"
import { DIR_TARGET, Platform } from "electron-builder"
import { mkdirs, outputFile, symlink, writeFile } from "fs-extra-p"
Expand Down
2 changes: 2 additions & 0 deletions test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async function runTests() {
case "skipFpm": {
testPathIgnorePatterns.push("[\\/]{1}fpmTest.js$")
testPathIgnorePatterns.push("[\\/]{1}linuxArchiveTest.js$")
testPathIgnorePatterns.push("[\\/]{1}snapTest.js$")
config.cacheDirectory += `-${suffix}`
}
break
Expand All @@ -140,6 +141,7 @@ async function runTests() {

case "skipArtifactPublisher": {
testPathIgnorePatterns.push("[\\/]{1}ArtifactPublisherTest.js$")
testPathIgnorePatterns.push("[\\/]{1}httpRequestTest.js$")
config.cacheDirectory += `-${suffix}`
}
break
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/winHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractFile } from "asar-electron-builder"
import { extractFile } from "asar"
import BluebirdPromise from "bluebird-lst"
import { Arch, Platform } from "electron-builder-core"
import { walk } from "electron-builder-util/out/fs"
Expand Down
2 changes: 1 addition & 1 deletion typings/asar.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "asar-electron-builder" {
declare module "asar" {
interface AsarFileInfo {
offset: number
size: number
Expand Down
Loading

0 comments on commit 3fa6259

Please sign in to comment.