Skip to content

Commit 94d89eb

Browse files
black-snowdevelar
authored andcommitted
fix(config): use json5 parser for json5 build configs
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
1 parent a41936b commit 94d89eb

File tree

7 files changed

+13
-9
lines changed

7 files changed

+13
-9
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ language: c
1616
cache:
1717
directories:
1818
- node_modules
19-
- packages/electron-builder/node_modules
20-
- packages/electron-builder-util/node_modules
2119
- $HOME/Library/Caches/electron
20+
- $HOME/Library/Caches/electron-builder
2221
- /tmp/jest-electron-builder-tests
2322

2423
before_install:

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ platform:
44
cache:
55
- node_modules
66
- '%LOCALAPPDATA%\electron\Cache'
7+
- '%LOCALAPPDATA%\electron-builder\cache'
78

89
environment:
910
TEST_FILES: ExtraBuildTest,BuildTest,extraMetadataTest,filesTest,globTest,nsisUpdaterTest,oneClickInstallerTest,installerTest

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"is-ci": "^1.0.10",
4747
"isbinaryfile": "^3.0.2",
4848
"js-yaml": "^3.8.4",
49+
"json5": "^0.5.1",
4950
"mime": "^1.3.6",
5051
"minimatch": "^3.0.4",
5152
"node-emoji": "^1.5.1",

packages/electron-builder/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"is-ci": "^1.0.10",
6363
"isbinaryfile": "^3.0.2",
6464
"js-yaml": "^3.8.4",
65+
"json5": "^0.5.1",
6566
"minimatch": "^3.0.4",
6667
"node-forge": "^0.7.1",
6768
"normalize-package-data": "^2.3.8",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { debug } from "electron-builder-util"
33
import { log, warn } from "electron-builder-util/out/log"
44
import { readFile, readJson } from "fs-extra-p"
55
import { safeLoad } from "js-yaml"
6+
import JSON5 from "json5"
67
import * as path from "path"
78
import { readAsarJson } from "../asar"
89
import { Config } from "../metadata"
@@ -45,7 +46,8 @@ function getConfigFromPackageData(metadata: any) {
4546
}
4647

4748
export async function doLoadConfig(configFile: string, projectDir: string) {
48-
const result = safeLoad(await readFile(configFile, "utf8"))
49+
const data = await readFile(configFile, "utf8")
50+
const result = configFile.endsWith(".json5") ? JSON5.parse(data) : safeLoad(data)
4951
const relativePath = path.relative(projectDir, configFile)
5052
log(`Using ${relativePath.startsWith("..") ? configFile : relativePath} configuration file`)
5153
return result

typings/json5.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "json5" {
2+
const json5: JSON
3+
export default json5
4+
}

yarn.lock

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@ json-stringify-safe@~5.0.1:
20812081
version "5.0.1"
20822082
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
20832083

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

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

2317-
minimist@0.0.8:
2317+
minimist@0.0.8, minimist@~0.0.1:
23182318
version "0.0.8"
23192319
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
23202320

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

2325-
minimist@~0.0.1:
2326-
version "0.0.10"
2327-
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
2328-
23292325
mkdirp2@^1.0.2:
23302326
version "1.0.3"
23312327
resolved "https://registry.yarnpkg.com/mkdirp2/-/mkdirp2-1.0.3.tgz#cc8dd8265f1f06e2d8f5b10b6e52f4e050bed21b"

0 commit comments

Comments
 (0)