Skip to content

Commit c702b8a

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 0047651 commit c702b8a

File tree

3 files changed

+17
-38
lines changed

3 files changed

+17
-38
lines changed

Diff for: package-lock.json

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

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"gulp-newer": "latest",
8484
"gulp-rename": "latest",
8585
"gulp-sourcemaps": "latest",
86+
"jsonc-parser": "^3.2.0",
8687
"merge2": "latest",
8788
"minimist": "latest",
8889
"mkdirp": "latest",

Diff for: scripts/build/utils.mjs

+3-38
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import path from "path";
77
import log from "fancy-log";
88
import del from "del";
99
import File from "vinyl";
10-
import ts from "../../lib/typescript.js";
1110
import chalk from "chalk";
1211
import which from "which";
1312
import { spawn } from "child_process";
1413
import { Duplex } from "stream";
1514
import assert from "assert";
15+
import JSONC from "jsonc-parser";
1616

1717
/**
1818
* Executes the provided command once with the supplied arguments.
@@ -53,47 +53,12 @@ export async function exec(cmd, args, options = {}) {
5353
}
5454

5555
/**
56-
* @param {ts.Diagnostic[]} diagnostics
57-
* @param {{ cwd?: string, pretty?: boolean }} [options]
58-
*/
59-
function formatDiagnostics(diagnostics, options) {
60-
return options && options.pretty
61-
? ts.formatDiagnosticsWithColorAndContext(diagnostics, getFormatDiagnosticsHost(options && options.cwd))
62-
: ts.formatDiagnostics(diagnostics, getFormatDiagnosticsHost(options && options.cwd));
63-
}
64-
65-
/**
66-
* @param {ts.Diagnostic[]} diagnostics
67-
* @param {{ cwd?: string }} [options]
68-
*/
69-
function reportDiagnostics(diagnostics, options) {
70-
log(formatDiagnostics(diagnostics, { cwd: options && options.cwd, pretty: process.stdout.isTTY }));
71-
}
72-
73-
/**
74-
* @param {string | undefined} cwd
75-
* @returns {ts.FormatDiagnosticsHost}
76-
*/
77-
function getFormatDiagnosticsHost(cwd) {
78-
return {
79-
getCanonicalFileName: fileName => fileName,
80-
getCurrentDirectory: () => cwd ?? process.cwd(),
81-
getNewLine: () => ts.sys.newLine,
82-
};
83-
}
84-
85-
/**
86-
* Reads JSON data with optional comments using the LKG TypeScript compiler
56+
* Reads JSON data with optional comments.
8757
* @param {string} jsonPath
8858
*/
8959
export function readJson(jsonPath) {
9060
const jsonText = fs.readFileSync(jsonPath, "utf8");
91-
const result = ts.parseConfigFileTextToJson(jsonPath, jsonText);
92-
if (result.error) {
93-
reportDiagnostics([result.error]);
94-
throw new Error("An error occurred during parse.");
95-
}
96-
return result.config;
61+
return JSONC.parse(jsonText);
9762
}
9863

9964
/**

0 commit comments

Comments
 (0)