@jxsuite/compiler 8.6.0 → 8.7.0
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/dist/cli.js +250 -215
- package/dist/compiler.js +145 -123
- package/package.json +11 -9
- package/src/cli.ts +12 -5
- package/src/shared.ts +249 -1
- package/src/site/bun-plugin.ts +61 -0
- package/src/site/bundler-backend.bun.ts +15 -3
- package/src/site/bundler-backend.node.ts +24 -1
- package/src/site/bundler-backend.ts +21 -4
- package/src/site/bundler.ts +28 -6
- package/src/site/component-set.ts +179 -0
- package/src/site/convert-command.ts +5 -27
- package/src/site/csp.ts +38 -8
- package/src/site/document-scripts.ts +231 -0
- package/src/site/format-command.ts +29 -0
- package/src/site/headers-emitter.ts +1 -1
- package/src/site/layout-resolver.ts +5 -4
- package/src/site/server-command.ts +63 -0
- package/src/site/service-worker.ts +19 -1
- package/src/site/site-build.ts +296 -84
- package/src/site/validate-command.ts +15 -6
- package/src/targets/compile-client.ts +9 -20
- package/src/targets/compile-element.ts +53 -73
- package/src/targets/compile-server.ts +49 -2
|
@@ -39,6 +39,12 @@ export const SERVICE_WORKER_PATH = "sw.js";
|
|
|
39
39
|
*/
|
|
40
40
|
export const CACHE_FIRST_PREFIX = "/images/_optimized/";
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The subtree the site worker answers (compiler.md §6.4): sessions, table rows and server-function
|
|
44
|
+
* results. The emitted worker leaves every request under it alone.
|
|
45
|
+
*/
|
|
46
|
+
export const DYNAMIC_PREFIX = "/_jx";
|
|
47
|
+
|
|
42
48
|
export interface ServiceWorkerOutput {
|
|
43
49
|
/** Path relative to `outDir`, or null when nothing should be emitted. */
|
|
44
50
|
path: string | null;
|
|
@@ -152,6 +158,7 @@ export function buildServiceWorker(
|
|
|
152
158
|
const cachedPrecache = precache.map((url) => withBase(base, url));
|
|
153
159
|
const cacheFirst = withBase(base, CACHE_FIRST_PREFIX);
|
|
154
160
|
const offlineFallback = fallback === undefined ? null : withBase(base, fallback);
|
|
161
|
+
const dynamic = `${withBase(base, DYNAMIC_PREFIX)}/`;
|
|
155
162
|
|
|
156
163
|
const cache = `jx-${configId(config)}`;
|
|
157
164
|
const source = `/*
|
|
@@ -162,6 +169,11 @@ const CACHE = ${JSON.stringify(cache)};
|
|
|
162
169
|
const PRECACHE = ${JSON.stringify(cachedPrecache)};
|
|
163
170
|
const CACHE_FIRST = ${JSON.stringify(cacheFirst)};
|
|
164
171
|
const OFFLINE_FALLBACK = ${JSON.stringify(offlineFallback)};
|
|
172
|
+
const DYNAMIC = ${JSON.stringify(dynamic)};
|
|
173
|
+
|
|
174
|
+
// A response its server marked as one visitor's, or as not to be kept, is never written to a cache.
|
|
175
|
+
const storable = (res) =>
|
|
176
|
+
res.ok && !/\\b(?:no-store|private)\\b/i.test(res.headers.get("Cache-Control") ?? "");
|
|
165
177
|
|
|
166
178
|
self.addEventListener("install", (event) => {
|
|
167
179
|
// Take over as soon as possible: a half-updated pair of workers is harder to reason about than
|
|
@@ -202,6 +214,12 @@ self.addEventListener("fetch", (event) => {
|
|
|
202
214
|
if (request.method !== "GET") return;
|
|
203
215
|
const url = new URL(request.url);
|
|
204
216
|
if (url.origin !== self.location.origin) return;
|
|
217
|
+
/*
|
|
218
|
+
* Sessions and application data. They are answered by the site worker for one visitor at one
|
|
219
|
+
* moment, so a cached copy is somebody's rows served after sign-out, or to the next person on the
|
|
220
|
+
* device. Not handled at all: the request goes to the network exactly as if no worker existed.
|
|
221
|
+
*/
|
|
222
|
+
if (url.pathname.startsWith(DYNAMIC)) return;
|
|
205
223
|
|
|
206
224
|
// Content-addressed output only: the filename embeds a digest, so a hit can never be stale.
|
|
207
225
|
if (url.pathname.startsWith(CACHE_FIRST)) {
|
|
@@ -227,7 +245,7 @@ self.addEventListener("fetch", (event) => {
|
|
|
227
245
|
(async () => {
|
|
228
246
|
try {
|
|
229
247
|
const res = await fetch(request);
|
|
230
|
-
if (res
|
|
248
|
+
if (storable(res)) {
|
|
231
249
|
const copy = res.clone();
|
|
232
250
|
caches.open(CACHE).then((c) => c.put(request, copy));
|
|
233
251
|
}
|