diff --git a/deps.ts b/deps.ts index 9ab8648..a1c331d 100644 --- a/deps.ts +++ b/deps.ts @@ -29,3 +29,4 @@ export { UpdateNotifier, } from "https://x.nest.land/hatcher@0.10.2/mod.ts"; export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts"; +export { parse as parseJson } from "https://deno.land/std@0.151.0/encoding/jsonc.ts"; diff --git a/src/load_config.ts b/src/load_config.ts index ef679b2..a70bf4d 100644 --- a/src/load_config.ts +++ b/src/load_config.ts @@ -1,4 +1,4 @@ -import { existsSync, parseYaml, path } from "../deps.ts"; +import { existsSync, parseYaml, path, parseJson } from "../deps.ts"; import { ScriptsConfiguration } from "./scripts_config.ts"; const CONFIG_FILE_NAMES = ["scripts", "velociraptor"]; @@ -60,14 +60,7 @@ async function parseConfig( async function parseDenoConfig( configPath: string, ): Promise { - let content = Deno.readTextFileSync(configPath); - // Strips comments for .jsonc (credits to @tarkh) - if (/\.jsonc$/.test(configPath)) { - content = content.replace( - /\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, - (m, g) => g ? "" : m, - ); - } - const { velociraptor: config = {} } = JSON.parse(content); + const content = Deno.readTextFileSync(configPath); + const { velociraptor: config = {} } = parseJson(content); return config as ScriptsConfiguration; }