next-workers-kit 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +138 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +23 -0
- package/dist/eslint.d.ts +16 -0
- package/dist/eslint.js +237 -0
- package/dist/hooks/format.d.ts +1 -0
- package/dist/hooks/format.js +26 -0
- package/dist/hooks/typecheck.d.ts +1 -0
- package/dist/hooks/typecheck.js +24 -0
- package/dist/lib/doctor.d.ts +2 -0
- package/dist/lib/doctor.js +271 -0
- package/dist/lib/files.d.ts +2 -0
- package/dist/lib/files.js +28 -0
- package/dist/lib/jsonc.d.ts +1 -0
- package/dist/lib/jsonc.js +31 -0
- package/dist/lib/sync.d.ts +6 -0
- package/dist/lib/sync.js +52 -0
- package/dist/meta.d.ts +4 -0
- package/dist/meta.js +9 -0
- package/dist/next.d.ts +4 -0
- package/dist/next.js +15 -0
- package/dist/prettier.d.ts +3 -0
- package/dist/prettier.js +7 -0
- package/dist/rules/class-rule.d.ts +2 -0
- package/dist/rules/class-rule.js +29 -0
- package/dist/rules/feature-layout.d.ts +2 -0
- package/dist/rules/feature-layout.js +16 -0
- package/dist/rules/spacing.d.ts +1 -0
- package/dist/rules/spacing.js +23 -0
- package/dist/rules/typography.d.ts +5 -0
- package/dist/rules/typography.js +7 -0
- package/package.json +81 -4
- package/templates/init/claude-settings.json +25 -0
- package/templates/init/eslint.config.mjs +4 -0
- package/templates/init/gitignore +30 -0
- package/templates/init/knip.json +7 -0
- package/templates/init/mcp.json +8 -0
- package/templates/init/prettier.config.mjs +5 -0
- package/templates/init/prettierignore +4 -0
- package/templates/init/tsconfig.json +14 -0
- package/templates/synced/CLAUDE.md +1 -0
- package/templates/synced/dependabot.yml +19 -0
- package/templates/synced/editorconfig +12 -0
- package/templates/synced/gitattributes +1 -0
- package/templates/synced/lefthook.yml +9 -0
- package/templates/synced/npmrc +1 -0
- package/templates/synced/nvmrc +1 -0
- package/tsconfig.base.json +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pnilssson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
|
1
|
-
#
|
|
1
|
+
# next-workers-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One opinionated setup for Next.js on Cloudflare Workers with [OpenNext](https://opennext.js.org/cloudflare), enforced by a check that runs before every deploy. You get strict ESLint, TypeScript and Prettier configs, a feature-folder structure that lint enforces, security headers, Dependabot, Claude Code hooks, and `next-workers-kit doctor`, which fails the build when a project drifts from the setup.
|
|
4
|
+
|
|
5
|
+
It's built for teams and agents that run several Next.js sites on Workers and want them to stay identical, so the same change works in every repo and the checks catch mistakes.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
In a Next.js project that deploys with `@opennextjs/cloudflare`:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i -D next-workers-kit eslint eslint-config-next prettier typescript@6.0.3 knip lefthook
|
|
13
|
+
npx next-workers-kit init
|
|
14
|
+
npm run check
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`init` writes the shared files and starter configs. Then fix what `doctor` reports; every message says what to change.
|
|
18
|
+
|
|
19
|
+
Requirements: Node 24, npm 12 or later, `next` 16.4 or later with `eslint-config-next` at the same version, ESLint 10, TypeScript 6.0 (typescript-eslint doesn't support 6.1 yet).
|
|
20
|
+
|
|
21
|
+
## What it sets up
|
|
22
|
+
|
|
23
|
+
**Configs you import**
|
|
24
|
+
|
|
25
|
+
`eslint.config.mjs`:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { defineConfig } from "eslint/config";
|
|
29
|
+
import { config } from "next-workers-kit/eslint";
|
|
30
|
+
|
|
31
|
+
export default defineConfig([...config({ root: import.meta.dirname })]);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`tsconfig.json`:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"extends": "next-workers-kit/tsconfig.json",
|
|
39
|
+
"compilerOptions": { "paths": { "@/*": ["./src/*"] } },
|
|
40
|
+
"include": [
|
|
41
|
+
"next-env.d.ts",
|
|
42
|
+
"cloudflare-env.d.ts",
|
|
43
|
+
"**/*.ts",
|
|
44
|
+
"**/*.tsx",
|
|
45
|
+
"**/*.mts",
|
|
46
|
+
".next/types/**/*.ts",
|
|
47
|
+
".next/dev/types/**/*.ts"
|
|
48
|
+
],
|
|
49
|
+
"exclude": ["node_modules"]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`prettier.config.mjs`:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import base from "next-workers-kit/prettier";
|
|
57
|
+
|
|
58
|
+
const config = { ...base, tailwindStylesheet: "./src/app/globals.css" };
|
|
59
|
+
|
|
60
|
+
export default config;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`next.config.ts`, with a Content-Security-Policy added where the project has one:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { securityHeaders } from "next-workers-kit/next";
|
|
67
|
+
|
|
68
|
+
const nextConfig: NextConfig = {
|
|
69
|
+
typedRoutes: true,
|
|
70
|
+
cacheComponents: false,
|
|
71
|
+
headers: () =>
|
|
72
|
+
Promise.resolve([{ source: "/:path*", headers: securityHeaders }]),
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**ESLint options**
|
|
77
|
+
|
|
78
|
+
| Option | Default | Effect |
|
|
79
|
+
| ------------ | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
80
|
+
| `root` | required | Repo root, for typed linting and import resolution |
|
|
81
|
+
| `typography` | `false` | Text styles only through `src/components/typography.tsx` |
|
|
82
|
+
| `installed` | shadcn paths | Files you install and never edit; exempt from the rules |
|
|
83
|
+
| `shared` | `components`, `hooks`, `lib`, `i18n`, `fonts`, `styles`, `types` | Folders under `src/` that count as shared code |
|
|
84
|
+
| `og` | `[]` | Extra files rendered by `next/og`, exempt from the class rules (`opengraph-image`, `twitter-image`, `icon`, `apple-icon` always are) |
|
|
85
|
+
| `ignores` | `[]` | Extra ignored paths |
|
|
86
|
+
|
|
87
|
+
Project-specific rules go after the spread, in the same `defineConfig` array.
|
|
88
|
+
|
|
89
|
+
**What lint enforces**
|
|
90
|
+
|
|
91
|
+
- `eslint-config-next` (Core Web Vitals and TypeScript), typescript-eslint `strictTypeChecked` and `stylisticTypeChecked`, jsx-a11y strict.
|
|
92
|
+
- Structure: `src/app` holds routes and imports features and shared code. A feature in `src/features/<feature>/` keeps its code in `components/`, `hooks/` or `lib/`, imports only itself and shared code, and never another feature. Shared code never imports a feature.
|
|
93
|
+
- Imports use `@/`, not `../` (except `messages/` for translations). `motion/react`, not `framer-motion`.
|
|
94
|
+
- Tailwind spacing divisible by four, or 2. With `typography`, text styles only from the typography roles.
|
|
95
|
+
- Braces on every control-flow body, a blank line before `return` and `throw` and around blocks, no unused `eslint-disable` comments.
|
|
96
|
+
- Prettier with Tailwind class sorting.
|
|
97
|
+
|
|
98
|
+
## doctor, sync and init
|
|
99
|
+
|
|
100
|
+
`npm run check` starts with `next-workers-kit doctor`. Run it as your Workers Builds build command (`npm run check && npx opennextjs-cloudflare build`) and a project that drifts can't deploy.
|
|
101
|
+
|
|
102
|
+
| Kind | Files | doctor checks |
|
|
103
|
+
| ------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
104
|
+
| Synced | `CLAUDE.md`, `.editorconfig`, `.gitattributes`, `.npmrc`, `.nvmrc`, `lefthook.yml`, `.github/dependabot.yml` | Identical to the package copy |
|
|
105
|
+
| Starter | `.gitignore`, `.prettierignore`, `knip.json`, `.mcp.json`, `.claude/settings.json`, ESLint, Prettier and TS configs | Still contain the baseline entries; add your own freely |
|
|
106
|
+
| Project | `package.json`, `next.config.ts`, `wrangler.jsonc`, `.dev.vars.example` | Baseline scripts, pins and settings; one `.dev.vars.example` line per required secret |
|
|
107
|
+
|
|
108
|
+
It also reports `.env*` files (OpenNext bundles them into the Worker; keep local secrets in `.dev.vars`), `src/middleware.ts` (use `proxy.ts`), and any `permissions.deny` or `ask` in `.claude/settings.json`: agents are never restricted through config.
|
|
109
|
+
|
|
110
|
+
- `npx next-workers-kit sync` rewrites the synced files and sets `packageManager` to the latest npm. Run it after upgrading this package.
|
|
111
|
+
- `npx next-workers-kit init` runs `sync` and writes any missing starter files. It never overwrites your files.
|
|
112
|
+
|
|
113
|
+
**Exceptions.** When a project legitimately needs a different script, declare it in `package.json` so it stays visible in review:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
"nextWorkersKit": {
|
|
117
|
+
"scripts": { "build": "next build --webpack" }
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`check` can't be overridden, because it runs `doctor`.
|
|
122
|
+
|
|
123
|
+
**Staying current.** Dependabot checks daily and waits three days after each release. When it upgrades this package, run `npx next-workers-kit sync` on that branch.
|
|
124
|
+
|
|
125
|
+
**Claude Code.** `.claude/settings.json` runs two hooks: one fixes lint and formats each file an agent edits inside the project, and one runs the typecheck before an agent stops when TypeScript files changed, handing errors back to it. `CLAUDE.md` imports `AGENTS.md`, so Claude Code reads the same instructions as other agents.
|
|
126
|
+
|
|
127
|
+
## Develop
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
npm test
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The tests build the package, lint `test/fixture` to check that each rule fires where it should and nowhere else, and run `doctor` against generated projects.
|
|
134
|
+
|
|
135
|
+
## Release
|
|
136
|
+
|
|
137
|
+
1. Change the code and its tests (the ESLint fixture or `test/doctor.test.js`), and commit.
|
|
138
|
+
2. `npm version patch` (fix), `minor` (a rule or doctor check that can fail existing code) or `major` (a removed option, a new required peer or a changed file path), then `git push --follow-tags`.
|
|
139
|
+
3. The Publish workflow tests and publishes the tag to npm through trusted publishing.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { doctor } from "./lib/doctor.js";
|
|
3
|
+
import { init, sync } from "./lib/sync.js";
|
|
4
|
+
import { command } from "./meta.js";
|
|
5
|
+
const root = process.cwd();
|
|
6
|
+
const action = process.argv[2];
|
|
7
|
+
if (action === "sync" || action === "init") {
|
|
8
|
+
const written = action === "sync" ? await sync(root) : await init(root);
|
|
9
|
+
console.log(written.length
|
|
10
|
+
? `Wrote ${written.join(", ")}.`
|
|
11
|
+
: "Everything is up to date.");
|
|
12
|
+
}
|
|
13
|
+
else if (action === "doctor") {
|
|
14
|
+
const problems = doctor(root);
|
|
15
|
+
if (problems.length) {
|
|
16
|
+
console.error(`${command} doctor found ${String(problems.length)} problem(s):\n${problems.map((problem) => ` ${problem}`).join("\n")}`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.error(`Usage: ${command} <init|sync|doctor>`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
package/dist/eslint.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Config } from "eslint/config";
|
|
2
|
+
export interface Options {
|
|
3
|
+
/** Repo root, for typed linting and import resolution: `import.meta.dirname`. */
|
|
4
|
+
root: string;
|
|
5
|
+
/** Allow text styles only through `src/components/typography.tsx`. */
|
|
6
|
+
typography?: boolean;
|
|
7
|
+
/** Files installed and never edited (shadcn by default); exempt from our rules. */
|
|
8
|
+
installed?: string[];
|
|
9
|
+
/** Folders under `src/` that count as shared code. */
|
|
10
|
+
shared?: string[];
|
|
11
|
+
/** Extra files rendered by `next/og`, exempt from the class rules. */
|
|
12
|
+
og?: string[];
|
|
13
|
+
/** Extra ignored paths. */
|
|
14
|
+
ignores?: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function config({ root, typography, installed, shared, og, ignores, }: Options): Config[];
|
package/dist/eslint.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import boundaries from "eslint-plugin-boundaries";
|
|
4
|
+
import prettier from "eslint-config-prettier/flat";
|
|
5
|
+
import nextVitals from "eslint-config-next/core-web-vitals";
|
|
6
|
+
import nextTs from "eslint-config-next/typescript";
|
|
7
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
8
|
+
import tseslint from "typescript-eslint";
|
|
9
|
+
import { featureLayout } from "./rules/feature-layout.js";
|
|
10
|
+
import { spacing } from "./rules/spacing.js";
|
|
11
|
+
import { typography, typographyStyle } from "./rules/typography.js";
|
|
12
|
+
const web = {
|
|
13
|
+
rules: { spacing, typography, "feature-layout": featureLayout },
|
|
14
|
+
};
|
|
15
|
+
// eslint-config-next ships resolver v3, which boundaries cannot load; point at our v4 by path.
|
|
16
|
+
const resolver = createRequire(import.meta.url).resolve("eslint-import-resolver-typescript");
|
|
17
|
+
const sources = ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"];
|
|
18
|
+
const app = ["src/**/*.{ts,tsx}"];
|
|
19
|
+
const scripts = ["**/*.{js,mjs,cjs}"];
|
|
20
|
+
const defaults = {
|
|
21
|
+
installed: [
|
|
22
|
+
"src/components/ui/**",
|
|
23
|
+
"src/hooks/use-mobile.ts",
|
|
24
|
+
"src/lib/utils.ts",
|
|
25
|
+
],
|
|
26
|
+
og: [
|
|
27
|
+
"**/opengraph-image.tsx",
|
|
28
|
+
"**/twitter-image.tsx",
|
|
29
|
+
"**/icon.tsx",
|
|
30
|
+
"**/apple-icon.tsx",
|
|
31
|
+
],
|
|
32
|
+
shared: ["components", "hooks", "lib", "i18n", "fonts", "styles", "types"],
|
|
33
|
+
};
|
|
34
|
+
function a11y() {
|
|
35
|
+
const plugin = nextVitals.find((entry) => entry.plugins?.["jsx-a11y"])
|
|
36
|
+
?.plugins?.["jsx-a11y"];
|
|
37
|
+
if (!plugin) {
|
|
38
|
+
throw new Error("eslint-config-next no longer registers jsx-a11y.");
|
|
39
|
+
}
|
|
40
|
+
return { files: sources, rules: plugin.flatConfigs.strict.rules };
|
|
41
|
+
}
|
|
42
|
+
function layers(root, shared) {
|
|
43
|
+
const elements = [
|
|
44
|
+
{ type: "app", pattern: "src/app" },
|
|
45
|
+
{ type: "feature", pattern: "src/features/*", capture: ["feature"] },
|
|
46
|
+
...shared.map((folder) => ({ type: "shared", pattern: `src/${folder}` })),
|
|
47
|
+
];
|
|
48
|
+
return {
|
|
49
|
+
files: app,
|
|
50
|
+
plugins: { boundaries: boundaries },
|
|
51
|
+
settings: {
|
|
52
|
+
"boundaries/root-path": root,
|
|
53
|
+
"boundaries/elements": elements,
|
|
54
|
+
"import/resolver": {
|
|
55
|
+
[resolver]: {
|
|
56
|
+
alwaysTryTypes: true,
|
|
57
|
+
project: join(root, "tsconfig.json"),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
rules: {
|
|
62
|
+
"boundaries/dependencies": [
|
|
63
|
+
"error",
|
|
64
|
+
{
|
|
65
|
+
default: "disallow",
|
|
66
|
+
message: "{{from.type}} cannot import {{to.type}}: features never import each other or app, and shared code never imports features.",
|
|
67
|
+
policies: [
|
|
68
|
+
{
|
|
69
|
+
from: { element: { type: "app" } },
|
|
70
|
+
allow: {
|
|
71
|
+
to: { element: { type: ["app", "feature", "shared"] } },
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
from: { element: { type: "feature" } },
|
|
76
|
+
allow: {
|
|
77
|
+
to: [
|
|
78
|
+
{
|
|
79
|
+
element: {
|
|
80
|
+
type: "feature",
|
|
81
|
+
captured: {
|
|
82
|
+
feature: "{{from.element.captured.feature}}",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{ element: { type: "shared" } },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
from: { element: { type: "shared" } },
|
|
92
|
+
allow: { to: { element: { type: "shared" } } },
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function features() {
|
|
101
|
+
return {
|
|
102
|
+
files: ["src/features/**"],
|
|
103
|
+
ignores: ["src/features/*/{components,hooks,lib}/**"],
|
|
104
|
+
plugins: { web },
|
|
105
|
+
rules: { "web/feature-layout": "error" },
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function imports() {
|
|
109
|
+
return {
|
|
110
|
+
files: app,
|
|
111
|
+
rules: {
|
|
112
|
+
"no-restricted-imports": [
|
|
113
|
+
"error",
|
|
114
|
+
{
|
|
115
|
+
paths: [{ name: "framer-motion", message: "Use motion/react." }],
|
|
116
|
+
patterns: [
|
|
117
|
+
{
|
|
118
|
+
regex: "^\\.\\./(?!.*/messages/)",
|
|
119
|
+
message: "Import with @/ instead of reaching into parent folders.",
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function style(installed) {
|
|
128
|
+
return {
|
|
129
|
+
files: sources,
|
|
130
|
+
ignores: installed,
|
|
131
|
+
rules: {
|
|
132
|
+
curly: ["error", "all"],
|
|
133
|
+
"no-empty": ["error", { allowEmptyCatch: true }],
|
|
134
|
+
"padding-line-between-statements": [
|
|
135
|
+
"error",
|
|
136
|
+
{ blankLine: "always", prev: "*", next: ["return", "throw"] },
|
|
137
|
+
{ blankLine: "always", prev: "block-like", next: "*" },
|
|
138
|
+
{ blankLine: "always", prev: "*", next: "block-like" },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function classes(roles, installed, og) {
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
files: app,
|
|
147
|
+
ignores: [...installed, "src/components/typography.tsx", ...og],
|
|
148
|
+
plugins: { web },
|
|
149
|
+
rules: {
|
|
150
|
+
"web/spacing": "error",
|
|
151
|
+
...(roles
|
|
152
|
+
? {
|
|
153
|
+
"web/typography": "error",
|
|
154
|
+
"no-restricted-syntax": ["error", typographyStyle],
|
|
155
|
+
}
|
|
156
|
+
: {}),
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
...(roles
|
|
160
|
+
? [
|
|
161
|
+
{
|
|
162
|
+
files: ["src/components/typography.tsx"],
|
|
163
|
+
plugins: { web },
|
|
164
|
+
rules: { "web/spacing": "error" },
|
|
165
|
+
},
|
|
166
|
+
]
|
|
167
|
+
: []),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
function vendored(installed) {
|
|
171
|
+
return defineConfig({
|
|
172
|
+
files: installed,
|
|
173
|
+
extends: [tseslint.configs.disableTypeChecked],
|
|
174
|
+
rules: {
|
|
175
|
+
"react-hooks/exhaustive-deps": "off",
|
|
176
|
+
"react-hooks/immutability": "off",
|
|
177
|
+
"react-hooks/purity": "off",
|
|
178
|
+
"react-hooks/refs": "off",
|
|
179
|
+
"react-hooks/set-state-in-effect": "off",
|
|
180
|
+
"react-hooks/static-components": "off",
|
|
181
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
182
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
183
|
+
"@typescript-eslint/consistent-type-definitions": "off",
|
|
184
|
+
"jsx-a11y/no-noninteractive-element-interactions": "off",
|
|
185
|
+
"jsx-a11y/no-static-element-interactions": "off",
|
|
186
|
+
"jsx-a11y/click-events-have-key-events": "off",
|
|
187
|
+
"jsx-a11y/heading-has-content": "off",
|
|
188
|
+
"jsx-a11y/anchor-has-content": "off",
|
|
189
|
+
"jsx-a11y/label-has-associated-control": "off",
|
|
190
|
+
"jsx-a11y/no-autofocus": "off",
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
export function config({ root, typography = false, installed = defaults.installed, shared = defaults.shared, og = [], ignores = [], }) {
|
|
195
|
+
if (!root) {
|
|
196
|
+
throw new Error("Pass the repo root: config({ root: import.meta.dirname }).");
|
|
197
|
+
}
|
|
198
|
+
return defineConfig([
|
|
199
|
+
globalIgnores([
|
|
200
|
+
".next/**",
|
|
201
|
+
"out/**",
|
|
202
|
+
"build/**",
|
|
203
|
+
"coverage/**",
|
|
204
|
+
".open-next/**",
|
|
205
|
+
".wrangler/**",
|
|
206
|
+
"next-env.d.ts",
|
|
207
|
+
"cloudflare-env.d.ts",
|
|
208
|
+
...ignores,
|
|
209
|
+
]),
|
|
210
|
+
...nextVitals,
|
|
211
|
+
...nextTs,
|
|
212
|
+
a11y(),
|
|
213
|
+
...tseslint.configs.strictTypeChecked,
|
|
214
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
215
|
+
{
|
|
216
|
+
languageOptions: {
|
|
217
|
+
parserOptions: { projectService: true, tsconfigRootDir: root },
|
|
218
|
+
},
|
|
219
|
+
linterOptions: { reportUnusedDisableDirectives: "error" },
|
|
220
|
+
rules: {
|
|
221
|
+
"@next/next/no-html-link-for-pages": "off",
|
|
222
|
+
"@typescript-eslint/restrict-template-expressions": [
|
|
223
|
+
"error",
|
|
224
|
+
{ allowNumber: true },
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{ files: scripts, extends: [tseslint.configs.disableTypeChecked] },
|
|
229
|
+
layers(root, shared),
|
|
230
|
+
features(),
|
|
231
|
+
imports(),
|
|
232
|
+
...classes(typography, installed, [...defaults.og, ...og]),
|
|
233
|
+
prettier,
|
|
234
|
+
style(installed),
|
|
235
|
+
...vendored(installed),
|
|
236
|
+
]);
|
|
237
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Claude Code PostToolUse hook: fix lint and format the file an agent just edited.
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
5
|
+
const input = JSON.parse(readFileSync(0, "utf8"));
|
|
6
|
+
const file = input.tool_input?.file_path;
|
|
7
|
+
const root = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
|
|
8
|
+
const path = typeof file === "string" ? relative(root, resolve(root, file)) : "";
|
|
9
|
+
// Leave files outside the project alone, such as notes in another folder.
|
|
10
|
+
if (path && !path.startsWith("..") && !isAbsolute(path)) {
|
|
11
|
+
const run = (command) => {
|
|
12
|
+
try {
|
|
13
|
+
execSync(`npx --no-install ${command} ${JSON.stringify(path)}`, {
|
|
14
|
+
cwd: root,
|
|
15
|
+
stdio: "ignore",
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Lint errors the fix can't resolve surface in npm run check.
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
if (/\.[cm]?[jt]sx?$/.test(path)) {
|
|
23
|
+
run("eslint --fix --no-warn-ignored");
|
|
24
|
+
}
|
|
25
|
+
run("prettier --write --ignore-unknown");
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Claude Code Stop hook: run the typecheck when TypeScript files changed, and
|
|
2
|
+
// hand any errors back to the agent instead of letting it stop.
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
const input = JSON.parse(readFileSync(0, "utf8"));
|
|
6
|
+
if (input.stop_hook_active) {
|
|
7
|
+
process.exit(0);
|
|
8
|
+
}
|
|
9
|
+
const options = {
|
|
10
|
+
cwd: process.env.CLAUDE_PROJECT_DIR ?? process.cwd(),
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
stdio: "pipe",
|
|
13
|
+
};
|
|
14
|
+
if (!/\.(?:ts|tsx|mts)$/m.test(execSync("git status --porcelain", options))) {
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
execSync("npm run typecheck", options);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const { stdout = "", stderr = "" } = error;
|
|
22
|
+
process.stderr.write(`${stdout}${stderr}`);
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|