Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports JSON files with comments #9

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: main

on: [push]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
"@types/node": "^13.7.7",
"@types/yarnpkg__lockfile": "^1.1.3",
"hard-source-webpack-plugin": "^0.13.1",
"strip-json-comments": "^3.1.1",
"ts-loader": "^6.2.2",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
},
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/core": "^1.2.4",
"@yarnpkg/lockfile": "^1.1.0",
"concat-stream": "^2.0.0",
"glob": "^7.1.6"
Expand Down
48 changes: 27 additions & 21 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createHost, createService } from './langSvc'
import { Reporter } from './reporter'
import { FileEntry } from './types'
import { getAllLibs, uniq } from './utils'
import stripJsonComments from 'strip-json-comments'

export class Doctor {
private service: _ts.LanguageService
Expand All @@ -19,30 +20,35 @@ export class Doctor {
}

static fromConfigFile(configPath: string, ts: typeof _ts): Doctor {
const content = fs.readFileSync(configPath).toString();
const parsed = ts.parseJsonConfigFileContent(
const content = stripJsonComments(fs.readFileSync(configPath).toString(), {whitespace: false});
try {
const parsed = ts.parseJsonConfigFileContent(
JSON.parse(content),
ts.sys,
path.dirname(configPath)
);
const compilerOptions = parsed.options

const defaultLibFileName = _ts.getDefaultLibFileName(compilerOptions)
const libs = [defaultLibFileName, ...(compilerOptions.lib || [])]
const allLibs = getAllLibs(uniq(libs))

/**
* Note:
*
* since we use CDN-hosted TS runtime, which is a bundled version,
* we need to manually added lib.*.d.ts.
*/
const fileNames = [
...parsed.fileNames,
...allLibs
]

return new Doctor(fileNames, compilerOptions, ts)
);
const compilerOptions = parsed.options

const defaultLibFileName = _ts.getDefaultLibFileName(compilerOptions)
const libs = [defaultLibFileName, ...(compilerOptions.lib || [])]
const allLibs = getAllLibs(uniq(libs))

/**
* Note:
*
* since we use CDN-hosted TS runtime, which is a bundled version,
* we need to manually added lib.*.d.ts.
*/
const fileNames = [
...parsed.fileNames,
...allLibs
]

return new Doctor(fileNames, compilerOptions, ts)
} catch (error) {
console.error(error)
throw error
}
}

getSemanticDiagnostics() {
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@actions/core@^1.2.3":
version "1.2.3"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.3.tgz#e844b4fa0820e206075445079130868f95bfca95"
integrity sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w==
"@actions/core@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.4.tgz#96179dbf9f8d951dd74b40a0dbd5c22555d186ab"
integrity sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==

"@types/concat-stream@^1.6.0":
version "1.6.0"
Expand Down Expand Up @@ -2509,6 +2509,11 @@ strip-eof@^1.0.0:
resolved "https://registry.yarnpkg.com/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==

[email protected]:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
Expand Down