Skip to content

Commit

Permalink
fix(config): use json5 parser for json5 build configs
Browse files Browse the repository at this point in the history
Use json5 parser to parse json5 build configs (i. e. files ending on
"json5").
Json5 can have javascript-style comments whereas yaml does not. Thus we
cannot use the yaml parser for json5.

Close #1569, #1578
black-snow authored and develar committed May 23, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a41936b commit 94d89eb
Showing 7 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -16,9 +16,8 @@ language: c
cache:
directories:
- node_modules
- packages/electron-builder/node_modules
- packages/electron-builder-util/node_modules
- $HOME/Library/Caches/electron
- $HOME/Library/Caches/electron-builder
- /tmp/jest-electron-builder-tests

before_install:
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ platform:
cache:
- node_modules
- '%LOCALAPPDATA%\electron\Cache'
- '%LOCALAPPDATA%\electron-builder\cache'

environment:
TEST_FILES: ExtraBuildTest,BuildTest,extraMetadataTest,filesTest,globTest,nsisUpdaterTest,oneClickInstallerTest,installerTest
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.8.4",
"json5": "^0.5.1",
"mime": "^1.3.6",
"minimatch": "^3.0.4",
"node-emoji": "^1.5.1",
1 change: 1 addition & 0 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.8.4",
"json5": "^0.5.1",
"minimatch": "^3.0.4",
"node-forge": "^0.7.1",
"normalize-package-data": "^2.3.8",
4 changes: 3 additions & 1 deletion packages/electron-builder/src/util/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { debug } from "electron-builder-util"
import { log, warn } from "electron-builder-util/out/log"
import { readFile, readJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import JSON5 from "json5"
import * as path from "path"
import { readAsarJson } from "../asar"
import { Config } from "../metadata"
@@ -45,7 +46,8 @@ function getConfigFromPackageData(metadata: any) {
}

export async function doLoadConfig(configFile: string, projectDir: string) {
const result = safeLoad(await readFile(configFile, "utf8"))
const data = await readFile(configFile, "utf8")
const result = configFile.endsWith(".json5") ? JSON5.parse(data) : safeLoad(data)
const relativePath = path.relative(projectDir, configFile)
log(`Using ${relativePath.startsWith("..") ? configFile : relativePath} configuration file`)
return result
4 changes: 4 additions & 0 deletions typings/json5.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "json5" {
const json5: JSON
export default json5
}
8 changes: 2 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -2081,7 +2081,7 @@ json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"

json5@^0.5.0:
json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

@@ -2314,18 +2314,14 @@ minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

[email protected]:
[email protected], minimist@~0.0.1:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"

minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"

mkdirp2@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/mkdirp2/-/mkdirp2-1.0.3.tgz#cc8dd8265f1f06e2d8f5b10b6e52f4e050bed21b"

0 comments on commit 94d89eb

Please sign in to comment.