Skip to content

Commit 6715a98

Browse files
committed
Use jsonc-parser instead of LKG compiler in build
Profiling the build roughly half of the time spent loading the build is spent importing typescript.js, for this one function. Since this stack is already adding required devDependencies, switch readJson to use jsonc-parser (published by the VS Code team), rather than importing the entire LKG typescript.js library.
1 parent 017ae89 commit 6715a98

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

package-lock.json

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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"fs-extra": "^9.1.0",
7171
"glob": "latest",
7272
"hereby": "^1.6.4",
73+
"jsonc-parser": "^3.2.0",
7374
"minimist": "latest",
7475
"mkdirp": "latest",
7576
"mocha": "latest",

scripts/build/utils.mjs

+2-37
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import fs from "fs";
44
import path from "path";
5-
import ts from "../../lib/typescript.js";
65
import chalk from "chalk";
76
import which from "which";
87
import { spawn } from "child_process";
98
import assert from "assert";
9+
import JSONC from "jsonc-parser";
1010

1111
/**
1212
* Executes the provided command once with the supplied arguments.
@@ -46,48 +46,13 @@ export async function exec(cmd, args, options = {}) {
4646
}));
4747
}
4848

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-
7949
/**
8050
* Reads JSON data with optional comments using the LKG TypeScript compiler
8151
* @param {string} jsonPath
8252
*/
8353
export function readJson(jsonPath) {
8454
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);
9156
}
9257

9358
/**

0 commit comments

Comments
 (0)