Skip to content

Commit 95c40b4

Browse files
committed
Use json5 instead of comment-json
1 parent 0ab5a35 commit 95c40b4

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

lib/vscode/colorThemeData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
const path = require('path');
99
const fs = require('fs');
10-
const json = require('comment-json');
10+
const JSON5 = require('json5');
1111
const plist = require('plist');
1212

1313
function loadColorTheme(themeLocation, resultRules = [], resultColors = {}) {
1414
let name = path.basename(themeLocation).split('.')[0];
1515
if (path.extname(themeLocation) === '.json') {
1616
const content = fs.readFileSync(themeLocation, 'utf8');
17-
let contentValue = json.parse(content);
17+
let contentValue = JSON5.parse(content);
1818
name = contentValue.name || name;
1919
if (contentValue.include) {
2020
loadColorTheme(path.join(path.dirname(themeLocation), contentValue.include), resultRules, resultColors);

package-lock.json

Lines changed: 7 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
},
3131
"homepage": "https://github.com/andrewbranch/gatsby-remark-vscode#readme",
3232
"devDependencies": {
33-
"@types/comment-json": "^1.1.1",
3433
"@types/decompress": "^4.2.3",
3534
"@types/glob": "^7.1.1",
3635
"@types/jest": "^24.0.11",
36+
"@types/json5": "0.0.30",
3737
"@types/lodash.escape": "^4.0.6",
3838
"@types/lodash.uniq": "^4.5.6",
3939
"@types/node": "^12.0.0",
@@ -45,8 +45,8 @@
4545
"typescript": "^3.4.5"
4646
},
4747
"dependencies": {
48-
"comment-json": "^1.1.3",
4948
"decompress": "^4.2.0",
49+
"json5": "^2.1.0",
5050
"lodash.escape": "^4.0.1",
5151
"lodash.uniq": "^4.5.0",
5252
"oniguruma": "^7.2.0",

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const fs = require('fs');
33
const util = require('util');
44
const path = require('path');
5-
const json = require('comment-json');
5+
const JSON5 = require('json5');
66
const plist = require('plist');
77
const uniq = require('lodash.uniq');
88

@@ -71,7 +71,7 @@ function sanitizeForClassName(str) {
7171
}
7272

7373
const readFile = util.promisify(fs.readFile);
74-
const requireJson = /** @param {string} pathName */ pathName => json.parse(fs.readFileSync(pathName, 'utf8'));
74+
const requireJson = /** @param {string} pathName */ pathName => JSON5.parse(fs.readFileSync(pathName, 'utf8'));
7575
const requireGrammar = /** @param {string} pathName */ async pathName =>
7676
path.extname(pathName) === '.json' ? requireJson(pathName) : plist.parse(await readFile(pathName, 'utf8'));
7777

test/gatsby-remark-vscode.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,11 @@ describe('prefers-color-scheme', () => {
245245
}, markdownAST);
246246
});
247247
});
248+
249+
describe('utils', () => {
250+
describe('requireJson', () => {
251+
it('works with json5', () => {
252+
expect(() => realUtils.requireJson(path.resolve(__dirname, 'json5.tmTheme.json'))).not.toThrow();
253+
});
254+
});
255+
});

test/json5.tmTheme.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "vscode://schemas/color-theme",
3+
"name": "json5",
4+
"tokenColors": [
5+
{
6+
scope: [
7+
"meta.embedded",
8+
"source.groovy.embedded",
9+
],
10+
"settings": {
11+
"foreground": "#D4D4D4" // a nice gray
12+
}
13+
},
14+
],
15+
}

0 commit comments

Comments
 (0)