Skip to content

Commit 65bf245

Browse files
Lazy-loading some heavy parsers, shaving some overhead from startup when they are not needed
1 parent 82168d6 commit 65bf245

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/config_prettier.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import TOML from "@iarna/toml";
2-
import yaml from "js-yaml";
3-
import JSON5 from "json5";
41
import fs from "node:fs";
52
import path from "node:path";
63
import JSONC from "tiny-jsonc";
@@ -33,6 +30,7 @@ const Loaders = {
3330
},
3431
json5: async (filePath: string): Promise<unknown> => {
3532
const fileContent = fs.readFileSync(filePath, "utf8");
33+
const JSON5 = (await import("json5")).default;
3634
const config = JSON5.parse(fileContent);
3735
return config;
3836
},
@@ -53,9 +51,11 @@ const Loaders = {
5351
},
5452
toml: async (filePath: string): Promise<unknown> => {
5553
const fileContent = fs.readFileSync(filePath, "utf8");
54+
const TOML = (await import("@iarna/toml")).default;
5655
return TOML.parse(fileContent);
5756
},
5857
yaml: async (filePath: string): Promise<unknown> => {
58+
const yaml = (await import("js-yaml")).default;
5959
const fileContent = fs.readFileSync(filePath, "utf8");
6060
return yaml.load(fileContent, {
6161
schema: yaml.JSON_SCHEMA,

0 commit comments

Comments
 (0)