basalt-ui 2.8.0 → 2.9.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/AGENTS.md +2 -2
- package/CHANGELOG.md +209 -189
- package/MIGRATING.md +98 -28
- package/README.md +7 -8
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/templates/AGENTS-block.md.tpl +2 -2
- package/configs/oxlint-plugin.js +25 -68
- package/configs/oxlint-plugin.test.ts +19 -27
- package/dist/charts/BandStrip.d.ts +1 -1
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +1 -10
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +2 -9
- package/dist/charts/band-fold.d.ts +15 -0
- package/dist/charts/band-fold.d.ts.map +1 -0
- package/dist/charts/band-fold.js +19 -0
- package/dist/charts/index.d.ts +1 -0
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/index.js +3 -1
- package/dist/cli/audit-allows.d.ts.map +1 -1
- package/dist/cli/audit-allows.js +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +4 -1
- package/dist/cli/config.d.ts +4 -4
- package/dist/cli/doctor-upgrade.d.ts +5 -4
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +23 -99
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +23 -25
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -3
- package/dist/cli/index.d.ts +15 -6
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +16 -27
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +9 -6
- package/dist/cli/install-root.d.ts +10 -0
- package/dist/cli/install-root.d.ts.map +1 -0
- package/dist/cli/install-root.js +32 -0
- package/dist/cli/router-wiring.d.ts +37 -0
- package/dist/cli/router-wiring.d.ts.map +1 -0
- package/dist/cli/router-wiring.js +116 -0
- package/dist/cli/source-text.d.ts +12 -0
- package/dist/cli/source-text.d.ts.map +1 -0
- package/dist/cli/source-text.js +46 -0
- package/dist/cli/sync.d.ts +0 -2
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +23 -21
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +1 -6
- package/dist/common/errors.d.ts +1 -6
- package/dist/common/errors.d.ts.map +1 -1
- package/dist/common/errors.js +0 -7
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -9
- package/dist/common/props.d.ts +2 -2
- package/dist/common/vx-family.d.ts +1 -1
- package/dist/content/code-block.d.ts.map +1 -1
- package/dist/content/code-block.js +36 -27
- package/dist/content/code-block.module.css +19 -1
- package/dist/content/mermaid-sanitize.d.ts +15 -0
- package/dist/content/mermaid-sanitize.d.ts.map +1 -0
- package/dist/content/mermaid-sanitize.js +28 -0
- package/dist/content/mermaid.d.ts +6 -0
- package/dist/content/mermaid.d.ts.map +1 -1
- package/dist/content/mermaid.js +3 -1
- package/dist/content/toc-click-pin.d.ts +45 -0
- package/dist/content/toc-click-pin.d.ts.map +1 -0
- package/dist/content/toc-click-pin.js +111 -0
- package/dist/content/toc-spy.d.ts +25 -0
- package/dist/content/toc-spy.d.ts.map +1 -0
- package/dist/content/toc-spy.js +43 -0
- package/dist/content/toc.d.ts +1 -4
- package/dist/content/toc.d.ts.map +1 -1
- package/dist/content/toc.js +38 -49
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +1 -1
- package/dist/dashboard/index.d.ts +1 -1
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +1 -3
- package/dist/dashboard/section.d.ts +10 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +20 -3
- package/dist/dashboard/stat-card.d.ts +2 -8
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +1 -1
- package/dist/guard/index.d.ts +13 -9
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +74 -37
- package/dist/guard/types.d.ts +8 -7
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +1 -33
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +3 -2
- package/dist/router-tanstack/search-store.d.ts +1 -11
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +1 -2
- package/dist/shell/index.d.ts +1 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +3 -0
- package/dist/shell/nav-types.d.ts +1 -1
- package/dist/shell/page-bar.d.ts +6 -0
- package/dist/shell/page-bar.d.ts.map +1 -1
- package/dist/shell/page-bar.js +12 -2
- package/dist/state/fields.d.ts +1 -1
- package/dist/state/fields.d.ts.map +1 -1
- package/dist/state/fields.js +3 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +5 -11
- package/dist/table/data-table.d.ts +2 -2
- package/dist/tokens/core.d.ts +0 -10
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -44
- package/dist/vite-boot.d.ts +25 -0
- package/dist/vite-boot.d.ts.map +1 -0
- package/dist/vite-boot.js +36 -0
- package/dist/vite.d.ts +24 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +7 -16
- package/llms.txt +26 -9
- package/package.json +8 -5
- package/src/charts/BandStrip.tsx +4 -16
- package/src/charts/MirroredBars.tsx +2 -11
- package/src/charts/band-fold.ts +26 -0
- package/src/charts/index.ts +1 -0
- package/src/cli/audit-allows.ts +1 -3
- package/src/cli/check-theme.ts +7 -1
- package/src/cli/config.ts +4 -4
- package/src/cli/doctor-upgrade.ts +29 -145
- package/src/cli/doctor.ts +25 -31
- package/src/cli/help.ts +1 -4
- package/src/cli/index.ts +27 -43
- package/src/cli/init.ts +9 -6
- package/src/cli/install-root.ts +40 -0
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +26 -22
- package/src/cli/tokens-css.ts +0 -5
- package/src/common/errors.ts +1 -18
- package/src/common/index.ts +1 -8
- package/src/common/props.ts +2 -2
- package/src/common/vx-family.ts +1 -1
- package/src/content/code-block.module.css +19 -1
- package/src/content/code-block.tsx +7 -2
- package/src/content/mermaid-sanitize.ts +49 -0
- package/src/content/mermaid.tsx +3 -2
- package/src/content/toc-click-pin.ts +156 -0
- package/src/content/toc-spy.ts +61 -0
- package/src/content/toc.tsx +47 -95
- package/src/controls/form-layout.tsx +1 -1
- package/src/controls/number-filter.tsx +6 -1
- package/src/dashboard/index.ts +1 -6
- package/src/dashboard/section.tsx +39 -8
- package/src/dashboard/stat-card.tsx +4 -11
- package/src/guard/index.ts +114 -89
- package/src/guard/types.ts +8 -7
- package/src/guard/vx-names.ts +1 -33
- package/src/index.ts +1 -2
- package/src/provider/index.tsx +6 -3
- package/src/router-tanstack/search-store.ts +2 -14
- package/src/shell/index.tsx +2 -0
- package/src/shell/nav-types.ts +1 -1
- package/src/shell/page-bar.tsx +21 -2
- package/src/state/fields.ts +7 -2
- package/src/surfaces.ts +5 -11
- package/src/table/data-table.tsx +2 -2
- package/src/tokens/core.ts +6 -67
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
- package/dist/tokens.css +0 -331
package/src/charts/BandStrip.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* `BandStrip` — a 1-D state strip: one gap-free band per slot over the shared x axis, no y
|
|
3
3
|
* dimension (`docs/V2-SPEC.md` § 9.3). Each band is in one of the `states`, tinted by the state's
|
|
4
4
|
* color (or an intensity `fill` of the datum's own), optionally carrying an inset `marker`.
|
|
5
|
-
* Absence is a state like any other: color
|
|
5
|
+
* Absence is a state like any other: a flat, unhatched fill whose color differs from every measured state's, not only by alpha. Name it
|
|
6
6
|
* with `absentState` and a folded band can carry an `absentFraction` share of it.
|
|
7
7
|
*
|
|
8
8
|
* The rung supplies the legend, cursor, crosshair and tooltip. The visible bands are decorative
|
|
@@ -19,6 +19,8 @@ import { oneOf, requiredProp } from '../common/errors'
|
|
|
19
19
|
import { NON_FINITE } from '../format/shared'
|
|
20
20
|
import { VX, alpha } from '../tokens'
|
|
21
21
|
import { CartesianRung } from './CartesianChart'
|
|
22
|
+
import { groupsOf } from './band-fold'
|
|
23
|
+
import type { Group } from './band-fold'
|
|
22
24
|
import { emphasis } from './marks'
|
|
23
25
|
import { rowX } from './types'
|
|
24
26
|
import type {
|
|
@@ -92,7 +94,7 @@ export type BandStripProps<T, X extends ChartX = ChartX> = Omit<
|
|
|
92
94
|
/**
|
|
93
95
|
* The `states` key that means "not measured". A band in it is flat-filled like any state; a
|
|
94
96
|
* band in another state paints its `absentFraction` share in this state's color, and the
|
|
95
|
-
* tooltip adds this state's row. Absent stays a legended, flat
|
|
97
|
+
* tooltip adds this state's row. Absent stays a legended, flat state, never a
|
|
96
98
|
* hatch: it reads as "no data" by hue and by sitting at the band's right edge, not as zero.
|
|
97
99
|
*/
|
|
98
100
|
absentState?: string | undefined
|
|
@@ -117,23 +119,9 @@ const UNKNOWN_FILL = alpha(VX.neutral, 0.2)
|
|
|
117
119
|
type Cell = { f0: number; f1: number; y0: number; y1: number }
|
|
118
120
|
/** Cells sharing one paint: a `rect` mark takes a constant fill and opacity. */
|
|
119
121
|
type Layer = { fill: string; opacity: number; cells: Cell[] }
|
|
120
|
-
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
121
|
-
type Group<T> = { start: number; items: T[] }
|
|
122
122
|
/** A slot that answers the pointer: its own source datum, and the (possibly merged) one it reads. */
|
|
123
123
|
type Hit<T> = { slot: number; source: T; state: string; datum: T }
|
|
124
124
|
|
|
125
|
-
/** Adjacent data in groups of equal size, the last possibly shorter, at most `cap` groups. */
|
|
126
|
-
function groupsOf<T>(data: readonly T[], cap: number): Group<T>[] {
|
|
127
|
-
const size = Math.max(1, Math.ceil(data.length / Math.max(cap, 1)))
|
|
128
|
-
const out: Group<T>[] = []
|
|
129
|
-
data.forEach((d, i) => {
|
|
130
|
-
const last = out.at(-1)
|
|
131
|
-
if (last && last.items.length < size) last.items.push(d)
|
|
132
|
-
else out.push({ start: i, items: [d] })
|
|
133
|
-
})
|
|
134
|
-
return out
|
|
135
|
-
}
|
|
136
|
-
|
|
137
125
|
/** Appends a cell to the layer with this paint, creating it in first-use order. */
|
|
138
126
|
function paintInto(layers: Map<string, Layer>, fill: string, opacity: number, cell: Cell): void {
|
|
139
127
|
const key = `${fill}|${opacity}`
|
|
@@ -26,6 +26,7 @@ import { barMark, emphasis } from './marks'
|
|
|
26
26
|
import { PanelRung, chartHeightOf, paneX, paneY, rowsOf } from './panel'
|
|
27
27
|
import type { PaneBuilder, PanelInput, PanelPlan } from './panel'
|
|
28
28
|
import { xScaleFor } from './scales'
|
|
29
|
+
import { foldBands } from './band-fold'
|
|
29
30
|
import { rowX } from './types'
|
|
30
31
|
import type { CartesianChartProps, ChartSeries, ChartX, PlotRow } from './types'
|
|
31
32
|
|
|
@@ -95,16 +96,6 @@ const BAND_FILL = 0.8
|
|
|
95
96
|
const clamp01 = (v: number | undefined): number =>
|
|
96
97
|
v === undefined || !Number.isFinite(v) ? 0 : Math.min(Math.max(v, 0), 1)
|
|
97
98
|
|
|
98
|
-
/** At most `cap` slots: adjacent data merged in equal runs. */
|
|
99
|
-
function fold<T>(data: readonly T[], cap: number, merge: (group: T[]) => T): T[] {
|
|
100
|
-
if (cap <= 0) return []
|
|
101
|
-
if (data.length <= cap) return [...data]
|
|
102
|
-
const size = Math.ceil(data.length / cap)
|
|
103
|
-
const out: T[] = []
|
|
104
|
-
for (let i = 0; i < data.length; i += size) out.push(merge(data.slice(i, i + size)))
|
|
105
|
-
return out
|
|
106
|
-
}
|
|
107
|
-
|
|
108
99
|
/** One pane's upper bound; `|| 1` guards a window with no traffic (a zero-width domain is NaN). */
|
|
109
100
|
function paneMax<T>(pane: MirroredBarPane, s: ChartSeries<T>, data: readonly T[], on: boolean) {
|
|
110
101
|
if (pane.max !== undefined && pane.max !== 'auto') return pane.max || 1
|
|
@@ -149,7 +140,7 @@ export function MirroredBars<T, X extends ChartX = ChartX>(
|
|
|
149
140
|
const upSeries = assertPaneKey('up', up.key, bars)
|
|
150
141
|
const downSeries = assertPaneKey('down', down.key, bars)
|
|
151
142
|
const drawn = foldConfig
|
|
152
|
-
?
|
|
143
|
+
? foldBands(
|
|
153
144
|
data,
|
|
154
145
|
Math.floor(width / (foldConfig.minBandPx ?? DEFAULT_MIN_BAND_PX)),
|
|
155
146
|
foldConfig.merge,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A run of adjacent slots drawn as one band; `items` are the source data it stands for. */
|
|
2
|
+
export type Group<T> = { start: number; items: T[] }
|
|
3
|
+
|
|
4
|
+
/** Adjacent data in groups of equal size, the last possibly shorter, at most `cap` groups. */
|
|
5
|
+
export function groupsOf<T>(data: readonly T[], cap: number): Group<T>[] {
|
|
6
|
+
const size = Math.max(1, Math.ceil(data.length / Math.max(cap, 1)))
|
|
7
|
+
const out: Group<T>[] = []
|
|
8
|
+
data.forEach((d, i) => {
|
|
9
|
+
const last = out.at(-1)
|
|
10
|
+
if (last && last.items.length < size) last.items.push(d)
|
|
11
|
+
else out.push({ start: i, items: [d] })
|
|
12
|
+
})
|
|
13
|
+
return out
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The width-driven fold `BandStrip` and `MirroredBars` run: at most `cap` slots, adjacent data
|
|
18
|
+
* merged in equal runs by the consumer's `merge` (a lone datum passes through unmerged). Exported
|
|
19
|
+
* so a consumer can test its `merge` against the real grouping; `cap` is
|
|
20
|
+
* `floor(width / minBandPx)`.
|
|
21
|
+
*/
|
|
22
|
+
export function foldBands<T>(data: readonly T[], cap: number, merge: (group: T[]) => T): T[] {
|
|
23
|
+
if (cap <= 0) return []
|
|
24
|
+
if (data.length <= cap) return [...data]
|
|
25
|
+
return groupsOf(data, cap).map((g) => merge(g.items))
|
|
26
|
+
}
|
package/src/charts/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export {
|
|
|
17
17
|
type BandSpan,
|
|
18
18
|
type BandFold,
|
|
19
19
|
} from './BandStrip'
|
|
20
|
+
export { foldBands } from './band-fold'
|
|
20
21
|
export { Donut, type DonutProps, type DonutDatum } from './Donut'
|
|
21
22
|
export { Heatmap, type HeatmapProps } from './Heatmap'
|
|
22
23
|
export { DualPanel, type DualPanelProps, type DualPanelLine, type DualPanelBar } from './DualPanel'
|
package/src/cli/audit-allows.ts
CHANGED
|
@@ -215,9 +215,7 @@ export function auditAllows(
|
|
|
215
215
|
slot: waiverLines.length,
|
|
216
216
|
rel,
|
|
217
217
|
line: site.line,
|
|
218
|
-
reach: site.
|
|
219
|
-
? 'a bare annotation, waiving every oxlint plugin rule on its line'
|
|
220
|
-
: `scoped to ${site.oxlintRules.join(', ')}, which oxlint judges`,
|
|
218
|
+
reach: `scoped to ${site.oxlintRules.join(', ')}, which oxlint judges`,
|
|
221
219
|
site: label,
|
|
222
220
|
suffix,
|
|
223
221
|
})
|
package/src/cli/check-theme.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { dirname, resolve } from 'node:path'
|
|
|
9
9
|
import {
|
|
10
10
|
checkSource,
|
|
11
11
|
guardKindRemedy,
|
|
12
|
+
REMOVED_VX_NAMES,
|
|
12
13
|
TOKENS_ONLY_DISABLED_KINDS,
|
|
13
14
|
unmatchedExemptPatterns,
|
|
14
15
|
} from '../guard'
|
|
@@ -189,7 +190,12 @@ export function checkTheme(
|
|
|
189
190
|
for (const [file, vs] of [...byFile].toSorted()) {
|
|
190
191
|
console.error(file)
|
|
191
192
|
for (const v of vs.toSorted((a, b) => a.line - b.line)) {
|
|
192
|
-
|
|
193
|
+
const replacement = v.kind === 'unknown-vx-token' ? REMOVED_VX_NAMES[v.token] : undefined
|
|
194
|
+
const hint =
|
|
195
|
+
replacement === undefined
|
|
196
|
+
? ''
|
|
197
|
+
: ` [${v.token} → ${replacement ?? 'deleted, no replacement'}]`
|
|
198
|
+
console.error(` ${String(v.line).padStart(4)} ${v.kind.padEnd(22)} ${v.text}${hint}`)
|
|
193
199
|
}
|
|
194
200
|
console.error('')
|
|
195
201
|
}
|
package/src/cli/config.ts
CHANGED
|
@@ -130,8 +130,8 @@ export type BasaltConfig = {
|
|
|
130
130
|
seriesModulePath?: string
|
|
131
131
|
/**
|
|
132
132
|
* Per-rule, per-path exemptions, complementing whole-file `exempt`. A pattern is matched against a
|
|
133
|
-
* finding's relative path: a path
|
|
134
|
-
* `src/agenting.ts`),
|
|
133
|
+
* finding's relative path: a relative path (`'public/site.webmanifest'`), a
|
|
134
|
+
* directory prefix (`'src/agent'` matches `src/agent/x.tsx`, not `src/agenting.ts`), or a glob (`*` stops at `/`, `**` does
|
|
135
135
|
* not; a slash-free glob also matches the basename). An entry that suppresses nothing is reported
|
|
136
136
|
* and `check-theme --audit-allows` exits 1 on it. Default: `{}`.
|
|
137
137
|
*
|
|
@@ -139,9 +139,9 @@ export type BasaltConfig = {
|
|
|
139
139
|
* `.webmanifest` finding's only escape is this key), which `--audit-allows` prints.
|
|
140
140
|
*
|
|
141
141
|
* @example
|
|
142
|
-
* { exemptRules: { 'inline-display': ['agent'] } } // inline-display never fires under src/agent/**
|
|
142
|
+
* { exemptRules: { 'inline-display': ['src/agent'] } } // inline-display never fires under src/agent/**
|
|
143
143
|
* @example
|
|
144
|
-
* { exemptRules: { 'raw-hex': { paths: ['site.webmanifest'],
|
|
144
|
+
* { exemptRules: { 'raw-hex': { paths: ['public/site.webmanifest'],
|
|
145
145
|
* reason: 'a PWA manifest theme_color MUST be a literal hex — JSON cannot reference a CSS var' } } }
|
|
146
146
|
*/
|
|
147
147
|
exemptRules?: Partial<Record<GuardKind, ExemptRuleEntry>>
|
|
@@ -2,21 +2,23 @@
|
|
|
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 {
|
|
5
|
+
import { 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, routerSeedDest, scannableFiles } from './index'
|
|
12
|
+
import type { BasaltInstall } from './index'
|
|
11
13
|
import {
|
|
14
|
+
appEntry,
|
|
15
|
+
hasRouteTree,
|
|
16
|
+
hasRouter,
|
|
17
|
+
isCodeRoutedApp,
|
|
12
18
|
isStartApp,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
routerSeedDest,
|
|
17
|
-
scannableFiles,
|
|
18
|
-
} from './index'
|
|
19
|
-
import type { BasaltInstall } from './index'
|
|
19
|
+
routeTreeDirs,
|
|
20
|
+
} from './router-wiring'
|
|
21
|
+
import { readIfExists, readPackageJson, tokenize } from './source-text'
|
|
20
22
|
|
|
21
23
|
export type Check = { fail: string } | { skip: string } | null
|
|
22
24
|
|
|
@@ -190,14 +192,6 @@ export function retiredLintRulesCheck(cwd: string, install: BasaltInstall): Chec
|
|
|
190
192
|
})
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
/**
|
|
194
|
-
* Strings and template literals (captured) and comments. Known, accepted gap: a regex literal that
|
|
195
|
-
* contains a quote (`/'/`) opens a string this tokenizer never closes, which can blank or hide code
|
|
196
|
-
* after it on that line; a template literal nested inside a `${…}` is not tracked either.
|
|
197
|
-
*/
|
|
198
|
-
const TOKEN =
|
|
199
|
-
/("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|\/\/[^\n]*|\/\*[\s\S]*?\*\//g
|
|
200
|
-
|
|
201
195
|
/**
|
|
202
196
|
* A `basalt-ui/<subpath>` specifier in statement position: `import … from`, `import type … from`
|
|
203
197
|
* (also split over lines), `export … from`, bare `import '…'`, `import('…')` and `require('…')`
|
|
@@ -206,24 +200,6 @@ const TOKEN =
|
|
|
206
200
|
const SUBPATH_IMPORT =
|
|
207
201
|
/(?:(?:^|;)[ \t]*(?:(?:import|export)\b[^'"`;]*?\bfrom|import)\s*|(?<![.\w$])(?:import|require)\s*\(\s*)(['"])basalt-ui\/([^'"]+)\1/gm
|
|
208
202
|
|
|
209
|
-
/** Source with comments blanked (and template text), plus a test for "offset sits inside a string". */
|
|
210
|
-
function tokenize(src: string): { code: string; inLiteral: (at: number) => boolean } {
|
|
211
|
-
const literals: [number, number][] = []
|
|
212
|
-
const code = src.replace(TOKEN, (m, literal: string | undefined, at: number) => {
|
|
213
|
-
if (literal === undefined) return m.replace(/[^\n]/g, ' ')
|
|
214
|
-
if (!literal.startsWith('`')) {
|
|
215
|
-
literals.push([at, at + m.length])
|
|
216
|
-
return m
|
|
217
|
-
}
|
|
218
|
-
// Template literal: blank the text, keep the delimiters and the `${…}` code scannable.
|
|
219
|
-
return m.replace(
|
|
220
|
-
/(\$\{[^}]*\})|[^\n`]/g,
|
|
221
|
-
(c, interpolation: string | undefined) => interpolation ?? ' ',
|
|
222
|
-
)
|
|
223
|
-
})
|
|
224
|
-
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) }
|
|
225
|
-
}
|
|
226
|
-
|
|
227
203
|
/** `[subpath, line]` per `basalt-ui/<subpath>` import that sits in code, not in a comment or literal. */
|
|
228
204
|
function basaltImports(src: string): [string, number][] {
|
|
229
205
|
const { code, inLiteral } = tokenize(src)
|
|
@@ -386,99 +362,11 @@ export function seedTsconfigExtends(cwd: string): string | null {
|
|
|
386
362
|
return `added "extends": "${TSCONFIG_PRESET_ID}" to ${name}.`
|
|
387
363
|
}
|
|
388
364
|
|
|
389
|
-
const VITE_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vite.config.${e}`)
|
|
390
365
|
const SEED_HINT = 'node_modules/basalt-ui/agent/templates/main.tpl'
|
|
391
366
|
const ROUTER_PLUGIN_FIX =
|
|
392
367
|
"Fix: `bun add -D @tanstack/router-plugin`, add `tanstackRouter({ target: 'react', autoCodeSplitting: true })` " +
|
|
393
368
|
"from '@tanstack/router-plugin/vite' to `plugins` in vite.config.ts (before react()), then run vite once " +
|
|
394
|
-
'to generate src/routeTree.gen.ts.'
|
|
395
|
-
|
|
396
|
-
/** The first local `<script type="module" src>` in index.html (comments and remote src skipped). */
|
|
397
|
-
function htmlEntry(html: string): string | undefined {
|
|
398
|
-
for (const [, attrs = ''] of html
|
|
399
|
-
.replace(/<!--[\s\S]*?-->/g, '')
|
|
400
|
-
.matchAll(/<script\b([^>]*)>/gi)) {
|
|
401
|
-
const src = /\bsrc\s*=\s*["']?([^"'\s>]+)/i.exec(attrs)?.[1]
|
|
402
|
-
if (
|
|
403
|
-
/\btype\s*=\s*["']?module\b/i.test(attrs) &&
|
|
404
|
-
src !== undefined &&
|
|
405
|
-
!/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(src)
|
|
406
|
-
) {
|
|
407
|
-
return src
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return undefined
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/** True when `code` calls a binding imported from `@tanstack/router-plugin` inside `plugins`. */
|
|
414
|
-
function registersRouterPlugin(src: string): boolean {
|
|
415
|
-
const { code, inLiteral } = tokenize(src)
|
|
416
|
-
const pluginsAt = [...code.matchAll(/\bplugins\b/g)].find((m) => !inLiteral(m.index))?.index
|
|
417
|
-
if (pluginsAt === undefined) return false
|
|
418
|
-
const imports = code.matchAll(
|
|
419
|
-
/(?:^|;)[ \t]*import\s+(?:type\s+)?([^'"`;]*?)\s*from\s*(['"])@tanstack\/router-plugin(?:\/[^'"]*)?\2/gm,
|
|
420
|
-
)
|
|
421
|
-
return [...imports].some((m) => {
|
|
422
|
-
if (inLiteral(m.index)) return false
|
|
423
|
-
const names = (m[1] ?? '')
|
|
424
|
-
.replace(/[{}]/g, '')
|
|
425
|
-
.split(',')
|
|
426
|
-
.map((part) => part.trim())
|
|
427
|
-
.filter((part) => part !== '' && !/^type\s/.test(part))
|
|
428
|
-
.map((part) => part.split(/\s+as\s+/).pop() as string)
|
|
429
|
-
return names.some((name) =>
|
|
430
|
-
[
|
|
431
|
-
...code.matchAll(
|
|
432
|
-
new RegExp(`(?<![.\\w$])${name.replace(/\$/g, '\\$')}(?:\\.\\w+)?\\s*\\(`, 'g'),
|
|
433
|
-
),
|
|
434
|
-
].some((call) => call.index > pluginsAt && !inLiteral(call.index)),
|
|
435
|
-
)
|
|
436
|
-
})
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const RELATIVE_IMPORT =
|
|
440
|
-
/(?:\b(?:import|export)\b[^'";]*?\bfrom|\bimport)\s*['"](\.{1,2}\/[^'"]+)['"]/g
|
|
441
|
-
|
|
442
|
-
/** The source file a relative specifier names: as written, `.ts`/`.tsx` appended, or a directory index. */
|
|
443
|
-
function resolveRelative(from: string, spec: string): string | null {
|
|
444
|
-
const base = resolve(dirname(from), spec.replace(/\.[jt]sx?$/, ''))
|
|
445
|
-
return (
|
|
446
|
-
[
|
|
447
|
-
resolve(dirname(from), spec),
|
|
448
|
-
`${base}.ts`,
|
|
449
|
-
`${base}.tsx`,
|
|
450
|
-
`${base}/index.ts`,
|
|
451
|
-
`${base}/index.tsx`,
|
|
452
|
-
].find((f) => /\.[jt]sx?$/.test(f) && existsSync(f)) ?? null
|
|
453
|
-
)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Whether a module the entry imports (relative imports, three deep) calls `createBasaltRouter` —
|
|
458
|
-
* the router often lives in a singleton module other code also imports.
|
|
459
|
-
*/
|
|
460
|
-
function routerCreatedInImports(cwd: string, entry: string): boolean {
|
|
461
|
-
const seen = new Set([resolve(cwd, entry)])
|
|
462
|
-
let frontier = [...seen]
|
|
463
|
-
for (let depth = 0; depth < 3 && frontier.length > 0; depth++) {
|
|
464
|
-
const next: string[] = []
|
|
465
|
-
for (const file of frontier) {
|
|
466
|
-
for (const m of (readIfExists(file) ?? '').matchAll(RELATIVE_IMPORT)) {
|
|
467
|
-
const dep = resolveRelative(file, m[1] ?? '')
|
|
468
|
-
if (dep === null || seen.has(dep)) continue
|
|
469
|
-
seen.add(dep)
|
|
470
|
-
const { code, inLiteral } = tokenize(readIfExists(dep) ?? '')
|
|
471
|
-
const called = [...code.matchAll(/\bcreateBasaltRouter\b/g)].some(
|
|
472
|
-
(c) => !inLiteral(c.index),
|
|
473
|
-
)
|
|
474
|
-
if (called) return true
|
|
475
|
-
next.push(dep)
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
frontier = next
|
|
479
|
-
}
|
|
480
|
-
return false
|
|
481
|
-
}
|
|
369
|
+
'to generate src/routeTree.gen.ts — or define the tree in code (`createRootRoute` + `createRoute`), drop the routeTree.gen import and pass the tree to createBasaltRouter.'
|
|
482
370
|
|
|
483
371
|
/** True when `{` at `i` opens a `{...spread}`: sticky, so any whitespace width is read. */
|
|
484
372
|
function isSpreadAt(code: string, i: number): boolean {
|
|
@@ -565,28 +453,30 @@ export function startWiringWarnings(cwd: string): string[] {
|
|
|
565
453
|
|
|
566
454
|
/**
|
|
567
455
|
* `app-wiring`: the entry module `index.html` loads (default src/main.tsx) mounts `BasaltProvider`
|
|
568
|
-
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree
|
|
569
|
-
* binding imported from `@tanstack/router-plugin`
|
|
570
|
-
* beside the entry (or in src/)
|
|
571
|
-
*
|
|
456
|
+
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree
|
|
457
|
+
* exists: the vite config calls a binding imported from `@tanstack/router-plugin` (after its
|
|
458
|
+
* `plugins` key), a `routeTree.gen.*` sits beside the entry (or in src/), or the app is code-routed
|
|
459
|
+
* (`isCodeRoutedApp`, the same predicate `init` and `sync` use). `basaltViteConfig` does not
|
|
460
|
+
* register the plugin, so naming it proves nothing.
|
|
572
461
|
*/
|
|
573
462
|
export function appWiringCheck(cwd: string): Check {
|
|
574
463
|
return guarded('app-wiring', () => {
|
|
575
464
|
if (isStartApp(cwd, '')) return startWiring(cwd)
|
|
576
|
-
const entry = (
|
|
577
|
-
htmlEntry(readIfExists(resolve(cwd, 'index.html')) ?? '') ?? 'src/main.tsx'
|
|
578
|
-
).replace(/^\//, '')
|
|
465
|
+
const entry = appEntry(cwd)
|
|
579
466
|
const text = readIfExists(resolve(cwd, entry))
|
|
580
467
|
if (text === null) {
|
|
581
468
|
return { fail: `app-wiring: ${entry} does not exist. Fix: make it match ${SEED_HINT}.` }
|
|
582
469
|
}
|
|
583
|
-
const
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
470
|
+
const tokens = tokenize(text)
|
|
471
|
+
const { code, inLiteral } = tokens
|
|
472
|
+
const wired: [string, boolean][] = [
|
|
473
|
+
[
|
|
474
|
+
'BasaltProvider',
|
|
475
|
+
[...code.matchAll(/\bBasaltProvider\b/g)].some((m) => !inLiteral(m.index)),
|
|
476
|
+
],
|
|
477
|
+
['createBasaltRouter', hasRouter(cwd, entry, tokens)],
|
|
478
|
+
]
|
|
479
|
+
const missing = wired.filter(([, present]) => !present).map(([name]) => name)
|
|
590
480
|
if (missing.length > 0) {
|
|
591
481
|
return {
|
|
592
482
|
fail:
|
|
@@ -594,15 +484,9 @@ export function appWiringCheck(cwd: string): Check {
|
|
|
594
484
|
`Fix: make it match ${SEED_HINT} (\`init\` seeds it only when the file is absent).`,
|
|
595
485
|
}
|
|
596
486
|
}
|
|
597
|
-
|
|
598
|
-
VITE_CONFIGS.map((f) => readIfExists(resolve(cwd, f))).find((t) => t !== null) ?? ''
|
|
599
|
-
const dirs = [...new Set([dirname(entry), 'src'])]
|
|
600
|
-
const generated = dirs.some((d) =>
|
|
601
|
-
['ts', 'tsx', 'js'].some((e) => existsSync(resolve(cwd, d, `routeTree.gen.${e}`))),
|
|
602
|
-
)
|
|
603
|
-
if (generated || registersRouterPlugin(vite)) return null
|
|
487
|
+
if (hasRouteTree(cwd, entry) || isCodeRoutedApp(cwd, '')) return null
|
|
604
488
|
return {
|
|
605
|
-
fail: `app-wiring: no vite.config calls the TanStack router plugin and ${
|
|
489
|
+
fail: `app-wiring: the entry imports a generated route tree but no vite.config calls the TanStack router plugin and ${routeTreeDirs(entry).join(' or ')}/routeTree.gen.ts does not exist. ${ROUTER_PLUGIN_FIX}`,
|
|
606
490
|
}
|
|
607
491
|
})
|
|
608
492
|
}
|
package/src/cli/doctor.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { relative, resolve } from 'node:path'
|
|
|
9
9
|
import {
|
|
10
10
|
AGENTS_MD,
|
|
11
11
|
LEGACY_BLOCK_HOST,
|
|
12
|
+
scanBlock,
|
|
12
13
|
MANIFEST_PATH,
|
|
13
14
|
basaltBinCommand,
|
|
14
15
|
basaltPresetEntry,
|
|
@@ -31,7 +32,6 @@ import {
|
|
|
31
32
|
ROUTER_SEED_DESTS,
|
|
32
33
|
sameFile,
|
|
33
34
|
scannableFiles,
|
|
34
|
-
scanBlock,
|
|
35
35
|
shippedAssetPath,
|
|
36
36
|
} from './index'
|
|
37
37
|
import { resolveRoots } from './config'
|
|
@@ -47,7 +47,8 @@ import {
|
|
|
47
47
|
unknownConfigKeysCheck,
|
|
48
48
|
} from './doctor-upgrade'
|
|
49
49
|
import type { Check } from './doctor-upgrade'
|
|
50
|
-
import { findManifestAbove,
|
|
50
|
+
import { findManifestAbove, installRootAbove } from './install-root'
|
|
51
|
+
import { parentInstallAdvice } from './sync'
|
|
51
52
|
|
|
52
53
|
/** `sameFile`, but doctor never crashes: a path that cannot be inspected is "not provably the same". */
|
|
53
54
|
function isSameFile(a: string, b: string): boolean {
|
|
@@ -109,7 +110,8 @@ function aiMajorsAt(dir: string): Partial<Record<AiMajorField, number>> {
|
|
|
109
110
|
* 7. `ai-major-parity`: the `ai` major agrees across this package.json's dependency fields
|
|
110
111
|
* (exempt via `basalt.aiMajorSkewReason`; a stale reason warns).
|
|
111
112
|
* 8-14. `tsconfig-base`, `retired-lint-rules`, `dropped-subpaths`, `app-wiring`, `exact-peers`,
|
|
112
|
-
* `subpath-peers`, `config-keys` (./doctor-upgrade
|
|
113
|
+
* `subpath-peers`, `config-keys` (./doctor-upgrade; a tokens-only consumer runs only
|
|
114
|
+
* `dropped-subpaths` of these — it imports CSS subpaths, where `tokens.css` was);
|
|
113
115
|
* a check that cannot run is SKIPPED and exits non-zero.
|
|
114
116
|
*
|
|
115
117
|
* Warning (non-fatal):
|
|
@@ -122,17 +124,9 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
122
124
|
if (conflictingProfileFlags('doctor', flags)) return 1
|
|
123
125
|
const project = resolveProjectDir(invocationCwd)
|
|
124
126
|
// Inside the app package of a monorepo the manifest is above: read the install root instead.
|
|
125
|
-
const aboveRoot =
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: null
|
|
129
|
-
const insideApp =
|
|
130
|
-
aboveRoot !== null &&
|
|
131
|
-
(() => {
|
|
132
|
-
const app = resolveAppDir(aboveRoot)
|
|
133
|
-
return !('error' in app) && app.dir === project.dir
|
|
134
|
-
})()
|
|
135
|
-
const cwd = insideApp && aboveRoot !== null ? aboveRoot : project.dir
|
|
127
|
+
const aboveRoot = project.relocatedFrom === null ? installRootAbove(project.dir) : null
|
|
128
|
+
const insideApp = aboveRoot !== null
|
|
129
|
+
const cwd = aboveRoot ?? project.dir
|
|
136
130
|
const cfg = readBasaltConfig(cwd)
|
|
137
131
|
const result: DoctorResult = { hardFailures: 0, warnings: 0, skipped: 0 }
|
|
138
132
|
const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
|
|
@@ -318,10 +312,6 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
318
312
|
const issues: string[] = []
|
|
319
313
|
if (scan.problem !== null) {
|
|
320
314
|
issues.push(`has a malformed basalt block (${scan.problem}) — fix it by hand, then \`sync\``)
|
|
321
|
-
} else if (scan.region !== null) {
|
|
322
|
-
issues.push(
|
|
323
|
-
`still carries a stale basalt block — delete it by hand; \`sync\` keeps ${AGENTS_MD} current`,
|
|
324
|
-
)
|
|
325
315
|
}
|
|
326
316
|
if (!importsAgentsMd(legacy)) {
|
|
327
317
|
issues.push(
|
|
@@ -384,24 +374,33 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
384
374
|
}
|
|
385
375
|
|
|
386
376
|
// ── Hard checks 8-13: strictness and the 1.x → 2.0 upgrade path (./doctor-upgrade) ──────────
|
|
377
|
+
const droppedCheck: [string, Check] = [
|
|
378
|
+
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
379
|
+
droppedSubpathsCheck(appDir, cfg, install),
|
|
380
|
+
]
|
|
381
|
+
const runChecks = (checks: [string, Check][]): void => {
|
|
382
|
+
for (const [ok, check] of checks) {
|
|
383
|
+
if (check === null) pass(ok)
|
|
384
|
+
else if ('fail' in check) fail(check.fail)
|
|
385
|
+
else skip(check.skip)
|
|
386
|
+
}
|
|
387
|
+
}
|
|
387
388
|
if (profile === 'tokens-only') {
|
|
388
389
|
pass(
|
|
389
|
-
'tsconfig-base / retired-lint-rules /
|
|
390
|
+
'tsconfig-base / retired-lint-rules / oxlint-floor / app-wiring / exact-peers / subpath-peers / config-keys: n/a — a tokens-only consumer',
|
|
390
391
|
)
|
|
392
|
+
runChecks([droppedCheck])
|
|
391
393
|
} else {
|
|
392
|
-
|
|
394
|
+
runChecks([
|
|
393
395
|
['tsconfig-base: tsconfig.json extends the shipped preset', tsconfigBaseCheck(appDir)],
|
|
394
396
|
[
|
|
395
397
|
'retired-lint-rules: .oxlintrc.json sets no retired basalt/* rule',
|
|
396
398
|
retiredLintRulesCheck(cwd, install),
|
|
397
399
|
],
|
|
398
|
-
|
|
399
|
-
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
400
|
-
droppedSubpathsCheck(appDir, cfg, install),
|
|
401
|
-
],
|
|
400
|
+
droppedCheck,
|
|
402
401
|
['oxlint-floor: the installed oxlint parses the shipped preset', oxlintFloorCheck(cwd)],
|
|
403
402
|
[
|
|
404
|
-
'app-wiring: the entry mounts BasaltProvider and the router tree
|
|
403
|
+
'app-wiring: the entry mounts BasaltProvider and the router tree exists',
|
|
405
404
|
appWiringCheck(appDir),
|
|
406
405
|
],
|
|
407
406
|
['exact-peers: installed exact-pinned peers match basalt-ui', exactPeersCheck(cwd, install)],
|
|
@@ -413,12 +412,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
413
412
|
'config-keys: the basalt config block sets only keys basalt-ui reads',
|
|
414
413
|
unknownConfigKeysCheck(cwd),
|
|
415
414
|
],
|
|
416
|
-
]
|
|
417
|
-
for (const [ok, check] of upgrade) {
|
|
418
|
-
if (check === null) pass(ok)
|
|
419
|
-
else if ('fail' in check) fail(check.fail)
|
|
420
|
-
else skip(check.skip)
|
|
421
|
-
}
|
|
415
|
+
])
|
|
422
416
|
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
423
417
|
}
|
|
424
418
|
|
package/src/cli/help.ts
CHANGED
|
@@ -41,7 +41,6 @@ export const COMMAND_OPTIONS: Record<string, Record<string, { type: 'string' | '
|
|
|
41
41
|
'default-scheme': { type: 'string' },
|
|
42
42
|
'media-fallback': { type: 'boolean' },
|
|
43
43
|
only: { type: 'string' },
|
|
44
|
-
'no-legacy-aliases': { type: 'boolean' },
|
|
45
44
|
},
|
|
46
45
|
'fonts:css': { out: { type: 'string' }, check: { type: 'boolean' } },
|
|
47
46
|
}
|
|
@@ -75,12 +74,10 @@ export const USAGE =
|
|
|
75
74
|
'tokens:css [--out <path>] [--check] [--selector-attribute <attr> | --selector-class <class>]\n' +
|
|
76
75
|
' [--light-class <class>] [--dark-value <v>] [--light-value <v>]\n' +
|
|
77
76
|
' [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n' +
|
|
78
|
-
' [--no-legacy-aliases]\n' +
|
|
79
77
|
' Emit the --vx-* stylesheet (stdout unless --out). Defaults emit the stock identity; commit the output as your tokens file.\n' +
|
|
80
78
|
' --selector-class emits `:root.dark` instead of an attribute selector (the Tailwind convention).\n' +
|
|
81
79
|
' --check writes nothing and exits 1 when --out differs from what would be emitted (a CI gate).\n' +
|
|
82
|
-
'
|
|
83
|
-
' which are emitted by default as aliases of the canonical kebab-case names.\n\n' +
|
|
80
|
+
'\n' +
|
|
84
81
|
'fonts:css [--out <path>] [--check]\n' +
|
|
85
82
|
' Emit the shipped --basalt-font-* stacks as plain CSS — the typeface half of the token layer,\n' +
|
|
86
83
|
' otherwise reachable only by importing styles.css.\n\n' +
|