Skip to content

Commit a875e65

Browse files
authored
feat: allow tsconfig comments (#22)
1 parent e6488db commit a875e65

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

package-lock.json

+18-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"dependencies": {
6060
"@knighted/specifier": "^1.0.0-rc.4",
6161
"glob": "^10.3.3",
62-
"read-pkg-up": "^10.0.0"
62+
"read-pkg-up": "^10.0.0",
63+
"strip-json-comments": "^5.0.1"
6364
},
6465
"prettier": {
6566
"arrowParens": "avoid",

src/init.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { cwd } from 'node:process'
22
import { parseArgs } from 'node:util'
33
import { resolve, join, dirname } from 'node:path'
44
import { stat, readFile } from 'node:fs/promises'
5+
import stripJsonComments from 'strip-json-comments'
56

67
import { readPackageUp } from 'read-pkg-up'
78

@@ -124,7 +125,7 @@ const init = async args => {
124125
let tsconfig = null
125126

126127
try {
127-
tsconfig = JSON.parse((await readFile(configPath)).toString())
128+
tsconfig = JSON.parse(stripJsonComments((await readFile(configPath)).toString()))
128129
} catch (err) {
129130
logError(`The config file found at ${configPath} is not parsable as JSON.`)
130131

test/__fixtures__/plain/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
// test comment
23
"compilerOptions": {
34
"target": "ESNext",
45
"module": "NodeNext",

0 commit comments

Comments
 (0)