Skip to content

Commit

Permalink
fix: update jsonc-register
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Moore committed Nov 9, 2021
1 parent 0512a49 commit cd37d41
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-wolves-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsonc-register": minor
---

Update loading technique to strip JSON comments only
4 changes: 3 additions & 1 deletion packages/jsonc-register/lib/index.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { addHook } = require('pirates');
const stripJsonComments = require('strip-json-comments');

const DEFAULT_EXTENSIONS = ['.json', '.jsonc']

function compile(sourcecode) {
if (sourcecode.startsWith('module.exports')) return sourcecode;
return `module.exports = ${sourcecode}`;
const value = JSON.parse(stripJsonComments(sourcecode));
return `module.exports = ${JSON.stringify(value)}`;
}

function register() {
Expand Down
3 changes: 2 additions & 1 deletion packages/jsonc-register/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
],
"author": "Nate Moore <[email protected]>",
"dependencies": {
"pirates": "^4.0.1"
"pirates": "^4.0.1",
"strip-json-comments": "3.1.1"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,11 @@ strip-indent@^3.0.0:
dependencies:
min-indent "^1.0.0"

[email protected]:
version "3.1.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down

0 comments on commit cd37d41

Please sign in to comment.