@uniweb/build 1.13.6 → 1.13.8
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 +5 -5
- package/src/foundation/stale-sources.js +89 -0
- package/src/generate-entry.js +6 -3
- package/src/i18n/index.js +15 -1
- package/src/i18n/merge.js +25 -0
- package/src/index.js +1 -0
- package/src/schema.js +3 -3
- package/src/site/file-records.js +12 -2
- package/src/vite-foundation-plugin.js +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.8",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
59
|
"@uniweb/content-reader": "~1.5.7",
|
|
60
60
|
"@uniweb/content-writer": "~1.3.1",
|
|
61
|
-
"@uniweb/schemas": "~1.6.7",
|
|
62
|
-
"@uniweb/semantic-parser": "~1.13.0",
|
|
63
61
|
"@uniweb/projections": "~1.2.9",
|
|
62
|
+
"@uniweb/semantic-parser": "~1.13.0",
|
|
63
|
+
"@uniweb/schemas": "~1.6.7",
|
|
64
64
|
"@uniweb/theming": "~1.2.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.3.
|
|
67
|
+
"@uniweb/runtime": "~1.3.5"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
76
|
"@uniweb/core": "~1.5.1",
|
|
77
|
-
"@uniweb/runtime": "~1.3.
|
|
77
|
+
"@uniweb/runtime": "~1.3.5"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `@source` that finds nothing — the CSS loses what was behind it, and nothing says so.
|
|
3
|
+
*
|
|
4
|
+
* `@source` tells Tailwind where else to look for class names, relative to the stylesheet. A path
|
|
5
|
+
* that leads nowhere is no error to Tailwind: the build succeeds, and every class found only
|
|
6
|
+
* there is missing from the CSS. Measured 2026-10-31 on four foundations moved up a level with
|
|
7
|
+
* `@source "../node_modules/@uniweb/kit/src/**"` left as it was: exit 0, and CSS of 128,255 bytes
|
|
8
|
+
* down to 78,634, with only the foundation's digest to show it. And on a template installed with
|
|
9
|
+
* npm, which hoists kit to the workspace's root, away from the `./node_modules/@uniweb/kit` the
|
|
10
|
+
* template names: 39,183 bytes where pnpm gave 51,967, from the first build.
|
|
11
|
+
*
|
|
12
|
+
* ⚖️ Only a path that reaches outside the foundation's own source counts: one that climbs, or one
|
|
13
|
+
* into `node_modules`. A starter's `./components/**` names a folder a foundation may not have
|
|
14
|
+
* yet, and with no such folder there is nothing to lose.
|
|
15
|
+
*
|
|
16
|
+
* @module @uniweb/build/foundation/stale-sources
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
20
|
+
import { dirname, join, relative, resolve } from 'node:path'
|
|
21
|
+
|
|
22
|
+
// `@source not "…"` excludes a path and `@source inline("…")` names no path: neither has a quote
|
|
23
|
+
// right after the keyword.
|
|
24
|
+
const SOURCE = /@source\s+(["'])(.+?)\1/g
|
|
25
|
+
|
|
26
|
+
/** The part of a glob with no pattern in it: the folder it starts from. */
|
|
27
|
+
function fixedPrefix(glob) {
|
|
28
|
+
const at = glob.search(/[*?[{(!]/)
|
|
29
|
+
return at < 0 ? glob : glob.slice(0, glob.lastIndexOf('/', at) + 1)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const reachesOut = (path) => path.startsWith('../') || /(^|\/)node_modules(\/|$)/.test(path)
|
|
33
|
+
|
|
34
|
+
// ⛔ Quoted strings are skipped, not searched: a glob's `/**/` reads exactly like a comment.
|
|
35
|
+
const withoutComments = (css) =>
|
|
36
|
+
css.replace(/("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')|\/\*[\s\S]*?\*\//g, (_, quoted) => quoted ?? '')
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The `@source` lines of a stylesheet that reach outside the foundation and find nothing.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} stylesPath - the foundation's stylesheet; none there, none stale
|
|
42
|
+
* @returns {Array<{ source: string, missing: string, foundAt: string|null }>} each path as written,
|
|
43
|
+
* the part of it that does not exist, and, for a package, where it is from the stylesheet
|
|
44
|
+
*/
|
|
45
|
+
export function staleSources(stylesPath) {
|
|
46
|
+
let css
|
|
47
|
+
try {
|
|
48
|
+
css = readFileSync(stylesPath, 'utf8')
|
|
49
|
+
} catch {
|
|
50
|
+
return []
|
|
51
|
+
}
|
|
52
|
+
const dir = dirname(stylesPath)
|
|
53
|
+
const stale = []
|
|
54
|
+
for (const [, , source] of withoutComments(css).matchAll(SOURCE)) {
|
|
55
|
+
const missing = fixedPrefix(source)
|
|
56
|
+
if (missing && reachesOut(source) && !existsSync(resolve(dir, missing))) {
|
|
57
|
+
stale.push({ source, missing, foundAt: foundAbove(dir, missing) })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return stale
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Where a path into `node_modules` does lead, looking up from the stylesheet as a package is
|
|
65
|
+
* resolved: relative to the stylesheet, or null when that package is nowhere above it.
|
|
66
|
+
*/
|
|
67
|
+
function foundAbove(dir, missing) {
|
|
68
|
+
const tail = /(?:^|\/)(node_modules\/.*)$/.exec(missing)?.[1]
|
|
69
|
+
if (!tail) return null
|
|
70
|
+
for (let at = dir; ; at = dirname(at)) {
|
|
71
|
+
if (existsSync(join(at, tail))) {
|
|
72
|
+
const rel = relative(dir, join(at, tail))
|
|
73
|
+
return rel.startsWith('.') ? rel : `./${rel}`
|
|
74
|
+
}
|
|
75
|
+
if (dirname(at) === at) return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A stale line's note: what is missing, and where it is instead when that is known. */
|
|
80
|
+
export const staleSourceNote = ({ missing, foundAt }) => `no ${missing}${foundAt ? `; it is at ${foundAt}` : ''}`
|
|
81
|
+
|
|
82
|
+
/** What the foundation build prints when `staleSources` finds any. */
|
|
83
|
+
export function staleSourcesWarning(stale) {
|
|
84
|
+
return [
|
|
85
|
+
'[uniweb] styles.css has a @source that finds nothing, so the CSS is missing every class that was only there:',
|
|
86
|
+
...stale.map((line) => ` @source "${line.source}" (${staleSourceNote(line)})`),
|
|
87
|
+
'Paths are relative to styles.css.'
|
|
88
|
+
].join('\n')
|
|
89
|
+
}
|
package/src/generate-entry.js
CHANGED
|
@@ -162,13 +162,13 @@ function generateEntrySource(components, options = {}) {
|
|
|
162
162
|
// Component imports
|
|
163
163
|
for (const name of componentNames) {
|
|
164
164
|
const { path, entryFile = `index.js` } = components[name]
|
|
165
|
-
lines.push(`import ${name} from './${path}/${entryFile}'`)
|
|
165
|
+
lines.push(`import ${name} from './${toPosix(path)}/${entryFile}'`)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// Layout imports
|
|
169
169
|
for (const name of layoutNames) {
|
|
170
170
|
const { path, entryFile = `index.js` } = layouts[name]
|
|
171
|
-
lines.push(`import ${name} from './${path}/${entryFile}'`)
|
|
171
|
+
lines.push(`import ${name} from './${toPosix(path)}/${entryFile}'`)
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
lines.push('')
|
|
@@ -388,7 +388,10 @@ export async function generateEntryPoint(srcDir, outputPath = null, options = {}
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* Normalize native path separators, so matching is platform-independent and a path written into
|
|
393
|
+
* generated JavaScript is one: in a string, the `\A` of `sections\Abstract` is just `A`.
|
|
394
|
+
*/
|
|
392
395
|
const toPosix = path => path.replace(/\\/g, '/')
|
|
393
396
|
|
|
394
397
|
/**
|
package/src/i18n/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { dataBlockModels } from './data-models.js'
|
|
|
18
18
|
import { syncManifests, formatSyncReport, formatKeptTranslations } from './sync.js'
|
|
19
19
|
import { keepEditedTranslations, rowsWantTranslation, manifestRows, settleFlags } from './outdated.js'
|
|
20
20
|
import { readKept, standingFlags } from '../uwx/locale-sync.js'
|
|
21
|
-
import { mergeTranslations, generateAllLocales } from './merge.js'
|
|
21
|
+
import { mergeTranslations, generateAllLocales, translationsHoldingHtml } from './merge.js'
|
|
22
22
|
import { auditLocale, cleanLocale, formatAuditReport } from './audit.js'
|
|
23
23
|
import {
|
|
24
24
|
extractRecordContent,
|
|
@@ -512,6 +512,20 @@ export async function buildLocalizedContent(siteRoot, options = {}) {
|
|
|
512
512
|
translations = JSON.parse(localeRaw)
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
+
// ⭐ HTML in a translation shows on the page as written. Pages and free-form translations say
|
|
516
|
+
// so as they are read; a table's values are read one by one deep in the merge, with no file in
|
|
517
|
+
// hand, so this says it once for the file. ⛔ Until 2026-10-31 nothing did: a site's headlines
|
|
518
|
+
// showed `<span primary="true">` in ten languages through a build and two publishes.
|
|
519
|
+
const holdingHtml = translationsHoldingHtml(translations)
|
|
520
|
+
if (holdingHtml.length) {
|
|
521
|
+
const n = holdingHtml.length
|
|
522
|
+
const keys = holdingHtml.slice(0, 8).join(', ') + (n > 8 ? `, and ${n - 8} more` : '')
|
|
523
|
+
console.warn(
|
|
524
|
+
`[i18n] ${localesDir}/${locale}.json: ${n} translation${n === 1 ? ' holds' : 's hold'} HTML, which shows on the page as written: ${keys}. ` +
|
|
525
|
+
'A translation is inline markdown: write a span as [text]{primary}.'
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
|
|
515
529
|
// Check if free-form translations exist for this locale
|
|
516
530
|
const freeformDir = join(localesPath, 'freeform', locale)
|
|
517
531
|
const hasFreeform = freeformEnabled && existsSync(freeformDir)
|
package/src/i18n/merge.js
CHANGED
|
@@ -418,6 +418,31 @@ function loneImage(fragment) {
|
|
|
418
418
|
return nodes.length === 1 && nodes[0].type === 'image' ? nodes[0] : null
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
+
/**
|
|
422
|
+
* The translations in a locale's table that hold HTML, by key. HTML is not content, so what the
|
|
423
|
+
* merge makes of such a value shows the tag on the page; the words are the merge's own, read the
|
|
424
|
+
* way it reads them (`@uniweb/content-reader`), and saying so is the caller's job.
|
|
425
|
+
*
|
|
426
|
+
* @param {Object} [translations] - a locale's table: `{ key: value }`, a value a string or
|
|
427
|
+
* `{ default, overrides }`
|
|
428
|
+
* @returns {string[]} the keys
|
|
429
|
+
*/
|
|
430
|
+
export function translationsHoldingHtml(translations) {
|
|
431
|
+
const holdsHtml = (value) => {
|
|
432
|
+
if (typeof value !== 'string') return false
|
|
433
|
+
let found = false
|
|
434
|
+
inlineMarkdownToProseMirror(value.trim(), { onWarning: () => (found = true) })
|
|
435
|
+
return found
|
|
436
|
+
}
|
|
437
|
+
return Object.entries(translations || {})
|
|
438
|
+
.filter(([, entry]) =>
|
|
439
|
+
typeof entry === 'string'
|
|
440
|
+
? holdsHtml(entry)
|
|
441
|
+
: holdsHtml(entry?.default) || Object.values(entry?.overrides || {}).some(holdsHtml)
|
|
442
|
+
)
|
|
443
|
+
.map(([key]) => key)
|
|
444
|
+
}
|
|
445
|
+
|
|
421
446
|
/**
|
|
422
447
|
* Does a translation keep the inline markup of its source element? The merge's own answer —
|
|
423
448
|
* what `translatedInline` makes of the value — so the audit can neither report a loss the merge
|
package/src/index.js
CHANGED
|
@@ -85,6 +85,7 @@ 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 } from './foundation/stale-sources.js'
|
|
88
89
|
|
|
89
90
|
// Package classification (foundation vs site vs standalone schemas package)
|
|
90
91
|
export { classifyPackage, isExtensionPackage, isSchemasPackage } from './utils/classify-package.js'
|
package/src/schema.js
CHANGED
|
@@ -1234,8 +1234,8 @@ export function reportPlacementDeclarations(components) {
|
|
|
1234
1234
|
* Returns { _self: { identity + config }, ComponentName: componentMeta, ... }
|
|
1235
1235
|
*
|
|
1236
1236
|
* The _self object contains:
|
|
1237
|
-
* - Identity from package.json (
|
|
1238
|
-
* -
|
|
1237
|
+
* - Identity from package.json (version, description, and the name when main.js gives none)
|
|
1238
|
+
* - Declarations from main.js (name, vars, etc.)
|
|
1239
1239
|
*
|
|
1240
1240
|
* @param {string} srcDir - Source directory
|
|
1241
1241
|
* @param {string[]} [sectionPaths] - Paths to scan for section types
|
|
@@ -1247,7 +1247,7 @@ export async function buildSchema(srcDir, sectionPaths, derivedSupports = null)
|
|
|
1247
1247
|
// Load identity from package.json
|
|
1248
1248
|
const identity = await loadPackageJson(srcDir)
|
|
1249
1249
|
|
|
1250
|
-
// Load
|
|
1250
|
+
// Load the declarations from main.js
|
|
1251
1251
|
const foundationConfig = await loadFoundationConfig(srcDir)
|
|
1252
1252
|
|
|
1253
1253
|
refuseDataDeclarations('the foundation (main.js)', lowerData(foundationConfig.data))
|
package/src/site/file-records.js
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
import { statSync } from 'node:fs'
|
|
19
19
|
import { extname } from 'node:path'
|
|
20
20
|
import { mimeFor } from '@uniweb/semantic-parser'
|
|
21
|
-
import { generatePdfThumbnail } from './advanced-processors.js'
|
|
22
21
|
|
|
23
22
|
export const FILE_MODEL = '@uniweb/file'
|
|
24
23
|
|
|
@@ -51,12 +50,23 @@ export function fileRecordValue({ absPath, name, url, preview }) {
|
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
52
|
* Make a PDF's preview image at `outputPath` — a placeholder card, not a render of the page — or
|
|
54
|
-
* report that none was made (not a PDF, or `pdf-lib` not
|
|
53
|
+
* report that none was made (not a PDF, or `pdf-lib` or `sharp` not available).
|
|
54
|
+
*
|
|
55
|
+
* ⛔ The card's module is loaded here, not at the top of this file. This file is on the chain of
|
|
56
|
+
* `@uniweb/build/content`, which promises no `sharp`, and that module imports `sharp` as it loads:
|
|
57
|
+
* a standalone binary has no native `sharp`, and with the import at the top it could not start, on
|
|
58
|
+
* any command (`tests/content-entry-graph.test.js`).
|
|
55
59
|
*
|
|
56
60
|
* @returns {Promise<boolean>} whether a preview now exists at `outputPath`
|
|
57
61
|
*/
|
|
58
62
|
export async function makeFilePreview(absPath, outputPath) {
|
|
59
63
|
if (!isPdfFile(absPath)) return false
|
|
64
|
+
let generatePdfThumbnail
|
|
65
|
+
try {
|
|
66
|
+
;({ generatePdfThumbnail } = await import('./advanced-processors.js'))
|
|
67
|
+
} catch {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
60
70
|
const result = await generatePdfThumbnail(absPath, outputPath)
|
|
61
71
|
return Boolean(result?.success)
|
|
62
72
|
}
|
|
@@ -17,6 +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
21
|
import { nodeEnvDefine } from './foundation/node-env.js'
|
|
21
22
|
import { foundationScopeDefine } from './foundation/scope-define.js'
|
|
22
23
|
import { ssrDormantDynamicImports } from './foundation/ssr-dormant-imports.js'
|
|
@@ -26,6 +27,8 @@ import { DEV_REBUILD_MARKER, hasDevRebuildMarker } from './foundation/dev-rebuil
|
|
|
26
27
|
// Foundations already told that their prose has no stylesheet — once per process, so a dev
|
|
27
28
|
// server's rebuild on every save does not repeat it.
|
|
28
29
|
const warnedProseWithoutStyles = new Set()
|
|
30
|
+
// Likewise for a `@source` that finds nothing.
|
|
31
|
+
const warnedStaleSources = new Set()
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* Build schema.json with preview image references
|
|
@@ -451,6 +454,16 @@ export function foundationBuildPlugin(options = {}) {
|
|
|
451
454
|
console.warn(PROSE_WITHOUT_STYLES_WARNING)
|
|
452
455
|
}
|
|
453
456
|
|
|
457
|
+
// A `@source` that finds nothing: the build succeeds and the CSS is short every class that
|
|
458
|
+
// was only there, and nothing else says so (`foundation/stale-sources.js`).
|
|
459
|
+
if (!warnedStaleSources.has(resolvedSrcDir)) {
|
|
460
|
+
const stale = staleSources(join(resolvedSrcDir, 'styles.css'))
|
|
461
|
+
if (stale.length) {
|
|
462
|
+
warnedStaleSources.add(resolvedSrcDir)
|
|
463
|
+
console.warn(staleSourcesWarning(stale))
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
454
467
|
// What host services this foundation actually reaches for, read off the
|
|
455
468
|
// post-tree-shake module graph rather than asked for in package.json.
|
|
456
469
|
//
|