Add build output manifest for static caching#262
Conversation
Coverage Report for CI Build 27524398777Coverage increased (+0.3%) to 92.204%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
31311d7 to
620a4bc
Compare
fb90546 to
e8c79b8
Compare
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
e8c79b8 to
f665681
Compare
a3079c4 to
260af7a
Compare
| Notable examples: | ||
|
|
||
| - [`examples/pwa`](./examples/pwa) - A static PWA with a site service worker, domstack manifest filtering, update prompts, offline fallback, and cache recovery behavior. | ||
|
|
There was a problem hiding this comment.
Dont need this callout here. We can link to it in the manifest docs.
| Alternatively, you could compose your layouts from re-usable template functions and strings. | ||
| If you find your layouts nesting more than one or two levels, perhaps composition would be a better strategy. | ||
|
|
||
| #### Layout composition pitfalls |
There was a problem hiding this comment.
This section should not be deleted.
|
|
||
| Copy folders must live **outside** of the `dest` directory. Copy directories can be in the src directory allowing for nested builds. In this case they are added to the ignore glob and ignored by the rest of `domstack`. | ||
|
|
||
| When using the programmatic `DomStack` constructor, `copy` entries may be relative or absolute paths. Relative `copy` paths are resolved to absolute paths from the current working directory, matching the CLI `--copy` behavior, before they are stored on `domstack.opts.copy` and passed to the copy build step. |
There was a problem hiding this comment.
This note should not be deleted.
| export default templateIterator | ||
| ``` | ||
|
|
||
| ### Choosing a template return type |
There was a problem hiding this comment.
This section should not have been removed.
| **Caveats:** | ||
| ### `domstack-manifest.settings.ts` | ||
|
|
||
| **`page.vars` is a cached, read-only computed getter.** The first access merges all variable sources and DomStack caches a shallow-frozen result. Direct access and destructuring are both fine. Treat the returned object as read-only; if you need derived values, create a new object instead of mutating `page.vars`. |
There was a problem hiding this comment.
The page vars caveats should not have been deleted.
260af7a to
0fe8310
Compare
0fe8310 to
714e90d
Compare
| - Running `domstack` will result in a `build` by default. | ||
| - Running `domstack --watch` or `domstack -w` will build the site and start an auto-reloading development web-server that watches for changes (provided by [`@domstack/sync`][domstack-sync]). | ||
| - Running `domstack --serve` will run a normal one-shot build and then serve the destination directory without watching. This is useful for PWA testing because it writes `domstack-manifest.json`. | ||
| - Running `domstack --target=es2022,chrome120` or `domstack -t es2022,chrome120` forwards the comma-separated target list to esbuild. See [esbuild's target docs](https://esbuild.github.io/api/#target) for accepted values such as `es2020`, `es2022`, `chrome120`, `firefox121`, `safari17`, and `node22`. |
There was a problem hiding this comment.
I thought I removed this in favor of the esbuild settings file. Maybe we should remove this in this upcoming v12 release.
| --drafts Build draft pages with the `.draft.{md,js,ts,html}` page suffix. | ||
| --target, -t comma separated esbuild targets, e.g. es2022,chrome120; see https://esbuild.github.io/api/#target | ||
| --noEsbuildMeta skip writing the esbuild metafile to disk | ||
| --customDomstackManifestName |
There was a problem hiding this comment.
This should go in the settings file as well.
| "domstack": "./bin.js", | ||
| "dom": "./bin.js" | ||
| }, | ||
| "files": [ |
There was a problem hiding this comment.
Need to audit this file array
Summary
This adds an unstable-preview domstack output manifest for static app caching and pairs it with first-class site service-worker support.
Warning
The domstack manifest,
domstack-manifest.settings.*, first-classservice-worker.*entries, and related browserprocess.env.DOMSTACK_*defines are preview APIs. Their names, option shapes, manifest schema, generated output, and runtime semantics may change outside of a major version while the API is validated with real PWA use cases. Consumers should pin@domstack/staticto an exact version before relying on this contract.The goal is to let a domstack app build a fully static client, then have its own service worker consume a normalized, revisioned list of emitted files. Domstack provides the build facts; the application still owns service-worker registration, update UX, route filtering, offline behavior, and cache policy.
What Changed
domstack-manifest.json, written by one-shot builds by default.results.domstackManifestfrom programmatic builds.report.outputsrecords.$schemaURL.@domstack/static/types.js/#typesusingjson-schema-to-ts.domstack-manifest.settings.{js,mjs,cjs,ts,mts,cts}for manifest filtering policy.service-worker.{js,mjs,cjs,ts,mts,cts}anywhere undersrcbuilds to stable root/service-worker.js..npmignorewith apackage.json#filesallowlist.New Preview APIs
Build Results
results.domstackManifestis still returned when writing the JSON file is disabled withdomstackManifest: false. Watch mode does not return a domstack manifest.CLI Options
--customDomstackManifestNamechanges the written manifest filename from the defaultdomstack-manifest.json.--noDomstackManifestdisables writing the JSON file.--serveruns a one-shot build and then serves the output without watch mode, which is useful for testing service-worker cache lifecycle behavior with a manifest-enabled build.Programmatic Options
Supported shape:
domstack-manifest.settings.*Apps can configure the generated manifest from a dedicated settings file anywhere under
src:The default export can be an object, a sync function, or an async function returning an object:
Filtering affects both the written
domstack-manifest.jsonandresults.domstackManifest, and it affectsmanifest.versionbecause versioning is based on final cache-relevant entries.Service Worker Support
Domstack reserves one site service-worker source filename:
The source may live anywhere under
src, but only one is allowed. Multiple matches fail withDOM_STACK_ERROR_DUPLICATE_SERVICE_WORKER.The service worker is bundled through esbuild and emitted with a stable root output path:
Domstack does not inject registration into the default layout. Registration timing, update prompts, local-development opt-outs, poisoned-cache recovery, and offline route behavior remain application policy.
Browser Defines
process.env.DOMSTACK_MANIFEST_URL/domstack-manifest.jsonprocess.env.DOMSTACK_MANIFEST_ENABLED"true"for one-shot builds that write the manifest,"false"when disabled or in watch modeprocess.env.DOMSTACK_SERVICE_WORKER_URL/service-worker.js, or""when absentprocess.env.DOMSTACK_SERVICE_WORKER_SCOPE/, or""when absentCompatibility Notes
copyis now the output kind for files copied by the generic copy step.domstack-manifest.jsonor returnresults.domstackManifest; it does still build and rebundle the site service worker.Testing
npm testnpm run test:tscnpm run test:neostandardnpm run build:declarationnpm run build:schemanode --test lib/identify-pages.test.js test-cases/general-features/index.test.js test-cases/type-exports/index.test.ts test-cases/watch/index.test.js test-cases/template-output-escape/index.test.jsgit diff --check