|
2 | 2 |
|
3 | 3 | import fs from "fs"; |
4 | 4 | import path from "path"; |
5 | | -import ts from "../../lib/typescript.js"; |
6 | 5 | import chalk from "chalk"; |
7 | 6 | import which from "which"; |
8 | 7 | import { spawn } from "child_process"; |
9 | 8 | import assert from "assert"; |
| 9 | +import JSONC from "jsonc-parser"; |
10 | 10 |
|
11 | 11 | /** |
12 | 12 | * Executes the provided command once with the supplied arguments. |
@@ -46,48 +46,13 @@ export async function exec(cmd, args, options = {}) { |
46 | 46 | })); |
47 | 47 | } |
48 | 48 |
|
49 | | -/** |
50 | | - * @param {ts.Diagnostic[]} diagnostics |
51 | | - * @param {{ cwd?: string, pretty?: boolean }} [options] |
52 | | - */ |
53 | | -function formatDiagnostics(diagnostics, options) { |
54 | | - return options && options.pretty |
55 | | - ? ts.formatDiagnosticsWithColorAndContext(diagnostics, getFormatDiagnosticsHost(options && options.cwd)) |
56 | | - : ts.formatDiagnostics(diagnostics, getFormatDiagnosticsHost(options && options.cwd)); |
57 | | -} |
58 | | - |
59 | | -/** |
60 | | - * @param {ts.Diagnostic[]} diagnostics |
61 | | - * @param {{ cwd?: string }} [options] |
62 | | - */ |
63 | | -function reportDiagnostics(diagnostics, options) { |
64 | | - console.log(formatDiagnostics(diagnostics, { cwd: options && options.cwd, pretty: process.stdout.isTTY })); |
65 | | -} |
66 | | - |
67 | | -/** |
68 | | - * @param {string | undefined} cwd |
69 | | - * @returns {ts.FormatDiagnosticsHost} |
70 | | - */ |
71 | | -function getFormatDiagnosticsHost(cwd) { |
72 | | - return { |
73 | | - getCanonicalFileName: fileName => fileName, |
74 | | - getCurrentDirectory: () => cwd ?? process.cwd(), |
75 | | - getNewLine: () => ts.sys.newLine, |
76 | | - }; |
77 | | -} |
78 | | - |
79 | 49 | /** |
80 | 50 | * Reads JSON data with optional comments using the LKG TypeScript compiler |
81 | 51 | * @param {string} jsonPath |
82 | 52 | */ |
83 | 53 | export function readJson(jsonPath) { |
84 | 54 | const jsonText = fs.readFileSync(jsonPath, "utf8"); |
85 | | - const result = ts.parseConfigFileTextToJson(jsonPath, jsonText); |
86 | | - if (result.error) { |
87 | | - reportDiagnostics([result.error]); |
88 | | - throw new Error("An error occurred during parse."); |
89 | | - } |
90 | | - return result.config; |
| 55 | + return JSONC.parse(jsonText); |
91 | 56 | } |
92 | 57 |
|
93 | 58 | /** |
|
0 commit comments