@qwik.dev/router 2.0.0-beta.13 → 2.0.0-beta.15

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 (66) hide show
  1. package/lib/adapters/azure-swa/vite/index.mjs +7 -7
  2. package/lib/adapters/bun-server/vite/index.mjs +7 -7
  3. package/lib/adapters/cloud-run/vite/index.mjs +7 -7
  4. package/lib/adapters/cloudflare-pages/vite/index.mjs +8 -8
  5. package/lib/adapters/deno-server/vite/index.mjs +7 -7
  6. package/lib/adapters/netlify-edge/vite/index.mjs +7 -7
  7. package/lib/adapters/node-server/vite/index.mjs +7 -7
  8. package/lib/adapters/shared/vite/index.mjs +8 -8
  9. package/lib/adapters/ssg/vite/index.mjs +7 -8
  10. package/lib/adapters/vercel-edge/vite/index.mjs +7 -7
  11. package/lib/chunks/error-handler.mjs +2 -4
  12. package/lib/chunks/format-error.mjs +6 -6
  13. package/lib/chunks/fs.mjs +6 -27
  14. package/lib/chunks/index.mjs +39 -31
  15. package/lib/chunks/mime-types.mjs +2 -3
  16. package/lib/chunks/routing.qwik.mjs +23 -47
  17. package/lib/chunks/types.qwik.mjs +2 -5
  18. package/lib/index.d.ts +2 -1
  19. package/lib/index.qwik.mjs +48 -68
  20. package/lib/middleware/aws-lambda/index.mjs +4 -5
  21. package/lib/middleware/azure-swa/index.mjs +6 -7
  22. package/lib/middleware/bun/index.mjs +8 -9
  23. package/lib/middleware/cloudflare-pages/index.mjs +5 -6
  24. package/lib/middleware/deno/index.mjs +7 -8
  25. package/lib/middleware/firebase/index.mjs +4 -5
  26. package/lib/middleware/netlify-edge/index.mjs +5 -6
  27. package/lib/middleware/node/index.mjs +15 -11
  28. package/lib/middleware/request-handler/index.d.ts +2 -2
  29. package/lib/middleware/request-handler/index.mjs +64 -79
  30. package/lib/middleware/vercel-edge/index.mjs +5 -6
  31. package/lib/service-worker/index.mjs +2 -3
  32. package/lib/ssg/index.mjs +3 -4
  33. package/lib/vite/index.d.ts +7 -1
  34. package/lib/vite/index.mjs +91 -68
  35. package/package.json +21 -39
  36. package/lib/adapters/azure-swa/vite/index.cjs +0 -61
  37. package/lib/adapters/bun-server/vite/index.cjs +0 -27
  38. package/lib/adapters/cloud-run/vite/index.cjs +0 -24
  39. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -65
  40. package/lib/adapters/deno-server/vite/index.cjs +0 -39
  41. package/lib/adapters/netlify-edge/vite/index.cjs +0 -88
  42. package/lib/adapters/node-server/vite/index.cjs +0 -27
  43. package/lib/adapters/shared/vite/index.cjs +0 -306
  44. package/lib/adapters/ssg/vite/index.cjs +0 -19
  45. package/lib/adapters/vercel-edge/vite/index.cjs +0 -81
  46. package/lib/chunks/error-handler.cjs +0 -58
  47. package/lib/chunks/format-error.cjs +0 -136
  48. package/lib/chunks/fs.cjs +0 -274
  49. package/lib/chunks/index.cjs +0 -877
  50. package/lib/chunks/mime-types.cjs +0 -52
  51. package/lib/chunks/routing.qwik.cjs +0 -452
  52. package/lib/chunks/types.qwik.cjs +0 -24
  53. package/lib/index.qwik.cjs +0 -1662
  54. package/lib/middleware/aws-lambda/index.cjs +0 -52
  55. package/lib/middleware/azure-swa/index.cjs +0 -92
  56. package/lib/middleware/bun/index.cjs +0 -143
  57. package/lib/middleware/cloudflare-pages/index.cjs +0 -96
  58. package/lib/middleware/deno/index.cjs +0 -130
  59. package/lib/middleware/firebase/index.cjs +0 -33
  60. package/lib/middleware/netlify-edge/index.cjs +0 -71
  61. package/lib/middleware/node/index.cjs +0 -219
  62. package/lib/middleware/request-handler/index.cjs +0 -1488
  63. package/lib/middleware/vercel-edge/index.cjs +0 -98
  64. package/lib/service-worker/index.cjs +0 -5
  65. package/lib/ssg/index.cjs +0 -15
  66. package/lib/vite/index.cjs +0 -2021
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
4
- require("node:path");
5
- require("node:fs");
6
- require("../../../chunks/error-handler.cjs");
7
- function bunServerAdapter(opts = {}) {
8
- const env = process?.env;
9
- return adapters_shared_vite.viteAdapter({
10
- name: opts.name || "bun-server",
11
- origin: env?.ORIGIN ?? env?.URL ?? "https://yoursitename.qwik.dev",
12
- ssg: opts.ssg,
13
- cleanStaticGenerated: true,
14
- config() {
15
- return {
16
- ssr: {
17
- target: "node"
18
- },
19
- build: {
20
- ssr: true
21
- },
22
- publicDir: false
23
- };
24
- }
25
- });
26
- }
27
- exports.bunServerAdapter = bunServerAdapter;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
4
- require("node:path");
5
- require("node:fs");
6
- require("../../../chunks/error-handler.cjs");
7
- function cloudRunAdapter(opts = {}) {
8
- const env = process?.env;
9
- return adapters_shared_vite.viteAdapter({
10
- name: "cloud-run",
11
- origin: env?.ORIGIN ?? env?.URL ?? "https://your-app-name.run.app",
12
- ssg: opts.ssg,
13
- cleanStaticGenerated: true,
14
- config() {
15
- return {
16
- build: {
17
- ssr: true
18
- },
19
- publicDir: false
20
- };
21
- }
22
- });
23
- }
24
- exports.cloudRunAdapter = cloudRunAdapter;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
- const fs$1 = require("../../../chunks/fs.cjs");
6
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
7
- require("../../../chunks/error-handler.cjs");
8
- function cloudflarePagesAdapter(opts = {}) {
9
- const env = process?.env;
10
- return adapters_shared_vite.viteAdapter({
11
- name: "cloudflare-pages",
12
- origin: env?.CF_PAGES_URL ?? env?.ORIGIN ?? "https://your.cloudflare.pages.dev",
13
- ssg: opts.ssg,
14
- staticPaths: opts.staticPaths,
15
- cleanStaticGenerated: true,
16
- config() {
17
- return {
18
- resolve: {
19
- conditions: ["webworker", "worker"]
20
- },
21
- ssr: {
22
- target: "webworker",
23
- noExternal: true,
24
- external: ["node:async_hooks"]
25
- },
26
- build: {
27
- ssr: true,
28
- rollupOptions: {
29
- output: {
30
- format: "es",
31
- hoistTransitiveImports: false
32
- }
33
- }
34
- },
35
- publicDir: false
36
- };
37
- },
38
- async generate({ clientOutDir, serverOutDir, basePathname, assetsDir }) {
39
- const routesJsonPath = path.join(clientOutDir, "_routes.json");
40
- const hasRoutesJson = fs.existsSync(routesJsonPath);
41
- if (!hasRoutesJson && opts.functionRoutes !== false) {
42
- let pathName = assetsDir ? path.join(basePathname, assetsDir) : basePathname;
43
- if (!pathName.endsWith("/")) {
44
- pathName += "/";
45
- }
46
- const routesJson = {
47
- version: 1,
48
- include: [basePathname + "*"],
49
- exclude: [pathName + "build/*", pathName + "assets/*"]
50
- };
51
- await fs.promises.writeFile(routesJsonPath, JSON.stringify(routesJson, void 0, 2));
52
- }
53
- const workerJsPath = path.join(clientOutDir, "_worker.js");
54
- const hasWorkerJs = fs.existsSync(workerJsPath);
55
- if (!hasWorkerJs) {
56
- const importPath = path.relative(clientOutDir, path.join(serverOutDir, "entry.cloudflare-pages"));
57
- await fs.promises.writeFile(
58
- workerJsPath,
59
- `import { fetch } from "${fs$1.normalizePathSlash(importPath)}"; export default { fetch };`
60
- );
61
- }
62
- }
63
- });
64
- }
65
- exports.cloudflarePagesAdapter = cloudflarePagesAdapter;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
4
- require("node:path");
5
- require("node:fs");
6
- require("../../../chunks/error-handler.cjs");
7
- function denoServerAdapter(opts = {}) {
8
- const env = process?.env;
9
- return adapters_shared_vite.viteAdapter({
10
- name: opts.name || "deno-server",
11
- origin: env?.ORIGIN ?? env?.URL ?? "https://yoursitename.qwik.dev",
12
- ssg: opts.ssg,
13
- cleanStaticGenerated: true,
14
- config() {
15
- return {
16
- resolve: {
17
- conditions: ["webworker", "worker"]
18
- },
19
- ssr: {
20
- target: "webworker",
21
- noExternal: true,
22
- external: ["node:async_hooks"]
23
- },
24
- build: {
25
- ssr: true,
26
- target: "esnext",
27
- rollupOptions: {
28
- output: {
29
- format: "es",
30
- hoistTransitiveImports: false
31
- }
32
- }
33
- },
34
- publicDir: false
35
- };
36
- }
37
- });
38
- }
39
- exports.denoServerAdapter = denoServerAdapter;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
6
- require("../../../chunks/error-handler.cjs");
7
- function netlifyEdgeAdapter(opts = {}) {
8
- const env = process?.env;
9
- return adapters_shared_vite.viteAdapter({
10
- name: "netlify-edge",
11
- origin: env?.ORIGIN ?? env?.URL ?? "https://yoursitename.netlify.app",
12
- ssg: opts.ssg,
13
- staticPaths: opts.staticPaths,
14
- cleanStaticGenerated: true,
15
- config(config) {
16
- const outDir = config.build?.outDir || ".netlify/edge-functions/entry.netlify-edge";
17
- return {
18
- resolve: {
19
- conditions: ["webworker", "worker"]
20
- },
21
- ssr: {
22
- target: "webworker",
23
- noExternal: true,
24
- external: ["node:async_hooks"]
25
- },
26
- build: {
27
- ssr: true,
28
- outDir,
29
- rollupOptions: {
30
- output: {
31
- format: "es",
32
- hoistTransitiveImports: false
33
- }
34
- }
35
- },
36
- publicDir: false
37
- };
38
- },
39
- async generate({ serverOutDir, basePathname }) {
40
- if (opts.functionRoutes !== false) {
41
- const excludedPath = [];
42
- if (typeof opts.excludedPath === "string") {
43
- excludedPath.push(opts.excludedPath);
44
- } else if (Array.isArray(opts.excludedPath)) {
45
- excludedPath.push(...opts.excludedPath);
46
- } else {
47
- excludedPath.push(
48
- "/build/*",
49
- "/favicon.ico",
50
- "/robots.txt",
51
- "/mainifest.json",
52
- "/~partytown/*",
53
- "/service-worker.js",
54
- "/sitemap.xml"
55
- );
56
- }
57
- const netlifyEdgeManifest = {
58
- functions: [
59
- {
60
- path: basePathname + "*",
61
- function: "entry.netlify-edge",
62
- cache: "manual",
63
- excludedPath
64
- }
65
- ],
66
- version: 1
67
- };
68
- const jsPath = path.join(serverOutDir, "entry.netlify-edge.js");
69
- const mjsPath = path.join(serverOutDir, "entry.netlify-edge.mjs");
70
- if (fs.existsSync(mjsPath)) {
71
- await fs.promises.writeFile(
72
- jsPath,
73
- [
74
- `import entry_netlifyEdge from './entry.netlify-edge.mjs';`,
75
- `export default entry_netlifyEdge;`
76
- ].join("\n")
77
- );
78
- }
79
- const netlifyEdgeFnsDir = adapters_shared_vite.getParentDir(serverOutDir, "edge-functions");
80
- await fs.promises.writeFile(
81
- path.join(netlifyEdgeFnsDir, "manifest.json"),
82
- JSON.stringify(netlifyEdgeManifest, null, 2)
83
- );
84
- }
85
- }
86
- });
87
- }
88
- exports.netlifyEdgeAdapter = netlifyEdgeAdapter;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
4
- require("node:path");
5
- require("node:fs");
6
- require("../../../chunks/error-handler.cjs");
7
- function nodeServerAdapter(opts = {}) {
8
- const env = process?.env;
9
- return adapters_shared_vite.viteAdapter({
10
- name: opts.name || "node-server",
11
- origin: env?.ORIGIN ?? env?.URL ?? "https://yoursitename.qwik.dev",
12
- ssg: opts.ssg,
13
- cleanStaticGenerated: true,
14
- config() {
15
- return {
16
- ssr: {
17
- target: "node"
18
- },
19
- build: {
20
- ssr: true
21
- },
22
- publicDir: false
23
- };
24
- }
25
- });
26
- }
27
- exports.nodeServerAdapter = nodeServerAdapter;
@@ -1,306 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
4
- const fs = require("node:fs");
5
- const errorHandler = require("../../../chunks/error-handler.cjs");
6
- async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
7
- if (pathName && !pathName.endsWith("/")) {
8
- pathName += "/";
9
- }
10
- const ignorePathnames = /* @__PURE__ */ new Set([
11
- pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
12
- pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
13
- ]);
14
- const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
15
- const notFounds = [];
16
- const loadItem = async (fsDir, fsName, pathname) => {
17
- pathname = normalizeTrailingSlash(pathname);
18
- if (ignorePathnames.has(pathname)) {
19
- return;
20
- }
21
- const fsPath = path.join(fsDir, fsName);
22
- if (fsName === "index.html" || fsName === "q-data.json") {
23
- if (!staticPaths.has(pathname) && cleanStatic) {
24
- await fs.promises.unlink(fsPath);
25
- }
26
- return;
27
- }
28
- if (fsName === "404.html") {
29
- const notFoundHtml = await fs.promises.readFile(fsPath, "utf-8");
30
- notFounds.push([pathname, notFoundHtml]);
31
- return;
32
- }
33
- const stat = await fs.promises.stat(fsPath);
34
- if (stat.isDirectory()) {
35
- await loadDir(fsPath, pathname + fsName + "/");
36
- } else if (stat.isFile()) {
37
- staticPaths.add(pathname + fsName);
38
- }
39
- };
40
- const loadDir = async (fsDir, pathname) => {
41
- const itemNames = await fs.promises.readdir(fsDir);
42
- await Promise.all(itemNames.map((i) => loadItem(fsDir, i, pathname)));
43
- };
44
- if (fs.existsSync(clientOutDir)) {
45
- await loadDir(clientOutDir, pathName);
46
- }
47
- const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
48
- const staticPathsCode = createStaticPathsCode(staticPaths);
49
- await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
50
- }
51
- function normalizeTrailingSlash(pathname) {
52
- if (!pathname.endsWith("/")) {
53
- return pathname + "/";
54
- }
55
- return pathname;
56
- }
57
- function createNotFoundPathsCode(basePathname, notFounds) {
58
- notFounds.sort((a, b) => {
59
- if (a[0].length > b[0].length) {
60
- return -1;
61
- }
62
- if (a[0].length < b[0].length) {
63
- return 1;
64
- }
65
- if (a[0] < b[0]) {
66
- return -1;
67
- }
68
- if (a[0] > b[0]) {
69
- return 1;
70
- }
71
- return 0;
72
- });
73
- if (!notFounds.some((r) => r[0] === basePathname)) {
74
- const html = errorHandler.getErrorHtml(404, "Resource Not Found");
75
- notFounds.push([basePathname, html]);
76
- }
77
- return JSON.stringify(notFounds, null, 2).slice(1, -1);
78
- }
79
- function createStaticPathsCode(staticPaths) {
80
- return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
81
- }
82
- const injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
83
- const promises = /* @__PURE__ */ new Set();
84
- const doReplace = async (path2) => {
85
- const code = await fs.promises.readFile(path2, "utf-8");
86
- let replaced = false;
87
- const newCode = code.replace(
88
- /(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
89
- (_, _quote, type) => {
90
- replaced = true;
91
- return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
92
- }
93
- );
94
- if (replaced) {
95
- await fs.promises.writeFile(path2, newCode);
96
- }
97
- };
98
- const walk = async (dir) => {
99
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
100
- for (const entry of entries) {
101
- if (entry.isDirectory()) {
102
- await walk(path.join(dir, entry.name));
103
- } else if (entry.name.endsWith("js")) {
104
- const p = doReplace(path.join(dir, entry.name)).finally(() => {
105
- promises.delete(p);
106
- });
107
- promises.add(p);
108
- }
109
- }
110
- };
111
- await walk(outDir);
112
- await Promise.all(promises);
113
- };
114
- function viteAdapter(opts) {
115
- let qwikRouterPlugin = null;
116
- let qwikVitePlugin = null;
117
- let serverOutDir = null;
118
- let renderModulePath = null;
119
- let qwikRouterConfigModulePath = null;
120
- let isSsrBuild = false;
121
- let viteCommand;
122
- const outputEntries = [];
123
- const plugin = {
124
- name: `vite-plugin-qwik-router-ssg-${opts.name}`,
125
- enforce: "post",
126
- apply: "build",
127
- config(config) {
128
- if (typeof opts.config === "function") {
129
- config = opts.config(config);
130
- }
131
- config.define = {
132
- "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "production"),
133
- ...config.define
134
- };
135
- return config;
136
- },
137
- configResolved(config) {
138
- isSsrBuild = !!config.build.ssr;
139
- viteCommand = config.command;
140
- if (isSsrBuild) {
141
- qwikRouterPlugin = config.plugins.find(
142
- (p) => p.name === "vite-plugin-qwik-router"
143
- );
144
- if (!qwikRouterPlugin) {
145
- throw new Error("Missing vite-plugin-qwik-router");
146
- }
147
- qwikVitePlugin = config.plugins.find(
148
- (p) => p.name === "vite-plugin-qwik"
149
- );
150
- if (!qwikVitePlugin) {
151
- throw new Error("Missing vite-plugin-qwik");
152
- }
153
- serverOutDir = config.build.outDir;
154
- if (config.build?.ssr !== true) {
155
- throw new Error(
156
- `"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
157
- );
158
- }
159
- if (!config.build?.rollupOptions?.input) {
160
- throw new Error(
161
- `"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
162
- );
163
- }
164
- }
165
- },
166
- buildStart() {
167
- if (isSsrBuild && opts.ssg !== null) {
168
- const { srcDir } = qwikVitePlugin.api.getOptions();
169
- if (viteCommand === "build" && serverOutDir && srcDir) {
170
- this.emitFile({
171
- id: "@qwik-router-config",
172
- type: "chunk",
173
- fileName: "@qwik-router-config.js"
174
- });
175
- this.emitFile({
176
- id: `${srcDir}/entry.ssr`,
177
- type: "chunk",
178
- fileName: "entry.ssr.js"
179
- });
180
- }
181
- }
182
- },
183
- generateBundle(_, bundles) {
184
- if (isSsrBuild) {
185
- outputEntries.length = 0;
186
- for (const fileName in bundles) {
187
- const chunk = bundles[fileName];
188
- if (chunk.type === "chunk" && chunk.isEntry) {
189
- outputEntries.push(fileName);
190
- if (chunk.name === "entry.ssr") {
191
- renderModulePath = path.join(serverOutDir, fileName);
192
- } else if (chunk.name === "@qwik-router-config") {
193
- qwikRouterConfigModulePath = path.join(serverOutDir, fileName);
194
- }
195
- }
196
- }
197
- }
198
- },
199
- closeBundle: {
200
- sequential: true,
201
- async handler() {
202
- if (isSsrBuild && serverOutDir && qwikRouterPlugin?.api && qwikVitePlugin?.api) {
203
- const staticPaths = opts.staticPaths || [];
204
- const routes = qwikRouterPlugin.api.getRoutes();
205
- const basePathname = qwikRouterPlugin.api.getBasePathname();
206
- const clientOutDir = qwikVitePlugin.api.getClientOutDir();
207
- const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
208
- const assetsDir = qwikVitePlugin.api.getAssetsDir();
209
- const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
210
- if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
211
- let ssgOrigin = opts.ssg?.origin ?? opts.origin;
212
- if (!ssgOrigin) {
213
- ssgOrigin = `https://yoursite.qwik.dev`;
214
- }
215
- if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
216
- ssgOrigin = `https://${ssgOrigin}`;
217
- }
218
- if (ssgOrigin.startsWith("//")) {
219
- ssgOrigin = `https:${ssgOrigin}`;
220
- }
221
- try {
222
- ssgOrigin = new URL(ssgOrigin).origin;
223
- } catch {
224
- this.warn(
225
- `Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
226
- );
227
- ssgOrigin = `https://yoursite.qwik.dev`;
228
- }
229
- const staticGenerate = await Promise.resolve().then(() => require("../../../ssg/index.cjs"));
230
- const generateOpts = {
231
- maxWorkers: opts.maxWorkers,
232
- basePathname,
233
- outDir: clientPublicOutDir,
234
- rootDir,
235
- ...opts.ssg,
236
- origin: ssgOrigin,
237
- renderModulePath,
238
- qwikRouterConfigModulePath
239
- };
240
- const staticGenerateResult = await staticGenerate.generate(generateOpts);
241
- if (staticGenerateResult.errors > 0) {
242
- const err = new Error(
243
- `Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`
244
- );
245
- err.stack = void 0;
246
- this.error(err);
247
- }
248
- staticPaths.push(...staticGenerateResult.staticPaths);
249
- }
250
- await postBuild(
251
- clientPublicOutDir,
252
- serverOutDir,
253
- assetsDir ? path.join(basePathname, assetsDir) : basePathname,
254
- staticPaths,
255
- !!opts.cleanStaticGenerated
256
- );
257
- if (typeof opts.generate === "function") {
258
- await opts.generate({
259
- outputEntries,
260
- serverOutDir,
261
- clientOutDir,
262
- clientPublicOutDir,
263
- basePathname,
264
- routes,
265
- assetsDir,
266
- warn: (message) => this.warn(message),
267
- error: (message) => this.error(message)
268
- });
269
- }
270
- this.warn(
271
- `
272
- ==============================================
273
- Note: Make sure that you are serving the built files with proper cache headers.
274
- See https://qwik.dev/docs/deployments/#cache-headers for more information.
275
- ==============================================`
276
- );
277
- if (opts.ssg !== null) {
278
- setTimeout(() => {
279
- console.warn(
280
- "SSG seems to be hanging after completion, forcing process to exit. Everything is likely fine."
281
- );
282
- process.exit(0);
283
- }, 5e3).unref();
284
- }
285
- }
286
- }
287
- }
288
- };
289
- return plugin;
290
- }
291
- function getParentDir(startDir, dirName) {
292
- const root = path.resolve("/");
293
- let dir = startDir;
294
- for (let i = 0; i < 20; i++) {
295
- dir = path.dirname(dir);
296
- if (path.basename(dir) === dirName) {
297
- return dir;
298
- }
299
- if (dir === root) {
300
- break;
301
- }
302
- }
303
- throw new Error(`Unable to find "${dirName}" directory from "${startDir}"`);
304
- }
305
- exports.getParentDir = getParentDir;
306
- exports.viteAdapter = viteAdapter;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
4
- require("node:path");
5
- require("node:fs");
6
- require("../../../chunks/error-handler.cjs");
7
- function ssgAdapter(opts) {
8
- return adapters_shared_vite.viteAdapter({
9
- name: "static-site-generation",
10
- origin: opts.origin,
11
- ssg: {
12
- include: ["/*"],
13
- ...opts
14
- }
15
- });
16
- }
17
- const staticAdapter = ssgAdapter;
18
- exports.ssgAdapter = ssgAdapter;
19
- exports.staticAdapter = staticAdapter;
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs");
4
- const path = require("node:path");
5
- const adapters_shared_vite = require("../../shared/vite/index.cjs");
6
- require("../../../chunks/error-handler.cjs");
7
- function vercelEdgeAdapter(opts = {}) {
8
- return adapters_shared_vite.viteAdapter({
9
- name: "vercel-edge",
10
- origin: process?.env?.VERCEL_URL || "https://yoursitename.vercel.app",
11
- ssg: opts.ssg,
12
- staticPaths: opts.staticPaths,
13
- cleanStaticGenerated: true,
14
- config(config) {
15
- const outDir = config.build?.outDir || path.join(".vercel", "output", "functions", "_qwik-router.func");
16
- return {
17
- resolve: {
18
- conditions: opts.target === "node" ? ["node", "import", "module", "browser", "default"] : ["edge-light", "webworker", "worker", "browser", "module", "main"]
19
- },
20
- ssr: {
21
- target: opts.target === "node" ? "node" : "webworker",
22
- noExternal: true
23
- },
24
- build: {
25
- ssr: true,
26
- outDir,
27
- rollupOptions: {
28
- output: {
29
- format: "es",
30
- hoistTransitiveImports: false
31
- }
32
- }
33
- },
34
- publicDir: false
35
- };
36
- },
37
- async generate({ clientPublicOutDir, serverOutDir, basePathname, outputEntries }) {
38
- const vercelOutputDir = adapters_shared_vite.getParentDir(serverOutDir, "output");
39
- if (opts.outputConfig !== false) {
40
- const vercelOutputConfig = {
41
- routes: [
42
- { handle: "filesystem" },
43
- {
44
- src: basePathname + ".*",
45
- dest: "/_qwik-router"
46
- }
47
- ],
48
- version: 3
49
- };
50
- await fs.promises.writeFile(
51
- path.join(vercelOutputDir, "config.json"),
52
- JSON.stringify(vercelOutputConfig, null, 2)
53
- );
54
- }
55
- let entrypoint = opts.vcConfigEntryPoint;
56
- if (!entrypoint) {
57
- if (outputEntries.some((n) => n === "entry.vercel-edge.mjs")) {
58
- entrypoint = "entry.vercel-edge.mjs";
59
- } else {
60
- entrypoint = "entry.vercel-edge.js";
61
- }
62
- }
63
- const vcConfigPath = path.join(serverOutDir, ".vc-config.json");
64
- const vcConfig = {
65
- runtime: "edge",
66
- entrypoint,
67
- envVarsInUse: opts.vcConfigEnvVarsInUse
68
- };
69
- await fs.promises.writeFile(vcConfigPath, JSON.stringify(vcConfig, null, 2));
70
- let vercelStaticDir = path.join(vercelOutputDir, "static");
71
- const basePathnameParts = basePathname.split("/").filter((p) => p.length > 0);
72
- if (basePathnameParts.length > 0) {
73
- vercelStaticDir = path.join(vercelStaticDir, ...basePathnameParts);
74
- }
75
- await fs.promises.rm(vercelStaticDir, { recursive: true, force: true });
76
- await fs.promises.mkdir(path.dirname(vercelStaticDir), { recursive: true });
77
- await fs.promises.rename(clientPublicOutDir, vercelStaticDir);
78
- }
79
- });
80
- }
81
- exports.vercelEdgeAdapter = vercelEdgeAdapter;