@qwik.dev/router 0.0.0 → 2.0.0-alpha.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/LICENSE +22 -0
- package/README.md +15 -0
- package/adapters/azure-swa/vite.d.ts +2 -0
- package/adapters/bun-server/vite.d.ts +2 -0
- package/adapters/cloud-run/vite.d.ts +2 -0
- package/adapters/cloudflare-pages/vite.d.ts +2 -0
- package/adapters/deno-server/vite.d.ts +2 -0
- package/adapters/netlify-edge/vite.d.ts +2 -0
- package/adapters/node-server/vite.d.ts +2 -0
- package/adapters/shared/vite.d.ts +2 -0
- package/adapters/static/vite.d.ts +2 -0
- package/adapters/vercel-edge/vite.d.ts +2 -0
- package/index.d.ts +2 -0
- package/lib/adapters/azure-swa/vite/index.cjs +96 -0
- package/lib/adapters/azure-swa/vite/index.d.ts +13 -0
- package/lib/adapters/azure-swa/vite/index.mjs +61 -0
- package/lib/adapters/bun-server/vite/index.cjs +50 -0
- package/lib/adapters/bun-server/vite/index.d.ts +14 -0
- package/lib/adapters/bun-server/vite/index.mjs +25 -0
- package/lib/adapters/cloud-run/vite/index.cjs +47 -0
- package/lib/adapters/cloud-run/vite/index.d.ts +13 -0
- package/lib/adapters/cloud-run/vite/index.mjs +22 -0
- package/lib/adapters/cloudflare-pages/vite/index.cjs +115 -0
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +27 -0
- package/lib/adapters/cloudflare-pages/vite/index.mjs +80 -0
- package/lib/adapters/deno-server/vite/index.cjs +62 -0
- package/lib/adapters/deno-server/vite/index.d.ts +14 -0
- package/lib/adapters/deno-server/vite/index.mjs +37 -0
- package/lib/adapters/netlify-edge/vite/index.cjs +129 -0
- package/lib/adapters/netlify-edge/vite/index.d.ts +44 -0
- package/lib/adapters/netlify-edge/vite/index.mjs +92 -0
- package/lib/adapters/node-server/vite/index.cjs +50 -0
- package/lib/adapters/node-server/vite/index.d.ts +14 -0
- package/lib/adapters/node-server/vite/index.mjs +25 -0
- package/lib/adapters/shared/vite/index.cjs +371 -0
- package/lib/adapters/shared/vite/index.d.ts +114 -0
- package/lib/adapters/shared/vite/index.mjs +331 -0
- package/lib/adapters/static/vite/index.cjs +361 -0
- package/lib/adapters/static/vite/index.d.ts +10 -0
- package/lib/adapters/static/vite/index.mjs +324 -0
- package/lib/adapters/vercel-edge/vite/index.cjs +118 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +45 -0
- package/lib/adapters/vercel-edge/vite/index.mjs +83 -0
- package/lib/index.d.ts +803 -0
- package/lib/index.qwik.cjs +1876 -0
- package/lib/index.qwik.mjs +1857 -0
- package/lib/middleware/aws-lambda/index.d.ts +50 -0
- package/lib/middleware/aws-lambda/index.mjs +55 -0
- package/lib/middleware/azure-swa/index.d.ts +28 -0
- package/lib/middleware/azure-swa/index.mjs +297 -0
- package/lib/middleware/bun/index.d.ts +35 -0
- package/lib/middleware/bun/index.mjs +208 -0
- package/lib/middleware/cloudflare-pages/index.d.ts +35 -0
- package/lib/middleware/cloudflare-pages/index.mjs +107 -0
- package/lib/middleware/deno/index.d.ts +47 -0
- package/lib/middleware/deno/index.mjs +195 -0
- package/lib/middleware/firebase/index.d.ts +26 -0
- package/lib/middleware/firebase/index.mjs +36 -0
- package/lib/middleware/netlify-edge/index.d.ts +27 -0
- package/lib/middleware/netlify-edge/index.mjs +83 -0
- package/lib/middleware/node/index.cjs +314 -0
- package/lib/middleware/node/index.d.ts +66 -0
- package/lib/middleware/node/index.mjs +287 -0
- package/lib/middleware/request-handler/index.cjs +1544 -0
- package/lib/middleware/request-handler/index.d.ts +681 -0
- package/lib/middleware/request-handler/index.mjs +1501 -0
- package/lib/middleware/vercel-edge/index.d.ts +26 -0
- package/lib/middleware/vercel-edge/index.mjs +109 -0
- package/lib/modules.d.ts +38 -0
- package/lib/service-worker.cjs +267 -0
- package/lib/service-worker.d.ts +4 -0
- package/lib/service-worker.mjs +265 -0
- package/lib/static/deno.mjs +8 -0
- package/lib/static/index.cjs +67 -0
- package/lib/static/index.d.ts +98 -0
- package/lib/static/index.mjs +48 -0
- package/lib/static/node.cjs +1124 -0
- package/lib/static/node.mjs +1086 -0
- package/lib/vite/index.cjs +27496 -0
- package/lib/vite/index.d.ts +154 -0
- package/lib/vite/index.mjs +27484 -0
- package/middleware/aws-lambda.d.ts +2 -0
- package/middleware/azure-swa.d.ts +2 -0
- package/middleware/bun.d.ts +2 -0
- package/middleware/cloudflare-pages.d.ts +2 -0
- package/middleware/deno.d.ts +2 -0
- package/middleware/firebase.d.ts +2 -0
- package/middleware/netlify-edge.d.ts +2 -0
- package/middleware/node.d.ts +2 -0
- package/middleware/request-handler/generated/not-found-paths.ts +7 -0
- package/middleware/request-handler/generated/static-paths.ts +35 -0
- package/middleware/request-handler.d.ts +2 -0
- package/middleware/vercel-edge.d.ts +2 -0
- package/modules.d.ts +38 -0
- package/package.json +171 -165
- package/service-worker.d.ts +2 -0
- package/static.d.ts +2 -0
- package/vite.d.ts +2 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
31
|
+
var vite_exports = {};
|
|
32
|
+
__export(vite_exports, {
|
|
33
|
+
NOT_FOUND_PATHS_ID: () => NOT_FOUND_PATHS_ID,
|
|
34
|
+
RESOLVED_NOT_FOUND_PATHS_ID: () => RESOLVED_NOT_FOUND_PATHS_ID,
|
|
35
|
+
RESOLVED_STATIC_PATHS_ID: () => RESOLVED_STATIC_PATHS_ID,
|
|
36
|
+
STATIC_PATHS_ID: () => STATIC_PATHS_ID,
|
|
37
|
+
getParentDir: () => getParentDir,
|
|
38
|
+
viteAdapter: () => viteAdapter
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(vite_exports);
|
|
41
|
+
var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
42
|
+
var import_node_path2 = require("node:path");
|
|
43
|
+
|
|
44
|
+
// packages/qwik-router/src/adapters/shared/vite/post-build.ts
|
|
45
|
+
var import_request_handler = require("../../../middleware/request-handler/index.cjs");
|
|
46
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
47
|
+
var import_node_path = require("node:path");
|
|
48
|
+
async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) {
|
|
49
|
+
if (pathName && !pathName.endsWith("/")) {
|
|
50
|
+
pathName += "/";
|
|
51
|
+
}
|
|
52
|
+
const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]);
|
|
53
|
+
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
|
|
54
|
+
const notFounds = [];
|
|
55
|
+
const loadItem = async (fsDir, fsName, pathname) => {
|
|
56
|
+
pathname = normalizeTrailingSlash(pathname);
|
|
57
|
+
if (ignorePathnames.has(pathname)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const fsPath = (0, import_node_path.join)(fsDir, fsName);
|
|
61
|
+
if (fsName === "index.html" || fsName === "q-data.json") {
|
|
62
|
+
if (!staticPaths.has(pathname) && cleanStatic) {
|
|
63
|
+
await import_node_fs.default.promises.unlink(fsPath);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (fsName === "404.html") {
|
|
68
|
+
const notFoundHtml = await import_node_fs.default.promises.readFile(fsPath, "utf-8");
|
|
69
|
+
notFounds.push([pathname, notFoundHtml]);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const stat = await import_node_fs.default.promises.stat(fsPath);
|
|
73
|
+
if (stat.isDirectory()) {
|
|
74
|
+
await loadDir(fsPath, pathname + fsName + "/");
|
|
75
|
+
} else if (stat.isFile()) {
|
|
76
|
+
staticPaths.add(pathname + fsName);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const loadDir = async (fsDir, pathname) => {
|
|
80
|
+
const itemNames = await import_node_fs.default.promises.readdir(fsDir);
|
|
81
|
+
await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname)));
|
|
82
|
+
};
|
|
83
|
+
if (import_node_fs.default.existsSync(clientOutDir)) {
|
|
84
|
+
await loadDir(clientOutDir, pathName);
|
|
85
|
+
}
|
|
86
|
+
const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format);
|
|
87
|
+
const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format);
|
|
88
|
+
return {
|
|
89
|
+
notFoundPathsCode,
|
|
90
|
+
staticPathsCode
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function normalizeTrailingSlash(pathname) {
|
|
94
|
+
if (!pathname.endsWith("/")) {
|
|
95
|
+
return pathname + "/";
|
|
96
|
+
}
|
|
97
|
+
return pathname;
|
|
98
|
+
}
|
|
99
|
+
function createNotFoundPathsModule(basePathname, notFounds, format) {
|
|
100
|
+
notFounds.sort((a, b) => {
|
|
101
|
+
if (a[0].length > b[0].length) {
|
|
102
|
+
return -1;
|
|
103
|
+
}
|
|
104
|
+
if (a[0].length < b[0].length) {
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
if (a[0] < b[0]) {
|
|
108
|
+
return -1;
|
|
109
|
+
}
|
|
110
|
+
if (a[0] > b[0]) {
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
return 0;
|
|
114
|
+
});
|
|
115
|
+
if (!notFounds.some((r) => r[0] === basePathname)) {
|
|
116
|
+
const html = (0, import_request_handler.getErrorHtml)(404, "Resource Not Found");
|
|
117
|
+
notFounds.push([basePathname, html]);
|
|
118
|
+
}
|
|
119
|
+
const c = [];
|
|
120
|
+
c.push(`const notFounds = ${JSON.stringify(notFounds, null, 2)};`);
|
|
121
|
+
c.push(`function getNotFound(p) {`);
|
|
122
|
+
c.push(` for (const r of notFounds) {`);
|
|
123
|
+
c.push(` if (p.startsWith(r[0])) {`);
|
|
124
|
+
c.push(` return r[1];`);
|
|
125
|
+
c.push(` }`);
|
|
126
|
+
c.push(` }`);
|
|
127
|
+
c.push(` return "Resource Not Found";`);
|
|
128
|
+
c.push(`}`);
|
|
129
|
+
if (format === "cjs") {
|
|
130
|
+
c.push("exports.getNotFound = getNotFound;");
|
|
131
|
+
} else {
|
|
132
|
+
c.push("export { getNotFound };");
|
|
133
|
+
}
|
|
134
|
+
return c.join("\n");
|
|
135
|
+
}
|
|
136
|
+
function createStaticPathsModule(basePathname, staticPaths, format) {
|
|
137
|
+
const assetsPath = basePathname + "assets/";
|
|
138
|
+
const baseBuildPath = basePathname + "build/";
|
|
139
|
+
const c = [];
|
|
140
|
+
c.push(
|
|
141
|
+
`const staticPaths = new Set(${JSON.stringify(
|
|
142
|
+
Array.from(new Set(staticPaths)).sort()
|
|
143
|
+
)});`
|
|
144
|
+
);
|
|
145
|
+
c.push(`function isStaticPath(method, url) {`);
|
|
146
|
+
c.push(` if (method.toUpperCase() !== 'GET') {`);
|
|
147
|
+
c.push(` return false;`);
|
|
148
|
+
c.push(` }`);
|
|
149
|
+
c.push(` const p = url.pathname;`);
|
|
150
|
+
c.push(` if (p.startsWith(${JSON.stringify(baseBuildPath)})) {`);
|
|
151
|
+
c.push(` return true;`);
|
|
152
|
+
c.push(` }`);
|
|
153
|
+
c.push(` if (p.startsWith(${JSON.stringify(assetsPath)})) {`);
|
|
154
|
+
c.push(` return true;`);
|
|
155
|
+
c.push(` }`);
|
|
156
|
+
c.push(` if (staticPaths.has(p)) {`);
|
|
157
|
+
c.push(` return true;`);
|
|
158
|
+
c.push(` }`);
|
|
159
|
+
c.push(` if (p.endsWith('/q-data.json')) {`);
|
|
160
|
+
c.push(` const pWithoutQdata = p.replace(/\\/q-data.json$/, '');`);
|
|
161
|
+
c.push(` if (staticPaths.has(pWithoutQdata + '/')) {`);
|
|
162
|
+
c.push(` return true;`);
|
|
163
|
+
c.push(` }`);
|
|
164
|
+
c.push(` if (staticPaths.has(pWithoutQdata)) {`);
|
|
165
|
+
c.push(` return true;`);
|
|
166
|
+
c.push(` }`);
|
|
167
|
+
c.push(` }`);
|
|
168
|
+
c.push(` return false;`);
|
|
169
|
+
c.push(`}`);
|
|
170
|
+
if (format === "cjs") {
|
|
171
|
+
c.push("exports.isStaticPath = isStaticPath;");
|
|
172
|
+
} else {
|
|
173
|
+
c.push("export { isStaticPath };");
|
|
174
|
+
}
|
|
175
|
+
return c.join("\n");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// packages/qwik-router/src/adapters/shared/vite/index.ts
|
|
179
|
+
function viteAdapter(opts) {
|
|
180
|
+
let qwikRouterPlugin = null;
|
|
181
|
+
let qwikVitePlugin = null;
|
|
182
|
+
let serverOutDir = null;
|
|
183
|
+
let renderModulePath = null;
|
|
184
|
+
let qwikRouterConfigModulePath = null;
|
|
185
|
+
let isSsrBuild = false;
|
|
186
|
+
let format = "esm";
|
|
187
|
+
const outputEntries = [];
|
|
188
|
+
const plugin = {
|
|
189
|
+
name: `vite-plugin-qwik-router-${opts.name}`,
|
|
190
|
+
enforce: "post",
|
|
191
|
+
apply: "build",
|
|
192
|
+
config(config) {
|
|
193
|
+
if (typeof opts.config === "function") {
|
|
194
|
+
config = opts.config(config);
|
|
195
|
+
}
|
|
196
|
+
config.define = {
|
|
197
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
|
|
198
|
+
...config.define
|
|
199
|
+
};
|
|
200
|
+
return config;
|
|
201
|
+
},
|
|
202
|
+
configResolved(config) {
|
|
203
|
+
var _a, _b, _c, _d;
|
|
204
|
+
isSsrBuild = !!config.build.ssr;
|
|
205
|
+
if (isSsrBuild) {
|
|
206
|
+
qwikRouterPlugin = config.plugins.find(
|
|
207
|
+
(p) => p.name === "vite-plugin-qwik-router"
|
|
208
|
+
);
|
|
209
|
+
if (!qwikRouterPlugin) {
|
|
210
|
+
throw new Error("Missing vite-plugin-qwik-router");
|
|
211
|
+
}
|
|
212
|
+
qwikVitePlugin = config.plugins.find(
|
|
213
|
+
(p) => p.name === "vite-plugin-qwik"
|
|
214
|
+
);
|
|
215
|
+
if (!qwikVitePlugin) {
|
|
216
|
+
throw new Error("Missing vite-plugin-qwik");
|
|
217
|
+
}
|
|
218
|
+
serverOutDir = config.build.outDir;
|
|
219
|
+
if (((_a = config.build) == null ? void 0 : _a.ssr) !== true) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (!((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input)) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (((_d = config.ssr) == null ? void 0 : _d.format) === "cjs") {
|
|
230
|
+
format = "cjs";
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
generateBundle(_, bundles) {
|
|
235
|
+
if (isSsrBuild) {
|
|
236
|
+
outputEntries.length = 0;
|
|
237
|
+
for (const fileName in bundles) {
|
|
238
|
+
const chunk = bundles[fileName];
|
|
239
|
+
if (chunk.type === "chunk" && chunk.isEntry) {
|
|
240
|
+
outputEntries.push(fileName);
|
|
241
|
+
if (chunk.name === "entry.ssr") {
|
|
242
|
+
renderModulePath = (0, import_node_path2.join)(serverOutDir, fileName);
|
|
243
|
+
} else if (chunk.name === "@qwik-router-config") {
|
|
244
|
+
qwikRouterConfigModulePath = (0, import_node_path2.join)(serverOutDir, fileName);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!renderModulePath) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
'Unable to find "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?'
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (!qwikRouterConfigModulePath) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
'Unable to find "@qwik-router-config" entry point. Did you forget to add it to "build.rollupOptions.input"?'
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
closeBundle: {
|
|
261
|
+
sequential: true,
|
|
262
|
+
async handler() {
|
|
263
|
+
var _a;
|
|
264
|
+
if (isSsrBuild && opts.ssg !== null && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
|
|
265
|
+
const staticPaths = opts.staticPaths || [];
|
|
266
|
+
const routes = qwikRouterPlugin.api.getRoutes();
|
|
267
|
+
const basePathname = qwikRouterPlugin.api.getBasePathname();
|
|
268
|
+
const clientOutDir = qwikVitePlugin.api.getClientOutDir();
|
|
269
|
+
const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
|
|
270
|
+
const assetsDir = qwikVitePlugin.api.getAssetsDir();
|
|
271
|
+
const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
|
|
272
|
+
if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
|
|
273
|
+
let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
|
|
274
|
+
if (!ssgOrigin) {
|
|
275
|
+
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
276
|
+
}
|
|
277
|
+
if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
|
|
278
|
+
ssgOrigin = `https://${ssgOrigin}`;
|
|
279
|
+
}
|
|
280
|
+
if (ssgOrigin.startsWith("//")) {
|
|
281
|
+
ssgOrigin = `https:${ssgOrigin}`;
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
ssgOrigin = new URL(ssgOrigin).origin;
|
|
285
|
+
} catch (e) {
|
|
286
|
+
this.warn(
|
|
287
|
+
`Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
|
|
288
|
+
);
|
|
289
|
+
ssgOrigin = `https://yoursite.qwik.dev`;
|
|
290
|
+
}
|
|
291
|
+
const staticGenerate = await import("../../../static/index.cjs");
|
|
292
|
+
const generateOpts = {
|
|
293
|
+
maxWorkers: opts.maxWorkers,
|
|
294
|
+
basePathname,
|
|
295
|
+
outDir: clientPublicOutDir,
|
|
296
|
+
rootDir,
|
|
297
|
+
...opts.ssg,
|
|
298
|
+
origin: ssgOrigin,
|
|
299
|
+
renderModulePath,
|
|
300
|
+
qwikRouterConfigModulePath
|
|
301
|
+
};
|
|
302
|
+
const staticGenerateResult = await staticGenerate.generate(generateOpts);
|
|
303
|
+
if (staticGenerateResult.errors > 0) {
|
|
304
|
+
const err = new Error(
|
|
305
|
+
`Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`
|
|
306
|
+
);
|
|
307
|
+
err.stack = void 0;
|
|
308
|
+
this.error(err);
|
|
309
|
+
}
|
|
310
|
+
staticPaths.push(...staticGenerateResult.staticPaths);
|
|
311
|
+
const { staticPathsCode, notFoundPathsCode } = await postBuild(
|
|
312
|
+
clientPublicOutDir,
|
|
313
|
+
assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname,
|
|
314
|
+
staticPaths,
|
|
315
|
+
format,
|
|
316
|
+
!!opts.cleanStaticGenerated
|
|
317
|
+
);
|
|
318
|
+
await Promise.all([
|
|
319
|
+
import_node_fs2.default.promises.writeFile((0, import_node_path2.join)(serverOutDir, RESOLVED_STATIC_PATHS_ID), staticPathsCode),
|
|
320
|
+
import_node_fs2.default.promises.writeFile(
|
|
321
|
+
(0, import_node_path2.join)(serverOutDir, RESOLVED_NOT_FOUND_PATHS_ID),
|
|
322
|
+
notFoundPathsCode
|
|
323
|
+
)
|
|
324
|
+
]);
|
|
325
|
+
if (typeof opts.generate === "function") {
|
|
326
|
+
await opts.generate({
|
|
327
|
+
outputEntries,
|
|
328
|
+
serverOutDir,
|
|
329
|
+
clientOutDir,
|
|
330
|
+
clientPublicOutDir,
|
|
331
|
+
basePathname,
|
|
332
|
+
routes,
|
|
333
|
+
assetsDir,
|
|
334
|
+
warn: (message) => this.warn(message),
|
|
335
|
+
error: (message) => this.error(message)
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
return plugin;
|
|
344
|
+
}
|
|
345
|
+
function getParentDir(startDir, dirName) {
|
|
346
|
+
const root = (0, import_node_path2.resolve)("/");
|
|
347
|
+
let dir = startDir;
|
|
348
|
+
for (let i = 0; i < 20; i++) {
|
|
349
|
+
dir = (0, import_node_path2.dirname)(dir);
|
|
350
|
+
if ((0, import_node_path2.basename)(dir) === dirName) {
|
|
351
|
+
return dir;
|
|
352
|
+
}
|
|
353
|
+
if (dir === root) {
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
throw new Error(`Unable to find "${dirName}" directory from "${startDir}"`);
|
|
358
|
+
}
|
|
359
|
+
var STATIC_PATHS_ID = "@qwik-router-static-paths";
|
|
360
|
+
var RESOLVED_STATIC_PATHS_ID = `${STATIC_PATHS_ID}.js`;
|
|
361
|
+
var NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
|
|
362
|
+
var RESOLVED_NOT_FOUND_PATHS_ID = `${NOT_FOUND_PATHS_ID}.js`;
|
|
363
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
364
|
+
0 && (module.exports = {
|
|
365
|
+
NOT_FOUND_PATHS_ID,
|
|
366
|
+
RESOLVED_NOT_FOUND_PATHS_ID,
|
|
367
|
+
RESOLVED_STATIC_PATHS_ID,
|
|
368
|
+
STATIC_PATHS_ID,
|
|
369
|
+
getParentDir,
|
|
370
|
+
viteAdapter
|
|
371
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Plugin as Plugin_2 } from 'vite';
|
|
2
|
+
import type { StaticGenerateRenderOptions } from '@qwik.dev/router/static';
|
|
3
|
+
import type { UserConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
/** @public */
|
|
6
|
+
export declare interface AdapterSSGOptions extends Omit<StaticGenerateRenderOptions, 'outDir' | 'origin'> {
|
|
7
|
+
/** Defines routes that should be static generated. Accepts wildcard behavior. */
|
|
8
|
+
include: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Defines routes that should not be static generated. Accepts wildcard behavior. `exclude` always
|
|
11
|
+
* take priority over `include`.
|
|
12
|
+
*/
|
|
13
|
+
exclude?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The URL `origin`, which is a combination of the scheme (protocol) and hostname (domain). For
|
|
16
|
+
* example, `https://qwik.dev` has the protocol `https://` and domain `qwik.dev`. However, the
|
|
17
|
+
* `origin` does not include a `pathname`.
|
|
18
|
+
*
|
|
19
|
+
* The `origin` is used to provide a full URL during Static Site Generation (SSG), and to simulate
|
|
20
|
+
* a complete URL rather than just the `pathname`. For example, in order to render a correct
|
|
21
|
+
* canonical tag URL or URLs within the `sitemap.xml`, the `origin` must be provided too.
|
|
22
|
+
*
|
|
23
|
+
* If the site also starts with a pathname other than `/`, please use the `basePathname` option in
|
|
24
|
+
* the Qwik Router config options.
|
|
25
|
+
*/
|
|
26
|
+
origin?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare interface BuildLayout {
|
|
30
|
+
filePath: string;
|
|
31
|
+
dirPath: string;
|
|
32
|
+
id: string;
|
|
33
|
+
layoutType: 'top' | 'nested';
|
|
34
|
+
layoutName: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare interface BuildRoute extends ParsedPathname {
|
|
38
|
+
/** Unique id built from its relative file system path */
|
|
39
|
+
id: string;
|
|
40
|
+
/** Local file system path */
|
|
41
|
+
filePath: string;
|
|
42
|
+
ext: string;
|
|
43
|
+
/** URL Pathname */
|
|
44
|
+
pathname: string;
|
|
45
|
+
layouts: BuildLayout[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @public */
|
|
49
|
+
export declare function getParentDir(startDir: string, dirName: string): string;
|
|
50
|
+
|
|
51
|
+
/** @public */
|
|
52
|
+
export declare const NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
|
|
53
|
+
|
|
54
|
+
declare interface ParsedPathname {
|
|
55
|
+
routeName: string;
|
|
56
|
+
pattern: RegExp;
|
|
57
|
+
paramNames: string[];
|
|
58
|
+
segments: PathnameSegment[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare type PathnameSegment = PathnameSegmentPart[];
|
|
62
|
+
|
|
63
|
+
declare interface PathnameSegmentPart {
|
|
64
|
+
content: string;
|
|
65
|
+
dynamic: boolean;
|
|
66
|
+
rest: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @public */
|
|
70
|
+
export declare const RESOLVED_NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths.js";
|
|
71
|
+
|
|
72
|
+
/** @public */
|
|
73
|
+
export declare const RESOLVED_STATIC_PATHS_ID = "@qwik-router-static-paths.js";
|
|
74
|
+
|
|
75
|
+
/** @public */
|
|
76
|
+
export declare interface ServerAdapterOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Options the adapter should use when running Static Site Generation (SSG). Defaults the `filter`
|
|
79
|
+
* to "auto" which will attempt to automatically decides if a page can be statically generated and
|
|
80
|
+
* does not have dynamic data, or if it the page should instead be rendered on the server (SSR).
|
|
81
|
+
* Setting to `null` will prevent any pages from being statically generated.
|
|
82
|
+
*/
|
|
83
|
+
ssg?: AdapterSSGOptions | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @public */
|
|
87
|
+
export declare const STATIC_PATHS_ID = "@qwik-router-static-paths";
|
|
88
|
+
|
|
89
|
+
/** @public */
|
|
90
|
+
export declare function viteAdapter(opts: ViteAdapterPluginOptions): Plugin_2<never>;
|
|
91
|
+
|
|
92
|
+
/** @public */
|
|
93
|
+
declare interface ViteAdapterPluginOptions {
|
|
94
|
+
name: string;
|
|
95
|
+
origin: string;
|
|
96
|
+
staticPaths?: string[];
|
|
97
|
+
ssg?: AdapterSSGOptions | null;
|
|
98
|
+
cleanStaticGenerated?: boolean;
|
|
99
|
+
maxWorkers?: number;
|
|
100
|
+
config?: (config: UserConfig) => UserConfig;
|
|
101
|
+
generate?: (generateOpts: {
|
|
102
|
+
outputEntries: string[];
|
|
103
|
+
clientOutDir: string;
|
|
104
|
+
clientPublicOutDir: string;
|
|
105
|
+
serverOutDir: string;
|
|
106
|
+
basePathname: string;
|
|
107
|
+
routes: BuildRoute[];
|
|
108
|
+
assetsDir?: string;
|
|
109
|
+
warn: (message: string) => void;
|
|
110
|
+
error: (message: string) => void;
|
|
111
|
+
}) => Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { }
|