@qwik.dev/router 2.0.0-beta.3 → 2.0.0-beta.31

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 (84) hide show
  1. package/adapters/static/vite.d.ts +1 -1
  2. package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
  3. package/lib/adapters/azure-swa/vite/index.mjs +39 -44
  4. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  5. package/lib/adapters/bun-server/vite/index.mjs +6 -7
  6. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  7. package/lib/adapters/cloud-run/vite/index.mjs +6 -7
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  9. package/lib/adapters/cloudflare-pages/vite/index.mjs +23 -32
  10. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/deno-server/vite/index.mjs +13 -9
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  13. package/lib/adapters/netlify-edge/vite/index.mjs +22 -36
  14. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  15. package/lib/adapters/node-server/vite/index.mjs +6 -7
  16. package/lib/adapters/shared/vite/index.d.ts +7 -19
  17. package/lib/adapters/shared/vite/index.mjs +244 -233
  18. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  19. package/lib/adapters/ssg/vite/index.mjs +17 -0
  20. package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
  21. package/lib/adapters/vercel-edge/vite/index.mjs +33 -19
  22. package/lib/chunks/deepFreeze.qwik.mjs +18 -0
  23. package/lib/chunks/error-handler.mjs +57 -0
  24. package/lib/chunks/fs.mjs +144 -0
  25. package/lib/chunks/http-error.qwik.mjs +35 -0
  26. package/lib/chunks/not-found-wrapper.qwik.mjs +25 -0
  27. package/lib/chunks/pathname.mjs +105 -0
  28. package/lib/chunks/redirect-handler.mjs +6 -0
  29. package/lib/chunks/routing.qwik.mjs +821 -0
  30. package/lib/chunks/system.mjs +333 -0
  31. package/lib/chunks/url.mjs +61 -0
  32. package/lib/chunks/use-functions.qwik.mjs +35 -0
  33. package/lib/chunks/worker-thread.qwik.mjs +2573 -0
  34. package/lib/index.d.ts +362 -142
  35. package/lib/index.qwik.mjs +949 -1244
  36. package/lib/middleware/aws-lambda/index.d.ts +0 -5
  37. package/lib/middleware/aws-lambda/index.mjs +14 -17
  38. package/lib/middleware/azure-swa/index.mjs +16 -221
  39. package/lib/middleware/bun/index.d.ts +11 -0
  40. package/lib/middleware/bun/index.mjs +50 -97
  41. package/lib/middleware/cloudflare-pages/index.mjs +22 -31
  42. package/lib/middleware/deno/index.d.ts +11 -0
  43. package/lib/middleware/deno/index.mjs +49 -97
  44. package/lib/middleware/firebase/index.mjs +6 -15
  45. package/lib/middleware/netlify-edge/index.mjs +22 -32
  46. package/lib/middleware/node/index.mjs +31 -105
  47. package/lib/middleware/request-handler/index.d.ts +163 -88
  48. package/lib/middleware/request-handler/index.mjs +1458 -1260
  49. package/lib/middleware/vercel-edge/index.mjs +27 -36
  50. package/lib/modules.d.ts +11 -16
  51. package/lib/service-worker/index.mjs +4 -0
  52. package/lib/{static → ssg}/index.d.ts +45 -13
  53. package/lib/ssg/index.mjs +336 -0
  54. package/lib/vite/index.d.ts +38 -10
  55. package/lib/vite/index.mjs +2067 -26841
  56. package/modules.d.ts +11 -16
  57. package/package.json +62 -67
  58. package/ssg.d.ts +2 -0
  59. package/static.d.ts +1 -1
  60. package/lib/adapters/azure-swa/vite/index.cjs +0 -96
  61. package/lib/adapters/bun-server/vite/index.cjs +0 -50
  62. package/lib/adapters/cloud-run/vite/index.cjs +0 -47
  63. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
  64. package/lib/adapters/deno-server/vite/index.cjs +0 -62
  65. package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
  66. package/lib/adapters/node-server/vite/index.cjs +0 -50
  67. package/lib/adapters/shared/vite/index.cjs +0 -378
  68. package/lib/adapters/static/vite/index.cjs +0 -368
  69. package/lib/adapters/static/vite/index.d.ts +0 -10
  70. package/lib/adapters/static/vite/index.mjs +0 -331
  71. package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
  72. package/lib/index.qwik.cjs +0 -1947
  73. package/lib/middleware/node/index.cjs +0 -314
  74. package/lib/middleware/request-handler/index.cjs +0 -1614
  75. package/lib/service-worker.cjs +0 -17
  76. package/lib/service-worker.mjs +0 -15
  77. package/lib/static/deno.mjs +0 -8
  78. package/lib/static/index.cjs +0 -67
  79. package/lib/static/index.mjs +0 -48
  80. package/lib/static/node.cjs +0 -1124
  81. package/lib/static/node.mjs +0 -1086
  82. package/lib/vite/index.cjs +0 -27445
  83. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  84. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -1,16 +1,102 @@
1
- // packages/qwik-router/src/adapters/shared/vite/index.ts
2
- import fs2 from "node:fs";
3
- import { basename, dirname, join as join2, resolve } from "node:path";
1
+ import { join, resolve, dirname, basename } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import fs from 'node:fs';
4
+ import { g as getErrorHtml } from '../../../chunks/error-handler.mjs';
4
5
 
5
- // packages/qwik-router/src/adapters/shared/vite/post-build.ts
6
- import { getErrorHtml } from "../../../middleware/request-handler/index.mjs";
7
- import fs from "node:fs";
8
- import { join } from "node:path";
9
- async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) {
6
+ const SSG_WORKER_IMPORT_PREFIX = "@qwik-router-ssg-worker/";
7
+ function ssgWorkerImportPlugin() {
8
+ return {
9
+ name: "qwik-router-ssg-worker-imports",
10
+ enforce: "pre",
11
+ async resolveId(id, importer) {
12
+ if (!id.startsWith(SSG_WORKER_IMPORT_PREFIX)) {
13
+ return null;
14
+ }
15
+ const subpath = id.slice(SSG_WORKER_IMPORT_PREFIX.length);
16
+ const sourceId = fileURLToPath(new URL(`../../${subpath}`, import.meta.url));
17
+ const resolved = await this.resolve(sourceId, importer, {
18
+ skipSelf: true
19
+ });
20
+ return `${(resolved ?? {
21
+ id: sourceId
22
+ }).id}?ssg-worker`;
23
+ }
24
+ };
25
+ }
26
+
27
+ function normalizeTrailingSlash(pathname) {
28
+ if (!pathname.endsWith("/")) {
29
+ return pathname + "/";
30
+ }
31
+ return pathname;
32
+ }
33
+ function createNotFoundPathsCode(basePathname, notFounds) {
34
+ notFounds.sort((a, b) => {
35
+ if (a[0].length > b[0].length) {
36
+ return -1;
37
+ }
38
+ if (a[0].length < b[0].length) {
39
+ return 1;
40
+ }
41
+ if (a[0] < b[0]) {
42
+ return -1;
43
+ }
44
+ if (a[0] > b[0]) {
45
+ return 1;
46
+ }
47
+ return 0;
48
+ });
49
+ if (!notFounds.some((r) => r[0] === basePathname)) {
50
+ const html = getErrorHtml(404, "Resource Not Found");
51
+ notFounds.push([
52
+ basePathname,
53
+ html
54
+ ]);
55
+ }
56
+ return JSON.stringify(notFounds, null, 2).slice(1, -1);
57
+ }
58
+ function createStaticPathsCode(staticPaths) {
59
+ return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
60
+ }
61
+ const injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
62
+ const promises = /* @__PURE__ */ new Set();
63
+ const doReplace = async (path) => {
64
+ const code = await fs.promises.readFile(path, "utf-8");
65
+ let replaced = false;
66
+ const newCode = code.replace(/(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g, (_, _quote, type) => {
67
+ replaced = true;
68
+ return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
69
+ });
70
+ if (replaced) {
71
+ await fs.promises.writeFile(path, newCode);
72
+ }
73
+ };
74
+ const walk = async (dir) => {
75
+ const entries = await fs.promises.readdir(dir, {
76
+ withFileTypes: true
77
+ });
78
+ for (const entry of entries) {
79
+ if (entry.isDirectory()) {
80
+ await walk(join(dir, entry.name));
81
+ } else if (entry.name.endsWith("js")) {
82
+ const p = doReplace(join(dir, entry.name)).finally(() => {
83
+ promises.delete(p);
84
+ });
85
+ promises.add(p);
86
+ }
87
+ }
88
+ };
89
+ await walk(outDir);
90
+ await Promise.all(promises);
91
+ };
92
+ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
10
93
  if (pathName && !pathName.endsWith("/")) {
11
94
  pathName += "/";
12
95
  }
13
- const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]);
96
+ const ignorePathnames = /* @__PURE__ */ new Set([
97
+ pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
98
+ pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
99
+ ]);
14
100
  const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
15
101
  const notFounds = [];
16
102
  const loadItem = async (fsDir, fsName, pathname) => {
@@ -27,7 +113,10 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
27
113
  }
28
114
  if (fsName === "404.html") {
29
115
  const notFoundHtml = await fs.promises.readFile(fsPath, "utf-8");
30
- notFounds.push([pathname, notFoundHtml]);
116
+ notFounds.push([
117
+ pathname,
118
+ notFoundHtml
119
+ ]);
31
120
  return;
32
121
  }
33
122
  const stat = await fs.promises.stat(fsPath);
@@ -44,110 +133,21 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
44
133
  if (fs.existsSync(clientOutDir)) {
45
134
  await loadDir(clientOutDir, pathName);
46
135
  }
47
- const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format);
48
- const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format);
49
- return {
50
- notFoundPathsCode,
51
- staticPathsCode
52
- };
53
- }
54
- function normalizeTrailingSlash(pathname) {
55
- if (!pathname.endsWith("/")) {
56
- return pathname + "/";
57
- }
58
- return pathname;
59
- }
60
- function createNotFoundPathsModule(basePathname, notFounds, format) {
61
- notFounds.sort((a, b) => {
62
- if (a[0].length > b[0].length) {
63
- return -1;
64
- }
65
- if (a[0].length < b[0].length) {
66
- return 1;
67
- }
68
- if (a[0] < b[0]) {
69
- return -1;
70
- }
71
- if (a[0] > b[0]) {
72
- return 1;
73
- }
74
- return 0;
75
- });
76
- if (!notFounds.some((r) => r[0] === basePathname)) {
77
- const html = getErrorHtml(404, "Resource Not Found");
78
- notFounds.push([basePathname, html]);
79
- }
80
- const c = [];
81
- c.push(`const notFounds = ${JSON.stringify(notFounds, null, 2)};`);
82
- c.push(`function getNotFound(p) {`);
83
- c.push(` for (const r of notFounds) {`);
84
- c.push(` if (p.startsWith(r[0])) {`);
85
- c.push(` return r[1];`);
86
- c.push(` }`);
87
- c.push(` }`);
88
- c.push(` return "Resource Not Found";`);
89
- c.push(`}`);
90
- if (format === "cjs") {
91
- c.push("exports.getNotFound = getNotFound;");
92
- } else {
93
- c.push("export { getNotFound };");
94
- }
95
- return c.join("\n");
96
- }
97
- function createStaticPathsModule(basePathname, staticPaths, format) {
98
- const assetsPath = basePathname + "assets/";
99
- const baseBuildPath = basePathname + "build/";
100
- const c = [];
101
- c.push(
102
- `const staticPaths = new Set(${JSON.stringify(
103
- Array.from(new Set(staticPaths)).sort()
104
- )});`
105
- );
106
- c.push(`function isStaticPath(method, url) {`);
107
- c.push(` if (method.toUpperCase() !== 'GET') {`);
108
- c.push(` return false;`);
109
- c.push(` }`);
110
- c.push(` const p = url.pathname;`);
111
- c.push(` if (p.startsWith(${JSON.stringify(baseBuildPath)})) {`);
112
- c.push(` return true;`);
113
- c.push(` }`);
114
- c.push(` if (p.startsWith(${JSON.stringify(assetsPath)})) {`);
115
- c.push(` return true;`);
116
- c.push(` }`);
117
- c.push(` if (staticPaths.has(p)) {`);
118
- c.push(` return true;`);
119
- c.push(` }`);
120
- c.push(` if (p.endsWith('/q-data.json')) {`);
121
- c.push(` const pWithoutQdata = p.replace(/\\/q-data.json$/, '');`);
122
- c.push(` if (staticPaths.has(pWithoutQdata + '/')) {`);
123
- c.push(` return true;`);
124
- c.push(` }`);
125
- c.push(` if (staticPaths.has(pWithoutQdata)) {`);
126
- c.push(` return true;`);
127
- c.push(` }`);
128
- c.push(` }`);
129
- c.push(` return false;`);
130
- c.push(`}`);
131
- if (format === "cjs") {
132
- c.push("exports.isStaticPath = isStaticPath;");
133
- } else {
134
- c.push("export { isStaticPath };");
135
- }
136
- return c.join("\n");
136
+ const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
137
+ const staticPathsCode = createStaticPathsCode(staticPaths);
138
+ await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
137
139
  }
138
140
 
139
- // packages/qwik-router/src/adapters/shared/vite/index.ts
141
+ const QWIK_SSG_ENTRY_ID = "@qwik-ssg-entry";
142
+ const QWIK_SSG_ENTRY_RESOLVED = "\0@qwik-ssg-entry";
140
143
  function viteAdapter(opts) {
141
144
  let qwikRouterPlugin = null;
142
145
  let qwikVitePlugin = null;
143
146
  let serverOutDir = null;
144
- let renderModulePath = null;
145
- let qwikRouterConfigModulePath = null;
146
- let isSsrBuild = false;
147
- let format = "esm";
147
+ let viteCommand;
148
148
  const outputEntries = [];
149
149
  const plugin = {
150
- name: `vite-plugin-qwik-router-${opts.name}`,
150
+ name: `vite-plugin-qwik-router-ssg-${opts.name}`,
151
151
  enforce: "post",
152
152
  apply: "build",
153
153
  config(config) {
@@ -161,154 +161,175 @@ function viteAdapter(opts) {
161
161
  return config;
162
162
  },
163
163
  configResolved(config) {
164
- var _a, _b, _c, _d;
165
- isSsrBuild = !!config.build.ssr;
166
- if (isSsrBuild) {
167
- qwikRouterPlugin = config.plugins.find(
168
- (p) => p.name === "vite-plugin-qwik-router"
169
- );
170
- if (!qwikRouterPlugin) {
171
- throw new Error("Missing vite-plugin-qwik-router");
172
- }
173
- qwikVitePlugin = config.plugins.find(
174
- (p) => p.name === "vite-plugin-qwik"
175
- );
176
- if (!qwikVitePlugin) {
177
- throw new Error("Missing vite-plugin-qwik");
178
- }
179
- serverOutDir = config.build.outDir;
180
- if (((_a = config.build) == null ? void 0 : _a.ssr) !== true) {
181
- throw new Error(
182
- `"build.ssr" must be set to "true" in order to use the "${opts.name}" adapter.`
183
- );
184
- }
185
- if (!((_c = (_b = config.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.input)) {
186
- throw new Error(
187
- `"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
188
- );
189
- }
190
- if (((_d = config.ssr) == null ? void 0 : _d.format) === "cjs") {
191
- format = "cjs";
164
+ viteCommand = config.command;
165
+ qwikRouterPlugin = config.plugins.find((p) => p.name === "vite-plugin-qwik-router");
166
+ if (!qwikRouterPlugin) {
167
+ throw new Error("Missing vite-plugin-qwik-router");
168
+ }
169
+ qwikVitePlugin = config.plugins.find((p) => p.name === "vite-plugin-qwik");
170
+ if (!qwikVitePlugin) {
171
+ throw new Error("Missing vite-plugin-qwik");
172
+ }
173
+ serverOutDir = config.build.outDir;
174
+ },
175
+ resolveId(id) {
176
+ if (id === QWIK_SSG_ENTRY_ID) {
177
+ return QWIK_SSG_ENTRY_RESOLVED;
178
+ }
179
+ },
180
+ load(id) {
181
+ if (id !== QWIK_SSG_ENTRY_RESOLVED) {
182
+ return;
183
+ }
184
+ const { srcDir } = qwikVitePlugin.api.getOptions();
185
+ const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
186
+ const basePathname = qwikRouterPlugin.api.getBasePathname();
187
+ const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
188
+ let ssgOrigin = opts.ssg?.origin ?? opts.origin;
189
+ if (!ssgOrigin) {
190
+ ssgOrigin = `https://yoursite.qwik.dev`;
191
+ }
192
+ if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
193
+ ssgOrigin = `https://${ssgOrigin}`;
194
+ }
195
+ if (ssgOrigin.startsWith("//")) {
196
+ ssgOrigin = `https:${ssgOrigin}`;
197
+ }
198
+ try {
199
+ ssgOrigin = new URL(ssgOrigin).origin;
200
+ } catch {
201
+ this.warn(`Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`);
202
+ ssgOrigin = `https://yoursite.qwik.dev`;
203
+ }
204
+ const ssgOpts = {
205
+ origin: ssgOrigin,
206
+ outDir: clientPublicOutDir,
207
+ basePathname,
208
+ rootDir,
209
+ ...opts.ssg,
210
+ maxWorkers: opts.maxWorkers
211
+ };
212
+ for (const key of Object.keys(ssgOpts)) {
213
+ if (ssgOpts[key] === void 0) {
214
+ delete ssgOpts[key];
192
215
  }
193
216
  }
217
+ return [
218
+ `import { isMainThread } from 'node:worker_threads';`,
219
+ `import render from '${srcDir}/entry.ssr';`,
220
+ `import qwikRouterConfig from '@qwik-router-config';`,
221
+ `import { runSsg, startWorker } from '@qwik.dev/router/ssg';`,
222
+ ``,
223
+ `const ssgOpts = ${JSON.stringify(ssgOpts)};`,
224
+ ``,
225
+ `// Parse --quiet / --debug CLI flags`,
226
+ `const args = isMainThread ? process.argv.slice(2) : [];`,
227
+ `if (args.includes('--quiet')) ssgOpts.log = 'quiet';`,
228
+ `if (args.includes('--debug')) ssgOpts.log = 'debug';`,
229
+ ``,
230
+ `if (isMainThread) {`,
231
+ ` await runSsg({`,
232
+ ` render,`,
233
+ ` qwikRouterConfig,`,
234
+ ` workerFilePath: new URL(import.meta.url).href,`,
235
+ ` ...ssgOpts,`,
236
+ ` });`,
237
+ `} else {`,
238
+ ` await startWorker({ render, qwikRouterConfig });`,
239
+ `}`
240
+ ].join("\n");
241
+ },
242
+ buildStart() {
243
+ if (this.environment.config.consumer === "server" && opts.ssg !== null && viteCommand === "build" && serverOutDir) {
244
+ this.emitFile({
245
+ id: QWIK_SSG_ENTRY_ID,
246
+ type: "chunk",
247
+ fileName: "run-ssg.js"
248
+ });
249
+ }
194
250
  },
195
251
  generateBundle(_, bundles) {
196
- if (isSsrBuild) {
252
+ if (this.environment.config.consumer === "server") {
197
253
  outputEntries.length = 0;
198
254
  for (const fileName in bundles) {
199
255
  const chunk = bundles[fileName];
200
256
  if (chunk.type === "chunk" && chunk.isEntry) {
201
257
  outputEntries.push(fileName);
202
- if (chunk.name === "entry.ssr") {
203
- renderModulePath = join2(serverOutDir, fileName);
204
- } else if (chunk.name === "@qwik-router-config") {
205
- qwikRouterConfigModulePath = join2(serverOutDir, fileName);
206
- }
207
258
  }
208
259
  }
209
- if (!renderModulePath) {
210
- throw new Error(
211
- 'Unable to find "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?'
212
- );
213
- }
214
- if (!qwikRouterConfigModulePath) {
215
- throw new Error(
216
- 'Unable to find "@qwik-router-config" entry point. Did you forget to add it to "build.rollupOptions.input"?'
217
- );
218
- }
219
260
  }
220
261
  },
221
262
  closeBundle: {
222
263
  sequential: true,
223
264
  async handler() {
224
- var _a;
225
- if (isSsrBuild && opts.ssg !== null && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
265
+ if (this.environment.config.consumer === "server" && serverOutDir && qwikRouterPlugin?.api && qwikVitePlugin?.api) {
226
266
  const staticPaths = opts.staticPaths || [];
227
267
  const routes = qwikRouterPlugin.api.getRoutes();
228
268
  const basePathname = qwikRouterPlugin.api.getBasePathname();
229
269
  const clientOutDir = qwikVitePlugin.api.getClientOutDir();
230
270
  const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
231
271
  const assetsDir = qwikVitePlugin.api.getAssetsDir();
232
- const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
233
- if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
234
- let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
235
- if (!ssgOrigin) {
236
- ssgOrigin = `https://yoursite.qwik.dev`;
237
- }
238
- if (ssgOrigin.length > 0 && !/:\/\//.test(ssgOrigin)) {
239
- ssgOrigin = `https://${ssgOrigin}`;
240
- }
241
- if (ssgOrigin.startsWith("//")) {
242
- ssgOrigin = `https:${ssgOrigin}`;
243
- }
244
- try {
245
- ssgOrigin = new URL(ssgOrigin).origin;
246
- } catch (e) {
247
- this.warn(
248
- `Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
249
- );
250
- ssgOrigin = `https://yoursite.qwik.dev`;
251
- }
252
- const staticGenerate = await import("../../../static/index.mjs");
253
- const generateOpts = {
254
- maxWorkers: opts.maxWorkers,
255
- basePathname,
256
- outDir: clientPublicOutDir,
257
- rootDir,
258
- ...opts.ssg,
259
- origin: ssgOrigin,
260
- renderModulePath,
261
- qwikRouterConfigModulePath
262
- };
263
- const staticGenerateResult = await staticGenerate.generate(generateOpts);
264
- if (staticGenerateResult.errors > 0) {
265
- const err = new Error(
266
- `Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`
267
- );
272
+ if (opts.ssg !== null && clientOutDir && clientPublicOutDir) {
273
+ const runSsgPath = join(serverOutDir, "run-ssg.js");
274
+ const { spawn } = await import('node:child_process');
275
+ const ssgExitCode = await new Promise((resolve2, reject) => {
276
+ const child = spawn(process.execPath, [
277
+ runSsgPath
278
+ ], {
279
+ stdio: [
280
+ "ignore",
281
+ "inherit",
282
+ "inherit"
283
+ ],
284
+ env: {
285
+ ...process.env,
286
+ NODE_ENV: process.env.NODE_ENV || "production"
287
+ }
288
+ });
289
+ child.on("close", resolve2);
290
+ child.on("error", reject);
291
+ });
292
+ if (ssgExitCode !== 0) {
293
+ const err = new Error(`Error while running SSG from "${opts.name}" adapter. At least one path failed to render.`);
268
294
  err.stack = void 0;
269
295
  this.error(err);
270
296
  }
271
- staticPaths.push(...staticGenerateResult.staticPaths);
272
- const { staticPathsCode, notFoundPathsCode } = await postBuild(
273
- clientPublicOutDir,
274
- assetsDir ? join2(basePathname, assetsDir) : basePathname,
275
- staticPaths,
276
- format,
277
- !!opts.cleanStaticGenerated
278
- );
279
- await Promise.all([
280
- fs2.promises.writeFile(join2(serverOutDir, RESOLVED_STATIC_PATHS_ID), staticPathsCode),
281
- fs2.promises.writeFile(
282
- join2(serverOutDir, RESOLVED_NOT_FOUND_PATHS_ID),
283
- notFoundPathsCode
284
- )
285
- ]);
286
- if (typeof opts.generate === "function") {
287
- await opts.generate({
288
- outputEntries,
289
- serverOutDir,
290
- clientOutDir,
291
- clientPublicOutDir,
292
- basePathname,
293
- routes,
294
- assetsDir,
295
- warn: (message) => this.warn(message),
296
- error: (message) => this.error(message)
297
- });
297
+ const fs = await import('node:fs');
298
+ const staticPathsFile = join(clientPublicOutDir, "_static-paths.json");
299
+ try {
300
+ const content = await fs.promises.readFile(staticPathsFile, "utf-8");
301
+ staticPaths.push(...JSON.parse(content));
302
+ await fs.promises.unlink(staticPathsFile);
303
+ } catch {
298
304
  }
299
- this.warn(
300
- `
305
+ }
306
+ await postBuild(clientPublicOutDir, serverOutDir, assetsDir ? join(basePathname, assetsDir) : basePathname, staticPaths, !!opts.cleanStaticGenerated);
307
+ if (typeof opts.generate === "function") {
308
+ await opts.generate({
309
+ outputEntries,
310
+ serverOutDir,
311
+ clientOutDir,
312
+ clientPublicOutDir,
313
+ basePathname,
314
+ routes,
315
+ assetsDir,
316
+ warn: (message) => this.warn(message),
317
+ error: (message) => this.error(message)
318
+ });
319
+ }
320
+ this.warn(`
301
321
  ==============================================
302
322
  Note: Make sure that you are serving the built files with proper cache headers.
303
323
  See https://qwik.dev/docs/deployments/#cache-headers for more information.
304
- ==============================================`
305
- );
306
- }
324
+ ==============================================`);
307
325
  }
308
326
  }
309
327
  }
310
328
  };
311
- return plugin;
329
+ return [
330
+ ssgWorkerImportPlugin(),
331
+ plugin
332
+ ];
312
333
  }
313
334
  function getParentDir(startDir, dirName) {
314
335
  const root = resolve("/");
@@ -324,15 +345,5 @@ function getParentDir(startDir, dirName) {
324
345
  }
325
346
  throw new Error(`Unable to find "${dirName}" directory from "${startDir}"`);
326
347
  }
327
- var STATIC_PATHS_ID = "@qwik-router-static-paths";
328
- var RESOLVED_STATIC_PATHS_ID = `${STATIC_PATHS_ID}.js`;
329
- var NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
330
- var RESOLVED_NOT_FOUND_PATHS_ID = `${NOT_FOUND_PATHS_ID}.js`;
331
- export {
332
- NOT_FOUND_PATHS_ID,
333
- RESOLVED_NOT_FOUND_PATHS_ID,
334
- RESOLVED_STATIC_PATHS_ID,
335
- STATIC_PATHS_ID,
336
- getParentDir,
337
- viteAdapter
338
- };
348
+
349
+ export { getParentDir, viteAdapter };
@@ -0,0 +1,13 @@
1
+ import type { SsgRenderOptions } from '../../../ssg';
2
+
3
+ /** @public */
4
+ export declare function ssgAdapter(opts: SsgAdapterOptions): any;
5
+
6
+ /** @public */
7
+ export declare interface SsgAdapterOptions extends Omit<SsgRenderOptions, 'outDir'> {
8
+ }
9
+
10
+ /** @public @deprecated Use `ssgAdapter` instead. */
11
+ export declare const staticAdapter: typeof ssgAdapter;
12
+
13
+ export { }
@@ -0,0 +1,17 @@
1
+ import { viteAdapter } from '../../shared/vite/index.mjs';
2
+
3
+ function ssgAdapter(opts) {
4
+ return viteAdapter({
5
+ name: "static-site-generation",
6
+ origin: opts.origin,
7
+ ssg: {
8
+ include: [
9
+ "/*"
10
+ ],
11
+ ...opts
12
+ }
13
+ });
14
+ }
15
+ const staticAdapter = ssgAdapter;
16
+
17
+ export { ssgAdapter, staticAdapter };
@@ -1,7 +1,7 @@
1
1
  import { ServerAdapterOptions } from '../../shared/vite';
2
- import type { StaticGenerateRenderOptions } from '@qwik.dev/router/static';
2
+ import type { SsgRenderOptions } from 'packages/qwik-router/src/ssg';
3
3
 
4
- export { StaticGenerateRenderOptions }
4
+ export { SsgRenderOptions }
5
5
 
6
6
  /** @public */
7
7
  export declare function vercelEdgeAdapter(opts?: VercelEdgeAdapterOptions): any;
@@ -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.mts` file.
38
+ * Define the `target` property in the `ssr` object in the `vite.config.ts` file.
39
39
  *
40
40
  * Defaults to `webworker`.
41
41
  */