uniweb 1.29.3 → 1.30.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniweb",
3
- "version": "1.29.3",
3
+ "version": "1.30.1",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,15 +41,15 @@
41
41
  "js-yaml": "^4.3.2",
42
42
  "prompts": "^2.4.2",
43
43
  "tar": "^7.5.21",
44
- "@uniweb/core": "~1.6.8",
44
+ "@uniweb/core": "~1.6.9",
45
45
  "@uniweb/semantic-parser": "~1.13.2",
46
46
  "@uniweb/schemas": "~1.6.11",
47
47
  "@uniweb/content-writer": "~1.3.1"
48
48
  },
49
49
  "peerDependencies": {
50
- "@uniweb/semantic-parser": "~1.13.2",
51
50
  "@uniweb/content-reader": "~1.5.9",
52
- "@uniweb/build": "~1.18.2"
51
+ "@uniweb/semantic-parser": "~1.13.2",
52
+ "@uniweb/build": "~1.19.1"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "@uniweb/build": {
@@ -247,6 +247,8 @@ extensions: ['@acme/fx@0.3.1']
247
247
 
248
248
  **A folder of pages holds pages of one section.** Under a `folder.yml`, each page is one `.md` file of one section, and each subfolder is a folder of pages too. The build stops on a subfolder with a `page.yml` of its own, a parametric `[slug]/` included. A page of several sections goes outside the folder. In the app, such a page takes no second section, and a pull holds one made there.
249
249
 
250
+ **Such a page's frontmatter holds its page's settings**, beside its section's `type:` and params: `title` (else its H1), `description`, `label`, `keywords`, `slug`, `hideIn`, `layout`, `seo`, `knowledge`, `trackSections`, as in a `page.yml`. A section param with one of those names goes under `props:` (`props: { label: … }`); the build warns where the section type declares one. `id:` is the section's id there too, and `hidden:` drafts the page. A pull writes the app's changes to them back into the file.
251
+
250
252
  **Routes:** folders map 1:1 to routes; `pages:` controls order only. The site root is the exception: the first of `pages:` sets `/`, else `index:`, declared in `site.yml` or in the pages directory's own `folder.yml`/`page.yml`, with `site.yml` winning. A folder with `page.yml` but no markdown is a structural group (`hasContent: false`); visiting it redirects to the first descendant with content.
251
253
 
252
254
  **Mounted folders:** a local folder for a mounted route says how *this site* presents it. Keep `layout:`, `title:` and SEO in a `folder.yml` there; the mounted repo's own `folder.yml` supplies ordering and title where the stub is silent. A `page.yml` with markdown of its own makes a real page above the mounted pages — a landing page for the branch. A mount is one level under `pages/`, and a subfolder in the local folder isn't read, since the branch's pages come from the mount; the build says so. What a site can't do from outside a repo it mounts: leave a file out, title or order a nested folder, or use a `README.md` as a page — those are the mounted repo's to do. A relative link to a markdown file (`./deploying.md#setup`), which is how docs in a repo link to each other, leads to the page that file became; the build names one that leads nowhere. A mount that is its own repository (a submodule, or a clone beside the site) takes its edits as commits there, and `uniweb refresh` takes its latest; a push or publish stops on one that is behind its remote or holds uncommitted changes, and `--mounts-as-is` sends it as it is. A pull writes an author's app edits into a mounted folder where the site's own repository holds it, or a submodule of it does (a commit there, to push before the site's repository). A folder it cannot merge into — a clone beside the site — keeps its text and the app keeps the author's: the pull and `status` name each such page as held, and a push leaves it alone while its file is unchanged. A mount is its folder, `pages/docs: ../docs`; the object form is refused.
@@ -136,6 +136,8 @@ data: {
136
136
 
137
137
  `single`/`whole` are refused over a schema whose root is a list (`@std/nav`, `@std/form`). A `whole` key its source cannot answer whole is `null`. An optional `schemas.config.js` routes a scope to a folder: `export default { '@acme': '../shared/acme-schemas' }` — a routed scope wins, has no package fallback, and `@/`/`@uniweb` are never routable. Worked examples: `development/schemas-in-practice.md`.
138
138
 
139
+ **Any foundation can use any registered data schema, by its full name** — `data: { members: '@acme/member' }`, `schema: '@acme/member'` in `queries.yml`. A scope is a namespace that keeps names from colliding, not a limit on who uses a type. So a type another foundation registers is named, never copied: a copy of its file is a second definition of the same type, which `doctor` points out (`type-defined-twice`). A register names such a type and sends no definition of it. A local build still needs the file: `schemas.config.js` routes that type, `'@acme/member': '../hub/src/schemas/member.yml'`, or its scope's folder. A site's records of it sit in `records/acme/member/`; in `records/member/` they'd be the foundation's own `@/member`.
140
+
139
141
  ```jsx
140
142
  function Article({ content, block }) { // data: { article: { schema: '@std/article', single: true } }
141
143
  if (block.dataLoading) return <DataPlaceholder />
@@ -73,6 +73,7 @@ Things you won't discover from exports:
73
73
  - **A reader can open a picture larger.** `components={{ image: EnlargeableImage }}` does it for an image in a page's body, and `Mermaid` does it on its own (`enlarge={false}` turns it off). `<Enlargeable>` goes around a picture a section draws itself. It's offered only when opening shows the picture noticeably larger, and the prerendered page doesn't change.
74
74
  - **Kit brings no words.** What a reader or a screen reader meets comes from your foundation, so `Media` takes `playLabel`, `Asset` `downloadLabel`, `Disclaimer` `closeLabel` (it has a button at its foot only with one), `Prose` `footnoteBackLabel` and `DataPlaceholder` `label`. Without one it uses what the author wrote, a role or a symbol: a play button with no caption or alt is named `▶`. `<Link>`'s own tooltip is only a social service's name, an address or a number, so a link holding only an icon needs a `title` or `aria-label` from you. Words your own section draws are content: *A section's own words*, below.
75
75
  - **A word wider than its box breaks**, so a long heading can't pan a phone's page (`overflow-wrap: break-word`, in kit's base). What must stay whole in a narrow box says `whitespace-nowrap`: a big numeral, a figure, a number with its unit. Without it, `10 min` in a tight box comes out as `10 mi / n`.
76
+ - **Headings balance their lines and a paragraph's last line keeps company**, inside prose and out (`text-wrap: balance` on `h1`–`h6`, `pretty` on `p`, in kit's base, at no weight). A `text-wrap` or `text-*` class of your own wins; don't write the default again.
76
77
  - **Kit hooks are SSR-safe.** "document is not defined" → use the hook, don't add guards.
77
78
  - **`cn()` drops an earlier `leading-*` when a `text-<size>` follows**, since Tailwind's size classes set line height too: `cn('leading-[1.1] text-4xl')` → `text-4xl`. Put the size first, or fold the leading into it (`text-[clamp(2rem,5vw,4rem)]/[1.1]`).
78
79
  - **"3 of 12 pages didn't render"** means the build stopped, exit 1, because a section threw while rendering a page, and `dist/` isn't complete. It names the error, the section type and the pages. A section that only fails here reads something only a browser has; `uniweb dev` won't show that one.
@@ -160,6 +161,10 @@ export default function Pricing({ content, params }) {
160
161
  }
161
162
  ```
162
163
 
164
+ ### Code several foundations share
165
+
166
+ Code that more than one foundation of a workspace uses lives in a workspace package, not in copies: components are imported as from any package, and Vite bundles them into each foundation. Give the package a stylesheet that reads its own folder, as kit's does — `@source "./**/*.{js,jsx}";` in its `styles.css` — and import it in each foundation's `styles.css` (`@import "@acme/ui/styles.css";`), so Tailwind finds its classes wherever it is installed. A section type the package holds is still each foundation's to offer: a folder in the foundation's `sections/` whose `index.jsx` is `export { default } from '@acme/ui/sections/Banner/index.jsx'`, and whose `meta.js` re-exports the package's the same way. A fix in the package reaches every foundation at its next build and release.
167
+
163
168
  ### The Front Desk pattern
164
169
 
165
170
  A section type is triage: it reads params, picks a worker, and translates author vocabulary into developer props — and that is all it does. The workers are ordinary components that know nothing about CCA, and they need not share an interface: a `Hero` might hand off to a `SliderHero` (image carousel) or a `ContactHero` (quote form) that want different content and different props. The front desk declares the **union** of what they need, and unused content for a given variant is normal — params change behavior, and that includes not rendering some content. This is what lets an author (or an A/B test) flip `variant:` on a section without touching its markdown.
@@ -343,7 +343,12 @@ export async function add(rawArgs) {
343
343
  const rootPkg = JSON.parse(
344
344
  await readFile(join(rootDir, 'package.json'), 'utf-8').catch(() => '{}')
345
345
  )
346
- const projectName = rootPkg.name || 'my-project'
346
+ // ⭐ The project a package is part of: the one `--project` names — the folder it goes in,
347
+ // `<project>/src` or `<project>/site` — else the workspace, by its root package's name. ⛔ Until
348
+ // 2026-11-08 it was always the workspace's, so `add foundation --project shop` in a workspace of
349
+ // projects described the foundation as "<workspace> foundation", and a site added so was named and
350
+ // titled for the workspace.
351
+ const projectName = parsed.project || rootPkg.name || 'my-project'
347
352
 
348
353
  // What this workspace installs with is a property of the repo (its lockfile), not of how the
349
354
  // CLI happened to be launched: `npx uniweb add` in a pnpm workspace wrote `npm -w` root scripts
@@ -407,10 +412,13 @@ async function addFoundation(rootDir, projectName, opts, pm = 'pnpm') {
407
412
  const fullPath = join(rootDir, relativePath)
408
413
 
409
414
  // The foundation's own name — what it registers as, written to main.js — is
410
- // the name asked for, before any workspace suffix below; with none (`src`),
411
- // the project's.
412
- const askedName =
413
- normalizeFoundationName(packageName) || normalizeFoundationName(projectName)
415
+ // the name asked for, before any workspace suffix below; with `--project`, the
416
+ // project's, which its package's `-src` is only the workspace's suffix to; with
417
+ // none (`src`), the workspace's. ⛔ Until 2026-11-08 `--project shop` named the
418
+ // foundation `shop-src`.
419
+ const askedName = opts.project
420
+ ? normalizeFoundationName(opts.project)
421
+ : normalizeFoundationName(packageName) || normalizeFoundationName(projectName)
414
422
 
415
423
  // Validate the derived package name (format + reserved-name check). The
416
424
  // auto-derived `src` default is grandfathered in (`src` IS reserved
@@ -6,19 +6,21 @@ import {
6
6
  existsSync,
7
7
  readFileSync,
8
8
  readdirSync,
9
+ realpathSync,
9
10
  statSync,
10
11
  writeFileSync,
11
12
  mkdirSync,
12
13
  rmSync
13
14
  } from 'node:fs'
14
- import { join, resolve, dirname, relative } from 'node:path'
15
+ import { join, resolve, dirname, relative, isAbsolute, sep } from 'node:path'
15
16
  import yaml from 'js-yaml'
16
17
  import {
17
18
  resolveFoundationSrcPath,
18
19
  classifyPackage,
19
20
  isExtensionPackage as buildIsExtensionPackage,
20
21
  extensionNameOf,
21
- findSiteExtension
22
+ findSiteExtension,
23
+ detectFoundationType
22
24
  } from '@uniweb/build'
23
25
  import {
24
26
  loadDeployYml,
@@ -37,6 +39,7 @@ import { writeJsonPreservingStyle } from '../utils/json-file.js'
37
39
  import { surveyWorkspaceDeps } from '../utils/dep-survey.js'
38
40
  import { discoverFoundations, discoverSites } from '../utils/discover.js'
39
41
  import { siteAround } from '../utils/pick-site.js'
42
+ import { workspaceTypesDefinedTwice } from '../utils/workspace-types.js'
40
43
  import { checkSiteInstall } from '../utils/install-integrity.js'
41
44
  import { editWorkspaceFilePackages } from '../utils/workspace-packages.js'
42
45
  import { findWorkspaceRoot } from '../utils/workspace.js'
@@ -1679,6 +1682,105 @@ export function checkGeneratedDataDir({ sitePath, siteName, siteYml, issues, sho
1679
1682
  * read.
1680
1683
  * @returns {Promise<{ issues: object[], errors: number, warnings: number, fixed: number }>}
1681
1684
  */
1685
+ /**
1686
+ * ⭐ WHAT DOCTOR CHECKS IS WHERE YOU STAND, by the rule `dev` and `status` read the folder you stand in
1687
+ * (`pick-site.js::siteAround`): in a site, that site and what it is built from, its foundation and its
1688
+ * extensions; in a foundation with no site around it, that foundation; elsewhere, the whole workspace.
1689
+ * ⛔ Until 2026-11-08 only the sites were narrowed: run in one site, doctor reported on every foundation
1690
+ * in the workspace before the site's own checks, which were hard to find among them.
1691
+ *
1692
+ * @returns {{ site?: object, foundation?: object, sites: object[], foundations: object[], extensions: object[] } | null}
1693
+ * null for the whole workspace
1694
+ */
1695
+ export function doctorFocus({ workspaceDir, projectDir, allSites, foundations, extensions }) {
1696
+ const here = siteAround(allSites.map((s) => relative(workspaceDir, s.path)), workspaceDir, projectDir)
1697
+ if (here) {
1698
+ const site = allSites.find((s) => relative(workspaceDir, s.path) === here)
1699
+ const used = siteBuiltFrom(site.path)
1700
+ const isUsed = (f) => used.has(realOf(f.path))
1701
+ return { site, sites: [site], foundations: foundations.filter(isUsed), extensions: extensions.filter(isUsed) }
1702
+ }
1703
+ const inside = (dir) => {
1704
+ const rel = relative(dir, projectDir)
1705
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
1706
+ }
1707
+ const foundation = foundations.find((f) => inside(f.path))
1708
+ const extension = extensions.find((e) => inside(e.path))
1709
+ if (!foundation && !extension) return null
1710
+ return {
1711
+ foundation: foundation || extension,
1712
+ sites: [],
1713
+ foundations: foundation ? [foundation] : [],
1714
+ extensions: extension ? [extension] : []
1715
+ }
1716
+ }
1717
+
1718
+ /**
1719
+ * A data schema two packages of the workspace each define under one scope — a copy, where using the
1720
+ * registered type by its full name was enough. Any foundation or site may use any registered data
1721
+ * schema; its scope is a namespace, so that names never collide, and never limits who uses it. So a
1722
+ * copy is a second definition of the one type `@acme/member` names, and the two come apart the first
1723
+ * time one is edited. A recommendation, never a failure: registering either is the registry's to judge.
1724
+ *
1725
+ * @param {{ workspaceDir: string, checkedDirs: string[]|null, issues: object[] }} ctx - `checkedDirs`,
1726
+ * the packages checked (`doctorFocus`); null for every one
1727
+ */
1728
+ export async function checkTypesDefinedTwice({ workspaceDir, checkedDirs, issues }) {
1729
+ let twice
1730
+ try {
1731
+ twice = await workspaceTypesDefinedTwice(workspaceDir)
1732
+ } catch {
1733
+ return
1734
+ }
1735
+ const checked = (file) => !checkedDirs || checkedDirs.some((dir) => {
1736
+ const rel = relative(realOf(dir), file)
1737
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
1738
+ })
1739
+ for (const t of twice.filter((t) => t.files.some(checked))) {
1740
+ const id = 'type-defined-twice'
1741
+ issues.push({
1742
+ id,
1743
+ type: 'info',
1744
+ message: `${t.ref} is defined ${t.files.length} times in the workspace${t.differ ? ', differently' : ''}`,
1745
+ files: t.files.map((f) => relative(workspaceDir, f))
1746
+ })
1747
+ info(`[${id}] ${t.ref} is defined in ${t.files.length} places${t.differ ? ', and they differ' : ''}`)
1748
+ for (const f of t.files) log(` ${relative(workspaceDir, f)}`)
1749
+ log(
1750
+ ` A registered data schema is usable by any foundation by its full name, so keep one definition and name ` +
1751
+ `it in full in the others (${colors.green}${t.ref}${colors.reset}); schemas.config.js gives a local build its file.`
1752
+ )
1753
+ }
1754
+ }
1755
+
1756
+ // The folders a site is built from, by the build's own rules: its foundation (`detectFoundationType`)
1757
+ // and each extension it names, as a site-relative URL or a local name (`findSiteExtension`).
1758
+ function siteBuiltFrom(sitePath) {
1759
+ const used = new Set()
1760
+ const siteYml = loadSiteYml(sitePath)
1761
+ try {
1762
+ const found = detectFoundationType(siteYml?.foundation, sitePath)
1763
+ if (found?.type === 'local' && found.path) used.add(realOf(found.path))
1764
+ } catch {
1765
+ // A foundation the build cannot find: the site's own checks name it.
1766
+ }
1767
+ for (const entry of Array.isArray(siteYml?.extensions) ? siteYml.extensions : []) {
1768
+ const url = typeof entry === 'string' ? entry : entry?.url
1769
+ const name = extensionNameOf(url)?.name ?? (typeof url === 'string' && /^[a-z0-9][a-z0-9_-]*$/i.test(url) ? url : null)
1770
+ const dir = name ? findSiteExtension(name, sitePath) : null
1771
+ if (dir) used.add(realOf(dir))
1772
+ }
1773
+ return used
1774
+ }
1775
+
1776
+ function realOf(path) {
1777
+ try {
1778
+ return realpathSync(path)
1779
+ } catch {
1780
+ return resolve(path)
1781
+ }
1782
+ }
1783
+
1682
1784
  export async function doctor(args = [], { quiet = false } = {}) {
1683
1785
  const before = print
1684
1786
  print = quiet ? () => {} : toConsole
@@ -1825,11 +1927,36 @@ async function runDoctor(args = []) {
1825
1927
  }
1826
1928
  }
1827
1929
 
1828
- if (foundations.length === 0) {
1829
- warn('No foundations found')
1930
+ // Discover sites via the canonical workspace globs (same rationale as
1931
+ // foundations above: respects whatever layout the user chose).
1932
+ const allSites = (await discoverSites(workspaceDir)).map((s) => ({
1933
+ path: join(workspaceDir, s.path),
1934
+ name: s.name
1935
+ }))
1936
+ // ⭐ What is checked is where you stand (`doctorFocus`): the site you're in and what it is built from,
1937
+ // the foundation you're in, or — from anywhere else — the whole workspace.
1938
+ const focus = doctorFocus({ workspaceDir, projectDir, allSites, foundations, extensions })
1939
+ const checkedFoundations = focus ? focus.foundations : foundations
1940
+ const checkedExtensions = focus ? focus.extensions : extensions
1941
+ const sites = focus ? focus.sites : allSites
1942
+ if (focus) {
1943
+ const builtFrom = [...checkedFoundations, ...checkedExtensions].map((f) => relative(workspaceDir, f.path))
1944
+ log('')
1945
+ info(
1946
+ focus.site
1947
+ ? `Checking the site here, ${relative(workspaceDir, focus.site.path)}` +
1948
+ (builtFrom.length ? `, and what it is built from: ${builtFrom.join(', ')}.` : '.')
1949
+ : `Checking the foundation here, ${relative(workspaceDir, focus.foundation.path)}.`
1950
+ )
1951
+ log(` ${colors.dim}Run this from ${workspaceDir} for all ${allSites.length} site(s) and ${foundations.length + extensions.length} foundation(s).${colors.reset}`)
1952
+ }
1953
+
1954
+ if (checkedFoundations.length === 0) {
1955
+ // A site whose foundation is a catalog ref has none here, and its own checks name the ref.
1956
+ if (!focus) warn('No foundations found')
1830
1957
  } else {
1831
- success(`Found ${foundations.length} foundation(s):`)
1832
- for (const f of foundations) {
1958
+ success(`Found ${checkedFoundations.length} foundation(s):`)
1959
+ for (const f of checkedFoundations) {
1833
1960
  const nameMismatch =
1834
1961
  f.name !== f.folderName
1835
1962
  ? ` ${colors.dim}(folder: ${f.folderName}/)${colors.reset}`
@@ -1851,7 +1978,7 @@ async function runDoctor(args = []) {
1851
1978
  //
1852
1979
  // kit closes this for anyone who imports the file; this closes it for anyone
1853
1980
  // who does not, which is the case kit cannot reach.
1854
- for (const f of foundations) {
1981
+ for (const f of checkedFoundations) {
1855
1982
  // `f.path` is already absolute (built above with join(workspaceDir, …)).
1856
1983
  // ⛔ The stylesheet is where the foundation's source is. Until 2026-10-31 this read the
1857
1984
  // package root, so a foundation with `src/` inside its package was never checked.
@@ -1891,7 +2018,7 @@ async function runDoctor(args = []) {
1891
2018
 
1892
2019
  // A `@source` that finds nothing: the build succeeds and the CSS is short every class that was
1893
2020
  // only there. The build says so too; here it reaches `uniweb status`.
1894
- for (const f of foundations) {
2021
+ for (const f of checkedFoundations) {
1895
2022
  await checkStaleSources({ foundationName: f.name, srcDir: resolveFoundationSrcPath(f.path), issues })
1896
2023
  await checkUnreadFolders({ foundationName: f.name, srcDir: resolveFoundationSrcPath(f.path), issues })
1897
2024
  }
@@ -1902,7 +2029,7 @@ async function runDoctor(args = []) {
1902
2029
  // naming one styles nothing and says a design the page does not have.
1903
2030
  // Only where the foundation imports kit's layer and does not load the plugin
1904
2031
  // itself — with its own `@plugin`, the modifier still means what it says.
1905
- for (const f of foundations) {
2032
+ for (const f of checkedFoundations) {
1906
2033
  const stylesPath = join(resolveFoundationSrcPath(f.path), 'styles.css')
1907
2034
  if (!existsSync(stylesPath)) continue
1908
2035
  const styles = readFileSync(stylesPath, 'utf8')
@@ -1956,7 +2083,7 @@ async function runDoctor(args = []) {
1956
2083
  // That is the same class as the `dist/schema.json` path bug (a check that
1957
2084
  // never fires is indistinguishable from a codebase with nothing to report),
1958
2085
  // so it is named here rather than left to be rediscovered.
1959
- for (const f of foundations) {
2086
+ for (const f of checkedFoundations) {
1960
2087
  if (!loadSchemaJson(f.path)) {
1961
2088
  info(
1962
2089
  `${f.folderName}: not built, so nothing was checked here ` +
@@ -1967,7 +2094,7 @@ async function runDoctor(args = []) {
1967
2094
  }
1968
2095
 
1969
2096
  // ── uniweb.supports — the services this foundation says it is built against ──
1970
- for (const f of foundations) {
2097
+ for (const f of checkedFoundations) {
1971
2098
  await checkFoundationSupports({
1972
2099
  foundationName: f.name,
1973
2100
  folderName: f.folderName,
@@ -2016,7 +2143,7 @@ async function runDoctor(args = []) {
2016
2143
  // answer is the union across its primary foundation and its extensions. The
2017
2144
  // regex-era check looked at foundations only, so an extension that drew a
2018
2145
  // search box was never asked about one.
2019
- for (const e of extensions) {
2146
+ for (const e of checkedExtensions) {
2020
2147
  await checkFoundationSupports({
2021
2148
  foundationName: e.name,
2022
2149
  folderName: e.folderName,
@@ -2056,10 +2183,17 @@ async function runDoctor(args = []) {
2056
2183
  })
2057
2184
  }
2058
2185
 
2059
- if (extensions.length > 0) {
2186
+ // One name in a scope is one type: each defined by two packages here, among those checked.
2187
+ await checkTypesDefinedTwice({
2188
+ workspaceDir,
2189
+ checkedDirs: focus ? [...checkedFoundations, ...checkedExtensions].map((f) => f.path) : null,
2190
+ issues
2191
+ })
2192
+
2193
+ if (checkedExtensions.length > 0) {
2060
2194
  log('')
2061
- success(`Found ${extensions.length} extension(s):`)
2062
- for (const e of extensions) {
2195
+ success(`Found ${checkedExtensions.length} extension(s):`)
2196
+ for (const e of checkedExtensions) {
2063
2197
  const nameMismatch =
2064
2198
  e.name !== e.folderName
2065
2199
  ? ` ${colors.dim}(folder: ${e.folderName}/)${colors.reset}`
@@ -2068,23 +2202,10 @@ async function runDoctor(args = []) {
2068
2202
  }
2069
2203
  }
2070
2204
 
2071
- // Discover sites via the canonical workspace globs (same rationale as
2072
- // foundations above: respects whatever layout the user chose).
2073
- const allSites = (await discoverSites(workspaceDir)).map((s) => ({
2074
- path: join(workspaceDir, s.path),
2075
- name: s.name
2076
- }))
2077
- // From inside a site, its checks are that site's, as `status` and `dev` read the folder you
2078
- // stand in. Other sites' findings are there from the workspace root.
2079
- const here = siteAround(allSites.map((s) => relative(workspaceDir, s.path)), workspaceDir, projectDir)
2080
- const sites = here ? allSites.filter((s) => relative(workspaceDir, s.path) === here) : allSites
2081
- if (here && allSites.length > sites.length) {
2082
- log('')
2083
- info(`Checking the site you're in. Run this from ${workspaceDir} for all ${allSites.length}.`)
2084
- }
2085
-
2205
+ // The sites checked were chosen with the foundations (`doctorFocus`, above).
2086
2206
  if (sites.length === 0) {
2087
- warn('No sites found')
2207
+ // In a foundation, its sites are checked from where each one is, or from the workspace root.
2208
+ if (!focus) warn('No sites found')
2088
2209
  } else {
2089
2210
  log('')
2090
2211
  success(`Found ${sites.length} site(s):`)
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-06T23:50:46.813Z",
3
+ "generatedAt": "2026-11-09T01:10:38.607Z",
4
4
  "packages": {
5
5
  "@uniweb/api": {
6
6
  "version": "1.6.9"
7
7
  },
8
8
  "@uniweb/build": {
9
- "version": "1.18.2"
9
+ "version": "1.19.1"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.9"
@@ -15,7 +15,7 @@
15
15
  "version": "1.3.1"
16
16
  },
17
17
  "@uniweb/core": {
18
- "version": "1.6.8"
18
+ "version": "1.6.9"
19
19
  },
20
20
  "@uniweb/frame-bridge": {
21
21
  "version": "1.0.3"
@@ -24,7 +24,7 @@
24
24
  "version": "1.0.8"
25
25
  },
26
26
  "@uniweb/kit": {
27
- "version": "1.7.14"
27
+ "version": "1.7.16"
28
28
  },
29
29
  "@uniweb/loom": {
30
30
  "version": "1.1.3"
@@ -36,7 +36,7 @@
36
36
  "version": "1.2.13"
37
37
  },
38
38
  "@uniweb/runtime": {
39
- "version": "1.5.3"
39
+ "version": "1.5.4"
40
40
  },
41
41
  "@uniweb/scene": {
42
42
  "version": "1.0.1"
@@ -60,7 +60,7 @@
60
60
  "version": "1.3.2"
61
61
  },
62
62
  "@uniweb/unipress": {
63
- "version": "1.1.35"
63
+ "version": "1.1.36"
64
64
  }
65
65
  },
66
66
  "templates": {
@@ -356,29 +356,64 @@ export function computeRootScripts(sites, pm = 'pnpm') {
356
356
  return scripts
357
357
  }
358
358
 
359
- if (sites.length === 1) {
360
- scripts.dev = 'uniweb dev'
361
- scripts.preview = filterCmd(pm, sites[0].name, 'preview')
362
- } else {
363
- // First site gets unqualified dev/preview (matches `uniweb dev`'s
364
- // default-to-first-site behavior).
365
- scripts.dev = 'uniweb dev'
366
- scripts.preview = filterCmd(pm, sites[0].name, 'preview')
367
-
368
- // Subsequent sites get qualified dev:{name}/preview:{name}
369
- for (let i = 1; i < sites.length; i++) {
370
- scripts[`dev:${sites[i].name}`] = `uniweb dev ${sites[i].name}`
371
- scripts[`preview:${sites[i].name}`] = filterCmd(
372
- pm,
373
- sites[i].name,
374
- 'preview'
375
- )
376
- }
359
+ // First site gets unqualified dev/preview (matches `uniweb dev`'s
360
+ // default-to-first-site behavior).
361
+ scripts.dev = 'uniweb dev'
362
+ scripts.preview = previewCommand(pm, sites[0])
363
+
364
+ // Subsequent sites get qualified dev:{name}/preview:{name}, by the name a site's scripts go by
365
+ // (`siteScriptName`) — its package's where another site's scripts already go by its project's.
366
+ for (let i = 1; i < sites.length; i++) {
367
+ const name = [siteScriptName(sites[i]), sites[i].name].find((n) => !(`dev:${n}` in scripts)) ?? sites[i].name
368
+ scripts[`dev:${name}`] = `uniweb dev ${sites[i].name}`
369
+ scripts[`preview:${name}`] = previewCommand(pm, sites[i])
377
370
  }
378
371
 
379
372
  return scripts
380
373
  }
381
374
 
375
+ /**
376
+ * ⭐ THE NAME A SITE'S ROOT SCRIPTS GO BY: a site that is a project's own — `<project>/site`, the
377
+ * folder layout `uniweb add project` makes — by its project's, the name a person knows it by
378
+ * (`dev:marketing`); any other by its package's. The command still names the package, which no other
379
+ * site can share. ⛔ Until 2026-11-08 every site went by its package's, so a project's scripts were
380
+ * `dev:marketing-site` where a workspace of projects names them for the project.
381
+ *
382
+ * @param {{ name: string, path: string }} site - a site, `path` from the workspace root
383
+ * @returns {string}
384
+ */
385
+ export function siteScriptName(site) {
386
+ const parts = String(site.path || '').split(/[\\/]/).filter(Boolean)
387
+ return parts.length >= 2 && parts[parts.length - 1] === 'site' ? parts[parts.length - 2] : site.name
388
+ }
389
+
390
+ /**
391
+ * The command a site's `preview` script runs: its own `preview`, through the package manager — under
392
+ * pnpm by its name, and under npm by its folder, since npm also reads a name as a folder and selects
393
+ * every package in it (`dev.js::devCommand`, the same rule for `dev`). ⛔ Until 2026-11-08 npm's was by
394
+ * name, so a site named for the folder around it previewed the foundation beside it as well.
395
+ */
396
+ function previewCommand(pm, site) {
397
+ return filterCmd(pm, pm === 'npm' ? site.path : site.name, 'preview')
398
+ }
399
+
400
+ /**
401
+ * Whether `command` is one this CLI writes into a `dev:` or `preview:` root script, and for which
402
+ * site — a package's name, or under npm a site's folder. Null for a command the CLI never writes,
403
+ * which is the person's.
404
+ *
405
+ * @param {string} command
406
+ * @returns {string|null}
407
+ */
408
+ function cliScriptTarget(command) {
409
+ if (typeof command !== 'string') return null
410
+ const m =
411
+ /^uniweb dev (\S+)$/.exec(command) ||
412
+ /^pnpm --filter (\S+) (?:run )?(?:dev|preview)$/.exec(command) ||
413
+ /^npm -w (\S+) run (?:dev|preview)$/.exec(command)
414
+ return m ? m[1] : null
415
+ }
416
+
382
417
  /**
383
418
  * Regenerate the per-site root scripts from the sites there are now — what `rename` needs, since a
384
419
  * script it wrote for the old name runs a site that is gone. `add` adds instead (`addRootScripts`).
@@ -394,7 +429,8 @@ export async function updateRootScripts(rootDir, sites, pm = 'pnpm') {
394
429
  // ⭐ `preview` stays on the site it runs. Adding a site is no reason to move it, and
395
430
  // "first" follows the listing, so a new site sorted ahead took the script over. A command the
396
431
  // CLI didn't write is the person's, and only one for a site that's gone is rewritten.
397
- const runs = unique.find((s) => cliSiteScripts('preview', s.name).includes(scripts.preview))
432
+ const isSite = (s, target) => target === s.name || target === s.path
433
+ const runs = unique.find((s) => isSite(s, cliScriptTarget(scripts.preview)))
398
434
  const newScripts = computeRootScripts(runs ? [runs, ...unique.filter((s) => s !== runs)] : unique, pm)
399
435
  const previewIsCli = /^(pnpm --filter \S+ (run )?preview|npm -w \S+ run preview)$/.test(scripts.preview ?? '')
400
436
  if (scripts.preview && !runs && !previewIsCli) delete newScripts.preview
@@ -416,13 +452,14 @@ export async function updateRootScripts(rootDir, sites, pm = 'pnpm') {
416
452
 
417
453
  // ⭐ The per-site scripts this CLI writes are regenerated from the sites there are
418
454
  // now, and one it wrote for a site that is gone — renamed, moved, removed — goes.
419
- // A script whose command is not one the CLI writes is the user's, and stays.
455
+ // A script whose command is not one the CLI writes is the user's, and stays. Known by its
456
+ // command, since a project's site goes by the project's name (`siteScriptName`).
420
457
  // ⛔ Until 2026-10-13 they were only ever added: after `rename site blog journal`,
421
458
  // `dev:blog` still ran `uniweb dev blog`, a site that no longer existed.
422
459
  for (const [key, value] of Object.entries(scripts)) {
423
- if (key in newScripts) continue
424
- const m = /^(dev|preview):(.+)$/.exec(key)
425
- if (m && cliSiteScripts(m[1], m[2]).includes(value)) delete scripts[key]
460
+ if (key in newScripts || !/^(dev|preview):./.test(key)) continue
461
+ const target = cliScriptTarget(value)
462
+ if (target && !unique.some((s) => isSite(s, target))) delete scripts[key]
426
463
  }
427
464
 
428
465
  pkg.scripts = { ...scripts, ...newScripts }
@@ -461,10 +498,13 @@ export async function addRootScripts(rootDir, added, sites, pm = 'pnpm') {
461
498
  added.forEach((site, i) => {
462
499
  if (isFirst && i === 0) {
463
500
  wanted.dev = 'uniweb dev'
464
- wanted.preview = filterCmd(pm, site.name, 'preview')
501
+ wanted.preview = previewCommand(pm, site)
465
502
  } else {
466
- wanted[`dev:${site.name}`] = `uniweb dev ${site.name}`
467
- wanted[`preview:${site.name}`] = filterCmd(pm, site.name, 'preview')
503
+ // By the name its scripts go by (`siteScriptName`), else its package's where that is taken.
504
+ const free = (n) => !(`dev:${n}` in scripts) && !(`dev:${n}` in wanted)
505
+ const name = [siteScriptName(site), site.name].find(free) ?? site.name
506
+ wanted[`dev:${name}`] = `uniweb dev ${site.name}`
507
+ wanted[`preview:${name}`] = previewCommand(pm, site)
468
508
  }
469
509
  })
470
510
 
@@ -477,10 +517,4 @@ export async function addRootScripts(rootDir, added, sites, pm = 'pnpm') {
477
517
  return written
478
518
  }
479
519
 
480
- /** Every command this CLI has written for the `dev:<site>` / `preview:<site>` script. */
481
- function cliSiteScripts(kind, site) {
482
- return kind === 'dev'
483
- ? [`uniweb dev ${site}`, filterCmd('pnpm', site, 'dev'), filterCmd('npm', site, 'dev')]
484
- : [filterCmd('pnpm', site, 'preview'), filterCmd('npm', site, 'preview')]
485
- }
486
520
 
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The data schema names two packages of the workspace each define under one scope — its foundations,
3
+ * extensions and schemas packages — for `uniweb doctor` to recommend one definition, named in full
4
+ * elsewhere (`@uniweb/build`'s `typesDefinedTwice`, which says why).
5
+ */
6
+
7
+ import { join } from 'node:path'
8
+ import { classifyPackage, isSchemasPackage, typesDefinedTwice } from '@uniweb/build'
9
+ import { workspacePackages } from './workspace-packages.js'
10
+
11
+ /**
12
+ * The names of one scope two packages of the workspace define.
13
+ *
14
+ * @param {string} workspaceDir
15
+ * @param {{ dir: string, kind: 'foundation'|'schemas', scope: string }} [self] - a package whose scope
16
+ * was just settled, which its own files may not say yet (`register`)
17
+ * @returns {Promise<{ ref: string, files: string[], differ: boolean }[]>}
18
+ */
19
+ export async function workspaceTypesDefinedTwice(workspaceDir, self = null) {
20
+ const packages = []
21
+ for (const rel of workspacePackages(workspaceDir)) {
22
+ const dir = join(workspaceDir, rel)
23
+ const kind = classifyPackage(dir) === 'foundation' ? 'foundation' : isSchemasPackage(dir) ? 'schemas' : null
24
+ if (kind) packages.push({ dir, kind })
25
+ }
26
+ if (self) packages.unshift(self)
27
+ return typesDefinedTwice(packages)
28
+ }