basalt-ui 2.8.0 → 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 +186 -190
- package/MIGRATING.md +52 -13
- 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 +17 -13
- 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/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 +15 -10
- 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.map +1 -1
- package/dist/provider/index.js +3 -2
- 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 +4 -3
- package/package.json +1 -1
- package/src/cli/doctor-upgrade.ts +29 -145
- package/src/cli/doctor.ts +19 -14
- package/src/cli/index.ts +26 -41
- package/src/cli/init.ts +9 -6
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +17 -10
- 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 +6 -3
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginOption, UserConfig } from 'vite';
|
|
2
|
+
import type { BootColorScheme } from './vite-boot.js';
|
|
2
3
|
type BasaltViteOptions = {
|
|
3
4
|
/** Dev server port. Passed with `strictPort: true` so the app fails fast on a busy port. */
|
|
4
5
|
port: number;
|
|
@@ -80,9 +81,29 @@ type BasaltAppOptions = {
|
|
|
80
81
|
*
|
|
81
82
|
* Set this to whatever the app passes as `defaultColorScheme` — a mismatch is a visible flash of
|
|
82
83
|
* the wrong surface, not a correctness bug: the boot rule stops applying the moment Mantine
|
|
83
|
-
* writes `data-mantine-color-scheme` on `<html>` (see `
|
|
84
|
+
* writes `data-mantine-color-scheme` on `<html>` (see `./vite-boot.ts`).
|
|
84
85
|
*/
|
|
85
|
-
colorScheme?:
|
|
86
|
+
colorScheme?: BootColorScheme;
|
|
87
|
+
/**
|
|
88
|
+
* Default `true`. Injects a ~300-byte inline `<script>` that reads the scheme the user last chose
|
|
89
|
+
* (Mantine's default `mantine-color-scheme-value` localStorage key — `light`, `dark` or `auto`,
|
|
90
|
+
* `auto` resolved through `prefers-color-scheme`) and sets a boot-only `data-basalt-boot`
|
|
91
|
+
* attribute on `<html>`, so the pre-boot paint matches the stored scheme instead of the build-time
|
|
92
|
+
* `colorScheme`. Storage unavailable or unset → the `colorScheme` paint stands. The script never
|
|
93
|
+
* writes `data-mantine-color-scheme`, so the boot rule still expires when Mantine mounts.
|
|
94
|
+
*
|
|
95
|
+
* `colorScheme: false` still gets the stored-scheme background paint; only `color-scheme` is
|
|
96
|
+
* suppressed. A stored value wins over the build-time `colorScheme`: an app that removes its scheme toggle
|
|
97
|
+
* should clear the stored key or set `bootScript: false`.
|
|
98
|
+
*
|
|
99
|
+
* CSP: Vite stamps `html.cspNonce` onto every `<script>`/`<style>` in the transformed HTML,
|
|
100
|
+
* plugin-injected ones included, so one nonce covers both boot tags. Without a nonce, a CSP that
|
|
101
|
+
* forbids inline scripts needs `bootScript: false`.
|
|
102
|
+
*
|
|
103
|
+
* Also set `false` when `BasaltProvider` gets a custom `colorSchemeManager` with another key
|
|
104
|
+
* (e.g. `localStorageColorSchemeManager({ key })`) — the script reads only the default key.
|
|
105
|
+
*/
|
|
106
|
+
bootScript?: boolean;
|
|
86
107
|
/**
|
|
87
108
|
* Manifest `background_color` + anti-FOUC paint color. Default: the theme color matching
|
|
88
109
|
* `colorScheme` (the dark one for `'dark'` / `'auto'` / `false`, the light one for `'light'`).
|
|
@@ -165,7 +186,7 @@ type BasaltAppOptions = {
|
|
|
165
186
|
* • It HOISTS the shell's `<meta charset>` ahead of everything it injects, so the encoding
|
|
166
187
|
* declaration stays inside the spec's first 1024 bytes (see `hoistCharset`).
|
|
167
188
|
* • The anti-FOUC `<style>` expires the moment Mantine resolves the real scheme, and `colorScheme`
|
|
168
|
-
* selects which surface it paints until then (see `
|
|
189
|
+
* selects which surface it paints until then (see `./vite-boot.ts`).
|
|
169
190
|
*
|
|
170
191
|
* @example
|
|
171
192
|
* // vite.config.ts
|
package/dist/vite.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAA6B,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAA6B,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAG/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGlD,KAAK,iBAAiB,GAAG;IACvB,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAA;IACZ,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AA6CD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,UAAU,CAgFpE;AAgBD;;;;;;;GAOG;AACH,KAAK,aAAa,GAAG;IACnB,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAA;IACX,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,kBAAkB,GAAG,WAAW,CAAA;CAClE,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,gGAAgG;IAChG,IAAI,EAAE,MAAM,CAAA;IACZ,0DAA0D;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gGAAgG;IAChG,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACrD;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B;;;;;;;;;;;;;;;;;;OAkBG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,wDAAwD;IACxD,OAAO,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,CAAA;IAChE;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,mGAAmG;IACnG,EAAE,CAAC,EAAE,MAAM,CAAA;IACX;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,aAAa,EAAE,CAAA;IAC3D,8FAA8F;IAC9F,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IAC3B,oFAAoF;IACpF,GAAG,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,SAAS,GAAG,qBAAqB,CAAA;KAAE,CAAA;IACvF,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClD,CAAA;AAuhBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAMzE"}
|
package/dist/vite.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
3
|
import { searchForWorkspaceRoot } from "vite";
|
|
4
4
|
import { SURFACE } from "./tokens/palette.js";
|
|
5
|
+
import { buildBootTags } from "./vite-boot.js";
|
|
5
6
|
import { resolveColorMix } from "./vite-color-mix.js";
|
|
6
7
|
const UNENFORCED_SEARCH_DEPTH = 3;
|
|
7
8
|
let unenforcedNoticePrinted = false;
|
|
@@ -152,17 +153,6 @@ const VIEWPORT_TAG = {
|
|
|
152
153
|
tag: "meta",
|
|
153
154
|
attrs: { name: "viewport", content: "width=device-width, initial-scale=1.0, viewport-fit=cover" }
|
|
154
155
|
};
|
|
155
|
-
const BOOT_SCOPE = "html:not([data-mantine-color-scheme])";
|
|
156
|
-
const BOOT_COLOR_SCHEME = { dark: "dark", light: "light", auto: "light dark" };
|
|
157
|
-
function buildBootStyle(input) {
|
|
158
|
-
const { colorScheme, themeColor, backgroundColor, explicitBackground } = input;
|
|
159
|
-
if (colorScheme === false) return `${BOOT_SCOPE}{background-color:${backgroundColor}}`;
|
|
160
|
-
const scheme = BOOT_COLOR_SCHEME[colorScheme];
|
|
161
|
-
if (colorScheme !== "auto" || explicitBackground) {
|
|
162
|
-
return `${BOOT_SCOPE}{background-color:${backgroundColor};color-scheme:${scheme}}`;
|
|
163
|
-
}
|
|
164
|
-
return `${BOOT_SCOPE}{background-color:${themeColor.light};color-scheme:${scheme}}@media(prefers-color-scheme:dark){${BOOT_SCOPE}{background-color:${themeColor.dark}}}`;
|
|
165
|
-
}
|
|
166
156
|
const CHARSET_META_RE = /[ \t]*<meta\s+charset\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>=]+))\s*\/?>[ \t]*\r?\n?/i;
|
|
167
157
|
const HTTP_EQUIV_CHARSET_RE = /<meta\s[^>]*http-equiv\s*=\s*["']?content-type["']?[^>]*>/i;
|
|
168
158
|
const DEFAULT_CHARSET = "UTF-8";
|
|
@@ -218,7 +208,7 @@ function buildStaticTags(input) {
|
|
|
218
208
|
options,
|
|
219
209
|
shortName,
|
|
220
210
|
themeColor,
|
|
221
|
-
|
|
211
|
+
bootTags,
|
|
222
212
|
icons,
|
|
223
213
|
darkreader,
|
|
224
214
|
manifestEnabled,
|
|
@@ -244,7 +234,7 @@ function buildStaticTags(input) {
|
|
|
244
234
|
}
|
|
245
235
|
}
|
|
246
236
|
);
|
|
247
|
-
tags.push(
|
|
237
|
+
tags.push(...bootTags);
|
|
248
238
|
if (icons.mode === "default") {
|
|
249
239
|
tags.push(
|
|
250
240
|
{
|
|
@@ -384,11 +374,12 @@ function createMainPlugin(options) {
|
|
|
384
374
|
const colorScheme = options.colorScheme ?? "dark";
|
|
385
375
|
const schemeColor = colorScheme === "light" ? themeColor.light : themeColor.dark;
|
|
386
376
|
const backgroundColor = options.backgroundColor ?? schemeColor;
|
|
387
|
-
const
|
|
377
|
+
const bootTags = buildBootTags({
|
|
388
378
|
colorScheme,
|
|
389
379
|
themeColor,
|
|
390
380
|
backgroundColor,
|
|
391
|
-
explicitBackground: options.backgroundColor !== void 0
|
|
381
|
+
explicitBackground: options.backgroundColor !== void 0,
|
|
382
|
+
bootScript: options.bootScript !== false
|
|
392
383
|
});
|
|
393
384
|
let manifestJson = "";
|
|
394
385
|
let manifestHref = "/site.webmanifest";
|
|
@@ -417,7 +408,7 @@ function createMainPlugin(options) {
|
|
|
417
408
|
options,
|
|
418
409
|
shortName,
|
|
419
410
|
themeColor,
|
|
420
|
-
|
|
411
|
+
bootTags,
|
|
421
412
|
icons,
|
|
422
413
|
darkreader,
|
|
423
414
|
manifestEnabled,
|
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.8.
|
|
1
|
+
# basalt-ui v2.8.1
|
|
2
2
|
# Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
|
|
3
3
|
#
|
|
4
4
|
# Entry points: use the exact import specifier below; do not guess.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
|
|
14
14
|
|
|
15
15
|
Package: basalt-ui
|
|
16
|
-
Version: 2.8.
|
|
16
|
+
Version: 2.8.1
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -468,7 +468,8 @@ Signature: basaltAppPlugin(options: BasaltAppOptions): PluginOption[]
|
|
|
468
468
|
shortName?: string
|
|
469
469
|
description?: string
|
|
470
470
|
themeColor?: "auto" | { light: string; dark: string; }
|
|
471
|
-
colorScheme?:
|
|
471
|
+
colorScheme?: BootColorScheme
|
|
472
|
+
bootScript?: boolean
|
|
472
473
|
backgroundColor?: string
|
|
473
474
|
display?: "standalone" | "minimal-ui" | "fullscreen" | "browser"
|
|
474
475
|
startUrl?: string
|
package/package.json
CHANGED
|
@@ -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
|
@@ -109,7 +109,8 @@ function aiMajorsAt(dir: string): Partial<Record<AiMajorField, number>> {
|
|
|
109
109
|
* 7. `ai-major-parity`: the `ai` major agrees across this package.json's dependency fields
|
|
110
110
|
* (exempt via `basalt.aiMajorSkewReason`; a stale reason warns).
|
|
111
111
|
* 8-14. `tsconfig-base`, `retired-lint-rules`, `dropped-subpaths`, `app-wiring`, `exact-peers`,
|
|
112
|
-
* `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);
|
|
113
114
|
* a check that cannot run is SKIPPED and exits non-zero.
|
|
114
115
|
*
|
|
115
116
|
* Warning (non-fatal):
|
|
@@ -384,24 +385,33 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
384
385
|
}
|
|
385
386
|
|
|
386
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
|
+
}
|
|
387
399
|
if (profile === 'tokens-only') {
|
|
388
400
|
pass(
|
|
389
|
-
'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',
|
|
390
402
|
)
|
|
403
|
+
runChecks([droppedCheck])
|
|
391
404
|
} else {
|
|
392
|
-
|
|
405
|
+
runChecks([
|
|
393
406
|
['tsconfig-base: tsconfig.json extends the shipped preset', tsconfigBaseCheck(appDir)],
|
|
394
407
|
[
|
|
395
408
|
'retired-lint-rules: .oxlintrc.json sets no retired basalt/* rule',
|
|
396
409
|
retiredLintRulesCheck(cwd, install),
|
|
397
410
|
],
|
|
398
|
-
|
|
399
|
-
'dropped-subpaths: no import of a basalt-ui subpath the install lacks',
|
|
400
|
-
droppedSubpathsCheck(appDir, cfg, install),
|
|
401
|
-
],
|
|
411
|
+
droppedCheck,
|
|
402
412
|
['oxlint-floor: the installed oxlint parses the shipped preset', oxlintFloorCheck(cwd)],
|
|
403
413
|
[
|
|
404
|
-
'app-wiring: the entry mounts BasaltProvider and the router tree
|
|
414
|
+
'app-wiring: the entry mounts BasaltProvider and the router tree exists',
|
|
405
415
|
appWiringCheck(appDir),
|
|
406
416
|
],
|
|
407
417
|
['exact-peers: installed exact-pinned peers match basalt-ui', exactPeersCheck(cwd, install)],
|
|
@@ -413,12 +423,7 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
413
423
|
'config-keys: the basalt config block sets only keys basalt-ui reads',
|
|
414
424
|
unknownConfigKeysCheck(cwd),
|
|
415
425
|
],
|
|
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
|
-
}
|
|
426
|
+
])
|
|
422
427
|
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
423
428
|
}
|
|
424
429
|
|
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))
|
|
@@ -677,15 +661,29 @@ export function routerSeedDests(appRel: string): string[] {
|
|
|
677
661
|
)
|
|
678
662
|
}
|
|
679
663
|
|
|
680
|
-
/** A TanStack Start app owns its router, so its router seeds give way to an in-tree `<BasaltProvider>`. */
|
|
681
|
-
export function isStartApp(cwd: string, appRel: string): boolean {
|
|
682
|
-
return hasDependency(resolve(cwd, appRel), '@tanstack/react-start')
|
|
683
|
-
}
|
|
684
|
-
|
|
685
664
|
export const START_APP_NOTE =
|
|
686
665
|
'TanStack Start app — no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); render ' +
|
|
687
666
|
'<BasaltProvider><Outlet /></BasaltProvider> in your root route component.'
|
|
688
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
|
+
|
|
689
687
|
/** The app directory a command's app-scoped half targets: `rel` is '' when it is the install root. */
|
|
690
688
|
export type AppResolution = { dir: string; rel: string } | { error: string }
|
|
691
689
|
|
|
@@ -731,22 +729,6 @@ export function resolveAppDir(root: string): AppResolution {
|
|
|
731
729
|
}
|
|
732
730
|
}
|
|
733
731
|
|
|
734
|
-
/** True when `pkgName` appears in the consumer's dependencies, devDependencies, or peerDependencies. */
|
|
735
|
-
function hasDependency(cwd: string, pkgName: string): boolean {
|
|
736
|
-
const pkg =
|
|
737
|
-
readPackageJson<
|
|
738
|
-
Record<
|
|
739
|
-
'dependencies' | 'devDependencies' | 'peerDependencies',
|
|
740
|
-
Record<string, string> | undefined
|
|
741
|
-
>
|
|
742
|
-
>(cwd)
|
|
743
|
-
return Boolean(
|
|
744
|
-
pkg?.dependencies?.[pkgName] ??
|
|
745
|
-
pkg?.devDependencies?.[pkgName] ??
|
|
746
|
-
pkg?.peerDependencies?.[pkgName],
|
|
747
|
-
)
|
|
748
|
-
}
|
|
749
|
-
|
|
750
732
|
/**
|
|
751
733
|
* Where the seed engine is running relative to the consumer's git repo — decides which
|
|
752
734
|
* repo-root-shaped seeds are safe to write. `init`/`sync` compute it once per run via
|
|
@@ -1225,7 +1207,8 @@ export function writeUnit(file: ManagedFile, cwd: string, desired: string): stri
|
|
|
1225
1207
|
* - missing : absent on disk → recreate.
|
|
1226
1208
|
* - current : on disk == desired → nothing to do.
|
|
1227
1209
|
* - unchanged: on disk matches a KNOWN-SHIPPED rendering (raw manifest hash, normalized manifest
|
|
1228
|
-
* 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.
|
|
1229
1212
|
* - drifted : matches none of them (a real local edit) → skip unless --force.
|
|
1230
1213
|
*/
|
|
1231
1214
|
export function classify(state: UnitState, manifestHash: string | undefined): Classification {
|
|
@@ -1784,6 +1767,8 @@ export function run(argv: string[], cwd: string = process.cwd()): number | Promi
|
|
|
1784
1767
|
}
|
|
1785
1768
|
|
|
1786
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'
|
|
1787
1772
|
export { RULE_NAMES, SKILL_NAMES }
|
|
1788
1773
|
export type { ManagedFile }
|
|
1789
1774
|
|
package/src/cli/init.ts
CHANGED
|
@@ -11,9 +11,8 @@ import type { MergeLintResult, ScaffoldFlags } from './index'
|
|
|
11
11
|
import {
|
|
12
12
|
MANIFEST_PATH,
|
|
13
13
|
declaredProfile,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
START_APP_NOTE,
|
|
14
|
+
routerSeedPlan,
|
|
15
|
+
seedSkipNote,
|
|
17
16
|
readBasaltConfig,
|
|
18
17
|
findBasaltInstall,
|
|
19
18
|
managedFiles,
|
|
@@ -128,8 +127,11 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
128
127
|
const placement = resolvePlacement(cwd)
|
|
129
128
|
// A tokens-only consumer has no use for the Mantine/React scaffolds (doctor skips them there too).
|
|
130
129
|
const tokensOnly = declaredProfile(readBasaltConfig(cwd), []) === 'tokens-only'
|
|
131
|
-
const
|
|
132
|
-
|
|
130
|
+
const { skip: seedSkip, skipped: skippedSeeds } = routerSeedPlan(
|
|
131
|
+
cwd,
|
|
132
|
+
placement.appRel,
|
|
133
|
+
tokensOnly,
|
|
134
|
+
)
|
|
133
135
|
const files = managedFiles(placement).filter((f) => !skippedSeeds.has(f.dest))
|
|
134
136
|
|
|
135
137
|
const writtenFiles: string[] = []
|
|
@@ -205,7 +207,8 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
205
207
|
const tsconfigLine = tokensOnly ? null : seedTsconfigExtends(cwd)
|
|
206
208
|
if (tsconfigLine !== null) console.log(`basalt-ui init: ${tsconfigLine}`)
|
|
207
209
|
if (buildNote !== null) console.log(`basalt-ui init: ${buildNote}`)
|
|
208
|
-
|
|
210
|
+
const skipNote = seedSkipNote(seedSkip)
|
|
211
|
+
if (skipNote !== null) console.log(`basalt-ui init: ${skipNote}`)
|
|
209
212
|
const rootsMessages = rootsNotices(rootsState)
|
|
210
213
|
for (const line of rootsMessages.log) console.log(`basalt-ui init: ${line}`)
|
|
211
214
|
for (const line of rootsMessages.error) console.error(`⚠ basalt-ui init: ${line}`)
|