@uniweb/build 0.44.1 → 0.44.3

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/README.md CHANGED
@@ -324,11 +324,15 @@ After building, your foundation will contain:
324
324
 
325
325
  ```
326
326
  dist/
327
- ├── foundation.js # Bundled components (~6KB typical)
328
- ├── foundation.js.map # Source map
327
+ ├── entry.js # The foundation section types, layouts, declarations
328
+ ├── entry.js.map # Source map
329
+ ├── entry-ssr.js # Single-file twin of entry.js, for server-side prerender
330
+ ├── runtime-pin.json # The @uniweb/runtime version it was built against
331
+ ├── *.js # Code-split chunks, when the foundation has any
332
+ ├── assets/ # Styles and static assets
329
333
  └── meta/ # Editor metadata (not needed at runtime)
330
334
  ├── schema.json # Full component metadata for editors
331
- └── previews/ # Preset preview images
335
+ └── previews/ # Preset preview images, when presets declare them
332
336
  └── Hero/
333
337
  └── default.webp
334
338
  ```
@@ -357,9 +361,9 @@ The `_self` object contains foundation-level metadata:
357
361
  | `name` | `package.json` | Foundation package name |
358
362
  | `version` | `package.json` | Foundation version |
359
363
  | `description` | `package.json` | Foundation description |
360
- | `vars` | `foundation.js` | CSS custom properties sites can override |
364
+ | `vars` | `main.js` | CSS custom properties sites can override |
361
365
 
362
- Identity fields (`name`, `version`, `description`) come from the foundation's `package.json`. Configuration fields (`vars`, etc.) come from `src/foundation.js`.
366
+ Identity fields (`name`, `version`, `description`) come from the foundation's `package.json`. Configuration fields (`vars`, etc.) come from the foundation's `main.js`.
363
367
 
364
368
  ## API Reference
365
369
 
@@ -370,7 +374,7 @@ Identity fields (`name`, `version`, `description`) come from the foundation's `p
370
374
  | `discoverComponents(srcDir)` | Discover all section types (folders with meta.js) |
371
375
  | `loadComponentMeta(componentDir)` | Load meta file for a component |
372
376
  | `loadPackageJson(srcDir)` | Load identity from package.json |
373
- | `loadFoundationConfig(srcDir)` | Load foundation.js configuration |
377
+ | `loadFoundationConfig(srcDir)` | Load the foundation's `main.js` declarations. A leftover `foundation.js` with no `main.js` beside it throws |
374
378
  | `buildSchema(srcDir)` | Build complete schema object |
375
379
 
376
380
  ### Entry Generation
@@ -387,7 +391,7 @@ The generated `_entry.generated.js` file exports:
387
391
  |--------|-------------|
388
392
  | `components` | Object map of component name → React component |
389
393
  | Named exports | Each component exported by name (e.g., `Hero`, `Features`) |
390
- | `capabilities` | Custom Layout and props from `src/foundation.js` (or `null`) |
394
+ | `capabilities` | Custom Layout and props from `main.js` (or `null`) |
391
395
  | `meta` | Runtime metadata extracted from component `meta.js` files |
392
396
 
393
397
  #### Runtime Metadata (`meta` export)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "0.44.1",
3
+ "version": "0.44.3",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -57,15 +57,15 @@
57
57
  "js-yaml": "^4.1.0",
58
58
  "sharp": "^0.35.3",
59
59
  "yaml": "^2.5.0",
60
- "@uniweb/content-writer": "^0.3.4",
61
- "@uniweb/semantic-parser": "^1.4.0",
62
- "@uniweb/projections": "^0.5.13",
63
- "@uniweb/theming": "^0.1.15",
60
+ "@uniweb/schemas": "^0.2.13",
64
61
  "@uniweb/content-reader": "^1.2.4",
65
- "@uniweb/schemas": "^0.2.13"
62
+ "@uniweb/projections": "^0.6.0",
63
+ "@uniweb/theming": "^0.1.15",
64
+ "@uniweb/content-writer": "^0.3.4",
65
+ "@uniweb/semantic-parser": "^1.4.0"
66
66
  },
67
67
  "optionalDependencies": {
68
- "@uniweb/runtime": "^0.19.3"
68
+ "@uniweb/runtime": "^0.19.4"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -74,7 +74,7 @@
74
74
  "@tailwindcss/vite": "^4.0.0",
75
75
  "@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
76
76
  "vite-plugin-svgr": "^4.0.0",
77
- "@uniweb/core": "^0.24.2"
77
+ "@uniweb/core": "^0.24.3"
78
78
  },
79
79
  "peerDependenciesMeta": {
80
80
  "vite": {
@@ -133,6 +133,30 @@ function isResolveServiceCall(node) {
133
133
  return false
134
134
  }
135
135
 
136
+ /**
137
+ * A `.isServiceEnabled(name)` call on anything.
138
+ *
139
+ * ⛔ **Its name argument is at index 0, not 1.** `resolveService(website, name)`
140
+ * passes the website first; the method form has already bound it as the
141
+ * receiver. Reading index 1 here would find `undefined`, fall to the blind
142
+ * branch, and under-report `uniweb.supports` with a warning nobody is watching
143
+ * for — which is why `derive-supports.test.js` asserts a foundation calling
144
+ * `isSubmitEnabled()` derives `submit`.
145
+ *
146
+ * ⭐ This is how every `@uniweb/kit` service predicate is seen: they compile to
147
+ * `website.isServiceEnabled('<name>')`, and kit is bundled into the foundation,
148
+ * so the literal survives the shake. One matcher covers all of them — the name
149
+ * is an argument, so the family does not grow a rule per service.
150
+ */
151
+ function isServiceEnabledCall(node) {
152
+ return (
153
+ node.type === 'CallExpression' &&
154
+ node.callee?.type === 'MemberExpression' &&
155
+ !node.callee.computed &&
156
+ node.callee.property?.name === 'isServiceEnabled'
157
+ )
158
+ }
159
+
136
160
  /** A `.isSearchEnabled()` call on anything. */
137
161
  function isSearchEnabledCall(node) {
138
162
  return (
@@ -164,6 +188,11 @@ function collectSurvivors(bundle) {
164
188
  /**
165
189
  * Derive the services this foundation reaches for.
166
190
  *
191
+ * Three call shapes are read, and two of them carry the name as an argument so
192
+ * they cover the open registry without a rule per service:
193
+ * `resolveService(website, name)`, `website.isServiceEnabled(name)` (what every
194
+ * `@uniweb/kit` predicate compiles to), and the two hand-written gates below.
195
+ *
167
196
  * @param {object} bundle - Rollup's bundle, as handed to `writeBundle`
168
197
  * @param {object} ctx - the Rollup plugin context (`this` in the hook)
169
198
  * @returns {{services: string[], blind: boolean, blindAt: string[]}}
@@ -191,9 +220,12 @@ export function deriveSupports(bundle, ctx) {
191
220
  services.add('search')
192
221
  return
193
222
  }
194
- if (!isResolveServiceCall(node)) return
223
+ const isMethod = isServiceEnabledCall(node)
224
+ if (!isMethod && !isResolveServiceCall(node)) return
195
225
 
196
- const arg = node.arguments?.[1]
226
+ // The name is argument 0 on the method (the website is the receiver) and
227
+ // argument 1 on the free function. Getting this wrong under-reports.
228
+ const arg = node.arguments?.[isMethod ? 0 : 1]
197
229
  if (typeof arg?.value === 'string') {
198
230
  services.add(arg.value)
199
231
  } else if (arg?.type === 'Identifier' && consts.has(arg.name)) {
package/src/i18n/index.js CHANGED
@@ -23,7 +23,8 @@ import {
23
23
  translateRecordData,
24
24
  RECORDS_DIR
25
25
  } from './records.js'
26
- import { generateSearchIndex, isSearchEnabled } from '@uniweb/projections'
26
+ import { generateSearchIndex } from '@uniweb/projections'
27
+ import { searchDeclaredOn } from '../site/search-declared.js'
27
28
 
28
29
  // Free-form translation support
29
30
  import {
@@ -400,7 +401,7 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
400
401
  outputs[locale] = { content: contentOutputPath }
401
402
 
402
403
  // Generate search index for this locale if search is enabled
403
- if (generateSearchIndexes && isSearchEnabled(translated)) {
404
+ if (generateSearchIndexes && searchDeclaredOn(translated)) {
404
405
  const searchConfig = translated.config?.search || {}
405
406
  const searchIndex = generateSearchIndex(translated, {
406
407
  locale,
package/src/schema.js CHANGED
@@ -184,7 +184,11 @@ export async function loadPackageJson(srcDir) {
184
184
  }
185
185
 
186
186
  /**
187
- * Load foundation-level config file (main.js, fallback foundation.js)
187
+ * Load the foundation's declarations from `src/main.js`.
188
+ *
189
+ * ⛔ There is no `foundation.js` fallback — the legacy name was removed
190
+ * 2026-09-05. A leftover `foundation.js` with no `main.js` beside it is
191
+ * REFUSED rather than ignored; see `loadFoundationConfig`.
188
192
  *
189
193
  * Contains foundation-wide configuration:
190
194
  * - vars: CSS custom properties sites can override
@@ -340,7 +344,30 @@ export async function loadFoundationConfig(srcDir) {
340
344
  break
341
345
  }
342
346
  }
343
- if (!filePath) return {}
347
+ if (!filePath) {
348
+ // ⛔ A LEFTOVER `foundation.js` IS NOT "NO CONFIG", AND MUST NOT READ AS ONE.
349
+ //
350
+ // The legacy name was removed 2026-09-05 (`FOUNDATION_FILE_NAMES` is
351
+ // `main.js` alone). This line used to return `{}` here regardless — so a
352
+ // project that kept the old name built "successfully" with every
353
+ // declaration silently gone: no `vars`, no `defaultLayout`, no
354
+ // `defaultSection`, no `props`. That is the exact outcome the guard below
355
+ // refuses on the import-failure path, reached through a door it did not
356
+ // cover. Found 2026-09-10 checking two downstream projects before an update;
357
+ // one would have lost its default layout and its output-format declarations.
358
+ //
359
+ // ⇒ Throw, like the guard below, rather than warn: a build log is where a
360
+ // warning goes to be missed, and the fix is a one-file rename.
361
+ const legacy = join(srcDir, 'foundation.js')
362
+ if (existsSync(legacy)) {
363
+ throw new Error(
364
+ `${legacy} is no longer read — rename it to main.js.\n` +
365
+ ` A foundation's declarations (vars, defaultLayout, defaultSection, props, name) live in\n` +
366
+ ` main.js. Left as foundation.js, the build would continue with none of them.`,
367
+ )
368
+ }
369
+ return {}
370
+ }
344
371
 
345
372
  let module
346
373
  try {
@@ -244,6 +244,7 @@ export async function defineSiteConfig(options = {}) {
244
244
  const agreement = checkFoundationResolution({
245
245
  name: foundationInfo.name,
246
246
  generatedInto: srcDir,
247
+ generatedEntry: entryPath,
247
248
  siteRoot,
248
249
  })
249
250
  if (!agreement.ok) console.warn(`\n${agreement.message}\n`)
@@ -209,8 +209,9 @@ async function processDevSectionFetches(sections, fetchOptions) {
209
209
  }
210
210
  }
211
211
  }
212
- import { generateSearchIndex, isSearchEnabled, getSearchIndexFilename } from '@uniweb/projections'
212
+ import { generateSearchIndex, getSearchIndexFilename } from '@uniweb/projections'
213
213
  import { mergeTranslations } from '../i18n/merge.js'
214
+ import { searchDeclaredOn } from './search-declared.js'
214
215
  import { mountDevApi } from '../dev/api-mount.js'
215
216
 
216
217
  /*
@@ -1145,7 +1146,7 @@ export function siteContentPlugin(options = {}) {
1145
1146
  // Serve search-index.json in dev mode (supports locale prefixes)
1146
1147
  const searchIndexMatch = req.url.match(new RegExp(`^(?:\\/(${LOCALE_RE}))?\\/search-index\\.json$`))
1147
1148
  if (searchIndexMatch && siteContent) {
1148
- const searchEnabled = searchPluginConfig.enabled !== false && isSearchEnabled(siteContent)
1149
+ const searchEnabled = searchPluginConfig.enabled !== false && searchDeclaredOn(siteContent)
1149
1150
  if (searchEnabled) {
1150
1151
  const searchConfig = siteContent.config?.search || {}
1151
1152
  const defaultLocale = resolveDefaultLocale(siteContent.config)
@@ -1511,7 +1512,7 @@ export function siteContentPlugin(options = {}) {
1511
1512
  }
1512
1513
 
1513
1514
  // Generate search index if enabled
1514
- const searchEnabled = searchPluginConfig.enabled !== false && isSearchEnabled(finalContent)
1515
+ const searchEnabled = searchPluginConfig.enabled !== false && searchDeclaredOn(finalContent)
1515
1516
  if (searchEnabled) {
1516
1517
  const searchConfig = finalContent.config?.search || {}
1517
1518
  const defaultLocale = resolveDefaultLocale(finalContent.config)
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Is search on for this site, as the AUTHOR declared it?
3
+ *
4
+ * ⭐ **The build's own decision about its own output.** Deliberately not
5
+ * `@uniweb/projections`': that package is a helper library — it derives
6
+ * artifacts from content and must not gate on a site setting. Deciding whether
7
+ * to generate is the caller's job *[Diego, 2026-09-10]*.
8
+ *
9
+ * ⛔ **The boolean form is why this is not a one-liner.**
10
+ * `config?.search?.enabled !== false` reads `false.enabled` when an author
11
+ * writes `search: false`, because optional chaining short-circuits on
12
+ * `null`/`undefined` only — so `undefined !== false` is `true` and the natural
13
+ * spelling of "off" still shipped a `search-index.json` carrying every page's
14
+ * text. On a static export that file is world-readable. `Website.isSearchEnabled`
15
+ * fixed the same expression in `@uniweb/core`; the copy in projections never got
16
+ * it and now needs none. Pinned by `tests/search-declared.test.js`.
17
+ *
18
+ * ⚖️ **Author tier only, and that is correct here.** A host's `services` block
19
+ * decides where queries are *answered* at render; it has no bearing on whether
20
+ * this build emits an index. The render-time question is
21
+ * `Website.isServiceEnabled('search')`.
22
+ *
23
+ * ⛔ **A leaf on purpose.** It lived in `site/plugin.js` for one commit, which
24
+ * made `i18n/index.js` import a 26-module Vite plugin to reach four lines — and
25
+ * put one future import in the other direction away from a cycle.
26
+ *
27
+ * @param {object} siteContent - parsed site content, or anything with `.config`
28
+ * @returns {boolean}
29
+ */
30
+ export function searchDeclaredOn(siteContent) {
31
+ const search = siteContent?.config?.search
32
+ if (typeof search === 'boolean') return search
33
+ return search?.enabled !== false
34
+ }
@@ -59,7 +59,7 @@
59
59
  * consulted. That is the step whose answer we need.
60
60
  */
61
61
 
62
- import { existsSync, realpathSync } from 'node:fs'
62
+ import { existsSync, readFileSync, realpathSync } from 'node:fs'
63
63
  import { dirname, join, parse } from 'node:path'
64
64
 
65
65
  /**
@@ -85,6 +85,50 @@ export function findPackageDir(name, fromDir) {
85
85
  }
86
86
  }
87
87
 
88
+ /**
89
+ * Does Vite's resolution of this package land on the very file we generated?
90
+ *
91
+ * ⭐ **This is the question the check exists to ask.** Comparing DIRECTORIES
92
+ * asked a different one and got it wrong for the most common layout there is: a
93
+ * package rooted at `foundations/<x>/`, its entry generated into
94
+ * `foundations/<x>/src/`, and `main` pointing there. That is two directories and
95
+ * ONE file. Measured 2026-09-10 against every site of a ten-site project: the
96
+ * directory check fired for six — five healthy `src/` layouts, and the single
97
+ * genuine case, a pnpm `file:` dependency copied into the store, buried among
98
+ * them. The entry comparison leaves exactly that one.
99
+ * A warning that fires on healthy projects is the failure this module's own
100
+ * header warns against.
101
+ *
102
+ * ⛔ **True only when the match is PROVEN** — both files exist and realpath to
103
+ * one place. Any failure to resolve returns false, so the caller reports the
104
+ * directory disagreement rather than silencing it: a copy with no entry, or one
105
+ * carrying a stale entry of its own, is still caught.
106
+ *
107
+ * Follows what Vite reads for a bare specifier: `exports['.']` (a string, or its
108
+ * `import`/`default` condition), else `main`, else `index.js`.
109
+ */
110
+ function resolvesToSameEntry(generatedEntry, packageDir) {
111
+ let pkg
112
+ try {
113
+ pkg = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8'))
114
+ } catch {
115
+ return false
116
+ }
117
+ const pick = (v) =>
118
+ typeof v === 'string' ? v : v && typeof v === 'object' ? pick(v.import ?? v.default) : null
119
+ const exp = pkg.exports
120
+ let rel = null
121
+ if (typeof exp === 'string') rel = exp
122
+ else if (exp && typeof exp === 'object') rel = pick('.' in exp ? exp['.'] : exp)
123
+ rel ??= typeof pkg.main === 'string' ? pkg.main : null
124
+ rel ??= 'index.js'
125
+ try {
126
+ return realpathSync(generatedEntry) === realpathSync(join(packageDir, rel))
127
+ } catch {
128
+ return false
129
+ }
130
+ }
131
+
88
132
  /**
89
133
  * Compare where we generated the foundation entry against where vite will look.
90
134
  *
@@ -100,9 +144,11 @@ export function findPackageDir(name, fromDir) {
100
144
  * @param {string} args.name - the foundation's declared name (the bare specifier)
101
145
  * @param {string} args.generatedInto - the directory we wrote `_entry.generated.js` to
102
146
  * @param {string} args.siteRoot - where vite resolves the bare specifier from
147
+ * @param {string} [args.generatedEntry] - the entry file we wrote; defaults to
148
+ * `_entry.generated.js` inside `generatedInto`
103
149
  * @returns {{ ok: true } | { ok: false, ours: string, theirs: string, message: string }}
104
150
  */
105
- export function checkFoundationResolution({ name, generatedInto, siteRoot }) {
151
+ export function checkFoundationResolution({ name, generatedInto, siteRoot, generatedEntry }) {
106
152
  const theirsRaw = findPackageDir(name, siteRoot)
107
153
  if (!theirsRaw) return { ok: true }
108
154
 
@@ -118,6 +164,13 @@ export function checkFoundationResolution({ name, generatedInto, siteRoot }) {
118
164
 
119
165
  if (ours === theirs) return { ok: true }
120
166
 
167
+ // Two directories are not two foundations. When the package Vite reaches
168
+ // resolves to the entry file we generated, the build reads what we wrote —
169
+ // the `src/` layout, where the entry sits one level below the package root.
170
+ if (resolvesToSameEntry(generatedEntry ?? join(generatedInto, '_entry.generated.js'), theirsRaw)) {
171
+ return { ok: true }
172
+ }
173
+
121
174
  return {
122
175
  ok: false,
123
176
  ours,
package/src/uwx/site.js CHANGED
@@ -852,7 +852,9 @@ function queriesNested(declarations, uuids = null) {
852
852
  // config is bound where the service is provisioned, and arrives here by `pull`.
853
853
  //
854
854
  // ⚖️ WHAT THESE ARE NOT. A site's OWN service declarations — `search:`, `submit:`,
855
- // `assistant:`, `tracking:` — stay top-level `info.*` keys and are untouched. Those
855
+ // `assistant:`, `tracking:` — ride the `settings` Section and are untouched here.
856
+ // (They were top-level `info.*` keys until 2026-09-09; `settingsNested` below is
857
+ // where they are now written.) Those
856
858
  // are authored, they resolve at the SITE tier (`config.<name>`, first choice in
857
859
  // `@uniweb/core`'s `resolveService`), and moving them here would flip them to the
858
860
  // host tier, where a block's mere presence declines every service it does not name.