Skip to content

Commit

Permalink
fix(compiler@json): now really replace jsonc-parser with @std/jsonc
Browse files Browse the repository at this point in the history
bruh
  • Loading branch information
TBroz15 committed Nov 3, 2024
1 parent 797401b commit c55b625
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
2 changes: 2 additions & 0 deletions eslint.config.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _default: import(".pnpm/@typescript-eslint+utils@8.12.2_eslint@9.14.0_jiti@1.21.6__typescript@5.6.3/node_modules/@typescript-eslint/utils/ts-eslint").FlatConfig.ConfigArray;
export default _default;
8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ export default tselint.config(
eslint.configs.recommended,
...tselint.configs.recommendedTypeChecked,
{
ignores: ["node_modules/**/*", "*.mjs", "ci/*.js", "dist/**/*"],
ignores: [
"node_modules/**/*",
"*.mjs",
"ci/*.js",
"dist/**/*",
"src/compiler/utils/JSONCParse/*.js",
],
languageOptions: {
parserOptions: {
projectService: true,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"adm-zip": "^0.5.15",
"fdir": "^6.3.0",
"fdir-size": "^1.0.3",
"jsonc-parser": "^3.3.1",
"mri": "^1.2.0",
"nanospinner": "^1.1.0",
"picocolors": "^1.0.1",
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/cli/utils/getVersion.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const a = await import("./../../../package.json");
console.log(a);
export const version = 1;
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, resolve } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export const { version } = JSON.parse(
readFileSync(resolve(__dirname, "../../../package.json"), "utf-8")
) as { version: string };
1 change: 1 addition & 0 deletions src/compiler/utils/JSONC/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./parse.js";
7 changes: 7 additions & 0 deletions src/compiler/utils/JSONC/parse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/compiler/workers/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sharp from "sharp";
import { join } from "path";
import JSONC from "jsonc-parser";
import { createHash } from "crypto";
import { copyFile, writeFile } from "fs/promises";
import * as JSONC from "../utils/JSONC/index.js";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { workerData as _WD, parentPort } from "worker_threads";

Expand Down Expand Up @@ -33,7 +33,7 @@ const errorList: unknown[] = [];

const checkParseJSON = (data: string, filePath: string): unknown => {
try {
return JSON.parse(JSONC.stripComments(data));
return JSONC.parse(data);
} catch (error) {
errorList.push({
error: (error as Error).toString(),
Expand All @@ -45,7 +45,6 @@ const checkParseJSON = (data: string, filePath: string): unknown => {

function minifyJSON() {
if (files.JSON.length === 0) return;
const { errorChecking } = compiler.JSON ?? { errorChecking: false };

const promises = files.JSON.map((path) => {
const tempPath = join(tempPack, path);
Expand All @@ -58,9 +57,7 @@ function minifyJSON() {
const cacheFileExists = existsSync(cacheFile);

if (!cacheFileExists) {
const parsedJSON: unknown = errorChecking
? checkParseJSON(data, filePath)
: JSONC.parse(data);
const parsedJSON: unknown = checkParseJSON(data, filePath);

if (!parsedJSON) return;

Expand Down
10 changes: 8 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
"strictFunctionTypes": true,
"rootDir": "src",
"outDir": "dist",
"declaration": true
"declaration": true,
"allowJs": true
},
"exclude": ["node_modules/**/*", "ci/*.js", "dist/**/*"]
"exclude": [
"node_modules/**/*",
"ci/*.js",
"dist/**/*",
"src/compiler/utils/JSONC/*.js"
]
}

0 comments on commit c55b625

Please sign in to comment.