@ingram-tech/nk-dev 0.18.0 → 0.20.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/README.md +11 -5
- package/guide.md +6 -3
- package/lib/agent-guide.js +59 -20
- package/lib/app-dir.js +34 -0
- package/lib/auth-next.js +1 -1
- package/lib/auth-shadow.js +5 -6
- package/lib/doctor.js +46 -44
- package/lib/init.js +3 -20
- package/lib/og-image.js +2 -5
- package/lib/oxlint-plugins/base-ui-native-button.js +28 -23
- package/lib/oxlint-plugins/no-crypto-random-uuid.js +23 -13
- package/lib/oxlint-plugins/no-server-env-in-client.js +36 -14
- package/lib/oxlint-plugins/no-sql-array-cast.js +3 -2
- package/lib/passthrough.js +10 -4
- package/lib/run.js +11 -4
- package/lib/tsgolint.js +35 -0
- package/package.json +9 -8
- package/skills/ts-codemod.md +1 -1
package/README.md
CHANGED
|
@@ -81,8 +81,10 @@ tsc), so versions stay under your control. nk only orchestrates.
|
|
|
81
81
|
skips files that already exist.
|
|
82
82
|
- **`nk doctor [--fix]`** — report drift from the canonical nk-dev toolchain
|
|
83
83
|
(superseded deps, config `extends`, package.json scripts, the agent-guide
|
|
84
|
-
import
|
|
85
|
-
|
|
84
|
+
import (from any CLAUDE.md up to the repository root), a stale
|
|
85
|
+
`.prettierignore`, an unsealed migration chain and the DDL in it drizzle
|
|
86
|
+
can't model, routes in a root `app/` instead of `src/app/`, a page under
|
|
87
|
+
`src/app/auth/` shadowing a Better Auth
|
|
86
88
|
endpoint — static segments beat the `[...all]` catch-all, so such a page
|
|
87
89
|
silently 405s the endpoint, a page or layout whose `openGraph` carries no
|
|
88
90
|
image — its own object replaces the inherited one, so the card unfurls as a
|
|
@@ -96,7 +98,10 @@ tsc), so versions stay under your control. nk only orchestrates.
|
|
|
96
98
|
- **`nk format` / `nk format --check`** — formats code (JS/TS/JSON/CSS) with
|
|
97
99
|
oxfmt. `--check` verifies without writing (CI). SQL isn't formatted; see
|
|
98
100
|
[Why no SQL formatting?](#why-no-sql-formatting).
|
|
99
|
-
- **`nk lint`** — `oxlint`.
|
|
101
|
+
- **`nk lint`** — `oxlint`. nk-dev ships oxlint's type-aware backend
|
|
102
|
+
(`oxlint-tsgolint`) and hands it to oxlint, so a site turns on type-aware
|
|
103
|
+
rules with `"options": { "typeAware": true }` in `.oxlintrc.json` and
|
|
104
|
+
declares nothing else. An `OXLINT_TSGOLINT_PATH` you set wins.
|
|
100
105
|
- **`nk knip`** — `knip` (unused dependencies / exports / files).
|
|
101
106
|
- **`nk migrations [--check|--reseal|--ddl]`** — guard the `drizzle/` migration
|
|
102
107
|
chain, with no database involved. Verifies each file against the hashes in
|
|
@@ -113,8 +118,9 @@ tsc), so versions stay under your control. nk only orchestrates.
|
|
|
113
118
|
apply → `nk format` + `nk type-check`) and its syntactic-not-semantic limits
|
|
114
119
|
live in the codemod skill, `skills/ts-codemod.md`.
|
|
115
120
|
- **`nk check`** — `oxlint` + `oxfmt --check` + `knip` (only when the repo has a
|
|
116
|
-
knip config) + the agent-guide import gate
|
|
117
|
-
|
|
121
|
+
knip config) + the agent-guide import gate (any CLAUDE.md from the site up
|
|
122
|
+
to the repository root) + the migration seal. The CI gate; runs every
|
|
123
|
+
checker and reports them all before failing.
|
|
118
124
|
- **`nk type-check`** — `next typegen && tsc --noEmit`, with recovery: when
|
|
119
125
|
every error sits inside generated types (`.next/types`, `.next/dev/types` —
|
|
120
126
|
a deleted route or a killed dev server leaves them stale, and `next typegen`
|
package/guide.md
CHANGED
|
@@ -7,18 +7,21 @@ package. Stay a thin, standard Next.js app (bun · oxlint + oxfmt · strict TS).
|
|
|
7
7
|
## Hard rules
|
|
8
8
|
|
|
9
9
|
- **Public contact/signup forms MUST use `@ingram-tech/nk-forms`** — one
|
|
10
|
-
`createFormsHandler` registry at `app/internal/forms/[form]/route.ts`
|
|
10
|
+
`createFormsHandler` registry at `src/app/internal/forms/[form]/route.ts`
|
|
11
11
|
(rate-limit → bot gate → validate → escaped-email deliver → uniform 200)
|
|
12
12
|
and `useFormSubmit(formEndpoint(name))` + `HoneypotInput` client-side.
|
|
13
13
|
Forms are plumbing, not API: never mount one under `/api/…` (see Route & URL
|
|
14
14
|
conventions). For guarding a *non-form* endpoint (a checkout, an authed
|
|
15
15
|
route), call nk-forms' `checkBot` / `verifyHuman` directly instead of the
|
|
16
16
|
pipeline. Never ship a public form without the bot gate.
|
|
17
|
+
- **Routes live in `src/app/`, never a root `app/`.** Next prefers a root
|
|
18
|
+
`app/` and silently ignores `src/app/` when both exist, and nk's checks and
|
|
19
|
+
lint rules only look in `src/app/`. `nk doctor` rejects a root `app/`.
|
|
17
20
|
- **Send email only via `@ingram-tech/nk-email`** — never add another mail client.
|
|
18
21
|
- **Never trust an external request body's shape — validate it with Zod, never
|
|
19
22
|
`as`-cast it.** Every `/api` route and webhook handler takes untrusted input;
|
|
20
23
|
an `as` cast is a lie the type-checker can't catch at runtime.
|
|
21
|
-
`nextkit/no-unvalidated-request-body` enforces this in `app/**/route.ts`:
|
|
24
|
+
`nextkit/no-unvalidated-request-body` enforces this in `src/app/**/route.ts`:
|
|
22
25
|
cast the parsed body to `unknown` on the way into a schema, never to a shape.
|
|
23
26
|
- Format/lint with **oxlint + oxfmt** via `nk` (`@ingram-tech/nk-dev`); don't
|
|
24
27
|
reintroduce ESLint or Prettier (SQL isn't formatted — it's generated). nk-dev
|
|
@@ -39,7 +42,7 @@ package. Stay a thin, standard Next.js app (bun · oxlint + oxfmt · strict TS).
|
|
|
39
42
|
Keep the URL namespace honest about **who calls each route**:
|
|
40
43
|
|
|
41
44
|
- **`/auth/…` — sign-in, via `@ingram-tech/nk-auth`.** Better Auth mounts here
|
|
42
|
-
through `basePath: authBasePath` (handler at `app/auth/[...all]/route.ts`,
|
|
45
|
+
through `basePath: authBasePath` (handler at `src/app/auth/[...all]/route.ts`,
|
|
43
46
|
client `createAuthClient({ basePath: authBasePath })`) — **not** the framework
|
|
44
47
|
default `/api/auth`. So **login / social OAuth callbacks are
|
|
45
48
|
`<site>/auth/callback/<provider>`** (e.g. Google `…/auth/callback/google`) —
|
package/lib/agent-guide.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, relative, resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** The line that `@import`s the shared guide into a CLAUDE.md. */
|
|
5
|
+
export const GUIDE_IMPORT = "@./node_modules/@ingram-tech/nk-dev/guide.md";
|
|
6
|
+
|
|
7
|
+
// Any spelling of the import, e.g.
|
|
5
8
|
// @./node_modules/@ingram-tech/nk-dev/guide.md
|
|
6
9
|
// @./web/node_modules/@ingram-tech/nk-dev/guide.md (app in a subdir)
|
|
7
10
|
const IMPORT_RE = /@\S*nk-dev\/guide\.md/;
|
|
@@ -15,21 +18,39 @@ function readDeps(cwd) {
|
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Every CLAUDE.md from `cwd` up to the repository root, nearest first. Claude
|
|
23
|
+
* Code loads all of them, so an import in any one reaches the agent. The walk
|
|
24
|
+
* stops at the directory holding `.git`: a CLAUDE.md above the repository is
|
|
25
|
+
* absent in CI, and must not pass the gate on one machine only.
|
|
26
|
+
*/
|
|
27
|
+
function claudeFiles(cwd) {
|
|
28
|
+
const files = [];
|
|
29
|
+
let dir = resolve(cwd);
|
|
30
|
+
for (;;) {
|
|
31
|
+
const file = resolve(dir, "CLAUDE.md");
|
|
32
|
+
if (existsSync(file)) files.push(file);
|
|
33
|
+
const parent = dirname(dir);
|
|
34
|
+
if (existsSync(resolve(dir, ".git")) || parent === dir) return files;
|
|
35
|
+
dir = parent;
|
|
24
36
|
}
|
|
25
|
-
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The CLAUDE.md that imports the guide, from `cwd` up to the repository root. */
|
|
40
|
+
function findGuideImport(cwd) {
|
|
41
|
+
const files = claudeFiles(cwd);
|
|
42
|
+
return {
|
|
43
|
+
files,
|
|
44
|
+
importer: files.find((file) => IMPORT_RE.test(readFileSync(file, "utf8"))),
|
|
45
|
+
};
|
|
26
46
|
}
|
|
27
47
|
|
|
28
48
|
/**
|
|
29
49
|
* nextkit's shared agent guidance (`@ingram-tech/nk-dev/guide.md`) only reaches
|
|
30
|
-
* an AI agent if
|
|
50
|
+
* an AI agent if a CLAUDE.md it loads `@import`s it. A site can depend on nk-dev
|
|
31
51
|
* yet forget the import line — then the guidance silently never loads. When the
|
|
32
|
-
* package is a dependency, assert CLAUDE.md
|
|
52
|
+
* package is a dependency, assert that a CLAUDE.md from here to the repository
|
|
53
|
+
* root imports it.
|
|
33
54
|
*
|
|
34
55
|
* Returns `{ ok, reason }`. `ok` is true when there's nothing to enforce (the
|
|
35
56
|
* package isn't a dependency) or the import is present; `reason` explains a miss.
|
|
@@ -38,18 +59,36 @@ export function checkAgentGuideImport(cwd = process.cwd()) {
|
|
|
38
59
|
const deps = readDeps(cwd);
|
|
39
60
|
if (!deps || !deps["@ingram-tech/nk-dev"]) return { ok: true };
|
|
40
61
|
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
62
|
+
const { files, importer } = findGuideImport(cwd);
|
|
63
|
+
if (importer) return { ok: true };
|
|
64
|
+
if (files.length === 0) {
|
|
43
65
|
return {
|
|
44
66
|
ok: false,
|
|
45
67
|
reason: "depends on @ingram-tech/nk-dev but has no CLAUDE.md importing its guide",
|
|
46
68
|
};
|
|
47
69
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
reason: "CLAUDE.md does not @import @ingram-tech/nk-dev/guide.md, and no CLAUDE.md above it up to the repository root does (shared agent guidance won't load)",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Make the guide reach the agent working in `dir`: when no CLAUDE.md from `dir`
|
|
78
|
+
* to the repository root imports it, add the import to `dir/CLAUDE.md`,
|
|
79
|
+
* creating the file if needed. Idempotent. Returns a short past-tense note.
|
|
80
|
+
*/
|
|
81
|
+
export function ensureGuideImport(dir) {
|
|
82
|
+
const { importer } = findGuideImport(dir);
|
|
83
|
+
if (importer) {
|
|
84
|
+
return `${relative(dir, importer) || "CLAUDE.md"} already imports the agent guide`;
|
|
85
|
+
}
|
|
86
|
+
const file = resolve(dir, "CLAUDE.md");
|
|
87
|
+
if (!existsSync(file)) {
|
|
88
|
+
writeFileSync(file, `# Project\n\n${GUIDE_IMPORT}\n`);
|
|
89
|
+
return "wrote CLAUDE.md with the agent-guide import";
|
|
53
90
|
}
|
|
54
|
-
|
|
91
|
+
const body = readFileSync(file, "utf8");
|
|
92
|
+
writeFileSync(file, `${body.replace(/\n*$/, "")}\n\n${GUIDE_IMPORT}\n`);
|
|
93
|
+
return "added the agent-guide import to CLAUDE.md";
|
|
55
94
|
}
|
package/lib/app-dir.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
// A Next site keeps its routes in `src/app/`, never a root `app/`. Next accepts
|
|
5
|
+
// both and silently prefers the root one when both exist, so a stray `app/`
|
|
6
|
+
// shadows the whole `src/app/` tree. nk's checks and lint rules (the endpoint
|
|
7
|
+
// shadow check, the OG image check, `no-redirect-only-page`, ...) only look in
|
|
8
|
+
// `src/app/`, so a root-`app/` site would also pass them without being checked.
|
|
9
|
+
|
|
10
|
+
const isDirectory = (path) => {
|
|
11
|
+
try {
|
|
12
|
+
return statSync(path).isDirectory();
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const dependsOnNext = (pkg) =>
|
|
19
|
+
Boolean(pkg.dependencies?.next ?? pkg.devDependencies?.next);
|
|
20
|
+
|
|
21
|
+
/** The "routes live in a root app/" finding, or nothing. */
|
|
22
|
+
export function appDirFindings(cwd, pkg) {
|
|
23
|
+
if (!dependsOnNext(pkg) || !isDirectory(resolve(cwd, "app"))) return [];
|
|
24
|
+
const both = isDirectory(resolve(cwd, "src/app"));
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
id: "layout:root-app-dir",
|
|
28
|
+
level: "error",
|
|
29
|
+
message: both
|
|
30
|
+
? "`app/` and `src/app/` both exist — Next serves `app/` and ignores `src/app/` entirely. Merge the routes into `src/app/` and delete `app/`."
|
|
31
|
+
: "routes live in a root `app/` — nextkit sites keep them in `src/app/`, the only place nk's checks and lint rules look. Move `app/` to `src/app/` and update tsconfig `paths` that point into it.",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
}
|
package/lib/auth-next.js
CHANGED
|
@@ -10,7 +10,7 @@ import { join, relative, resolve } from "node:path";
|
|
|
10
10
|
// this check catches it before the site is even run. Textual, like the
|
|
11
11
|
// endpoint-shadow check: we grep the site's sources, never execute them.
|
|
12
12
|
|
|
13
|
-
const SOURCE_DIRS = ["src", "
|
|
13
|
+
const SOURCE_DIRS = ["src", "lib", "proxy.ts", "middleware.ts"];
|
|
14
14
|
const SOURCE_FILES = /\.(ts|tsx|js|jsx|mjs)$/;
|
|
15
15
|
const SKIP_DIRS = new Set(["node_modules", ".next", "dist", "build"]);
|
|
16
16
|
|
package/lib/auth-shadow.js
CHANGED
|
@@ -15,12 +15,11 @@ const ENDPOINT_RE = /createAuthEndpoint\(\s*"([^"]+)"/g;
|
|
|
15
15
|
|
|
16
16
|
/** The `app/auth/[...all]` mount dir, or null when the site has no auth mount. */
|
|
17
17
|
function findMount(cwd) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
18
|
+
const appDir = "src/app";
|
|
19
|
+
const catchAll = resolve(cwd, appDir, "auth", "[...all]");
|
|
20
|
+
for (const ext of ["ts", "js", "tsx", "jsx"]) {
|
|
21
|
+
if (existsSync(join(catchAll, `route.${ext}`))) {
|
|
22
|
+
return { appDir, authDir: resolve(cwd, appDir, "auth") };
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
return null;
|
package/lib/doctor.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
+
import { checkAgentGuideImport, ensureGuideImport } from "./agent-guide.js";
|
|
4
|
+
import { appDirFindings } from "./app-dir.js";
|
|
3
5
|
import { authNextFindings } from "./auth-next.js";
|
|
4
6
|
import { authShadowFindings } from "./auth-shadow.js";
|
|
5
7
|
import { authVersionFindings } from "./auth-version.js";
|
|
@@ -25,7 +27,6 @@ const CANONICAL_SCRIPTS = {
|
|
|
25
27
|
"type-check": "nk type-check",
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
const GUIDE_IMPORT = "@./node_modules/@ingram-tech/nk-dev/guide.md";
|
|
29
30
|
const OXLINTRC_FILE = "node_modules/@ingram-tech/nk-dev/oxlintrc.json";
|
|
30
31
|
/** Matches any `extends` entry that reaches nk-dev's oxlintrc, whatever the prefix. */
|
|
31
32
|
const OXLINTRC_EXTENDS_RE = /(^|\/)node_modules\/@ingram-tech\/nk-dev\/oxlintrc\.json$/;
|
|
@@ -180,31 +181,15 @@ export function findings(cwd) {
|
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
183
|
|
|
183
|
-
// 5. CLAUDE.md imports the shared guide.
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
claude === null
|
|
193
|
-
? "no CLAUDE.md importing the nk-dev guide"
|
|
194
|
-
: "CLAUDE.md does not @import the nk-dev guide",
|
|
195
|
-
fix: (dir) => {
|
|
196
|
-
const p = resolve(dir, "CLAUDE.md");
|
|
197
|
-
const body = existsSync(p)
|
|
198
|
-
? readFileSync(p, "utf8")
|
|
199
|
-
: "# Project\n";
|
|
200
|
-
writeFileSync(
|
|
201
|
-
p,
|
|
202
|
-
`${body.replace(/\n*$/, "")}\n\n${GUIDE_IMPORT}\n`,
|
|
203
|
-
);
|
|
204
|
-
return "added the guide import to CLAUDE.md";
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
}
|
|
184
|
+
// 5. A CLAUDE.md from here to the repository root imports the shared guide.
|
|
185
|
+
const guide = checkAgentGuideImport(cwd);
|
|
186
|
+
if (!guide.ok) {
|
|
187
|
+
out.push({
|
|
188
|
+
id: "claude:guide-import",
|
|
189
|
+
level: "error",
|
|
190
|
+
message: guide.reason,
|
|
191
|
+
fix: ensureGuideImport,
|
|
192
|
+
});
|
|
208
193
|
}
|
|
209
194
|
|
|
210
195
|
// 6. knip.json ignoreDependencies referencing superseded packages (stale).
|
|
@@ -241,33 +226,41 @@ export function findings(cwd) {
|
|
|
241
226
|
// (even on a clean no-op) and hides journal drift.
|
|
242
227
|
// `nk-pg-migrate` (@ingram-tech/nk-db) is the one runner that applies:
|
|
243
228
|
// it surfaces the real Postgres error and pre-flights drift.
|
|
229
|
+
// The autofix rewrites the whole script, so it is only offered when
|
|
230
|
+
// drizzle-kit is the whole script: in a compound one (`build && drizzle-kit
|
|
231
|
+
// push`) the other steps are the site's, and only a human can split them.
|
|
244
232
|
for (const [name, cmd] of Object.entries(scripts)) {
|
|
245
233
|
if (typeof cmd !== "string") continue;
|
|
234
|
+
const compound = /[;&|]/.test(cmd);
|
|
246
235
|
if (/\bdrizzle-kit\s+push\b/.test(cmd)) {
|
|
247
236
|
out.push({
|
|
248
237
|
id: `script:drizzle-push:${name}`,
|
|
249
238
|
level: "error",
|
|
250
239
|
message: `\`${name}\` runs \`drizzle-kit push\` — it applies schema to the live DB with no migration (drift). Generate a migration and apply it with \`nk-pg-migrate\`.`,
|
|
251
|
-
fix:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
fix: compound
|
|
241
|
+
? undefined
|
|
242
|
+
: (dir) => {
|
|
243
|
+
const p = resolve(dir, "package.json");
|
|
244
|
+
const j = readJson(p);
|
|
245
|
+
delete j.scripts?.[name];
|
|
246
|
+
writeJson(p, j);
|
|
247
|
+
return `removed \`${name}\` (drizzle-kit push)`;
|
|
248
|
+
},
|
|
258
249
|
});
|
|
259
250
|
} else if (/\bdrizzle-kit\s+migrate\b/.test(cmd)) {
|
|
260
251
|
out.push({
|
|
261
252
|
id: `script:drizzle-migrate:${name}`,
|
|
262
253
|
level: "error",
|
|
263
254
|
message: `\`${name}\` runs \`drizzle-kit migrate\` — apply with \`nk-pg-migrate\` instead (it surfaces the real error and pre-flights journal drift).`,
|
|
264
|
-
fix:
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
255
|
+
fix: compound
|
|
256
|
+
? undefined
|
|
257
|
+
: (dir) => {
|
|
258
|
+
const p = resolve(dir, "package.json");
|
|
259
|
+
const j = readJson(p);
|
|
260
|
+
j.scripts[name] = "nk-pg-migrate";
|
|
261
|
+
writeJson(p, j);
|
|
262
|
+
return `set \`${name}\` → "nk-pg-migrate"`;
|
|
263
|
+
},
|
|
271
264
|
});
|
|
272
265
|
}
|
|
273
266
|
}
|
|
@@ -343,6 +336,9 @@ export function findings(cwd) {
|
|
|
343
336
|
// 14. No page/layout declares an Open Graph card without an image in reach.
|
|
344
337
|
out.push(...ogImageFindings(cwd));
|
|
345
338
|
|
|
339
|
+
// 15. Routes live in src/app/, never a root app/.
|
|
340
|
+
out.push(...appDirFindings(cwd, pkg));
|
|
341
|
+
|
|
346
342
|
return out;
|
|
347
343
|
}
|
|
348
344
|
|
|
@@ -412,6 +408,15 @@ function migrationFindings(cwd) {
|
|
|
412
408
|
return out;
|
|
413
409
|
}
|
|
414
410
|
|
|
411
|
+
/**
|
|
412
|
+
* The exit code for a report-only `nk doctor` run: non-zero only when there are
|
|
413
|
+
* model-breaking (error-level) findings, so `nk doctor` can gate CI while
|
|
414
|
+
* cosmetic warnings don't.
|
|
415
|
+
*/
|
|
416
|
+
export function exitCodeFor(results) {
|
|
417
|
+
return results.some((r) => r.level === "error") ? 1 : 0;
|
|
418
|
+
}
|
|
419
|
+
|
|
415
420
|
/**
|
|
416
421
|
* `nk doctor [--fix]` — report drift from the canonical nk-dev model (scripts,
|
|
417
422
|
* dependencies, oxlint/tsconfig extends, the CLAUDE.md guide import, stale knip
|
|
@@ -434,7 +439,6 @@ export function doctor(args = []) {
|
|
|
434
439
|
}
|
|
435
440
|
|
|
436
441
|
if (!fix) {
|
|
437
|
-
const errors = results.filter((r) => r.level === "error").length;
|
|
438
442
|
console.log(`nk doctor: ${results.length} finding(s):\n`);
|
|
439
443
|
for (const r of results) {
|
|
440
444
|
const mark = r.level === "error" ? "✗" : "•";
|
|
@@ -443,9 +447,7 @@ export function doctor(args = []) {
|
|
|
443
447
|
console.log(
|
|
444
448
|
`\n Run \`nk doctor --fix\` to apply the ${results.filter((r) => r.fix).length} auto-fixable one(s).`,
|
|
445
449
|
);
|
|
446
|
-
|
|
447
|
-
// doctor` can gate CI while cosmetic warnings don't.
|
|
448
|
-
process.exit(errors > 0 ? 1 : 0);
|
|
450
|
+
process.exit(exitCodeFor(results));
|
|
449
451
|
}
|
|
450
452
|
|
|
451
453
|
let applied = 0;
|
package/lib/init.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { ensureGuideImport } from "./agent-guide.js";
|
|
5
6
|
|
|
6
7
|
// Files live at the package root, two levels up from lib/.
|
|
7
8
|
const PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
@@ -99,8 +100,6 @@ set -eu
|
|
|
99
100
|
exec bun x --bun nextkit-format-staged
|
|
100
101
|
`;
|
|
101
102
|
|
|
102
|
-
const GUIDE_IMPORT = "@./node_modules/@ingram-tech/nk-dev/guide.md";
|
|
103
|
-
|
|
104
103
|
export function init() {
|
|
105
104
|
const cwd = process.cwd();
|
|
106
105
|
|
|
@@ -135,8 +134,8 @@ export function init() {
|
|
|
135
134
|
// 7. Format-on-commit hook + git wiring.
|
|
136
135
|
setupGitHook(cwd);
|
|
137
136
|
|
|
138
|
-
// 8. Make sure the agent guide is imported into CLAUDE.md.
|
|
139
|
-
ensureGuideImport(cwd);
|
|
137
|
+
// 8. Make sure the agent guide is imported into a CLAUDE.md the agent loads.
|
|
138
|
+
log(ensureGuideImport(cwd));
|
|
140
139
|
|
|
141
140
|
// 9. A `prepare` script so the hook re-wires itself on every `bun install`.
|
|
142
141
|
ensurePrepareScript(cwd);
|
|
@@ -163,22 +162,6 @@ function setupGitHook(cwd) {
|
|
|
163
162
|
});
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
function ensureGuideImport(cwd) {
|
|
167
|
-
const claudePath = resolve(cwd, "CLAUDE.md");
|
|
168
|
-
if (!existsSync(claudePath)) {
|
|
169
|
-
writeFileSync(claudePath, `# Project\n\n${GUIDE_IMPORT}\n`);
|
|
170
|
-
log("wrote CLAUDE.md with the agent-guide import");
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const body = readFileSync(claudePath, "utf8");
|
|
174
|
-
if (body.includes("nk-dev/guide.md")) {
|
|
175
|
-
log("CLAUDE.md already imports the agent guide.");
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
writeFileSync(claudePath, `${body.replace(/\n*$/, "")}\n\n${GUIDE_IMPORT}\n`);
|
|
179
|
-
log("added the agent-guide import to CLAUDE.md");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
165
|
function hintVitestConfig(cwd) {
|
|
183
166
|
if (existsSync(resolve(cwd, "vitest.config.ts"))) {
|
|
184
167
|
skip("vitest.config.ts");
|
package/lib/og-image.js
CHANGED
|
@@ -18,11 +18,8 @@ const CARRIES_IMAGE = /\bimages\s*[:,}]|\bogImageMetadata\s*\(/;
|
|
|
18
18
|
|
|
19
19
|
/** The site's app directory, or null when it has none. */
|
|
20
20
|
function findAppDir(cwd) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (existsSync(dir)) return dir;
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
21
|
+
const dir = resolve(cwd, "src/app");
|
|
22
|
+
return existsSync(dir) ? dir : null;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
/**
|
|
@@ -29,13 +29,18 @@
|
|
|
29
29
|
// value, or a spread that might carry one, still reports: a spread is not
|
|
30
30
|
// an explicit `nativeButton={false}`.
|
|
31
31
|
//
|
|
32
|
-
// Which components count: only the ones
|
|
33
|
-
// In @base-ui/react 1.8.0
|
|
34
|
-
// items
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
32
|
+
// Which components count: only the ones whose `nativeButton` defaults to true.
|
|
33
|
+
// In @base-ui/react 1.8.0 Button and Popover.Trigger extend `NativeButtonProps`
|
|
34
|
+
// (default true). Menu items and Switch take the prop too, but extend
|
|
35
|
+
// `NonNativeButtonProps`: it defaults to false there, they render a <div> or
|
|
36
|
+
// <span> by default, and `render={<Link />}` on a menu item is already correct.
|
|
37
|
+
// Demanding `nativeButton={false}` on those would flag correct code. Other
|
|
38
|
+
// default-true parts (Menu.Trigger, Dialog.Trigger, Tabs.Tab, ...) are not
|
|
39
|
+
// listed yet; the list is exact names, never `Button`/`Trigger` suffixes, which
|
|
40
|
+
// would report design-system Buttons that render a native <button>.
|
|
41
|
+
//
|
|
42
|
+
// Hosts match by their shadcn wrapper name (`PopoverTrigger`) or by Base UI's
|
|
43
|
+
// namespace form (`Popover.Trigger`), which joins to the same name.
|
|
39
44
|
//
|
|
40
45
|
// The host must also be Base UI's own component. A locally defined
|
|
41
46
|
// `SidebarMenuButton` shares the name and takes no such prop, so the name list
|
|
@@ -43,21 +48,17 @@
|
|
|
43
48
|
|
|
44
49
|
import { fileUsesBaseUi } from "./base-ui-project.js";
|
|
45
50
|
|
|
46
|
-
const NATIVE_BUTTON_PROP_COMPONENTS = new Set([
|
|
47
|
-
"Button",
|
|
48
|
-
"PopoverTrigger",
|
|
49
|
-
"Switch",
|
|
50
|
-
"MenuItem",
|
|
51
|
-
]);
|
|
51
|
+
const NATIVE_BUTTON_PROP_COMPONENTS = new Set(["Button", "PopoverTrigger"]);
|
|
52
52
|
|
|
53
|
-
/** `<Foo>` -> "Foo", `<
|
|
53
|
+
/** `<Foo>` -> "Foo", `<Popover.Trigger>` -> "Popover.Trigger", otherwise null. */
|
|
54
54
|
const componentNameOf = (opening) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const jsxName = (name) => {
|
|
56
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
57
|
+
if (name.type !== "JSXMemberExpression") return null;
|
|
58
|
+
const object = jsxName(name.object);
|
|
59
|
+
return object === null ? null : `${object}.${name.property.name}`;
|
|
60
|
+
};
|
|
61
|
+
return jsxName(opening.name);
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
/**
|
|
@@ -71,10 +72,14 @@ const componentNameOf = (opening) => {
|
|
|
71
72
|
* Those set `nativeButton={false}` on their own inner button, so the mistake
|
|
72
73
|
* is contained in the wrapper rather than at every call site.
|
|
73
74
|
*/
|
|
74
|
-
const rendersNativeButton = (name) =>
|
|
75
|
-
|
|
75
|
+
const rendersNativeButton = (name) => {
|
|
76
|
+
const last = name.slice(name.lastIndexOf(".") + 1);
|
|
77
|
+
return last === "button" || (/^[A-Z]/.test(last) && last.endsWith("Button"));
|
|
78
|
+
};
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
/** `Popover.Trigger` and `PopoverTrigger` are the same host. */
|
|
81
|
+
const isButtonLike = (name) =>
|
|
82
|
+
name !== null && NATIVE_BUTTON_PROP_COMPONENTS.has(name.replaceAll(".", ""));
|
|
78
83
|
|
|
79
84
|
/** The JSX element literal passed to `render`, or null. */
|
|
80
85
|
const renderedElement = (attribute) => {
|
|
@@ -34,18 +34,26 @@
|
|
|
34
34
|
|
|
35
35
|
const NODE_CRYPTO_MODULES = new Set(["crypto", "node:crypto"]);
|
|
36
36
|
|
|
37
|
-
/** `crypto
|
|
38
|
-
const
|
|
37
|
+
/** Whether a binding is `import crypto from "node:crypto"` / `import * as c`. */
|
|
38
|
+
const isNodeCryptoModuleBinding = (def) =>
|
|
39
|
+
def.type === "ImportBinding" &&
|
|
40
|
+
(def.node.type === "ImportDefaultSpecifier" ||
|
|
41
|
+
def.node.type === "ImportNamespaceSpecifier") &&
|
|
42
|
+
NODE_CRYPTO_MODULES.has(def.parent?.source?.value);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `crypto.randomUUID` on the global (`crypto`, `globalThis.crypto`) or on the
|
|
46
|
+
* node:crypto module imported whole (`import crypto from "node:crypto"`,
|
|
47
|
+
* `import * as c from "crypto"`): every spelling that mints a v4.
|
|
48
|
+
*/
|
|
49
|
+
const isCryptoRandomUuid = (callee, scope) => {
|
|
39
50
|
if (callee.type !== "MemberExpression") return false;
|
|
40
51
|
if (callee.computed) return false;
|
|
41
52
|
if (callee.property.type !== "Identifier") return false;
|
|
42
53
|
if (callee.property.name !== "randomUUID") return false;
|
|
43
54
|
|
|
44
55
|
const object = callee.object;
|
|
45
|
-
|
|
46
|
-
if (object.type === "Identifier" && object.name === "crypto") {
|
|
47
|
-
root = object;
|
|
48
|
-
} else if (
|
|
56
|
+
if (
|
|
49
57
|
object.type === "MemberExpression" &&
|
|
50
58
|
!object.computed &&
|
|
51
59
|
object.object.type === "Identifier" &&
|
|
@@ -55,17 +63,19 @@ const isGlobalCryptoRandomUuid = (callee, scope) => {
|
|
|
55
63
|
) {
|
|
56
64
|
// `globalThis.crypto` can't be shadowed by a local binding.
|
|
57
65
|
return true;
|
|
58
|
-
} else {
|
|
59
|
-
return false;
|
|
60
66
|
}
|
|
67
|
+
if (object.type !== "Identifier") return false;
|
|
61
68
|
|
|
62
|
-
// A local `crypto` (a mock, an injected dependency) is not the global one.
|
|
63
69
|
for (let current = scope; current; current = current.upper) {
|
|
64
|
-
const variable = current.variables?.find((v) => v.name ===
|
|
70
|
+
const variable = current.variables?.find((v) => v.name === object.name);
|
|
65
71
|
if (!variable) continue;
|
|
66
|
-
|
|
72
|
+
// No defs: the implicit global. Otherwise the module imported whole is
|
|
73
|
+
// the same v4 mint; any other local (a mock, an injected dependency) is
|
|
74
|
+
// not.
|
|
75
|
+
if (variable.defs.length === 0) return object.name === "crypto";
|
|
76
|
+
return variable.defs.some(isNodeCryptoModuleBinding);
|
|
67
77
|
}
|
|
68
|
-
return
|
|
78
|
+
return object.name === "crypto";
|
|
69
79
|
};
|
|
70
80
|
|
|
71
81
|
const noCryptoRandomUuid = {
|
|
@@ -101,7 +111,7 @@ const noCryptoRandomUuid = {
|
|
|
101
111
|
callee.type === "Identifier" && importedNames.has(callee.name);
|
|
102
112
|
if (
|
|
103
113
|
!isImported &&
|
|
104
|
-
!
|
|
114
|
+
!isCryptoRandomUuid(callee, sourceCode.getScope(node))
|
|
105
115
|
) {
|
|
106
116
|
return;
|
|
107
117
|
}
|
|
@@ -19,6 +19,18 @@
|
|
|
19
19
|
|
|
20
20
|
const CLIENT_SAFE = /^NEXT_PUBLIC_/;
|
|
21
21
|
|
|
22
|
+
/** The key a destructuring property reads, or null when it is computed. */
|
|
23
|
+
const propertyKeyName = (property) => {
|
|
24
|
+
if (property.type !== "Property" || property.computed) return null;
|
|
25
|
+
if (property.key.type === "Identifier") return property.key.name;
|
|
26
|
+
if (property.key.type === "Literal" && typeof property.key.value === "string") {
|
|
27
|
+
return property.key.value;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const isClientSafe = (name) => name === "NODE_ENV" || CLIENT_SAFE.test(name);
|
|
33
|
+
|
|
22
34
|
/** Whether the file opens with the "use client" directive. */
|
|
23
35
|
const isClientFile = (program) => {
|
|
24
36
|
for (const statement of program.body) {
|
|
@@ -30,16 +42,18 @@ const isClientFile = (program) => {
|
|
|
30
42
|
return false;
|
|
31
43
|
};
|
|
32
44
|
|
|
45
|
+
/** Whether `node` is `process.env` itself. */
|
|
46
|
+
const isProcessEnv = (node) =>
|
|
47
|
+
node.type === "MemberExpression" &&
|
|
48
|
+
!node.computed &&
|
|
49
|
+
node.object.type === "Identifier" &&
|
|
50
|
+
node.object.name === "process" &&
|
|
51
|
+
node.property.type === "Identifier" &&
|
|
52
|
+
node.property.name === "env";
|
|
53
|
+
|
|
33
54
|
/** The variable name in `process.env.FOO` / `process.env["FOO"]`, or null. */
|
|
34
55
|
const envVarName = (node) => {
|
|
35
|
-
|
|
36
|
-
if (object.type !== "MemberExpression" || object.computed) return null;
|
|
37
|
-
if (object.object.type !== "Identifier" || object.object.name !== "process") {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
if (object.property.type !== "Identifier" || object.property.name !== "env") {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
56
|
+
if (!isProcessEnv(node.object)) return null;
|
|
43
57
|
if (!node.computed && node.property.type === "Identifier") {
|
|
44
58
|
return node.property.name;
|
|
45
59
|
}
|
|
@@ -63,6 +77,8 @@ const noServerEnvInClient = {
|
|
|
63
77
|
},
|
|
64
78
|
create(context) {
|
|
65
79
|
let client = false;
|
|
80
|
+
const report = (node, name) =>
|
|
81
|
+
context.report({ node, messageId: "serverEnvInClient", data: { name } });
|
|
66
82
|
return {
|
|
67
83
|
Program(node) {
|
|
68
84
|
client = isClientFile(node);
|
|
@@ -71,12 +87,18 @@ const noServerEnvInClient = {
|
|
|
71
87
|
if (!client) return;
|
|
72
88
|
const name = envVarName(node);
|
|
73
89
|
if (name === null) return;
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
if (isClientSafe(name)) return;
|
|
91
|
+
report(node, name);
|
|
92
|
+
},
|
|
93
|
+
// `const { STRIPE_SECRET_KEY } = process.env` reads the same var.
|
|
94
|
+
VariableDeclarator(node) {
|
|
95
|
+
if (!client || node.id.type !== "ObjectPattern") return;
|
|
96
|
+
if (!node.init || !isProcessEnv(node.init)) return;
|
|
97
|
+
for (const property of node.id.properties) {
|
|
98
|
+
const name = propertyKeyName(property);
|
|
99
|
+
if (name === null || isClientSafe(name)) continue;
|
|
100
|
+
report(property.key, name);
|
|
101
|
+
}
|
|
80
102
|
},
|
|
81
103
|
};
|
|
82
104
|
},
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
// Casting a *column* to an array type is legitimate and indistinguishable
|
|
15
15
|
// syntactically, so that case takes a justified disable comment.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Postgres allows whitespace around `::`, so `${ids} :: uuid[]` is the same cast.
|
|
18
|
+
const ARRAY_CAST = /^\s*::\s*("?[A-Za-z_][\w."]*"?\s*\[\s*\])/;
|
|
18
19
|
|
|
19
20
|
const noSqlArrayCast = {
|
|
20
21
|
meta: {
|
|
@@ -41,7 +42,7 @@ const noSqlArrayCast = {
|
|
|
41
42
|
context.report({
|
|
42
43
|
node: node.quasi.expressions[i - 1] ?? node,
|
|
43
44
|
messageId: "sqlArrayCast",
|
|
44
|
-
data: { type: match[
|
|
45
|
+
data: { type: match[1] },
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
},
|
package/lib/passthrough.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkAgentGuideImport } from "./agent-guide.js";
|
|
1
|
+
import { GUIDE_IMPORT, checkAgentGuideImport } from "./agent-guide.js";
|
|
2
2
|
import {
|
|
3
3
|
cleanGeneratedArtifacts,
|
|
4
4
|
onlyGeneratedTypeErrors,
|
|
@@ -9,6 +9,7 @@ import { FORMATTER } from "./formatter.js";
|
|
|
9
9
|
import { hasKnipConfig, runKnip } from "./knip.js";
|
|
10
10
|
import { checkSeal } from "./migrations.js";
|
|
11
11
|
import { run, runCapture, writeThrough } from "./run.js";
|
|
12
|
+
import { lintEnvironment } from "./tsgolint.js";
|
|
12
13
|
import {
|
|
13
14
|
tailwindCoverageFindings,
|
|
14
15
|
tailwindSourceFindings,
|
|
@@ -17,7 +18,11 @@ import { readdirSync, rmSync } from "node:fs";
|
|
|
17
18
|
|
|
18
19
|
/** `nk lint [...]` — oxlint, with extra args passed through (e.g. `--fix`). */
|
|
19
20
|
export function lint(extraArgs = []) {
|
|
20
|
-
process.exit(
|
|
21
|
+
process.exit(
|
|
22
|
+
run(FORMATTER.lint[0], [...FORMATTER.lint[1], ...extraArgs], {
|
|
23
|
+
env: lintEnvironment(),
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
/**
|
|
@@ -31,7 +36,8 @@ export function lint(extraArgs = []) {
|
|
|
31
36
|
export function check() {
|
|
32
37
|
// Run every gate before deciding (no short-circuit), so one failure doesn't
|
|
33
38
|
// hide another. oxc splits lint (oxlint) and format (oxfmt), so we run both.
|
|
34
|
-
const lintFailed =
|
|
39
|
+
const lintFailed =
|
|
40
|
+
run(FORMATTER.lint[0], FORMATTER.lint[1], { env: lintEnvironment() }) !== 0;
|
|
35
41
|
const fmtFailed = run(FORMATTER.checkFormat[0], FORMATTER.checkFormat[1]) !== 0;
|
|
36
42
|
// knip (unused deps/exports/files). Opt-in: only when the repo has a knip
|
|
37
43
|
// config — knip has no shareable config, so absence means "not adopted".
|
|
@@ -42,7 +48,7 @@ export function check() {
|
|
|
42
48
|
if (!guide.ok) {
|
|
43
49
|
console.error(`nk check: ${guide.reason}`);
|
|
44
50
|
console.error(
|
|
45
|
-
|
|
51
|
+
` → add \`${GUIDE_IMPORT}\` to your CLAUDE.md (or run \`nk init\`).`,
|
|
46
52
|
);
|
|
47
53
|
}
|
|
48
54
|
// Applied migrations are immutable. A no-op on sites without a `drizzle/`
|
package/lib/run.js
CHANGED
|
@@ -16,9 +16,16 @@ export function run(tool, args = [], opts = {}) {
|
|
|
16
16
|
}
|
|
17
17
|
throw res.error;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
return exitStatus(res);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The exit code of a finished `spawnSync` child. A signal-killed child (OOM,
|
|
24
|
+
* SIGSEGV) has status null — that's a failure, not a pass; `?? 0` would let a
|
|
25
|
+
* crashed linter through the CI gate.
|
|
26
|
+
*/
|
|
27
|
+
export function exitStatus({ status, signal }) {
|
|
28
|
+
return status ?? (signal ? 1 : 0);
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
/**
|
|
@@ -47,7 +54,7 @@ export function runCapture(tool, args = [], opts = {}) {
|
|
|
47
54
|
throw res.error;
|
|
48
55
|
}
|
|
49
56
|
return {
|
|
50
|
-
status:
|
|
57
|
+
status: exitStatus(res),
|
|
51
58
|
stdout: res.stdout ?? "",
|
|
52
59
|
stderr: res.stderr ?? "",
|
|
53
60
|
output: `${res.stdout ?? ""}${res.stderr ?? ""}`,
|
package/lib/tsgolint.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The native binary behind oxlint's type-aware rules, or null when this
|
|
7
|
+
* platform has none. oxlint looks for it only in `node_modules/.bin` above the
|
|
8
|
+
* linted directory and on PATH, and a dependency of nk-dev reaches neither
|
|
9
|
+
* (bun's isolated installs link only a project's direct dependencies). So nk
|
|
10
|
+
* resolves it from here, through the platform package oxlint-tsgolint's own
|
|
11
|
+
* wrapper would spawn — the binary, not the wrapper, which needs `node`.
|
|
12
|
+
*/
|
|
13
|
+
export function tsgolintPath() {
|
|
14
|
+
const binary = process.platform === "win32" ? "tsgolint.exe" : "tsgolint";
|
|
15
|
+
try {
|
|
16
|
+
const wrapper = createRequire(require.resolve("oxlint-tsgolint/package.json"));
|
|
17
|
+
return wrapper.resolve(
|
|
18
|
+
`@oxlint-tsgolint/${process.platform}-${process.arch}/${binary}`,
|
|
19
|
+
);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error.code === "MODULE_NOT_FOUND") return null;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The environment for an oxlint run: `env` with `OXLINT_TSGOLINT_PATH` set to
|
|
28
|
+
* the resolved backend. A path the caller set wins. oxlint reads the variable
|
|
29
|
+
* only when the project's config turns on type-aware linting.
|
|
30
|
+
*/
|
|
31
|
+
export function lintEnvironment(env = process.env) {
|
|
32
|
+
if (env.OXLINT_TSGOLINT_PATH) return env;
|
|
33
|
+
const path = tsgolintPath();
|
|
34
|
+
return path === null ? env : { ...env, OXLINT_TSGOLINT_PATH: path };
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "The nextkit dev toolchain in one package: the `nk` CLI plus shared oxlint/oxfmt, TypeScript, and Vitest config, the format-on-commit hook, and the AI agent guide. `nk init` scaffolds a site to use it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -45,16 +45,17 @@
|
|
|
45
45
|
"test": "vitest run"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ast-grep/cli": "^0.
|
|
49
|
-
"@testing-library/dom": "^10.4.
|
|
48
|
+
"@ast-grep/cli": "^0.50.0",
|
|
49
|
+
"@testing-library/dom": "^10.4.2",
|
|
50
50
|
"@testing-library/jest-dom": "^7.0.1",
|
|
51
51
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
52
|
-
"jsdom": "^30.
|
|
53
|
-
"knip": "^6.
|
|
54
|
-
"oxfmt": "^0.
|
|
55
|
-
"oxlint": "^1.
|
|
52
|
+
"jsdom": "^30.1.2",
|
|
53
|
+
"knip": "^6.41.0",
|
|
54
|
+
"oxfmt": "^0.72.0",
|
|
55
|
+
"oxlint": "^1.87.0",
|
|
56
|
+
"oxlint-tsgolint": "^7.0.2004",
|
|
56
57
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
57
|
-
"vitest": "^5.0.
|
|
58
|
+
"vitest": "^5.0.3"
|
|
58
59
|
},
|
|
59
60
|
"engines": {
|
|
60
61
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
package/skills/ts-codemod.md
CHANGED
|
@@ -68,7 +68,7 @@ one-off edit in one file, just edit the file.
|
|
|
68
68
|
- **`$$$ARGS`** — matches **zero or more** nodes (argument lists, statements,
|
|
69
69
|
JSX children). This is what makes rewrites arity-agnostic.
|
|
70
70
|
- **`-l ts` / `-l tsx`** — the language. Use `tsx` for anything with JSX (most of
|
|
71
|
-
a Next.js `app/`), `ts` for plain `.ts`. Getting this wrong makes patterns
|
|
71
|
+
a Next.js `src/app/`), `ts` for plain `.ts`. Getting this wrong makes patterns
|
|
72
72
|
silently fail to parse.
|
|
73
73
|
- **`-p` pattern**, **`-r` rewrite**, **`-U`** apply, **`-i`** interactive
|
|
74
74
|
(approve each edit). Scope by passing paths: `nk ast-grep run ... src/app`.
|