next-workers-kit 0.0.0-stage → 2.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/lib/doctor.d.ts +2 -0
- package/dist/lib/doctor.js +270 -0
- package/dist/lib/files.d.ts +2 -0
- package/dist/lib/files.js +27 -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 +80 -4
- 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 +14 -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, commit and push 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`, 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
|
+
**When checks run.** Never after each edit: `lefthook` checks formatting and lint on staged files before a commit, runs `npm run check` before a push, and Workers Builds runs it again before every deploy. `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,270 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { command, configKey, packageName } from "../meta.js";
|
|
4
|
+
import { synced } from "./files.js";
|
|
5
|
+
import { parseJsonc } from "./jsonc.js";
|
|
6
|
+
export const scripts = {
|
|
7
|
+
dev: "next dev",
|
|
8
|
+
build: "next build",
|
|
9
|
+
typecheck: "next typegen && tsc --noEmit",
|
|
10
|
+
lint: "next typegen && eslint --max-warnings=0",
|
|
11
|
+
format: "prettier --write .",
|
|
12
|
+
fix: "eslint --fix && prettier --write .",
|
|
13
|
+
knip: "knip",
|
|
14
|
+
check: `${command} doctor && prettier --check . && npm run lint && npm run typecheck && knip`,
|
|
15
|
+
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
|
|
16
|
+
preview: "opennextjs-cloudflare build && opennextjs-cloudflare preview",
|
|
17
|
+
deploy: "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
|
|
18
|
+
upload: "opennextjs-cloudflare build && opennextjs-cloudflare upload",
|
|
19
|
+
prepare: "lefthook install",
|
|
20
|
+
};
|
|
21
|
+
const gitignore = [
|
|
22
|
+
"/node_modules",
|
|
23
|
+
"/.next/",
|
|
24
|
+
"/out/",
|
|
25
|
+
"/build",
|
|
26
|
+
"/coverage",
|
|
27
|
+
".DS_Store",
|
|
28
|
+
"*.pem",
|
|
29
|
+
"npm-debug.log*",
|
|
30
|
+
".env*",
|
|
31
|
+
".dev.vars*",
|
|
32
|
+
"!.dev.vars.example",
|
|
33
|
+
"/.open-next/",
|
|
34
|
+
"/.wrangler/",
|
|
35
|
+
"next-env.d.ts",
|
|
36
|
+
"*.tsbuildinfo",
|
|
37
|
+
".claude/settings.local.json",
|
|
38
|
+
"CLAUDE.local.md",
|
|
39
|
+
];
|
|
40
|
+
const prettierignore = [
|
|
41
|
+
"AGENTS.md",
|
|
42
|
+
"src/components/ui",
|
|
43
|
+
"cloudflare-env.d.ts",
|
|
44
|
+
];
|
|
45
|
+
const required = [
|
|
46
|
+
"AGENTS.md",
|
|
47
|
+
"README.md",
|
|
48
|
+
"cloudflare-env.d.ts",
|
|
49
|
+
"open-next.config.ts",
|
|
50
|
+
"next.config.ts",
|
|
51
|
+
"wrangler.jsonc",
|
|
52
|
+
];
|
|
53
|
+
function normalize(text) {
|
|
54
|
+
return text.replace(/\r\n/g, "\n");
|
|
55
|
+
}
|
|
56
|
+
// Ignore-file entries, compared without leading or trailing slashes so
|
|
57
|
+
// "dir", "/dir" and "dir/" match.
|
|
58
|
+
function ignoreEntry(line) {
|
|
59
|
+
return line.trim().replace(/^\/|\/$/g, "");
|
|
60
|
+
}
|
|
61
|
+
function lines(text) {
|
|
62
|
+
return new Set(normalize(text).split("\n").map(ignoreEntry));
|
|
63
|
+
}
|
|
64
|
+
export function doctor(root) {
|
|
65
|
+
const problems = [];
|
|
66
|
+
const report = (file, message) => problems.push(`${file}: ${message}`);
|
|
67
|
+
const read = (file) => {
|
|
68
|
+
const path = join(root, file);
|
|
69
|
+
return existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
70
|
+
};
|
|
71
|
+
const json = (file) => {
|
|
72
|
+
const text = read(file);
|
|
73
|
+
if (text === undefined) {
|
|
74
|
+
report(file, "missing");
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return parseJsonc(text);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
report(file, "is not valid JSON");
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
for (const file of required) {
|
|
86
|
+
if (read(file) === undefined) {
|
|
87
|
+
report(file, "missing");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const [file, source] of Object.entries(synced)) {
|
|
91
|
+
const text = read(file);
|
|
92
|
+
if (text === undefined ||
|
|
93
|
+
normalize(text) !== normalize(readFileSync(source, "utf8"))) {
|
|
94
|
+
report(file, `${text === undefined ? "missing" : "differs from the baseline"}; run npx ${command} sync`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const entry of readdirSync(root)) {
|
|
98
|
+
if (entry.startsWith(".env")) {
|
|
99
|
+
report(entry, "env files are not used; keep local secrets in .dev.vars");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (existsSync(join(root, "src/middleware.ts"))) {
|
|
103
|
+
report("src/middleware.ts", "use src/proxy.ts instead");
|
|
104
|
+
}
|
|
105
|
+
for (const [file, entries] of [
|
|
106
|
+
[".gitignore", gitignore],
|
|
107
|
+
[".prettierignore", prettierignore],
|
|
108
|
+
]) {
|
|
109
|
+
const text = read(file);
|
|
110
|
+
if (text === undefined) {
|
|
111
|
+
report(file, "missing");
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const present = lines(text);
|
|
115
|
+
for (const entry of entries.filter((line) => !present.has(ignoreEntry(line)))) {
|
|
116
|
+
report(file, `add "${entry}"`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const pkg = json("package.json");
|
|
120
|
+
if (pkg) {
|
|
121
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
122
|
+
const exceptions = (pkg[configKey] ?? {});
|
|
123
|
+
const overrides = exceptions.scripts ?? {};
|
|
124
|
+
if ("check" in overrides) {
|
|
125
|
+
report("package.json", `${configKey}.scripts can't override check, which runs ${command} doctor`);
|
|
126
|
+
}
|
|
127
|
+
for (const [name, baseline] of Object.entries(scripts)) {
|
|
128
|
+
const expected = name === "check" ? baseline : (overrides[name] ?? baseline);
|
|
129
|
+
if (pkg.scripts?.[name] !== expected) {
|
|
130
|
+
report("package.json", `scripts.${name} must be "${expected}"`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// A project may raise the minimum within Node 24 when a dependency needs it.
|
|
134
|
+
if (!/^>=24(?:\.\d+){0,2} <25$/.test(pkg.engines?.node ?? "")) {
|
|
135
|
+
report("package.json", 'engines.node must be ">=24 <25" (or a higher Node 24 minimum)');
|
|
136
|
+
}
|
|
137
|
+
const npm = /^npm@(\d+)\.\d+\.\d+$/.exec(pkg.packageManager ?? "");
|
|
138
|
+
if (!npm || Number(npm[1]) < 12) {
|
|
139
|
+
report("package.json", `packageManager must name an exact npm 12 or later; npx ${command} sync sets the latest`);
|
|
140
|
+
}
|
|
141
|
+
if (deps.typescript !== "6.0.3") {
|
|
142
|
+
report("package.json", 'typescript must be exactly "6.0.3"');
|
|
143
|
+
}
|
|
144
|
+
if (deps["eslint-config-next"] !== deps.next) {
|
|
145
|
+
report("package.json", "eslint-config-next must match the next version");
|
|
146
|
+
}
|
|
147
|
+
for (const name of [
|
|
148
|
+
packageName,
|
|
149
|
+
"eslint",
|
|
150
|
+
"prettier",
|
|
151
|
+
"knip",
|
|
152
|
+
"lefthook",
|
|
153
|
+
]) {
|
|
154
|
+
if (!deps[name]) {
|
|
155
|
+
report("package.json", `add ${name} as a dependency`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const knip = json("knip.json");
|
|
160
|
+
if (knip) {
|
|
161
|
+
if (!knip.entry?.includes("open-next.config.ts")) {
|
|
162
|
+
report("knip.json", 'entry must include "open-next.config.ts"');
|
|
163
|
+
}
|
|
164
|
+
const ui = knip.ignoreIssues?.["src/components/ui/**"] ?? [];
|
|
165
|
+
if (!ui.includes("exports") || !ui.includes("types")) {
|
|
166
|
+
report("knip.json", 'ignoreIssues["src/components/ui/**"] must include "exports" and "types"');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const mcp = read(".mcp.json");
|
|
170
|
+
if (mcp === undefined) {
|
|
171
|
+
report(".mcp.json", "missing");
|
|
172
|
+
}
|
|
173
|
+
else if (!mcp.includes("next-devtools-mcp")) {
|
|
174
|
+
report(".mcp.json", "add the next-devtools-mcp server");
|
|
175
|
+
}
|
|
176
|
+
const settings = existsSync(join(root, ".claude/settings.json"))
|
|
177
|
+
? json(".claude/settings.json")
|
|
178
|
+
: undefined;
|
|
179
|
+
if (settings) {
|
|
180
|
+
// Agents may do everything; checks run at commit, push and deploy instead.
|
|
181
|
+
for (const rule of ["deny", "ask"]) {
|
|
182
|
+
if (settings.permissions?.[rule]?.length) {
|
|
183
|
+
report(".claude/settings.json", `remove permissions.${rule}; agents are not restricted`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (JSON.stringify(settings.hooks ?? {}).includes(`${packageName}/dist/hooks`)) {
|
|
187
|
+
report(".claude/settings.json", `remove the ${packageName} hooks; checks run at commit, push and deploy`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const [file, needle] of [
|
|
191
|
+
["eslint.config.mjs", `${packageName}/eslint`],
|
|
192
|
+
["prettier.config.mjs", `${packageName}/prettier`],
|
|
193
|
+
["tsconfig.json", `${packageName}/tsconfig.json`],
|
|
194
|
+
]) {
|
|
195
|
+
const text = read(file);
|
|
196
|
+
if (text === undefined) {
|
|
197
|
+
report(file, "missing");
|
|
198
|
+
}
|
|
199
|
+
else if (!text.includes(needle)) {
|
|
200
|
+
report(file, `must use ${needle}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const next = read("next.config.ts");
|
|
204
|
+
if (next !== undefined) {
|
|
205
|
+
for (const [pattern, message] of [
|
|
206
|
+
[/typedRoutes:\s*true/, "set typedRoutes: true"],
|
|
207
|
+
[
|
|
208
|
+
/cacheComponents:\s*false/,
|
|
209
|
+
"set cacheComponents: false (OpenNext #1464)",
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
/securityHeaders/,
|
|
213
|
+
`send securityHeaders from ${packageName}/next in headers()`,
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
/PHASE_DEVELOPMENT_SERVER/,
|
|
217
|
+
"call initOpenNextCloudflareForDev() only in PHASE_DEVELOPMENT_SERVER",
|
|
218
|
+
],
|
|
219
|
+
]) {
|
|
220
|
+
if (!pattern.test(next)) {
|
|
221
|
+
report("next.config.ts", message);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const wrangler = existsSync(join(root, "wrangler.jsonc"))
|
|
226
|
+
? json("wrangler.jsonc")
|
|
227
|
+
: undefined;
|
|
228
|
+
if (wrangler) {
|
|
229
|
+
const flags = wrangler.compatibility_flags ?? [];
|
|
230
|
+
if (wrangler.main !== ".open-next/worker.js") {
|
|
231
|
+
report("wrangler.jsonc", 'main must be ".open-next/worker.js"');
|
|
232
|
+
}
|
|
233
|
+
for (const flag of ["nodejs_compat", "global_fetch_strictly_public"]) {
|
|
234
|
+
if (!flags.includes(flag)) {
|
|
235
|
+
report("wrangler.jsonc", `compatibility_flags must include "${flag}"`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (wrangler.assets?.directory !== ".open-next/assets" ||
|
|
239
|
+
wrangler.assets.binding !== "ASSETS") {
|
|
240
|
+
report("wrangler.jsonc", 'assets must be { "directory": ".open-next/assets", "binding": "ASSETS" }');
|
|
241
|
+
}
|
|
242
|
+
for (const key of ["workers_dev", "preview_urls"]) {
|
|
243
|
+
if (wrangler[key] !== true) {
|
|
244
|
+
report("wrangler.jsonc", `set ${key}: true (dashboard-created Workers start with it off)`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (wrangler.observability?.enabled !== true) {
|
|
248
|
+
report("wrangler.jsonc", "set observability.enabled: true");
|
|
249
|
+
}
|
|
250
|
+
if (!wrangler.routes?.length) {
|
|
251
|
+
report("wrangler.jsonc", "declare the site's custom domains in routes");
|
|
252
|
+
}
|
|
253
|
+
else if (wrangler.dev?.host !== "localhost") {
|
|
254
|
+
report("wrangler.jsonc", 'set dev.host: "localhost" so local previews do not use the first route');
|
|
255
|
+
}
|
|
256
|
+
const secrets = wrangler.secrets?.required ?? [];
|
|
257
|
+
if (secrets.length) {
|
|
258
|
+
const example = read(".dev.vars.example");
|
|
259
|
+
if (example === undefined) {
|
|
260
|
+
report(".dev.vars.example", "missing; list the names in secrets.required");
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
for (const name of secrets.filter((secret) => !new RegExp(`^${secret}=`, "m").test(example))) {
|
|
264
|
+
report(".dev.vars.example", `add ${name}=`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return problems;
|
|
270
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { packageRoot } from "../meta.js";
|
|
3
|
+
const templates = join(packageRoot, "templates");
|
|
4
|
+
// Identical in every project and owned by this package: `sync` writes them,
|
|
5
|
+
// `doctor` fails when they differ. npm drops dotfiles such as .npmrc from
|
|
6
|
+
// packages, so the templates are stored without the leading dot.
|
|
7
|
+
export const synced = {
|
|
8
|
+
"CLAUDE.md": join(templates, "synced", "CLAUDE.md"),
|
|
9
|
+
".editorconfig": join(templates, "synced", "editorconfig"),
|
|
10
|
+
".gitattributes": join(templates, "synced", "gitattributes"),
|
|
11
|
+
".npmrc": join(templates, "synced", "npmrc"),
|
|
12
|
+
".nvmrc": join(templates, "synced", "nvmrc"),
|
|
13
|
+
"lefthook.yml": join(templates, "synced", "lefthook.yml"),
|
|
14
|
+
".github/dependabot.yml": join(templates, "synced", "dependabot.yml"),
|
|
15
|
+
};
|
|
16
|
+
// Owned by the project, which may add to them. `init` writes them once;
|
|
17
|
+
// `doctor` checks that they still contain the baseline. "{{package}}" in a
|
|
18
|
+
// starter becomes this package's name.
|
|
19
|
+
export const starters = {
|
|
20
|
+
".gitignore": join(templates, "init", "gitignore"),
|
|
21
|
+
".prettierignore": join(templates, "init", "prettierignore"),
|
|
22
|
+
"knip.json": join(templates, "init", "knip.json"),
|
|
23
|
+
".mcp.json": join(templates, "init", "mcp.json"),
|
|
24
|
+
"eslint.config.mjs": join(templates, "init", "eslint.config.mjs"),
|
|
25
|
+
"prettier.config.mjs": join(templates, "init", "prettier.config.mjs"),
|
|
26
|
+
"tsconfig.json": join(templates, "init", "tsconfig.json"),
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseJsonc(text: string): unknown;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Parses JSON with comments and trailing commas, as in wrangler.jsonc.
|
|
2
|
+
export function parseJsonc(text) {
|
|
3
|
+
let out = "";
|
|
4
|
+
let i = 0;
|
|
5
|
+
while (i < text.length) {
|
|
6
|
+
const char = text[i];
|
|
7
|
+
if (char === '"') {
|
|
8
|
+
const start = i;
|
|
9
|
+
i += 1;
|
|
10
|
+
while (i < text.length && text[i] !== '"') {
|
|
11
|
+
i += text[i] === "\\" ? 2 : 1;
|
|
12
|
+
}
|
|
13
|
+
i += 1;
|
|
14
|
+
out += text.slice(start, i);
|
|
15
|
+
}
|
|
16
|
+
else if (char === "/" && text[i + 1] === "/") {
|
|
17
|
+
while (i < text.length && text[i] !== "\n") {
|
|
18
|
+
i += 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (char === "/" && text[i + 1] === "*") {
|
|
22
|
+
const end = text.indexOf("*/", i + 2);
|
|
23
|
+
i = end === -1 ? text.length : end + 2;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
out += char;
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
31
|
+
}
|
package/dist/lib/sync.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { packageName } from "../meta.js";
|
|
4
|
+
import { starters, synced } from "./files.js";
|
|
5
|
+
function write(root, files, overwrite) {
|
|
6
|
+
const written = [];
|
|
7
|
+
for (const [target, source] of Object.entries(files)) {
|
|
8
|
+
const path = join(root, target);
|
|
9
|
+
const content = readFileSync(source, "utf8").replaceAll("{{package}}", packageName);
|
|
10
|
+
if (existsSync(path) &&
|
|
11
|
+
(!overwrite || readFileSync(path, "utf8") === content)) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
15
|
+
writeFileSync(path, content);
|
|
16
|
+
written.push(target);
|
|
17
|
+
}
|
|
18
|
+
return written;
|
|
19
|
+
}
|
|
20
|
+
// Workers Builds installs the npm that packageManager names, and Dependabot
|
|
21
|
+
// doesn't update that field, so sync moves it to the latest npm.
|
|
22
|
+
async function latestNpm(root) {
|
|
23
|
+
const path = join(root, "package.json");
|
|
24
|
+
if (!existsSync(path)) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch("https://registry.npmjs.org/npm/latest");
|
|
29
|
+
const { version } = (await response.json());
|
|
30
|
+
const text = readFileSync(path, "utf8");
|
|
31
|
+
const pkg = JSON.parse(text);
|
|
32
|
+
const packageManager = `npm@${version}`;
|
|
33
|
+
if (pkg.packageManager === packageManager) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
pkg.packageManager = packageManager;
|
|
37
|
+
writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
38
|
+
return [`package.json (packageManager ${packageManager})`];
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function sync(root, { packageManager = true } = {}) {
|
|
45
|
+
return [
|
|
46
|
+
...write(root, synced, true),
|
|
47
|
+
...(packageManager ? await latestNpm(root) : []),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
export async function init(root, options = {}) {
|
|
51
|
+
return [...(await sync(root, options)), ...write(root, starters, false)];
|
|
52
|
+
}
|
package/dist/meta.d.ts
ADDED
package/dist/meta.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
// The package's own name and command, so files and messages follow a rename.
|
|
4
|
+
export const packageRoot = join(import.meta.dirname, "..");
|
|
5
|
+
const manifest = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
|
|
6
|
+
export const packageName = manifest.name;
|
|
7
|
+
export const command = Object.keys(manifest.bin)[0] ?? packageName;
|
|
8
|
+
// The package.json field where a project declares its exceptions.
|
|
9
|
+
export const configKey = command.replace(/-(\w)/g, (_, letter) => letter.toUpperCase());
|
package/dist/next.d.ts
ADDED
package/dist/next.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Security headers for every route. Add a Content-Security-Policy per project:
|
|
2
|
+
// headers: () => [{ source: "/:path*", headers: [...securityHeaders, csp] }]
|
|
3
|
+
export const securityHeaders = [
|
|
4
|
+
{
|
|
5
|
+
key: "Strict-Transport-Security",
|
|
6
|
+
value: "max-age=63072000; includeSubDomains",
|
|
7
|
+
},
|
|
8
|
+
{ key: "X-Frame-Options", value: "DENY" },
|
|
9
|
+
{ key: "X-Content-Type-Options", value: "nosniff" },
|
|
10
|
+
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
|
|
11
|
+
{
|
|
12
|
+
key: "Permissions-Policy",
|
|
13
|
+
value: "accelerometer=(), camera=(), display-capture=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), usb=()",
|
|
14
|
+
},
|
|
15
|
+
];
|
package/dist/prettier.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function classRule(message, breaks) {
|
|
2
|
+
return {
|
|
3
|
+
meta: { type: "suggestion", schema: [], messages: { token: message } },
|
|
4
|
+
create(context) {
|
|
5
|
+
function check(node, text) {
|
|
6
|
+
if (typeof text !== "string") {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
for (const token of text.split(/\s+/)) {
|
|
10
|
+
if (breaks(token)) {
|
|
11
|
+
context.report({
|
|
12
|
+
node,
|
|
13
|
+
messageId: "token",
|
|
14
|
+
data: { utility: token },
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
Literal: (node) => {
|
|
21
|
+
check(node, node.value);
|
|
22
|
+
},
|
|
23
|
+
TemplateElement: (node) => {
|
|
24
|
+
check(node, node.value.cooked);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const featureLayout = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
schema: [],
|
|
5
|
+
messages: {
|
|
6
|
+
folder: "Feature code lives in components/, hooks/ or lib/ inside src/features/<feature>/.",
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
create(context) {
|
|
10
|
+
return {
|
|
11
|
+
Program: (node) => {
|
|
12
|
+
context.report({ node, messageId: "folder" });
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const spacing: import("eslint").Rule.RuleModule;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { classRule } from "./class-rule.js";
|
|
2
|
+
const pattern = /(?:^|:)!?-?((?:[mp](?:[trblxyse]|[bi][se]?)?|space-[xy]|gap(?:-[xy])?))-(.+?)(?:!)?$/;
|
|
3
|
+
export const spacing = classRule('Use a Tailwind spacing number divisible by four, or 2, instead of "{{utility}}".', (token) => {
|
|
4
|
+
const match = pattern.exec(token);
|
|
5
|
+
if (!match) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const [, property = "", value = ""] = match;
|
|
9
|
+
if (property.startsWith("m") && value === "auto") {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (property.startsWith("space-") && value === "reverse") {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (/^[[(].*--/.test(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// Other strings, such as storage keys, can look like a spacing utility.
|
|
19
|
+
if (!/^(?:[\d.]+|px|\[.*\]|\(.*\))$/.test(value)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return !(value === "2" || (/^\d+$/.test(value) && Number(value) % 4 === 0));
|
|
23
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { classRule } from "./class-rule.js";
|
|
2
|
+
const pattern = /(?:^|:)!?-?(?:text-(?:xs|sm|base|lg|[2-9]?xl)(?:\/\S+)?|text-[[(]\S+|font-\S+|leading-\S+|tracking-\S+|italic|not-italic|uppercase|lowercase|capitalize|normal-case)!?$/;
|
|
3
|
+
export const typography = classRule('Use a role from components/typography.tsx instead of "{{utility}}".', (token) => pattern.test(token));
|
|
4
|
+
export const typographyStyle = {
|
|
5
|
+
selector: 'JSXAttribute[name.name="style"] Property[key.name=/^(font|fontFamily|fontSize|fontStyle|fontWeight|letterSpacing|lineHeight|textTransform)$/]',
|
|
6
|
+
message: "Use a role from components/typography.tsx.",
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-workers-kit",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Config, structure rules and drift checks for Next.js on Cloudflare Workers (OpenNext): ESLint, TypeScript, Prettier and a project doctor",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "pnilssson",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pnilssson/next-workers-kit.git"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./eslint": {
|
|
14
|
+
"types": "./dist/eslint.d.ts",
|
|
15
|
+
"default": "./dist/eslint.js"
|
|
16
|
+
},
|
|
17
|
+
"./next": {
|
|
18
|
+
"types": "./dist/next.d.ts",
|
|
19
|
+
"default": "./dist/next.js"
|
|
20
|
+
},
|
|
21
|
+
"./prettier": {
|
|
22
|
+
"types": "./dist/prettier.d.ts",
|
|
23
|
+
"default": "./dist/prettier.js"
|
|
24
|
+
},
|
|
25
|
+
"./tsconfig.json": "./tsconfig.base.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"templates",
|
|
30
|
+
"tsconfig.base.json"
|
|
31
|
+
],
|
|
32
|
+
"packageManager": "npm@12.2.1",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=24 <25"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"prepack": "npm run build",
|
|
39
|
+
"test": "npm run build && node --test test/*.test.js",
|
|
40
|
+
"format": "prettier --write .",
|
|
41
|
+
"format:check": "prettier --check ."
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"eslint-config-prettier": "^10.1.8",
|
|
45
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
46
|
+
"eslint-plugin-boundaries": "^7.4.0",
|
|
47
|
+
"prettier-plugin-tailwindcss": "^0.8.1",
|
|
48
|
+
"typescript-eslint": "^8.72.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"eslint": "^10.13.0",
|
|
52
|
+
"eslint-config-next": ">=16.4.0",
|
|
53
|
+
"prettier": "^3.9.0",
|
|
54
|
+
"typescript": ">=6.0.3 <6.1.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^24.19.2",
|
|
58
|
+
"@types/react": "^19.3.0",
|
|
59
|
+
"eslint": "10.13.0",
|
|
60
|
+
"eslint-config-next": "16.4.3",
|
|
61
|
+
"next": "16.4.3",
|
|
62
|
+
"prettier": "3.9.10",
|
|
63
|
+
"react": "19.3.1",
|
|
64
|
+
"typescript": "6.0.3"
|
|
65
|
+
},
|
|
66
|
+
"bin": {
|
|
67
|
+
"next-workers-kit": "./dist/cli.js"
|
|
68
|
+
},
|
|
69
|
+
"keywords": [
|
|
70
|
+
"nextjs",
|
|
71
|
+
"cloudflare",
|
|
72
|
+
"cloudflare-workers",
|
|
73
|
+
"opennext",
|
|
74
|
+
"eslint-config",
|
|
75
|
+
"prettier-config",
|
|
76
|
+
"tsconfig"
|
|
77
|
+
],
|
|
78
|
+
"homepage": "https://github.com/pnilssson/next-workers-kit#readme",
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/pnilssson/next-workers-kit/issues"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# dependencies
|
|
2
|
+
/node_modules
|
|
3
|
+
|
|
4
|
+
# next.js
|
|
5
|
+
/.next/
|
|
6
|
+
/out/
|
|
7
|
+
/build
|
|
8
|
+
next-env.d.ts
|
|
9
|
+
*.tsbuildinfo
|
|
10
|
+
|
|
11
|
+
# testing
|
|
12
|
+
/coverage
|
|
13
|
+
|
|
14
|
+
# misc
|
|
15
|
+
.DS_Store
|
|
16
|
+
*.pem
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
|
|
19
|
+
# env files
|
|
20
|
+
.env*
|
|
21
|
+
.dev.vars*
|
|
22
|
+
!.dev.vars.example
|
|
23
|
+
|
|
24
|
+
# cloudflare
|
|
25
|
+
/.open-next/
|
|
26
|
+
/.wrangler/
|
|
27
|
+
|
|
28
|
+
# agents
|
|
29
|
+
.claude/settings.local.json
|
|
30
|
+
CLAUDE.local.md
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "{{package}}/tsconfig.json",
|
|
3
|
+
"compilerOptions": { "paths": { "@/*": ["./src/*"] } },
|
|
4
|
+
"include": [
|
|
5
|
+
"next-env.d.ts",
|
|
6
|
+
"cloudflare-env.d.ts",
|
|
7
|
+
"**/*.ts",
|
|
8
|
+
"**/*.tsx",
|
|
9
|
+
"**/*.mts",
|
|
10
|
+
".next/types/**/*.ts",
|
|
11
|
+
".next/dev/types/**/*.ts"
|
|
12
|
+
],
|
|
13
|
+
"exclude": ["node_modules"]
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: /
|
|
5
|
+
schedule:
|
|
6
|
+
interval: daily
|
|
7
|
+
cooldown:
|
|
8
|
+
default-days: 3
|
|
9
|
+
ignore:
|
|
10
|
+
# typescript-eslint supports TypeScript below 6.1.
|
|
11
|
+
- dependency-name: typescript
|
|
12
|
+
versions: [">=6.1"]
|
|
13
|
+
groups:
|
|
14
|
+
next:
|
|
15
|
+
patterns: ["next", "eslint-config-next"]
|
|
16
|
+
react:
|
|
17
|
+
patterns: ["react", "react-dom", "@types/react", "@types/react-dom"]
|
|
18
|
+
cloudflare:
|
|
19
|
+
patterns: ["@opennextjs/cloudflare", "wrangler"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
pre-commit:
|
|
2
|
+
parallel: true
|
|
3
|
+
jobs:
|
|
4
|
+
- name: prettier
|
|
5
|
+
glob: "*.{js,mjs,cjs,ts,tsx,mts,json,jsonc,css,md,yml,yaml}"
|
|
6
|
+
run: npx prettier --check {staged_files}
|
|
7
|
+
- name: eslint
|
|
8
|
+
glob: "*.{js,mjs,cjs,ts,tsx,mts}"
|
|
9
|
+
run: npx eslint --max-warnings=0 --no-warn-ignored {staged_files}
|
|
10
|
+
|
|
11
|
+
pre-push:
|
|
12
|
+
jobs:
|
|
13
|
+
- name: check
|
|
14
|
+
run: npm run check
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
allow-scripts-pin=false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"types": ["node"],
|
|
10
|
+
"allowJs": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"forceConsistentCasingInFileNames": true,
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUncheckedIndexedAccess": true,
|
|
20
|
+
"noImplicitOverride": true,
|
|
21
|
+
"noImplicitReturns": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
24
|
+
"erasableSyntaxOnly": true,
|
|
25
|
+
"noUncheckedSideEffectImports": true,
|
|
26
|
+
"plugins": [{ "name": "next" }]
|
|
27
|
+
}
|
|
28
|
+
}
|