Skip to content

Commit 3fa6259

Browse files
committed
fix(deployment): warn if cannot resolve repository
1 parent 3cb5b93 commit 3fa6259

File tree

14 files changed

+263
-103
lines changed

14 files changed

+263
-103
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"ajv": "^5.0.2-beta",
2929
"ajv-keywords": "^2.0.1-beta.0",
3030
"archiver": "^1.3.0",
31-
"asar-electron-builder": "^0.13.5",
31+
"asar": "~0.13.0",
3232
"aws-sdk": "^2.17.0",
3333
"bluebird-lst": "^1.0.1",
3434
"chalk": "^1.1.3",

packages/electron-builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"ajv": "^5.0.2-beta",
4848
"ajv-keywords": "^2.0.1-beta.0",
4949
"7zip-bin": "^2.0.4",
50-
"asar-electron-builder": "^0.13.5",
50+
"asar": "~0.13.0",
5151
"bluebird-lst": "^1.0.1",
5252
"chalk": "^1.1.3",
5353
"chromium-pickle-js": "^0.2.0",

packages/electron-builder/src/asarUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AsarFileInfo, listPackage, statFile } from "asar-electron-builder"
1+
import { AsarFileInfo, listPackage, statFile } from "asar"
22
import BluebirdPromise from "bluebird-lst"
33
import { debug } from "electron-builder-util"
44
import { deepAssign } from "electron-builder-util/out/deepAssign"
@@ -10,7 +10,7 @@ import { AsarOptions } from "./metadata"
1010

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

1616
const NODE_MODULES_PATTERN = `${path.sep}node_modules${path.sep}`

packages/electron-builder/src/packager.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import Ajv from "ajv"
2-
import { extractFile } from "asar-electron-builder"
1+
import { extractFile } from "asar"
32
import BluebirdPromise from "bluebird-lst"
43
import { Arch, Platform, Target } from "electron-builder-core"
54
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
@@ -9,7 +8,6 @@ import { log, warn } from "electron-builder-util/out/log"
98
import { all, executeFinally } from "electron-builder-util/out/promise"
109
import { TmpDir } from "electron-builder-util/out/tmp"
1110
import { EventEmitter } from "events"
12-
import { readJson } from "fs-extra-p"
1311
import * as path from "path"
1412
import { lt as isVersionLessThan } from "semver"
1513
import { AppInfo } from "./appInfo"
@@ -19,7 +17,7 @@ import { ArtifactCreated, BuildInfo, PackagerOptions, SourceRepositoryInfo } fro
1917
import { PlatformPackager } from "./platformPackager"
2018
import { getRepositoryInfo } from "./repositoryInfo"
2119
import { createTargets } from "./targets/targetFactory"
22-
import { doLoadConfig, getElectronVersion, loadConfig, normaliseErrorMessages, readPackageJson } from "./util/readPackageJson"
20+
import { doLoadConfig, getElectronVersion, loadConfig, readPackageJson, validateConfig } from "./util/readPackageJson"
2321
import { WinPackager } from "./winPackager"
2422
import { getGypEnv, installOrRebuild } from "./yarn"
2523

@@ -130,14 +128,7 @@ export class Packager implements BuildInfo {
130128
}
131129
}
132130

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

142133
this._config = config
143134
this.appDir = await computeDefaultAppDirectory(projectDir, use(config.directories, it => it!.app))

packages/electron-builder/src/publish/publisher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { BintrayOptions, GenericServerOptions, GithubOptions, PublishConfiguration, S3Options } from "electron-builder-http/out/publishOptions"
2+
import { warn } from "electron-builder-util/out/log"
13
import { BuildInfo } from "../packagerApi"
2-
import { PublishConfiguration, GithubOptions, S3Options, BintrayOptions, GenericServerOptions } from "electron-builder-http/out/publishOptions"
34

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

26+
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`
2527
if (!errorIfCannot) {
28+
warn(message)
2629
return null
2730
}
2831

29-
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`)
32+
throw new Error(message)
3033
}
3134

3235
let owner = publishConfig.owner

packages/electron-builder/src/util/readPackageJson.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { extractFile } from "asar-electron-builder"
1+
import Ajv from "ajv"
2+
import { extractFile } from "asar"
23
import { log, warn } from "electron-builder-util/out/log"
34
import { readFile, readJson } from "fs-extra-p"
45
import { safeLoad } from "js-yaml"
@@ -130,7 +131,28 @@ function findFromElectronPrebuilt(packageData: any): any {
130131
return null
131132
}
132133

133-
export function normaliseErrorMessages(errors: Array<ErrorObject>) {
134+
let validatorPromise: Promise<any> | null = null
135+
136+
async function createConfigValidator() {
137+
const ajv = new Ajv({allErrors: true})
138+
ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"))
139+
require("ajv-keywords")(ajv, ["typeof"])
140+
const schema = await readJson(path.join(__dirname, "..", "..", "scheme.json"))
141+
return ajv.compile(schema)
142+
}
143+
144+
export async function validateConfig(config: Config) {
145+
if (validatorPromise == null) {
146+
validatorPromise = createConfigValidator()
147+
}
148+
149+
const validator = await validatorPromise
150+
if (!validator(config)) {
151+
throw new Error("Config is invalid:\n" + JSON.stringify(normaliseErrorMessages(validator.errors!), null, 2) + "\n\nRaw validation errors: " + JSON.stringify(validator.errors, null, 2))
152+
}
153+
}
154+
155+
function normaliseErrorMessages(errors: Array<ErrorObject>) {
134156
const result: any = Object.create(null)
135157
for (const e of errors) {
136158
if (e.keyword === "type" && (<TypeParams>e.params).type === "null") {

test/out/__snapshots__/BuildTest.js.snap

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,6 @@ Array [
256256
]
257257
`;
258258
259-
exports[`name in the build 1`] = `
260-
"Config is invalid:
261-
{
262-
\\"name\\": \\"Unknown option\\"
263-
}
264-
265-
Raw validation errors: [
266-
{
267-
\\"keyword\\": \\"additionalProperties\\",
268-
\\"dataPath\\": \\"\\",
269-
\\"schemaPath\\": \\"#/additionalProperties\\",
270-
\\"params\\": {
271-
\\"additionalProperty\\": \\"name\\"
272-
},
273-
\\"message\\": \\"should NOT have additional properties\\"
274-
}
275-
]"
276-
`;
277-
278259
exports[`scheme validation 1`] = `
279260
"Config is invalid:
280261
{

test/src/BuildTest.ts

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { extractFile } from "asar-electron-builder"
1+
import { extractFile } from "asar"
22
import BluebirdPromise from "bluebird-lst"
3-
import { Arch, BuildOptions, DIR_TARGET, PackagerOptions, Platform } from "electron-builder"
3+
import { Arch, BuildOptions, DIR_TARGET, Platform } from "electron-builder"
44
import { build, normalizeOptions } from "electron-builder/out/builder"
55
import { createYargs } from "electron-builder/out/cli/cliOptions"
66
import { checkWineVersion } from "electron-builder/out/packager"
@@ -9,7 +9,9 @@ import isCi from "is-ci"
99
import * as path from "path"
1010
import { ELECTRON_VERSION } from "./helpers/config"
1111
import { assertThat } from "./helpers/fileAssert"
12-
import { allPlatforms, app, appThrows, appTwoThrows, assertPack, getPossiblePlatforms, modifyPackageJson, packageJson } from "./helpers/packTester"
12+
import { allPlatforms, app, appThrows, appTwo, appTwoThrows, assertPack, getPossiblePlatforms, modifyPackageJson, packageJson } from "./helpers/packTester"
13+
14+
const linuxDirTarget = Platform.LINUX.createTarget(DIR_TARGET)
1315

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

83-
test("build in the app package.json", appTwoThrows(allPlatforms(), {
85+
test("build in the app package.json", appTwoThrows(linuxDirTarget, {
8486
projectDirCreated: it => modifyPackageJson(it, data => {
8587
data.build = {
8688
"iconUrl": "bar",
8789
}
8890
}, true)
8991
}))
9092

91-
test("name in the build", appThrows(currentPlatform(), {projectDirCreated: packageJson(it => it.build = {"name": "Cool App"})}))
92-
93-
test("relative index", () => assertPack("test-app", allPlatforms(false), {
93+
test("relative index", appTwo(allPlatforms(false), {
9494
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
9595
data.main = "./index.js"
9696
}, true)
9797
}))
9898

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

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

127127
test.ifDevOrLinuxCi("electron version from build", app({
128-
targets: Platform.LINUX.createTarget(DIR_TARGET),
128+
targets: linuxDirTarget,
129129
}, {
130130
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
131131
data.devDependencies = {}
132132
data.build.electronVersion = ELECTRON_VERSION
133133
})
134134
}))
135135

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

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

158158
test("beforeBuild", () => {
159-
const targets = isCi ? Platform.fromString(process.platform).createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
159+
const targets = isCi ? Platform.current().createTarget(DIR_TARGET) : getPossiblePlatforms(DIR_TARGET)
160160
let called = 0
161161
return assertPack("test-app-one", {
162162
targets: targets,
@@ -174,39 +174,31 @@ test("beforeBuild", () => {
174174
})
175175
})
176176

177-
test.ifDevOrLinuxCi("smart unpack", () => {
178-
return assertPack("test-app-one", {
179-
targets: Platform.LINUX.createTarget(DIR_TARGET),
180-
}, {
181-
npmInstallBefore: true,
182-
projectDirCreated: packageJson(it => {
183-
it.dependencies = {
184-
"debug": "^2.2.0",
185-
"edge-cs": "^1.0.0"
186-
}
187-
}),
188-
packed: context => {
189-
expect(JSON.parse(extractFile(path.join(context.getResources(Platform.LINUX), "app.asar"), "node_modules/debug/package.json").toString())).toMatchObject({
190-
name: "debug"
191-
})
192-
return BluebirdPromise.resolve()
177+
test.ifDevOrLinuxCi("smart unpack", app({
178+
targets: linuxDirTarget,
179+
}, {
180+
npmInstallBefore: true,
181+
projectDirCreated: packageJson(it => {
182+
it.dependencies = {
183+
"debug": "^2.2.0",
184+
"edge-cs": "^1.0.0"
193185
}
194-
})
195-
})
186+
}),
187+
packed: context => {
188+
expect(JSON.parse(extractFile(path.join(context.getResources(Platform.LINUX), "app.asar"), "node_modules/debug/package.json").toString())).toMatchObject({
189+
name: "debug"
190+
})
191+
return BluebirdPromise.resolve()
192+
}
193+
}))
196194

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

202-
function currentPlatform(): PackagerOptions {
203-
return {
204-
targets: Platform.fromString(process.platform).createTarget(DIR_TARGET),
205-
}
206-
}
207-
208200
test.ifDevOrLinuxCi("prepackaged", app({
209-
targets: Platform.LINUX.createTarget(DIR_TARGET),
201+
targets: linuxDirTarget,
210202
}, {
211203
packed: async (context) => {
212204
await build(normalizeOptions({
@@ -219,7 +211,7 @@ test.ifDevOrLinuxCi("prepackaged", app({
219211
}))
220212

221213
test.ifDevOrLinuxCi("scheme validation", appThrows({
222-
targets: Platform.LINUX.createTarget(DIR_TARGET),
214+
targets: linuxDirTarget,
223215
config: <any>{
224216
foo: 123,
225217
mac: {
@@ -229,7 +221,7 @@ test.ifDevOrLinuxCi("scheme validation", appThrows({
229221
}))
230222

231223
test.ifDevOrLinuxCi("scheme validation 2", appThrows({
232-
targets: Platform.LINUX.createTarget(DIR_TARGET),
224+
targets: linuxDirTarget,
233225
config: <any>{
234226
appId: 123,
235227
},

test/src/extraMetadataTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { extractFile } from "asar-electron-builder"
1+
import { extractFile } from "asar"
22
import { DIR_TARGET, Platform } from "electron-builder"
33
import * as path from "path"
44
import { assertThat } from "./helpers/fileAssert"

test/src/globTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { statFile } from "asar-electron-builder"
1+
import { statFile } from "asar"
22
import BluebirdPromise from "bluebird-lst"
33
import { DIR_TARGET, Platform } from "electron-builder"
44
import { mkdirs, outputFile, symlink, writeFile } from "fs-extra-p"

0 commit comments

Comments
 (0)