Skip to content

Commit cc2101a

Browse files
committed
refactor(build): use tsdown, add publish validation
simplifies lots of stuff. thanks VoidZero! - bundle ESM files, rather than distribute their source - index.js -> index.ts to easily generate ESM and CJS types from it - remove deprecated main, module, types fields from package.json; our required node version supports exports field - installed tsgo and added tsconfig.json for tsdown; now we also get type checking in IDE - add publint and attw checks for package.json and type resolution issues (yay! manually testing that matrix was a pain)
1 parent 6565ecf commit cc2101a

File tree

12 files changed

+864
-299
lines changed

12 files changed

+864
-299
lines changed

build.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,25 @@
55
"author": "Nick van Dyke",
66
"license": "MIT",
77
"type": "module",
8-
"module": "./src/index.js",
9-
"main": "./dist/index.cjs",
10-
"types": "./types/index.d.ts",
118
"exports": {
129
"import": {
13-
"types": "./types/index.d.ts",
14-
"default": "./src/index.js"
10+
"types": "./dist/index.d.mts",
11+
"default": "./dist/index.mjs"
1512
},
1613
"require": {
17-
"types": "./types/index.d.cts",
14+
"types": "./dist/index.d.cts",
1815
"default": "./dist/index.cjs"
1916
}
2017
},
2118
"files": [
22-
"src",
23-
"types",
2419
"dist"
2520
],
2621
"repository": {
2722
"type": "git",
2823
"url": "https://github.com/NickvanDyke/eslint-plugin-react-you-might-not-need-an-effect.git"
2924
},
3025
"scripts": {
31-
"build": "node build.js",
26+
"build": "tsdown",
3227
"lint": "eslint",
3328
"test": "mocha --recursive"
3429
},
@@ -45,15 +40,19 @@
4540
"globals": "^16.2.0"
4641
},
4742
"devDependencies": {
43+
"@arethetypeswrong/core": "^0.18.2",
4844
"@eslint/js": "^9.28.0",
49-
"esbuild": "^0.25.3",
45+
"@typescript/native-preview": "^7.0.0-dev.20260408.1",
46+
"attw": "^1.0.0",
5047
"eslint": "^9.20.1",
5148
"eslint-plugin-eslint-plugin": "^6.4.0",
5249
"eslint-plugin-n": "^17.17.0",
5350
"lint-staged": "^16.1.0",
5451
"mocha": "11.1.0",
5552
"prettier": "^3.5.3",
56-
"simple-git-hooks": "^2.13.0"
53+
"publint": "^0.3.18",
54+
"simple-git-hooks": "^2.13.0",
55+
"tsdown": "^0.21.7"
5756
},
5857
"peerDependencies": {
5958
"eslint": ">=8.40.0"

src/index.cjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/index.js renamed to src/index.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import noChainStateUpdates from "./rules/no-chain-state-updates.js";
88
import noDerivedState from "./rules/no-derived-state.js";
99
import noPassDataToParent from "./rules/no-pass-data-to-parent.js";
1010
import globals from "globals";
11+
import type { ESLint, Linter } from "eslint";
1112

12-
/**
13-
* @type {import("eslint").ESLint.Plugin}
14-
*/
1513
const plugin = {
1614
meta: {
1715
name: "react-you-might-not-need-an-effect",
@@ -30,11 +28,14 @@ const plugin = {
3028
},
3129
};
3230

33-
const rules = (severity) =>
34-
Object.keys(plugin.rules).reduce((acc, ruleName) => {
35-
acc[plugin.meta.name + "/" + ruleName] = severity;
36-
return acc;
37-
}, {});
31+
const rules = (severity: "error" | "warn") =>
32+
Object.keys(plugin.rules).reduce(
33+
(acc, ruleName) => {
34+
acc[plugin.meta.name + "/" + ruleName] = severity;
35+
return acc;
36+
},
37+
{} as Record<string, "error" | "warn">,
38+
);
3839

3940
const languageOptions = {
4041
globals: {
@@ -81,4 +82,12 @@ Object.assign(plugin.configs, {
8182
},
8283
});
8384

84-
export default plugin;
85+
// HACK: unsure how to type this properly because we need to gradually add fields to `plugin` so it can self-reference in the config definitions.
86+
export default plugin as unknown as ESLint.Plugin & {
87+
configs: {
88+
recommended: Linter.Config;
89+
strict: Linter.Config;
90+
"legacy-recommended": Linter.LegacyConfig;
91+
"legacy-strict": Linter.LegacyConfig;
92+
};
93+
};

test/config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ESLint } from "eslint";
22
import { LegacyESLint } from "eslint/use-at-your-own-risk";
33
import { js } from "./rule-tester.js";
44
import assert from "assert";
5-
import plugin from "../src/index.js";
5+
import plugin from "../src/index.ts";
66

77
describe("config", () => {
88
const codeThatDerivesState = js`

test/real-world.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ESLint } from "eslint";
2-
import plugin from "../src/index.js";
2+
import plugin from "../src/index.ts";
33
import { js } from "./rule-tester.js";
44
import assert from "assert";
55

test/rule-tester.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import { RuleTester } from "eslint";
3-
import plugin from "../src/index.js";
3+
import plugin from "../src/index.ts";
44

55
// For syntax highlighting inside code under test
66
export const js = String.raw;

tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"include": ["./src/**/*"],
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"noEmit": true
6+
}
7+
}

tsdown.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { defineConfig } from "tsdown";
2+
3+
export default defineConfig({
4+
entry: ["./src/index.ts"],
5+
format: ["esm", "cjs"],
6+
platform: "node",
7+
sourcemap: true,
8+
dts: {
9+
enabled: true,
10+
sourcemap: true,
11+
tsgo: true,
12+
},
13+
publint: {
14+
enabled: true,
15+
level: "error",
16+
},
17+
attw: {
18+
enabled: true,
19+
level: "error",
20+
profile: "node16", // Ignore node10 resolution errors - we require node 14+
21+
},
22+
});

types/index.d.cts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)