@uniweb/build 1.15.6 → 1.16.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/src/uwx/site.js CHANGED
@@ -47,6 +47,7 @@
47
47
 
48
48
  import { readdir, readFile } from 'node:fs/promises'
49
49
  import { dataBlockModels } from '../i18n/data-models.js'
50
+ import { SINGLE_SECTION } from './route-mode.js'
50
51
  import { existsSync } from 'node:fs'
51
52
  import { join, parse, relative } from 'node:path'
52
53
  import {
@@ -67,6 +68,7 @@ import {
67
68
  assertRouteFolder,
68
69
  resolveMounts,
69
70
  layerMountedFolder,
71
+ refusePageInFolderMode,
70
72
  folderModePageFiles,
71
73
  folderModeChildren,
72
74
  rootOrderConfig,
@@ -480,7 +482,7 @@ function buildPageData(config, ctx) {
480
482
  // unless the local folder declares one, and the children read from the mount. ⛔ Until 2026-10-23
481
483
  // this lane read no mount, so a mounted route was pushed as an empty container (a local stub) or
482
484
  // not at all (none) — measured 2026-09-18 on a documentation site: 49 pages built, 2 pushed.
483
- async function orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts = null) {
485
+ async function orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts = null, siteRoot = dirPath) {
484
486
  const entries = await readdir(dirPath, { withFileTypes: true })
485
487
  const local = new Map()
486
488
  for (const e of entries) {
@@ -493,6 +495,7 @@ async function orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts =
493
495
  const localConfig = localPath ? await readFolderConfig(localPath, inheritedMode) : null
494
496
  const mountedConfig = mountPath ? await readFolderConfig(mountPath, 'pages') : null
495
497
  const { dirConfig, dirMode, childMode } = layerMountedFolder(dirName, localConfig, mountedConfig, inheritedMode)
498
+ refusePageInFolderMode(inheritedMode, dirMode, relative(siteRoot, localPath ?? mountPath))
496
499
  folders.push({
497
500
  dirName,
498
501
  name: parseNumericPrefix(dirName).name,
@@ -508,12 +511,10 @@ async function orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts =
508
511
  })
509
512
  }
510
513
  // Explicit order, then numeric-prefix filename order, then the parent's `pages:` wildcard —
511
- // one function, which the pull reproduces a level's order with too (`site-project.js`).
512
- // ⚠️ It does NOT match the build's own page-folder sort in one case, and the note that said
513
- // "mirror content-collector's pageFolders sort" here read as if it did: the collector compares
514
- // a level's folder names whole, as strings, and matches `pages:` against them whole, where
515
- // this strips a numeric prefix (`2-about` is `about`, and `10-` sorts after `2-`). Only a level
516
- // with numbered page folders can tell them apart, and which rule is right for them is open.
514
+ // one function, which the pull reproduces a level's order with too (`site-project.js`), on the
515
+ // comparison the build sorts a level's folders with (`compareFolders`). A folder's number orders it
516
+ // and is no part of its name (`2-about` is `about`, and `10-` sorts after `2-`), on every lane
517
+ // [Diego, 2026-11-04]. ⛔ Until then the build kept the number in the route, `/2-about`.
517
518
  return orderFolders(folders, parentConfig?.pages)
518
519
  }
519
520
 
@@ -833,7 +834,7 @@ async function walkPagesNested(ctx, dirPath, parentSlugPath, inheritedMode, pare
833
834
  const { siteRoot, siteIndex, sourceLocale, translations, pageFields } = ctx
834
835
  const files = inheritedMode === 'pages' ? await folderModePageRecords(ctx, dirPath, parentConfig, isRoot) : []
835
836
  const made = []
836
- const folders = await orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts)
837
+ const folders = await orderedSubfolders(dirPath, inheritedMode, parentConfig, mounts, siteRoot)
837
838
  // A folder inside a `[...path]` folder can never be reached, and `[dir]` /
838
839
  // `[path]` would name a route variable — refused here as the collector refuses
839
840
  // them, so a site that cannot build cannot sync either (ruled 2026-09-11).
@@ -852,7 +853,11 @@ async function walkPagesNested(ctx, dirPath, parentSlugPath, inheritedMode, pare
852
853
  // ONE page whose sections were its `.md` files while the build rendered each as a
853
854
  // page of its own. Nothing warned, and a pull then wrote a `page.yml` into the
854
855
  // folder, converting the author's own site to the wrong shape.
855
- const mode = f.internalMode === 'pages' ? 'folder' : 'page'
856
+ // ⭐ WHAT ITS PAGES MAY HOLD, not how the files hold them: `single-section` where they are a folder-mode
857
+ // folder's `.md` files, one section each, else `page`. The mode its PAGES are read in (`childMode`), so
858
+ // a page above a mounted folder of `.md` pages says it too, with its own sections. The app reads it to
859
+ // offer no second section there. ⛔ Until 2026-11-04 it was the folder's own mode, spelled `folder`.
860
+ const mode = f.childMode === 'pages' ? SINGLE_SECTION : 'page'
856
861
  const slugPath = parentSlugPath ? `${parentSlugPath}/${slug}` : slug
857
862
 
858
863
  const data = buildPageData(f.config, {
@@ -882,7 +887,7 @@ async function walkPagesNested(ctx, dirPath, parentSlugPath, inheritedMode, pare
882
887
  }
883
888
 
884
889
  // A folder-mode folder has no sections: its `.md` files are pages, sent among its children.
885
- if (mode === 'page') {
890
+ if (f.internalMode !== 'pages') {
886
891
  const sections = await collectPageSectionsNested(f.path, siteRoot, f.config, ctx.media)
887
892
  if (sections.length > 0) record.page_sections = sections
888
893
  }
@@ -29,7 +29,8 @@ import { buildFolderEntity } from './folder.js'
29
29
  import { siteProjectToDocument } from './site.js'
30
30
  import { siteSourceLocale } from './source-locale.js'
31
31
  import { siteSelfScope, refuseOrgOption } from './self-scope.js'
32
- import { stampUnitUuids, collectUnitUuids } from './site-diff.js'
32
+ import { stampUnitUuids, collectUnitUuids, computeUnitHashes } from './site-diff.js'
33
+ import { leaveHeldOut } from './held-units.js'
33
34
  import { emitEntitySyncPackage } from './entity-document.js'
34
35
  import { recordQueriesShown } from './shown-records.js'
35
36
  import { isLocalAssetPath } from '../site/assets.js'
@@ -245,6 +246,13 @@ function rewriteEntityAssets(node, map, ids, bare = null) {
245
246
  * stamped onto the site-content document so the backend matches our items
246
247
  * instead of re-minting them (which deletes and recreates every page and
247
248
  * section row). Sourced from a pull or a push response, cached by the caller.
249
+ * @param {Object<string,string>} [opts.heldUnits] - unit path → hash: what a pull held, where the
250
+ * files keep it (`held-units.js::heldUnitsOf`). Those whose files still say it are left out
251
+ * of the site-content document (`heldLeftOut`); when any changed, none is, and the result's
252
+ * `heldChanged` names them. Omit to send them, as `--force` does.
253
+ * @param {boolean} [opts.unitHashes] - also return each unit of the files' document, before any
254
+ * media is rewritten, by path: its hash and its `$uuid` from `opts.itemUuids`
255
+ * (`unitHashes`, `unitUuids`), for a pull to record what it held.
248
256
  * @param {Object<string,Object<string,string>>} [opts.recordItemUuids] - record `$uuid` → the
249
257
  * identity of its list items, as a previous push or pull banked it
250
258
  * (`record-items.js`); stamped onto each record the backend holds, so a re-sent
@@ -395,9 +403,8 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
395
403
 
396
404
  // `queryUuids` — identity for the `queries` section, keyed by query
397
405
  // NAME because a declaration has no file of its own (see queriesNested).
398
- const siteDoc = includeSite
399
- ? await siteProjectToDocument(siteRoot, {
400
- media,
406
+ const docOpts = includeSite
407
+ ? {
401
408
  sourceLocale,
402
409
  // Whose $uuid belongs on this wire document — see siteProjectToDocument.
403
410
  ...(opts.backend ? { backend: opts.backend } : {}),
@@ -416,8 +423,9 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
416
423
  ...(Array.isArray(opts.queryFields) ? { queryFields: opts.queryFields } : {}),
417
424
  ...(Array.isArray(opts.pageFields) ? { pageFields: opts.pageFields } : {}),
418
425
  ...(Array.isArray(opts.settingsFields) ? { settingsFields: opts.settingsFields } : {})
419
- })
426
+ }
420
427
  : null
428
+ const siteDoc = includeSite ? await siteProjectToDocument(siteRoot, { ...docOpts, media }) : null
421
429
  // Deploy-derived `info` fields are stamped here — NOT authored in site.yml, so they
422
430
  // ride the wire but never project back on pull. They are part of the hashed content,
423
431
  // so a changed value correctly re-fires the site-content lane.
@@ -563,6 +571,21 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
563
571
  recordItemIdentity.unknown += n.unknown
564
572
  }
565
573
 
574
+ // ⭐ WHAT A PULL HELD STAYS AS THE APP HAS IT (`held-units.js`): a held unit whose files still say what
575
+ // they said at the pull is not sent, and one whose files changed is named for the caller to stop on.
576
+ // Compared on the document the files give before any media is rewritten (`plain`), which `unitHashes`
577
+ // hands a pull to record. A walk of its own, made only when a pull held something.
578
+ const heldUnits = opts.heldUnits && typeof opts.heldUnits === 'object' && Object.keys(opts.heldUnits).length ? opts.heldUnits : null
579
+ const plain = siteDoc && (heldUnits || opts.unitHashes) ? await siteProjectToDocument(siteRoot, { ...docOpts, media: null }) : null
580
+ const held = heldUnits ? leaveHeldOut(siteDoc, { held: heldUnits, plain, sourceLocale }) : { left: [], changed: [] }
581
+ let unitHashes = null
582
+ let unitUuids = null
583
+ if (plain && opts.unitHashes) {
584
+ stampUnitUuids(plain, opts.itemUuids && typeof opts.itemUuids === 'object' ? opts.itemUuids : {}, sourceLocale)
585
+ unitHashes = computeUnitHashes(plain, sourceLocale)
586
+ unitUuids = collectUnitUuids(plain, sourceLocale)
587
+ }
588
+
566
589
  const siteEntity = siteDoc
567
590
  ? { id: siteDoc.$id, model: siteDoc.$schema, file: 'entities/site-content.json', document: siteDoc }
568
591
  : null
@@ -702,5 +725,13 @@ export async function emitSyncPackages(siteRoot, opts = {}) {
702
725
  // leaves the backend's folder exactly as it is — no records directory, or one holding files
703
726
  // that are not records — so a caller can say so where the backend still holds records.
704
727
  sendsFolder: folder !== null,
728
+ // What a pull held (`opts.heldUnits`): the paths this push left out, its files unchanged, and the paths
729
+ // that changed since the pull, for a caller that submits to stop on — none is left out then.
730
+ heldLeftOut: held.left,
731
+ heldChanged: held.changed,
732
+ // With `opts.unitHashes`: each unit of the files' document before any media is rewritten, by path —
733
+ // its hash, and its `$uuid` from `opts.itemUuids` — for a pull to record what it held (`held-units.js`).
734
+ unitHashes,
735
+ unitUuids,
705
736
  }
706
737
  }