@ingram-tech/nk-dev 0.21.0 → 0.22.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 +1 -1
- package/bin/format-staged.mjs +1 -1
- package/lib/format.js +1 -1
- package/lib/og-image.js +44 -2
- package/oxfmtrc.json +0 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ tsc), so versions stay under your control. nk only orchestrates.
|
|
|
98
98
|
to it: boot Postgres-in-WASM, apply the `drizzle/` migrations, set
|
|
99
99
|
`DATABASE_URL`, then `next dev --turbopack`. No Docker, no daemon.
|
|
100
100
|
- **Plain** — otherwise just `next dev` (static/marketing sites with no DB).
|
|
101
|
-
- **`nk format` / `nk format --check`** — formats code (JS/TS/JSON/CSS) with
|
|
101
|
+
- **`nk format` / `nk format --check`** — formats code (JS/TS/JSON/CSS/TOML) with
|
|
102
102
|
oxfmt. `--check` verifies without writing (CI). SQL isn't formatted; see
|
|
103
103
|
[Why no SQL formatting?](#why-no-sql-formatting).
|
|
104
104
|
- **`nk lint`** — `oxlint`. nk-dev ships oxlint's type-aware backend
|
package/bin/format-staged.mjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { execFileSync } from "node:child_process";
|
|
20
20
|
import { existsSync } from "node:fs";
|
|
21
21
|
|
|
22
|
-
const FORMATTABLE = /\.(jsx?|mjs|cjs|tsx?|mts|cts|json|jsonc|css|graphql|gql)$/;
|
|
22
|
+
const FORMATTABLE = /\.(jsx?|mjs|cjs|tsx?|mts|cts|json|jsonc|css|graphql|gql|toml)$/;
|
|
23
23
|
|
|
24
24
|
const git = (args) => execFileSync("git", args, { encoding: "utf8" });
|
|
25
25
|
|
package/lib/format.js
CHANGED
|
@@ -4,7 +4,7 @@ import { run } from "./run.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* `nk format` / `nk format --check`.
|
|
6
6
|
*
|
|
7
|
-
* Code (JS/TS/JSON/CSS) goes through oxfmt — the one formatter nk owns. SQL is
|
|
7
|
+
* Code (JS/TS/JSON/CSS/TOML) goes through oxfmt — the one formatter nk owns. SQL is
|
|
8
8
|
* intentionally NOT formatted: it's almost entirely generated (drizzle
|
|
9
9
|
* migrations, `pg_dump` baselines, pglite fixtures), so a SQL formatter only
|
|
10
10
|
* churns generated files and chokes on psql directives (`\restrict`, …) for no
|
package/lib/og-image.js
CHANGED
|
@@ -13,9 +13,51 @@ import { join, resolve } from "node:path";
|
|
|
13
13
|
|
|
14
14
|
const PAGE_OR_LAYOUT = /^(layout|page)\.(tsx|jsx|ts|js)$/;
|
|
15
15
|
const IMAGE_FILE = /^opengraph-image\d*\.(tsx|jsx|ts|js|png|jpe?g|gif)$/;
|
|
16
|
-
const
|
|
16
|
+
const CARD_KEY = /\b(openGraph|twitter)\s*:/g;
|
|
17
17
|
const CARRIES_IMAGE = /\bimages\s*[:,}]|\bogImageMetadata\s*\(/;
|
|
18
18
|
|
|
19
|
+
/** Blank out string and template literals, keeping offsets, so braces inside
|
|
20
|
+
* copy (`"{name}"`) don't confuse the bracket walk below. */
|
|
21
|
+
const blankStrings = (src) =>
|
|
22
|
+
src.replace(/(["'`])(?:\\.|(?!\1)[\s\S])*\1/g, (m) => " ".repeat(m.length));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether the card key at `at` sits in a metadata object the file builds
|
|
26
|
+
* itself (`export const metadata = { ... }`, `return { ... }`, `=> ({ ... })`)
|
|
27
|
+
* rather than in an argument to a call (`createPageMetadata({ openGraph })`).
|
|
28
|
+
* A call can add the image (nk-seo's `createMetadata` merges `defaultImage`
|
|
29
|
+
* into the override), and a text check cannot see what it adds, so only a
|
|
30
|
+
* literal the file returns is provably missing one.
|
|
31
|
+
*/
|
|
32
|
+
function inOwnLiteral(src, at) {
|
|
33
|
+
let depth = 0;
|
|
34
|
+
for (let i = at - 1; i >= 0; i--) {
|
|
35
|
+
const c = src[i];
|
|
36
|
+
if (c === ")" || c === "]" || c === "}") {
|
|
37
|
+
depth++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (c !== "(" && c !== "[" && c !== "{") continue;
|
|
41
|
+
if (depth > 0) {
|
|
42
|
+
depth--;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (c === "[") continue; // an element of an array: keep walking out
|
|
46
|
+
const before = src.slice(0, i).trimEnd();
|
|
47
|
+
if (/(=>|\breturn|[^=!<>]=)$/.test(before)) return true;
|
|
48
|
+
if (c === "(") return false; // a call argument
|
|
49
|
+
if (/[:,{(]$/.test(before)) continue; // a nested object: keep walking out
|
|
50
|
+
return true; // a statement or function body: the literal is the file's own
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Whether the file returns a card (openGraph/twitter) of its own building. */
|
|
56
|
+
const declaresOwnCard = (src) => {
|
|
57
|
+
const code = blankStrings(src);
|
|
58
|
+
return [...code.matchAll(CARD_KEY)].some((m) => inOwnLiteral(code, m.index));
|
|
59
|
+
};
|
|
60
|
+
|
|
19
61
|
/** The site's app directory, or null when it has none. */
|
|
20
62
|
function findAppDir(cwd) {
|
|
21
63
|
const dir = resolve(cwd, "src/app");
|
|
@@ -47,7 +89,7 @@ function collect(cwd, dir, segments, nearest, out) {
|
|
|
47
89
|
if (!PAGE_OR_LAYOUT.test(entry.name)) continue;
|
|
48
90
|
if (here) continue; // the file convention wins in its own segment
|
|
49
91
|
const src = readFileSync(full, "utf8");
|
|
50
|
-
if (!
|
|
92
|
+
if (!declaresOwnCard(src) || CARRIES_IMAGE.test(src)) continue;
|
|
51
93
|
out.push({
|
|
52
94
|
file: full.slice(cwd.length + 1),
|
|
53
95
|
route: `/${segments.join("/")}`,
|
package/oxfmtrc.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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,17 +45,17 @@
|
|
|
45
45
|
"test": "vitest run"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ast-grep/cli": "^0.
|
|
48
|
+
"@ast-grep/cli": "^0.51.0",
|
|
49
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.1.
|
|
53
|
-
"knip": "^6.
|
|
54
|
-
"oxfmt": "^0.
|
|
55
|
-
"oxlint": "^1.
|
|
56
|
-
"oxlint-tsgolint": "^7.0.
|
|
52
|
+
"jsdom": "^30.1.3",
|
|
53
|
+
"knip": "^6.43.0",
|
|
54
|
+
"oxfmt": "^0.75.0",
|
|
55
|
+
"oxlint": "^1.90.0",
|
|
56
|
+
"oxlint-tsgolint": "^7.0.2005",
|
|
57
57
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
58
|
-
"vitest": "^5.0.
|
|
58
|
+
"vitest": "^5.0.5"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|