uniweb 1.29.3 → 1.30.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniweb",
3
- "version": "1.29.3",
3
+ "version": "1.30.0",
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",
45
44
  "@uniweb/semantic-parser": "~1.13.2",
46
45
  "@uniweb/schemas": "~1.6.11",
46
+ "@uniweb/core": "~1.6.8",
47
47
  "@uniweb/content-writer": "~1.3.1"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@uniweb/semantic-parser": "~1.13.2",
51
51
  "@uniweb/content-reader": "~1.5.9",
52
- "@uniweb/build": "~1.18.2"
52
+ "@uniweb/build": "~1.19.0"
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
+ **A type several foundations of one scope use is defined once.** A name in a scope is one type, so each foundation's `schemas/member.yml` under `@acme` is a definition of the same `@acme/member`, and a register of either changes it for the other's sites: `register` refuses one that differs from another in the workspace, and `doctor` names copies (`type-defined-twice`). Keep it in the scope's schemas package, or in the one foundation that owns it, and name it in full everywhere else: `data: { members: '@acme/member' }`, `schema: '@acme/member'` in `queries.yml`, and a site's records in `records/acme/member/` (in `records/member/` they're the foundation's own `@/member`, which it no longer defines). Route it with `schemas.config.js`: the scope's folder, or that one type, `'@acme/member': '../hub/src/schemas/member.yml'`.
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,110 @@ 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
+ * ⭐ ONE NAME IN A SCOPE IS ONE TYPE (`workspaceTypesDefinedTwice`): each data schema two packages of
1720
+ * one scope here define — two foundations, or a foundation and the scope's schemas package. A register
1721
+ * of either changes the type for the other's sites, and `uniweb register` refuses one whose definition
1722
+ * differs, so differing copies are a warning and agreeing ones a recommendation: they come apart the
1723
+ * first time one is edited.
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: t.differ ? 'warn' : '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
+ const say = t.differ ? warn : info
1748
+ say(`[${id}] ${t.ref} is defined in ${t.files.length} places${t.differ ? ', and they differ' : ''}`)
1749
+ for (const f of t.files) log(` ${relative(workspaceDir, f)}`)
1750
+ log(
1751
+ ` A name in a scope is one type, so a register of either changes it for the other's sites` +
1752
+ (t.differ ? ` — \`uniweb register\` refuses this one.` : `, and copies come apart the first time one is edited.`)
1753
+ )
1754
+ log(
1755
+ ` Keep it in one place — the scope's schemas package, or the foundation that owns it — and name it in full ` +
1756
+ `elsewhere (${colors.green}${t.ref}${colors.reset}), with schemas.config.js routing the scope to its folder.`
1757
+ )
1758
+ }
1759
+ }
1760
+
1761
+ // The folders a site is built from, by the build's own rules: its foundation (`detectFoundationType`)
1762
+ // and each extension it names, as a site-relative URL or a local name (`findSiteExtension`).
1763
+ function siteBuiltFrom(sitePath) {
1764
+ const used = new Set()
1765
+ const siteYml = loadSiteYml(sitePath)
1766
+ try {
1767
+ const found = detectFoundationType(siteYml?.foundation, sitePath)
1768
+ if (found?.type === 'local' && found.path) used.add(realOf(found.path))
1769
+ } catch {
1770
+ // A foundation the build cannot find: the site's own checks name it.
1771
+ }
1772
+ for (const entry of Array.isArray(siteYml?.extensions) ? siteYml.extensions : []) {
1773
+ const url = typeof entry === 'string' ? entry : entry?.url
1774
+ const name = extensionNameOf(url)?.name ?? (typeof url === 'string' && /^[a-z0-9][a-z0-9_-]*$/i.test(url) ? url : null)
1775
+ const dir = name ? findSiteExtension(name, sitePath) : null
1776
+ if (dir) used.add(realOf(dir))
1777
+ }
1778
+ return used
1779
+ }
1780
+
1781
+ function realOf(path) {
1782
+ try {
1783
+ return realpathSync(path)
1784
+ } catch {
1785
+ return resolve(path)
1786
+ }
1787
+ }
1788
+
1682
1789
  export async function doctor(args = [], { quiet = false } = {}) {
1683
1790
  const before = print
1684
1791
  print = quiet ? () => {} : toConsole
@@ -1825,11 +1932,36 @@ async function runDoctor(args = []) {
1825
1932
  }
1826
1933
  }
1827
1934
 
1828
- if (foundations.length === 0) {
1829
- warn('No foundations found')
1935
+ // Discover sites via the canonical workspace globs (same rationale as
1936
+ // foundations above: respects whatever layout the user chose).
1937
+ const allSites = (await discoverSites(workspaceDir)).map((s) => ({
1938
+ path: join(workspaceDir, s.path),
1939
+ name: s.name
1940
+ }))
1941
+ // ⭐ What is checked is where you stand (`doctorFocus`): the site you're in and what it is built from,
1942
+ // the foundation you're in, or — from anywhere else — the whole workspace.
1943
+ const focus = doctorFocus({ workspaceDir, projectDir, allSites, foundations, extensions })
1944
+ const checkedFoundations = focus ? focus.foundations : foundations
1945
+ const checkedExtensions = focus ? focus.extensions : extensions
1946
+ const sites = focus ? focus.sites : allSites
1947
+ if (focus) {
1948
+ const builtFrom = [...checkedFoundations, ...checkedExtensions].map((f) => relative(workspaceDir, f.path))
1949
+ log('')
1950
+ info(
1951
+ focus.site
1952
+ ? `Checking the site here, ${relative(workspaceDir, focus.site.path)}` +
1953
+ (builtFrom.length ? `, and what it is built from: ${builtFrom.join(', ')}.` : '.')
1954
+ : `Checking the foundation here, ${relative(workspaceDir, focus.foundation.path)}.`
1955
+ )
1956
+ log(` ${colors.dim}Run this from ${workspaceDir} for all ${allSites.length} site(s) and ${foundations.length + extensions.length} foundation(s).${colors.reset}`)
1957
+ }
1958
+
1959
+ if (checkedFoundations.length === 0) {
1960
+ // A site whose foundation is a catalog ref has none here, and its own checks name the ref.
1961
+ if (!focus) warn('No foundations found')
1830
1962
  } else {
1831
- success(`Found ${foundations.length} foundation(s):`)
1832
- for (const f of foundations) {
1963
+ success(`Found ${checkedFoundations.length} foundation(s):`)
1964
+ for (const f of checkedFoundations) {
1833
1965
  const nameMismatch =
1834
1966
  f.name !== f.folderName
1835
1967
  ? ` ${colors.dim}(folder: ${f.folderName}/)${colors.reset}`
@@ -1851,7 +1983,7 @@ async function runDoctor(args = []) {
1851
1983
  //
1852
1984
  // kit closes this for anyone who imports the file; this closes it for anyone
1853
1985
  // who does not, which is the case kit cannot reach.
1854
- for (const f of foundations) {
1986
+ for (const f of checkedFoundations) {
1855
1987
  // `f.path` is already absolute (built above with join(workspaceDir, …)).
1856
1988
  // ⛔ The stylesheet is where the foundation's source is. Until 2026-10-31 this read the
1857
1989
  // package root, so a foundation with `src/` inside its package was never checked.
@@ -1891,7 +2023,7 @@ async function runDoctor(args = []) {
1891
2023
 
1892
2024
  // A `@source` that finds nothing: the build succeeds and the CSS is short every class that was
1893
2025
  // only there. The build says so too; here it reaches `uniweb status`.
1894
- for (const f of foundations) {
2026
+ for (const f of checkedFoundations) {
1895
2027
  await checkStaleSources({ foundationName: f.name, srcDir: resolveFoundationSrcPath(f.path), issues })
1896
2028
  await checkUnreadFolders({ foundationName: f.name, srcDir: resolveFoundationSrcPath(f.path), issues })
1897
2029
  }
@@ -1902,7 +2034,7 @@ async function runDoctor(args = []) {
1902
2034
  // naming one styles nothing and says a design the page does not have.
1903
2035
  // Only where the foundation imports kit's layer and does not load the plugin
1904
2036
  // itself — with its own `@plugin`, the modifier still means what it says.
1905
- for (const f of foundations) {
2037
+ for (const f of checkedFoundations) {
1906
2038
  const stylesPath = join(resolveFoundationSrcPath(f.path), 'styles.css')
1907
2039
  if (!existsSync(stylesPath)) continue
1908
2040
  const styles = readFileSync(stylesPath, 'utf8')
@@ -1956,7 +2088,7 @@ async function runDoctor(args = []) {
1956
2088
  // That is the same class as the `dist/schema.json` path bug (a check that
1957
2089
  // never fires is indistinguishable from a codebase with nothing to report),
1958
2090
  // so it is named here rather than left to be rediscovered.
1959
- for (const f of foundations) {
2091
+ for (const f of checkedFoundations) {
1960
2092
  if (!loadSchemaJson(f.path)) {
1961
2093
  info(
1962
2094
  `${f.folderName}: not built, so nothing was checked here ` +
@@ -1967,7 +2099,7 @@ async function runDoctor(args = []) {
1967
2099
  }
1968
2100
 
1969
2101
  // ── uniweb.supports — the services this foundation says it is built against ──
1970
- for (const f of foundations) {
2102
+ for (const f of checkedFoundations) {
1971
2103
  await checkFoundationSupports({
1972
2104
  foundationName: f.name,
1973
2105
  folderName: f.folderName,
@@ -2016,7 +2148,7 @@ async function runDoctor(args = []) {
2016
2148
  // answer is the union across its primary foundation and its extensions. The
2017
2149
  // regex-era check looked at foundations only, so an extension that drew a
2018
2150
  // search box was never asked about one.
2019
- for (const e of extensions) {
2151
+ for (const e of checkedExtensions) {
2020
2152
  await checkFoundationSupports({
2021
2153
  foundationName: e.name,
2022
2154
  folderName: e.folderName,
@@ -2056,10 +2188,17 @@ async function runDoctor(args = []) {
2056
2188
  })
2057
2189
  }
2058
2190
 
2059
- if (extensions.length > 0) {
2191
+ // One name in a scope is one type: each defined by two packages here, among those checked.
2192
+ await checkTypesDefinedTwice({
2193
+ workspaceDir,
2194
+ checkedDirs: focus ? [...checkedFoundations, ...checkedExtensions].map((f) => f.path) : null,
2195
+ issues
2196
+ })
2197
+
2198
+ if (checkedExtensions.length > 0) {
2060
2199
  log('')
2061
- success(`Found ${extensions.length} extension(s):`)
2062
- for (const e of extensions) {
2200
+ success(`Found ${checkedExtensions.length} extension(s):`)
2201
+ for (const e of checkedExtensions) {
2063
2202
  const nameMismatch =
2064
2203
  e.name !== e.folderName
2065
2204
  ? ` ${colors.dim}(folder: ${e.folderName}/)${colors.reset}`
@@ -2068,23 +2207,10 @@ async function runDoctor(args = []) {
2068
2207
  }
2069
2208
  }
2070
2209
 
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
-
2210
+ // The sites checked were chosen with the foundations (`doctorFocus`, above).
2086
2211
  if (sites.length === 0) {
2087
- warn('No sites found')
2212
+ // In a foundation, its sites are checked from where each one is, or from the workspace root.
2213
+ if (!focus) warn('No sites found')
2088
2214
  } else {
2089
2215
  log('')
2090
2216
  success(`Found ${sites.length} site(s):`)
@@ -64,6 +64,7 @@ import {
64
64
  readFileSync,
65
65
  writeFileSync,
66
66
  readdirSync,
67
+ realpathSync,
67
68
  statSync
68
69
  } from 'node:fs'
69
70
  import { execSync } from 'node:child_process'
@@ -100,6 +101,20 @@ import {
100
101
  } from '../utils/workspace.js'
101
102
  import { isNonInteractive, getCliPrefix } from '../utils/interactive.js'
102
103
  import { checkFlags } from '../utils/flag-guard.js'
104
+ import { workspaceTypesDefinedTwice } from '../utils/workspace-types.js'
105
+
106
+ // Is `path` inside `dir` (or `dir` itself)? By their real paths, as the type rule reads them.
107
+ const realOf = (p) => {
108
+ try {
109
+ return realpathSync(p)
110
+ } catch {
111
+ return resolve(p)
112
+ }
113
+ }
114
+ const isWithin = (dir, path) => {
115
+ const rel = relative(realOf(dir), realOf(path))
116
+ return rel === '' || (!rel.startsWith('..') && !rel.startsWith('/'))
117
+ }
103
118
 
104
119
  const colors = {
105
120
  reset: '\x1b[0m',
@@ -603,6 +618,31 @@ export function foundationNeedsBuild(targetDir) {
603
618
  return { needs: false }
604
619
  }
605
620
 
621
+ /**
622
+ * ⭐ ONE NAME IN A SCOPE IS ONE TYPE (`workspaceTypesDefinedTwice`): a definition that differs from
623
+ * another of the same name in this workspace is refused, since a register replaces what the type is for
624
+ * the other package's sites too. Copies that agree register as one, and `uniweb doctor` names them.
625
+ * Says why and returns true when it refuses.
626
+ */
627
+ async function typesRefused(targetDir, kind, scope) {
628
+ if (!scope) return false
629
+ const workspaceDir = findWorkspaceRoot(targetDir)
630
+ if (!workspaceDir) return false
631
+ const twice = (await workspaceTypesDefinedTwice(workspaceDir, { dir: targetDir, kind, scope }))
632
+ .filter((t) => t.differ && t.files.some((f) => isWithin(targetDir, f)))
633
+ if (!twice.length) return false
634
+ error(`${twice.length === 1 ? 'A data schema this registers is' : `${twice.length} data schemas this registers are`} defined differently elsewhere in the workspace:`)
635
+ for (const t of twice) {
636
+ log(` ${colors.bright}${t.ref}${colors.reset}`)
637
+ for (const f of t.files) log(` ${colors.dim}${relative(workspaceDir, f)}${colors.reset}`)
638
+ }
639
+ log('')
640
+ log(` A name in ${scope} is one type: registering this would change it for the other's sites too.`)
641
+ log(` Keep each in one place — the scope's schemas package, or the foundation that owns it — and name it`)
642
+ log(` in full elsewhere (${twice[0].ref}), with ${colors.bright}schemas.config.js${colors.reset} routing ${scope} to its folder.`)
643
+ return true
644
+ }
645
+
606
646
  export async function register(args = []) {
607
647
  // See utils/flag-guard.js — an unrecognized flag is invisible to a
608
648
  // literal scan, so it silently keeps the default (production, for --backend).
@@ -713,6 +753,8 @@ async function runRegister(args = []) {
713
753
  if (!settled) return { exitCode: 2 }
714
754
  scope = settled.scope
715
755
  scopeSource = settled.source
756
+ // Before the build: the type rule reads the source, and a refusal needs no build to say.
757
+ if (await typesRefused(targetDir, 'foundation', scope)) return { exitCode: 2 }
716
758
  // Build-if-stale (`foundationNeedsBuild`): a missing or stale dist/ gets
717
759
  // (re)built before we read its schema. Preview paths
718
760
  // (--dry-run / -o) must not write to dist/, so they require a pre-built
@@ -803,6 +845,9 @@ async function runRegister(args = []) {
803
845
  // states its own floor and whoever resolves a whole site does the arithmetic.
804
846
  const runtime = standalone ? null : readRuntimePin(join(targetDir, 'dist'))
805
847
 
848
+ // A schemas package's scope is known only now; a foundation's was before its build.
849
+ if (standalone && (await typesRefused(targetDir, 'schemas', scope))) return { exitCode: 2 }
850
+
806
851
  const exporter = { tool: 'uniweb', version: cliVersion(), instance: 'build' }
807
852
  let doc
808
853
  try {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-11-06T23:50:46.813Z",
3
+ "generatedAt": "2026-11-08T22:27:32.223Z",
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.0"
10
10
  },
11
11
  "@uniweb/content-reader": {
12
12
  "version": "1.5.9"
@@ -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.15"
28
28
  },
29
29
  "@uniweb/loom": {
30
30
  "version": "1.1.3"
@@ -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,29 @@
1
+ /**
2
+ * ⭐ ONE NAME IN A SCOPE IS ONE TYPE (`@uniweb/build`'s `typesDefinedTwice`, which says why): the data
3
+ * schema names the workspace's packages of one scope each define — its foundations, extensions and
4
+ * schemas packages — for `uniweb register` to refuse a definition that differs, and `uniweb doctor` to
5
+ * name every one defined twice.
6
+ */
7
+
8
+ import { join } from 'node:path'
9
+ import { classifyPackage, isSchemasPackage, typesDefinedTwice } from '@uniweb/build'
10
+ import { workspacePackages } from './workspace-packages.js'
11
+
12
+ /**
13
+ * The names of one scope two packages of the workspace define.
14
+ *
15
+ * @param {string} workspaceDir
16
+ * @param {{ dir: string, kind: 'foundation'|'schemas', scope: string }} [self] - a package whose scope
17
+ * was just settled, which its own files may not say yet (`register`)
18
+ * @returns {Promise<{ ref: string, files: string[], differ: boolean }[]>}
19
+ */
20
+ export async function workspaceTypesDefinedTwice(workspaceDir, self = null) {
21
+ const packages = []
22
+ for (const rel of workspacePackages(workspaceDir)) {
23
+ const dir = join(workspaceDir, rel)
24
+ const kind = classifyPackage(dir) === 'foundation' ? 'foundation' : isSchemasPackage(dir) ? 'schemas' : null
25
+ if (kind) packages.push({ dir, kind })
26
+ }
27
+ if (self) packages.unshift(self)
28
+ return typesDefinedTwice(packages)
29
+ }