@ingram-tech/nk-dev 0.12.1 → 0.13.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/bin/nk.js CHANGED
@@ -34,8 +34,11 @@ Commands:
34
34
  mechanical refactors — see the codemod skill.
35
35
  check The CI gate: lint + format verify + knip (when configured)
36
36
  + the agent-guide import gate + the migration seal.
37
- type-check next typegen && tsc --noEmit. Recovers automatically when
37
+ type-check [--cold] next typegen && tsc --noEmit. Recovers automatically when
38
38
  generated types are damaged (e.g. a killed dev server).
39
+ Drops the incremental cache when the lockfile changed
40
+ since it was written (a stale cache passes against old
41
+ .d.ts); --cold always drops it.
39
42
  clean Remove regenerable build artifacts: Next's generated
40
43
  types and TypeScript incremental caches.
41
44
  test [...] vitest run (extra args passed through).
@@ -75,7 +78,7 @@ switch (cmd) {
75
78
  check();
76
79
  break;
77
80
  case "type-check":
78
- typeCheck();
81
+ typeCheck(rest);
79
82
  break;
80
83
  case "clean":
81
84
  clean();
package/guide.md CHANGED
@@ -80,7 +80,10 @@ the UI/page tree, and never expose internal plumbing under `/api/`.
80
80
  installed in PGlite automatically and in prod by one custom migration). So no
81
81
  `ids.x.decode(param)` before a query and no `ids.x.encode(row.id)` after one
82
82
  — `nextkit/no-id-codec-in-app-code` flags both; validate input with
83
- `ids.x.is(param)` instead. At the shell, `bunx id758 decode inv_…`.
83
+ `ids.x.is(param)` instead. Session ids come in the same form from
84
+ `createAuthHelpers(auth, { ids })` (and `backendJwtOptions({ ids })`), and
85
+ `withRls*` decode a public `sub` before it reaches `auth.uid()`. At the
86
+ shell, `bunx id758 decode inv_…`.
84
87
  - **Migrations don't auto-apply on deploy.** Code ships ahead of the prod schema
85
88
  unless someone runs the migration against the target DB — a page that reads a
86
89
  newly-added column 500s in prod until then. Apply migrations with
package/lib/artifacts.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readdirSync, rmSync } from "node:fs";
1
+ import { existsSync, readdirSync, rmSync, statSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
 
4
4
  /**
@@ -45,6 +45,38 @@ export function listGeneratedArtifacts(cwd = process.cwd()) {
45
45
  return [...present, ...buildInfo];
46
46
  }
47
47
 
48
+ /**
49
+ * Files whose change means the dependency tree changed. The lockfile is the
50
+ * precise signal; `package.json` covers a hand edit not yet installed.
51
+ */
52
+ const DEPENDENCY_MANIFESTS = [
53
+ "bun.lock",
54
+ "bun.lockb",
55
+ "package-lock.json",
56
+ "package.json",
57
+ ];
58
+
59
+ /**
60
+ * TypeScript incremental caches older than the dependency manifests.
61
+ *
62
+ * `tsc --incremental` does not reliably notice a dependency's `.d.ts`
63
+ * changing, so after an upgrade a type-check can pass against the cached
64
+ * program while a cold run fails — the exact failure a dependency bump exists
65
+ * to catch. Keying invalidation on the lockfile catches that case without
66
+ * giving up the cache on every other run.
67
+ */
68
+ export function staleBuildInfo(cwd = process.cwd()) {
69
+ const manifests = DEPENDENCY_MANIFESTS.map((name) => join(cwd, name)).filter(
70
+ (file) => existsSync(file),
71
+ );
72
+ if (manifests.length === 0) return [];
73
+ const newest = Math.max(...manifests.map((file) => statSync(file).mtimeMs));
74
+ return listGeneratedArtifacts(cwd)
75
+ .filter((entry) => entry.owner === "tsc")
76
+ .filter((entry) => statSync(join(cwd, entry.path)).mtimeMs < newest)
77
+ .map((entry) => entry.path);
78
+ }
79
+
48
80
  /**
49
81
  * Remove generated artifacts and return the paths actually deleted. Missing
50
82
  * paths are skipped rather than reported, so this is idempotent.
package/lib/doctor.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1
+ import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { authShadowFindings } from "./auth-shadow.js";
4
4
  import { SUPERSEDED_DEPS } from "./drift.js";
@@ -252,30 +252,82 @@ export function findings(cwd) {
252
252
  }
253
253
  }
254
254
 
255
- // 8. .prettierignore is now dead weight (nk no longer formats SQL).
256
- const prettierIgnore = resolve(cwd, ".prettierignore");
257
- if (existsSync(prettierIgnore)) {
255
+ // 8. Prettier leftovers are dead weight (nk no longer runs Prettier):
256
+ // .prettierignore, any .prettierrc*, and a "prettier" key in package.json.
257
+ for (const file of prettierFiles(cwd)) {
258
258
  out.push({
259
- id: "prettierignore",
259
+ id: `prettier:${file}`,
260
+ level: "warn",
261
+ message: `${file} is unused (nk no longer runs Prettier) — remove it`,
262
+ fix: (dir) => {
263
+ rmSync(resolve(dir, file));
264
+ return `removed ${file}`;
265
+ },
266
+ });
267
+ }
268
+ if (pkg.prettier !== undefined) {
269
+ out.push({
270
+ id: "prettier:package.json",
260
271
  level: "warn",
261
272
  message:
262
- ".prettierignore is unused (nk no longer runs Prettier) — remove it",
273
+ 'package.json has a "prettier" key (nk no longer runs Prettier) — remove it',
263
274
  fix: (dir) => {
264
- rmSync(resolve(dir, ".prettierignore"));
265
- return "removed .prettierignore";
275
+ const p = resolve(dir, "package.json");
276
+ const j = readJson(p);
277
+ delete j.prettier;
278
+ writeJson(p, j);
279
+ return 'removed "prettier" from package.json';
266
280
  },
267
281
  });
268
282
  }
269
283
 
270
- // 9. The migration chain is sealed, and its unmodelled DDL is declared.
284
+ // 9. A `ci` script exists and runs the house gate. Its full contents are
285
+ // the site's call (migrations, i18n, email catalogs, build…), so this only
286
+ // warns and never writes — but the dep-upgrade flow and pre-push both
287
+ // assume `bun run ci` is the one command that proves a change.
288
+ const ci = scripts["ci"];
289
+ if (ci === undefined) {
290
+ out.push({
291
+ id: "script:ci",
292
+ level: "warn",
293
+ message:
294
+ 'missing `ci` script — the one command that proves a change (e.g. "nk check && nk type-check && nk test")',
295
+ });
296
+ } else {
297
+ const missing = ["nk check", "nk type-check"].filter(
298
+ (cmd) => !ci.includes(cmd) && !ci.includes(`bun run ${cmd.slice(3)}`),
299
+ );
300
+ if (missing.length > 0) {
301
+ out.push({
302
+ id: "script:ci",
303
+ level: "warn",
304
+ message: `\`ci\` script does not run ${missing.map((c) => `\`${c}\``).join(" or ")} — the gate should run both`,
305
+ });
306
+ }
307
+ }
308
+
309
+ // 10. The migration chain is sealed, and its unmodelled DDL is declared.
271
310
  out.push(...migrationFindings(cwd));
272
311
 
273
- // 10. No page/route under app/auth/ shadows a Better Auth endpoint.
312
+ // 11. No page/route under app/auth/ shadows a Better Auth endpoint.
274
313
  out.push(...authShadowFindings(cwd));
275
314
 
276
315
  return out;
277
316
  }
278
317
 
318
+ /** Prettier config files present in `cwd` (relative names). */
319
+ function prettierFiles(cwd) {
320
+ let names;
321
+ try {
322
+ names = readdirSync(cwd);
323
+ } catch {
324
+ return [];
325
+ }
326
+ return names.filter(
327
+ (name) => name === ".prettierignore" || name.startsWith(".prettierrc"),
328
+ );
329
+ }
330
+
279
331
  /**
280
332
  * Findings over a `drizzle/` chain. Silent on repos without one.
281
333
  *
@@ -332,8 +384,8 @@ function migrationFindings(cwd) {
332
384
  /**
333
385
  * `nk doctor [--fix]` — report drift from the canonical nk-dev model (scripts,
334
386
  * dependencies, oxlint/tsconfig extends, the CLAUDE.md guide import, stale knip
335
- * ignores, forbidden schema-applying drizzle-kit scripts, a dead
336
- * .prettierignore, an unsealed or unmodelled-DDL-carrying migration chain, a
387
+ * ignores, forbidden schema-applying drizzle-kit scripts, Prettier leftovers,
388
+ * a missing or thin `ci` script, an unsealed or unmodelled-DDL-carrying migration chain, a
337
389
  * page under app/auth/ shadowing a Better Auth endpoint).
338
390
  * With `--fix`, apply every auto-fixable finding, then remind
339
391
  * to reinstall.
@@ -1,10 +1,15 @@
1
1
  import { checkAgentGuideImport } from "./agent-guide.js";
2
- import { cleanGeneratedArtifacts, onlyGeneratedTypeErrors } from "./artifacts.js";
2
+ import {
3
+ cleanGeneratedArtifacts,
4
+ onlyGeneratedTypeErrors,
5
+ staleBuildInfo,
6
+ } from "./artifacts.js";
3
7
  import { toolDrift } from "./drift.js";
4
8
  import { FORMATTER } from "./formatter.js";
5
9
  import { hasKnipConfig, runKnip } from "./knip.js";
6
10
  import { checkSeal } from "./migrations.js";
7
11
  import { run, runCapture, writeThrough } from "./run.js";
12
+ import { readdirSync, rmSync } from "node:fs";
8
13
 
9
14
  /** `nk lint [...]` — oxlint, with extra args passed through (e.g. `--fix`). */
10
15
  export function lint(extraArgs = []) {
@@ -75,8 +80,27 @@ function warnToolDrift() {
75
80
  * output suppresses semantic diagnostics for the whole program, so real `src/`
76
81
  * errors are hidden behind it. Recovering surfaces them and still exits
77
82
  * non-zero — it never turns a failing check into a passing one.
83
+ *
84
+ * Starts cold when the dependency tree moved. `tsc --incremental` does not
85
+ * reliably re-check a program when a dependency's `.d.ts` changes, so a
86
+ * `.tsbuildinfo` older than the lockfile is a green light that means nothing;
87
+ * it is dropped (with a note) before the run. `--cold` drops it
88
+ * unconditionally.
78
89
  */
79
- export function typeCheck() {
90
+ export function typeCheck(extraArgs = []) {
91
+ const cold = extraArgs.includes("--cold");
92
+ const stale = cold
93
+ ? cleanBuildInfoOnly()
94
+ : staleBuildInfo().map((file) => {
95
+ rmSync(file, { force: true });
96
+ return file;
97
+ });
98
+ if (stale.length > 0) {
99
+ console.error(
100
+ `nk type-check: ${cold ? "--cold" : "dependencies changed since the last run"} — removed ${stale.join(", ")}; checking from scratch.`,
101
+ );
102
+ }
103
+
80
104
  const typegen = run("next", ["typegen"]);
81
105
  if (typegen !== 0) process.exit(typegen);
82
106
 
@@ -99,6 +123,17 @@ export function typeCheck() {
99
123
  process.exit(run("tsc", ["--noEmit"]));
100
124
  }
101
125
 
126
+ /** Delete every `*.tsbuildinfo` in cwd and return the names removed. */
127
+ function cleanBuildInfoOnly() {
128
+ const removed = [];
129
+ for (const name of readdirSync(process.cwd())) {
130
+ if (!name.endsWith(".tsbuildinfo")) continue;
131
+ rmSync(name, { force: true });
132
+ removed.push(name);
133
+ }
134
+ return removed;
135
+ }
136
+
102
137
  /**
103
138
  * `nk clean` — remove build artifacts that tools regenerate from source
104
139
  * (Next's generated types, TypeScript incremental caches). Safe by
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingram-tech/nk-dev",
3
- "version": "0.12.1",
3
+ "version": "0.13.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",