@qwik.dev/router 2.0.0-beta.43 → 2.0.0-beta.45
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/lib/adapters/azure-swa/vite/index.mjs +2 -1
- package/lib/adapters/bun-server/vite/index.mjs +2 -1
- package/lib/adapters/cloud-run/vite/index.mjs +2 -1
- package/lib/adapters/cloudflare-pages/vite/index.mjs +2 -1
- package/lib/adapters/deno-server/vite/index.mjs +2 -1
- package/lib/adapters/netlify-edge/vite/index.mjs +2 -1
- package/lib/adapters/node-server/vite/index.mjs +2 -1
- package/lib/adapters/shared/vite/index.mjs +35 -31
- package/lib/adapters/ssg/vite/index.mjs +4 -2
- package/lib/adapters/vercel-edge/vite/index.mjs +18 -15
- package/lib/chunks/fs.mjs +26 -23
- package/lib/chunks/head.qwik.mjs +611 -445
- package/lib/chunks/http-error.qwik.mjs +8 -7
- package/lib/chunks/pathname.mjs +9 -8
- package/lib/chunks/request-path.mjs +8 -4
- package/lib/chunks/routes.mjs +14 -14
- package/lib/chunks/server-error.mjs +11 -5
- package/lib/chunks/{url.mjs → static-file.mjs} +12 -2
- package/lib/chunks/system.mjs +18 -17
- package/lib/chunks/user-response.mjs +419 -323
- package/lib/chunks/worker-thread.mjs +87 -86
- package/lib/index.d.ts +47 -59
- package/lib/index.qwik.mjs +550 -496
- package/lib/middleware/aws-lambda/index.mjs +6 -3
- package/lib/middleware/azure-swa/index.mjs +4 -2
- package/lib/middleware/bun/index.mjs +12 -12
- package/lib/middleware/cloudflare-pages/index.mjs +19 -4
- package/lib/middleware/deno/index.mjs +12 -12
- package/lib/middleware/firebase/index.mjs +4 -2
- package/lib/middleware/netlify-edge/index.mjs +4 -2
- package/lib/middleware/node/index.mjs +16 -15
- package/lib/middleware/request-handler/index.mjs +35 -24
- package/lib/middleware/vercel-edge/index.mjs +4 -2
- package/lib/service-worker/index.mjs +2 -1
- package/lib/ssg/index.mjs +20 -16
- package/lib/vite/index.d.ts +1 -1
- package/lib/vite/index.mjs +596 -586
- package/package.json +5 -5
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function azureSwaAdapter(opts = {}) {
|
|
5
6
|
const env = process?.env;
|
|
6
7
|
return viteAdapter({
|
|
7
8
|
name: "azure-swa",
|
|
@@ -3,7 +3,8 @@ import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
|
3
3
|
import { y as normalizePathSlash } from "../../../chunks/fs.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import { join, relative } from "node:path";
|
|
6
|
-
/** @public */
|
|
6
|
+
/** @public */
|
|
7
|
+
function cloudflarePagesAdapter(opts = {}) {
|
|
7
8
|
const env = process?.env;
|
|
8
9
|
return viteAdapter({
|
|
9
10
|
name: "cloudflare-pages",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getParentDir, viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
2
|
import fs, { existsSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function netlifyEdgeAdapter(opts = {}) {
|
|
5
6
|
const env = process?.env;
|
|
6
7
|
return viteAdapter({
|
|
7
8
|
name: "netlify-edge",
|
|
@@ -4,34 +4,8 @@ import fs from "node:fs";
|
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { readFile, rm, unlink } from "node:fs/promises";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
var injectStatics = async (staticPathsCode, outDir) => {
|
|
11
|
-
const promises = /* @__PURE__ */ new Set();
|
|
12
|
-
const doReplace = async (path) => {
|
|
13
|
-
const code = await fs.promises.readFile(path, "utf-8");
|
|
14
|
-
let replaced = false;
|
|
15
|
-
const newCode = code.replace(/(['"`])__QWIK_ROUTER_STATIC_PATHS_ARRAY__\1/g, () => {
|
|
16
|
-
replaced = true;
|
|
17
|
-
return staticPathsCode;
|
|
18
|
-
});
|
|
19
|
-
if (replaced) await fs.promises.writeFile(path, newCode);
|
|
20
|
-
};
|
|
21
|
-
const walk = async (dir) => {
|
|
22
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
23
|
-
for (const entry of entries) if (entry.isDirectory()) await walk(join(dir, entry.name));
|
|
24
|
-
else if (entry.name.endsWith("js")) {
|
|
25
|
-
const p = doReplace(join(dir, entry.name)).finally(() => {
|
|
26
|
-
promises.delete(p);
|
|
27
|
-
});
|
|
28
|
-
promises.add(p);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
await walk(outDir);
|
|
32
|
-
await Promise.all(promises);
|
|
33
|
-
};
|
|
34
|
-
/** Cleans the client output SSG results if needed and injects the SSG metadata into the build output */ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic, noTrailingSlash) {
|
|
7
|
+
/** Cleans the client output SSG results if needed and injects the SSG metadata into the build output */
|
|
8
|
+
async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic, noTrailingSlash) {
|
|
35
9
|
if (pathName && !pathName.endsWith("/")) pathName = ensureSlash(pathName);
|
|
36
10
|
const pathNameBase = pathName || "/";
|
|
37
11
|
const ignorePathnames = /* @__PURE__ */ new Set([pathNameBase + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/", pathNameBase + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"]);
|
|
@@ -66,17 +40,46 @@ var injectStatics = async (staticPathsCode, outDir) => {
|
|
|
66
40
|
if (fs.existsSync(clientOutDir)) await loadDir(clientOutDir, pathName);
|
|
67
41
|
await injectStatics(createStaticPathsCode(staticPaths), serverOutDir);
|
|
68
42
|
}
|
|
43
|
+
function createStaticPathsCode(staticPaths) {
|
|
44
|
+
return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
|
|
45
|
+
}
|
|
46
|
+
var injectStatics = async (staticPathsCode, outDir) => {
|
|
47
|
+
const promises = /* @__PURE__ */ new Set();
|
|
48
|
+
const doReplace = async (path) => {
|
|
49
|
+
const code = await fs.promises.readFile(path, "utf-8");
|
|
50
|
+
let replaced = false;
|
|
51
|
+
const newCode = code.replace(/(['"`])__QWIK_ROUTER_STATIC_PATHS_ARRAY__\1/g, () => {
|
|
52
|
+
replaced = true;
|
|
53
|
+
return staticPathsCode;
|
|
54
|
+
});
|
|
55
|
+
if (replaced) await fs.promises.writeFile(path, newCode);
|
|
56
|
+
};
|
|
57
|
+
const walk = async (dir) => {
|
|
58
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
59
|
+
for (const entry of entries) if (entry.isDirectory()) await walk(join(dir, entry.name));
|
|
60
|
+
else if (entry.name.endsWith("js")) {
|
|
61
|
+
const p = doReplace(join(dir, entry.name)).finally(() => {
|
|
62
|
+
promises.delete(p);
|
|
63
|
+
});
|
|
64
|
+
promises.add(p);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
await walk(outDir);
|
|
68
|
+
await Promise.all(promises);
|
|
69
|
+
};
|
|
69
70
|
/**
|
|
70
71
|
* Implements the SSG after the build is complete. Also provides a `generate(...)` callback that is
|
|
71
72
|
* called after the SSG is complete, which allows for custom post-processing of the complete build
|
|
72
73
|
* results.
|
|
73
74
|
*
|
|
74
75
|
* @public
|
|
75
|
-
*/
|
|
76
|
+
*/
|
|
77
|
+
var QWIK_SSG_ENTRY_ID = "@qwik-ssg-entry";
|
|
76
78
|
var QWIK_SSG_ENTRY_RESOLVED = "\0@qwik-ssg-entry";
|
|
77
79
|
var QWIK_SSG_WORKER_ENTRY_ID = "@qwik-ssg-worker-entry";
|
|
78
80
|
var QWIK_SSG_WORKER_ENTRY_RESOLVED = "\0@qwik-ssg-worker-entry";
|
|
79
|
-
/** @public */
|
|
81
|
+
/** @public */
|
|
82
|
+
function viteAdapter(opts) {
|
|
80
83
|
let qwikRouterPlugin = null;
|
|
81
84
|
let qwikVitePlugin = null;
|
|
82
85
|
let viteCommand;
|
|
@@ -272,7 +275,8 @@ var QWIK_SSG_WORKER_ENTRY_RESOLVED = "\0@qwik-ssg-worker-entry";
|
|
|
272
275
|
}
|
|
273
276
|
}];
|
|
274
277
|
}
|
|
275
|
-
/** @public */
|
|
278
|
+
/** @public */
|
|
279
|
+
function getParentDir(startDir, dirName) {
|
|
276
280
|
const root = resolve("/");
|
|
277
281
|
let dir = startDir;
|
|
278
282
|
for (let i = 0; i < 20; i++) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
|
-
/** @public */
|
|
2
|
+
/** @public */
|
|
3
|
+
function ssgAdapter(opts) {
|
|
3
4
|
return viteAdapter({
|
|
4
5
|
name: "static-site-generation",
|
|
5
6
|
origin: opts.origin,
|
|
@@ -9,5 +10,6 @@ import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
|
9
10
|
}
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
/** @public @deprecated Use `ssgAdapter` instead. */
|
|
13
|
+
/** @public @deprecated Use `ssgAdapter` instead. */
|
|
14
|
+
var staticAdapter = ssgAdapter;
|
|
13
15
|
export { ssgAdapter, staticAdapter };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getParentDir, viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
/** @public */
|
|
4
|
+
/** @public */
|
|
5
|
+
function vercelEdgeAdapter(opts = {}) {
|
|
5
6
|
return viteAdapter({
|
|
6
7
|
name: "vercel-edge",
|
|
7
8
|
origin: process?.env?.VERCEL_URL || "https://yoursitename.vercel.app",
|
|
@@ -10,22 +11,24 @@ import { dirname, join } from "node:path";
|
|
|
10
11
|
cleanStaticGenerated: true,
|
|
11
12
|
config(config) {
|
|
12
13
|
const outDir = config.build?.outDir || join(".vercel", "output", "functions", "_qwik-router.func");
|
|
14
|
+
const conditions = opts.target === "node" ? [
|
|
15
|
+
"node",
|
|
16
|
+
"import",
|
|
17
|
+
"module",
|
|
18
|
+
"browser",
|
|
19
|
+
"default"
|
|
20
|
+
] : [
|
|
21
|
+
"edge-light",
|
|
22
|
+
"webworker",
|
|
23
|
+
"worker",
|
|
24
|
+
"browser",
|
|
25
|
+
"module",
|
|
26
|
+
"main"
|
|
27
|
+
];
|
|
13
28
|
return {
|
|
14
|
-
resolve: { conditions
|
|
15
|
-
"node",
|
|
16
|
-
"import",
|
|
17
|
-
"module",
|
|
18
|
-
"browser",
|
|
19
|
-
"default"
|
|
20
|
-
] : [
|
|
21
|
-
"edge-light",
|
|
22
|
-
"webworker",
|
|
23
|
-
"worker",
|
|
24
|
-
"browser",
|
|
25
|
-
"module",
|
|
26
|
-
"main"
|
|
27
|
-
] },
|
|
29
|
+
resolve: { conditions },
|
|
28
30
|
ssr: {
|
|
31
|
+
resolve: { conditions },
|
|
29
32
|
target: opts.target === "node" ? "node" : "webworker",
|
|
30
33
|
noExternal: true
|
|
31
34
|
},
|
package/lib/chunks/fs.mjs
CHANGED
|
@@ -15,6 +15,18 @@ function parseRouteIndexName(extlessName) {
|
|
|
15
15
|
layoutStop
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
function getPathnameFromDirPath(opts, dirPath) {
|
|
19
|
+
let pathname = normalizePath(relative(opts.routesDir, dirPath));
|
|
20
|
+
pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
|
|
21
|
+
if (pathname === "") return "/";
|
|
22
|
+
return pathname;
|
|
23
|
+
}
|
|
24
|
+
function getMenuPathname(opts, filePath) {
|
|
25
|
+
let pathname = normalizePath(relative(opts.routesDir, filePath));
|
|
26
|
+
pathname = `/` + normalizePath(dirname(pathname));
|
|
27
|
+
const result = normalizePathname(pathname, opts.basePathname);
|
|
28
|
+
return ensureSlash(result);
|
|
29
|
+
}
|
|
18
30
|
function getExtension(fileName) {
|
|
19
31
|
if (typeof fileName === "string") {
|
|
20
32
|
const parts = fileName.trim().toLowerCase().split(".");
|
|
@@ -34,30 +46,25 @@ function removeExtension(fileName) {
|
|
|
34
46
|
}
|
|
35
47
|
return "";
|
|
36
48
|
}
|
|
37
|
-
function normalizePathSlash(path) {
|
|
38
|
-
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
39
|
-
const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
|
|
40
|
-
if (isExtendedLengthPath || hasNonAscii) return path;
|
|
41
|
-
path = path.replace(/\\/g, "/");
|
|
42
|
-
if (path.endsWith("/")) path = path.slice(0, path.length - 1);
|
|
43
|
-
return path;
|
|
44
|
-
}
|
|
45
49
|
function normalizePath(path) {
|
|
46
50
|
return normalizePathSlash(normalize(path));
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pathname = `/` + normalizePath(dirname(pathname));
|
|
51
|
-
const result = normalizePathname(pathname, opts.basePathname);
|
|
52
|
-
return ensureSlash(result);
|
|
53
|
-
}
|
|
54
|
-
/** Normalize equivalent filesystem paths for string-key comparisons. */ function normalizePathKey(path) {
|
|
52
|
+
/** Normalize equivalent filesystem paths for string-key comparisons. */
|
|
53
|
+
function normalizePathKey(path) {
|
|
55
54
|
if (path.startsWith("\\\\?\\UNC\\")) path = `\\\\${path.slice(8)}`;
|
|
56
55
|
else if (path.startsWith("\\\\?\\")) path = path.slice(4);
|
|
57
56
|
else if (path.startsWith("//?/UNC/")) path = `//${path.slice(8)}`;
|
|
58
57
|
else if (path.startsWith("//?/")) path = path.slice(4);
|
|
59
58
|
return normalizePath(path).replace(/\\/g, "/");
|
|
60
59
|
}
|
|
60
|
+
function normalizePathSlash(path) {
|
|
61
|
+
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
62
|
+
const hasNonAscii = /[^\u0000-\u0080]+/.test(path);
|
|
63
|
+
if (isExtendedLengthPath || hasNonAscii) return path;
|
|
64
|
+
path = path.replace(/\\/g, "/");
|
|
65
|
+
if (path.endsWith("/")) path = path.slice(0, path.length - 1);
|
|
66
|
+
return path;
|
|
67
|
+
}
|
|
61
68
|
/**
|
|
62
69
|
* Creates an id for the module, based on its path.
|
|
63
70
|
*
|
|
@@ -65,7 +72,8 @@ function getMenuPathname(opts, filePath) {
|
|
|
65
72
|
* @param fsPath
|
|
66
73
|
* @param explicitFileType Add to avoid collisions between different types of modules. `Menu` and
|
|
67
74
|
* `Layout` files are named based on their path (eg. /routes/about/menu.md => AboutMenu)
|
|
68
|
-
*/
|
|
75
|
+
*/
|
|
76
|
+
function createFileId(routesDir, fsPath, explicitFileType) {
|
|
69
77
|
const ids = [];
|
|
70
78
|
for (let i = 0; i < 25; i++) {
|
|
71
79
|
let baseName = removeExtension(basename(fsPath));
|
|
@@ -121,7 +129,8 @@ function isServiceWorkerName(extlessName) {
|
|
|
121
129
|
function isEntryName(extlessName) {
|
|
122
130
|
return extlessName === "entry";
|
|
123
131
|
}
|
|
124
|
-
/** The boundary kind, ignoring any `@x`/`!` modifier: `'404'`, `'error'`, or undefined. */
|
|
132
|
+
/** The boundary kind, ignoring any `@x`/`!` modifier: `'404'`, `'error'`, or undefined. */
|
|
133
|
+
function errorBoundaryName(extlessName) {
|
|
125
134
|
const match = /^(error|404)(?:|!|@.+)$/.exec(extlessName);
|
|
126
135
|
return match ? match[1] : void 0;
|
|
127
136
|
}
|
|
@@ -131,10 +140,4 @@ function isErrorName(extlessName) {
|
|
|
131
140
|
function isGroupedLayoutName(dirName, warn = true) {
|
|
132
141
|
return dirName.startsWith("(") && dirName.endsWith(")");
|
|
133
142
|
}
|
|
134
|
-
function getPathnameFromDirPath(opts, dirPath) {
|
|
135
|
-
let pathname = normalizePath(relative(opts.routesDir, dirPath));
|
|
136
|
-
pathname = normalizePathname(pathname, opts.basePathname).split("/").filter((segment) => !isGroupedLayoutName(segment)).join("/");
|
|
137
|
-
if (pathname === "") return "/";
|
|
138
|
-
return pathname;
|
|
139
|
-
}
|
|
140
143
|
export { normalizePath as _, getPathnameFromDirPath as a, parseRouteIndexName as b, isIndexModule as c, isMenuFileName as d, isModuleExt as f, isServiceWorkerName as g, isPluginModule as h, getMenuPathname as i, isLayoutModule as l, isPageModuleExt as m, errorBoundaryName as n, isEntryName as o, isPageExt as p, getExtension as r, isErrorName as s, createFileId as t, isMarkdownExt as u, normalizePathKey as v, removeExtension as x, normalizePathSlash as y };
|