diff --git a/src/bin.ts b/src/bin.ts index 3cc39d83b..86e09a08e 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -126,13 +126,18 @@ if (readFileSync(file, "utf-8").trim() === "") { // Set up database let adapter: Adapter; +const stripBom = (text: string) => text.replace(/^\uFEFF/, '') + if (extname(file) === ".json5") { adapter = new DataFile(file, { - parse: JSON5.parse, + parse: (text) => JSON5.parse(stripBom(text)), stringify: JSON5.stringify, - }); + }) } else { - adapter = new JSONFile(file); + adapter = new DataFile(file, { + parse: (text) => JSON.parse(stripBom(text)) as RawData, + stringify: (data) => JSON.stringify(data, null, 2), + }) } const observer = new Observer(new NormalizedAdapter(adapter));