basalt-ui 2.12.0 → 2.13.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/CHANGELOG.md +23 -0
- package/MIGRATING.md +39 -12
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +1 -1
- package/agent/templates/main.tpl +1 -0
- package/dist/cli/basalt-install.d.ts +10 -0
- package/dist/cli/basalt-install.d.ts.map +1 -0
- package/dist/cli/basalt-install.js +0 -0
- package/dist/cli/check-theme.js +1 -1
- package/dist/cli/doctor-upgrade.d.ts +3 -3
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +28 -44
- package/dist/cli/doctor.js +3 -3
- package/dist/cli/index.d.ts +4 -28
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +10 -49
- package/dist/cli/provider-tags.d.ts +12 -0
- package/dist/cli/provider-tags.d.ts.map +1 -0
- package/dist/cli/provider-tags.js +28 -0
- package/dist/cli/render-imports.d.ts +24 -0
- package/dist/cli/render-imports.d.ts.map +1 -0
- package/dist/cli/render-imports.js +74 -0
- package/dist/cli/router-wiring.d.ts +12 -0
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +18 -0
- package/dist/cli/source-text.d.ts +7 -0
- package/dist/cli/source-text.d.ts.map +1 -1
- package/dist/cli/source-text.js +34 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +18 -13
- package/dist/guard/fonts-hint.d.ts +3 -0
- package/dist/guard/fonts-hint.d.ts.map +1 -0
- package/dist/guard/fonts-hint.js +4 -0
- package/dist/guard/index.d.ts +1 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/provider/create-router.d.ts +57 -10
- package/dist/provider/create-router.d.ts.map +1 -1
- package/dist/provider/create-router.js +28 -17
- package/dist/provider/index.d.ts +2 -2
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +23 -7
- package/dist/query-client.d.ts +2 -62
- package/dist/query-client.d.ts.map +1 -1
- package/dist/query-client.js +13 -18
- package/dist/router-tanstack/search-store-warnings.d.ts +33 -0
- package/dist/router-tanstack/search-store-warnings.d.ts.map +1 -0
- package/dist/router-tanstack/search-store-warnings.js +77 -0
- package/dist/router-tanstack/search-store.d.ts +2 -5
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +111 -110
- package/dist/telemetry.d.ts +31 -2
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +32 -12
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +17 -30
- package/dist/theme/extend.d.ts +18 -0
- package/dist/theme/extend.d.ts.map +1 -0
- package/dist/theme/extend.js +6 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +44 -84
- package/dist/unwrap.d.ts +29 -0
- package/dist/unwrap.d.ts.map +1 -0
- package/dist/unwrap.js +18 -0
- package/llms.txt +9 -5
- package/package.json +1 -1
- package/src/cli/basalt-install.ts +9 -0
- package/src/cli/check-theme.ts +1 -1
- package/src/cli/doctor-upgrade.ts +40 -61
- package/src/cli/doctor.ts +3 -3
- package/src/cli/index.ts +14 -71
- package/src/cli/provider-tags.ts +38 -0
- package/src/cli/render-imports.ts +104 -0
- package/src/cli/router-wiring.ts +23 -0
- package/src/cli/source-text.ts +39 -0
- package/src/cli/sync.ts +27 -21
- package/src/guard/fonts-hint.ts +2 -0
- package/src/guard/index.ts +2 -2
- package/src/index.ts +4 -2
- package/src/provider/create-router.tsx +103 -39
- package/src/provider/index.tsx +27 -9
- package/src/query-client.ts +20 -78
- package/src/router-tanstack/search-store-warnings.ts +120 -0
- package/src/router-tanstack/search-store.ts +200 -206
- package/src/telemetry.ts +71 -13
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2354 -0
- package/src/theme/ctl-theme.tsx +20 -19
- package/src/theme/extend.ts +18 -0
- package/src/theme/index.ts +50 -49
- package/src/unwrap.ts +44 -0
|
@@ -9,8 +9,7 @@ import { dirname, relative, resolve } from 'node:path'
|
|
|
9
9
|
|
|
10
10
|
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS, shellConfigError } from './config'
|
|
11
11
|
import type { BasaltConfig } from './config'
|
|
12
|
-
import {
|
|
13
|
-
import type { BasaltInstall } from './index'
|
|
12
|
+
import type { BasaltInstall } from './basalt-install'
|
|
14
13
|
import {
|
|
15
14
|
appEntry,
|
|
16
15
|
callsIn,
|
|
@@ -19,8 +18,14 @@ import {
|
|
|
19
18
|
isCodeRoutedApp,
|
|
20
19
|
isStartApp,
|
|
21
20
|
routeTreeDirs,
|
|
21
|
+
routerSeedDest,
|
|
22
|
+
START_PROVIDER_HINT,
|
|
22
23
|
} from './router-wiring'
|
|
23
|
-
import {
|
|
24
|
+
import { FONTS_CSS_HINT } from '../guard/fonts-hint'
|
|
25
|
+
import { carriesRouter } from './provider-tags'
|
|
26
|
+
import { followProviderHops, loadModule } from './render-imports'
|
|
27
|
+
import type { ModuleFile } from './render-imports'
|
|
28
|
+
import { parseJsonc, readIfExists, readPackageJson, tokenize } from './source-text'
|
|
24
29
|
|
|
25
30
|
export type Check = { fail: string } | { skip: string } | null
|
|
26
31
|
|
|
@@ -229,8 +234,8 @@ function cssImports(src: string): [string, number][] {
|
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
/** `[subpath, file, line]` per `basalt-ui/<subpath>` import in the app's source and style files. */
|
|
232
|
-
const appImports = (cwd: string,
|
|
233
|
-
|
|
237
|
+
const appImports = (cwd: string, scanned: string[]): [string, string, number][] =>
|
|
238
|
+
scanned.flatMap((rel) => {
|
|
234
239
|
const isCode = /\.(?:[cm]?[jt]sx?|vue|astro)$/.test(rel)
|
|
235
240
|
if (!isCode && !rel.endsWith('.css')) return []
|
|
236
241
|
const src = readIfExists(resolve(cwd, rel)) ?? ''
|
|
@@ -243,7 +248,7 @@ const appImports = (cwd: string, cfg: BasaltConfig): [string, string, number][]
|
|
|
243
248
|
const DROPPED_FIXES = new Map([
|
|
244
249
|
[
|
|
245
250
|
'tokens.css',
|
|
246
|
-
|
|
251
|
+
`commit the emit instead: \`basalt-ui tokens:css --out src/tokens.css\` and import that file (${FONTS_CSS_HINT})`,
|
|
247
252
|
],
|
|
248
253
|
[
|
|
249
254
|
'router-tanstack',
|
|
@@ -254,7 +259,7 @@ const DROPPED_FIXES = new Map([
|
|
|
254
259
|
/** `dropped-subpaths`: `basalt-ui/<subpath>` imports the installed `exports` map does not have. */
|
|
255
260
|
export function droppedSubpathsCheck(
|
|
256
261
|
cwd: string,
|
|
257
|
-
|
|
262
|
+
scanned: string[],
|
|
258
263
|
install: BasaltInstall,
|
|
259
264
|
): Check {
|
|
260
265
|
const id = 'dropped-subpaths'
|
|
@@ -270,7 +275,7 @@ export function droppedSubpathsCheck(
|
|
|
270
275
|
(k) => k === `./${sub}` || (k.endsWith('*') && `./${sub}`.startsWith(k.slice(0, -1))),
|
|
271
276
|
)
|
|
272
277
|
const isDropped = (sub: string): boolean => DROPPED_FIXES.has(sub) || !hasExport(sub)
|
|
273
|
-
const found = appImports(cwd,
|
|
278
|
+
const found = appImports(cwd, scanned).filter(([sub]) => isDropped(sub))
|
|
274
279
|
if (found.length === 0) return null
|
|
275
280
|
const hits = found.map(([sub, rel, line]) => `${rel}:${line} imports basalt-ui/${sub}`)
|
|
276
281
|
const more = hits.length > 10 ? ` (+${hits.length - 10} more)` : ''
|
|
@@ -370,42 +375,6 @@ const ROUTER_PLUGIN_FIX =
|
|
|
370
375
|
"from '@tanstack/router-plugin/vite' to `plugins` in vite.config.ts (before react()), then run vite once " +
|
|
371
376
|
'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.'
|
|
372
377
|
|
|
373
|
-
/** True when `{` at `i` opens a `{...spread}`: sticky, so any whitespace width is read. */
|
|
374
|
-
function isSpreadAt(code: string, i: number): boolean {
|
|
375
|
-
const spread = /\{\s*\.\.\./y
|
|
376
|
-
spread.lastIndex = i
|
|
377
|
-
return spread.test(code)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
type ProviderTag = { attrs: string; spread: boolean }
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Every `<BasaltProvider …>` opening tag in a root route: its attribute text at JSX brace depth 0,
|
|
384
|
-
* with string literals skipped (so `className="a > b"` cannot end the tag, nor `"router="` count),
|
|
385
|
-
* and whether a `{...spread}` could carry a `router`.
|
|
386
|
-
*/
|
|
387
|
-
function providerTags(src: string): ProviderTag[] {
|
|
388
|
-
const { code, inLiteral } = tokenize(src)
|
|
389
|
-
return [...code.matchAll(/<BasaltProvider\b/g)]
|
|
390
|
-
.filter((m) => !inLiteral(m.index))
|
|
391
|
-
.map((m) => {
|
|
392
|
-
const tag: ProviderTag = { attrs: '', spread: false }
|
|
393
|
-
let depth = 0
|
|
394
|
-
for (let i = m.index + m[0].length; i < code.length; i++) {
|
|
395
|
-
const ch = code[i]!
|
|
396
|
-
if (inLiteral(i)) continue
|
|
397
|
-
if (ch === '{') {
|
|
398
|
-
if (depth++ === 0 && isSpreadAt(code, i)) tag.spread = true
|
|
399
|
-
} else if (ch === '}') depth--
|
|
400
|
-
else if (ch === '>' && depth === 0) break
|
|
401
|
-
else if (depth === 0) tag.attrs += ch
|
|
402
|
-
}
|
|
403
|
-
return tag
|
|
404
|
-
})
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const carriesRouter = (tag: ProviderTag): boolean => /(^|\s)router\s*=/.test(tag.attrs)
|
|
408
|
-
|
|
409
378
|
/** `_app.tsx` or `_app/route.tsx` at any depth: a pathless layout (`_app.map.tsx` is a child, `__root` is the root). */
|
|
410
379
|
const PATHLESS_LAYOUT = /(^|\/)(_[^_./][^./]*\.[jt]sx|_[^_./][^./]*\/route\.[jt]sx)$/
|
|
411
380
|
|
|
@@ -422,20 +391,21 @@ function filesUnder(cwd: string, rel: string): string[] {
|
|
|
422
391
|
)
|
|
423
392
|
}
|
|
424
393
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
394
|
+
/** The root route and every pathless layout, then the modules they render a provider from (`hops`, one import hop). */
|
|
395
|
+
function startProviderFiles(cwd: string): {
|
|
396
|
+
root: ModuleFile
|
|
397
|
+
layouts: ModuleFile[]
|
|
398
|
+
hops: ModuleFile[]
|
|
399
|
+
far: string[]
|
|
400
|
+
} {
|
|
429
401
|
const rootFile = routerSeedDest('', 'root')
|
|
430
402
|
const routesDir = dirname(rootFile)
|
|
431
|
-
const
|
|
432
|
-
const text = readIfExists(resolve(cwd, file))
|
|
433
|
-
return { file, text, tags: providerTags(text ?? '') }
|
|
434
|
-
}
|
|
403
|
+
const root = loadModule(cwd, rootFile)
|
|
435
404
|
const layouts = filesUnder(cwd, routesDir)
|
|
436
405
|
.filter((f) => PATHLESS_LAYOUT.test(f.slice(routesDir.length + 1)))
|
|
437
406
|
.toSorted()
|
|
438
|
-
|
|
407
|
+
.map((f) => loadModule(cwd, f))
|
|
408
|
+
return { root, layouts, ...followProviderHops(cwd, [root, ...layouts]) }
|
|
439
409
|
}
|
|
440
410
|
|
|
441
411
|
/**
|
|
@@ -465,8 +435,8 @@ const fail = (problem: string, fix: string): { fail: string } => ({
|
|
|
465
435
|
* missing `Route` export is skipped silently, and the context's type argument is left to TypeScript.
|
|
466
436
|
*/
|
|
467
437
|
function startWiring(cwd: string): { fail: string } | null {
|
|
468
|
-
const { root, layouts } = startProviderFiles(cwd)
|
|
469
|
-
const withTags = [root, ...layouts].filter((f) => f.tags.length > 0)
|
|
438
|
+
const { root, layouts, hops, far } = startProviderFiles(cwd)
|
|
439
|
+
const withTags = [root, ...layouts, ...hops].filter((f) => f.tags.length > 0)
|
|
470
440
|
const mounting = withTags.find((f) => f.tags.some(carriesRouter))
|
|
471
441
|
if (mounting) {
|
|
472
442
|
return fail(
|
|
@@ -479,13 +449,22 @@ function startWiring(cwd: string): { fail: string } | null {
|
|
|
479
449
|
const problem =
|
|
480
450
|
root.text === null
|
|
481
451
|
? `${root.file} does not exist and no pathless layout renders <BasaltProvider>`
|
|
482
|
-
: `neither ${root.file} nor a pathless layout (src/routes/_<name>.tsx, _<name>/route.tsx) renders <BasaltProvider>`
|
|
452
|
+
: `neither ${root.file} nor a pathless layout (src/routes/_<name>.tsx, _<name>/route.tsx) renders <BasaltProvider>` +
|
|
453
|
+
(far.length > 0
|
|
454
|
+
? `, and the provider in ${far.join(', ')} is two imports away (doctor follows one import hop from a route file)`
|
|
455
|
+
: '')
|
|
483
456
|
return fail(problem, START_PROVIDER_HINT)
|
|
484
457
|
}
|
|
458
|
+
if (far.length > 0) {
|
|
459
|
+
return fail(
|
|
460
|
+
`${first.file} renders a <BasaltProvider> and so does ${far.join(', ')}, two imports away (doctor follows one import hop from a route file); the extra one nests a duplicate Query/Mantine tree`,
|
|
461
|
+
'keep one',
|
|
462
|
+
)
|
|
463
|
+
}
|
|
485
464
|
const tagCount = withTags.reduce((n, f) => n + f.tags.length, 0)
|
|
486
465
|
if (tagCount > 1) {
|
|
487
466
|
return fail(
|
|
488
|
-
`${withTags.map((f) => f.file).join(' and ')} render ${tagCount} <BasaltProvider> tags; the extra ones nest a duplicate Query/Mantine tree`,
|
|
467
|
+
`${[...new Set(withTags.map((f) => f.file))].join(' and ')} render ${tagCount} <BasaltProvider> tags; the extra ones nest a duplicate Query/Mantine tree`,
|
|
489
468
|
'keep one',
|
|
490
469
|
)
|
|
491
470
|
}
|
|
@@ -508,8 +487,8 @@ function startWiring(cwd: string): { fail: string } | null {
|
|
|
508
487
|
*/
|
|
509
488
|
export function startWiringWarnings(cwd: string): string[] {
|
|
510
489
|
if (!isStartApp(cwd, '')) return []
|
|
511
|
-
const { root, layouts } = startProviderFiles(cwd)
|
|
512
|
-
return [root, ...layouts]
|
|
490
|
+
const { root, layouts, hops } = startProviderFiles(cwd)
|
|
491
|
+
return [...new Set([root, ...layouts, ...hops])]
|
|
513
492
|
.filter((f) => f.tags.some((t) => t.spread))
|
|
514
493
|
.map(
|
|
515
494
|
(f) =>
|
|
@@ -658,12 +637,12 @@ export const SUBPATH_REQUIRED_PEERS: Readonly<Record<string, readonly string[]>>
|
|
|
658
637
|
* `subpath-peers`: every `basalt-ui/<subpath>` the app imports has its required peers installed. A
|
|
659
638
|
* missing one still builds, then throws "Could not resolve" when the chunk loads.
|
|
660
639
|
*/
|
|
661
|
-
export function subpathPeersCheck(cwd: string,
|
|
640
|
+
export function subpathPeersCheck(cwd: string, scanned: string[], install: BasaltInstall): Check {
|
|
662
641
|
const id = 'subpath-peers'
|
|
663
642
|
return withInstall(id, install, 'peers', (dir) => {
|
|
664
643
|
const missing = new Map<string, string[]>()
|
|
665
644
|
for (const [sub, file] of new Map(
|
|
666
|
-
appImports(cwd,
|
|
645
|
+
appImports(cwd, scanned)
|
|
667
646
|
.toReversed()
|
|
668
647
|
.map(([s, f]) => [s, f]),
|
|
669
648
|
)) {
|
package/src/cli/doctor.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
OXLINT_FILES,
|
|
23
23
|
OXLINT_NO_BIN,
|
|
24
24
|
oxlintBinResolves,
|
|
25
|
-
parseJsonc,
|
|
26
25
|
readBasaltConfig,
|
|
27
26
|
readIfExists,
|
|
28
27
|
readManifest,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
scannableFiles,
|
|
35
34
|
shippedAssetPath,
|
|
36
35
|
} from './index'
|
|
36
|
+
import { parseJsonc } from './source-text'
|
|
37
37
|
import { resolveRoots } from './config'
|
|
38
38
|
import {
|
|
39
39
|
appWiringCheck,
|
|
@@ -377,7 +377,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
377
377
|
// ── Hard checks 8-13: strictness and the 1.x → 2.0 upgrade path (./doctor-upgrade) ──────────
|
|
378
378
|
const droppedCheck: [string, Check] = [
|
|
379
379
|
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
380
|
-
droppedSubpathsCheck(appDir, cfg, install),
|
|
380
|
+
droppedSubpathsCheck(appDir, scannableFiles(appDir, cfg), install),
|
|
381
381
|
]
|
|
382
382
|
const runChecks = (checks: [string, Check][]): void => {
|
|
383
383
|
for (const [ok, check] of checks) {
|
|
@@ -407,7 +407,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
407
407
|
['exact-peers: installed exact-pinned peers match basalt-ui', exactPeersCheck(cwd, install)],
|
|
408
408
|
[
|
|
409
409
|
'subpath-peers: every imported basalt-ui subpath has its required peers installed',
|
|
410
|
-
subpathPeersCheck(appDir, cfg, install),
|
|
410
|
+
subpathPeersCheck(appDir, scannableFiles(appDir, cfg), install),
|
|
411
411
|
],
|
|
412
412
|
[
|
|
413
413
|
'config-keys: the basalt config block sets only keys basalt-ui reads',
|
package/src/cli/index.ts
CHANGED
|
@@ -29,9 +29,20 @@ import { guardHook } from './guard-hook'
|
|
|
29
29
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from './help'
|
|
30
30
|
import { init } from './init'
|
|
31
31
|
import { sync } from './sync'
|
|
32
|
-
import {
|
|
32
|
+
import type { BasaltInstall } from './basalt-install'
|
|
33
|
+
import {
|
|
34
|
+
CODE_ROUTED_NOTE,
|
|
35
|
+
ROUTER_SEED_DESTS,
|
|
36
|
+
SHELL_LESS_NOTE,
|
|
37
|
+
START_PROVIDER_HINT,
|
|
38
|
+
routerSeedDest,
|
|
39
|
+
routerSeedDests,
|
|
40
|
+
routerSeedSkip,
|
|
41
|
+
} from './router-wiring'
|
|
33
42
|
import type { RouterSeedSkip } from './router-wiring'
|
|
34
|
-
|
|
43
|
+
|
|
44
|
+
export type { BasaltInstall }
|
|
45
|
+
import { hasDependency, parseJsonc, readIfExists, readPackageJson, stripJsonc } from './source-text'
|
|
35
46
|
import { fontsCss, normalizeColorFunctions, tokensCss } from './tokens-css'
|
|
36
47
|
import { DEFAULT_ROOT, exemptRulePaths, resolveRoots } from './config'
|
|
37
48
|
import type { BasaltConfig } from './config'
|
|
@@ -213,14 +224,6 @@ export function relativePosix(fromDir: string, toPath: string): string {
|
|
|
213
224
|
* resolution walks OUTWARD from the consumer dir, then across workspace packages, and every caller
|
|
214
225
|
* renders its paths from the answer rather than assuming the root.
|
|
215
226
|
*/
|
|
216
|
-
export type BasaltInstall = {
|
|
217
|
-
/** Absolute path of the resolved `node_modules/basalt-ui` directory, or null when unresolvable. */
|
|
218
|
-
dir: string | null
|
|
219
|
-
/** The resolved copy's own version, or null. */
|
|
220
|
-
version: string | null
|
|
221
|
-
/** How it was found — `null` when unresolved. `'workspace'` is the isolated-linker case. */
|
|
222
|
-
how: 'cwd' | 'ancestor' | 'workspace' | null
|
|
223
|
-
}
|
|
224
227
|
|
|
225
228
|
const UNRESOLVED_INSTALL: BasaltInstall = { dir: null, version: null, how: null }
|
|
226
229
|
|
|
@@ -642,28 +645,7 @@ export function importsAgentsMd(text: string): boolean {
|
|
|
642
645
|
/** Scaffold options. `noMergeLint`: `--no-merge-lint` leaves an existing `.oxlintrc.json` untouched. */
|
|
643
646
|
export type ScaffoldFlags = { noMergeLint?: boolean }
|
|
644
647
|
|
|
645
|
-
|
|
646
|
-
export const ROUTER_SEED_DESTS = {
|
|
647
|
-
nav: 'src/lib/nav.tsx',
|
|
648
|
-
root: 'src/routes/__root.tsx',
|
|
649
|
-
main: 'src/main.tsx',
|
|
650
|
-
} as const
|
|
651
|
-
|
|
652
|
-
/** A router seed's dest, relative to the install root: under the app dir when it is not the root. */
|
|
653
|
-
export function routerSeedDest(appRel: string, seed: keyof typeof ROUTER_SEED_DESTS): string {
|
|
654
|
-
return appRel === '' ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`
|
|
655
|
-
}
|
|
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
|
-
/** Where a Start app's embedded provider goes (doctor, init and sync all say it). */
|
|
665
|
-
export const START_PROVIDER_HINT =
|
|
666
|
-
'render <BasaltProvider><Outlet /></BasaltProvider> in the root route component or a pathless layout'
|
|
648
|
+
export { ROUTER_SEED_DESTS, START_PROVIDER_HINT, routerSeedDest, routerSeedDests }
|
|
667
649
|
|
|
668
650
|
export const START_APP_NOTE = `TanStack Start app — no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); ${START_PROVIDER_HINT}.`
|
|
669
651
|
|
|
@@ -1371,45 +1353,6 @@ export function rootsNotices(state: RootsState): { log: string[]; error: string[
|
|
|
1371
1353
|
}
|
|
1372
1354
|
}
|
|
1373
1355
|
|
|
1374
|
-
/**
|
|
1375
|
-
* Strip JSONC comments and trailing commas so oxlint/tsconfig files can be READ (string-aware). A
|
|
1376
|
-
* mangled string fails as a parse error, which callers treat as "cannot tell", never as a pass.
|
|
1377
|
-
*/
|
|
1378
|
-
function stripJsonc(text: string): string {
|
|
1379
|
-
let out = ''
|
|
1380
|
-
let inString = false
|
|
1381
|
-
for (let i = 0; i < text.length; i++) {
|
|
1382
|
-
const ch = text[i] as string
|
|
1383
|
-
if (inString) {
|
|
1384
|
-
out += ch
|
|
1385
|
-
if (ch === '\\') out += text[++i] ?? ''
|
|
1386
|
-
else if (ch === '"') inString = false
|
|
1387
|
-
continue
|
|
1388
|
-
}
|
|
1389
|
-
if (ch === '"') inString = true
|
|
1390
|
-
else if (ch === '/' && text[i + 1] === '/') {
|
|
1391
|
-
while (i < text.length && text[i] !== '\n') i++
|
|
1392
|
-
continue
|
|
1393
|
-
} else if (ch === '/' && text[i + 1] === '*') {
|
|
1394
|
-
i += 2
|
|
1395
|
-
while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++
|
|
1396
|
-
i++
|
|
1397
|
-
continue
|
|
1398
|
-
}
|
|
1399
|
-
out += ch
|
|
1400
|
-
}
|
|
1401
|
-
return out.replace(/,(\s*[}\]])/g, '$1')
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
/** Parse a JSONC document, or null when it does not parse at all. */
|
|
1405
|
-
export function parseJsonc(text: string): Record<string, unknown> | null {
|
|
1406
|
-
try {
|
|
1407
|
-
return JSON.parse(stripJsonc(text.replace(/^\uFEFF/, ''))) as Record<string, unknown>
|
|
1408
|
-
} catch {
|
|
1409
|
-
return null
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
1356
|
/** Outcome of splicing the shipped preset into an `.oxlintrc.json` the consumer already had. */
|
|
1414
1357
|
export type MergeLintResult = 'added' | 'already' | 'absent' | 'unreadable' | 'has-comments'
|
|
1415
1358
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** `<BasaltProvider>` tag reading — a leaf: the CLI's doctor and sync share it without importing each other. */
|
|
2
|
+
import { tokenize } from './source-text'
|
|
3
|
+
|
|
4
|
+
/** True when `{` at `i` opens a `{...spread}`: sticky, so any whitespace width is read. */
|
|
5
|
+
function isSpreadAt(code: string, i: number): boolean {
|
|
6
|
+
const spread = /\{\s*\.\.\./y
|
|
7
|
+
spread.lastIndex = i
|
|
8
|
+
return spread.test(code)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ProviderTag = { attrs: string; spread: boolean }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Every `<BasaltProvider …>` opening tag in a root route: its attribute text at JSX brace depth 0,
|
|
15
|
+
* with string literals skipped (so `className="a > b"` cannot end the tag, nor `"router="` count),
|
|
16
|
+
* and whether a `{...spread}` could carry a `router`.
|
|
17
|
+
*/
|
|
18
|
+
export function providerTags(src: string): ProviderTag[] {
|
|
19
|
+
const { code, inLiteral } = tokenize(src)
|
|
20
|
+
return [...code.matchAll(/<BasaltProvider\b/g)]
|
|
21
|
+
.filter((m) => !inLiteral(m.index))
|
|
22
|
+
.map((m) => {
|
|
23
|
+
const tag: ProviderTag = { attrs: '', spread: false }
|
|
24
|
+
let depth = 0
|
|
25
|
+
for (let i = m.index + m[0].length; i < code.length; i++) {
|
|
26
|
+
const ch = code[i]!
|
|
27
|
+
if (inLiteral(i)) continue
|
|
28
|
+
if (ch === '{') {
|
|
29
|
+
if (depth++ === 0 && isSpreadAt(code, i)) tag.spread = true
|
|
30
|
+
} else if (ch === '}') depth--
|
|
31
|
+
else if (ch === '>' && depth === 0) break
|
|
32
|
+
else if (depth === 0) tag.attrs += ch
|
|
33
|
+
}
|
|
34
|
+
return tag
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const carriesRouter = (tag: ProviderTag): boolean => /(^|\s)router\s*=/.test(tag.attrs)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE import hop `doctor` follows from a Start route file to a component wrapper that holds the
|
|
3
|
+
* `<BasaltProvider>` tag. A leaf: it imports no CLI command module. Textual, so blind to tsconfig
|
|
4
|
+
* `extends` paths, `export … from` re-exports, dynamic `import()` and multi-wildcard `paths`.
|
|
5
|
+
*/
|
|
6
|
+
import { dirname, relative, resolve } from 'node:path'
|
|
7
|
+
|
|
8
|
+
import { providerTags } from './provider-tags'
|
|
9
|
+
import type { ProviderTag } from './provider-tags'
|
|
10
|
+
import { parseJsonc, readIfExists, tokenize } from './source-text'
|
|
11
|
+
|
|
12
|
+
export type ModuleFile = { file: string; text: string | null; tags: ProviderTag[] }
|
|
13
|
+
|
|
14
|
+
/** One read path for every module in the walk; `text` is null for a missing file. */
|
|
15
|
+
export function loadModule(cwd: string, file: string): ModuleFile {
|
|
16
|
+
const text = readIfExists(resolve(cwd, file))
|
|
17
|
+
return { file, text, tags: providerTags(text ?? '') }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MODULE_SUFFIXES = ['.tsx', '.ts', '.jsx', '.js', '/index.tsx', '/index.ts']
|
|
21
|
+
|
|
22
|
+
type Alias = [prefix: string, dir: string]
|
|
23
|
+
|
|
24
|
+
/** tsconfig `compilerOptions.paths` single-wildcard `alias/*` entries; a malformed shape is no alias. */
|
|
25
|
+
export function pathAliases(cwd: string): Alias[] {
|
|
26
|
+
const opts = parseJsonc(readIfExists(resolve(cwd, 'tsconfig.json')) ?? '')?.['compilerOptions']
|
|
27
|
+
if (typeof opts !== 'object' || opts === null) return []
|
|
28
|
+
const { baseUrl, paths } = opts as { baseUrl?: unknown; paths?: Record<string, unknown> | null }
|
|
29
|
+
if (typeof paths !== 'object' || paths === null || Array.isArray(paths)) return []
|
|
30
|
+
const base = typeof baseUrl === 'string' ? baseUrl : '.'
|
|
31
|
+
return Object.entries(paths).flatMap(([pattern, targets]) => {
|
|
32
|
+
const target: unknown = Array.isArray(targets) ? targets[0] : undefined
|
|
33
|
+
if (!pattern.endsWith('/*') || typeof target !== 'string' || !target.endsWith('/*')) return []
|
|
34
|
+
return [[pattern.slice(0, -1), `${base}/${target.slice(0, -1)}`]]
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const aliasedBase = (cwd: string, spec: string, aliases: Alias[]): string | undefined => {
|
|
39
|
+
const hit = aliases.find(([prefix]) => spec.startsWith(prefix))
|
|
40
|
+
return hit === undefined ? undefined : resolve(cwd, hit[1] + spec.slice(hit[0].length))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const escapeRegex = (name: string): string => name.replaceAll('$', String.raw`\$`)
|
|
44
|
+
|
|
45
|
+
/** The local modules `file` renders a component from: `<Name` in JSX, name imported from a relative or aliased specifier. */
|
|
46
|
+
export function renderedImports(
|
|
47
|
+
cwd: string,
|
|
48
|
+
file: string,
|
|
49
|
+
text: string,
|
|
50
|
+
aliases: Alias[],
|
|
51
|
+
): string[] {
|
|
52
|
+
const { code, inLiteral } = tokenize(text)
|
|
53
|
+
const found = new Set<string>()
|
|
54
|
+
for (const m of code.matchAll(/\bimport\s+(?!type\b)([^'"]*?)\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
55
|
+
if (inLiteral(m.index)) continue
|
|
56
|
+
const spec = m[2]!.replace(/\.[jt]sx?$/, '')
|
|
57
|
+
const base = spec.startsWith('.')
|
|
58
|
+
? resolve(cwd, dirname(file), spec)
|
|
59
|
+
: aliasedBase(cwd, spec, aliases)
|
|
60
|
+
if (base === undefined) continue
|
|
61
|
+
const names = [...m[1]!.replace(/\btype\s+/g, '').matchAll(/[A-Za-z_$][\w$]*/g)].map(
|
|
62
|
+
(n) => n[0],
|
|
63
|
+
)
|
|
64
|
+
if (!names.some((n) => new RegExp(`<${escapeRegex(n)}\\b`).test(code))) continue
|
|
65
|
+
const rel = relative(cwd, base).split('\\').join('/')
|
|
66
|
+
const hit = MODULE_SUFFIXES.map((x) => rel + x).find(
|
|
67
|
+
(c) => readIfExists(resolve(cwd, c)) !== null,
|
|
68
|
+
)
|
|
69
|
+
if (hit !== undefined) found.add(hit)
|
|
70
|
+
}
|
|
71
|
+
return [...found]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `hops`: one entry per render EDGE (scanned file -> rendered module holding a provider tag), so the
|
|
76
|
+
* same wrapper rendered from two route files counts twice. `far`: provider-holding modules one more hop out, which doctor does not follow but
|
|
77
|
+
* names (the one-provider invariant and the failure message both need them).
|
|
78
|
+
*/
|
|
79
|
+
export function followProviderHops(
|
|
80
|
+
cwd: string,
|
|
81
|
+
scanned: ModuleFile[],
|
|
82
|
+
): { hops: ModuleFile[]; far: string[] } {
|
|
83
|
+
const aliases = pathAliases(cwd)
|
|
84
|
+
const modules = new Map(scanned.map((f) => [f.file, f]))
|
|
85
|
+
const load = (file: string): ModuleFile => {
|
|
86
|
+
const known = modules.get(file) ?? loadModule(cwd, file)
|
|
87
|
+
modules.set(file, known)
|
|
88
|
+
return known
|
|
89
|
+
}
|
|
90
|
+
const hops: ModuleFile[] = []
|
|
91
|
+
const far = new Set<string>()
|
|
92
|
+
for (const f of scanned) {
|
|
93
|
+
for (const mod of renderedImports(cwd, f.file, f.text ?? '', aliases)) {
|
|
94
|
+
if (scanned.some((s) => s.file === mod)) continue
|
|
95
|
+
const hop = load(mod)
|
|
96
|
+
if (hop.tags.length > 0) hops.push(hop)
|
|
97
|
+
for (const next of renderedImports(cwd, mod, hop.text ?? '', aliases)) {
|
|
98
|
+
if (!scanned.some((s) => s.file === next) && load(next).tags.length > 0) far.add(next)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const nearFiles = new Set(hops.map((h) => h.file))
|
|
103
|
+
return { hops, far: [...far].filter((f) => !nearFiles.has(f)) }
|
|
104
|
+
}
|
package/src/cli/router-wiring.ts
CHANGED
|
@@ -187,3 +187,26 @@ export function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip {
|
|
|
187
187
|
|
|
188
188
|
export const SHELL_LESS_NOTE =
|
|
189
189
|
'`basalt.shell: false` — no main.tsx/nav.tsx/__root.tsx seeded; the app owns its root route (or has none).'
|
|
190
|
+
|
|
191
|
+
/** The router seeds (TanStack Router and Query are required peers of `.`, so they are always written). */
|
|
192
|
+
export const ROUTER_SEED_DESTS = {
|
|
193
|
+
nav: 'src/lib/nav.tsx',
|
|
194
|
+
root: 'src/routes/__root.tsx',
|
|
195
|
+
main: 'src/main.tsx',
|
|
196
|
+
} as const
|
|
197
|
+
|
|
198
|
+
/** A router seed's dest, relative to the install root: under the app dir when it is not the root. */
|
|
199
|
+
export function routerSeedDest(appRel: string, seed: keyof typeof ROUTER_SEED_DESTS): string {
|
|
200
|
+
return appRel === '' ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The router seeds' dests for an app dir (`main.tsx`, `nav.tsx`, `__root.tsx`). */
|
|
204
|
+
export function routerSeedDests(appRel: string): string[] {
|
|
205
|
+
return (Object.keys(ROUTER_SEED_DESTS) as (keyof typeof ROUTER_SEED_DESTS)[]).map((seed) =>
|
|
206
|
+
routerSeedDest(appRel, seed),
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Where a Start app's embedded provider goes (doctor, init and sync all say it). */
|
|
211
|
+
export const START_PROVIDER_HINT =
|
|
212
|
+
'render <BasaltProvider><Outlet /></BasaltProvider> in the root route component or a pathless layout'
|
package/src/cli/source-text.ts
CHANGED
|
@@ -60,3 +60,42 @@ export function tokenize(src: string): { code: string; inLiteral: (at: number) =
|
|
|
60
60
|
})
|
|
61
61
|
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) }
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Strip JSONC comments and trailing commas so oxlint/tsconfig files can be READ (string-aware). A
|
|
66
|
+
* mangled string fails as a parse error, which callers treat as "cannot tell", never as a pass.
|
|
67
|
+
*/
|
|
68
|
+
export function stripJsonc(text: string): string {
|
|
69
|
+
let out = ''
|
|
70
|
+
let inString = false
|
|
71
|
+
for (let i = 0; i < text.length; i++) {
|
|
72
|
+
const ch = text[i] as string
|
|
73
|
+
if (inString) {
|
|
74
|
+
out += ch
|
|
75
|
+
if (ch === '\\') out += text[++i] ?? ''
|
|
76
|
+
else if (ch === '"') inString = false
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
if (ch === '"') inString = true
|
|
80
|
+
else if (ch === '/' && text[i + 1] === '/') {
|
|
81
|
+
while (i < text.length && text[i] !== '\n') i++
|
|
82
|
+
continue
|
|
83
|
+
} else if (ch === '/' && text[i + 1] === '*') {
|
|
84
|
+
i += 2
|
|
85
|
+
while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++
|
|
86
|
+
i++
|
|
87
|
+
continue
|
|
88
|
+
}
|
|
89
|
+
out += ch
|
|
90
|
+
}
|
|
91
|
+
return out.replace(/,(\s*[}\]])/g, '$1')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Parse a JSONC document, or null when it does not parse at all. */
|
|
95
|
+
export function parseJsonc(text: string): Record<string, unknown> | null {
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(stripJsonc(text.replace(/^\uFEFF/, ''))) as Record<string, unknown>
|
|
98
|
+
} catch {
|
|
99
|
+
return null
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/cli/sync.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { resolve } from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
import { deriveSpacing } from '../tokens/core'
|
|
6
6
|
import { shellConfigError } from './config'
|
|
7
|
+
import type { RouterSeedSkip } from './router-wiring'
|
|
8
|
+
import { carriesRouter, providerTags } from './provider-tags'
|
|
7
9
|
import {
|
|
8
10
|
MANIFEST_PATH,
|
|
9
11
|
basaltPresetEntry,
|
|
@@ -18,7 +20,6 @@ import {
|
|
|
18
20
|
normalizeForLedger,
|
|
19
21
|
noteRelocation,
|
|
20
22
|
OXLINT_FILES,
|
|
21
|
-
parseJsonc,
|
|
22
23
|
placementNotices,
|
|
23
24
|
pruneRetiredManagedFiles,
|
|
24
25
|
readBasaltConfig,
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
writeFileEnsuringDir,
|
|
42
43
|
writeUnit,
|
|
43
44
|
} from './index'
|
|
45
|
+
import { parseJsonc } from './source-text'
|
|
44
46
|
import { findManifestAbove, installRootAbove } from './install-root'
|
|
45
47
|
|
|
46
48
|
/** The oxlint plugins the shipped preset switches on — read from the preset, never restated. */
|
|
@@ -67,6 +69,12 @@ export function parentInstallAdvice(cwd: string, parent: string, verb: string):
|
|
|
67
69
|
)
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
const RETIRED_BECAUSE = {
|
|
73
|
+
'code-routed': 'code-routed app',
|
|
74
|
+
start: 'TanStack Start app',
|
|
75
|
+
'shell-less': 'basalt.shell: false',
|
|
76
|
+
} as const satisfies Record<NonNullable<RouterSeedSkip>, string>
|
|
77
|
+
|
|
70
78
|
/**
|
|
71
79
|
* Reconcile managed files with the shipped versions via a sha256 three-way compare.
|
|
72
80
|
*
|
|
@@ -208,16 +216,18 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
208
216
|
})
|
|
209
217
|
staleForCheck += pruned.removed.length + pruned.drifted.length
|
|
210
218
|
|
|
211
|
-
// A code-routed or declared shell-less app takes no router seeds: their manifest entries
|
|
212
|
-
// (so the next sync does not resurrect them); any file stays the consumer's.
|
|
219
|
+
// A code-routed, Start or declared shell-less app takes no router seeds: their manifest entries
|
|
220
|
+
// go (so the next sync does not resurrect them); any file stays the consumer's.
|
|
213
221
|
const isTracked = (d: string): boolean => manifest.files[d] !== undefined
|
|
214
|
-
const retiredBecause =
|
|
215
|
-
seedSkip === 'code-routed'
|
|
216
|
-
? 'code-routed app'
|
|
217
|
-
: seedSkip === 'shell-less'
|
|
218
|
-
? 'basalt.shell: false'
|
|
219
|
-
: null
|
|
222
|
+
const retiredBecause = seedSkip === null ? null : RETIRED_BECAUSE[seedSkip]
|
|
220
223
|
const retiredSeeds = retiredBecause === null ? [] : [...skipped].filter(isTracked)
|
|
224
|
+
// Start is the new retirement: a gate green over seeds the next sync would drop is a stale gate.
|
|
225
|
+
if (opts.check && seedSkip === 'start' && retiredSeeds.length > 0) {
|
|
226
|
+
staleForCheck += retiredSeeds.length
|
|
227
|
+
console.error(
|
|
228
|
+
`basalt-ui sync --check: ${retiredSeeds.join(', ')} still tracked in the manifest of a TanStack Start app. Fix: run \`basalt-ui sync\`.`,
|
|
229
|
+
)
|
|
230
|
+
}
|
|
221
231
|
if (retiredSeeds.length > 0 && !opts.check) {
|
|
222
232
|
for (const d of retiredSeeds) delete manifest.files[d]
|
|
223
233
|
console.error(
|
|
@@ -228,20 +238,16 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
228
238
|
// Placement notices — informational, never affecting the exit code, and PERMANENT: `--check`
|
|
229
239
|
// hides them behind `--verbose` (it sits in consumers' CI chains, where three unchanging
|
|
230
240
|
// "skipped" paragraphs per run are noise indistinguishable from drift) but still prints the COUNT.
|
|
231
|
-
// Start
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
241
|
+
// A Start app's leftover seed is judged by CONTENT: only a `<BasaltProvider router=…>` tag mounts one.
|
|
242
|
+
const mounting =
|
|
243
|
+
seedSkip === 'start'
|
|
244
|
+
? [...skipped].filter((d) =>
|
|
245
|
+
providerTags(readIfExists(resolve(cwd, d)) ?? '').some(carriesRouter),
|
|
246
|
+
)
|
|
247
|
+
: []
|
|
237
248
|
if (mounting.length > 0) {
|
|
238
249
|
console.error(
|
|
239
|
-
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. ${embedded
|
|
240
|
-
)
|
|
241
|
-
}
|
|
242
|
-
if (inert.length > 0) {
|
|
243
|
-
console.error(
|
|
244
|
-
`⚠ basalt-ui sync: ${inert.join(', ')} was seeded before this became a Start app; it mounts nothing, so keep or delete it. Left untouched.`,
|
|
250
|
+
`⚠ basalt-ui sync: ${mounting.join(', ')} mount a second router inside this TanStack Start app; left untouched. Delete them and ${START_PROVIDER_HINT} (embedded mode).`,
|
|
245
251
|
)
|
|
246
252
|
}
|
|
247
253
|
if (seedSkip === 'start' && (!opts.check || syncFlags.includes('--verbose')))
|