uniweb 0.12.18 → 0.12.19

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": "0.12.18",
3
+ "version": "0.12.19",
4
4
  "description": "Create structured Vite + React sites with content/code separation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,9 +41,9 @@
41
41
  "js-yaml": "^4.1.0",
42
42
  "prompts": "^2.4.2",
43
43
  "tar": "^7.0.0",
44
+ "@uniweb/core": "0.7.11",
44
45
  "@uniweb/kit": "0.9.11",
45
- "@uniweb/runtime": "0.8.13",
46
- "@uniweb/core": "0.7.11"
46
+ "@uniweb/runtime": "0.8.13"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@uniweb/build": "0.14.4",
@@ -45,8 +45,8 @@
45
45
  * --bundle # Full vite pipeline (third-party hosts)
46
46
  */
47
47
 
48
- import { existsSync, readFileSync } from 'node:fs'
49
- import { resolve, join, dirname } from 'node:path'
48
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
49
+ import { resolve, join, dirname, basename } from 'node:path'
50
50
  import { spawn } from 'node:child_process'
51
51
  import { writeFile, mkdir } from 'node:fs/promises'
52
52
  import { createRequire } from 'node:module'
@@ -243,6 +243,118 @@ async function buildFoundation(projectDir, options = {}) {
243
243
  log(` ${colors.bright}uniweb handoff <email>${colors.reset} Hand off a site to a client`)
244
244
  }
245
245
 
246
+ /**
247
+ * Ensure a local foundation's `dist/entry.js` is current.
248
+ *
249
+ * Whenever a build or deploy reads a local foundation from disk — bundle
250
+ * mode (vite imports it, prerender loads it for SSG), or link mode where
251
+ * the foundation is uploaded alongside the site — the foundation must be
252
+ * built and current. Otherwise the verb fails with "Foundation not found
253
+ * at .../dist/entry.js" or silently ships stale artifacts.
254
+ *
255
+ * `buildWorkspace()` already cascades when invoked from a workspace root,
256
+ * but verbs invoked from a site directory (`uniweb build` in `sites/x/`,
257
+ * `uniweb deploy`, `uniweb export`) used to skip the cascade and rely on
258
+ * the user having pre-built the foundation. That broke fresh checkouts
259
+ * where the foundation has never been built locally.
260
+ *
261
+ * This helper is idempotent: when the workspace-root cascade has already
262
+ * run, the freshness check sees a current `dist/entry.js` and returns
263
+ * without rebuilding. So adding the call inside `buildSite()` /
264
+ * `buildSiteLink()` does not double-build under `buildWorkspace()`.
265
+ *
266
+ * Freshness rule: a built artifact (`dist/entry.js` or the legacy
267
+ * `dist/foundation.js`) exists AND its mtime is >= the newest mtime of
268
+ * any tracked source file. Tracked sources: every file under
269
+ * `<foundation>/src/`, plus root-level `package.json`, `foundation.js`,
270
+ * `meta.js` (the structural files that drive entry generation and
271
+ * schema). Build outputs and node_modules are skipped.
272
+ *
273
+ * Both artifact names are accepted because the foundation build emitter
274
+ * was renamed `dist/foundation.js → dist/entry.js` in `@uniweb/build`
275
+ * v0.14.3. A foundation built with an older @uniweb/build still produces
276
+ * the legacy name; we don't want the cascade to keep rebuilding such a
277
+ * foundation forever just because the new name is missing.
278
+ */
279
+ async function ensureFoundationFresh(foundationDir, label = 'foundation') {
280
+ const distArtifact = findFoundationDistArtifact(foundationDir)
281
+
282
+ if (!distArtifact) {
283
+ info(`Local ${label} not built yet — building ${basename(foundationDir)} first`)
284
+ log('')
285
+ await buildFoundation(foundationDir)
286
+ log('')
287
+ return { built: true, reason: 'missing' }
288
+ }
289
+
290
+ const distMtime = statSync(distArtifact).mtimeMs
291
+ const stale = isFoundationSourceNewerThan(foundationDir, distMtime)
292
+
293
+ if (stale) {
294
+ info(`Local ${label} sources changed — rebuilding ${basename(foundationDir)}`)
295
+ log('')
296
+ await buildFoundation(foundationDir)
297
+ log('')
298
+ return { built: true, reason: 'stale' }
299
+ }
300
+
301
+ return { built: false, reason: 'fresh' }
302
+ }
303
+
304
+ /**
305
+ * Locate the foundation's built entry artifact. Returns the path of the
306
+ * first match, or null when neither file exists. Prefers the current
307
+ * name (`dist/entry.js`) over the legacy one (`dist/foundation.js`).
308
+ */
309
+ function findFoundationDistArtifact(foundationDir) {
310
+ for (const name of ['entry.js', 'foundation.js']) {
311
+ const p = join(foundationDir, 'dist', name)
312
+ if (existsSync(p)) return p
313
+ }
314
+ return null
315
+ }
316
+
317
+ /**
318
+ * Returns true if any tracked foundation source file has an mtime newer
319
+ * than `referenceMtime`. Walks `<foundationDir>/src/` recursively (skipping
320
+ * dotfiles, node_modules, and dist). Also stats the root structural files.
321
+ */
322
+ function isFoundationSourceNewerThan(foundationDir, referenceMtime) {
323
+ const rootFiles = ['package.json', 'foundation.js', 'meta.js']
324
+ for (const f of rootFiles) {
325
+ const p = join(foundationDir, f)
326
+ if (existsSync(p) && statSync(p).mtimeMs > referenceMtime) return true
327
+ }
328
+
329
+ const srcDir = join(foundationDir, 'src')
330
+ if (!existsSync(srcDir)) return false
331
+
332
+ const stack = [srcDir]
333
+ while (stack.length) {
334
+ const dir = stack.pop()
335
+ let entries
336
+ try {
337
+ entries = readdirSync(dir, { withFileTypes: true })
338
+ } catch {
339
+ continue
340
+ }
341
+ for (const e of entries) {
342
+ if (e.name === 'node_modules' || e.name === 'dist' || e.name.startsWith('.')) continue
343
+ const full = join(dir, e.name)
344
+ if (e.isDirectory()) {
345
+ stack.push(full)
346
+ continue
347
+ }
348
+ if (!e.isFile()) continue
349
+ try {
350
+ if (statSync(full).mtimeMs > referenceMtime) return true
351
+ } catch { /* ignore */ }
352
+ }
353
+ }
354
+
355
+ return false
356
+ }
357
+
246
358
  /**
247
359
  * Load site i18n configuration
248
360
  *
@@ -452,6 +564,11 @@ async function buildSiteLink(projectDir, options = {}) {
452
564
  // null and theme defaults come from theme.yml only.
453
565
  const foundationDir = await resolveFoundationDirForSite(projectDir, siteConfig).catch(() => null)
454
566
 
567
+ // Cascade: a local foundation in link mode is uploaded alongside the
568
+ // site (site-bound mode), so its dist must be current. Idempotent under
569
+ // buildWorkspace() — the freshness check no-ops when already built.
570
+ if (foundationDir) await ensureFoundationFresh(foundationDir)
571
+
455
572
  await buildSiteData({
456
573
  siteRoot: projectDir,
457
574
  distDir,
@@ -548,6 +665,12 @@ async function buildSite(projectDir, options = {}) {
548
665
 
549
666
  info('Building site...')
550
667
 
668
+ // Cascade: bundle mode imports the foundation through vite, and (when
669
+ // prerender is on) loads dist/entry.js for SSG. A local foundation must
670
+ // therefore be current. Idempotent under buildWorkspace() — when the
671
+ // workspace cascade has already built it, the freshness check no-ops.
672
+ if (foundationDir) await ensureFoundationFresh(foundationDir)
673
+
551
674
  // Run vite build for sites
552
675
  await runLocalVite(projectDir, ['build'])
553
676
 
@@ -924,7 +1047,20 @@ export async function build(args = []) {
924
1047
  if (prerenderFlag) prerender = true
925
1048
  if (noPrerenderFlag) prerender = false
926
1049
 
927
- await buildSite(projectDir, { prerender, foundationDir, siteConfig, host })
1050
+ // If `--foundation-dir` wasn't passed, resolve the local foundation
1051
+ // from site.yml + package.json. Required so buildSite() can cascade
1052
+ // to the local foundation when the user runs `uniweb build` from a
1053
+ // site dir on a fresh checkout where dist/ doesn't exist yet.
1054
+ const resolvedFoundationDir =
1055
+ foundationDir
1056
+ || (await resolveFoundationDirForSite(projectDir, siteConfig).catch(() => null))
1057
+
1058
+ await buildSite(projectDir, {
1059
+ prerender,
1060
+ foundationDir: resolvedFoundationDir,
1061
+ siteConfig,
1062
+ host,
1063
+ })
928
1064
  }
929
1065
  } catch (err) {
930
1066
  error(err.message)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-05-06T22:01:04.763Z",
3
+ "generatedAt": "2026-05-06T22:34:24.827Z",
4
4
  "packages": {
5
5
  "@uniweb/build": {
6
6
  "version": "0.14.4",
@@ -92,7 +92,7 @@
92
92
  "deps": []
93
93
  },
94
94
  "@uniweb/unipress": {
95
- "version": "0.4.8",
95
+ "version": "0.4.9",
96
96
  "path": "framework/unipress",
97
97
  "deps": [
98
98
  "@uniweb/build",