@qwik.dev/router 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.
Files changed (48) hide show
  1. package/lib/adapters/azure-swa/vite/index.cjs +3 -3
  2. package/lib/adapters/azure-swa/vite/index.d.ts +13 -13
  3. package/lib/adapters/bun-server/vite/index.cjs +3 -3
  4. package/lib/adapters/bun-server/vite/index.d.ts +14 -14
  5. package/lib/adapters/cloud-run/vite/index.cjs +3 -3
  6. package/lib/adapters/cloud-run/vite/index.d.ts +13 -13
  7. package/lib/adapters/cloudflare-pages/vite/index.cjs +3 -3
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +27 -27
  9. package/lib/adapters/deno-server/vite/index.cjs +3 -3
  10. package/lib/adapters/deno-server/vite/index.d.ts +14 -14
  11. package/lib/adapters/netlify-edge/vite/index.cjs +3 -3
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +44 -44
  13. package/lib/adapters/node-server/vite/index.cjs +3 -3
  14. package/lib/adapters/node-server/vite/index.d.ts +14 -14
  15. package/lib/adapters/shared/vite/index.cjs +10 -3
  16. package/lib/adapters/shared/vite/index.d.ts +114 -114
  17. package/lib/adapters/shared/vite/index.mjs +7 -0
  18. package/lib/adapters/static/vite/index.cjs +10 -3
  19. package/lib/adapters/static/vite/index.d.ts +10 -10
  20. package/lib/adapters/static/vite/index.mjs +7 -0
  21. package/lib/adapters/vercel-edge/vite/index.cjs +3 -3
  22. package/lib/adapters/vercel-edge/vite/index.d.ts +45 -45
  23. package/lib/index.d.ts +878 -801
  24. package/lib/index.qwik.cjs +84 -84
  25. package/lib/index.qwik.mjs +64 -64
  26. package/lib/middleware/aws-lambda/index.d.ts +48 -50
  27. package/lib/middleware/azure-swa/index.d.ts +28 -28
  28. package/lib/middleware/bun/index.d.ts +35 -35
  29. package/lib/middleware/cloudflare-pages/index.d.ts +35 -35
  30. package/lib/middleware/deno/index.d.ts +47 -47
  31. package/lib/middleware/firebase/index.d.ts +26 -26
  32. package/lib/middleware/netlify-edge/index.d.ts +27 -27
  33. package/lib/middleware/node/index.cjs +3 -3
  34. package/lib/middleware/node/index.d.ts +64 -66
  35. package/lib/middleware/request-handler/index.cjs +37 -38
  36. package/lib/middleware/request-handler/index.d.ts +676 -681
  37. package/lib/middleware/request-handler/index.mjs +34 -35
  38. package/lib/middleware/vercel-edge/index.d.ts +26 -26
  39. package/lib/service-worker.cjs +13 -263
  40. package/lib/service-worker.d.ts +15 -4
  41. package/lib/service-worker.mjs +13 -263
  42. package/lib/static/index.cjs +3 -3
  43. package/lib/static/index.d.ts +96 -98
  44. package/lib/static/node.cjs +3 -3
  45. package/lib/vite/index.cjs +129 -247
  46. package/lib/vite/index.d.ts +154 -154
  47. package/lib/vite/index.mjs +127 -245
  48. package/package.json +10 -9
@@ -1,265 +1,15 @@
1
- const getCacheToDelete = (appBundles, cachedUrls) => cachedUrls.filter((url) => !appBundles.some((appBundle) => url.endsWith(appBundle[0])));
2
- const useCache = (request, response) => !!response && !hasNoCacheHeader(response);
3
- const hasNoCacheHeader = (r) => {
4
- const cacheControl = r.headers.get('Cache-Control') || '';
5
- return cacheControl.includes('no-cache') || cacheControl.includes('max-age=0');
6
- };
7
- const isAppBundleRequest = (appBundles, requestPathname) => appBundles.some((b) => requestPathname.endsWith('/' + b[0]));
8
- const getAppBundleByName = (appBundles, appBundleName) => appBundles.find((b) => b[0] === appBundleName);
9
- const getAppBundlesNamesFromIds = (appBundles, bundleIds) => bundleIds.map((bundleId) => (appBundles[bundleId] ? appBundles[bundleId][0] : null));
10
- const resolveSymbols = (appSymbols, symbolsHashes) => symbolsHashes.map((s) => appSymbols.get(s)).filter((s) => s != null);
11
- const computeAppSymbols = (appBundles) => {
12
- const appSymbols = new Map();
13
- for (const bundle of appBundles) {
14
- const hashes = bundle[2];
15
- if (hashes) {
16
- for (const hash of hashes) {
17
- appSymbols.set(hash, bundle[0]);
18
- }
19
- }
20
- }
21
- return appSymbols;
22
- };
23
-
24
- const cachedFetch = (cache, fetch, awaitingRequests, request) => new Promise((promiseResolve, promiseReject) => {
25
- const url = request.url;
26
- const awaitingRequestResolves = awaitingRequests.get(url);
27
- if (awaitingRequestResolves) {
28
- // there's already an active request happening
29
- // don't start a new request
30
- awaitingRequestResolves.push([promiseResolve, promiseReject]);
31
- }
32
- else {
33
- // there isn't already an active request for this url
34
- // start a new request
35
- const resolve = (response) => {
36
- // the response has been resolved
37
- const resolves = awaitingRequests.get(url);
38
- if (resolves) {
39
- awaitingRequests.delete(url);
40
- // loop through each of the active requests
41
- for (const [awaitingResolve] of resolves) {
42
- // clone a new response for each of the active requests
43
- awaitingResolve(response.clone());
44
- }
45
- }
46
- else {
47
- // somehow the array of awaiting requests doesn't exist
48
- promiseResolve(response.clone());
49
- }
50
- };
51
- const reject = (msg) => {
52
- const resolves = awaitingRequests.get(url);
53
- if (resolves) {
54
- awaitingRequests.delete(url);
55
- for (const [_, awaitingReject] of resolves) {
56
- awaitingReject(msg);
57
- }
58
- }
59
- else {
60
- promiseReject(msg);
61
- }
62
- };
63
- // create a new array of the request waiting to be resolved
64
- awaitingRequests.set(url, [[promiseResolve, promiseReject]]);
65
- cache
66
- .match(url)
67
- .then((cachedResponse) => {
68
- if (useCache(request, cachedResponse)) {
69
- // cached response found and user did not specifically send
70
- // a request header to NOT use the cache (wasn't a hard refresh)
71
- resolve(cachedResponse);
72
- }
73
- else {
74
- // no cached response found or user didn't want to use the cache
75
- // do a full network request
76
- return fetch(request).then(async (networkResponse) => {
77
- if (networkResponse.ok) {
78
- // network response was good, let's cache it
79
- await cache.put(url, networkResponse.clone());
80
- }
81
- resolve(networkResponse);
82
- });
83
- }
84
- })
85
- .catch((err) => {
86
- // network error, probably offline
87
- return cache.match(url).then((cachedResponse) => {
88
- if (cachedResponse) {
89
- // luckily we have a cached version, let's use it instead of an offline message
90
- resolve(cachedResponse);
91
- }
92
- else {
93
- // darn, we've got no connectivity and no cached response
94
- reject(err);
95
- }
96
- });
97
- });
98
- }
99
- });
100
-
101
- const qBuildCacheName = 'QwikBuild';
102
- const existingPrefetchUrls = new Set();
103
- const awaitingRequests = new Map();
104
- const prefetchQueue = [];
105
-
106
- const prefetchBundleNames = (appBundles, qBuildCache, fetch, baseUrl, prefetchAppBundleNames, highPriority = false) => {
107
- if (Array.isArray(prefetchAppBundleNames)) {
108
- addBundlesToPrefetchQueue(prefetchAppBundleNames, appBundles, baseUrl, highPriority);
109
- }
110
- drainQueue(qBuildCache, fetch);
111
- };
112
- function addBundlesToPrefetchQueue(bundlesToPrefetch, appBundles, baseUrl, highPriority) {
113
- for (const prefetchAppBundleName of bundlesToPrefetch) {
114
- try {
115
- const appBundle = getAppBundleByName(appBundles, prefetchAppBundleName);
116
- if (appBundle) {
117
- const importedBundleNames = getAppBundlesNamesFromIds(appBundles, appBundle[1]);
118
- const url = new URL(prefetchAppBundleName, baseUrl).href;
119
- const queueIndex = prefetchQueue.indexOf(url);
120
- if (queueIndex > -1) {
121
- // already in the queue
122
- if (highPriority) {
123
- // move to the front of the queue
124
- prefetchQueue.splice(queueIndex, 1);
125
- prefetchQueue.unshift(url);
126
- }
127
- }
128
- else {
129
- if (highPriority) {
130
- // add to the front of the queue
131
- prefetchQueue.unshift(url);
132
- }
133
- else {
134
- // add to the end of the queue
135
- prefetchQueue.push(url);
136
- }
137
- addBundlesToPrefetchQueue(importedBundleNames, appBundles, baseUrl, highPriority);
138
- }
139
- }
140
- }
141
- catch (e) {
142
- console.error(e);
143
- }
144
- }
145
- }
146
- function drainQueue(qBuildCache, fetch) {
147
- // do not prefetch more than 6 requests at a time to ensure
148
- // the browser is able to handle a user request as soon as possible
149
- while (prefetchQueue.length > 0 && awaitingRequests.size < 6) {
150
- const url = prefetchQueue.shift();
151
- if (!existingPrefetchUrls.has(url)) {
152
- const request = new Request(url);
153
- existingPrefetchUrls.add(url);
154
- cachedFetch(qBuildCache, fetch, awaitingRequests, request)
155
- .catch(() => {
156
- existingPrefetchUrls.delete(url);
157
- })
158
- .finally(() => drainQueue(qBuildCache, fetch));
159
- }
160
- }
161
- }
162
- const prefetchLinkBundles = (appBundles, libraryBundleIds, linkBundles, qBuildCache, fetch, baseUrl, linkPathnames) => {
163
- try {
164
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, libraryBundleIds));
165
- }
166
- catch (e) {
167
- console.error(e);
168
- }
169
- for (const linkPathname of linkPathnames) {
170
- try {
171
- for (const linkBundle of linkBundles) {
172
- const [route, linkBundleIds] = linkBundle;
173
- console;
174
- if (route.test(linkPathname)) {
175
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, linkBundleIds));
176
- break;
177
- }
178
- }
179
- }
180
- catch (e) {
181
- console.error(e);
182
- }
183
- }
184
- };
185
- const prefetchWaterfall = (appBundles, qBuildCache, fetch, requestedBuildUrl) => {
186
- try {
187
- const { baseUrl, requestedBundleName } = splitUrlToBaseAndBundle(requestedBuildUrl);
188
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, [requestedBundleName], true);
189
- }
190
- catch (e) {
191
- console.error(e);
192
- }
193
- };
194
- function splitUrlToBaseAndBundle(fullUrl) {
195
- const segments = fullUrl.href.split('/');
196
- const requestedBundleName = segments[segments.length - 1];
197
- segments[segments.length - 1] = '';
198
- const baseUrl = new URL(segments.join('/'));
199
- return {
200
- baseUrl,
201
- requestedBundleName,
202
- };
203
- }
204
-
205
- const setupServiceWorkerScope = (swScope, appBundles, libraryBundleIds, linkBundles) => {
206
- const swFetch = swScope.fetch.bind(swScope);
207
- const appSymbols = computeAppSymbols(appBundles);
208
- swScope.addEventListener('activate', (event) => {
209
- (async () => {
210
- try {
211
- // Delete any other caches that are not the current SW cache name
212
- event.waitUntil(swScope.caches.keys().then((keys) => Promise.all(keys.map((key) => {
213
- if (key !== qBuildCacheName) {
214
- return caches.delete(key);
215
- }
216
- }))));
217
- // Delete old bundles
218
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
219
- const cachedRequestKeys = await qBuildCache.keys();
220
- const cachedUrls = cachedRequestKeys.map((r) => r.url);
221
- const cachedRequestsToDelete = getCacheToDelete(appBundles, cachedUrls);
222
- await Promise.all(cachedRequestsToDelete.map((r) => qBuildCache.delete(r)));
223
- }
224
- catch (e) {
225
- console.error(e);
226
- }
227
- })();
228
- });
229
- swScope.addEventListener('message', async ({ data }) => {
230
- if (data.type === 'qprefetch' && typeof data.base === 'string') {
231
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
232
- const baseUrl = new URL(data.base, swScope.origin);
233
- if (Array.isArray(data.links)) {
234
- prefetchLinkBundles(appBundles, libraryBundleIds, linkBundles, qBuildCache, swFetch, baseUrl, data.links);
235
- }
236
- if (Array.isArray(data.bundles)) {
237
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, data.bundles);
238
- }
239
- if (Array.isArray(data.symbols)) {
240
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, resolveSymbols(appSymbols, data.symbols));
241
- }
242
- }
243
- });
244
- swScope.addEventListener('fetch', (event) => {
245
- const request = event.request;
246
- if (request.method === 'GET') {
247
- const url = new URL(request.url);
248
- if (isAppBundleRequest(appBundles, url.pathname)) {
249
- event.respondWith(swScope.caches.open(qBuildCacheName).then((qBuildCache) => {
250
- prefetchWaterfall(appBundles, qBuildCache, swFetch, url);
251
- return cachedFetch(qBuildCache, swFetch, awaitingRequests, request);
252
- }));
253
- }
254
- }
255
- });
256
- };
257
-
258
- /** @public */
259
- const setupServiceWorker = () => {
260
- if (typeof self !== 'undefined' && typeof appBundles !== 'undefined') {
261
- setupServiceWorkerScope(self, appBundles, libraryBundleIds, linkBundles);
262
- }
263
- };
1
+ /**
2
+ * @deprecated This is no longer needed, Qwik now automatically embeds preloading logic into the
3
+ * application.
4
+ *
5
+ * If your service-worker.ts file contains no custom code, you should deploy to production until
6
+ * you're sure that all users picked up the new version, then you can remove it and also remove
7
+ * the `<ServiceWorkerRegister />` component from your `Root.tsx`.
8
+ *
9
+ * If you do have custom service worker logic, you should keep the `service-worker.ts` file and
10
+ * `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
11
+ * @public
12
+ */
13
+ const setupServiceWorker = () => { };
264
14
 
265
15
  export { setupServiceWorker };
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // packages/qwik-router/src/static/index.ts
21
- var static_exports = {};
22
- __export(static_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  generate: () => generate
24
24
  });
25
- module.exports = __toCommonJS(static_exports);
25
+ module.exports = __toCommonJS(index_exports);
26
26
  async function generate(opts) {
27
27
  const ssgPlatform = await getEntryModule();
28
28
  const result = await ssgPlatform.generate(opts);
@@ -1,98 +1,96 @@
1
- /// <reference types="node" />
2
-
3
- import type { RenderOptions } from '@qwik.dev/core/server';
4
-
5
- /**
6
- * Use this function when SSG should be generated from another module, such as a Vite plugin. This
7
- * function's should be passed the paths of the entry module and Qwik Router Plan.
8
- *
9
- * @public
10
- */
11
- export declare function generate(opts: StaticGenerateOptions): Promise<StaticGenerateResult>;
12
-
13
- /** @public */
14
- export declare interface StaticGenerateOptions extends StaticGenerateRenderOptions {
15
- /**
16
- * Path to the SSR module exporting the default render function. In most cases it'll be
17
- * `./src/entry.ssr.tsx`.
18
- */
19
- renderModulePath: string;
20
- /** Path to the Qwik Router Config module exporting the default `@qwik-router-config`. */
21
- qwikRouterConfigModulePath: string;
22
- /** @deprecated Use `qwikRouterConfigModulePath` instead. Will be removed in V3 */
23
- qwikCityPlanModulePath?: string;
24
- /** Defaults to `/` */
25
- basePathname?: string;
26
- rootDir?: string;
27
- }
28
-
29
- /** @public */
30
- export declare interface StaticGenerateRenderOptions extends RenderOptions {
31
- /** File system directory where the static files should be written. */
32
- outDir: string;
33
- /**
34
- * The URL `origin`, which is a combination of the scheme (protocol) and hostname (domain). For
35
- * example, `https://qwik.dev` has the protocol `https://` and domain `qwik.dev`. However, the
36
- * `origin` does not include a `pathname`.
37
- *
38
- * The `origin` is used to provide a full URL during Static Site Generation (SSG), and to simulate
39
- * a complete URL rather than just the `pathname`. For example, in order to render a correct
40
- * canonical tag URL or URLs within the `sitemap.xml`, the `origin` must be provided too.
41
- *
42
- * If the site also starts with a pathname other than `/`, please use the `basePathname` option in
43
- * the Qwik Router config options.
44
- */
45
- origin: string;
46
- /**
47
- * Maximum number of workers to use while generating the static pages. Defaults to the number of
48
- * CPUs available.
49
- */
50
- maxWorkers?: number;
51
- /** Maximum number of tasks to be running at one time per worker. Defaults to `20`. */
52
- maxTasksPerWorker?: number;
53
- /**
54
- * File system path to write the `sitemap.xml` to. Defaults to `sitemap.xml` and written to the
55
- * root of the `outDir`. Setting to `null` will prevent the sitemap from being created.
56
- */
57
- sitemapOutFile?: string | null;
58
- /** Log level. */
59
- log?: 'debug';
60
- /**
61
- * Set to `false` if the generated static HTML files should not be written to disk. Setting to
62
- * `false` is useful if the SSG should only write the `q-data.json` files to disk. Defaults to
63
- * `true`.
64
- */
65
- emitHtml?: boolean;
66
- /**
67
- * Set to `false` if the generated `q-data.json` data files should not be written to disk.
68
- * Defaults to `true`.
69
- */
70
- emitData?: boolean;
71
- /**
72
- * Set to `false` if the static build should not write custom or default `404.html` pages.
73
- * Defaults to `true`.
74
- */
75
- emit404Pages?: boolean;
76
- /**
77
- * Defines file system routes relative to the source `routes` directory that should be static
78
- * generated. Accepts wildcard behavior. This should not include the "base" pathname. If not
79
- * provided, all routes will be static generated. `exclude` always takes priority over `include`.
80
- */
81
- include?: string[];
82
- /**
83
- * Defines file system routes relative to the source `routes` directory that should not be static
84
- * generated. Accepts wildcard behavior. This should not include the "base" pathname. `exclude`
85
- * always takes priority over `include`.
86
- */
87
- exclude?: string[];
88
- }
89
-
90
- /** @public */
91
- export declare interface StaticGenerateResult {
92
- duration: number;
93
- rendered: number;
94
- errors: number;
95
- staticPaths: string[];
96
- }
97
-
98
- export { }
1
+ import type { RenderOptions } from '@qwik.dev/core/server';
2
+
3
+ /**
4
+ * Use this function when SSG should be generated from another module, such as a Vite plugin. This
5
+ * function's should be passed the paths of the entry module and Qwik Router Plan.
6
+ *
7
+ * @public
8
+ */
9
+ export declare function generate(opts: StaticGenerateOptions): Promise<StaticGenerateResult>;
10
+
11
+ /** @public */
12
+ export declare interface StaticGenerateOptions extends StaticGenerateRenderOptions {
13
+ /**
14
+ * Path to the SSR module exporting the default render function. In most cases it'll be
15
+ * `./src/entry.ssr.tsx`.
16
+ */
17
+ renderModulePath: string;
18
+ /** Path to the Qwik Router Config module exporting the default `@qwik-router-config`. */
19
+ qwikRouterConfigModulePath: string;
20
+ /** @deprecated Use `qwikRouterConfigModulePath` instead. Will be removed in V3 */
21
+ qwikCityPlanModulePath?: string;
22
+ /** Defaults to `/` */
23
+ basePathname?: string;
24
+ rootDir?: string;
25
+ }
26
+
27
+ /** @public */
28
+ export declare interface StaticGenerateRenderOptions extends RenderOptions {
29
+ /** File system directory where the static files should be written. */
30
+ outDir: string;
31
+ /**
32
+ * The URL `origin`, which is a combination of the scheme (protocol) and hostname (domain). For
33
+ * example, `https://qwik.dev` has the protocol `https://` and domain `qwik.dev`. However, the
34
+ * `origin` does not include a `pathname`.
35
+ *
36
+ * The `origin` is used to provide a full URL during Static Site Generation (SSG), and to simulate
37
+ * a complete URL rather than just the `pathname`. For example, in order to render a correct
38
+ * canonical tag URL or URLs within the `sitemap.xml`, the `origin` must be provided too.
39
+ *
40
+ * If the site also starts with a pathname other than `/`, please use the `basePathname` option in
41
+ * the Qwik Router config options.
42
+ */
43
+ origin: string;
44
+ /**
45
+ * Maximum number of workers to use while generating the static pages. Defaults to the number of
46
+ * CPUs available.
47
+ */
48
+ maxWorkers?: number;
49
+ /** Maximum number of tasks to be running at one time per worker. Defaults to `20`. */
50
+ maxTasksPerWorker?: number;
51
+ /**
52
+ * File system path to write the `sitemap.xml` to. Defaults to `sitemap.xml` and written to the
53
+ * root of the `outDir`. Setting to `null` will prevent the sitemap from being created.
54
+ */
55
+ sitemapOutFile?: string | null;
56
+ /** Log level. */
57
+ log?: 'debug';
58
+ /**
59
+ * Set to `false` if the generated static HTML files should not be written to disk. Setting to
60
+ * `false` is useful if the SSG should only write the `q-data.json` files to disk. Defaults to
61
+ * `true`.
62
+ */
63
+ emitHtml?: boolean;
64
+ /**
65
+ * Set to `false` if the generated `q-data.json` data files should not be written to disk.
66
+ * Defaults to `true`.
67
+ */
68
+ emitData?: boolean;
69
+ /**
70
+ * Set to `false` if the static build should not write custom or default `404.html` pages.
71
+ * Defaults to `true`.
72
+ */
73
+ emit404Pages?: boolean;
74
+ /**
75
+ * Defines file system routes relative to the source `routes` directory that should be static
76
+ * generated. Accepts wildcard behavior. This should not include the "base" pathname. If not
77
+ * provided, all routes will be static generated. `exclude` always takes priority over `include`.
78
+ */
79
+ include?: string[];
80
+ /**
81
+ * Defines file system routes relative to the source `routes` directory that should not be static
82
+ * generated. Accepts wildcard behavior. This should not include the "base" pathname. `exclude`
83
+ * always takes priority over `include`.
84
+ */
85
+ exclude?: string[];
86
+ }
87
+
88
+ /** @public */
89
+ export declare interface StaticGenerateResult {
90
+ duration: number;
91
+ rendered: number;
92
+ errors: number;
93
+ staticPaths: string[];
94
+ }
95
+
96
+ export { }
@@ -28,11 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // packages/qwik-router/src/static/node/index.ts
31
- var node_exports = {};
32
- __export(node_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  generate: () => generate
34
34
  });
35
- module.exports = __toCommonJS(node_exports);
35
+ module.exports = __toCommonJS(index_exports);
36
36
 
37
37
  // packages/qwik-router/src/static/node/node-system.ts
38
38
  var import_node_fs2 = __toESM(require("node:fs"), 1);