Skip to content

Commit 021970e

Browse files
committed
refactor(plugin): import package.json file directly
1 parent 6fc7231 commit 021970e

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

package-metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2+
"@schema": "https://raw.githubusercontent.com/complete-ts/complete/refs/heads/main/packages/complete-cli/schemas/package-metadata-schema.json",
23
"dependencies": {
4+
"figlet": {
5+
"lock-version": true,
6+
"lock-reason": "https://github.com/patorjk/figlet.js/issues/139"
7+
},
38
"typescript": {
49
"lock-version": true,
510
"lock-reason": "https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/package.json#L45"

packages/eslint-plugin-isaacscript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"license": "MIT",
3131
"author": "Zamiell",
3232
"type": "module",
33-
"main": "./dist/index.js",
33+
"main": "./dist/src/index.js",
3434
"files": [
3535
"dist",
3636
"LICENSE",

packages/eslint-plugin-isaacscript/src/index.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { TSESLint } from "@typescript-eslint/utils";
22
import 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" };
54
import { configs } from "./configs.js";
65
import { rules } from "./rules.js";
76

8-
const { name, version } = getPackageJSON();
7+
const { name, version } = packageJSON;
98

109
const plugin = {
1110
meta: {
@@ -22,20 +21,6 @@ addPluginToConfigs(configs, name);
2221
// eslint-disable-next-line
2322
export 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 */
4025
function addPluginToConfigs(
4126
configsToMutate: ReadonlyRecord<string, TSESLint.FlatConfig.ConfigArray>,

packages/eslint-plugin-isaacscript/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
// https://www.typescriptlang.org/docs/handbook/compiler-options.html
1313
"compilerOptions": {
1414
// Needed since this is a library.
15+
"sourceMap": true,
1516
"declaration": true,
1617
"declarationMap": true,
18+
19+
// Needed since we import from the "package.json" file.
20+
// TODO: Remove this when the monorepo version of TypeScript is: >= 5.9.2
21+
// (It automatically gets applied for some reason on newer TypeScript versions.)
22+
"resolveJsonModule": true,
1723
},
1824
}

0 commit comments

Comments
 (0)