mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:10:43 -05:00
Replace json-fixer with jsonrepair (#1052)
The `fixJson` package is stale and `jsonrepair` is an active alternative. Seams to work well.
This commit is contained in:
commit
7c3b10d0de
@ -41,9 +41,9 @@
|
|||||||
"date-fns-tz": "~3.1",
|
"date-fns-tz": "~3.1",
|
||||||
"fs-extra": "11.2.0",
|
"fs-extra": "11.2.0",
|
||||||
"i18n": "~0.15",
|
"i18n": "~0.15",
|
||||||
"json-fixer": "~1.6",
|
|
||||||
"json5": "~2.2",
|
"json5": "~2.2",
|
||||||
"jsonc": "~2.0",
|
"jsonc": "~2.0",
|
||||||
|
"jsonrepair": "3.11.2",
|
||||||
"logform": "~2.6",
|
"logform": "~2.6",
|
||||||
"mongoid-js": "~1.3",
|
"mongoid-js": "~1.3",
|
||||||
"reflect-metadata": "~0.2",
|
"reflect-metadata": "~0.2",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import type { ILogger } from "@spt/models/spt/utils/ILogger";
|
import type { ILogger } from "@spt/models/spt/utils/ILogger";
|
||||||
import { FileSystemSync } from "@spt/utils/FileSystemSync";
|
import { FileSystemSync } from "@spt/utils/FileSystemSync";
|
||||||
import { HashUtil } from "@spt/utils/HashUtil";
|
import { HashUtil } from "@spt/utils/HashUtil";
|
||||||
import fixJson from "json-fixer";
|
|
||||||
import { parse, stringify } from "json5";
|
import { parse, stringify } from "json5";
|
||||||
import { jsonc } from "jsonc";
|
import { jsonc } from "jsonc";
|
||||||
import { IParseOptions, IStringifyOptions, Reviver } from "jsonc/lib/interfaces";
|
import { IParseOptions, IStringifyOptions, Reviver } from "jsonc/lib/interfaces";
|
||||||
|
import { jsonrepair } from "jsonrepair";
|
||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
@ -153,10 +153,13 @@ export class JsonUtil {
|
|||||||
let savedHash = this.fileHashes[filePath];
|
let savedHash = this.fileHashes[filePath];
|
||||||
if (!savedHash || savedHash !== generatedHash) {
|
if (!savedHash || savedHash !== generatedHash) {
|
||||||
try {
|
try {
|
||||||
const { data, changed } = fixJson(jsonString);
|
const fixedJsonString = jsonrepair(jsonString);
|
||||||
|
const data = this.deserialize<T>(fixedJsonString);
|
||||||
|
const changed = jsonString !== fixedJsonString;
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
// data invalid, return it
|
// data invalid, return it
|
||||||
this.logger.error(`${filePath} - Detected faulty json, please fix your json file using VSCodium`);
|
this.logger.error(`${filePath} - Detected faulty JSON, please fix using a validator`);
|
||||||
} else {
|
} else {
|
||||||
// data valid, save hash and call function again
|
// data valid, save hash and call function again
|
||||||
this.fileHashes[filePath] = generatedHash;
|
this.fileHashes[filePath] = generatedHash;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user