basalt-ui 2.7.3 → 2.8.1
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/CHANGELOG.md +194 -172
- package/MIGRATING.md +137 -16
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +7 -7
- package/agent/templates/AGENTS-block.md.tpl +1 -1
- package/dist/charts/BandStrip.d.ts +13 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +142 -44
- package/dist/cli/doctor-upgrade.d.ts +16 -4
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +132 -96
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +21 -13
- package/dist/cli/help.js +1 -1
- package/dist/cli/index.d.ts +18 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -24
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +10 -4
- 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.map +1 -1
- package/dist/cli/sync.js +32 -2
- 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/provider/index.d.ts +22 -4
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +24 -8
- package/dist/provider/test-router.d.ts +2 -1
- package/dist/provider/test-router.d.ts.map +1 -1
- package/dist/provider/test-router.js +6 -7
- 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 +37 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +223 -48
- package/src/cli/doctor-upgrade.ts +181 -141
- package/src/cli/doctor.ts +23 -14
- package/src/cli/help.ts +1 -1
- package/src/cli/index.ts +37 -36
- package/src/cli/init.ts +10 -6
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +36 -2
- 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/provider/index.tsx +71 -18
- package/src/provider/test-router.tsx +9 -9
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
|
@@ -2,14 +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,
|
|
11
|
+
import { parseJsonc, routerSeedDest, scannableFiles } from './index'
|
|
12
12
|
import type { BasaltInstall } from './index'
|
|
13
|
+
import {
|
|
14
|
+
appEntry,
|
|
15
|
+
hasRouteTree,
|
|
16
|
+
hasRouter,
|
|
17
|
+
isCodeRoutedApp,
|
|
18
|
+
isStartApp,
|
|
19
|
+
routeTreeDirs,
|
|
20
|
+
} from './router-wiring'
|
|
21
|
+
import { readIfExists, readPackageJson, tokenize } from './source-text'
|
|
13
22
|
|
|
14
23
|
export type Check = { fail: string } | { skip: string } | null
|
|
15
24
|
|
|
@@ -183,14 +192,6 @@ export function retiredLintRulesCheck(cwd: string, install: BasaltInstall): Chec
|
|
|
183
192
|
})
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
/**
|
|
187
|
-
* Strings and template literals (captured) and comments. Known, accepted gap: a regex literal that
|
|
188
|
-
* contains a quote (`/'/`) opens a string this tokenizer never closes, which can blank or hide code
|
|
189
|
-
* after it on that line; a template literal nested inside a `${…}` is not tracked either.
|
|
190
|
-
*/
|
|
191
|
-
const TOKEN =
|
|
192
|
-
/("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|\/\/[^\n]*|\/\*[\s\S]*?\*\//g
|
|
193
|
-
|
|
194
195
|
/**
|
|
195
196
|
* A `basalt-ui/<subpath>` specifier in statement position: `import … from`, `import type … from`
|
|
196
197
|
* (also split over lines), `export … from`, bare `import '…'`, `import('…')` and `require('…')`
|
|
@@ -199,24 +200,6 @@ const TOKEN =
|
|
|
199
200
|
const SUBPATH_IMPORT =
|
|
200
201
|
/(?:(?:^|;)[ \t]*(?:(?:import|export)\b[^'"`;]*?\bfrom|import)\s*|(?<![.\w$])(?:import|require)\s*\(\s*)(['"])basalt-ui\/([^'"]+)\1/gm
|
|
201
202
|
|
|
202
|
-
/** Source with comments blanked (and template text), plus a test for "offset sits inside a string". */
|
|
203
|
-
function tokenize(src: string): { code: string; inLiteral: (at: number) => boolean } {
|
|
204
|
-
const literals: [number, number][] = []
|
|
205
|
-
const code = src.replace(TOKEN, (m, literal: string | undefined, at: number) => {
|
|
206
|
-
if (literal === undefined) return m.replace(/[^\n]/g, ' ')
|
|
207
|
-
if (!literal.startsWith('`')) {
|
|
208
|
-
literals.push([at, at + m.length])
|
|
209
|
-
return m
|
|
210
|
-
}
|
|
211
|
-
// Template literal: blank the text, keep the delimiters and the `${…}` code scannable.
|
|
212
|
-
return m.replace(
|
|
213
|
-
/(\$\{[^}]*\})|[^\n`]/g,
|
|
214
|
-
(c, interpolation: string | undefined) => interpolation ?? ' ',
|
|
215
|
-
)
|
|
216
|
-
})
|
|
217
|
-
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) }
|
|
218
|
-
}
|
|
219
|
-
|
|
220
203
|
/** `[subpath, line]` per `basalt-ui/<subpath>` import that sits in code, not in a comment or literal. */
|
|
221
204
|
function basaltImports(src: string): [string, number][] {
|
|
222
205
|
const { code, inLiteral } = tokenize(src)
|
|
@@ -225,15 +208,46 @@ function basaltImports(src: string): [string, number][] {
|
|
|
225
208
|
.map((m) => [m[2] as string, code.slice(0, m.index + m[0].length).split('\n').length])
|
|
226
209
|
}
|
|
227
210
|
|
|
228
|
-
/**
|
|
211
|
+
/** `@import 'basalt-ui/x'`, `@import "basalt-ui/x"`, `@import url(basalt-ui/x)` in a stylesheet (at-rule position only). */
|
|
212
|
+
const CSS_SUBPATH_IMPORT = /(?:^|[;{}])\s*@import\s+(?:url\(\s*)?(['"]?)basalt-ui\/([^'")\s;]+)\1/g
|
|
213
|
+
|
|
214
|
+
/** `[subpath, line]` per `basalt-ui/<subpath>` `@import` in a stylesheet (comments blanked). */
|
|
215
|
+
function cssImports(src: string): [string, number][] {
|
|
216
|
+
const blank = (m: string): string => m.replace(/[^\n]/g, ' ')
|
|
217
|
+
const code = src
|
|
218
|
+
.replace(/\/\*[\s\S]*?\*\//g, blank)
|
|
219
|
+
// A quoted string that is not an @import/url() target is a value: `content: "a; @import …"`.
|
|
220
|
+
.replace(/(@import\s+|url\(\s*)?(["'])(?:\\.|(?!\2)[^\\\n])*\2/g, (m, target) =>
|
|
221
|
+
target === undefined ? blank(m) : m,
|
|
222
|
+
)
|
|
223
|
+
return [...code.matchAll(CSS_SUBPATH_IMPORT)].map((m) => [
|
|
224
|
+
m[2] as string,
|
|
225
|
+
code.slice(0, m.index + m[0].length).split('\n').length,
|
|
226
|
+
])
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** `[subpath, file, line]` per `basalt-ui/<subpath>` import in the app's source and style files. */
|
|
229
230
|
const appImports = (cwd: string, cfg: BasaltConfig): [string, string, number][] =>
|
|
230
|
-
scannableFiles(cwd, cfg)
|
|
231
|
-
|
|
232
|
-
.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
),
|
|
231
|
+
scannableFiles(cwd, cfg).flatMap((rel) => {
|
|
232
|
+
const isCode = /\.(?:[cm]?[jt]sx?|vue|astro)$/.test(rel)
|
|
233
|
+
if (!isCode && !rel.endsWith('.css')) return []
|
|
234
|
+
const src = readIfExists(resolve(cwd, rel)) ?? ''
|
|
235
|
+
return (isCode ? basaltImports(src) : cssImports(src)).map(
|
|
236
|
+
([sub, line]): [string, string, number] => [sub, rel, line],
|
|
236
237
|
)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
/** Subpaths 2.x removed, checked besides the install's `exports`: a walked-up 1.x install exports them. */
|
|
241
|
+
const DROPPED_FIXES = new Map([
|
|
242
|
+
[
|
|
243
|
+
'tokens.css',
|
|
244
|
+
'commit the emit instead: `basalt-ui tokens:css --out src/tokens.css` and import that file',
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
'router-tanstack',
|
|
248
|
+
'nav symbols (`defineNav`, `navTarget`, …) now import from `basalt-ui`, stores (`createSearchStore`, `field`, …) from `basalt-ui/state`',
|
|
249
|
+
],
|
|
250
|
+
])
|
|
237
251
|
|
|
238
252
|
/** `dropped-subpaths`: `basalt-ui/<subpath>` imports the installed `exports` map does not have. */
|
|
239
253
|
export function droppedSubpathsCheck(
|
|
@@ -249,17 +263,51 @@ export function droppedSubpathsCheck(
|
|
|
249
263
|
// No `exports` field means nothing restricts the deep imports.
|
|
250
264
|
if (exportsMap === undefined) return null
|
|
251
265
|
const keys = Object.keys(exportsMap)
|
|
252
|
-
const
|
|
266
|
+
const hasExport = (sub: string): boolean =>
|
|
253
267
|
keys.some(
|
|
254
268
|
(k) => k === `./${sub}` || (k.endsWith('*') && `./${sub}`.startsWith(k.slice(0, -1))),
|
|
255
269
|
)
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
270
|
+
const isDropped = (sub: string): boolean => DROPPED_FIXES.has(sub) || !hasExport(sub)
|
|
271
|
+
const found = appImports(cwd, cfg).filter(([sub]) => isDropped(sub))
|
|
272
|
+
if (found.length === 0) return null
|
|
273
|
+
const hits = found.map(([sub, rel, line]) => `${rel}:${line} imports basalt-ui/${sub}`)
|
|
260
274
|
const more = hits.length > 10 ? ` (+${hits.length - 10} more)` : ''
|
|
275
|
+
const fixes = [...new Set(found.map(([sub]) => sub))].flatMap((sub) => {
|
|
276
|
+
const fix = DROPPED_FIXES.get(sub)
|
|
277
|
+
return fix === undefined ? [] : [`basalt-ui/${sub}: ${fix}`]
|
|
278
|
+
})
|
|
279
|
+
fixes.push("see MIGRATING.md § 2.0 for each subpath's replacement")
|
|
280
|
+
return { fail: `${id}: ${hits.slice(0, 10).join('; ')}${more}. Fix: ${fixes.join('; ')}.` }
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The oldest oxlint that parses the shipped preset (1.78 lacks `react/globals` and friends). */
|
|
285
|
+
const OXLINT_FLOOR = '1.79.0'
|
|
286
|
+
|
|
287
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(-[^+]+)?(?:\+.*)?$/
|
|
288
|
+
|
|
289
|
+
/** True when `version` is below `floor`; a prerelease of the floor is below it, build metadata is ignored. */
|
|
290
|
+
function isBelowFloor(version: string, floor: string): boolean {
|
|
291
|
+
const [v, f] = [SEMVER.exec(version), SEMVER.exec(floor)]
|
|
292
|
+
if (v === null || f === null) return false
|
|
293
|
+
for (const i of [1, 2, 3]) {
|
|
294
|
+
if (Number(v[i]) !== Number(f[i])) return Number(v[i]) < Number(f[i])
|
|
295
|
+
}
|
|
296
|
+
return v[4] !== undefined
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* `oxlint-floor`: fails when the nearest installed oxlint is older than {@link OXLINT_FLOOR}, which
|
|
301
|
+
* cannot parse the preset. Reads `cwd`, as `oxlint-preset` does; a missing oxlint is that check's job.
|
|
302
|
+
*/
|
|
303
|
+
export function oxlintFloorCheck(cwd: string): Check {
|
|
304
|
+
const id = 'oxlint-floor'
|
|
305
|
+
return guarded(id, () => {
|
|
306
|
+
if (readIfExists(resolve(cwd, '.oxlintrc.json')) === null) return null
|
|
307
|
+
const version = installedVersion(cwd, 'oxlint')
|
|
308
|
+
if (version === null || !isBelowFloor(version, OXLINT_FLOOR)) return null
|
|
261
309
|
return {
|
|
262
|
-
fail: `${id}: ${
|
|
310
|
+
fail: `${id}: oxlint ${version} is installed, but the shipped preset needs >= ${OXLINT_FLOOR} (older versions reject its react/* rules). Fix: \`bun add -D oxlint@^${OXLINT_FLOOR}\`.`,
|
|
263
311
|
}
|
|
264
312
|
})
|
|
265
313
|
}
|
|
@@ -314,123 +362,121 @@ export function seedTsconfigExtends(cwd: string): string | null {
|
|
|
314
362
|
return `added "extends": "${TSCONFIG_PRESET_ID}" to ${name}.`
|
|
315
363
|
}
|
|
316
364
|
|
|
317
|
-
const VITE_CONFIGS = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map((e) => `vite.config.${e}`)
|
|
318
365
|
const SEED_HINT = 'node_modules/basalt-ui/agent/templates/main.tpl'
|
|
319
366
|
const ROUTER_PLUGIN_FIX =
|
|
320
367
|
"Fix: `bun add -D @tanstack/router-plugin`, add `tanstackRouter({ target: 'react', autoCodeSplitting: true })` " +
|
|
321
368
|
"from '@tanstack/router-plugin/vite' to `plugins` in vite.config.ts (before react()), then run vite once " +
|
|
322
|
-
'to generate src/routeTree.gen.ts.'
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const src = /\bsrc\s*=\s*["']?([^"'\s>]+)/i.exec(attrs)?.[1]
|
|
330
|
-
if (
|
|
331
|
-
/\btype\s*=\s*["']?module\b/i.test(attrs) &&
|
|
332
|
-
src !== undefined &&
|
|
333
|
-
!/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(src)
|
|
334
|
-
) {
|
|
335
|
-
return src
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return undefined
|
|
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.'
|
|
370
|
+
|
|
371
|
+
/** True when `{` at `i` opens a `{...spread}`: sticky, so any whitespace width is read. */
|
|
372
|
+
function isSpreadAt(code: string, i: number): boolean {
|
|
373
|
+
const spread = /\{\s*\.\.\./y
|
|
374
|
+
spread.lastIndex = i
|
|
375
|
+
return spread.test(code)
|
|
339
376
|
}
|
|
340
377
|
|
|
341
|
-
|
|
342
|
-
|
|
378
|
+
type ProviderTag = { attrs: string; spread: boolean }
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Every `<BasaltProvider …>` opening tag in a root route: its attribute text at JSX brace depth 0,
|
|
382
|
+
* with string literals skipped (so `className="a > b"` cannot end the tag, nor `"router="` count),
|
|
383
|
+
* and whether a `{...spread}` could carry a `router`.
|
|
384
|
+
*/
|
|
385
|
+
function providerTags(src: string): ProviderTag[] {
|
|
343
386
|
const { code, inLiteral } = tokenize(src)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
new RegExp(`(?<![.\\w$])${name.replace(/\$/g, '\\$')}(?:\\.\\w+)?\\s*\\(`, 'g'),
|
|
361
|
-
),
|
|
362
|
-
].some((call) => call.index > pluginsAt && !inLiteral(call.index)),
|
|
363
|
-
)
|
|
364
|
-
})
|
|
387
|
+
return [...code.matchAll(/<BasaltProvider\b/g)]
|
|
388
|
+
.filter((m) => !inLiteral(m.index))
|
|
389
|
+
.map((m) => {
|
|
390
|
+
const tag: ProviderTag = { attrs: '', spread: false }
|
|
391
|
+
let depth = 0
|
|
392
|
+
for (let i = m.index + m[0].length; i < code.length; i++) {
|
|
393
|
+
const ch = code[i]!
|
|
394
|
+
if (inLiteral(i)) continue
|
|
395
|
+
if (ch === '{') {
|
|
396
|
+
if (depth++ === 0 && isSpreadAt(code, i)) tag.spread = true
|
|
397
|
+
} else if (ch === '}') depth--
|
|
398
|
+
else if (ch === '>' && depth === 0) break
|
|
399
|
+
else if (depth === 0) tag.attrs += ch
|
|
400
|
+
}
|
|
401
|
+
return tag
|
|
402
|
+
})
|
|
365
403
|
}
|
|
366
404
|
|
|
367
|
-
const
|
|
368
|
-
/(?:\b(?:import|export)\b[^'";]*?\bfrom|\bimport)\s*['"](\.{1,2}\/[^'"]+)['"]/g
|
|
405
|
+
const carriesRouter = (tag: ProviderTag): boolean => /(^|\s)router\s*=/.test(tag.attrs)
|
|
369
406
|
|
|
370
|
-
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
407
|
+
/**
|
|
408
|
+
* A Start app owns its router and entry: the wiring is an embedded `<BasaltProvider>` (no `router=`)
|
|
409
|
+
* in its root route component, around `<Outlet />`. ANY tag with `router=` mounts a second router
|
|
410
|
+
* inside Start's, so it fails even beside an embedded one.
|
|
411
|
+
*/
|
|
412
|
+
function startWiring(cwd: string): { fail: string } | null {
|
|
413
|
+
const root = routerSeedDest('', 'root')
|
|
414
|
+
const text = readIfExists(resolve(cwd, root))
|
|
415
|
+
const tags = providerTags(text ?? '')
|
|
416
|
+
const mounting = tags.some(carriesRouter)
|
|
417
|
+
if (!mounting && tags.length > 0) return null
|
|
418
|
+
const problem =
|
|
419
|
+
text === null
|
|
420
|
+
? 'does not exist'
|
|
421
|
+
: mounting
|
|
422
|
+
? 'passes router= to BasaltProvider, which mounts a second router inside Start'
|
|
423
|
+
: 'does not render <BasaltProvider>'
|
|
424
|
+
return {
|
|
425
|
+
fail: `app-wiring: ${root} ${problem} (TanStack Start app). Fix: render <BasaltProvider><Outlet /></BasaltProvider> in the root route component.`,
|
|
426
|
+
}
|
|
382
427
|
}
|
|
383
428
|
|
|
384
429
|
/**
|
|
385
|
-
*
|
|
386
|
-
*
|
|
430
|
+
* Warnings for a Start app's embedded provider; heuristics, not proofs. A `{...spread}` on the tag
|
|
431
|
+
* could carry a `router`; `src/router.tsx` never mentioning `queryClient` means the embedded
|
|
432
|
+
* provider will find no `context.queryClient`. Empty when there is nothing to judge.
|
|
387
433
|
*/
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
frontier = next
|
|
434
|
+
export function startWiringWarnings(cwd: string): string[] {
|
|
435
|
+
if (!isStartApp(cwd, '')) return []
|
|
436
|
+
const out: string[] = []
|
|
437
|
+
const root = readIfExists(resolve(cwd, routerSeedDest('', 'root')))
|
|
438
|
+
if (root !== null && providerTags(root).some((t) => t.spread)) {
|
|
439
|
+
out.push(
|
|
440
|
+
'app-wiring: <BasaltProvider {...spread}> in the root route could pass router=, which mounts ' +
|
|
441
|
+
'a second router inside Start (heuristic: the spread is not followed).',
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
const router = readIfExists(resolve(cwd, 'src/router.tsx'))
|
|
445
|
+
if (router !== null && !/queryClient/.test(router)) {
|
|
446
|
+
out.push(
|
|
447
|
+
'app-wiring: src/router.tsx never mentions queryClient — embedded BasaltProvider needs ' +
|
|
448
|
+
'context.queryClient on the Start router (heuristic text check; ignore if you build it elsewhere).',
|
|
449
|
+
)
|
|
407
450
|
}
|
|
408
|
-
return
|
|
451
|
+
return out
|
|
409
452
|
}
|
|
410
453
|
|
|
411
454
|
/**
|
|
412
455
|
* `app-wiring`: the entry module `index.html` loads (default src/main.tsx) mounts `BasaltProvider`
|
|
413
|
-
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree
|
|
414
|
-
* binding imported from `@tanstack/router-plugin`
|
|
415
|
-
* beside the entry (or in src/)
|
|
416
|
-
*
|
|
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.
|
|
417
461
|
*/
|
|
418
462
|
export function appWiringCheck(cwd: string): Check {
|
|
419
463
|
return guarded('app-wiring', () => {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
).replace(/^\//, '')
|
|
464
|
+
if (isStartApp(cwd, '')) return startWiring(cwd)
|
|
465
|
+
const entry = appEntry(cwd)
|
|
423
466
|
const text = readIfExists(resolve(cwd, entry))
|
|
424
467
|
if (text === null) {
|
|
425
468
|
return { fail: `app-wiring: ${entry} does not exist. Fix: make it match ${SEED_HINT}.` }
|
|
426
469
|
}
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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)
|
|
434
480
|
if (missing.length > 0) {
|
|
435
481
|
return {
|
|
436
482
|
fail:
|
|
@@ -438,15 +484,9 @@ export function appWiringCheck(cwd: string): Check {
|
|
|
438
484
|
`Fix: make it match ${SEED_HINT} (\`init\` seeds it only when the file is absent).`,
|
|
439
485
|
}
|
|
440
486
|
}
|
|
441
|
-
|
|
442
|
-
VITE_CONFIGS.map((f) => readIfExists(resolve(cwd, f))).find((t) => t !== null) ?? ''
|
|
443
|
-
const dirs = [...new Set([dirname(entry), 'src'])]
|
|
444
|
-
const generated = dirs.some((d) =>
|
|
445
|
-
['ts', 'tsx', 'js'].some((e) => existsSync(resolve(cwd, d, `routeTree.gen.${e}`))),
|
|
446
|
-
)
|
|
447
|
-
if (generated || registersRouterPlugin(vite)) return null
|
|
487
|
+
if (hasRouteTree(cwd, entry) || isCodeRoutedApp(cwd, '')) return null
|
|
448
488
|
return {
|
|
449
|
-
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}`,
|
|
450
490
|
}
|
|
451
491
|
})
|
|
452
492
|
}
|
|
@@ -483,7 +523,7 @@ const EXACT_VERSION = /^\d+\.\d+\.\d+$/
|
|
|
483
523
|
function installedVersion(cwd: string, pkg: string): string | null {
|
|
484
524
|
for (let dir = cwd; ; dir = dirname(dir)) {
|
|
485
525
|
const manifest = readPackageJson<{ version?: string }>(resolve(dir, 'node_modules', pkg))
|
|
486
|
-
if (manifest !== null) return manifest.version
|
|
526
|
+
if (manifest !== null) return typeof manifest.version === 'string' ? manifest.version : null
|
|
487
527
|
if (dirname(dir) === dir) return null
|
|
488
528
|
}
|
|
489
529
|
}
|
package/src/cli/doctor.ts
CHANGED
|
@@ -37,8 +37,10 @@ import {
|
|
|
37
37
|
import { resolveRoots } from './config'
|
|
38
38
|
import {
|
|
39
39
|
appWiringCheck,
|
|
40
|
+
startWiringWarnings,
|
|
40
41
|
droppedSubpathsCheck,
|
|
41
42
|
exactPeersCheck,
|
|
43
|
+
oxlintFloorCheck,
|
|
42
44
|
retiredLintRulesCheck,
|
|
43
45
|
subpathPeersCheck,
|
|
44
46
|
tsconfigBaseCheck,
|
|
@@ -107,7 +109,8 @@ function aiMajorsAt(dir: string): Partial<Record<AiMajorField, number>> {
|
|
|
107
109
|
* 7. `ai-major-parity`: the `ai` major agrees across this package.json's dependency fields
|
|
108
110
|
* (exempt via `basalt.aiMajorSkewReason`; a stale reason warns).
|
|
109
111
|
* 8-14. `tsconfig-base`, `retired-lint-rules`, `dropped-subpaths`, `app-wiring`, `exact-peers`,
|
|
110
|
-
* `subpath-peers`, `config-keys` (./doctor-upgrade
|
|
112
|
+
* `subpath-peers`, `config-keys` (./doctor-upgrade; a tokens-only consumer runs only
|
|
113
|
+
* `dropped-subpaths` of these — it imports CSS subpaths, where `tokens.css` was);
|
|
111
114
|
* a check that cannot run is SKIPPED and exits non-zero.
|
|
112
115
|
*
|
|
113
116
|
* Warning (non-fatal):
|
|
@@ -382,23 +385,33 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
382
385
|
}
|
|
383
386
|
|
|
384
387
|
// ── Hard checks 8-13: strictness and the 1.x → 2.0 upgrade path (./doctor-upgrade) ──────────
|
|
388
|
+
const droppedCheck: [string, Check] = [
|
|
389
|
+
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
390
|
+
droppedSubpathsCheck(appDir, cfg, install),
|
|
391
|
+
]
|
|
392
|
+
const runChecks = (checks: [string, Check][]): void => {
|
|
393
|
+
for (const [ok, check] of checks) {
|
|
394
|
+
if (check === null) pass(ok)
|
|
395
|
+
else if ('fail' in check) fail(check.fail)
|
|
396
|
+
else skip(check.skip)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
385
399
|
if (profile === 'tokens-only') {
|
|
386
400
|
pass(
|
|
387
|
-
'tsconfig-base / retired-lint-rules /
|
|
401
|
+
'tsconfig-base / retired-lint-rules / oxlint-floor / app-wiring / exact-peers / subpath-peers / config-keys: n/a — a tokens-only consumer',
|
|
388
402
|
)
|
|
403
|
+
runChecks([droppedCheck])
|
|
389
404
|
} else {
|
|
390
|
-
|
|
405
|
+
runChecks([
|
|
391
406
|
['tsconfig-base: tsconfig.json extends the shipped preset', tsconfigBaseCheck(appDir)],
|
|
392
407
|
[
|
|
393
408
|
'retired-lint-rules: .oxlintrc.json sets no retired basalt/* rule',
|
|
394
409
|
retiredLintRulesCheck(cwd, install),
|
|
395
410
|
],
|
|
411
|
+
droppedCheck,
|
|
412
|
+
['oxlint-floor: the installed oxlint parses the shipped preset', oxlintFloorCheck(cwd)],
|
|
396
413
|
[
|
|
397
|
-
'
|
|
398
|
-
droppedSubpathsCheck(appDir, cfg, install),
|
|
399
|
-
],
|
|
400
|
-
[
|
|
401
|
-
'app-wiring: the entry mounts BasaltProvider and the router tree is generated',
|
|
414
|
+
'app-wiring: the entry mounts BasaltProvider and the router tree exists',
|
|
402
415
|
appWiringCheck(appDir),
|
|
403
416
|
],
|
|
404
417
|
['exact-peers: installed exact-pinned peers match basalt-ui', exactPeersCheck(cwd, install)],
|
|
@@ -410,12 +423,8 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
410
423
|
'config-keys: the basalt config block sets only keys basalt-ui reads',
|
|
411
424
|
unknownConfigKeysCheck(cwd),
|
|
412
425
|
],
|
|
413
|
-
]
|
|
414
|
-
for (const
|
|
415
|
-
if (check === null) pass(ok)
|
|
416
|
-
else if ('fail' in check) fail(check.fail)
|
|
417
|
-
else skip(check.skip)
|
|
418
|
-
}
|
|
426
|
+
])
|
|
427
|
+
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
419
428
|
}
|
|
420
429
|
|
|
421
430
|
// ── Report ──────────────────────────────────────────────────────────────────
|
package/src/cli/help.ts
CHANGED
|
@@ -76,7 +76,7 @@ export const USAGE =
|
|
|
76
76
|
' [--light-class <class>] [--dark-value <v>] [--light-value <v>]\n' +
|
|
77
77
|
' [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n' +
|
|
78
78
|
' [--no-legacy-aliases]\n' +
|
|
79
|
-
' Emit the --vx-* stylesheet (stdout unless --out). Defaults
|
|
79
|
+
' Emit the --vx-* stylesheet (stdout unless --out). Defaults emit the stock identity; commit the output as your tokens file.\n' +
|
|
80
80
|
' --selector-class emits `:root.dark` instead of an attribute selector (the Tailwind convention).\n' +
|
|
81
81
|
' --check writes nothing and exits 1 when --out differs from what would be emitted (a CI gate).\n' +
|
|
82
82
|
' --no-legacy-aliases drops the deprecated camelCase spellings (--vx-accentFill and friends),\n' +
|
package/src/cli/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
existsSync,
|
|
12
12
|
mkdirSync,
|
|
13
13
|
readdirSync,
|
|
14
|
-
readFileSync,
|
|
15
14
|
rmdirSync,
|
|
16
15
|
statSync,
|
|
17
16
|
realpathSync,
|
|
@@ -30,6 +29,9 @@ import { guardHook } from './guard-hook'
|
|
|
30
29
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from './help'
|
|
31
30
|
import { init } from './init'
|
|
32
31
|
import { sync } from './sync'
|
|
32
|
+
import { CODE_ROUTED_NOTE, routerSeedSkip } from './router-wiring'
|
|
33
|
+
import type { RouterSeedSkip } from './router-wiring'
|
|
34
|
+
import { hasDependency, readIfExists, readPackageJson } from './source-text'
|
|
33
35
|
import { fontsCss, normalizeColorFunctions, tokensCss } from './tokens-css'
|
|
34
36
|
import { DEFAULT_ROOT, exemptRulePaths, resolveRoots } from './config'
|
|
35
37
|
import type { BasaltConfig } from './config'
|
|
@@ -477,24 +479,6 @@ export function sha256(text: string): string {
|
|
|
477
479
|
return createHash('sha256').update(text, 'utf8').digest('hex')
|
|
478
480
|
}
|
|
479
481
|
|
|
480
|
-
export function readIfExists(abs: string): string | null {
|
|
481
|
-
try {
|
|
482
|
-
return readFileSync(abs, 'utf8')
|
|
483
|
-
} catch {
|
|
484
|
-
return null // absent, a directory, unreadable or raced away: callers treat all four as "not there"
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/** `<dir>/package.json` parsed as `T`; null when absent or not JSON. */
|
|
489
|
-
export function readPackageJson<T>(dir: string): T | null {
|
|
490
|
-
const raw = readIfExists(resolve(dir, 'package.json'))
|
|
491
|
-
try {
|
|
492
|
-
return raw === null ? null : (JSON.parse(raw) as T)
|
|
493
|
-
} catch {
|
|
494
|
-
return null
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
482
|
/** Read a shipped source asset from the package root; null if the sibling hasn't authored it yet. */
|
|
499
483
|
export function readSource(pkgRoot: string, source: string): string | null {
|
|
500
484
|
return readIfExists(resolve(pkgRoot, source))
|
|
@@ -670,6 +654,36 @@ export function routerSeedDest(appRel: string, seed: keyof typeof ROUTER_SEED_DE
|
|
|
670
654
|
return appRel === '' ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`
|
|
671
655
|
}
|
|
672
656
|
|
|
657
|
+
/** The router seeds' dests for an app dir (`main.tsx`, `nav.tsx`, `__root.tsx`). */
|
|
658
|
+
export function routerSeedDests(appRel: string): string[] {
|
|
659
|
+
return (Object.keys(ROUTER_SEED_DESTS) as (keyof typeof ROUTER_SEED_DESTS)[]).map((seed) =>
|
|
660
|
+
routerSeedDest(appRel, seed),
|
|
661
|
+
)
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export const START_APP_NOTE =
|
|
665
|
+
'TanStack Start app — no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); render ' +
|
|
666
|
+
'<BasaltProvider><Outlet /></BasaltProvider> in your root route component.'
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` | null)
|
|
670
|
+
* and which dests. A tokens-only consumer gets none of them either.
|
|
671
|
+
*/
|
|
672
|
+
export function routerSeedPlan(
|
|
673
|
+
cwd: string,
|
|
674
|
+
appRel: string,
|
|
675
|
+
tokensOnly = false,
|
|
676
|
+
): { skip: RouterSeedSkip; skipped: Set<string> } {
|
|
677
|
+
const skip = tokensOnly ? null : routerSeedSkip(cwd, appRel)
|
|
678
|
+
return { skip, skipped: new Set(tokensOnly || skip !== null ? routerSeedDests(appRel) : []) }
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/** The note `init` prints for a router-seed skip, or null when nothing was skipped. */
|
|
682
|
+
export function seedSkipNote(skip: RouterSeedSkip): string | null {
|
|
683
|
+
if (skip === 'start') return START_APP_NOTE
|
|
684
|
+
return skip === 'code-routed' ? CODE_ROUTED_NOTE : null
|
|
685
|
+
}
|
|
686
|
+
|
|
673
687
|
/** The app directory a command's app-scoped half targets: `rel` is '' when it is the install root. */
|
|
674
688
|
export type AppResolution = { dir: string; rel: string } | { error: string }
|
|
675
689
|
|
|
@@ -715,22 +729,6 @@ export function resolveAppDir(root: string): AppResolution {
|
|
|
715
729
|
}
|
|
716
730
|
}
|
|
717
731
|
|
|
718
|
-
/** True when `pkgName` appears in the consumer's dependencies, devDependencies, or peerDependencies. */
|
|
719
|
-
function hasDependency(cwd: string, pkgName: string): boolean {
|
|
720
|
-
const pkg =
|
|
721
|
-
readPackageJson<
|
|
722
|
-
Record<
|
|
723
|
-
'dependencies' | 'devDependencies' | 'peerDependencies',
|
|
724
|
-
Record<string, string> | undefined
|
|
725
|
-
>
|
|
726
|
-
>(cwd)
|
|
727
|
-
return Boolean(
|
|
728
|
-
pkg?.dependencies?.[pkgName] ??
|
|
729
|
-
pkg?.devDependencies?.[pkgName] ??
|
|
730
|
-
pkg?.peerDependencies?.[pkgName],
|
|
731
|
-
)
|
|
732
|
-
}
|
|
733
|
-
|
|
734
732
|
/**
|
|
735
733
|
* Where the seed engine is running relative to the consumer's git repo — decides which
|
|
736
734
|
* repo-root-shaped seeds are safe to write. `init`/`sync` compute it once per run via
|
|
@@ -1209,7 +1207,8 @@ export function writeUnit(file: ManagedFile, cwd: string, desired: string): stri
|
|
|
1209
1207
|
* - missing : absent on disk → recreate.
|
|
1210
1208
|
* - current : on disk == desired → nothing to do.
|
|
1211
1209
|
* - unchanged: on disk matches a KNOWN-SHIPPED rendering (raw manifest hash, normalized manifest
|
|
1212
|
-
* hash, or
|
|
1210
|
+
* hash, or — with or without a manifest entry — normalized == normalized desired,
|
|
1211
|
+
* the format-only difference a formatter pass leaves) → safe overwrite.
|
|
1213
1212
|
* - drifted : matches none of them (a real local edit) → skip unless --force.
|
|
1214
1213
|
*/
|
|
1215
1214
|
export function classify(state: UnitState, manifestHash: string | undefined): Classification {
|
|
@@ -1768,6 +1767,8 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
|
|
|
1768
1767
|
}
|
|
1769
1768
|
|
|
1770
1769
|
// `RULE_NAMES`/`SKILL_NAMES` re-exported for testing / introspection (no default export).
|
|
1770
|
+
export { isStartApp } from './router-wiring'
|
|
1771
|
+
export { readIfExists, readPackageJson } from './source-text'
|
|
1771
1772
|
export { RULE_NAMES, SKILL_NAMES }
|
|
1772
1773
|
export type { ManagedFile }
|
|
1773
1774
|
|