@uniweb/build 1.20.4 → 1.20.6
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 +8 -8
- package/src/foundation/libraries.js +94 -0
- package/src/foundation/shared-types.js +37 -14
- package/src/foundation/stale-sources.js +84 -1
- package/src/index.js +5 -1
- package/src/prerender.js +1 -1
- package/src/resolve-data-schema.js +19 -18
- package/src/site/config.js +25 -2
- package/src/site/projections.js +9 -18
- package/src/vite-foundation-plugin.js +12 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.6",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"sharp": "^0.35.5",
|
|
59
59
|
"yaml": "^2.5.0",
|
|
60
60
|
"@uniweb/content-reader": "~1.5.9",
|
|
61
|
+
"@uniweb/schemas": "~1.7.1",
|
|
61
62
|
"@uniweb/theming": "~1.3.2",
|
|
62
|
-
"@uniweb/
|
|
63
|
-
"@uniweb/
|
|
64
|
-
"@uniweb/content-writer": "~1.3.1"
|
|
65
|
-
"@uniweb/semantic-parser": "~1.13.2"
|
|
63
|
+
"@uniweb/semantic-parser": "~1.13.2",
|
|
64
|
+
"@uniweb/projections": "~1.2.16",
|
|
65
|
+
"@uniweb/content-writer": "~1.3.1"
|
|
66
66
|
},
|
|
67
67
|
"optionalDependencies": {
|
|
68
|
-
"@uniweb/runtime": "~1.5.
|
|
68
|
+
"@uniweb/runtime": "~1.5.6"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,8 +74,8 @@
|
|
|
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/
|
|
78
|
-
"@uniweb/
|
|
77
|
+
"@uniweb/runtime": "~1.5.6",
|
|
78
|
+
"@uniweb/core": "~1.6.11"
|
|
79
79
|
},
|
|
80
80
|
"peerDependenciesMeta": {
|
|
81
81
|
"vite": {
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ⭐ A LIBRARY IS ANY LOCAL PACKAGE A FOUNDATION DEPENDS ON: one whose files are on this disk to
|
|
3
|
+
* edit, in the workspace, in another folder or in another repository. Nothing else marks one, no
|
|
4
|
+
* key in its `package.json` and no kind of its own, so a package made by hand, kept in a git
|
|
5
|
+
* submodule or cloned is a library as soon as a foundation depends on it. A foundation's build bundles
|
|
6
|
+
* its libraries, so a library's files are the foundation's sources too: whatever asks what a
|
|
7
|
+
* foundation's build reads asks this.
|
|
8
|
+
*
|
|
9
|
+
* Found through the foundation's `package.json`, then each library's own:
|
|
10
|
+
* - a `file:` or `link:` path names the library's folder, whatever the package manager made of
|
|
11
|
+
* it (pnpm copies a `file:` package from outside the workspace into its store, and the folder
|
|
12
|
+
* named is the one a developer edits);
|
|
13
|
+
* - any other spec (`workspace:`, a version range) is where Node would find the package, up the
|
|
14
|
+
* `node_modules` folders. One installed there is a copy of a release, and only a package that
|
|
15
|
+
* links back out of `node_modules` is a library.
|
|
16
|
+
* A foundation's `devDependencies` count, since a foundation is bundled and what it imports ships
|
|
17
|
+
* whichever list names it; a library's don't, since they are its own tools. Neither do
|
|
18
|
+
* `peerDependencies`, which the foundation provides. What a foundation's build leaves to the
|
|
19
|
+
* runtime (`DEFAULT_EXTERNALS`) is never bundled, so it is never a library.
|
|
20
|
+
*
|
|
21
|
+
* @module @uniweb/build/foundation/libraries
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
25
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
26
|
+
import { DEFAULT_EXTERNALS } from '../import-map-plugin.js'
|
|
27
|
+
|
|
28
|
+
const EXTERNAL = new Set(DEFAULT_EXTERNALS)
|
|
29
|
+
|
|
30
|
+
const real = (path) => {
|
|
31
|
+
try {
|
|
32
|
+
return realpathSync(path)
|
|
33
|
+
} catch {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function readPackage(dir) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
41
|
+
} catch {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Where Node finds `name` from `fromDir`: the first `node_modules/<name>` up the folders, followed. */
|
|
47
|
+
function installedAt(fromDir, name) {
|
|
48
|
+
for (let dir = fromDir; ; dir = dirname(dir)) {
|
|
49
|
+
const at = join(dir, 'node_modules', name)
|
|
50
|
+
if (existsSync(join(at, 'package.json'))) return real(at)
|
|
51
|
+
if (dirname(dir) === dir) return null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A dependency's folder when it is local, else null. */
|
|
56
|
+
function libraryDir(fromDir, name, spec) {
|
|
57
|
+
const path = /^(?:file|link):(.+)$/.exec(spec)?.[1]
|
|
58
|
+
if (path) {
|
|
59
|
+
const dir = real(resolve(fromDir, path))
|
|
60
|
+
return dir && existsSync(join(dir, 'package.json')) ? dir : null
|
|
61
|
+
}
|
|
62
|
+
const dir = installedAt(fromDir, name)
|
|
63
|
+
// ⚖️ Judged from where the two meet, so a workspace that is itself under a `node_modules` folder
|
|
64
|
+
// still has libraries.
|
|
65
|
+
return dir && !relative(fromDir, dir).split(sep).includes('node_modules') ? dir : null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The libraries a package bundles, its libraries' libraries included, each once.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} packageDir - a foundation (or a library)
|
|
72
|
+
* @returns {Array<{ name: string, dir: string }>} each by the name it is depended on by, and its
|
|
73
|
+
* real folder; in the order found
|
|
74
|
+
*/
|
|
75
|
+
export function librariesOf(packageDir) {
|
|
76
|
+
const start = real(packageDir) ?? resolve(packageDir)
|
|
77
|
+
const seen = new Set([start])
|
|
78
|
+
const found = []
|
|
79
|
+
const visit = (dir, fields) => {
|
|
80
|
+
const pkg = readPackage(dir)
|
|
81
|
+
for (const field of fields) {
|
|
82
|
+
for (const [name, spec] of Object.entries(pkg?.[field] ?? {})) {
|
|
83
|
+
if (typeof spec !== 'string' || EXTERNAL.has(name)) continue
|
|
84
|
+
const lib = libraryDir(dir, name, spec)
|
|
85
|
+
if (!lib || seen.has(lib)) continue
|
|
86
|
+
seen.add(lib)
|
|
87
|
+
found.push({ name, dir: lib })
|
|
88
|
+
visit(lib, ['dependencies', 'optionalDependencies'])
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
visit(start, ['dependencies', 'devDependencies', 'optionalDependencies'])
|
|
93
|
+
return found
|
|
94
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
17
|
-
import { join, relative, resolve, isAbsolute, sep } from 'node:path'
|
|
17
|
+
import { dirname, join, relative, resolve, isAbsolute, sep } from 'node:path'
|
|
18
18
|
import { readFoundationName } from '../schema.js'
|
|
19
19
|
import { splitFoundationName } from '../foundation-name.js'
|
|
20
20
|
import { ownSchemaFiles, resolveSchemaRef } from '../resolve-data-schema.js'
|
|
@@ -23,6 +23,7 @@ import { canonicalJson } from '../uwx/same-content.js'
|
|
|
23
23
|
import { workspacePackages } from '../workspace-patterns.js'
|
|
24
24
|
import { workspaceRootOf } from '../site/workspace-extension.js'
|
|
25
25
|
import { classifyPackage, isSchemasPackage } from '../utils/classify-package.js'
|
|
26
|
+
import { librariesOf } from './libraries.js'
|
|
26
27
|
|
|
27
28
|
const real = (path) => {
|
|
28
29
|
try {
|
|
@@ -145,17 +146,31 @@ const within = (dir, path) => {
|
|
|
145
146
|
return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
|
|
146
147
|
}
|
|
147
148
|
|
|
149
|
+
/** The package `dir` is in: the nearest folder at or above it that holds a package.json. */
|
|
150
|
+
function packageDirOf(dir) {
|
|
151
|
+
for (let at = resolve(dir); ; at = dirname(at)) {
|
|
152
|
+
if (existsSync(join(at, 'package.json'))) return at
|
|
153
|
+
if (dirname(at) === at) return null
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
148
157
|
/**
|
|
149
|
-
* ⭐ A TYPE ANOTHER PACKAGE OF THE WORKSPACE
|
|
150
|
-
* team develops together share a type by its full
|
|
151
|
-
* from the package that defines it: a foundation
|
|
152
|
-
* `schemas/` holds `member`, or a schemas package
|
|
153
|
-
*
|
|
154
|
-
* easy and good DX to share schemas"]*.
|
|
158
|
+
* ⭐ A TYPE ANOTHER PACKAGE OF THE WORKSPACE, OR A LIBRARY THE ASKING PACKAGE BUNDLES, DEFINES,
|
|
159
|
+
* found with nothing configured. Foundations a team develops together share a type by its full
|
|
160
|
+
* name, `@acme/member`, and a local build reads it from the package that defines it: a foundation
|
|
161
|
+
* whose name gives the `@acme` scope and whose own `schemas/` holds `member`, or a schemas package
|
|
162
|
+
* of that scope. No `schemas.config.js`, no package to install, nothing registered: sharing a type
|
|
163
|
+
* never needs a backend *[Diego, 2026-11-08: "it should be easy and good DX to share schemas"]*.
|
|
155
164
|
*
|
|
156
|
-
*
|
|
157
|
-
* packages, as pnpm reads its list (`../workspace-patterns.js`),
|
|
158
|
-
*
|
|
165
|
+
* Two kinds of package are read, each one the asker's to read:
|
|
166
|
+
* - the workspace's packages, as pnpm reads its list (`../workspace-patterns.js`), when `fromDir`
|
|
167
|
+
* is in one of them, so a copy kept outside the list, a backup folder say, is never read;
|
|
168
|
+
* - each library the asking package bundles (`librariesOf`), wherever it is: in another
|
|
169
|
+
* repository beside the workspace, say, linked with `file:` or `link:`. A library is such a
|
|
170
|
+
* schemas package when it gives its scope in its `package.json` (`uniweb.scope`) and holds
|
|
171
|
+
* `schemas/`. ⛔ Until 2026-11-09 only the workspace's were, and a library outside it needed
|
|
172
|
+
* `schemas.config.js` in every foundation that named its types.
|
|
173
|
+
* Found by the same rule `typesDefinedTwice` names copies by.
|
|
159
174
|
*
|
|
160
175
|
* @param {string} ref - `@scope/name`
|
|
161
176
|
* @param {string} fromDir - the foundation (its source folder) or site asking
|
|
@@ -165,12 +180,20 @@ export async function workspaceTypeFiles(ref, fromDir) {
|
|
|
165
180
|
const m = /^(@[^/]+)\/(.+)$/.exec(ref || '')
|
|
166
181
|
if (!m) return []
|
|
167
182
|
const [, scope, name] = m
|
|
183
|
+
const candidates = []
|
|
168
184
|
const root = workspaceRootOf(fromDir)
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
|
|
185
|
+
if (root) {
|
|
186
|
+
const packages = workspacePackages(root).map((rel) => join(root, rel))
|
|
187
|
+
if (packages.some((dir) => within(dir, resolve(fromDir)))) candidates.push(...packages)
|
|
188
|
+
}
|
|
189
|
+
const asking = packageDirOf(fromDir)
|
|
190
|
+
if (asking) candidates.push(...librariesOf(asking).map((lib) => lib.dir))
|
|
172
191
|
const files = new Map()
|
|
173
|
-
|
|
192
|
+
const seen = new Set()
|
|
193
|
+
for (const dir of candidates) {
|
|
194
|
+
const at = real(dir)
|
|
195
|
+
if (seen.has(at)) continue
|
|
196
|
+
seen.add(at)
|
|
174
197
|
const kind = classifyPackage(dir) === 'foundation' ? 'foundation' : isSchemasPackage(dir) ? 'schemas' : null
|
|
175
198
|
if (!kind) continue
|
|
176
199
|
if ((await cachedTypeScope(dir, kind)) !== scope) continue
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* is missing classes would be false. With a kit from before that, the loss is real: its stylesheet
|
|
20
20
|
* names nothing, so the line is still reported.
|
|
21
21
|
*
|
|
22
|
-
* A folder no `@source` names is the same loss from the other side: see `unreadFolders
|
|
22
|
+
* A folder no `@source` names is the same loss from the other side: see `unreadFolders`, and
|
|
23
|
+
* `unreadLibraries` for the local packages a foundation bundles.
|
|
23
24
|
*
|
|
24
25
|
* @module @uniweb/build/foundation/stale-sources
|
|
25
26
|
*/
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
import { existsSync, readFileSync, readdirSync, realpathSync } from 'node:fs'
|
|
28
29
|
import { createRequire } from 'node:module'
|
|
29
30
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
31
|
+
import { librariesOf } from './libraries.js'
|
|
30
32
|
|
|
31
33
|
// `@source not "…"` excludes a path and `@source inline("…")` names no path: neither has a quote
|
|
32
34
|
// right after the keyword.
|
|
@@ -262,6 +264,87 @@ export function unreadFoldersWarning(unread) {
|
|
|
262
264
|
].join('\n')
|
|
263
265
|
}
|
|
264
266
|
|
|
267
|
+
/** The library's own stylesheet, when importing it reads the library: its line, else null. */
|
|
268
|
+
function libraryStylesheetLine(lib) {
|
|
269
|
+
const sheet = join(lib.dir, 'styles.css')
|
|
270
|
+
if (!existsSync(sheet)) return null
|
|
271
|
+
// ⛔ An `exports` map without the stylesheet refuses the import, in Tailwind and in Node alike.
|
|
272
|
+
let pkg = null
|
|
273
|
+
try {
|
|
274
|
+
pkg = JSON.parse(readFileSync(join(lib.dir, 'package.json'), 'utf8'))
|
|
275
|
+
} catch {
|
|
276
|
+
// no manifest to refuse it
|
|
277
|
+
}
|
|
278
|
+
const exp = pkg?.exports
|
|
279
|
+
if (exp && typeof exp === 'object' && !Object.keys(exp).some((k) => k === './styles.css' || k === './*')) return null
|
|
280
|
+
const covers = pathsRead(sheet).some((path) => lib.dir === path || lib.dir.startsWith(path + sep))
|
|
281
|
+
return covers ? `@import "${lib.name}/styles.css";` : null
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* ⭐ The libraries a foundation bundles whose classes no `@source` reads: local packages it depends
|
|
286
|
+
* on (`librariesOf`), outside the stylesheet's folder, that write classes.
|
|
287
|
+
*
|
|
288
|
+
* Tailwind reads the folder it is rooted in and whatever `@source` names, and a library is outside
|
|
289
|
+
* the foundation. So a class only a library uses is in no CSS at all: not the foundation's own,
|
|
290
|
+
* which a hosted site loads with the foundation, and not a site build's. Measured 2026-11-09 on a
|
|
291
|
+
* foundation whose sections render a library's component, with the library's stylesheet left out
|
|
292
|
+
* of the foundation's: both builds exited 0, and `ring-primary-500`, `tracking-tight` and
|
|
293
|
+
* `space-y-1`, used only in the library, were in neither CSS.
|
|
294
|
+
*
|
|
295
|
+
* ⚖️ It errs toward saying nothing, as `unreadFolders` does: any `@source` at, above or inside a
|
|
296
|
+
* library reads it, and a library that writes no classes needs none. A library inside the
|
|
297
|
+
* stylesheet's folder is the foundation's code to `unreadFolders`.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} stylesPath - the foundation's stylesheet; none there, nothing to say
|
|
300
|
+
* @param {string} packageDir - the foundation's folder, the one its package.json is in
|
|
301
|
+
* @returns {Array<{ name: string, files: number, line: string }>} each library by the name the
|
|
302
|
+
* foundation depends on it by, how many of its files write classes, and the line that reads it
|
|
303
|
+
*/
|
|
304
|
+
export function unreadLibraries(stylesPath, packageDir) {
|
|
305
|
+
let stylesheet, css
|
|
306
|
+
try {
|
|
307
|
+
stylesheet = realpathSync(stylesPath)
|
|
308
|
+
css = withoutComments(readFileSync(stylesheet, 'utf8'))
|
|
309
|
+
} catch {
|
|
310
|
+
return []
|
|
311
|
+
}
|
|
312
|
+
if (!USES_TAILWIND.test(css)) return []
|
|
313
|
+
|
|
314
|
+
const dir = dirname(stylesheet)
|
|
315
|
+
const read = pathsRead(stylesheet)
|
|
316
|
+
const unread = []
|
|
317
|
+
for (const lib of librariesOf(packageDir)) {
|
|
318
|
+
if (lib.dir === dir || lib.dir.startsWith(dir + sep)) continue
|
|
319
|
+
if (read.some((path) => lib.dir === path || lib.dir.startsWith(path + sep) || path.startsWith(lib.dir + sep))) continue
|
|
320
|
+
let files = 0
|
|
321
|
+
for (const file of codeFiles(lib.dir)) {
|
|
322
|
+
if (writesClasses(withoutComments(readFileSync(file, 'utf8')))) files++
|
|
323
|
+
}
|
|
324
|
+
if (!files) continue
|
|
325
|
+
const rel = relative(dir, lib.dir).split(sep).join('/')
|
|
326
|
+
unread.push({ name: lib.name, files, line: libraryStylesheetLine(lib) ?? `@source "${rel.startsWith('.') ? rel : `./${rel}`}";` })
|
|
327
|
+
}
|
|
328
|
+
return unread
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* What a foundation build, a site build and `uniweb dev` print when `unreadLibraries` finds any,
|
|
333
|
+
* each the CSS it makes: a site build of a stale foundation runs both builds, and says both.
|
|
334
|
+
*
|
|
335
|
+
* @param {Array<{ name: string, line: string }>} unread
|
|
336
|
+
* @param {{ build?: 'foundation'|'site' }} [options] - the build that prints it
|
|
337
|
+
*/
|
|
338
|
+
export function unreadLibrariesWarning(unread, { build = 'site' } = {}) {
|
|
339
|
+
const named = unread.map(({ name }) => name).join(', ')
|
|
340
|
+
const many = unread.length > 1
|
|
341
|
+
const lost = build === 'foundation' ? "the foundation's CSS, which a hosted site loads with it" : "this site's CSS, and from the foundation's own"
|
|
342
|
+
return [
|
|
343
|
+
`[uniweb] The foundation bundles ${named}, and its styles.css reads no classes from ${many ? 'them' : 'it'}, so any class only ${many ? 'they write is' : 'it writes is'} missing from ${lost}. Add to the foundation's styles.css:`,
|
|
344
|
+
...unread.map(({ line }) => ` ${line}`)
|
|
345
|
+
].join('\n')
|
|
346
|
+
}
|
|
347
|
+
|
|
265
348
|
/** A stale line's note: what is missing, and where it is instead when that is known. */
|
|
266
349
|
export const staleSourceNote = ({ missing, foundAt }) => `no ${missing}${foundAt ? `; it is at ${foundAt}` : ''}`
|
|
267
350
|
|
package/src/index.js
CHANGED
|
@@ -85,7 +85,11 @@ export {
|
|
|
85
85
|
|
|
86
86
|
// Foundation source root resolution (reads package.json::main)
|
|
87
87
|
export { resolveFoundationSrcDir, resolveFoundationSrcPath } from './utils/foundation-source-root.js'
|
|
88
|
-
export { staleSources, staleSourceNote, unreadFolders } from './foundation/stale-sources.js'
|
|
88
|
+
export { staleSources, staleSourceNote, unreadFolders, unreadLibraries } from './foundation/stale-sources.js'
|
|
89
|
+
|
|
90
|
+
// A library is any local package a foundation depends on: the one rule for what else a foundation's
|
|
91
|
+
// build reads, which the CLI's freshness check asks
|
|
92
|
+
export { librariesOf } from './foundation/libraries.js'
|
|
89
93
|
|
|
90
94
|
// Package classification (foundation vs site vs standalone schemas package)
|
|
91
95
|
export { classifyPackage, isExtensionPackage, isSchemasPackage } from './utils/classify-package.js'
|
package/src/prerender.js
CHANGED
|
@@ -1322,7 +1322,7 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
1322
1322
|
locale,
|
|
1323
1323
|
})
|
|
1324
1324
|
if (count > 0) {
|
|
1325
|
-
onProgress(` Page markdown: ${count
|
|
1325
|
+
onProgress(` Page markdown: ${count === 1 ? '1 page now carries' : `${count} pages now carry`} the records their sections show`)
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
1328
1328
|
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* '@std/name' → the shared standard schemas, shipped in the framework's
|
|
12
12
|
* `@uniweb/schemas` package (resolved from the FOUNDATION's
|
|
13
13
|
* node_modules)
|
|
14
|
-
* '@org/name' → an org's own schemas: the package of this workspace
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* backend. (The org
|
|
20
|
-
* time.)
|
|
14
|
+
* '@org/name' → an org's own schemas: the package of this workspace, or the
|
|
15
|
+
* library this foundation bundles, whose name or `uniweb.scope`
|
|
16
|
+
* gives the scope and that defines `name` (a foundation's own
|
|
17
|
+
* `schemas/`, or a schemas package), with nothing configured;
|
|
18
|
+
* else that org's installed `@org/schemas` package. Either way
|
|
19
|
+
* shared across foundations locally, no backend. (The org
|
|
20
|
+
* becomes a real registry scope at publish time.)
|
|
21
21
|
* '@uniweb/name' → reserved: the platform system namespace, not a data
|
|
22
22
|
* schema source (rejected, with a pointer to '@std').
|
|
23
23
|
*
|
|
@@ -284,15 +284,15 @@ export async function resolveSchemaRef(ref, { srcDir, aliases }) {
|
|
|
284
284
|
return normalizeNamedSchema(await loadSchemaFile(file), ref)
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
// ⭐ A type another package of this workspace
|
|
288
|
-
// or a schemas package of it, read with nothing configured
|
|
289
|
-
// routes `schemas.config.js` gives, which are explicit, and
|
|
290
|
-
// workspace is the copy being worked on. Two
|
|
291
|
-
// there is one definition of a type.
|
|
287
|
+
// ⭐ A type another package of this workspace, or a library this foundation bundles, defines: a
|
|
288
|
+
// foundation whose name gives the scope, or a schemas package of it, read with nothing configured
|
|
289
|
+
// (`workspaceTypeFiles`). After the routes `schemas.config.js` gives, which are explicit, and
|
|
290
|
+
// before an installed package, since a workspace or a library is the copy being worked on. Two
|
|
291
|
+
// packages defining it are refused, naming both: there is one definition of a type.
|
|
292
292
|
const inWorkspace = await workspaceTypeFiles(`@${scope}/${name}`, srcDir)
|
|
293
293
|
if (inWorkspace.length > 1) {
|
|
294
294
|
throw new Error(
|
|
295
|
-
`Data schema '${ref}' is defined by ${inWorkspace.length} packages
|
|
295
|
+
`Data schema '${ref}' is defined by ${inWorkspace.length} packages this foundation reads: ` +
|
|
296
296
|
`${inWorkspace.join(', ')}. A type has one definition: keep one file, and name the type in ` +
|
|
297
297
|
`full in the others (\`uniweb doctor\` lists them as type-defined-twice).`
|
|
298
298
|
)
|
|
@@ -307,11 +307,12 @@ export async function resolveSchemaRef(ref, { srcDir, aliases }) {
|
|
|
307
307
|
if (pkg !== SCOPE_PACKAGE.std && !isScopePackageInstalled(scope, srcDir)) {
|
|
308
308
|
throw Object.assign(
|
|
309
309
|
new Error(
|
|
310
|
-
`Data schema '${ref}' is defined nowhere this foundation can read: no package of its workspace ` +
|
|
311
|
-
`whose name gives the scope '@${scope}' defines '${name}', and '${pkg}'
|
|
312
|
-
`
|
|
313
|
-
`
|
|
314
|
-
`
|
|
310
|
+
`Data schema '${ref}' is defined nowhere this foundation can read: no package of its workspace, ` +
|
|
311
|
+
`and no library it bundles, whose name gives the scope '@${scope}' defines '${name}', and '${pkg}' ` +
|
|
312
|
+
`is not installed. Keep it in the schemas/ of a library the foundation depends on, whose ` +
|
|
313
|
+
`package.json gives "uniweb": { "scope": "@${scope}" }; name the foundation that defines it ` +
|
|
314
|
+
`'@${scope}/<name>' in its main.js; route the type with schemas.config.js ` +
|
|
315
|
+
`('@${scope}/${name}': '<its file>'); or add '${pkg}' to the foundation's devDependencies.`
|
|
315
316
|
),
|
|
316
317
|
{ code: SCHEMA_NOT_FOUND }
|
|
317
318
|
)
|
package/src/site/config.js
CHANGED
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
24
|
-
import { resolve, dirname, join } from 'node:path'
|
|
24
|
+
import { resolve, dirname, join, sep } from 'node:path'
|
|
25
25
|
import yaml from 'js-yaml'
|
|
26
26
|
import { YAML_OPTIONS } from '../utils/yaml-schema.js'
|
|
27
|
-
import { unreadFolders, unreadFoldersWarning } from '../foundation/stale-sources.js'
|
|
27
|
+
import { unreadFolders, unreadFoldersWarning, unreadLibraries, unreadLibrariesWarning } from '../foundation/stale-sources.js'
|
|
28
28
|
import {
|
|
29
29
|
generateEntryPoint,
|
|
30
30
|
shouldRegenerateForFile,
|
|
@@ -37,12 +37,22 @@ import { resolveModuleUrl, resolveExtensionUrls } from './extension-urls.js'
|
|
|
37
37
|
import { resolveFoundationSrcPath } from '../utils/foundation-source-root.js'
|
|
38
38
|
import { checkFoundationResolution } from '../utils/foundation-resolution-check.js'
|
|
39
39
|
import { detectFoundationType } from './foundation-ref.js'
|
|
40
|
+
import { librariesOf } from '../foundation/libraries.js'
|
|
40
41
|
import { readPreview, PREVIEW_ENV } from './preview.js'
|
|
41
42
|
import { previewMediaPlugin } from './preview-media.js'
|
|
42
43
|
import { previewDirectoryIndexPlugin } from './preview-directory-index.js'
|
|
43
44
|
import { devServerRecordPlugin, requestedDevPort } from './dev-server.js'
|
|
44
45
|
import { refuseSearchOption } from './search-declared.js'
|
|
45
46
|
|
|
47
|
+
/** A folder's real path, or the path itself when it cannot be read. */
|
|
48
|
+
const realpathOr = (path) => {
|
|
49
|
+
try {
|
|
50
|
+
return realpathSync(path)
|
|
51
|
+
} catch {
|
|
52
|
+
return path
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
/**
|
|
47
57
|
* Normalize a base path for Vite compatibility
|
|
48
58
|
*
|
|
@@ -292,6 +302,9 @@ export async function defineSiteConfig(options = {}) {
|
|
|
292
302
|
// missing, in a site build and under `uniweb dev`, while its own build has them all.
|
|
293
303
|
const unread = unreadFolders(join(srcDir, 'styles.css'))
|
|
294
304
|
if (unread.length) console.warn(unreadFoldersWarning(unread))
|
|
305
|
+
// And a library it bundles that no `@source` reads, whose classes no CSS has.
|
|
306
|
+
const libraries = unreadLibraries(join(srcDir, 'styles.css'), foundationInfo.path)
|
|
307
|
+
if (libraries.length) console.warn(unreadLibrariesWarning(libraries))
|
|
295
308
|
}
|
|
296
309
|
},
|
|
297
310
|
|
|
@@ -574,6 +587,16 @@ export async function defineSiteConfig(options = {}) {
|
|
|
574
587
|
}
|
|
575
588
|
}
|
|
576
589
|
}
|
|
590
|
+
// ⭐ And each library the bundled foundation imports, from wherever it is (`librariesOf`).
|
|
591
|
+
// Vite serves what an import reaches anyway; this is for what only a stylesheet names.
|
|
592
|
+
// ⛔ Until 2026-11-09 an image or font a library outside the workspace names in its CSS
|
|
593
|
+
// was refused, "403 … outside of Vite serving allow list" (measured under npm, `file:`).
|
|
594
|
+
if (!isRuntimeMode && foundationInfo.type === 'local' && foundationInfo.path) {
|
|
595
|
+
const within = realpathOr(parentDir)
|
|
596
|
+
for (const { dir } of librariesOf(foundationInfo.path)) {
|
|
597
|
+
if (dir !== within && !dir.startsWith(within + sep)) allowed.push(dir)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
577
600
|
return allowed
|
|
578
601
|
})()
|
|
579
602
|
},
|
package/src/site/projections.js
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
renderSiteIndex,
|
|
29
29
|
renderPageMarkdown,
|
|
30
30
|
resolveAgentsConfig,
|
|
31
|
-
|
|
31
|
+
markdownPageRule,
|
|
32
32
|
selectIndexBranches,
|
|
33
33
|
pageMarkdownFilename,
|
|
34
34
|
branchIndexFilename,
|
|
@@ -136,15 +136,18 @@ export function agentFiles(content, records, { sections = null } = {}) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
if (agents.markdown) {
|
|
139
|
-
|
|
139
|
+
// ⭐ Which pages have one is `markdownPageRule`'s: the rule a host answers a request for one by
|
|
140
|
+
// (`resolvePageMarkdown`), so a static build writes a page's markdown exactly where a host
|
|
141
|
+
// serves one for the same content.
|
|
142
|
+
const rule = markdownPageRule(content)
|
|
143
|
+
for (const page of content.pages.filter(rule.page)) {
|
|
140
144
|
const markdown = renderPageMarkdown(page, { sections: sections?.get(page.route) })
|
|
141
145
|
if (markdown) files.push({ kind: 'markdown', fileName: `${prefix}${pageMarkdownFilename(at(page.route))}`, source: markdown, route: page.route })
|
|
142
146
|
}
|
|
143
|
-
// Each record's page,
|
|
144
|
-
//
|
|
145
|
-
const listed = indexableRecordRoutes(content.pages, records?.pages, agents.exclude)
|
|
147
|
+
// Each record's page, by the same rule: a record under a branch `llms.txt` leaves out gets no
|
|
148
|
+
// file, as it gets no line there.
|
|
146
149
|
for (const { route, markdown } of records?.pages || []) {
|
|
147
|
-
if (!
|
|
150
|
+
if (!rule.record(route)) continue
|
|
148
151
|
files.push({ kind: 'markdown', fileName: `${prefix}${pageMarkdownFilename(routeOnDisk(at(route)))}`, source: markdown, route })
|
|
149
152
|
}
|
|
150
153
|
}
|
|
@@ -184,15 +187,3 @@ export function describeProjections(files) {
|
|
|
184
187
|
if (markdown) lines.push(`Generated ${markdown} page markdown projections (the records their sections show are added by prerendering)`)
|
|
185
188
|
return lines
|
|
186
189
|
}
|
|
187
|
-
|
|
188
|
-
/** The routes of the record pages `llms.txt` lists, judged among the site's own pages. */
|
|
189
|
-
function indexableRecordRoutes(pages = [], recordPages = [], exclude) {
|
|
190
|
-
if (!recordPages?.length) return new Set()
|
|
191
|
-
const routes = new Set(recordPages.map((page) => page.route))
|
|
192
|
-
const candidates = [...pages, ...recordPages.map(({ route }) => ({ route }))]
|
|
193
|
-
return new Set(
|
|
194
|
-
selectIndexablePages(candidates, { exclude })
|
|
195
|
-
.map((page) => page.route)
|
|
196
|
-
.filter((route) => routes.has(route))
|
|
197
|
-
)
|
|
198
|
-
}
|
|
@@ -17,7 +17,7 @@ import { generateFoundationVars } from './theme/index.js'
|
|
|
17
17
|
import { DEFAULT_EXTERNALS } from './import-map-plugin.js'
|
|
18
18
|
import { deriveSupports } from './foundation/derive-supports.js'
|
|
19
19
|
import { proseWithoutStyles, PROSE_WITHOUT_STYLES_WARNING } from './foundation/prose-styles.js'
|
|
20
|
-
import { staleSources, staleSourcesWarning } from './foundation/stale-sources.js'
|
|
20
|
+
import { staleSources, staleSourcesWarning, unreadLibraries, unreadLibrariesWarning } from './foundation/stale-sources.js'
|
|
21
21
|
import { nodeEnvDefine } from './foundation/node-env.js'
|
|
22
22
|
import { foundationScopeDefine } from './foundation/scope-define.js'
|
|
23
23
|
import { ssrDormantDynamicImports } from './foundation/ssr-dormant-imports.js'
|
|
@@ -29,6 +29,7 @@ import { DEV_REBUILD_MARKER, hasDevRebuildMarker } from './foundation/dev-rebuil
|
|
|
29
29
|
const warnedProseWithoutStyles = new Set()
|
|
30
30
|
// Likewise for a `@source` that finds nothing.
|
|
31
31
|
const warnedStaleSources = new Set()
|
|
32
|
+
const warnedUnreadLibraries = new Set()
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Build schema.json with preview image references
|
|
@@ -469,6 +470,16 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
472
|
|
|
473
|
+
// A library it bundles whose classes no `@source` reads: missing from this CSS, which a hosted
|
|
474
|
+
// site loads with the foundation, and from a site build's (`unreadLibraries`).
|
|
475
|
+
if (!warnedUnreadLibraries.has(resolvedSrcDir)) {
|
|
476
|
+
const unread = unreadLibraries(join(resolvedSrcDir, 'styles.css'), resolvedRoot)
|
|
477
|
+
if (unread.length) {
|
|
478
|
+
warnedUnreadLibraries.add(resolvedSrcDir)
|
|
479
|
+
console.warn(unreadLibrariesWarning(unread, { build: 'foundation' }))
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
472
483
|
// What host services this foundation actually reaches for, read off the
|
|
473
484
|
// post-tree-shake module graph rather than asked for in package.json.
|
|
474
485
|
//
|