@ingram-tech/nk-dev 0.6.0 → 0.7.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
@@ -20,7 +20,7 @@ Commands:
20
20
  dev Start the Next dev server (Turbopack). Boots local PGlite
21
21
  first when @ingram-tech/nk-db is installed (no Docker).
22
22
  format [--check] Format code with oxfmt. --check verifies without writing.
23
- lint Lint with oxlint.
23
+ lint [...] Lint with oxlint (extra args passed through, e.g. --fix).
24
24
  knip Find unused dependencies / exports / files with knip.
25
25
  ast-grep [...] Structural search & rewrite of TS/TSX by AST pattern
26
26
  (vendored ast-grep; args passed through). For large
@@ -50,7 +50,7 @@ switch (cmd) {
50
50
  format({ check: rest.includes("--check") });
51
51
  break;
52
52
  case "lint":
53
- lint();
53
+ lint(rest);
54
54
  break;
55
55
  case "knip":
56
56
  knip(rest);
package/guide.md CHANGED
@@ -77,6 +77,18 @@ the UI/page tree, and never expose internal plumbing under `/api/`.
77
77
  `@ingram-tech/nk-db`'s drift-aware runner (`@ingram-tech/nk-db/migrate`), which
78
78
  surfaces the real Postgres error and pre-flights journal drift. Generate **and
79
79
  apply** in the same step; don't leave "run the migration" as a handoff.
80
+ - **`drizzle-kit` is GENERATE-ONLY — it must never apply schema.** Use it for
81
+ `drizzle-kit generate` (and `generate --custom` for a package-owned/raw SQL
82
+ migration). Applying is always **`nk-pg-migrate`** (the bin from
83
+ `@ingram-tech/nk-db`): `bun run db:migrate`, and check first with
84
+ `db:migrate:status`. Two commands are banned, and `nk doctor` fails on either:
85
+ - **`drizzle-kit push`** applies a diff straight to the live DB with no
86
+ migration file and no journal entry. It is the schema-drift source — it has
87
+ already drifted a production database in this fleet, and where the dev DB is
88
+ shared it rewrites everyone's. To iterate locally, rebuild from migrations
89
+ (the PGlite harness / your `dev:*fresh` script), don't push.
90
+ - **`drizzle-kit migrate`** is opaque: it exits non-zero with no message (even
91
+ on a clean no-op) and hides journal drift.
80
92
 
81
93
  ## Large-scale / structural edits
82
94
 
package/lib/dev.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { createRequire } from "node:module";
3
- import { resolve } from "node:path";
3
+ import { dirname, resolve } from "node:path";
4
4
 
5
5
  /**
6
6
  * Whether `@ingram-tech/nk-db` is resolvable from the site — the signal that
@@ -19,6 +19,32 @@ function hasPgliteDev() {
19
19
  }
20
20
  }
21
21
 
22
+ /**
23
+ * If `@ingram-tech/nk-auth` is installed, the `nk-pglite-dev` flag that makes
24
+ * the local database apply its shipped auth-table migration chain (see
25
+ * docs/db-package.md § "The nk-auth migration chain"). Returned as
26
+ * `--dep-migrations <folder>#<table>` args, or `[]` when nk-auth is absent.
27
+ *
28
+ * This resolution lives here, not in nk-db: `nk` is the orchestrator that
29
+ * already knows both packages, so nk-db's harness stays generic and the
30
+ * dependency graph stays acyclic (nk-auth → nk-db, never the reverse).
31
+ */
32
+ function authMigrationArgs() {
33
+ try {
34
+ const require = createRequire(resolve(process.cwd(), "package.json"));
35
+ // Resolve the shipped journal via nk-auth's `./migrations/*` export (its
36
+ // `exports` deliberately does not expose `./package.json`). A successful
37
+ // resolve both locates the folder AND confirms the chain is shipped; the
38
+ // folder is the journal's grandparent (…/migrations/meta/_journal.json).
39
+ const journal =
40
+ require.resolve("@ingram-tech/nk-auth/migrations/meta/_journal.json");
41
+ const folder = dirname(dirname(journal));
42
+ return ["--dep-migrations", `${folder}#__nkauth_migrations`];
43
+ } catch {
44
+ return [];
45
+ }
46
+ }
47
+
22
48
  /**
23
49
  * `nk dev` — start the Next dev server on the golden-path local database.
24
50
  *
@@ -33,7 +59,7 @@ function hasPgliteDev() {
33
59
  */
34
60
  export function dev(extraArgs = []) {
35
61
  const command = hasPgliteDev()
36
- ? ["nk-pglite-dev", ...extraArgs]
62
+ ? ["nk-pglite-dev", ...authMigrationArgs(), ...extraArgs]
37
63
  : ["next", "dev", "--turbopack", ...extraArgs];
38
64
  if (command[0] === "nk-pglite-dev") {
39
65
  console.log("nk: @ingram-tech/nk-db found — booting local PGlite (no Docker)…");
package/lib/doctor.js CHANGED
@@ -36,7 +36,7 @@ function writeJson(file, value) {
36
36
  * returns a short past-tense note. `level` is "error" (breaks the model) or
37
37
  * "warn" (cosmetic / cleanup).
38
38
  */
39
- function findings(cwd) {
39
+ export function findings(cwd) {
40
40
  const out = [];
41
41
  const pkgPath = resolve(cwd, "package.json");
42
42
  const pkg = readJson(pkgPath);
@@ -202,7 +202,47 @@ function findings(cwd) {
202
202
  }
203
203
  }
204
204
 
205
- // 7. .prettierignore is now dead weight (nk no longer formats SQL).
205
+ // 7. drizzle-kit is GENERATE-ONLY it must never apply schema.
206
+ // `drizzle-kit push` diffs the live DB and applies straight to it with no
207
+ // migration file and no journal entry: the schema-drift source (it has
208
+ // already drifted one production database in this fleet, and on sites
209
+ // whose dev DB is shared it rewrites everyone's).
210
+ // `drizzle-kit migrate` is opaque — it exits non-zero with no message
211
+ // (even on a clean no-op) and hides journal drift.
212
+ // `nk-pg-migrate` (@ingram-tech/nk-db) is the one runner that applies:
213
+ // it surfaces the real Postgres error and pre-flights drift.
214
+ for (const [name, cmd] of Object.entries(scripts)) {
215
+ if (typeof cmd !== "string") continue;
216
+ if (/\bdrizzle-kit\s+push\b/.test(cmd)) {
217
+ out.push({
218
+ id: `script:drizzle-push:${name}`,
219
+ level: "error",
220
+ 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\`.`,
221
+ fix: (dir) => {
222
+ const p = resolve(dir, "package.json");
223
+ const j = readJson(p);
224
+ delete j.scripts?.[name];
225
+ writeJson(p, j);
226
+ return `removed \`${name}\` (drizzle-kit push)`;
227
+ },
228
+ });
229
+ } else if (/\bdrizzle-kit\s+migrate\b/.test(cmd)) {
230
+ out.push({
231
+ id: `script:drizzle-migrate:${name}`,
232
+ level: "error",
233
+ message: `\`${name}\` runs \`drizzle-kit migrate\` — apply with \`nk-pg-migrate\` instead (it surfaces the real error and pre-flights journal drift).`,
234
+ fix: (dir) => {
235
+ const p = resolve(dir, "package.json");
236
+ const j = readJson(p);
237
+ j.scripts[name] = "nk-pg-migrate";
238
+ writeJson(p, j);
239
+ return `set \`${name}\` → "nk-pg-migrate"`;
240
+ },
241
+ });
242
+ }
243
+ }
244
+
245
+ // 8. .prettierignore is now dead weight (nk no longer formats SQL).
206
246
  const prettierIgnore = resolve(cwd, ".prettierignore");
207
247
  if (existsSync(prettierIgnore)) {
208
248
  out.push({
@@ -223,8 +263,9 @@ function findings(cwd) {
223
263
  /**
224
264
  * `nk doctor [--fix]` — report drift from the canonical nk-dev model (scripts,
225
265
  * dependencies, oxlint/tsconfig extends, the CLAUDE.md guide import, stale knip
226
- * ignores, a dead .prettierignore). With `--fix`, apply every auto-fixable
227
- * finding, then remind to reinstall.
266
+ * ignores, forbidden schema-applying drizzle-kit scripts, a dead
267
+ * .prettierignore). With `--fix`, apply every auto-fixable finding, then remind
268
+ * to reinstall.
228
269
  */
229
270
  export function doctor(args = []) {
230
271
  const fix = args.includes("--fix");
@@ -4,9 +4,9 @@ import { FORMATTER } from "./formatter.js";
4
4
  import { hasKnipConfig, runKnip } from "./knip.js";
5
5
  import { run } from "./run.js";
6
6
 
7
- /** `nk lint` — oxlint. */
8
- export function lint() {
9
- process.exit(run(FORMATTER.lint[0], FORMATTER.lint[1]));
7
+ /** `nk lint [...]` — oxlint, with extra args passed through (e.g. `--fix`). */
8
+ export function lint(extraArgs = []) {
9
+ process.exit(run(FORMATTER.lint[0], [...FORMATTER.lint[1], ...extraArgs]));
10
10
  }
11
11
 
12
12
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingram-tech/nk-dev",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",
@@ -49,9 +49,9 @@
49
49
  "@testing-library/jest-dom": "^6.9.1",
50
50
  "@typescript/native": "npm:typescript@^7.0.2",
51
51
  "jsdom": "^29.1.1",
52
- "knip": "^6.25.0",
53
- "oxfmt": "^0.58.0",
54
- "oxlint": "^1.73.0",
52
+ "knip": "^6.27.0",
53
+ "oxfmt": "^0.59.0",
54
+ "oxlint": "^1.74.0",
55
55
  "typescript": "npm:@typescript/typescript6@^6.0.2",
56
56
  "vitest": "^4.1.10"
57
57
  },