@qwik.dev/router 2.0.0-beta.9 → 2.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +44 -57
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +16 -22
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +15 -19
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +45 -76
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +25 -34
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +49 -89
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +16 -22
- package/lib/adapters/shared/vite/index.d.ts +9 -16
- package/lib/adapters/shared/vite/index.mjs +280 -293
- package/lib/adapters/ssg/vite/index.d.ts +1 -1
- package/lib/adapters/ssg/vite/index.mjs +13 -299
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +75 -79
- package/lib/chunks/dev-preloaded-route-loader.mjs +2 -0
- package/lib/chunks/format.mjs +24 -0
- package/lib/chunks/fs.mjs +143 -0
- package/lib/chunks/head.qwik.mjs +1570 -0
- package/lib/chunks/http-error.qwik.mjs +28 -0
- package/lib/chunks/pathname.mjs +58 -0
- package/lib/chunks/request-body-limit.mjs +27 -0
- package/lib/chunks/request-path.mjs +53 -0
- package/lib/chunks/route-trie-key.mjs +10 -0
- package/lib/chunks/routes.mjs +26 -0
- package/lib/chunks/server-error.mjs +38 -0
- package/lib/chunks/static-file.mjs +70 -0
- package/lib/chunks/system.mjs +271 -0
- package/lib/chunks/user-response.mjs +1883 -0
- package/lib/chunks/worker-thread.mjs +274 -0
- package/lib/index.d.ts +550 -182
- package/lib/index.qwik.mjs +1742 -2057
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +46 -50
- package/lib/middleware/azure-swa/index.mjs +85 -294
- package/lib/middleware/bun/index.d.ts +20 -5
- package/lib/middleware/bun/index.mjs +117 -201
- package/lib/middleware/cloudflare-pages/index.mjs +101 -101
- package/lib/middleware/deno/index.d.ts +22 -5
- package/lib/middleware/deno/index.mjs +103 -191
- package/lib/middleware/firebase/index.mjs +22 -31
- package/lib/middleware/netlify-edge/index.mjs +63 -80
- package/lib/middleware/node/index.d.ts +17 -5
- package/lib/middleware/node/index.mjs +298 -269
- package/lib/middleware/request-handler/index.d.ts +259 -58
- package/lib/middleware/request-handler/index.mjs +108 -1730
- package/lib/middleware/vercel-edge/index.mjs +76 -100
- package/lib/modules.d.ts +7 -4
- package/lib/service-worker/index.mjs +14 -0
- package/lib/ssg/index.d.ts +50 -26
- package/lib/ssg/index.mjs +257 -43
- package/lib/vite/index.d.ts +59 -11
- package/lib/vite/index.mjs +2533 -27535
- package/modules.d.ts +7 -4
- package/package.json +53 -70
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -130
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -338
- package/lib/adapters/ssg/vite/index.cjs +0 -339
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -2112
- package/lib/middleware/node/index.cjs +0 -310
- package/lib/middleware/request-handler/index.cjs +0 -1766
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/ssg/deno.mjs +0 -8
- package/lib/ssg/index.cjs +0 -67
- package/lib/ssg/node.cjs +0 -1128
- package/lib/ssg/node.mjs +0 -1090
- package/lib/vite/index.cjs +0 -27607
|
@@ -1,301 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// packages/qwik-router/src/adapters/shared/vite/post-build.ts
|
|
5
|
-
import { getErrorHtml } from "@qwik.dev/router/middleware/request-handler";
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
|
|
9
|
-
if (pathName && !pathName.endsWith("/")) {
|
|
10
|
-
pathName += "/";
|
|
11
|
-
}
|
|
12
|
-
const ignorePathnames = /* @__PURE__ */ new Set([
|
|
13
|
-
pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
|
|
14
|
-
pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
|
|
15
|
-
]);
|
|
16
|
-
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
|
|
17
|
-
const notFounds = [];
|
|
18
|
-
const loadItem = async (fsDir, fsName, pathname) => {
|
|
19
|
-
pathname = normalizeTrailingSlash(pathname);
|
|
20
|
-
if (ignorePathnames.has(pathname)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const fsPath = join(fsDir, fsName);
|
|
24
|
-
if (fsName === "index.html" || fsName === "q-data.json") {
|
|
25
|
-
if (!staticPaths.has(pathname) && cleanStatic) {
|
|
26
|
-
await fs.promises.unlink(fsPath);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (fsName === "404.html") {
|
|
31
|
-
const notFoundHtml = await fs.promises.readFile(fsPath, "utf-8");
|
|
32
|
-
notFounds.push([pathname, notFoundHtml]);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const stat = await fs.promises.stat(fsPath);
|
|
36
|
-
if (stat.isDirectory()) {
|
|
37
|
-
await loadDir(fsPath, pathname + fsName + "/");
|
|
38
|
-
} else if (stat.isFile()) {
|
|
39
|
-
staticPaths.add(pathname + fsName);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const loadDir = async (fsDir, pathname) => {
|
|
43
|
-
const itemNames = await fs.promises.readdir(fsDir);
|
|
44
|
-
await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname)));
|
|
45
|
-
};
|
|
46
|
-
if (fs.existsSync(clientOutDir)) {
|
|
47
|
-
await loadDir(clientOutDir, pathName);
|
|
48
|
-
}
|
|
49
|
-
const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
|
|
50
|
-
const staticPathsCode = createStaticPathsCode(staticPaths);
|
|
51
|
-
await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
|
|
52
|
-
}
|
|
53
|
-
function normalizeTrailingSlash(pathname) {
|
|
54
|
-
if (!pathname.endsWith("/")) {
|
|
55
|
-
return pathname + "/";
|
|
56
|
-
}
|
|
57
|
-
return pathname;
|
|
58
|
-
}
|
|
59
|
-
function createNotFoundPathsCode(basePathname, notFounds) {
|
|
60
|
-
notFounds.sort((a, b) => {
|
|
61
|
-
if (a[0].length > b[0].length) {
|
|
62
|
-
return -1;
|
|
63
|
-
}
|
|
64
|
-
if (a[0].length < b[0].length) {
|
|
65
|
-
return 1;
|
|
66
|
-
}
|
|
67
|
-
if (a[0] < b[0]) {
|
|
68
|
-
return -1;
|
|
69
|
-
}
|
|
70
|
-
if (a[0] > b[0]) {
|
|
71
|
-
return 1;
|
|
72
|
-
}
|
|
73
|
-
return 0;
|
|
74
|
-
});
|
|
75
|
-
if (!notFounds.some((r) => r[0] === basePathname)) {
|
|
76
|
-
const html = getErrorHtml(404, "Resource Not Found");
|
|
77
|
-
notFounds.push([basePathname, html]);
|
|
78
|
-
}
|
|
79
|
-
return JSON.stringify(notFounds, null, 2).slice(1, -1);
|
|
80
|
-
}
|
|
81
|
-
function createStaticPathsCode(staticPaths) {
|
|
82
|
-
return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
|
|
83
|
-
}
|
|
84
|
-
var injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
|
|
85
|
-
const promises = /* @__PURE__ */ new Set();
|
|
86
|
-
const doReplace = async (path) => {
|
|
87
|
-
const code = await fs.promises.readFile(path, "utf-8");
|
|
88
|
-
let replaced = false;
|
|
89
|
-
const newCode = code.replace(
|
|
90
|
-
/(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
|
|
91
|
-
(_, _quote, type) => {
|
|
92
|
-
replaced = true;
|
|
93
|
-
return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
if (replaced) {
|
|
97
|
-
await fs.promises.writeFile(path, newCode);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const walk = async (dir) => {
|
|
101
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
102
|
-
for (const entry of entries) {
|
|
103
|
-
if (entry.isDirectory()) {
|
|
104
|
-
await walk(join(dir, entry.name));
|
|
105
|
-
} else if (entry.name.endsWith("js")) {
|
|
106
|
-
const p = doReplace(join(dir, entry.name)).finally(() => {
|
|
107
|
-
promises.delete(p);
|
|
108
|
-
});
|
|
109
|
-
promises.add(p);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
await walk(outDir);
|
|
114
|
-
await Promise.all(promises);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
118
|
-
function viteAdapter(opts) {
|
|
119
|
-
let qwikRouterPlugin = null;
|
|
120
|
-
let qwikVitePlugin = null;
|
|
121
|
-
let serverOutDir = null;
|
|
122
|
-
let renderModulePath = null;
|
|
123
|
-
let qwikRouterConfigModulePath = null;
|
|
124
|
-
let isSsrBuild = false;
|
|
125
|
-
const outputEntries = [];
|
|
126
|
-
const plugin = {
|
|
127
|
-
name: `vite-plugin-qwik-router-ssg-${opts.name}`,
|
|
128
|
-
enforce: "post",
|
|
129
|
-
apply: "build",
|
|
130
|
-
config(config) {
|
|
131
|
-
if (typeof opts.config === "function") {
|
|
132
|
-
config = opts.config(config);
|
|
133
|
-
}
|
|
134
|
-
config.define = {
|
|
135
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
|
|
136
|
-
...config.define
|
|
137
|
-
};
|
|
138
|
-
return config;
|
|
139
|
-
},
|
|
140
|
-
configResolved(config) {
|
|
141
|
-
var _a, _b, _c;
|
|
142
|
-
isSsrBuild = !!config.build.ssr;
|
|
143
|
-
if (isSsrBuild) {
|
|
144
|
-
qwikRouterPlugin = config.plugins.find(
|
|
145
|
-
(p) => p.name === "vite-plugin-qwik-router"
|
|
146
|
-
);
|
|
147
|
-
if (!qwikRouterPlugin) {
|
|
148
|
-
throw new Error("Missing vite-plugin-qwik-router");
|
|
149
|
-
}
|
|
150
|
-
qwikVitePlugin = config.plugins.find(
|
|
151
|
-
(p) => p.name === "vite-plugin-qwik"
|
|
152
|
-
);
|
|
153
|
-
if (!qwikVitePlugin) {
|
|
154
|
-
throw new Error("Missing vite-plugin-qwik");
|
|
155
|
-
}
|
|
156
|
-
serverOutDir = config.build.outDir;
|
|
157
|
-
if (((_a = config.build) == null ? void 0 : _a.ssr) !== true) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
`"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
if (!((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input)) {
|
|
163
|
-
throw new Error(
|
|
164
|
-
`"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
buildStart() {
|
|
170
|
-
if (isSsrBuild && opts.ssg !== null) {
|
|
171
|
-
const { srcDir } = qwikVitePlugin.api.getOptions();
|
|
172
|
-
this.emitFile({
|
|
173
|
-
id: "@qwik-router-config",
|
|
174
|
-
type: "chunk",
|
|
175
|
-
fileName: "@qwik-router-config.js"
|
|
176
|
-
});
|
|
177
|
-
this.emitFile({
|
|
178
|
-
id: `${srcDir}/entry.ssr`,
|
|
179
|
-
type: "chunk",
|
|
180
|
-
fileName: "entry.ssr.js"
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
generateBundle(_, bundles) {
|
|
185
|
-
if (isSsrBuild) {
|
|
186
|
-
outputEntries.length = 0;
|
|
187
|
-
for (const fileName in bundles) {
|
|
188
|
-
const chunk = bundles[fileName];
|
|
189
|
-
if (chunk.type === "chunk" && chunk.isEntry) {
|
|
190
|
-
outputEntries.push(fileName);
|
|
191
|
-
if (chunk.name === "entry.ssr") {
|
|
192
|
-
renderModulePath = join2(serverOutDir, fileName);
|
|
193
|
-
} else if (chunk.name === "@qwik-router-config") {
|
|
194
|
-
qwikRouterConfigModulePath = join2(serverOutDir, fileName);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
closeBundle: {
|
|
201
|
-
sequential: true,
|
|
202
|
-
async handler() {
|
|
203
|
-
var _a;
|
|
204
|
-
if (isSsrBuild && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
|
|
205
|
-
const staticPaths = opts.staticPaths || [];
|
|
206
|
-
const routes = qwikRouterPlugin.api.getRoutes();
|
|
207
|
-
const basePathname = qwikRouterPlugin.api.getBasePathname();
|
|
208
|
-
const clientOutDir = qwikVitePlugin.api.getClientOutDir();
|
|
209
|
-
const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
|
|
210
|
-
const assetsDir = qwikVitePlugin.api.getAssetsDir();
|
|
211
|
-
const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
|
|
212
|
-
if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
|
|
213
|
-
let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
|
|
214
|
-
if (!ssgOrigin) {
|
|
215
|
-
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
216
|
-
}
|
|
217
|
-
if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
|
|
218
|
-
ssgOrigin = `https://${ssgOrigin}`;
|
|
219
|
-
}
|
|
220
|
-
if (ssgOrigin.startsWith("//")) {
|
|
221
|
-
ssgOrigin = `https:${ssgOrigin}`;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
ssgOrigin = new URL(ssgOrigin).origin;
|
|
225
|
-
} catch {
|
|
226
|
-
this.warn(
|
|
227
|
-
`Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
|
|
228
|
-
);
|
|
229
|
-
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
230
|
-
}
|
|
231
|
-
const staticGenerate = await import("../../../ssg/index.mjs");
|
|
232
|
-
const generateOpts = {
|
|
233
|
-
maxWorkers: opts.maxWorkers,
|
|
234
|
-
basePathname,
|
|
235
|
-
outDir: clientPublicOutDir,
|
|
236
|
-
rootDir,
|
|
237
|
-
...opts.ssg,
|
|
238
|
-
origin: ssgOrigin,
|
|
239
|
-
renderModulePath,
|
|
240
|
-
qwikRouterConfigModulePath
|
|
241
|
-
};
|
|
242
|
-
const staticGenerateResult = await staticGenerate.generate(generateOpts);
|
|
243
|
-
if (staticGenerateResult.errors > 0) {
|
|
244
|
-
const err = new Error(
|
|
245
|
-
`Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`
|
|
246
|
-
);
|
|
247
|
-
err.stack = void 0;
|
|
248
|
-
this.error(err);
|
|
249
|
-
}
|
|
250
|
-
staticPaths.push(...staticGenerateResult.staticPaths);
|
|
251
|
-
}
|
|
252
|
-
await postBuild(
|
|
253
|
-
clientPublicOutDir,
|
|
254
|
-
serverOutDir,
|
|
255
|
-
assetsDir ? join2(basePathname, assetsDir) : basePathname,
|
|
256
|
-
staticPaths,
|
|
257
|
-
!!opts.cleanStaticGenerated
|
|
258
|
-
);
|
|
259
|
-
if (typeof opts.generate === "function") {
|
|
260
|
-
await opts.generate({
|
|
261
|
-
outputEntries,
|
|
262
|
-
serverOutDir,
|
|
263
|
-
clientOutDir,
|
|
264
|
-
clientPublicOutDir,
|
|
265
|
-
basePathname,
|
|
266
|
-
routes,
|
|
267
|
-
assetsDir,
|
|
268
|
-
warn: (message) => this.warn(message),
|
|
269
|
-
error: (message) => this.error(message)
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
this.warn(
|
|
273
|
-
`
|
|
274
|
-
==============================================
|
|
275
|
-
Note: Make sure that you are serving the built files with proper cache headers.
|
|
276
|
-
See https://qwik.dev/docs/deployments/#cache-headers for more information.
|
|
277
|
-
==============================================`
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
return plugin;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// packages/qwik-router/src/adapters/ssg/vite/index.ts
|
|
1
|
+
import { viteAdapter } from "../../shared/vite/index.mjs";
|
|
2
|
+
/** @public */
|
|
287
3
|
function ssgAdapter(opts) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
4
|
+
return viteAdapter({
|
|
5
|
+
name: "static-site-generation",
|
|
6
|
+
origin: opts.origin,
|
|
7
|
+
ssg: {
|
|
8
|
+
include: ["/*"],
|
|
9
|
+
...opts
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** @public @deprecated Use `ssgAdapter` instead. */
|
|
297
14
|
var staticAdapter = ssgAdapter;
|
|
298
|
-
export {
|
|
299
|
-
ssgAdapter,
|
|
300
|
-
staticAdapter
|
|
301
|
-
};
|
|
15
|
+
export { ssgAdapter, staticAdapter };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ServerAdapterOptions } from '../../shared/vite';
|
|
2
|
-
import type { SsgRenderOptions } from '
|
|
1
|
+
import { ServerAdapterOptions } from '../../shared/vite/index.js';
|
|
2
|
+
import type { SsgRenderOptions } from '../../../ssg/index.js';
|
|
3
3
|
|
|
4
4
|
export { SsgRenderOptions }
|
|
5
5
|
|
|
@@ -35,7 +35,7 @@ export declare interface VercelEdgeAdapterOptions extends ServerAdapterOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
staticPaths?: string[];
|
|
37
37
|
/**
|
|
38
|
-
* Define the `target` property in the `ssr` object in the `vite.config.
|
|
38
|
+
* Define the `target` property in the `ssr` object in the `vite.config.ts` file.
|
|
39
39
|
*
|
|
40
40
|
* Defaults to `webworker`.
|
|
41
41
|
*/
|
|
@@ -1,83 +1,79 @@
|
|
|
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
|
-
|
|
4
|
+
/** @public */
|
|
5
5
|
function vercelEdgeAdapter(opts = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
});
|
|
6
|
+
return viteAdapter({
|
|
7
|
+
name: "vercel-edge",
|
|
8
|
+
origin: process?.env?.VERCEL_URL || "https://yoursitename.vercel.app",
|
|
9
|
+
ssg: opts.ssg,
|
|
10
|
+
staticPaths: opts.staticPaths,
|
|
11
|
+
cleanStaticGenerated: true,
|
|
12
|
+
config(config) {
|
|
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
|
+
];
|
|
28
|
+
return {
|
|
29
|
+
resolve: { conditions },
|
|
30
|
+
ssr: {
|
|
31
|
+
resolve: { conditions },
|
|
32
|
+
target: opts.target === "node" ? "node" : "webworker",
|
|
33
|
+
noExternal: true
|
|
34
|
+
},
|
|
35
|
+
build: {
|
|
36
|
+
ssr: true,
|
|
37
|
+
outDir,
|
|
38
|
+
rolldownOptions: { output: { format: "es" } }
|
|
39
|
+
},
|
|
40
|
+
publicDir: false
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
async generate({ clientPublicOutDir, serverOutDir, basePathname, outputEntries }) {
|
|
44
|
+
const vercelOutputDir = getParentDir(serverOutDir, "output");
|
|
45
|
+
if (opts.outputConfig !== false) {
|
|
46
|
+
const vercelOutputConfig = {
|
|
47
|
+
routes: [{ handle: "filesystem" }, {
|
|
48
|
+
src: basePathname + ".*",
|
|
49
|
+
dest: "/_qwik-router"
|
|
50
|
+
}],
|
|
51
|
+
version: 3
|
|
52
|
+
};
|
|
53
|
+
await fs.promises.writeFile(join(vercelOutputDir, "config.json"), JSON.stringify(vercelOutputConfig, null, 2));
|
|
54
|
+
}
|
|
55
|
+
let entrypoint = opts.vcConfigEntryPoint;
|
|
56
|
+
if (!entrypoint) {
|
|
57
|
+
if (outputEntries.some((n) => n === "entry.vercel-edge.mjs")) entrypoint = "entry.vercel-edge.mjs";
|
|
58
|
+
else entrypoint = "entry.vercel-edge.js";
|
|
59
|
+
}
|
|
60
|
+
const vcConfigPath = join(serverOutDir, ".vc-config.json");
|
|
61
|
+
const vcConfig = {
|
|
62
|
+
runtime: "edge",
|
|
63
|
+
entrypoint,
|
|
64
|
+
envVarsInUse: opts.vcConfigEnvVarsInUse
|
|
65
|
+
};
|
|
66
|
+
await fs.promises.writeFile(vcConfigPath, JSON.stringify(vcConfig, null, 2));
|
|
67
|
+
let vercelStaticDir = join(vercelOutputDir, "static");
|
|
68
|
+
const basePathnameParts = basePathname.split("/").filter((p) => p.length > 0);
|
|
69
|
+
if (basePathnameParts.length > 0) vercelStaticDir = join(vercelStaticDir, ...basePathnameParts);
|
|
70
|
+
await fs.promises.rm(vercelStaticDir, {
|
|
71
|
+
recursive: true,
|
|
72
|
+
force: true
|
|
73
|
+
});
|
|
74
|
+
await fs.promises.mkdir(dirname(vercelStaticDir), { recursive: true });
|
|
75
|
+
await fs.promises.rename(clientPublicOutDir, vercelStaticDir);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
80
78
|
}
|
|
81
|
-
export {
|
|
82
|
-
vercelEdgeAdapter
|
|
83
|
-
};
|
|
79
|
+
export { vercelEdgeAdapter };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function toTitleCase(str) {
|
|
2
|
+
return str.replace(/\w\S*/g, (txt) => {
|
|
3
|
+
return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
function addError(ctx, e) {
|
|
7
|
+
ctx.diagnostics.push({
|
|
8
|
+
type: "error",
|
|
9
|
+
message: e ? String(e.stack || e) : "Error"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function addWarning(ctx, message) {
|
|
13
|
+
ctx.diagnostics.push({
|
|
14
|
+
type: "warn",
|
|
15
|
+
message: String(message)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function msToString(ms) {
|
|
19
|
+
if (ms < 1) return ms.toFixed(2) + " ms";
|
|
20
|
+
if (ms < 1e3) return ms.toFixed(1) + " ms";
|
|
21
|
+
if (ms < 6e4) return (ms / 1e3).toFixed(1) + " s";
|
|
22
|
+
return (ms / 6e4).toFixed(1) + " m";
|
|
23
|
+
}
|
|
24
|
+
export { toTitleCase as i, addWarning as n, msToString as r, addError as t };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { i as normalizePathname, t as ensureSlash } from "./pathname.mjs";
|
|
2
|
+
import { i as toTitleCase } from "./format.mjs";
|
|
3
|
+
import { basename, dirname, normalize, relative } from "node:path";
|
|
4
|
+
function parseRouteIndexName(extlessName) {
|
|
5
|
+
let layoutName = "";
|
|
6
|
+
const layoutStop = extlessName.endsWith("!");
|
|
7
|
+
if (layoutStop) extlessName = extlessName.slice(0, extlessName.length - 1);
|
|
8
|
+
const namedLayoutParts = extlessName.split("@");
|
|
9
|
+
if (namedLayoutParts.length > 1) {
|
|
10
|
+
namedLayoutParts.shift();
|
|
11
|
+
layoutName = namedLayoutParts.join("@");
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
layoutName,
|
|
15
|
+
layoutStop
|
|
16
|
+
};
|
|
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
|
+
}
|
|
30
|
+
function getExtension(fileName) {
|
|
31
|
+
if (typeof fileName === "string") {
|
|
32
|
+
const parts = fileName.trim().toLowerCase().split(".");
|
|
33
|
+
if (parts.length > 1) {
|
|
34
|
+
const ext = parts.pop().split("?")[0].split("#")[0];
|
|
35
|
+
if (ext === "ts" && parts.pop() === "d") return ".d.ts";
|
|
36
|
+
return "." + ext;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
function removeExtension(fileName) {
|
|
42
|
+
if (typeof fileName === "string") {
|
|
43
|
+
fileName = fileName.trim();
|
|
44
|
+
const ext = getExtension(fileName);
|
|
45
|
+
return fileName.slice(0, fileName.length - ext.length);
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
function normalizePath(path) {
|
|
50
|
+
return normalizePathSlash(normalize(path));
|
|
51
|
+
}
|
|
52
|
+
/** Normalize equivalent filesystem paths for string-key comparisons. */
|
|
53
|
+
function normalizePathKey(path) {
|
|
54
|
+
if (path.startsWith("\\\\?\\UNC\\")) path = `\\\\${path.slice(8)}`;
|
|
55
|
+
else if (path.startsWith("\\\\?\\")) path = path.slice(4);
|
|
56
|
+
else if (path.startsWith("//?/UNC/")) path = `//${path.slice(8)}`;
|
|
57
|
+
else if (path.startsWith("//?/")) path = path.slice(4);
|
|
58
|
+
return normalizePath(path).replace(/\\/g, "/");
|
|
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
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates an id for the module, based on its path.
|
|
70
|
+
*
|
|
71
|
+
* @param routesDir
|
|
72
|
+
* @param fsPath
|
|
73
|
+
* @param explicitFileType Add to avoid collisions between different types of modules. `Menu` and
|
|
74
|
+
* `Layout` files are named based on their path (eg. /routes/about/menu.md => AboutMenu)
|
|
75
|
+
*/
|
|
76
|
+
function createFileId(routesDir, fsPath, explicitFileType) {
|
|
77
|
+
const ids = [];
|
|
78
|
+
for (let i = 0; i < 25; i++) {
|
|
79
|
+
let baseName = removeExtension(basename(fsPath));
|
|
80
|
+
baseName = baseName.replace(/[\W_]+/g, "");
|
|
81
|
+
if (baseName === "") baseName = "Q" + i;
|
|
82
|
+
else if (!isNaN(baseName.charAt(0))) baseName = "Q" + baseName;
|
|
83
|
+
ids.push(toTitleCase(baseName));
|
|
84
|
+
fsPath = normalizePath(dirname(fsPath));
|
|
85
|
+
if (fsPath === routesDir) break;
|
|
86
|
+
}
|
|
87
|
+
if (ids.length > 1 && ids[0] === "Index") ids.shift();
|
|
88
|
+
return ids.reverse().join("").concat(explicitFileType || "");
|
|
89
|
+
}
|
|
90
|
+
var PAGE_MODULE_EXTS = {
|
|
91
|
+
".tsx": true,
|
|
92
|
+
".jsx": true
|
|
93
|
+
};
|
|
94
|
+
var MODULE_EXTS = {
|
|
95
|
+
".ts": true,
|
|
96
|
+
".js": true
|
|
97
|
+
};
|
|
98
|
+
var MARKDOWN_EXTS = {
|
|
99
|
+
".md": true,
|
|
100
|
+
".mdx": true
|
|
101
|
+
};
|
|
102
|
+
function isIndexModule(extlessName) {
|
|
103
|
+
return /^index(|!|@.+)$/.test(extlessName);
|
|
104
|
+
}
|
|
105
|
+
function isPluginModule(extlessName) {
|
|
106
|
+
return /^plugin(|@.+)$/.test(extlessName) && !/\.(test|unit|spec)(\.[jt]s)?$/.test(extlessName);
|
|
107
|
+
}
|
|
108
|
+
function isLayoutModule(extlessName) {
|
|
109
|
+
return /^layout(|!|-.+)$/.test(extlessName);
|
|
110
|
+
}
|
|
111
|
+
function isPageModuleExt(ext) {
|
|
112
|
+
return ext in PAGE_MODULE_EXTS;
|
|
113
|
+
}
|
|
114
|
+
function isModuleExt(ext) {
|
|
115
|
+
return ext in MODULE_EXTS;
|
|
116
|
+
}
|
|
117
|
+
function isMarkdownExt(ext) {
|
|
118
|
+
return ext in MARKDOWN_EXTS;
|
|
119
|
+
}
|
|
120
|
+
function isPageExt(ext) {
|
|
121
|
+
return ext in PAGE_MODULE_EXTS || ext in MARKDOWN_EXTS;
|
|
122
|
+
}
|
|
123
|
+
function isMenuFileName(fileName) {
|
|
124
|
+
return fileName === "menu.md";
|
|
125
|
+
}
|
|
126
|
+
function isServiceWorkerName(extlessName) {
|
|
127
|
+
return extlessName === "service-worker";
|
|
128
|
+
}
|
|
129
|
+
function isEntryName(extlessName) {
|
|
130
|
+
return extlessName === "entry";
|
|
131
|
+
}
|
|
132
|
+
/** Which caught error a page renders (`'404'` or `'error'`), ignoring `@x`/`!` modifiers. */
|
|
133
|
+
function caughtErrorName(extlessName) {
|
|
134
|
+
const match = /^(error|404)(?:|!|@.+)$/.exec(extlessName);
|
|
135
|
+
return match ? match[1] : void 0;
|
|
136
|
+
}
|
|
137
|
+
function isErrorName(extlessName) {
|
|
138
|
+
return caughtErrorName(extlessName) !== void 0;
|
|
139
|
+
}
|
|
140
|
+
function isGroupedLayoutName(dirName, warn = true) {
|
|
141
|
+
return dirName.startsWith("(") && dirName.endsWith(")");
|
|
142
|
+
}
|
|
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, createFileId as n, isEntryName as o, isPageExt as p, getExtension as r, isErrorName as s, caughtErrorName as t, isMarkdownExt as u, normalizePathKey as v, removeExtension as x, normalizePathSlash as y };
|