diff --git a/package.json b/package.json index 3845e16..fe207dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tscpaths", - "version": "0.0.9", + "version": "0.0.10", "description": "Replace absolute paths to relative paths after typescript compilation", "main": "cjs/index.js", "module": "lib/index.js", @@ -53,6 +53,7 @@ }, "dependencies": { "commander": "^2.20.0", - "globby": "^9.2.0" + "globby": "^9.2.0", + "strip-json-comments": "^3.1.1" } } diff --git a/src/util.ts b/src/util.ts index e289245..d63e952 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,6 @@ +import * as fs from 'fs'; import { dirname, resolve } from 'path'; +import * as stripJsonComments from 'strip-json-comments'; /* "baseUrl": ".", @@ -35,6 +37,7 @@ export const mapPaths = ( }; export const loadConfig = (file: string): ITSConfig => { + const configString = fs.readFileSync(file).toString(); const { extends: ext, compilerOptions: { baseUrl, outDir, paths } = { @@ -42,7 +45,7 @@ export const loadConfig = (file: string): ITSConfig => { outDir: undefined, paths: undefined, }, - } = require(file) as IRawTSConfig; + } = JSON.parse(stripJsonComments(configString)) as IRawTSConfig; const config: ITSConfig = {}; if (baseUrl) { diff --git a/yarn.lock b/yarn.lock index ea658af..4023a92 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3440,6 +3440,11 @@ strip-eof@^1.0.0: resolved "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= +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== + strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"