Skip to content

feat(assets): embed directories with key prefixes and every Vite manifest output - #37

Merged
BYK merged 1 commit into
mainfrom
devin/1789771900-asset-dirs-vite-manifest
Sep 18, 2026
Merged

BYK merged 1 commit into
mainfrom
devin/1789771900-asset-dirs-vite-manifest

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Two gaps that made embedding a Vite-built UI need a hand-written asset map (BYK/loreai#1831 currently stages ~27 files and writes its own manifest for fossilize):

  1. -a only took files, keyed by the literal argument (Add support for asset directories #6).
  2. -m only embedded each chunk's file, so an HTML entry's CSS (css[]), imported static assets (assets[]) and the manifest's real location under dist/.vite/ (Vite ≥ 5) were missed — spotlight only works because it sets build.manifest: "manifest.json".

Asset resolution moves into src/assets.ts (also exported from the library):

// -a <path>[=<key>]
collectAssets(["asset.txt", "dist/ui=ui", "dist/favicon.svg=favicon.svg", "dist="])
// → { "asset.txt": ..., "ui/index.html": ..., "ui/assets/index-abc.js": ..., "favicon.svg": ..., "index.html": ... }
//   directories are walked recursively, keys always use "/" (Windows too),
//   "" key = root of the asset namespace, later specs win on collision

// -m <manifest>: file + css[] + assets[] of every chunk, entry key if it exists as output
collectViteManifestAssets("dist/.vite/manifest.json")
// → { "manifest.json", "index.html", "assets/index-abc.js", "assets/index-def.css", "assets/logo-xyz.svg" }

Behaviour kept: file specs without = keep the literal argument as key (-a asset.txt → getRawAsset("asset.txt")), the manifest is still embedded under its basename, -a still overrides -m. One deliberate change: the isEntry key (e.g. index.html) is only embedded when <outDir>/<key> exists, instead of failing the build for JS entries whose key is a source path (src/main.ts).

Not included from #36: built-in br/gzip precompression (consumers can precompress into the directory they pass to -a) and node:vfs (needs Node ≥ 26.4).

Test plan

  • npm run build (tsc + tsup) clean
  • New CI step on all three OSes: -a assets-dir=data → binary reads data/a.txt + data/nested/b.txt; -m vite-dist/.vite/manifest.json → binary reads index.html, the JS chunk, its CSS and SVG via the embedded manifest.json
  • Existing -a asset.txt smoke unchanged
  • Locally: collectAssets(["./assets-dir", "vite-dist=", "assets-dir/a.txt=x/y.txt", "vite-dist/assets=static/"]) yields the expected normalized keys

Closes #6, refs #36.

Link to Devin session: https://app.devin.ai/sessions/5ac126b5d15542608f3dcaccc477ac32
Open in Devin Desktop: https://app.devin.ai/desktop/session/5ac126b5d15542608f3dcaccc477ac32?variant=devin
Requested by: @BYK

…fest output

- `-a <path>[=<key>]` accepts directories (recursive, POSIX keys under
  `<key>/`) and optional key remapping for files; fixes #6
- `-m` embeds each chunk's `css` and `assets` in addition to `file`,
  resolves paths from the Vite outDir (parent of `.vite/`), and only
  embeds the entry key when it exists as a build output
- export `collectAssets`/`collectViteManifestAssets` from the library
- CI smoke for both paths on all three platforms

Closes #36

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@BYK
BYK merged commit 4964fca into main Sep 18, 2026
5 checks passed
@BYK
BYK deleted the devin/1789771900-asset-dirs-vite-manifest branch September 18, 2026 22:59
@craft-deployer craft-deployer Bot mentioned this pull request Sep 19, 2026
2 tasks
devin-ai-integration Bot added a commit to BYK/loreai that referenced this pull request Sep 19, 2026
Released with BYK/fossilize#37 (directory assets with key prefixes).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
BYK added a commit to BYK/loreai that referenced this pull request Sep 19, 2026
## Summary

Follow-up to #1831, stacked on its branch (retarget to `main` once #1831
lands). Pins `fossilize` to `0.11.0` (the release with BYK/fossilize#37)
and uses its directory-asset embedding for the UI.

`build-binary-sea.ts` stops enumerating the UI files for fossilize. The
staged tree is copied to `<staging>/ui` and passed as one directory
asset with a key prefix:

```ts
// per target
await fossilize({
  assetManifest: manifestPath,            // workers, model, vec0, ORT (unchanged)
  assets: [`${join(stagingDir, "ui")}=ui/`], // → SEA keys ui/<relative path>
  ...
}, bundlePath);
```

so `ui/index.html`, `ui/assets/index-*.js.br`, `ui/ui-manifest.json`, …
are embedded exactly as before and `src/ui-static.ts`'s
`getRawAsset("ui/<path>")` is untouched. The `sharedManifest` UI loop
and `UiAssetsResult.staged` (its only consumer) are removed;
`--from-staging` stays self-contained since the copy lives inside the
staging dir. The `.br`/`.gz` variants are still produced by
`script/ui-assets.ts` and ride along in the directory — fossilize 0.11.0
does not precompress.

Lockfile change is limited to the fossilize entry (same transitive deps
as 0.10.1); `pnpm install --frozen-lockfile` accepts it. No effect on
`dist/index.cjs` (17,478,460 B, unchanged from #1831) — only the SEA
binary build path changes.

Verified against the released `fossilize@0.11.0`: `build:binary:sea
--platforms linux-x64` logs `Embedding 40 assets` (12 manifest + 27
`ui/` + `manifest.json`), `node scripts/ui-deep-link-smoke.mjs --
<binary>` passes from outside the repo, main JS served
`content-encoding: br` (78,658 B) decodes to the 294,264 B identity
file, `/ui/favicon.svg` (public asset) 200. `pnpm run typecheck` /
`lint` / `format:check` clean.

Part of #1797.


Link to Devin session:
https://app.devin.ai/sessions/5ac126b5d15542608f3dcaccc477ac32
Open in Devin Desktop:
https://app.devin.ai/desktop/session/5ac126b5d15542608f3dcaccc477ac32?variant=devin
Requested by: @BYK

---------

Co-authored-by: Burak Yigit Kaya <madbyk@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for asset directories

1 participant