Skip to content

Commit

Permalink
Lazy-loading some heavy parsers, shaving some overhead from startup w…
Browse files Browse the repository at this point in the history
…hen they are not needed
  • Loading branch information
fabiospampinato committed Apr 13, 2024
1 parent 82168d6 commit 65bf245
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/config_prettier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import TOML from "@iarna/toml";
import yaml from "js-yaml";
import JSON5 from "json5";
import fs from "node:fs";
import path from "node:path";
import JSONC from "tiny-jsonc";
Expand Down Expand Up @@ -33,6 +30,7 @@ const Loaders = {
},
json5: async (filePath: string): Promise<unknown> => {
const fileContent = fs.readFileSync(filePath, "utf8");
const JSON5 = (await import("json5")).default;
const config = JSON5.parse(fileContent);
return config;
},
Expand All @@ -53,9 +51,11 @@ const Loaders = {
},
toml: async (filePath: string): Promise<unknown> => {
const fileContent = fs.readFileSync(filePath, "utf8");
const TOML = (await import("@iarna/toml")).default;
return TOML.parse(fileContent);
},
yaml: async (filePath: string): Promise<unknown> => {
const yaml = (await import("js-yaml")).default;
const fileContent = fs.readFileSync(filePath, "utf8");
return yaml.load(fileContent, {
schema: yaml.JSON_SCHEMA,
Expand Down

0 comments on commit 65bf245

Please sign in to comment.