@qwik.dev/core 2.0.0-beta.30 → 2.0.0-beta.32
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/backpatch/package.json +1 -1
- package/dist/build/package.json +1 -1
- package/dist/cli.mjs +215 -170
- package/dist/core-internal.d.ts +147 -29
- package/dist/core.min.mjs +2 -2
- package/dist/core.mjs +11021 -10352
- package/dist/core.mjs.map +1 -1
- package/dist/core.prod.mjs +6064 -5555
- package/dist/insights/vite/index.mjs +36 -33
- package/dist/loader/index.mjs +2 -2
- package/dist/loader/package.json +1 -1
- package/dist/optimizer.mjs +790 -766
- package/dist/preloader.mjs +210 -112
- package/dist/qwikloader.debug.js +261 -101
- package/dist/qwikloader.js +1 -1
- package/dist/server.mjs +272 -95
- package/dist/server.prod.mjs +873 -681
- package/dist/starters/adapters/bun/src/entry.bun.ts +2 -8
- package/dist/starters/adapters/cloud-run/src/entry.cloud-run.tsx +2 -4
- package/dist/starters/adapters/deno/src/entry.deno.ts +2 -8
- package/dist/starters/adapters/express/src/entry.express.tsx +1 -4
- package/dist/starters/adapters/fastify/src/plugins/fastify-qwik.ts +1 -2
- package/dist/starters/adapters/node-server/src/entry.node-server.tsx +2 -4
- package/dist/testing/index.d.ts +9 -4
- package/dist/testing/index.mjs +1226 -472
- package/dist/testing/package.json +1 -1
- package/package.json +3 -3
package/dist/preloader.mjs
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { isBrowser } from "@qwik.dev/core/build";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
import { isServer, isBrowser as isBrowser$2 } from "@qwik.dev/core/build";
|
|
2
|
+
const createMacroTask = (e) => {
|
|
3
|
+
let t;
|
|
4
|
+
if (typeof MessageChannel !== "undefined") {
|
|
5
|
+
const n = new MessageChannel();
|
|
6
|
+
n.port1.onmessage = () => e();
|
|
7
|
+
t = () => n.port2.postMessage(null);
|
|
8
|
+
} else t = () => setTimeout(e);
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
const isBrowser$1 = !isServer;
|
|
12
|
+
const doc = isBrowser$1 ? document : void 0;
|
|
13
|
+
const config = { t: 0, o: 25, u: 0.65 };
|
|
14
|
+
const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
|
|
15
|
+
const loadStart = performance.now();
|
|
6
16
|
const isJSRegex = /\.[mc]?js$/;
|
|
17
|
+
const yieldInterval = 1e3 / 60;
|
|
7
18
|
const BundleImportState_None = 0;
|
|
8
19
|
const BundleImportState_Queued = 1;
|
|
9
20
|
const BundleImportState_Preload = 2;
|
|
@@ -13,178 +24,265 @@ const bundles = /* @__PURE__ */ new Map();
|
|
|
13
24
|
let queueDirty;
|
|
14
25
|
let preloadCount = 0;
|
|
15
26
|
const queue = [];
|
|
27
|
+
const nextTriggerMacroTask = createMacroTask(trigger);
|
|
28
|
+
const nextAdjustmentMacroTask = createMacroTask(processPendingAdjustments);
|
|
29
|
+
let isTriggerScheduled = 0;
|
|
30
|
+
let isAdjustmentScheduled = 0;
|
|
31
|
+
let isProcessingAdjustments = 0;
|
|
32
|
+
const shouldYieldInBrowser = isBrowser$2;
|
|
33
|
+
const adjustmentStack = [];
|
|
16
34
|
const log = (...e) => {
|
|
17
|
-
console.log(`Preloader ${
|
|
35
|
+
console.log(`Preloader ${performance.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`, ...e);
|
|
18
36
|
};
|
|
19
37
|
const sortQueue = () => {
|
|
20
38
|
if (queueDirty) {
|
|
21
|
-
queue.sort((e, t) => e.
|
|
39
|
+
queue.sort((e, t) => e.l - t.l);
|
|
22
40
|
queueDirty = 0;
|
|
23
41
|
}
|
|
24
42
|
};
|
|
25
|
-
|
|
43
|
+
function trigger() {
|
|
44
|
+
isTriggerScheduled = 0;
|
|
26
45
|
if (!queue.length) return;
|
|
27
46
|
sortQueue();
|
|
47
|
+
const e = performance.now() + yieldInterval;
|
|
48
|
+
let t = 0;
|
|
28
49
|
while (queue.length) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const o = 1 -
|
|
32
|
-
const
|
|
50
|
+
const n = queue[0];
|
|
51
|
+
const s = n.l;
|
|
52
|
+
const o = 1 - s;
|
|
53
|
+
const r = graph ? config.o : (
|
|
33
54
|
// While the graph is not available, we limit to 5 preloads
|
|
34
55
|
5
|
|
35
56
|
);
|
|
36
|
-
if (o >= 0.99 || preloadCount <
|
|
57
|
+
if (o >= 0.99 || preloadCount < r) {
|
|
37
58
|
queue.shift();
|
|
38
|
-
preloadOne(
|
|
59
|
+
preloadOne(n);
|
|
60
|
+
if (performance.now() >= e) {
|
|
61
|
+
t = 1;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
39
64
|
} else break;
|
|
40
65
|
}
|
|
66
|
+
if (t && queue.length && !isTriggerScheduled) {
|
|
67
|
+
isTriggerScheduled = 1;
|
|
68
|
+
nextTriggerMacroTask();
|
|
69
|
+
}
|
|
41
70
|
if (config.t && !queue.length) {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
log(`>>>> done ${
|
|
71
|
+
const e2 = [...bundles.values()].filter((e3) => e3.i > BundleImportState_None);
|
|
72
|
+
const t2 = e2.reduce((e3, t3) => e3 + t3.m, 0);
|
|
73
|
+
const n = e2.reduce((e3, t3) => e3 + t3.p, 0);
|
|
74
|
+
log(`>>>> done ${e2.length}/${bundles.size} total: ${t2}ms waited, ${n}ms loaded`);
|
|
46
75
|
}
|
|
76
|
+
}
|
|
77
|
+
const enqueueAdjustment = (e, t, n, s) => {
|
|
78
|
+
adjustmentStack.unshift({ $: e, l: t, B: s, h: n });
|
|
47
79
|
};
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
e.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
const processAdjustmentFrame = () => {
|
|
81
|
+
const e = adjustmentStack[adjustmentStack.length - 1];
|
|
82
|
+
const t = e.$;
|
|
83
|
+
if (e.S) {
|
|
84
|
+
const n2 = e.j;
|
|
85
|
+
if (n2 >= e.S.length) {
|
|
86
|
+
adjustmentStack.pop();
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
const s = e.S[n2];
|
|
90
|
+
e.j = n2 + 1;
|
|
91
|
+
const o = getBundle(s.k);
|
|
92
|
+
if (o.l === 0) return 1;
|
|
93
|
+
const r = 1 - t.l;
|
|
94
|
+
let a;
|
|
95
|
+
if (r === 1 || r >= 0.99 && e.h.T < 100) {
|
|
96
|
+
e.h.T++;
|
|
97
|
+
a = Math.min(0.01, 1 - s.I);
|
|
98
|
+
} else {
|
|
99
|
+
const e2 = 1 - s.I * r;
|
|
100
|
+
const t2 = s.A;
|
|
101
|
+
const n3 = e2 / t2;
|
|
102
|
+
a = Math.max(0.02, o.l * n3);
|
|
103
|
+
s.A = n3;
|
|
104
|
+
}
|
|
105
|
+
adjustmentStack.push({ $: o, l: a, B: e.B, h: e.h });
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
if (e.B?.has(t)) {
|
|
109
|
+
adjustmentStack.pop();
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
const n = t.l;
|
|
113
|
+
t.l = e.l;
|
|
114
|
+
if (n - t.l < 0.01) {
|
|
115
|
+
adjustmentStack.pop();
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
75
118
|
if (
|
|
76
119
|
// don't queue until we have initialized the preloader
|
|
77
|
-
base != null &&
|
|
120
|
+
base != null && t.i < BundleImportState_Preload
|
|
78
121
|
) {
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
queue.push(
|
|
82
|
-
config.t && log(`queued ${Math.round((1 -
|
|
122
|
+
if (t.i === BundleImportState_None) {
|
|
123
|
+
t.i = BundleImportState_Queued;
|
|
124
|
+
queue.push(t);
|
|
125
|
+
config.t && log(`queued ${Math.round((1 - t.l) * 100)}%`, t.k);
|
|
83
126
|
}
|
|
84
127
|
queueDirty = 1;
|
|
85
128
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
if (t.S?.length) {
|
|
130
|
+
const n2 = e.B || /* @__PURE__ */ new Set();
|
|
131
|
+
n2.add(t);
|
|
132
|
+
e.B = n2;
|
|
133
|
+
e.S = t.S;
|
|
134
|
+
e.j = 0;
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
adjustmentStack.pop();
|
|
138
|
+
return 0;
|
|
139
|
+
};
|
|
140
|
+
function processPendingAdjustments() {
|
|
141
|
+
if (isProcessingAdjustments || !adjustmentStack.length) return;
|
|
142
|
+
isAdjustmentScheduled = 0;
|
|
143
|
+
isProcessingAdjustments = 1;
|
|
144
|
+
const e = shouldYieldInBrowser ? performance.now() + yieldInterval : 0;
|
|
145
|
+
let t = 0;
|
|
146
|
+
while (adjustmentStack.length) {
|
|
147
|
+
t = 1;
|
|
148
|
+
const n = processAdjustmentFrame();
|
|
149
|
+
if (shouldYieldInBrowser && n && performance.now() >= e) {
|
|
150
|
+
if (!isAdjustmentScheduled) {
|
|
151
|
+
isAdjustmentScheduled = 1;
|
|
152
|
+
nextAdjustmentMacroTask();
|
|
103
153
|
}
|
|
104
|
-
|
|
154
|
+
break;
|
|
105
155
|
}
|
|
106
156
|
}
|
|
157
|
+
isProcessingAdjustments = 0;
|
|
158
|
+
if (t && shouldYieldInBrowser) nextTriggerMacroTask();
|
|
159
|
+
}
|
|
160
|
+
const preloadOne = (e) => {
|
|
161
|
+
if (e.i >= BundleImportState_Preload) return;
|
|
162
|
+
preloadCount++;
|
|
163
|
+
const t = performance.now();
|
|
164
|
+
e.m = t - e.M;
|
|
165
|
+
e.i = BundleImportState_Preload;
|
|
166
|
+
config.t && log(`<< load ${Math.round((1 - e.l) * 100)}% after ${`${e.m}ms`}`, e.k);
|
|
167
|
+
const n = doc.createElement("link");
|
|
168
|
+
n.href = new URL(`${base}${e.k}`, doc.baseURI).toString();
|
|
169
|
+
n.rel = rel;
|
|
170
|
+
n.as = "script";
|
|
171
|
+
n.onload = n.onerror = () => {
|
|
172
|
+
preloadCount--;
|
|
173
|
+
const s = performance.now();
|
|
174
|
+
e.p = s - t;
|
|
175
|
+
e.i = BundleImportState_Loaded;
|
|
176
|
+
config.t && log(`>> done after ${e.p}ms`, e.k);
|
|
177
|
+
n.remove();
|
|
178
|
+
nextTriggerMacroTask();
|
|
179
|
+
};
|
|
180
|
+
doc.head.appendChild(n);
|
|
107
181
|
};
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (
|
|
182
|
+
const adjustProbabilities = (e, t, n) => {
|
|
183
|
+
enqueueAdjustment(e, t, { T: 0 }, n);
|
|
184
|
+
if (shouldYieldInBrowser) nextAdjustmentMacroTask();
|
|
185
|
+
else processPendingAdjustments();
|
|
186
|
+
};
|
|
187
|
+
const handleBundle = (e, t, n) => {
|
|
188
|
+
const s = getBundle(e);
|
|
189
|
+
if (s && s.l > t) if (n) enqueueAdjustment(s, t, n);
|
|
190
|
+
else adjustProbabilities(s, t);
|
|
111
191
|
};
|
|
112
|
-
let depsCount;
|
|
113
192
|
const preload = (e, t) => {
|
|
114
193
|
if (!e?.length) return;
|
|
115
|
-
|
|
116
|
-
|
|
194
|
+
let n = t ? 1 - t : 0.4;
|
|
195
|
+
const s = { T: 0 };
|
|
117
196
|
if (Array.isArray(e)) for (let t2 = e.length - 1; t2 >= 0; t2--) {
|
|
118
|
-
const
|
|
119
|
-
if (typeof
|
|
120
|
-
else handleBundle(n,
|
|
197
|
+
const o = e[t2];
|
|
198
|
+
if (typeof o === "number") n = 1 - o / 10;
|
|
199
|
+
else handleBundle(o, n, s);
|
|
121
200
|
}
|
|
122
|
-
else handleBundle(e,
|
|
123
|
-
if (
|
|
201
|
+
else handleBundle(e, n, s);
|
|
202
|
+
if (shouldYieldInBrowser) nextAdjustmentMacroTask();
|
|
203
|
+
else processPendingAdjustments();
|
|
124
204
|
};
|
|
125
|
-
if (isBrowser) document.addEventListener("qsymbol", (e) => {
|
|
126
|
-
const { symbol: t, href:
|
|
127
|
-
if (
|
|
205
|
+
if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
|
|
206
|
+
const { symbol: t, href: n } = e.detail;
|
|
207
|
+
if (n) {
|
|
128
208
|
const e2 = t.slice(t.lastIndexOf("_") + 1);
|
|
129
209
|
preload(e2, 1);
|
|
130
210
|
}
|
|
131
211
|
});
|
|
132
212
|
let base;
|
|
133
213
|
let graph;
|
|
134
|
-
const
|
|
214
|
+
const isBrowser = !isServer;
|
|
215
|
+
const makeBundle = (e, t) => ({ k: e, i: isJSRegex.test(e) ? BundleImportState_None : BundleImportState_Alias, S: t, l: 1, M: performance.now(), m: 0, p: 0 });
|
|
135
216
|
const parseBundleGraph = (e) => {
|
|
136
217
|
const t = /* @__PURE__ */ new Map();
|
|
137
|
-
let
|
|
138
|
-
while (
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
let
|
|
142
|
-
let
|
|
143
|
-
while (
|
|
144
|
-
if (
|
|
145
|
-
else
|
|
146
|
-
|
|
218
|
+
let n = 0;
|
|
219
|
+
while (n < e.length) {
|
|
220
|
+
const s = e[n++];
|
|
221
|
+
const o = [];
|
|
222
|
+
let r;
|
|
223
|
+
let a = 1;
|
|
224
|
+
while (r = e[n], typeof r === "number") {
|
|
225
|
+
if (r < 0) a = -r / 10;
|
|
226
|
+
else o.push({ k: e[r], I: a, A: 1 });
|
|
227
|
+
n++;
|
|
147
228
|
}
|
|
148
|
-
t.set(
|
|
229
|
+
t.set(s, o);
|
|
149
230
|
}
|
|
150
231
|
return t;
|
|
151
232
|
};
|
|
152
233
|
const getBundle = (e) => {
|
|
153
234
|
let t = bundles.get(e);
|
|
154
235
|
if (!t) {
|
|
155
|
-
let
|
|
236
|
+
let n;
|
|
156
237
|
if (graph) {
|
|
157
|
-
|
|
158
|
-
if (!
|
|
159
|
-
if (!
|
|
238
|
+
n = graph.get(e);
|
|
239
|
+
if (!n) return;
|
|
240
|
+
if (!n.length) n = void 0;
|
|
160
241
|
}
|
|
161
|
-
t = makeBundle(e,
|
|
242
|
+
t = makeBundle(e, n);
|
|
162
243
|
bundles.set(e, t);
|
|
163
244
|
}
|
|
164
245
|
return t;
|
|
165
246
|
};
|
|
166
|
-
const loadBundleGraph = (e, t,
|
|
167
|
-
if (
|
|
168
|
-
if ("d" in
|
|
169
|
-
if ("P" in
|
|
170
|
-
if ("Q" in
|
|
247
|
+
const loadBundleGraph = (e, t, n) => {
|
|
248
|
+
if (n) {
|
|
249
|
+
if ("d" in n) config.t = !!n.d;
|
|
250
|
+
if ("P" in n) config.o = n["P"];
|
|
251
|
+
if ("Q" in n) config.u = 1 - n["Q"];
|
|
171
252
|
}
|
|
172
253
|
if (!isBrowser || e == null) return;
|
|
173
254
|
base = e;
|
|
174
255
|
if (t) t.then((e2) => e2.text()).then((e2) => {
|
|
175
256
|
graph = parseBundleGraph(JSON.parse(e2));
|
|
176
257
|
const t2 = [];
|
|
177
|
-
for (const [e3,
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
t2.push([
|
|
182
|
-
|
|
258
|
+
for (const [e3, n3] of graph.entries()) {
|
|
259
|
+
const s2 = getBundle(e3);
|
|
260
|
+
s2.S = n3;
|
|
261
|
+
if (s2.l < 1) {
|
|
262
|
+
t2.push([s2, s2.l]);
|
|
263
|
+
s2.l = 1;
|
|
183
264
|
}
|
|
184
265
|
}
|
|
185
266
|
config.t && log(`parseBundleGraph got ${graph.size} bundles, adjusting ${t2.length}`);
|
|
186
|
-
|
|
187
|
-
|
|
267
|
+
if (!t2.length) {
|
|
268
|
+
nextTriggerMacroTask();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
let n2 = 0;
|
|
272
|
+
const s = createMacroTask(() => {
|
|
273
|
+
const e3 = performance.now() + yieldInterval;
|
|
274
|
+
while (n2 < t2.length) {
|
|
275
|
+
const [o, r] = t2[n2];
|
|
276
|
+
n2++;
|
|
277
|
+
adjustProbabilities(o, r);
|
|
278
|
+
if (n2 < t2.length && performance.now() >= e3) {
|
|
279
|
+
s();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
nextTriggerMacroTask();
|
|
284
|
+
});
|
|
285
|
+
s();
|
|
188
286
|
}).catch(console.warn);
|
|
189
287
|
};
|
|
190
288
|
export {
|