basalt-ui 2.0.4 → 2.1.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/dist/cli/index.js CHANGED
@@ -91,20 +91,10 @@ function sanitizeSeverity(cfg) {
91
91
  return { ...cfg, severity: kept };
92
92
  }
93
93
  function hasBasaltKey(cwd) {
94
- const raw = readIfExists(resolve(cwd, "package.json"));
95
- try {
96
- return raw !== null && JSON.parse(raw).basalt !== void 0;
97
- } catch {
98
- return false;
99
- }
94
+ return readPackageJson(cwd)?.basalt !== void 0;
100
95
  }
101
96
  function readBasaltConfig(cwd) {
102
- try {
103
- const pkg = JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
104
- return sanitizeSeverity(pkg.basalt ?? {});
105
- } catch {
106
- return {};
107
- }
97
+ return sanitizeSeverity(readPackageJson(cwd)?.basalt ?? {});
108
98
  }
109
99
  const SCANNABLE_EXT = /\.(?:tsx?|jsx|[cm][jt]s|astro|vue|css|html?|webmanifest)$/;
110
100
  function walkSourceFiles(dir, out = []) {
@@ -136,14 +126,11 @@ function relativePosix(fromDir, toPath) {
136
126
  const UNRESOLVED_INSTALL = { dir: null, version: null, how: null };
137
127
  function basaltInstallAt(dir) {
138
128
  const installDir = resolve(dir, "node_modules", "basalt-ui");
139
- const raw = readIfExists(resolve(installDir, "package.json"));
140
- if (raw === null) return null;
141
- try {
142
- const pkg = JSON.parse(raw);
143
- return { dir: installDir, version: pkg.version ?? null };
144
- } catch {
145
- return { dir: installDir, version: null };
146
- }
129
+ if (readIfExists(resolve(installDir, "package.json")) === null) return null;
130
+ return {
131
+ dir: installDir,
132
+ version: readPackageJson(installDir)?.version ?? null
133
+ };
147
134
  }
148
135
  function findBasaltInstall(cwd) {
149
136
  const own = basaltInstallAt(cwd);
@@ -244,24 +231,24 @@ function readIfExists(abs) {
244
231
  return null;
245
232
  }
246
233
  }
234
+ function readPackageJson(dir) {
235
+ const raw = readIfExists(resolve(dir, "package.json"));
236
+ try {
237
+ return raw === null ? null : JSON.parse(raw);
238
+ } catch {
239
+ return null;
240
+ }
241
+ }
247
242
  function readSource(pkgRoot, source) {
248
243
  return readIfExists(resolve(pkgRoot, source));
249
244
  }
250
245
  function readPackageName(cwd) {
251
- try {
252
- const pkg = JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
253
- if (pkg.name && pkg.name.length > 0) return pkg.name;
254
- } catch {
255
- }
246
+ const name = readPackageJson(cwd)?.name;
247
+ if (name && name.length > 0) return name;
256
248
  return cwd.split("/").filter(Boolean).pop() ?? "app";
257
249
  }
258
250
  function readFrameworkVersion(pkgRoot) {
259
- try {
260
- const pkg = JSON.parse(readFileSync(resolve(pkgRoot, "package.json"), "utf8"));
261
- return pkg.version ?? "0.0.0";
262
- } catch {
263
- return "0.0.0";
264
- }
251
+ return readPackageJson(pkgRoot)?.version ?? "0.0.0";
265
252
  }
266
253
  function basaltBinCommand(install, cwd) {
267
254
  if (install.dir === null) return "bunx basalt-ui";
@@ -397,14 +384,10 @@ function resolveAppDir(root) {
397
384
  };
398
385
  }
399
386
  function hasDependency(cwd, pkgName) {
400
- try {
401
- const pkg = JSON.parse(readFileSync(resolve(cwd, "package.json"), "utf8"));
402
- return Boolean(
403
- pkg.dependencies?.[pkgName] ?? pkg.devDependencies?.[pkgName] ?? pkg.peerDependencies?.[pkgName]
404
- );
405
- } catch {
406
- return false;
407
- }
387
+ const pkg = readPackageJson(cwd);
388
+ return Boolean(
389
+ pkg?.dependencies?.[pkgName] ?? pkg?.devDependencies?.[pkgName] ?? pkg?.peerDependencies?.[pkgName]
390
+ );
408
391
  }
409
392
  const ROOT_PLACEMENT = {
410
393
  isPackageRepoRoot: true,
@@ -694,14 +677,8 @@ function renderContext(cwd) {
694
677
  function patchPackageJson(cwd, mutate) {
695
678
  const abs = resolve(cwd, "package.json");
696
679
  const raw = readIfExists(abs);
697
- if (raw === null) return false;
698
- let pkg;
699
- try {
700
- pkg = JSON.parse(raw);
701
- } catch {
702
- return false;
703
- }
704
- if (!mutate(pkg)) return false;
680
+ const pkg = readPackageJson(cwd);
681
+ if (raw === null || pkg === null || !mutate(pkg)) return false;
705
682
  const indent = /\n([ \t]+)"/.exec(raw)?.[1] ?? " ";
706
683
  writeFileSync(abs, JSON.stringify(pkg, null, indent) + (raw.endsWith("\n") ? "\n" : ""));
707
684
  return true;
@@ -926,14 +903,8 @@ function expandWorkspaceGlobs(cwd, patterns) {
926
903
  return dirs;
927
904
  }
928
905
  function collectWorkspacePackages(cwd) {
929
- const raw = readIfExists(resolve(cwd, "package.json"));
930
- if (raw === null) return { packages: [], hasWorkspacesField: false };
931
- let parsed;
932
- try {
933
- parsed = JSON.parse(raw);
934
- } catch {
935
- return { packages: [], hasWorkspacesField: false };
936
- }
906
+ const parsed = readPackageJson(cwd);
907
+ if (parsed === null) return { packages: [], hasWorkspacesField: false };
937
908
  const patterns = isStringArray(parsed.workspaces) ? parsed.workspaces : parsed.workspaces !== null && typeof parsed.workspaces === "object" && isStringArray(parsed.workspaces.packages) ? parsed.workspaces.packages : null;
938
909
  if (patterns === null) return { packages: [], hasWorkspacesField: false };
939
910
  const rootName = parsed.name && parsed.name.length > 0 ? `${parsed.name} (root)` : "(root)";
@@ -1048,6 +1019,7 @@ export {
1048
1019
  readFrameworkVersion,
1049
1020
  readIfExists,
1050
1021
  readManifest,
1022
+ readPackageJson,
1051
1023
  readSource,
1052
1024
  reconcileRoots,
1053
1025
  relativePosix,
@@ -1 +1 @@
1
- {"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../../src/content/highlighter.ts"],"names":[],"mappings":"AAkGA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBtF"}
1
+ {"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../../src/content/highlighter.ts"],"names":[],"mappings":"AAkHA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBtF"}
@@ -37,6 +37,14 @@ const LANG_ALIASES = {
37
37
  docker: "dockerfile"
38
38
  };
39
39
  let highlighterPromise = null;
40
+ let warnedMissingPeer = false;
41
+ function warnMissingPeer(error) {
42
+ if (warnedMissingPeer || process.env["NODE_ENV"] === "production") return;
43
+ warnedMissingPeer = true;
44
+ console.warn(
45
+ `[basalt] CodeBlock: syntax highlighting is off \u2014 a peer of basalt-ui/content did not load (${error instanceof Error ? error.message : String(error)}). Code renders unhighlighted. Install them with: bun add shiki @shikijs/langs @shikijs/themes`
46
+ );
47
+ }
40
48
  async function loadHighlighter() {
41
49
  const [{ createHighlighterCore }, { createJavaScriptRegexEngine }] = await Promise.all([
42
50
  import("shiki/core"),
@@ -49,7 +57,10 @@ async function loadHighlighter() {
49
57
  });
50
58
  }
51
59
  function getHighlighter() {
52
- highlighterPromise ??= loadHighlighter().catch(() => null);
60
+ highlighterPromise ??= loadHighlighter().catch((error) => {
61
+ warnMissingPeer(error);
62
+ return null;
63
+ });
53
64
  return highlighterPromise;
54
65
  }
55
66
  async function ensureLanguage(highlighter, lang) {
@@ -59,7 +70,8 @@ async function ensureLanguage(highlighter, lang) {
59
70
  try {
60
71
  await highlighter.loadLanguage(loadLang());
61
72
  return true;
62
- } catch {
73
+ } catch (error) {
74
+ warnMissingPeer(error);
63
75
  return false;
64
76
  }
65
77
  }
@@ -103,9 +103,11 @@
103
103
  * Block is breathing room under the band's single `--vx-divider` line — nothing aligns to it.
104
104
  * `stack-md` (12) on a phone, one rung down (`stack-sm`, 8) from `sm` up where the inline gutter
105
105
  * is 16: the page then sits 16 from the seam and 8 under the header, rather than the 20/12 it
106
- * used to.
106
+ * used to. The value rides `--basalt-main-pad-block`, which descendants inherit: the data
107
+ * table's page-sticky offset reads it instead of repeating this module's `sm` switch.
107
108
  */
108
- padding: var(--vx-space-stack-md) var(--app-shell-padding);
109
+ --basalt-main-pad-block: var(--vx-space-stack-md);
110
+ padding: var(--basalt-main-pad-block) var(--app-shell-padding);
109
111
  /* Without this a wide flex/grid child (a bare table, a nowrap control row) sizes Main to ITSELF. */
110
112
  min-width: 0;
111
113
  overflow-y: auto;
@@ -124,7 +126,7 @@
124
126
 
125
127
  @media (min-width: 52.5em) {
126
128
  .main {
127
- padding-block: var(--vx-space-stack-sm);
129
+ --basalt-main-pad-block: var(--vx-space-stack-sm);
128
130
  }
129
131
  }
130
132
 
@@ -1 +1 @@
1
- {"version":3,"file":"app-sidebar.d.ts","sourceRoot":"","sources":["../../src/shell/app-sidebar.tsx"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAe,cAAc,EAAE,MAAM,aAAa,CAAA;AAI5E,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAgBjF,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAC1C;;;;OAIG;IACH,KAAK,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,eAAe,EAAE,CAAA;KAAE,CAAA;IACjD,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,SAAS,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACtC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B;;;;OAIG;IACH,MAAM,CAAC,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,oBAAoB,CAAA;KAAE,CAAA;IACjE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;CACxB,CAAA;AAiUD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BA2KhD"}
1
+ {"version":3,"file":"app-sidebar.d.ts","sourceRoot":"","sources":["../../src/shell/app-sidebar.tsx"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAe,cAAc,EAAE,MAAM,aAAa,CAAA;AAI5E,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAgBjF,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG;IAC1C;;;;OAIG;IACH,KAAK,EAAE,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,eAAe,EAAE,CAAA;KAAE,CAAA;IACjD,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,SAAS,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACtC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAA;IAC5B;;;;OAIG;IACH,MAAM,CAAC,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,oBAAoB,CAAA;KAAE,CAAA;IACjE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;CACxB,CAAA;AAmUD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BA2KhD"}
@@ -163,7 +163,7 @@ function NavSection({ section, collapsed }) {
163
163
  ]
164
164
  }
165
165
  ),
166
- /* @__PURE__ */ jsx(Collapse, { expanded: !folded, children: /* @__PURE__ */ jsx(Stack, { gap: 1, children: items }) })
166
+ /* @__PURE__ */ jsx(Collapse, { expanded: !folded || collapsed, children: /* @__PURE__ */ jsx(Stack, { gap: 1, children: items }) })
167
167
  ] });
168
168
  }
169
169
  function NavItemRow({ item, collapsed }) {
@@ -70,20 +70,14 @@
70
70
  * one rung down to `stack-sm` from `sm` up). A sticky `<thead>` resolves against the scrollport's
71
71
  * CONTENT edge, so at `top: 0` it parked that padding below the band and every body row scrolled
72
72
  * through the gap. A negative offset equal to the padding moves the stick line out to the band's
73
- * edge, flush. The two media/token pairs below mirror `.main` there — the layout suite
74
- * (`data-table.layout.test.ts`, invariant 8) fails on drift. A consumer `stickyHeaderOffset` is an
73
+ * edge, flush. The padding is read from `--basalt-main-pad-block`, which `.main` sets and owns
74
+ * (including its `sm` switch), so the two cannot drift; `data-table.layout.test.ts` invariant 8
75
+ * pins both steps. A consumer `stickyHeaderOffset` is an
75
76
  * inline `--table-sticky-header-offset` on the table and beats this class, so it still wins.
76
77
  * Outside a shell no `.mantine-AppShell-main` ancestor matches and the offset stays 0.
77
78
  */
78
79
  :global(.mantine-AppShell-main) .pageSticky {
79
- --table-sticky-header-offset: calc(-1 * var(--vx-space-stack-md));
80
- }
81
-
82
- /* theme-allow raw-media-query — mirrors app-main.module.css's own `sm` switch for Main's block padding; invariant 8 in data-table.layout.test.ts fails on drift */
83
- @media (min-width: 52.5em) {
84
- :global(.mantine-AppShell-main) .pageSticky {
85
- --table-sticky-header-offset: calc(-1 * var(--vx-space-stack-sm));
86
- }
80
+ --table-sticky-header-offset: calc(-1 * var(--basalt-main-pad-block, 0px));
87
81
  }
88
82
 
89
83
  /*
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # basalt-ui v2.0.4
1
+ # basalt-ui v2.1.0
2
2
  # Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
3
3
  #
4
4
  # Entry points: use the exact import specifier below; do not guess.
@@ -13,7 +13,7 @@
13
13
  # A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
14
14
 
15
15
  Package: basalt-ui
16
- Version: 2.0.4
16
+ Version: 2.1.0
17
17
 
18
18
  ## basalt-ui
19
19
  Import: import { ... } from 'basalt-ui'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basalt-ui",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets",
5
5
  "keywords": [
6
6
  "charts",
@@ -26,7 +26,22 @@ function stringField(value: unknown, key: string): string | undefined {
26
26
  return typeof field === 'string' ? field : undefined
27
27
  }
28
28
 
29
- /** Maps whatever a transport threw onto the closed `AgentError` union. */
29
+ /**
30
+ * Classifies whatever a chat transport threw or received into the closed `AgentError` union — the
31
+ * same mapping `useAgentThreadRuns` applies to `ThreadRunState.error`, so a custom transport can
32
+ * report failures identically.
33
+ *
34
+ * Input is any thrown value, matched by shape (never `instanceof`, so the optional `ai` peer is not
35
+ * loaded). First match wins:
36
+ * - `name === 'AbortError'` (an `Error` or a `DOMException`) → `{ kind: 'aborted' }`
37
+ * - numeric `statusCode` (AI SDK `APICallError`) → `{ kind: 'http', status }`
38
+ * - string `chunkType` and `chunkId` (AI SDK `UIMessageStreamError`) → `{ kind: 'stream', ... }`
39
+ * - anything else, including an `error` chunk's text, a plain object or a primitive →
40
+ * `{ kind: 'server', message }` with the value's `message` string, else `String(value)`.
41
+ *
42
+ * A `Response` is not classified: read its `status` and pass `{ statusCode: response.status }`.
43
+ * Never throws.
44
+ */
30
45
  export function toAgentError(error: unknown): AgentError {
31
46
  // By name, not `instanceof Error`: a `fetch` abort is a DOMException, which is not an Error.
32
47
  if (stringField(error, 'name') === 'AbortError') return { kind: 'aborted' }
@@ -18,6 +18,7 @@ export { aiSdkTransport } from './ai-sdk-transport'
18
18
  export { useAgentThreadRuns } from './use-agent-thread-runs'
19
19
  export type { ThreadRunState } from './use-agent-thread-runs'
20
20
  export type { AgentError } from './error'
21
+ export { toAgentError } from './error'
21
22
 
22
23
  // ── Thread contracts (the store is consumer-owned) ────────────────────────────
23
24
  export type { ChatMessage } from './history'
@@ -2,13 +2,13 @@
2
2
  * `doctor`'s 2.0 strictness and upgrade checks. Each returns null (pass), `{ fail }` (the problem
3
3
  * plus its fix) or `{ skip }` (the check could not run: a check that cannot run is not a pass).
4
4
  */
5
- import { existsSync, readFileSync, writeFileSync } from 'node:fs'
5
+ import { existsSync, writeFileSync } from 'node:fs'
6
6
  import { createRequire } from 'node:module'
7
7
  import { dirname, relative, resolve } from 'node:path'
8
8
 
9
9
  import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS } from './config'
10
10
  import type { BasaltConfig } from './config'
11
- import { parseJsonc, readIfExists, scannableFiles } from './index'
11
+ import { parseJsonc, readIfExists, readPackageJson, scannableFiles } from './index'
12
12
  import type { BasaltInstall } from './index'
13
13
 
14
14
  export type Check = { fail: string } | { skip: string } | null
@@ -22,6 +22,19 @@ const guarded = (id: string, run: () => Check): Check => {
22
22
  }
23
23
  }
24
24
 
25
+ /** A check that reads the resolved install: skips when basalt-ui does not resolve. */
26
+ const withInstall = (
27
+ id: string,
28
+ install: BasaltInstall,
29
+ reads: string,
30
+ run: (dir: string) => Check,
31
+ ): Check => {
32
+ const { dir } = install
33
+ return dir === null
34
+ ? { skip: `${id}: basalt-ui does not resolve, so its ${reads} cannot be read.` }
35
+ : guarded(id, () => run(dir))
36
+ }
37
+
25
38
  const TSCONFIG_PRESET = /(?:^|\/)basalt-ui\/configs\/tsconfig\.(?:base|react-app)\.json$/
26
39
  const TSCONFIG_PRESET_ID = 'basalt-ui/configs/tsconfig.react-app.json'
27
40
  const TSCONFIG_FIX = `"extends": "${TSCONFIG_PRESET_ID}" (tsconfig.base.json for a package without a DOM)`
@@ -148,10 +161,7 @@ function basaltRuleIds(file: string, seen = new Set<string>()): string[] {
148
161
  /** `retired-lint-rules`: `basalt/<id>` entries the installed plugin no longer registers. */
149
162
  export function retiredLintRulesCheck(cwd: string, install: BasaltInstall): Check {
150
163
  const id = 'retired-lint-rules'
151
- const dir = install.dir
152
- if (dir === null)
153
- return { skip: `${id}: basalt-ui does not resolve, so its plugin cannot be read.` }
154
- return guarded(id, () => {
164
+ return withInstall(id, install, 'plugin', (dir) => {
155
165
  const ids = [...new Set(basaltRuleIds(resolve(cwd, '.oxlintrc.json')))]
156
166
  if (ids.length === 0) return null
157
167
  const pluginPath = resolve(dir, 'configs/oxlint-plugin.js')
@@ -215,6 +225,16 @@ function basaltImports(src: string): [string, number][] {
215
225
  .map((m) => [m[2] as string, code.slice(0, m.index + m[0].length).split('\n').length])
216
226
  }
217
227
 
228
+ /** `[subpath, file, line]` per `basalt-ui/<subpath>` import in the app's source files. */
229
+ const appImports = (cwd: string, cfg: BasaltConfig): [string, string, number][] =>
230
+ scannableFiles(cwd, cfg)
231
+ .filter((f) => /\.(?:[cm]?[jt]sx?|vue|astro)$/.test(f))
232
+ .flatMap((rel) =>
233
+ basaltImports(readIfExists(resolve(cwd, rel)) ?? '').map(
234
+ ([sub, line]): [string, string, number] => [sub, rel, line],
235
+ ),
236
+ )
237
+
218
238
  /** `dropped-subpaths`: `basalt-ui/<subpath>` imports the installed `exports` map does not have. */
219
239
  export function droppedSubpathsCheck(
220
240
  cwd: string,
@@ -222,28 +242,20 @@ export function droppedSubpathsCheck(
222
242
  install: BasaltInstall,
223
243
  ): Check {
224
244
  const id = 'dropped-subpaths'
225
- const dir = install.dir
226
- if (dir === null)
227
- return { skip: `${id}: basalt-ui does not resolve, so its exports cannot be read.` }
228
- return guarded(id, () => {
229
- const pkg = JSON.parse(readFileSync(resolve(dir, 'package.json'), 'utf8')) as {
230
- exports?: Record<string, unknown>
231
- }
245
+ return withInstall(id, install, 'exports', (dir) => {
246
+ const pkg = readPackageJson<{ exports?: Record<string, unknown> }>(dir)
247
+ if (pkg === null) throw new Error(`${dir}/package.json is unreadable`)
248
+ const exportsMap = pkg.exports
232
249
  // No `exports` field means nothing restricts the deep imports.
233
- if (pkg.exports === undefined) return null
234
- const keys = Object.keys(pkg.exports)
250
+ if (exportsMap === undefined) return null
251
+ const keys = Object.keys(exportsMap)
235
252
  const has = (sub: string): boolean =>
236
253
  keys.some(
237
254
  (k) => k === `./${sub}` || (k.endsWith('*') && `./${sub}`.startsWith(k.slice(0, -1))),
238
255
  )
239
- const hits: string[] = []
240
- for (const rel of scannableFiles(cwd, cfg).filter((f) =>
241
- /\.(?:[cm]?[jt]sx?|vue|astro)$/.test(f),
242
- )) {
243
- for (const [sub, line] of basaltImports(readIfExists(resolve(cwd, rel)) ?? '')) {
244
- if (!has(sub)) hits.push(`${rel}:${line} imports basalt-ui/${sub}`)
245
- }
246
- }
256
+ const hits = appImports(cwd, cfg)
257
+ .filter(([sub]) => !has(sub))
258
+ .map(([sub, rel, line]) => `${rel}:${line} imports basalt-ui/${sub}`)
247
259
  if (hits.length === 0) return null
248
260
  const more = hits.length > 10 ? ` (+${hits.length - 10} more)` : ''
249
261
  return {
@@ -446,8 +458,7 @@ export function appWiringCheck(cwd: string): Check {
446
458
  */
447
459
  export function unknownConfigKeysCheck(cwd: string): Check {
448
460
  return guarded('config-keys', () => {
449
- const raw = readIfExists(resolve(cwd, 'package.json'))
450
- const block = raw === null ? null : (JSON.parse(raw) as { basalt?: unknown }).basalt
461
+ const block = readPackageJson<{ basalt?: unknown }>(cwd)?.basalt
451
462
  if (typeof block !== 'object' || block === null || Array.isArray(block)) return null
452
463
  const known = new Set<string>(BASALT_CONFIG_KEYS)
453
464
  const unknown = Object.keys(block).filter((k) => !known.has(k))
@@ -461,13 +472,18 @@ export function unknownConfigKeysCheck(cwd: string): Check {
461
472
  })
462
473
  }
463
474
 
475
+ /** The `peerDependencies` ranges declared by the package installed at `dir`. */
476
+ function peerRanges(dir: string): Record<string, string> {
477
+ return readPackageJson<{ peerDependencies?: Record<string, string> }>(dir)?.peerDependencies ?? {}
478
+ }
479
+
464
480
  const EXACT_VERSION = /^\d+\.\d+\.\d+$/
465
481
 
466
482
  /** `node_modules/<pkg>/package.json`'s version, searching `cwd` then every ancestor. */
467
483
  function installedVersion(cwd: string, pkg: string): string | null {
468
484
  for (let dir = cwd; ; dir = dirname(dir)) {
469
- const raw = readIfExists(resolve(dir, 'node_modules', pkg, 'package.json'))
470
- if (raw !== null) return (JSON.parse(raw) as { version?: string }).version ?? null
485
+ const manifest = readPackageJson<{ version?: string }>(resolve(dir, 'node_modules', pkg))
486
+ if (manifest !== null) return manifest.version ?? null
471
487
  if (dirname(dir) === dir) return null
472
488
  }
473
489
  }
@@ -479,16 +495,8 @@ function installedVersion(cwd: string, pkg: string): string | null {
479
495
  */
480
496
  export function exactPeersCheck(cwd: string, install: BasaltInstall): Check {
481
497
  const id = 'exact-peers'
482
- if (install.dir === null)
483
- return { skip: `${id}: basalt-ui does not resolve, so its peers cannot be read.` }
484
- const dir = install.dir
485
- return guarded(id, () => {
486
- const raw = readIfExists(resolve(dir, 'package.json'))
487
- const peers =
488
- (raw === null
489
- ? {}
490
- : (JSON.parse(raw) as { peerDependencies?: Record<string, string> }).peerDependencies) ?? {}
491
- const off = Object.entries(peers)
498
+ return withInstall(id, install, 'peers', (dir) => {
499
+ const off = Object.entries(peerRanges(dir))
492
500
  .filter(([, range]) => EXACT_VERSION.test(range))
493
501
  .flatMap(([pkg, pin]) => {
494
502
  const have = installedVersion(cwd, pkg)
@@ -502,3 +510,46 @@ export function exactPeersCheck(cwd: string, install: BasaltInstall): Check {
502
510
  }
503
511
  })
504
512
  }
513
+
514
+ /**
515
+ * The peers a subpath needs installed: V2-SPEC § 1's subpath-required class plus `./content`'s
516
+ * shiki trio, which a bundler cannot resolve without them (argo friction row 15). The test pins it
517
+ * to `package.json` and `surfaces.ts`.
518
+ */
519
+ export const SUBPATH_REQUIRED_PEERS: Readonly<Record<string, readonly string[]>> = {
520
+ agent: ['ai', '@ai-sdk/provider', 'motion'],
521
+ charts: ['@tanstack/charts', 'd3-scale'],
522
+ commands: ['@tanstack/react-hotkeys'],
523
+ content: ['react-markdown', 'shiki', '@shikijs/langs', '@shikijs/themes'],
524
+ 'controls-dates': ['@mantine/dates', 'dayjs'],
525
+ forms: ['@mantine/form'],
526
+ table: ['@tanstack/react-table'],
527
+ }
528
+
529
+ /**
530
+ * `subpath-peers`: every `basalt-ui/<subpath>` the app imports has its required peers installed. A
531
+ * missing one still builds, then throws "Could not resolve" when the chunk loads.
532
+ */
533
+ export function subpathPeersCheck(cwd: string, cfg: BasaltConfig, install: BasaltInstall): Check {
534
+ const id = 'subpath-peers'
535
+ return withInstall(id, install, 'peers', (dir) => {
536
+ const missing = new Map<string, string[]>()
537
+ for (const [sub, file] of new Map(
538
+ appImports(cwd, cfg)
539
+ .toReversed()
540
+ .map(([s, f]) => [s, f]),
541
+ )) {
542
+ for (const peer of SUBPATH_REQUIRED_PEERS[sub] ?? []) {
543
+ if (installedVersion(cwd, peer) !== null) continue
544
+ missing.set(peer, [...(missing.get(peer) ?? []), `basalt-ui/${sub} (${file})`])
545
+ }
546
+ }
547
+ if (missing.size === 0) return null
548
+ const ranges = peerRanges(dir)
549
+ const named = [...missing].map(([peer, by]) => `${peer} for ${by.join(', ')}`)
550
+ const add = [...missing.keys()].map((peer) => (ranges[peer] ? `${peer}@${ranges[peer]}` : peer))
551
+ return {
552
+ fail: `${id}: peers a used basalt-ui subpath requires are not installed: ${named.join('; ')}. Fix: \`bun add ${add.join(' ')}\`.`,
553
+ }
554
+ })
555
+ }
package/src/cli/doctor.ts CHANGED
@@ -6,7 +6,6 @@
6
6
  import { existsSync } from 'node:fs'
7
7
  import { relative, resolve } from 'node:path'
8
8
 
9
- import type { BasaltConfig } from './config'
10
9
  import {
11
10
  AGENTS_MD,
12
11
  LEGACY_BLOCK_HOST,
@@ -26,6 +25,7 @@ import {
26
25
  readBasaltConfig,
27
26
  readIfExists,
28
27
  readManifest,
28
+ readPackageJson,
29
29
  resolveAppDir,
30
30
  resolveProjectDir,
31
31
  ROUTER_SEED_DESTS,
@@ -40,6 +40,7 @@ import {
40
40
  droppedSubpathsCheck,
41
41
  exactPeersCheck,
42
42
  retiredLintRulesCheck,
43
+ subpathPeersCheck,
43
44
  tsconfigBaseCheck,
44
45
  unknownConfigKeysCheck,
45
46
  } from './doctor-upgrade'
@@ -85,32 +86,13 @@ type AiMajorField = (typeof AI_MAJOR_FIELDS)[number]
85
86
 
86
87
  /** The `ai` major per dependency field of THIS package.json (not walked across workspaces). */
87
88
  function aiMajorsAt(dir: string): Partial<Record<AiMajorField, number>> {
88
- const raw = readIfExists(resolve(dir, 'package.json'))
89
- if (raw === null) return {}
90
- try {
91
- const pkg = JSON.parse(raw) as Partial<Record<AiMajorField, Record<string, string>>>
92
- const out: Partial<Record<AiMajorField, number>> = {}
93
- for (const field of AI_MAJOR_FIELDS) {
94
- const major = majorOf(pkg[field]?.['ai'])
95
- if (major !== null) out[field] = major
96
- }
97
- return out
98
- } catch {
99
- return {}
100
- }
101
- }
102
-
103
- /** `basalt.aiMajorSkewReason` as a validated reason, plus whether the key was present but invalid. */
104
- function resolveAiMajorSkewReason(cfg: BasaltConfig): {
105
- reason: string | null
106
- presentButInvalid: boolean
107
- } {
108
- const raw = cfg.aiMajorSkewReason
109
- if (raw === undefined) return { reason: null, presentButInvalid: false }
110
- if (typeof raw === 'string' && raw.trim().length > 0) {
111
- return { reason: raw, presentButInvalid: false }
89
+ const pkg = readPackageJson<Partial<Record<AiMajorField, Record<string, string>>>>(dir) ?? {}
90
+ const out: Partial<Record<AiMajorField, number>> = {}
91
+ for (const field of AI_MAJOR_FIELDS) {
92
+ const major = majorOf(pkg[field]?.['ai'])
93
+ if (major !== null) out[field] = major
112
94
  }
113
- return { reason: null, presentButInvalid: true }
95
+ return out
114
96
  }
115
97
 
116
98
  /**
@@ -124,8 +106,8 @@ function resolveAiMajorSkewReason(cfg: BasaltConfig): {
124
106
  * 4. `oxlint-preset`: `.oxlintrc.json` extends the shipped preset AND that path resolves.
125
107
  * 7. `ai-major-parity`: the `ai` major agrees across this package.json's dependency fields
126
108
  * (exempt via `basalt.aiMajorSkewReason`; a stale reason warns).
127
- * 8-13. `tsconfig-base`, `retired-lint-rules`, `dropped-subpaths`, `app-wiring`, `exact-peers`,
128
- * `config-keys` (./doctor-upgrade);
109
+ * 8-14. `tsconfig-base`, `retired-lint-rules`, `dropped-subpaths`, `app-wiring`, `exact-peers`,
110
+ * `subpath-peers`, `config-keys` (./doctor-upgrade);
129
111
  * a check that cannot run is SKIPPED and exits non-zero.
130
112
  *
131
113
  * Warning (non-fatal):
@@ -153,21 +135,10 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
153
135
  const result: DoctorResult = { hardFailures: 0, warnings: 0, skipped: 0 }
154
136
  const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
155
137
 
156
- function pass(msg: string): void {
157
- lines.push(` ✓ ${msg}`)
158
- }
159
- function warn(msg: string): void {
160
- lines.push(` ⚠ ${msg}`)
161
- result.warnings++
162
- }
163
- function fail(msg: string): void {
164
- lines.push(` ✖ ${msg}`)
165
- result.hardFailures++
166
- }
167
- function skip(msg: string): void {
168
- lines.push(` ? SKIPPED ${msg}`)
169
- result.skipped++
170
- }
138
+ const pass = (msg: string): number => lines.push(` ✓ ${msg}`)
139
+ const warn = (msg: string): number => lines.push(` ⚠ ${msg}`) && result.warnings++
140
+ const fail = (msg: string): number => lines.push(` ✖ ${msg}`) && result.hardFailures++
141
+ const skip = (msg: string): number => lines.push(` ? SKIPPED ${msg}`) && result.skipped++
171
142
 
172
143
  if (project.relocatedFrom !== null) {
173
144
  lines.push(` → BASALT_CWD relocated from ${project.relocatedFrom} to ${cwd}.\n`)
@@ -368,8 +339,11 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
368
339
  const aiEntries = AI_MAJOR_FIELDS.filter((field) => aiMajors[field] !== undefined).map(
369
340
  (field) => ({ field, major: aiMajors[field] as number }),
370
341
  )
371
- const { reason: aiMajorSkewReason, presentButInvalid: aiMajorSkewReasonInvalid } =
372
- resolveAiMajorSkewReason(cfg)
342
+ // `basalt.aiMajorSkewReason`: a non-blank string exempts a skew; any other present value is invalid.
343
+ const rawSkewReason = cfg.aiMajorSkewReason
344
+ const aiMajorSkewReason =
345
+ typeof rawSkewReason === 'string' && rawSkewReason.trim().length > 0 ? rawSkewReason : null
346
+ const aiMajorSkewReasonInvalid = aiMajorSkewReason === null && rawSkewReason !== undefined
373
347
  if (aiEntries.length > 0) {
374
348
  const distinctMajors = new Set(aiEntries.map((entry) => entry.major))
375
349
  if (distinctMajors.size > 1) {
@@ -428,6 +402,10 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
428
402
  appWiringCheck(appDir),
429
403
  ],
430
404
  ['exact-peers: installed exact-pinned peers match basalt-ui', exactPeersCheck(cwd, install)],
405
+ [
406
+ 'subpath-peers: every imported basalt-ui subpath has its required peers installed',
407
+ subpathPeersCheck(cwd, cfg, install),
408
+ ],
431
409
  [
432
410
  'config-keys: the basalt config block sets only keys basalt-ui reads',
433
411
  unknownConfigKeysCheck(cwd),