diff --git a/.changeset/mighty-wolves-happen.md b/.changeset/mighty-wolves-happen.md new file mode 100644 index 0000000..49d4962 --- /dev/null +++ b/.changeset/mighty-wolves-happen.md @@ -0,0 +1,5 @@ +--- +"jsonc-register": minor +--- + +Update loading technique to strip JSON comments only diff --git a/packages/jsonc-register/lib/index.cjs b/packages/jsonc-register/lib/index.cjs index 14b4bd0..1d1bce8 100644 --- a/packages/jsonc-register/lib/index.cjs +++ b/packages/jsonc-register/lib/index.cjs @@ -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() { diff --git a/packages/jsonc-register/package.json b/packages/jsonc-register/package.json index cd1b5d3..9cce775 100644 --- a/packages/jsonc-register/package.json +++ b/packages/jsonc-register/package.json @@ -22,7 +22,8 @@ ], "author": "Nate Moore ", "dependencies": { - "pirates": "^4.0.1" + "pirates": "^4.0.1", + "strip-json-comments": "3.1.1" }, "repository": { "type": "git", diff --git a/yarn.lock b/yarn.lock index 54e95be..35e579c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1663,6 +1663,11 @@ strip-indent@^3.0.0: dependencies: min-indent "^1.0.0" +strip-json-comments@3.1.1: + 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"