11import type { TSESLint } from "@typescript-eslint/utils" ;
22import type { ReadonlyRecord } from "complete-common" ;
3- import fs from "node:fs" ;
4- import path from "node:path" ;
3+ import packageJSON from "../package.json" with { type : "json" } ;
54import { configs } from "./configs.js" ;
65import { rules } from "./rules.js" ;
76
8- const { name, version } = getPackageJSON ( ) ;
7+ const { name, version } = packageJSON ;
98
109const plugin = {
1110 meta : {
@@ -22,20 +21,6 @@ addPluginToConfigs(configs, name);
2221// eslint-disable-next-line
2322export default plugin ;
2423
25- /**
26- * We parse the package JSON manually since importing JSON files directly in Node is experimental.
27- */
28- function getPackageJSON ( ) : Record < string , unknown > {
29- const packageRoot = path . resolve ( import . meta. dirname , ".." ) ;
30- const packageJSONPath = path . join ( packageRoot , "package.json" ) ;
31- try {
32- const packageJSONString = fs . readFileSync ( packageJSONPath , "utf8" ) ;
33- return JSON . parse ( packageJSONString ) as Record < string , unknown > ;
34- } catch ( error ) {
35- throw new Error ( `Failed to read the "${ packageJSONPath } " file: ${ error } ` ) ;
36- }
37- }
38-
3924/** @see https://eslint.org/docs/latest/extend/plugins#configs-in-plugins */
4025function addPluginToConfigs (
4126 configsToMutate : ReadonlyRecord < string , TSESLint . FlatConfig . ConfigArray > ,
0 commit comments