@qwik.dev/core 2.0.0-alpha.1 → 2.0.0-alpha.10
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/bindings/qwik.darwin-arm64.node +0 -0
- package/bindings/qwik.darwin-x64.node +0 -0
- package/bindings/qwik.linux-x64-gnu.node +0 -0
- package/bindings/qwik.wasm.cjs +259 -272
- package/bindings/qwik.wasm.mjs +259 -272
- package/bindings/qwik.win32-x64-msvc.node +0 -0
- package/bindings/qwik_wasm_bg.wasm +0 -0
- package/dist/build/index.cjs +3 -3
- package/dist/build/index.d.ts +22 -22
- package/dist/build/package.json +1 -1
- package/dist/cli.cjs +1453 -798
- package/dist/core-internal.d.ts +4368 -3895
- package/dist/core.cjs +6786 -6121
- package/dist/core.cjs.map +1 -1
- package/dist/core.min.mjs +1 -1
- package/dist/core.mjs +6759 -6117
- package/dist/core.mjs.map +1 -1
- package/dist/core.prod.cjs +3568 -3206
- package/dist/core.prod.mjs +3916 -3586
- package/dist/insights/index.qwik.cjs +1 -751
- package/dist/insights/index.qwik.mjs +62 -741
- package/dist/insights/vite/index.cjs +1 -82
- package/dist/insights/vite/index.mjs +65 -37
- package/dist/insights/vite.d.ts +22 -0
- package/dist/{insights/insights.d.ts → insights.d.ts} +33 -22
- package/dist/loader/index.cjs +2 -2
- package/dist/loader/index.mjs +2 -2
- package/dist/loader/package.json +1 -1
- package/dist/optimizer.cjs +703 -5856
- package/dist/optimizer.d.ts +741 -707
- package/dist/optimizer.mjs +690 -6282
- package/dist/preloader.cjs +243 -0
- package/dist/preloader.mjs +183 -0
- package/dist/qwikloader.debug.js +211 -220
- package/dist/qwikloader.js +1 -3
- package/dist/server.cjs +1371 -7279
- package/dist/server.d.ts +467 -402
- package/dist/server.mjs +1339 -7230
- package/dist/starters/adapters/aws-lambda/serverless.yml +15 -0
- package/dist/starters/adapters/aws-lambda/src/entry_aws-lambda.tsx +0 -2
- package/dist/starters/adapters/azure-swa/public/staticwebapp.config.json +7 -0
- package/dist/starters/adapters/azure-swa/src/entry.azure-swa.tsx +1 -2
- package/dist/starters/adapters/bun/src/entry.bun.ts +3 -2
- package/dist/starters/adapters/cloud-run/src/entry.cloud-run.tsx +1 -3
- package/dist/starters/adapters/cloudflare-pages/public/_headers +2 -0
- package/dist/starters/adapters/cloudflare-pages/src/entry.cloudflare-pages.tsx +1 -2
- package/dist/starters/adapters/deno/src/entry.deno.ts +3 -2
- package/dist/starters/adapters/express/src/entry.express.tsx +5 -2
- package/dist/starters/adapters/fastify/src/entry.fastify.tsx +2 -1
- package/dist/starters/adapters/fastify/src/plugins/fastify-qwik.ts +11 -1
- package/dist/starters/adapters/firebase/firebase.json +12 -1
- package/dist/starters/adapters/firebase/functions/index.js +2 -3
- package/dist/starters/adapters/firebase/src/entry-firebase.tsx +1 -2
- package/dist/starters/adapters/netlify-edge/public/_headers +2 -0
- package/dist/starters/adapters/netlify-edge/src/entry.netlify-edge.tsx +1 -2
- package/dist/starters/adapters/node-server/src/entry.node-server.tsx +3 -2
- package/dist/starters/adapters/static/README.md +4 -0
- package/dist/starters/adapters/vercel-edge/src/entry.vercel-edge.tsx +1 -2
- package/dist/starters/adapters/vercel-edge/vercel.json +1 -1
- package/dist/starters/features/auth/package.json +3 -1
- package/dist/starters/features/bootstrap/src/routes/bootstrap/layout.tsx +0 -11
- package/dist/starters/features/cypress/package.json +1 -1
- package/dist/starters/features/drizzle/drizzle/schema.ts +6 -18
- package/dist/starters/features/drizzle/drizzle.config.ts +5 -4
- package/dist/starters/features/drizzle/package.json +16 -12
- package/dist/starters/features/localize/src/entry.ssr.tsx +0 -2
- package/dist/starters/features/localize/src/routes/[locale]/i18n-utils.ts +1 -1
- package/dist/starters/features/pandacss/package.json +1 -1
- package/dist/starters/features/partytown/package.json +1 -1
- package/dist/starters/features/postcss/package.json +4 -1
- package/dist/starters/features/postcss/postcss.config.js +1 -1
- package/dist/starters/features/prisma/package.json +3 -2
- package/dist/starters/features/react/package.json +1 -1
- package/dist/starters/features/service-worker/package.json +13 -0
- package/dist/starters/features/service-worker/src/routes/service-worker.ts +14 -0
- package/dist/starters/features/storybook/package.json +1 -1
- package/dist/starters/features/styled-vanilla-extract/package.json +4 -2
- package/dist/starters/features/tailwind/package.json +19 -9
- package/dist/starters/features/tailwind/src/global.css +1 -7
- package/dist/starters/features/tailwind-v3/package.json +21 -0
- package/dist/starters/features/{tailwind → tailwind-v3}/postcss.config.cjs +1 -1
- package/dist/starters/features/tailwind-v3/src/global.css +7 -0
- package/dist/starters/features/{tailwind → tailwind-v3}/tailwind.config.js +1 -1
- package/dist/starters/features/turso/package.json +5 -2
- package/dist/starters/features/turso/src/utils/turso.ts +1 -1
- package/dist/starters/features/vitest/package.json +1 -1
- package/dist/testing/index.cjs +7562 -6858
- package/dist/testing/index.d.ts +141 -140
- package/dist/testing/index.mjs +7495 -6790
- package/dist/testing/package.json +1 -1
- package/handlers.mjs +9 -0
- package/package.json +25 -13
- package/public.d.ts +13 -0
- package/server.d.ts +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/insights/index.d.ts +0 -1
- package/dist/insights/vite/index.d.ts +0 -1
- package/dist/insights/vite/insights-plugin.d.ts +0 -10
- package/dist/prefetch/index.cjs +0 -4
- package/dist/prefetch/index.d.ts +0 -2
- package/dist/prefetch/index.mjs +0 -3
- package/dist/prefetch/package.json +0 -8
- package/dist/qwik-prefetch.debug.js +0 -244
- package/dist/qwik-prefetch.js +0 -1
- /package/dist/starters/features/{tailwind → tailwind-v3}/.vscode/settings.json +0 -0
package/handlers.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This re-exports the QRL handlers so that they can be used as QRLs.
|
|
3
|
+
*
|
|
4
|
+
* In vite dev mode, this file is referenced directly. This ensures that the correct path to core is
|
|
5
|
+
* used so that there's only one instance of Qwik.
|
|
6
|
+
*
|
|
7
|
+
* Make sure that these handlers are listed in manifest.ts
|
|
8
|
+
*/
|
|
9
|
+
export { _run, _task } from '@qwik.dev/core';
|
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/core",
|
|
3
3
|
"description": "An open source framework for building instant loading web apps at any scale, without the extra effort.",
|
|
4
|
-
"version": "2.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.10",
|
|
5
5
|
"author": "Qwik Team",
|
|
6
6
|
"bin": {
|
|
7
7
|
"qwik": "./qwik-cli.cjs"
|
|
8
8
|
},
|
|
9
9
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"csstype": "^3.1"
|
|
11
|
+
"csstype": "^3.1",
|
|
12
|
+
"rollup": ">= 4.39.0"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
15
|
+
"ignore": "5.3.1",
|
|
14
16
|
"image-size": "1.1.1",
|
|
15
17
|
"kleur": "4.1.5",
|
|
16
|
-
"prettier": "3.
|
|
17
|
-
"
|
|
18
|
-
"
|
|
18
|
+
"prettier": "3.4.2",
|
|
19
|
+
"ts-morph": "23.0.0",
|
|
20
|
+
"vitest": "3.1.1",
|
|
21
|
+
"@qwik.dev/core": "2.0.0-alpha.10",
|
|
19
22
|
"@qwik.dev/dom": "2.1.19"
|
|
20
23
|
},
|
|
21
24
|
"engines": {
|
|
@@ -39,8 +42,9 @@
|
|
|
39
42
|
"./cli": {
|
|
40
43
|
"require": "./dist/cli.cjs"
|
|
41
44
|
},
|
|
45
|
+
"./handlers.mjs": "./handlers.mjs",
|
|
42
46
|
"./internal": {
|
|
43
|
-
"types": "./core-internal.d.ts",
|
|
47
|
+
"types": "./dist/core-internal.d.ts",
|
|
44
48
|
"import": {
|
|
45
49
|
"development": "./dist/core.mjs",
|
|
46
50
|
"production": "./dist/core.prod.mjs",
|
|
@@ -116,6 +120,10 @@
|
|
|
116
120
|
"import": "./dist/optimizer.mjs",
|
|
117
121
|
"require": "./dist/optimizer.cjs"
|
|
118
122
|
},
|
|
123
|
+
"./preloader": {
|
|
124
|
+
"import": "./dist/preloader.mjs",
|
|
125
|
+
"require": "./dist/preloader.cjs"
|
|
126
|
+
},
|
|
119
127
|
"./server.cjs": "./dist/server.cjs",
|
|
120
128
|
"./server.mjs": "./dist/server.mjs",
|
|
121
129
|
"./server": {
|
|
@@ -130,9 +138,7 @@
|
|
|
130
138
|
},
|
|
131
139
|
"./qwikloader.js": "./dist/qwikloader.js",
|
|
132
140
|
"./qwikloader.debug.js": "./dist/qwikloader.debug.js",
|
|
133
|
-
"./
|
|
134
|
-
"./qwik-prefetch.debug.js": "./dist/qwik-prefetch.debug.js",
|
|
135
|
-
"./package.json": "./dist/package.json"
|
|
141
|
+
"./package.json": "./package.json"
|
|
136
142
|
},
|
|
137
143
|
"exports_annotation": "We use the build for the optimizer because esbuild doesn't like the html?raw imports in the server plugin and it's only used in the vite configs",
|
|
138
144
|
"files": [
|
|
@@ -142,6 +148,7 @@
|
|
|
142
148
|
"bindings",
|
|
143
149
|
"build.d.ts",
|
|
144
150
|
"cli.d.ts",
|
|
151
|
+
"handlers.mjs",
|
|
145
152
|
"jsx-dev-runtime.d.ts",
|
|
146
153
|
"jsx-runtime.d.ts",
|
|
147
154
|
"loader.d.ts",
|
|
@@ -153,10 +160,15 @@
|
|
|
153
160
|
],
|
|
154
161
|
"homepage": "https://qwik.dev/",
|
|
155
162
|
"keywords": [
|
|
156
|
-
"
|
|
163
|
+
"Automatic Optimization",
|
|
157
164
|
"framework",
|
|
158
165
|
"generator",
|
|
166
|
+
"javascript streaming",
|
|
167
|
+
"lazy execution",
|
|
168
|
+
"performance",
|
|
159
169
|
"prerender",
|
|
170
|
+
"resumability",
|
|
171
|
+
"resumable",
|
|
160
172
|
"server-side-render",
|
|
161
173
|
"ssg",
|
|
162
174
|
"ssr",
|
|
@@ -169,8 +181,8 @@
|
|
|
169
181
|
"main": "./src/index.ts",
|
|
170
182
|
"peerDependencies": {
|
|
171
183
|
"prettier": "*",
|
|
172
|
-
"vite": "
|
|
173
|
-
"vitest": "
|
|
184
|
+
"vite": ">=5 <7",
|
|
185
|
+
"vitest": ">=2 <3"
|
|
174
186
|
},
|
|
175
187
|
"peerDependenciesMeta": {
|
|
176
188
|
"vitest": {
|
|
@@ -189,7 +201,7 @@
|
|
|
189
201
|
"directory": "packages/qwik"
|
|
190
202
|
},
|
|
191
203
|
"type": "module",
|
|
192
|
-
"types": "./
|
|
204
|
+
"types": "./public.d.ts",
|
|
193
205
|
"scripts": {
|
|
194
206
|
"build.insights": "cd src/insights && vite build --mode lib --emptyOutDir"
|
|
195
207
|
}
|
package/public.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export {
|
|
|
6
6
|
ComputedSignal,
|
|
7
7
|
ContextId,
|
|
8
8
|
createComputed$,
|
|
9
|
+
createSerializer$,
|
|
9
10
|
createContextId,
|
|
10
11
|
createSignal,
|
|
11
12
|
CSSProperties,
|
|
@@ -17,6 +18,9 @@ export {
|
|
|
17
18
|
getLocale,
|
|
18
19
|
getPlatform,
|
|
19
20
|
implicit$FirstArg,
|
|
21
|
+
isBrowser,
|
|
22
|
+
isDev,
|
|
23
|
+
isServer,
|
|
20
24
|
isSignal,
|
|
21
25
|
jsx,
|
|
22
26
|
JSXChildren,
|
|
@@ -25,6 +29,9 @@ export {
|
|
|
25
29
|
JSXOutput,
|
|
26
30
|
noSerialize,
|
|
27
31
|
NoSerialize,
|
|
32
|
+
NoSerializeSymbol,
|
|
33
|
+
SerializerSymbol,
|
|
34
|
+
OnVisibleTaskOptions,
|
|
28
35
|
PrefetchGraph,
|
|
29
36
|
PrefetchServiceWorker,
|
|
30
37
|
PropsOf,
|
|
@@ -32,6 +39,8 @@ export {
|
|
|
32
39
|
// TODO should this be used instead of EventHandler?
|
|
33
40
|
QRLEventHandlerMulti,
|
|
34
41
|
QwikIntrinsicElements,
|
|
42
|
+
QwikHTMLElements,
|
|
43
|
+
QwikSVGElements,
|
|
35
44
|
QwikJSX as JSX,
|
|
36
45
|
QwikJSX,
|
|
37
46
|
ReadonlySignal,
|
|
@@ -57,6 +66,7 @@ export {
|
|
|
57
66
|
useOnDocument,
|
|
58
67
|
useOnWindow,
|
|
59
68
|
useResource$,
|
|
69
|
+
useSerializer$,
|
|
60
70
|
useServerData,
|
|
61
71
|
useSignal,
|
|
62
72
|
useStore,
|
|
@@ -67,4 +77,7 @@ export {
|
|
|
67
77
|
ValueOrPromise,
|
|
68
78
|
version,
|
|
69
79
|
withLocale,
|
|
80
|
+
SVGAttributes,
|
|
81
|
+
HTMLElementAttrs,
|
|
82
|
+
SVGProps,
|
|
70
83
|
} from './dist/core-internal';
|
package/server.d.ts
CHANGED
package/dist/index.d.ts
DELETED
package/dist/insights/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './insights';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './insights-plugin';
|
package/dist/prefetch/index.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const QWIK_PREFETCH = "(()=>{const t=Number.MAX_SAFE_INTEGER>>>1;function n(n,i){const[o,s]=c(i),a=n.t.find((t=>o===t.i));if(a)return n.o(\"intercepting\",i.pathname),e(n,a,[s],t).then((()=>function(t,n){const e=t.u.find((t=>t.l.pathname===n.pathname));return e?e.$.then((t=>t.clone())):(t.o(\"CACHE HIT\",n.pathname),t.h(n))}(n,i)))}async function e(n,e,o,c){const a=new Map;o.forEach((t=>s(e,a,t,c))),await Promise.all(Array.from(a.entries()).map((([i,o])=>async function(n,e,i){let o=n.u.find((t=>t.l.pathname===e.pathname));const s=i>=t?\"direct\":\"prefetch\";if(o){const t=o.p?\"fetching\":\"waiting\";o.m<i?(n.o(\"queue update priority\",t,e.pathname),o.m=i):n.o(\"already in queue\",s,t,e.pathname)}else await n.h(e)||(n.o(\"enqueue\",s,e.pathname),o={m:i,l:e,v:null,$:null,p:!1},o.$=new Promise((t=>o.v=t)),n.u.push(o));return o}(n,new URL(e.i+i,n.l.origin),o)))),i(n)}function i(n){n.u.sort(o);let e=0;for(const o of n.u)if(o.p)e++;else if(n.C()&&(e<n.T||o.m>=t)){o.p=!0,e++;const s=o.m>=t?\"FETCH (CACHE MISS)\":\"FETCH\";n.o(s,o.l.pathname),n.H(o.l).then((async t=>{o.v(t),200===t.status&&(n.o(\"CACHED\",o.l.pathname),await n.R(o.l,t.clone()))})).finally((()=>{n.o(\"FETCH DONE\",o.l.pathname),n.u.splice(n.u.indexOf(o),1),i(n)}))}}function o(t,n){return n.m-t.m}function s(t,n,e,i,o=!0){if(!n.has(e)){if(n.set(e,i),!t.U){let n,e;t.U=new Map;for(let i=0;i<t.L.length;i++){const o=t.L[i];if(\"string\"==typeof o)n={S:[],A:[]},e=!0,t.U.set(o,n);else if(-1===o)e=!1;else{const i=t.L[o];e?n.S.push(i):n.A.push(i)}}}const c=t.U.get(e);if(!c)return n;for(const e of c.S)s(t,n,e,i);if(o){i--;for(const e of c.A)s(t,n,e,i,!1)}}return n}function c(t){const n=new URL(t).pathname,e=n.lastIndexOf(\"/\");return[n.substring(0,e+1),n.substring(e+1)]}const a=(...t)=>{console.log(\"⚙️ Prefetch SW:\",...t)};async function r(t,n,e,i){const o=t.t.findIndex((t=>t.i===n));if(-1!==o&&t.t.splice(o,1),t.o(\"adding base:\",n),t.t.push({i:n,L:e,U:void 0}),i){const i=new Set(e.filter((t=>\"string\"==typeof t))),o=await t.C();if(o)for(const e of await o.keys()){const[s,a]=c(new URL(e.url)),r=[];s!==n||i.has(a)||(t.o(\"deleting\",e.url),r.push(o.delete(e))),await Promise.all(r)}}}function u(t,n,i){let o=t.t.find((t=>t.L.includes(i[0].replace(\"./\",\"\"))));o||(o=t.t.find((t=>n===t.i))),o?e(t,o,i,0):console.error(`Base path not found: ${n}, ignoring prefetch.`)}function f(t){if(!t.N&&t.B.length){const e=t.B.shift();t.N=(async(t,e)=>{const i=e[0];t.o(\"received message:\",i,e[1],e.slice(2)),\"graph\"===i?await r(t,e[1],e.slice(2),!0):\"graph-url\"===i?await async function(t,e,i){await r(t,e,[],!1);const o=await n(t,new URL(e+i,t.l.origin));if(o&&200===o.status){const n=await o.json();n.push(i),await r(t,e,n,!0)}}(t,e[1],e[2]):\"prefetch\"===i?await u(t,e[1],e.slice(2)):\"prefetch-all\"===i?await function(t,n){const e=t.t.find((t=>n===t.i));e?u(t,n,e.L.filter((t=>\"string\"==typeof t))):console.error(`Base path not found: ${n}, ignoring prefetch.`)}(t,e[1]):\"ping\"===i?a(\"ping\"):\"verbose\"===i?(t.o=a)(\"mode: verbose\"):console.error(\"UNKNOWN MESSAGE:\",e)})(t,e).then((()=>{t.N=null,f(t)}))}}class l{constructor(t,n,e=4,i=null,o=null,s=[],c=[],a=[]){this.H=t,this.l=n,this.T=e,this.F=i,this.N=o,this.u=s,this.t=c,this.B=a}C(){return this.F}async R(t,n){const e=await this.C();return null==e?void 0:e.put(t,n)}async h(t){const n=await this.C();return null==n?void 0:n.match(t)}o(){}}(t=>{const e=(i=t.fetch.bind(t),o=new URL(t.location.href),new l(i,o));var i,o;e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open(\"QwikBundles\")),t.addEventListener(\"fetch\",(t=>{const i=t.request;if(\"GET\"===i.method){const o=n(e,new URL(i.url));o&&t.respondWith(o)}})),t.addEventListener(\"message\",(t=>{e.B.push(t.data),f(e)})),t.addEventListener(\"install\",(()=>{t.skipWaiting()})),t.addEventListener(\"activate\",(n=>{e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open(\"QwikBundles\")),n.waitUntil(t.clients.claim())}))})(globalThis)})();";
|
|
2
|
-
const QWIK_PREFETCH_DEBUG = "(() => {\n const DIRECT_PRIORITY = Number.MAX_SAFE_INTEGER >>> 1;\n function directFetch(swState, url) {\n const [basePath, filename] = parseBaseFilename(url);\n const base = swState.$bases$.find((base2 => basePath === base2.$path$));\n if (base) {\n swState.$log$(\"intercepting\", url.pathname);\n return enqueueFileAndDependencies(swState, base, [ filename ], DIRECT_PRIORITY).then((() => function(swState, url) {\n const currentRequestTask = swState.$queue$.find((task => task.$url$.pathname === url.pathname));\n if (currentRequestTask) {\n return currentRequestTask.$response$.then((response => response.clone()));\n }\n swState.$log$(\"CACHE HIT\", url.pathname);\n return swState.$match$(url);\n }(swState, url)));\n }\n }\n async function enqueueFileAndDependencies(swState, base, filenames, priority) {\n const fetchMap = new Map;\n filenames.forEach((filename => addDependencies(base, fetchMap, filename, priority)));\n await Promise.all(Array.from(fetchMap.entries()).map((([filename, prio]) => async function(swState, url, priority) {\n let task = swState.$queue$.find((task2 => task2.$url$.pathname === url.pathname));\n const mode = priority >= DIRECT_PRIORITY ? \"direct\" : \"prefetch\";\n if (task) {\n const state = task.$isFetching$ ? \"fetching\" : \"waiting\";\n if (task.$priority$ < priority) {\n swState.$log$(\"queue update priority\", state, url.pathname);\n task.$priority$ = priority;\n } else {\n swState.$log$(\"already in queue\", mode, state, url.pathname);\n }\n } else {\n if (!await swState.$match$(url)) {\n swState.$log$(\"enqueue\", mode, url.pathname);\n task = {\n $priority$: priority,\n $url$: url,\n $resolveResponse$: null,\n $response$: null,\n $isFetching$: !1\n };\n task.$response$ = new Promise((resolve => task.$resolveResponse$ = resolve));\n swState.$queue$.push(task);\n }\n }\n return task;\n }(swState, new URL(base.$path$ + filename, swState.$url$.origin), prio))));\n taskTick(swState);\n }\n function taskTick(swState) {\n swState.$queue$.sort(byFetchOrder);\n let outstandingRequests = 0;\n for (const task of swState.$queue$) {\n if (task.$isFetching$) {\n outstandingRequests++;\n } else if (swState.$getCache$() && (outstandingRequests < swState.$maxPrefetchRequests$ || task.$priority$ >= DIRECT_PRIORITY)) {\n task.$isFetching$ = !0;\n outstandingRequests++;\n const action = task.$priority$ >= DIRECT_PRIORITY ? \"FETCH (CACHE MISS)\" : \"FETCH\";\n swState.$log$(action, task.$url$.pathname);\n swState.$fetch$(task.$url$).then((async response => {\n task.$resolveResponse$(response);\n if (200 === response.status) {\n swState.$log$(\"CACHED\", task.$url$.pathname);\n await swState.$put$(task.$url$, response.clone());\n }\n })).finally((() => {\n swState.$log$(\"FETCH DONE\", task.$url$.pathname);\n swState.$queue$.splice(swState.$queue$.indexOf(task), 1);\n taskTick(swState);\n }));\n }\n }\n }\n function byFetchOrder(a, b) {\n return b.$priority$ - a.$priority$;\n }\n function addDependencies(base, fetchMap, filename, priority, addIndirect = !0) {\n if (!fetchMap.has(filename)) {\n fetchMap.set(filename, priority);\n if (!base.$processed$) {\n base.$processed$ = new Map;\n let current, isDirect;\n for (let i = 0; i < base.$graph$.length; i++) {\n const item = base.$graph$[i];\n if (\"string\" == typeof item) {\n current = {\n $direct$: [],\n $indirect$: []\n };\n isDirect = !0;\n base.$processed$.set(item, current);\n } else if (-1 === item) {\n isDirect = !1;\n } else {\n const depName = base.$graph$[item];\n isDirect ? current.$direct$.push(depName) : current.$indirect$.push(depName);\n }\n }\n }\n const deps = base.$processed$.get(filename);\n if (!deps) {\n return fetchMap;\n }\n for (const dependentFilename of deps.$direct$) {\n addDependencies(base, fetchMap, dependentFilename, priority);\n }\n if (addIndirect) {\n priority--;\n for (const dependentFilename of deps.$indirect$) {\n addDependencies(base, fetchMap, dependentFilename, priority, !1);\n }\n }\n }\n return fetchMap;\n }\n function parseBaseFilename(url) {\n const pathname = new URL(url).pathname;\n const slashIndex = pathname.lastIndexOf(\"/\");\n return [ pathname.substring(0, slashIndex + 1), pathname.substring(slashIndex + 1) ];\n }\n const log = (...args) => {\n console.log(\"⚙️ Prefetch SW:\", ...args);\n };\n const processMessage = async (state, msg) => {\n const type = msg[0];\n state.$log$(\"received message:\", type, msg[1], msg.slice(2));\n \"graph\" === type ? await processBundleGraph(state, msg[1], msg.slice(2), !0) : \"graph-url\" === type ? await async function(swState, base, graphPath) {\n await processBundleGraph(swState, base, [], !1);\n const response = await directFetch(swState, new URL(base + graphPath, swState.$url$.origin));\n if (response && 200 === response.status) {\n const graph = await response.json();\n graph.push(graphPath);\n await processBundleGraph(swState, base, graph, !0);\n }\n }(state, msg[1], msg[2]) : \"prefetch\" === type ? await processPrefetch(state, msg[1], msg.slice(2)) : \"prefetch-all\" === type ? await function(swState, basePath) {\n const base = swState.$bases$.find((base2 => basePath === base2.$path$));\n base ? processPrefetch(swState, basePath, base.$graph$.filter((item => \"string\" == typeof item))) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);\n }(state, msg[1]) : \"ping\" === type ? log(\"ping\") : \"verbose\" === type ? (state.$log$ = log)(\"mode: verbose\") : console.error(\"UNKNOWN MESSAGE:\", msg);\n };\n async function processBundleGraph(swState, base, graph, cleanup) {\n const existingBaseIndex = swState.$bases$.findIndex((b => b.$path$ === base));\n -1 !== existingBaseIndex && swState.$bases$.splice(existingBaseIndex, 1);\n swState.$log$(\"adding base:\", base);\n swState.$bases$.push({\n $path$: base,\n $graph$: graph,\n $processed$: void 0\n });\n if (cleanup) {\n const bundles = new Set(graph.filter((item => \"string\" == typeof item)));\n const cache = await swState.$getCache$();\n if (cache) {\n for (const request of await cache.keys()) {\n const [cacheBase, filename] = parseBaseFilename(new URL(request.url));\n const promises = [];\n if (cacheBase === base && !bundles.has(filename)) {\n swState.$log$(\"deleting\", request.url);\n promises.push(cache.delete(request));\n }\n await Promise.all(promises);\n }\n }\n }\n }\n function processPrefetch(swState, basePath, bundles) {\n let base = swState.$bases$.find((base2 => base2.$graph$.includes(bundles[0].replace(\"./\", \"\"))));\n base || (base = swState.$bases$.find((base2 => basePath === base2.$path$)));\n base ? enqueueFileAndDependencies(swState, base, bundles, 0) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);\n }\n function drainMsgQueue(swState) {\n if (!swState.$msgQueuePromise$ && swState.$msgQueue$.length) {\n const top = swState.$msgQueue$.shift();\n swState.$msgQueuePromise$ = processMessage(swState, top).then((() => {\n swState.$msgQueuePromise$ = null;\n drainMsgQueue(swState);\n }));\n }\n }\n class SWStateImpl {\n constructor($fetch$, $url$, $maxPrefetchRequests$ = 4, $cache$ = null, $msgQueuePromise$ = null, $queue$ = [], $bases$ = [], $msgQueue$ = []) {\n this.$fetch$ = $fetch$;\n this.$url$ = $url$;\n this.$maxPrefetchRequests$ = $maxPrefetchRequests$;\n this.$cache$ = $cache$;\n this.$msgQueuePromise$ = $msgQueuePromise$;\n this.$queue$ = $queue$;\n this.$bases$ = $bases$;\n this.$msgQueue$ = $msgQueue$;\n }\n $getCache$() {\n return this.$cache$;\n }\n async $put$(request, response) {\n const cache = await this.$getCache$();\n return null == cache ? void 0 : cache.put(request, response);\n }\n async $match$(request) {\n const cache = await this.$getCache$();\n return null == cache ? void 0 : cache.match(request);\n }\n $log$() {}\n }\n (swScope => {\n const swState = ((fetch, url) => new SWStateImpl(fetch, url))(swScope.fetch.bind(swScope), new URL(swScope.location.href));\n swState.$getCache$ = () => {\n if (swState.$cache$) {\n return swState.$cache$;\n }\n clearTimeout(undefined);\n setTimeout((() => {\n swState.$cache$ = null;\n }), 5e3);\n return swScope.caches.open(\"QwikBundles\");\n };\n swScope.addEventListener(\"fetch\", (ev => {\n const request = ev.request;\n if (\"GET\" === request.method) {\n const response = directFetch(swState, new URL(request.url));\n response && ev.respondWith(response);\n }\n }));\n swScope.addEventListener(\"message\", (ev => {\n swState.$msgQueue$.push(ev.data);\n drainMsgQueue(swState);\n }));\n swScope.addEventListener(\"install\", (() => {\n swScope.skipWaiting();\n }));\n swScope.addEventListener(\"activate\", (event => {\n swState.$getCache$ = () => {\n if (swState.$cache$) {\n return swState.$cache$;\n }\n clearTimeout(undefined);\n setTimeout((() => {\n swState.$cache$ = null;\n }), 5e3);\n return swScope.caches.open(\"QwikBundles\");\n };\n event.waitUntil(swScope.clients.claim());\n }));\n })(globalThis);\n})();";
|
|
3
|
-
exports.QWIK_PREFETCH = QWIK_PREFETCH;
|
|
4
|
-
exports.QWIK_PREFETCH_DEBUG = QWIK_PREFETCH_DEBUG;
|
package/dist/prefetch/index.d.ts
DELETED
package/dist/prefetch/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
const QWIK_PREFETCH = "(()=>{const t=Number.MAX_SAFE_INTEGER>>>1;function n(n,i){const[o,s]=c(i),a=n.t.find((t=>o===t.i));if(a)return n.o(\"intercepting\",i.pathname),e(n,a,[s],t).then((()=>function(t,n){const e=t.u.find((t=>t.l.pathname===n.pathname));return e?e.$.then((t=>t.clone())):(t.o(\"CACHE HIT\",n.pathname),t.h(n))}(n,i)))}async function e(n,e,o,c){const a=new Map;o.forEach((t=>s(e,a,t,c))),await Promise.all(Array.from(a.entries()).map((([i,o])=>async function(n,e,i){let o=n.u.find((t=>t.l.pathname===e.pathname));const s=i>=t?\"direct\":\"prefetch\";if(o){const t=o.p?\"fetching\":\"waiting\";o.m<i?(n.o(\"queue update priority\",t,e.pathname),o.m=i):n.o(\"already in queue\",s,t,e.pathname)}else await n.h(e)||(n.o(\"enqueue\",s,e.pathname),o={m:i,l:e,v:null,$:null,p:!1},o.$=new Promise((t=>o.v=t)),n.u.push(o));return o}(n,new URL(e.i+i,n.l.origin),o)))),i(n)}function i(n){n.u.sort(o);let e=0;for(const o of n.u)if(o.p)e++;else if(n.C()&&(e<n.T||o.m>=t)){o.p=!0,e++;const s=o.m>=t?\"FETCH (CACHE MISS)\":\"FETCH\";n.o(s,o.l.pathname),n.H(o.l).then((async t=>{o.v(t),200===t.status&&(n.o(\"CACHED\",o.l.pathname),await n.R(o.l,t.clone()))})).finally((()=>{n.o(\"FETCH DONE\",o.l.pathname),n.u.splice(n.u.indexOf(o),1),i(n)}))}}function o(t,n){return n.m-t.m}function s(t,n,e,i,o=!0){if(!n.has(e)){if(n.set(e,i),!t.U){let n,e;t.U=new Map;for(let i=0;i<t.L.length;i++){const o=t.L[i];if(\"string\"==typeof o)n={S:[],A:[]},e=!0,t.U.set(o,n);else if(-1===o)e=!1;else{const i=t.L[o];e?n.S.push(i):n.A.push(i)}}}const c=t.U.get(e);if(!c)return n;for(const e of c.S)s(t,n,e,i);if(o){i--;for(const e of c.A)s(t,n,e,i,!1)}}return n}function c(t){const n=new URL(t).pathname,e=n.lastIndexOf(\"/\");return[n.substring(0,e+1),n.substring(e+1)]}const a=(...t)=>{console.log(\"⚙️ Prefetch SW:\",...t)};async function r(t,n,e,i){const o=t.t.findIndex((t=>t.i===n));if(-1!==o&&t.t.splice(o,1),t.o(\"adding base:\",n),t.t.push({i:n,L:e,U:void 0}),i){const i=new Set(e.filter((t=>\"string\"==typeof t))),o=await t.C();if(o)for(const e of await o.keys()){const[s,a]=c(new URL(e.url)),r=[];s!==n||i.has(a)||(t.o(\"deleting\",e.url),r.push(o.delete(e))),await Promise.all(r)}}}function u(t,n,i){let o=t.t.find((t=>t.L.includes(i[0].replace(\"./\",\"\"))));o||(o=t.t.find((t=>n===t.i))),o?e(t,o,i,0):console.error(`Base path not found: ${n}, ignoring prefetch.`)}function f(t){if(!t.N&&t.B.length){const e=t.B.shift();t.N=(async(t,e)=>{const i=e[0];t.o(\"received message:\",i,e[1],e.slice(2)),\"graph\"===i?await r(t,e[1],e.slice(2),!0):\"graph-url\"===i?await async function(t,e,i){await r(t,e,[],!1);const o=await n(t,new URL(e+i,t.l.origin));if(o&&200===o.status){const n=await o.json();n.push(i),await r(t,e,n,!0)}}(t,e[1],e[2]):\"prefetch\"===i?await u(t,e[1],e.slice(2)):\"prefetch-all\"===i?await function(t,n){const e=t.t.find((t=>n===t.i));e?u(t,n,e.L.filter((t=>\"string\"==typeof t))):console.error(`Base path not found: ${n}, ignoring prefetch.`)}(t,e[1]):\"ping\"===i?a(\"ping\"):\"verbose\"===i?(t.o=a)(\"mode: verbose\"):console.error(\"UNKNOWN MESSAGE:\",e)})(t,e).then((()=>{t.N=null,f(t)}))}}class l{constructor(t,n,e=4,i=null,o=null,s=[],c=[],a=[]){this.H=t,this.l=n,this.T=e,this.F=i,this.N=o,this.u=s,this.t=c,this.B=a}C(){return this.F}async R(t,n){const e=await this.C();return null==e?void 0:e.put(t,n)}async h(t){const n=await this.C();return null==n?void 0:n.match(t)}o(){}}(t=>{const e=(i=t.fetch.bind(t),o=new URL(t.location.href),new l(i,o));var i,o;e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open(\"QwikBundles\")),t.addEventListener(\"fetch\",(t=>{const i=t.request;if(\"GET\"===i.method){const o=n(e,new URL(i.url));o&&t.respondWith(o)}})),t.addEventListener(\"message\",(t=>{e.B.push(t.data),f(e)})),t.addEventListener(\"install\",(()=>{t.skipWaiting()})),t.addEventListener(\"activate\",(n=>{e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open(\"QwikBundles\")),n.waitUntil(t.clients.claim())}))})(globalThis)})();";
|
|
2
|
-
const QWIK_PREFETCH_DEBUG = "(() => {\n const DIRECT_PRIORITY = Number.MAX_SAFE_INTEGER >>> 1;\n function directFetch(swState, url) {\n const [basePath, filename] = parseBaseFilename(url);\n const base = swState.$bases$.find((base2 => basePath === base2.$path$));\n if (base) {\n swState.$log$(\"intercepting\", url.pathname);\n return enqueueFileAndDependencies(swState, base, [ filename ], DIRECT_PRIORITY).then((() => function(swState, url) {\n const currentRequestTask = swState.$queue$.find((task => task.$url$.pathname === url.pathname));\n if (currentRequestTask) {\n return currentRequestTask.$response$.then((response => response.clone()));\n }\n swState.$log$(\"CACHE HIT\", url.pathname);\n return swState.$match$(url);\n }(swState, url)));\n }\n }\n async function enqueueFileAndDependencies(swState, base, filenames, priority) {\n const fetchMap = new Map;\n filenames.forEach((filename => addDependencies(base, fetchMap, filename, priority)));\n await Promise.all(Array.from(fetchMap.entries()).map((([filename, prio]) => async function(swState, url, priority) {\n let task = swState.$queue$.find((task2 => task2.$url$.pathname === url.pathname));\n const mode = priority >= DIRECT_PRIORITY ? \"direct\" : \"prefetch\";\n if (task) {\n const state = task.$isFetching$ ? \"fetching\" : \"waiting\";\n if (task.$priority$ < priority) {\n swState.$log$(\"queue update priority\", state, url.pathname);\n task.$priority$ = priority;\n } else {\n swState.$log$(\"already in queue\", mode, state, url.pathname);\n }\n } else {\n if (!await swState.$match$(url)) {\n swState.$log$(\"enqueue\", mode, url.pathname);\n task = {\n $priority$: priority,\n $url$: url,\n $resolveResponse$: null,\n $response$: null,\n $isFetching$: !1\n };\n task.$response$ = new Promise((resolve => task.$resolveResponse$ = resolve));\n swState.$queue$.push(task);\n }\n }\n return task;\n }(swState, new URL(base.$path$ + filename, swState.$url$.origin), prio))));\n taskTick(swState);\n }\n function taskTick(swState) {\n swState.$queue$.sort(byFetchOrder);\n let outstandingRequests = 0;\n for (const task of swState.$queue$) {\n if (task.$isFetching$) {\n outstandingRequests++;\n } else if (swState.$getCache$() && (outstandingRequests < swState.$maxPrefetchRequests$ || task.$priority$ >= DIRECT_PRIORITY)) {\n task.$isFetching$ = !0;\n outstandingRequests++;\n const action = task.$priority$ >= DIRECT_PRIORITY ? \"FETCH (CACHE MISS)\" : \"FETCH\";\n swState.$log$(action, task.$url$.pathname);\n swState.$fetch$(task.$url$).then((async response => {\n task.$resolveResponse$(response);\n if (200 === response.status) {\n swState.$log$(\"CACHED\", task.$url$.pathname);\n await swState.$put$(task.$url$, response.clone());\n }\n })).finally((() => {\n swState.$log$(\"FETCH DONE\", task.$url$.pathname);\n swState.$queue$.splice(swState.$queue$.indexOf(task), 1);\n taskTick(swState);\n }));\n }\n }\n }\n function byFetchOrder(a, b) {\n return b.$priority$ - a.$priority$;\n }\n function addDependencies(base, fetchMap, filename, priority, addIndirect = !0) {\n if (!fetchMap.has(filename)) {\n fetchMap.set(filename, priority);\n if (!base.$processed$) {\n base.$processed$ = new Map;\n let current, isDirect;\n for (let i = 0; i < base.$graph$.length; i++) {\n const item = base.$graph$[i];\n if (\"string\" == typeof item) {\n current = {\n $direct$: [],\n $indirect$: []\n };\n isDirect = !0;\n base.$processed$.set(item, current);\n } else if (-1 === item) {\n isDirect = !1;\n } else {\n const depName = base.$graph$[item];\n isDirect ? current.$direct$.push(depName) : current.$indirect$.push(depName);\n }\n }\n }\n const deps = base.$processed$.get(filename);\n if (!deps) {\n return fetchMap;\n }\n for (const dependentFilename of deps.$direct$) {\n addDependencies(base, fetchMap, dependentFilename, priority);\n }\n if (addIndirect) {\n priority--;\n for (const dependentFilename of deps.$indirect$) {\n addDependencies(base, fetchMap, dependentFilename, priority, !1);\n }\n }\n }\n return fetchMap;\n }\n function parseBaseFilename(url) {\n const pathname = new URL(url).pathname;\n const slashIndex = pathname.lastIndexOf(\"/\");\n return [ pathname.substring(0, slashIndex + 1), pathname.substring(slashIndex + 1) ];\n }\n const log = (...args) => {\n console.log(\"⚙️ Prefetch SW:\", ...args);\n };\n const processMessage = async (state, msg) => {\n const type = msg[0];\n state.$log$(\"received message:\", type, msg[1], msg.slice(2));\n \"graph\" === type ? await processBundleGraph(state, msg[1], msg.slice(2), !0) : \"graph-url\" === type ? await async function(swState, base, graphPath) {\n await processBundleGraph(swState, base, [], !1);\n const response = await directFetch(swState, new URL(base + graphPath, swState.$url$.origin));\n if (response && 200 === response.status) {\n const graph = await response.json();\n graph.push(graphPath);\n await processBundleGraph(swState, base, graph, !0);\n }\n }(state, msg[1], msg[2]) : \"prefetch\" === type ? await processPrefetch(state, msg[1], msg.slice(2)) : \"prefetch-all\" === type ? await function(swState, basePath) {\n const base = swState.$bases$.find((base2 => basePath === base2.$path$));\n base ? processPrefetch(swState, basePath, base.$graph$.filter((item => \"string\" == typeof item))) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);\n }(state, msg[1]) : \"ping\" === type ? log(\"ping\") : \"verbose\" === type ? (state.$log$ = log)(\"mode: verbose\") : console.error(\"UNKNOWN MESSAGE:\", msg);\n };\n async function processBundleGraph(swState, base, graph, cleanup) {\n const existingBaseIndex = swState.$bases$.findIndex((b => b.$path$ === base));\n -1 !== existingBaseIndex && swState.$bases$.splice(existingBaseIndex, 1);\n swState.$log$(\"adding base:\", base);\n swState.$bases$.push({\n $path$: base,\n $graph$: graph,\n $processed$: void 0\n });\n if (cleanup) {\n const bundles = new Set(graph.filter((item => \"string\" == typeof item)));\n const cache = await swState.$getCache$();\n if (cache) {\n for (const request of await cache.keys()) {\n const [cacheBase, filename] = parseBaseFilename(new URL(request.url));\n const promises = [];\n if (cacheBase === base && !bundles.has(filename)) {\n swState.$log$(\"deleting\", request.url);\n promises.push(cache.delete(request));\n }\n await Promise.all(promises);\n }\n }\n }\n }\n function processPrefetch(swState, basePath, bundles) {\n let base = swState.$bases$.find((base2 => base2.$graph$.includes(bundles[0].replace(\"./\", \"\"))));\n base || (base = swState.$bases$.find((base2 => basePath === base2.$path$)));\n base ? enqueueFileAndDependencies(swState, base, bundles, 0) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);\n }\n function drainMsgQueue(swState) {\n if (!swState.$msgQueuePromise$ && swState.$msgQueue$.length) {\n const top = swState.$msgQueue$.shift();\n swState.$msgQueuePromise$ = processMessage(swState, top).then((() => {\n swState.$msgQueuePromise$ = null;\n drainMsgQueue(swState);\n }));\n }\n }\n class SWStateImpl {\n constructor($fetch$, $url$, $maxPrefetchRequests$ = 4, $cache$ = null, $msgQueuePromise$ = null, $queue$ = [], $bases$ = [], $msgQueue$ = []) {\n this.$fetch$ = $fetch$;\n this.$url$ = $url$;\n this.$maxPrefetchRequests$ = $maxPrefetchRequests$;\n this.$cache$ = $cache$;\n this.$msgQueuePromise$ = $msgQueuePromise$;\n this.$queue$ = $queue$;\n this.$bases$ = $bases$;\n this.$msgQueue$ = $msgQueue$;\n }\n $getCache$() {\n return this.$cache$;\n }\n async $put$(request, response) {\n const cache = await this.$getCache$();\n return null == cache ? void 0 : cache.put(request, response);\n }\n async $match$(request) {\n const cache = await this.$getCache$();\n return null == cache ? void 0 : cache.match(request);\n }\n $log$() {}\n }\n (swScope => {\n const swState = ((fetch, url) => new SWStateImpl(fetch, url))(swScope.fetch.bind(swScope), new URL(swScope.location.href));\n swState.$getCache$ = () => {\n if (swState.$cache$) {\n return swState.$cache$;\n }\n clearTimeout(undefined);\n setTimeout((() => {\n swState.$cache$ = null;\n }), 5e3);\n return swScope.caches.open(\"QwikBundles\");\n };\n swScope.addEventListener(\"fetch\", (ev => {\n const request = ev.request;\n if (\"GET\" === request.method) {\n const response = directFetch(swState, new URL(request.url));\n response && ev.respondWith(response);\n }\n }));\n swScope.addEventListener(\"message\", (ev => {\n swState.$msgQueue$.push(ev.data);\n drainMsgQueue(swState);\n }));\n swScope.addEventListener(\"install\", (() => {\n swScope.skipWaiting();\n }));\n swScope.addEventListener(\"activate\", (event => {\n swState.$getCache$ = () => {\n if (swState.$cache$) {\n return swState.$cache$;\n }\n clearTimeout(undefined);\n setTimeout((() => {\n swState.$cache$ = null;\n }), 5e3);\n return swScope.caches.open(\"QwikBundles\");\n };\n event.waitUntil(swScope.clients.claim());\n }));\n })(globalThis);\n})();";
|
|
3
|
-
export { QWIK_PREFETCH, QWIK_PREFETCH_DEBUG };
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
const DIRECT_PRIORITY = Number.MAX_SAFE_INTEGER >>> 1;
|
|
3
|
-
function directFetch(swState, url) {
|
|
4
|
-
const [basePath, filename] = parseBaseFilename(url);
|
|
5
|
-
const base = swState.$bases$.find((base2 => basePath === base2.$path$));
|
|
6
|
-
if (base) {
|
|
7
|
-
swState.$log$("intercepting", url.pathname);
|
|
8
|
-
return enqueueFileAndDependencies(swState, base, [ filename ], DIRECT_PRIORITY).then((() => function(swState, url) {
|
|
9
|
-
const currentRequestTask = swState.$queue$.find((task => task.$url$.pathname === url.pathname));
|
|
10
|
-
if (currentRequestTask) {
|
|
11
|
-
return currentRequestTask.$response$.then((response => response.clone()));
|
|
12
|
-
}
|
|
13
|
-
swState.$log$("CACHE HIT", url.pathname);
|
|
14
|
-
return swState.$match$(url);
|
|
15
|
-
}(swState, url)));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function enqueueFileAndDependencies(swState, base, filenames, priority) {
|
|
19
|
-
const fetchMap = new Map;
|
|
20
|
-
filenames.forEach((filename => addDependencies(base, fetchMap, filename, priority)));
|
|
21
|
-
await Promise.all(Array.from(fetchMap.entries()).map((([filename, prio]) => async function(swState, url, priority) {
|
|
22
|
-
let task = swState.$queue$.find((task2 => task2.$url$.pathname === url.pathname));
|
|
23
|
-
const mode = priority >= DIRECT_PRIORITY ? "direct" : "prefetch";
|
|
24
|
-
if (task) {
|
|
25
|
-
const state = task.$isFetching$ ? "fetching" : "waiting";
|
|
26
|
-
if (task.$priority$ < priority) {
|
|
27
|
-
swState.$log$("queue update priority", state, url.pathname);
|
|
28
|
-
task.$priority$ = priority;
|
|
29
|
-
} else {
|
|
30
|
-
swState.$log$("already in queue", mode, state, url.pathname);
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
if (!await swState.$match$(url)) {
|
|
34
|
-
swState.$log$("enqueue", mode, url.pathname);
|
|
35
|
-
task = {
|
|
36
|
-
$priority$: priority,
|
|
37
|
-
$url$: url,
|
|
38
|
-
$resolveResponse$: null,
|
|
39
|
-
$response$: null,
|
|
40
|
-
$isFetching$: !1
|
|
41
|
-
};
|
|
42
|
-
task.$response$ = new Promise((resolve => task.$resolveResponse$ = resolve));
|
|
43
|
-
swState.$queue$.push(task);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return task;
|
|
47
|
-
}(swState, new URL(base.$path$ + filename, swState.$url$.origin), prio))));
|
|
48
|
-
taskTick(swState);
|
|
49
|
-
}
|
|
50
|
-
function taskTick(swState) {
|
|
51
|
-
swState.$queue$.sort(byFetchOrder);
|
|
52
|
-
let outstandingRequests = 0;
|
|
53
|
-
for (const task of swState.$queue$) {
|
|
54
|
-
if (task.$isFetching$) {
|
|
55
|
-
outstandingRequests++;
|
|
56
|
-
} else if (swState.$getCache$() && (outstandingRequests < swState.$maxPrefetchRequests$ || task.$priority$ >= DIRECT_PRIORITY)) {
|
|
57
|
-
task.$isFetching$ = !0;
|
|
58
|
-
outstandingRequests++;
|
|
59
|
-
const action = task.$priority$ >= DIRECT_PRIORITY ? "FETCH (CACHE MISS)" : "FETCH";
|
|
60
|
-
swState.$log$(action, task.$url$.pathname);
|
|
61
|
-
swState.$fetch$(task.$url$).then((async response => {
|
|
62
|
-
task.$resolveResponse$(response);
|
|
63
|
-
if (200 === response.status) {
|
|
64
|
-
swState.$log$("CACHED", task.$url$.pathname);
|
|
65
|
-
await swState.$put$(task.$url$, response.clone());
|
|
66
|
-
}
|
|
67
|
-
})).finally((() => {
|
|
68
|
-
swState.$log$("FETCH DONE", task.$url$.pathname);
|
|
69
|
-
swState.$queue$.splice(swState.$queue$.indexOf(task), 1);
|
|
70
|
-
taskTick(swState);
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function byFetchOrder(a, b) {
|
|
76
|
-
return b.$priority$ - a.$priority$;
|
|
77
|
-
}
|
|
78
|
-
function addDependencies(base, fetchMap, filename, priority, addIndirect = !0) {
|
|
79
|
-
if (!fetchMap.has(filename)) {
|
|
80
|
-
fetchMap.set(filename, priority);
|
|
81
|
-
if (!base.$processed$) {
|
|
82
|
-
base.$processed$ = new Map;
|
|
83
|
-
let current, isDirect;
|
|
84
|
-
for (let i = 0; i < base.$graph$.length; i++) {
|
|
85
|
-
const item = base.$graph$[i];
|
|
86
|
-
if ("string" == typeof item) {
|
|
87
|
-
current = {
|
|
88
|
-
$direct$: [],
|
|
89
|
-
$indirect$: []
|
|
90
|
-
};
|
|
91
|
-
isDirect = !0;
|
|
92
|
-
base.$processed$.set(item, current);
|
|
93
|
-
} else if (-1 === item) {
|
|
94
|
-
isDirect = !1;
|
|
95
|
-
} else {
|
|
96
|
-
const depName = base.$graph$[item];
|
|
97
|
-
isDirect ? current.$direct$.push(depName) : current.$indirect$.push(depName);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const deps = base.$processed$.get(filename);
|
|
102
|
-
if (!deps) {
|
|
103
|
-
return fetchMap;
|
|
104
|
-
}
|
|
105
|
-
for (const dependentFilename of deps.$direct$) {
|
|
106
|
-
addDependencies(base, fetchMap, dependentFilename, priority);
|
|
107
|
-
}
|
|
108
|
-
if (addIndirect) {
|
|
109
|
-
priority--;
|
|
110
|
-
for (const dependentFilename of deps.$indirect$) {
|
|
111
|
-
addDependencies(base, fetchMap, dependentFilename, priority, !1);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return fetchMap;
|
|
116
|
-
}
|
|
117
|
-
function parseBaseFilename(url) {
|
|
118
|
-
const pathname = new URL(url).pathname;
|
|
119
|
-
const slashIndex = pathname.lastIndexOf("/");
|
|
120
|
-
return [ pathname.substring(0, slashIndex + 1), pathname.substring(slashIndex + 1) ];
|
|
121
|
-
}
|
|
122
|
-
const log = (...args) => {
|
|
123
|
-
console.log("⚙️ Prefetch SW:", ...args);
|
|
124
|
-
};
|
|
125
|
-
const processMessage = async (state, msg) => {
|
|
126
|
-
const type = msg[0];
|
|
127
|
-
state.$log$("received message:", type, msg[1], msg.slice(2));
|
|
128
|
-
"graph" === type ? await processBundleGraph(state, msg[1], msg.slice(2), !0) : "graph-url" === type ? await async function(swState, base, graphPath) {
|
|
129
|
-
await processBundleGraph(swState, base, [], !1);
|
|
130
|
-
const response = await directFetch(swState, new URL(base + graphPath, swState.$url$.origin));
|
|
131
|
-
if (response && 200 === response.status) {
|
|
132
|
-
const graph = await response.json();
|
|
133
|
-
graph.push(graphPath);
|
|
134
|
-
await processBundleGraph(swState, base, graph, !0);
|
|
135
|
-
}
|
|
136
|
-
}(state, msg[1], msg[2]) : "prefetch" === type ? await processPrefetch(state, msg[1], msg.slice(2)) : "prefetch-all" === type ? await function(swState, basePath) {
|
|
137
|
-
const base = swState.$bases$.find((base2 => basePath === base2.$path$));
|
|
138
|
-
base ? processPrefetch(swState, basePath, base.$graph$.filter((item => "string" == typeof item))) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);
|
|
139
|
-
}(state, msg[1]) : "ping" === type ? log("ping") : "verbose" === type ? (state.$log$ = log)("mode: verbose") : console.error("UNKNOWN MESSAGE:", msg);
|
|
140
|
-
};
|
|
141
|
-
async function processBundleGraph(swState, base, graph, cleanup) {
|
|
142
|
-
const existingBaseIndex = swState.$bases$.findIndex((b => b.$path$ === base));
|
|
143
|
-
-1 !== existingBaseIndex && swState.$bases$.splice(existingBaseIndex, 1);
|
|
144
|
-
swState.$log$("adding base:", base);
|
|
145
|
-
swState.$bases$.push({
|
|
146
|
-
$path$: base,
|
|
147
|
-
$graph$: graph,
|
|
148
|
-
$processed$: void 0
|
|
149
|
-
});
|
|
150
|
-
if (cleanup) {
|
|
151
|
-
const bundles = new Set(graph.filter((item => "string" == typeof item)));
|
|
152
|
-
const cache = await swState.$getCache$();
|
|
153
|
-
if (cache) {
|
|
154
|
-
for (const request of await cache.keys()) {
|
|
155
|
-
const [cacheBase, filename] = parseBaseFilename(new URL(request.url));
|
|
156
|
-
const promises = [];
|
|
157
|
-
if (cacheBase === base && !bundles.has(filename)) {
|
|
158
|
-
swState.$log$("deleting", request.url);
|
|
159
|
-
promises.push(cache.delete(request));
|
|
160
|
-
}
|
|
161
|
-
await Promise.all(promises);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function processPrefetch(swState, basePath, bundles) {
|
|
167
|
-
let base = swState.$bases$.find((base2 => base2.$graph$.includes(bundles[0].replace("./", ""))));
|
|
168
|
-
base || (base = swState.$bases$.find((base2 => basePath === base2.$path$)));
|
|
169
|
-
base ? enqueueFileAndDependencies(swState, base, bundles, 0) : console.error(`Base path not found: ${basePath}, ignoring prefetch.`);
|
|
170
|
-
}
|
|
171
|
-
function drainMsgQueue(swState) {
|
|
172
|
-
if (!swState.$msgQueuePromise$ && swState.$msgQueue$.length) {
|
|
173
|
-
const top = swState.$msgQueue$.shift();
|
|
174
|
-
swState.$msgQueuePromise$ = processMessage(swState, top).then((() => {
|
|
175
|
-
swState.$msgQueuePromise$ = null;
|
|
176
|
-
drainMsgQueue(swState);
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
class SWStateImpl {
|
|
181
|
-
constructor($fetch$, $url$, $maxPrefetchRequests$ = 4, $cache$ = null, $msgQueuePromise$ = null, $queue$ = [], $bases$ = [], $msgQueue$ = []) {
|
|
182
|
-
this.$fetch$ = $fetch$;
|
|
183
|
-
this.$url$ = $url$;
|
|
184
|
-
this.$maxPrefetchRequests$ = $maxPrefetchRequests$;
|
|
185
|
-
this.$cache$ = $cache$;
|
|
186
|
-
this.$msgQueuePromise$ = $msgQueuePromise$;
|
|
187
|
-
this.$queue$ = $queue$;
|
|
188
|
-
this.$bases$ = $bases$;
|
|
189
|
-
this.$msgQueue$ = $msgQueue$;
|
|
190
|
-
}
|
|
191
|
-
$getCache$() {
|
|
192
|
-
return this.$cache$;
|
|
193
|
-
}
|
|
194
|
-
async $put$(request, response) {
|
|
195
|
-
const cache = await this.$getCache$();
|
|
196
|
-
return null == cache ? void 0 : cache.put(request, response);
|
|
197
|
-
}
|
|
198
|
-
async $match$(request) {
|
|
199
|
-
const cache = await this.$getCache$();
|
|
200
|
-
return null == cache ? void 0 : cache.match(request);
|
|
201
|
-
}
|
|
202
|
-
$log$() {}
|
|
203
|
-
}
|
|
204
|
-
(swScope => {
|
|
205
|
-
const swState = ((fetch, url) => new SWStateImpl(fetch, url))(swScope.fetch.bind(swScope), new URL(swScope.location.href));
|
|
206
|
-
swState.$getCache$ = () => {
|
|
207
|
-
if (swState.$cache$) {
|
|
208
|
-
return swState.$cache$;
|
|
209
|
-
}
|
|
210
|
-
clearTimeout(undefined);
|
|
211
|
-
setTimeout((() => {
|
|
212
|
-
swState.$cache$ = null;
|
|
213
|
-
}), 5e3);
|
|
214
|
-
return swScope.caches.open("QwikBundles");
|
|
215
|
-
};
|
|
216
|
-
swScope.addEventListener("fetch", (ev => {
|
|
217
|
-
const request = ev.request;
|
|
218
|
-
if ("GET" === request.method) {
|
|
219
|
-
const response = directFetch(swState, new URL(request.url));
|
|
220
|
-
response && ev.respondWith(response);
|
|
221
|
-
}
|
|
222
|
-
}));
|
|
223
|
-
swScope.addEventListener("message", (ev => {
|
|
224
|
-
swState.$msgQueue$.push(ev.data);
|
|
225
|
-
drainMsgQueue(swState);
|
|
226
|
-
}));
|
|
227
|
-
swScope.addEventListener("install", (() => {
|
|
228
|
-
swScope.skipWaiting();
|
|
229
|
-
}));
|
|
230
|
-
swScope.addEventListener("activate", (event => {
|
|
231
|
-
swState.$getCache$ = () => {
|
|
232
|
-
if (swState.$cache$) {
|
|
233
|
-
return swState.$cache$;
|
|
234
|
-
}
|
|
235
|
-
clearTimeout(undefined);
|
|
236
|
-
setTimeout((() => {
|
|
237
|
-
swState.$cache$ = null;
|
|
238
|
-
}), 5e3);
|
|
239
|
-
return swScope.caches.open("QwikBundles");
|
|
240
|
-
};
|
|
241
|
-
event.waitUntil(swScope.clients.claim());
|
|
242
|
-
}));
|
|
243
|
-
})(globalThis);
|
|
244
|
-
})();
|
package/dist/qwik-prefetch.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{const t=Number.MAX_SAFE_INTEGER>>>1;function n(n,i){const[o,s]=c(i),a=n.t.find((t=>o===t.i));if(a)return n.o("intercepting",i.pathname),e(n,a,[s],t).then((()=>function(t,n){const e=t.u.find((t=>t.l.pathname===n.pathname));return e?e.$.then((t=>t.clone())):(t.o("CACHE HIT",n.pathname),t.h(n))}(n,i)))}async function e(n,e,o,c){const a=new Map;o.forEach((t=>s(e,a,t,c))),await Promise.all(Array.from(a.entries()).map((([i,o])=>async function(n,e,i){let o=n.u.find((t=>t.l.pathname===e.pathname));const s=i>=t?"direct":"prefetch";if(o){const t=o.p?"fetching":"waiting";o.m<i?(n.o("queue update priority",t,e.pathname),o.m=i):n.o("already in queue",s,t,e.pathname)}else await n.h(e)||(n.o("enqueue",s,e.pathname),o={m:i,l:e,v:null,$:null,p:!1},o.$=new Promise((t=>o.v=t)),n.u.push(o));return o}(n,new URL(e.i+i,n.l.origin),o)))),i(n)}function i(n){n.u.sort(o);let e=0;for(const o of n.u)if(o.p)e++;else if(n.C()&&(e<n.T||o.m>=t)){o.p=!0,e++;const s=o.m>=t?"FETCH (CACHE MISS)":"FETCH";n.o(s,o.l.pathname),n.H(o.l).then((async t=>{o.v(t),200===t.status&&(n.o("CACHED",o.l.pathname),await n.R(o.l,t.clone()))})).finally((()=>{n.o("FETCH DONE",o.l.pathname),n.u.splice(n.u.indexOf(o),1),i(n)}))}}function o(t,n){return n.m-t.m}function s(t,n,e,i,o=!0){if(!n.has(e)){if(n.set(e,i),!t.U){let n,e;t.U=new Map;for(let i=0;i<t.L.length;i++){const o=t.L[i];if("string"==typeof o)n={S:[],A:[]},e=!0,t.U.set(o,n);else if(-1===o)e=!1;else{const i=t.L[o];e?n.S.push(i):n.A.push(i)}}}const c=t.U.get(e);if(!c)return n;for(const e of c.S)s(t,n,e,i);if(o){i--;for(const e of c.A)s(t,n,e,i,!1)}}return n}function c(t){const n=new URL(t).pathname,e=n.lastIndexOf("/");return[n.substring(0,e+1),n.substring(e+1)]}const a=(...t)=>{console.log("⚙️ Prefetch SW:",...t)};async function r(t,n,e,i){const o=t.t.findIndex((t=>t.i===n));if(-1!==o&&t.t.splice(o,1),t.o("adding base:",n),t.t.push({i:n,L:e,U:void 0}),i){const i=new Set(e.filter((t=>"string"==typeof t))),o=await t.C();if(o)for(const e of await o.keys()){const[s,a]=c(new URL(e.url)),r=[];s!==n||i.has(a)||(t.o("deleting",e.url),r.push(o.delete(e))),await Promise.all(r)}}}function u(t,n,i){let o=t.t.find((t=>t.L.includes(i[0].replace("./",""))));o||(o=t.t.find((t=>n===t.i))),o?e(t,o,i,0):console.error(`Base path not found: ${n}, ignoring prefetch.`)}function f(t){if(!t.N&&t.B.length){const e=t.B.shift();t.N=(async(t,e)=>{const i=e[0];t.o("received message:",i,e[1],e.slice(2)),"graph"===i?await r(t,e[1],e.slice(2),!0):"graph-url"===i?await async function(t,e,i){await r(t,e,[],!1);const o=await n(t,new URL(e+i,t.l.origin));if(o&&200===o.status){const n=await o.json();n.push(i),await r(t,e,n,!0)}}(t,e[1],e[2]):"prefetch"===i?await u(t,e[1],e.slice(2)):"prefetch-all"===i?await function(t,n){const e=t.t.find((t=>n===t.i));e?u(t,n,e.L.filter((t=>"string"==typeof t))):console.error(`Base path not found: ${n}, ignoring prefetch.`)}(t,e[1]):"ping"===i?a("ping"):"verbose"===i?(t.o=a)("mode: verbose"):console.error("UNKNOWN MESSAGE:",e)})(t,e).then((()=>{t.N=null,f(t)}))}}class l{constructor(t,n,e=4,i=null,o=null,s=[],c=[],a=[]){this.H=t,this.l=n,this.T=e,this.F=i,this.N=o,this.u=s,this.t=c,this.B=a}C(){return this.F}async R(t,n){const e=await this.C();return null==e?void 0:e.put(t,n)}async h(t){const n=await this.C();return null==n?void 0:n.match(t)}o(){}}(t=>{const e=(i=t.fetch.bind(t),o=new URL(t.location.href),new l(i,o));var i,o;e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open("QwikBundles")),t.addEventListener("fetch",(t=>{const i=t.request;if("GET"===i.method){const o=n(e,new URL(i.url));o&&t.respondWith(o)}})),t.addEventListener("message",(t=>{e.B.push(t.data),f(e)})),t.addEventListener("install",(()=>{t.skipWaiting()})),t.addEventListener("activate",(n=>{e.C=()=>e.F?e.F:(clearTimeout(void 0),setTimeout((()=>{e.F=null}),5e3),t.caches.open("QwikBundles")),n.waitUntil(t.clients.claim())}))})(globalThis)})();
|
|
File without changes
|