@ingram-tech/nk-dev 0.20.0 → 0.21.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 +3 -0
- package/lib/doctor.js +81 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,9 @@ tsc), so versions stay under your control. nk only orchestrates.
|
|
|
89
89
|
silently 405s the endpoint, a page or layout whose `openGraph` carries no
|
|
90
90
|
image — its own object replaces the inherited one, so the card unfurls as a
|
|
91
91
|
blank placeholder); `--fix` applies the auto-fixable findings.
|
|
92
|
+
In a workspace it judges each package for its role: the root may fan
|
|
93
|
+
`type-check`/`ci` out to members, a member inherits nk-dev and `lint`/`format`
|
|
94
|
+
from the root, and only a Next app is asked for `nk type-check`.
|
|
92
95
|
- **`nk dev`** — start the Next dev server on the golden-path local database
|
|
93
96
|
(see [`db-package.md`](https://github.com/ingram-technologies/nextkit/blob/main/docs/db-package.md)):
|
|
94
97
|
- **PGlite** — if `@ingram-tech/nk-db`'s `nk-pglite-dev` bin resolves, hand off
|
package/lib/doctor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { dirname, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { checkAgentGuideImport, ensureGuideImport } from "./agent-guide.js";
|
|
4
4
|
import { appDirFindings } from "./app-dir.js";
|
|
5
5
|
import { authNextFindings } from "./auth-next.js";
|
|
@@ -56,6 +56,59 @@ function readJson(file) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** A package.json `workspaces` field as a list of patterns. */
|
|
60
|
+
function workspacePatterns(pkg) {
|
|
61
|
+
const ws = pkg?.workspaces;
|
|
62
|
+
if (Array.isArray(ws)) return ws;
|
|
63
|
+
if (Array.isArray(ws?.packages)) return ws.packages;
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True if `rel` (a `/`-separated path) matches a workspace pattern: a `*`
|
|
68
|
+
* segment matches any one segment, `**` any depth. */
|
|
69
|
+
function matchesWorkspace(rel, pattern) {
|
|
70
|
+
const want = pattern.replace(/^\.\//, "").replace(/\/$/, "").split("/");
|
|
71
|
+
const have = rel.split("/");
|
|
72
|
+
if (want.at(-1) === "**") {
|
|
73
|
+
return want.slice(0, -1).every((seg, i) => seg === "*" || seg === have[i]);
|
|
74
|
+
}
|
|
75
|
+
return (
|
|
76
|
+
want.length === have.length &&
|
|
77
|
+
want.every((seg, i) => seg === "*" || seg === have[i])
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The workspace root that lists `cwd` as a member, or null. Walks up from the
|
|
83
|
+
* parent directory: the first package.json declaring `workspaces` decides.
|
|
84
|
+
*/
|
|
85
|
+
function workspaceRootOf(cwd) {
|
|
86
|
+
let dir = dirname(cwd);
|
|
87
|
+
for (;;) {
|
|
88
|
+
const pkg = readJson(resolve(dir, "package.json"));
|
|
89
|
+
if (pkg && workspacePatterns(pkg).length > 0) {
|
|
90
|
+
const rel = relative(dir, cwd).split(sep).join("/");
|
|
91
|
+
return workspacePatterns(pkg).some((p) => matchesWorkspace(rel, p))
|
|
92
|
+
? { dir, pkg }
|
|
93
|
+
: null;
|
|
94
|
+
}
|
|
95
|
+
const parent = dirname(dir);
|
|
96
|
+
if (parent === dir) return null;
|
|
97
|
+
dir = parent;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const NEXT_CONFIGS = [
|
|
102
|
+
"next.config.ts",
|
|
103
|
+
"next.config.mjs",
|
|
104
|
+
"next.config.js",
|
|
105
|
+
"next.config.cjs",
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
/** A script that runs the same script in every workspace member. */
|
|
109
|
+
const DELEGATES_RE =
|
|
110
|
+
/(^|\s)(--filter|-F|--recursive|-r|--workspaces|-ws)(\s|=|$)|\bturbo\s+run\b/;
|
|
111
|
+
|
|
59
112
|
/** Write JSON in the house style (tabs, trailing newline). */
|
|
60
113
|
function writeJson(file, value) {
|
|
61
114
|
writeFileSync(file, `${JSON.stringify(value, null, "\t")}\n`);
|
|
@@ -74,8 +127,22 @@ export function findings(cwd) {
|
|
|
74
127
|
if (!pkg) return out; // not a package — nothing to reconcile
|
|
75
128
|
|
|
76
129
|
// 1. Scripts point at `nk`. Accept either `type-check` or `typecheck` key.
|
|
130
|
+
// In a workspace: the root may fan `type-check` out to its members; a
|
|
131
|
+
// member leaves `lint`/`format` to a root that runs them; and only a Next
|
|
132
|
+
// app wants `nk type-check` (it runs `next typegen`), a library runs tsc.
|
|
77
133
|
const scripts = pkg.scripts ?? {};
|
|
134
|
+
const isWorkspaceRoot = workspacePatterns(pkg).length > 0;
|
|
135
|
+
const delegates = (cmd) => isWorkspaceRoot && DELEGATES_RE.test(cmd ?? "");
|
|
136
|
+
const root = workspaceRootOf(cwd);
|
|
137
|
+
const isNextApp = NEXT_CONFIGS.some((f) => existsSync(resolve(cwd, f)));
|
|
138
|
+
const runsTsc = (cmd) => root !== null && !isNextApp && /\btsc\b/.test(cmd ?? "");
|
|
78
139
|
for (const [name, wanted] of Object.entries(CANONICAL_SCRIPTS)) {
|
|
140
|
+
if (
|
|
141
|
+
(name === "lint" || name === "format") &&
|
|
142
|
+
root?.pkg.scripts?.[name] === wanted
|
|
143
|
+
) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
79
146
|
const key =
|
|
80
147
|
name === "type-check" &&
|
|
81
148
|
scripts["typecheck"] !== undefined &&
|
|
@@ -84,6 +151,7 @@ export function findings(cwd) {
|
|
|
84
151
|
: name;
|
|
85
152
|
const current = scripts[key];
|
|
86
153
|
if (current === wanted) continue;
|
|
154
|
+
if (name === "type-check" && (delegates(current) || runsTsc(current))) continue;
|
|
87
155
|
// Only flag `check` as missing if the repo has scripts at all; a repo
|
|
88
156
|
// truly without a check script still wants one on the nk model.
|
|
89
157
|
out.push({
|
|
@@ -104,9 +172,11 @@ export function findings(cwd) {
|
|
|
104
172
|
});
|
|
105
173
|
}
|
|
106
174
|
|
|
107
|
-
// 2. Superseded deps still declared.
|
|
175
|
+
// 2. Superseded deps still declared. A workspace member inherits nk-dev
|
|
176
|
+
// from the root that declares it (one toolchain, hoisted).
|
|
108
177
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
109
|
-
|
|
178
|
+
const rootDeps = { ...root?.pkg.dependencies, ...root?.pkg.devDependencies };
|
|
179
|
+
if (deps["@ingram-tech/nk-dev"] || rootDeps["@ingram-tech/nk-dev"]) {
|
|
110
180
|
const superseded = SUPERSEDED_DEPS.filter((d) => d in deps);
|
|
111
181
|
for (const dep of superseded) {
|
|
112
182
|
out.push({
|
|
@@ -297,7 +367,9 @@ export function findings(cwd) {
|
|
|
297
367
|
// 9. A `ci` script exists and runs the house gate. Its full contents are
|
|
298
368
|
// the site's call (migrations, i18n, email catalogs, build…), so this only
|
|
299
369
|
// warns and never writes — but the dep-upgrade flow and pre-push both
|
|
300
|
-
// assume `bun run ci` is the one command that proves a change.
|
|
370
|
+
// assume `bun run ci` is the one command that proves a change. A
|
|
371
|
+
// workspace root that fans `ci` out to its members passes: each member's
|
|
372
|
+
// own `ci` is what this checks when doctor runs there.
|
|
301
373
|
const ci = scripts["ci"];
|
|
302
374
|
if (ci === undefined) {
|
|
303
375
|
out.push({
|
|
@@ -306,9 +378,12 @@ export function findings(cwd) {
|
|
|
306
378
|
message:
|
|
307
379
|
'missing `ci` script — the one command that proves a change (e.g. "nk check && nk type-check && nk test")',
|
|
308
380
|
});
|
|
309
|
-
} else {
|
|
381
|
+
} else if (!delegates(ci)) {
|
|
310
382
|
const missing = ["nk check", "nk type-check"].filter(
|
|
311
|
-
(cmd) =>
|
|
383
|
+
(cmd) =>
|
|
384
|
+
!ci.includes(cmd) &&
|
|
385
|
+
!ci.includes(`bun run ${cmd.slice(3)}`) &&
|
|
386
|
+
!(cmd === "nk type-check" && runsTsc(ci)),
|
|
312
387
|
);
|
|
313
388
|
if (missing.length > 0) {
|
|
314
389
|
out.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.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",
|