@qwik.dev/router 2.0.0-beta.5 → 2.0.0-beta.6

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 (49) 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/bun-server/vite/index.d.ts +2 -2
  4. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  5. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  6. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  7. package/lib/adapters/netlify-edge/vite/index.cjs +1 -0
  8. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  9. package/lib/adapters/netlify-edge/vite/index.mjs +1 -0
  10. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/shared/vite/index.cjs +88 -128
  12. package/lib/adapters/shared/vite/index.d.ts +9 -15
  13. package/lib/adapters/shared/vite/index.mjs +88 -124
  14. package/lib/adapters/{static → ssg}/vite/index.cjs +95 -124
  15. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  16. package/lib/adapters/{static → ssg}/vite/index.mjs +93 -123
  17. package/lib/adapters/vercel-edge/vite/index.d.ts +2 -2
  18. package/lib/index.qwik.cjs +7 -9
  19. package/lib/index.qwik.mjs +8 -10
  20. package/lib/middleware/aws-lambda/index.d.ts +3 -2
  21. package/lib/middleware/aws-lambda/index.mjs +2 -4
  22. package/lib/middleware/azure-swa/index.mjs +6 -6
  23. package/lib/middleware/bun/index.mjs +4 -6
  24. package/lib/middleware/cloudflare-pages/index.mjs +4 -6
  25. package/lib/middleware/deno/index.mjs +8 -7
  26. package/lib/middleware/firebase/index.mjs +1 -3
  27. package/lib/middleware/netlify-edge/index.mjs +7 -6
  28. package/lib/middleware/node/index.cjs +4 -8
  29. package/lib/middleware/node/index.mjs +7 -7
  30. package/lib/middleware/request-handler/index.cjs +331 -268
  31. package/lib/middleware/request-handler/index.d.ts +18 -6
  32. package/lib/middleware/request-handler/index.mjs +335 -264
  33. package/lib/middleware/vercel-edge/index.mjs +7 -6
  34. package/lib/modules.d.ts +4 -12
  35. package/lib/{static → ssg}/deno.mjs +1 -1
  36. package/lib/{static → ssg}/index.cjs +1 -1
  37. package/lib/{static → ssg}/index.d.ts +17 -17
  38. package/lib/{static → ssg}/index.mjs +1 -1
  39. package/lib/{static → ssg}/node.cjs +16 -16
  40. package/lib/{static → ssg}/node.mjs +15 -15
  41. package/lib/vite/index.cjs +10260 -10437
  42. package/lib/vite/index.mjs +8220 -8387
  43. package/modules.d.ts +4 -12
  44. package/package.json +19 -8
  45. package/ssg.d.ts +2 -0
  46. package/static.d.ts +1 -1
  47. package/lib/adapters/static/vite/index.d.ts +0 -10
  48. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  49. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -1,16 +1,18 @@
1
1
  // packages/qwik-router/src/adapters/shared/vite/index.ts
2
- import fs2 from "node:fs";
3
2
  import { basename, dirname, join as join2, resolve } from "node:path";
4
3
 
5
4
  // packages/qwik-router/src/adapters/shared/vite/post-build.ts
6
5
  import { getErrorHtml } from "../../../middleware/request-handler/index.mjs";
7
6
  import fs from "node:fs";
8
7
  import { join } from "node:path";
9
- async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) {
8
+ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
10
9
  if (pathName && !pathName.endsWith("/")) {
11
10
  pathName += "/";
12
11
  }
13
- const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]);
12
+ const ignorePathnames = /* @__PURE__ */ new Set([
13
+ pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
14
+ pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
15
+ ]);
14
16
  const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
15
17
  const notFounds = [];
16
18
  const loadItem = async (fsDir, fsName, pathname) => {
@@ -44,12 +46,9 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
44
46
  if (fs.existsSync(clientOutDir)) {
45
47
  await loadDir(clientOutDir, pathName);
46
48
  }
47
- const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format);
48
- const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format);
49
- return {
50
- notFoundPathsCode,
51
- staticPathsCode
52
- };
49
+ const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
50
+ const staticPathsCode = createStaticPathsCode(staticPaths);
51
+ await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
53
52
  }
54
53
  function normalizeTrailingSlash(pathname) {
55
54
  if (!pathname.endsWith("/")) {
@@ -57,7 +56,7 @@ function normalizeTrailingSlash(pathname) {
57
56
  }
58
57
  return pathname;
59
58
  }
60
- function createNotFoundPathsModule(basePathname, notFounds, format) {
59
+ function createNotFoundPathsCode(basePathname, notFounds) {
61
60
  notFounds.sort((a, b) => {
62
61
  if (a[0].length > b[0].length) {
63
62
  return -1;
@@ -77,64 +76,43 @@ function createNotFoundPathsModule(basePathname, notFounds, format) {
77
76
  const html = getErrorHtml(404, "Resource Not Found");
78
77
  notFounds.push([basePathname, html]);
79
78
  }
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");
79
+ return JSON.stringify(notFounds, null, 2).slice(1, -1);
96
80
  }
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");
81
+ function createStaticPathsCode(staticPaths) {
82
+ return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
137
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
+ };
138
116
 
139
117
  // packages/qwik-router/src/adapters/shared/vite/index.ts
140
118
  function viteAdapter(opts) {
@@ -144,10 +122,9 @@ function viteAdapter(opts) {
144
122
  let renderModulePath = null;
145
123
  let qwikRouterConfigModulePath = null;
146
124
  let isSsrBuild = false;
147
- let format = "esm";
148
125
  const outputEntries = [];
149
126
  const plugin = {
150
- name: `vite-plugin-qwik-router-${opts.name}`,
127
+ name: `vite-plugin-qwik-router-ssg-${opts.name}`,
151
128
  enforce: "post",
152
129
  apply: "build",
153
130
  config(config) {
@@ -161,7 +138,7 @@ function viteAdapter(opts) {
161
138
  return config;
162
139
  },
163
140
  configResolved(config) {
164
- var _a, _b, _c, _d;
141
+ var _a, _b, _c;
165
142
  isSsrBuild = !!config.build.ssr;
166
143
  if (isSsrBuild) {
167
144
  qwikRouterPlugin = config.plugins.find(
@@ -187,9 +164,21 @@ function viteAdapter(opts) {
187
164
  `"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
188
165
  );
189
166
  }
190
- if (((_d = config.ssr) == null ? void 0 : _d.format) === "cjs") {
191
- format = "cjs";
192
- }
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
+ });
193
182
  }
194
183
  },
195
184
  generateBundle(_, bundles) {
@@ -206,23 +195,13 @@ function viteAdapter(opts) {
206
195
  }
207
196
  }
208
197
  }
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
198
  }
220
199
  },
221
200
  closeBundle: {
222
201
  sequential: true,
223
202
  async handler() {
224
203
  var _a;
225
- if (isSsrBuild && opts.ssg !== null && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
204
+ if (isSsrBuild && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
226
205
  const staticPaths = opts.staticPaths || [];
227
206
  const routes = qwikRouterPlugin.api.getRoutes();
228
207
  const basePathname = qwikRouterPlugin.api.getBasePathname();
@@ -230,7 +209,7 @@ function viteAdapter(opts) {
230
209
  const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
231
210
  const assetsDir = qwikVitePlugin.api.getAssetsDir();
232
211
  const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
233
- if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
212
+ if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
234
213
  let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
235
214
  if (!ssgOrigin) {
236
215
  ssgOrigin = `https://yoursite.qwik.dev`;
@@ -243,13 +222,13 @@ function viteAdapter(opts) {
243
222
  }
244
223
  try {
245
224
  ssgOrigin = new URL(ssgOrigin).origin;
246
- } catch (e) {
225
+ } catch {
247
226
  this.warn(
248
227
  `Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
249
228
  );
250
229
  ssgOrigin = `https://yoursite.qwik.dev`;
251
230
  }
252
- const staticGenerate = await import("../../../static/index.mjs");
231
+ const staticGenerate = await import("../../../ssg/index.mjs");
253
232
  const generateOpts = {
254
233
  maxWorkers: opts.maxWorkers,
255
234
  basePathname,
@@ -269,41 +248,34 @@ function viteAdapter(opts) {
269
248
  this.error(err);
270
249
  }
271
250
  staticPaths.push(...staticGenerateResult.staticPaths);
272
- const { staticPathsCode, notFoundPathsCode } = await postBuild(
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,
273
264
  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
- });
298
- }
299
- this.warn(
300
- `
265
+ basePathname,
266
+ routes,
267
+ assetsDir,
268
+ warn: (message) => this.warn(message),
269
+ error: (message) => this.error(message)
270
+ });
271
+ }
272
+ this.warn(
273
+ `
301
274
  ==============================================
302
275
  Note: Make sure that you are serving the built files with proper cache headers.
303
276
  See https://qwik.dev/docs/deployments/#cache-headers for more information.
304
277
  ==============================================`
305
- );
306
- }
278
+ );
307
279
  }
308
280
  }
309
281
  }
@@ -324,15 +296,7 @@ function getParentDir(startDir, dirName) {
324
296
  }
325
297
  throw new Error(`Unable to find "${dirName}" directory from "${startDir}"`);
326
298
  }
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
299
  export {
332
- NOT_FOUND_PATHS_ID,
333
- RESOLVED_NOT_FOUND_PATHS_ID,
334
- RESOLVED_STATIC_PATHS_ID,
335
- STATIC_PATHS_ID,
336
300
  getParentDir,
337
301
  viteAdapter
338
302
  };
@@ -27,26 +27,29 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // packages/qwik-router/src/adapters/static/vite/index.ts
30
+ // packages/qwik-router/src/adapters/ssg/vite/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ssgAdapter: () => ssgAdapter,
33
34
  staticAdapter: () => staticAdapter
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
 
37
38
  // packages/qwik-router/src/adapters/shared/vite/index.ts
38
- var import_node_fs2 = __toESM(require("node:fs"), 1);
39
39
  var import_node_path2 = require("node:path");
40
40
 
41
41
  // packages/qwik-router/src/adapters/shared/vite/post-build.ts
42
42
  var import_request_handler = require("@qwik.dev/router/middleware/request-handler");
43
43
  var import_node_fs = __toESM(require("node:fs"), 1);
44
44
  var import_node_path = require("node:path");
45
- async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanStatic) {
45
+ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
46
46
  if (pathName && !pathName.endsWith("/")) {
47
47
  pathName += "/";
48
48
  }
49
- const ignorePathnames = /* @__PURE__ */ new Set([pathName + "build/", pathName + "assets/"]);
49
+ const ignorePathnames = /* @__PURE__ */ new Set([
50
+ pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
51
+ pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
52
+ ]);
50
53
  const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
51
54
  const notFounds = [];
52
55
  const loadItem = async (fsDir, fsName, pathname) => {
@@ -80,12 +83,9 @@ async function postBuild(clientOutDir, pathName, userStaticPaths, format, cleanS
80
83
  if (import_node_fs.default.existsSync(clientOutDir)) {
81
84
  await loadDir(clientOutDir, pathName);
82
85
  }
83
- const notFoundPathsCode = createNotFoundPathsModule(pathName, notFounds, format);
84
- const staticPathsCode = createStaticPathsModule(pathName, staticPaths, format);
85
- return {
86
- notFoundPathsCode,
87
- staticPathsCode
88
- };
86
+ const notFoundPathsCode = createNotFoundPathsCode(pathName, notFounds);
87
+ const staticPathsCode = createStaticPathsCode(staticPaths);
88
+ await injectStatics(staticPathsCode, notFoundPathsCode, serverOutDir);
89
89
  }
90
90
  function normalizeTrailingSlash(pathname) {
91
91
  if (!pathname.endsWith("/")) {
@@ -93,7 +93,7 @@ function normalizeTrailingSlash(pathname) {
93
93
  }
94
94
  return pathname;
95
95
  }
96
- function createNotFoundPathsModule(basePathname, notFounds, format) {
96
+ function createNotFoundPathsCode(basePathname, notFounds) {
97
97
  notFounds.sort((a, b) => {
98
98
  if (a[0].length > b[0].length) {
99
99
  return -1;
@@ -113,64 +113,43 @@ function createNotFoundPathsModule(basePathname, notFounds, format) {
113
113
  const html = (0, import_request_handler.getErrorHtml)(404, "Resource Not Found");
114
114
  notFounds.push([basePathname, html]);
115
115
  }
116
- const c = [];
117
- c.push(`const notFounds = ${JSON.stringify(notFounds, null, 2)};`);
118
- c.push(`function getNotFound(p) {`);
119
- c.push(` for (const r of notFounds) {`);
120
- c.push(` if (p.startsWith(r[0])) {`);
121
- c.push(` return r[1];`);
122
- c.push(` }`);
123
- c.push(` }`);
124
- c.push(` return "Resource Not Found";`);
125
- c.push(`}`);
126
- if (format === "cjs") {
127
- c.push("exports.getNotFound = getNotFound;");
128
- } else {
129
- c.push("export { getNotFound };");
130
- }
131
- return c.join("\n");
116
+ return JSON.stringify(notFounds, null, 2).slice(1, -1);
132
117
  }
133
- function createStaticPathsModule(basePathname, staticPaths, format) {
134
- const assetsPath = basePathname + "assets/";
135
- const baseBuildPath = basePathname + "build/";
136
- const c = [];
137
- c.push(
138
- `const staticPaths = new Set(${JSON.stringify(
139
- Array.from(new Set(staticPaths)).sort()
140
- )});`
141
- );
142
- c.push(`function isStaticPath(method, url) {`);
143
- c.push(` if (method.toUpperCase() !== 'GET') {`);
144
- c.push(` return false;`);
145
- c.push(` }`);
146
- c.push(` const p = url.pathname;`);
147
- c.push(` if (p.startsWith(${JSON.stringify(baseBuildPath)})) {`);
148
- c.push(` return true;`);
149
- c.push(` }`);
150
- c.push(` if (p.startsWith(${JSON.stringify(assetsPath)})) {`);
151
- c.push(` return true;`);
152
- c.push(` }`);
153
- c.push(` if (staticPaths.has(p)) {`);
154
- c.push(` return true;`);
155
- c.push(` }`);
156
- c.push(` if (p.endsWith('/q-data.json')) {`);
157
- c.push(` const pWithoutQdata = p.replace(/\\/q-data.json$/, '');`);
158
- c.push(` if (staticPaths.has(pWithoutQdata + '/')) {`);
159
- c.push(` return true;`);
160
- c.push(` }`);
161
- c.push(` if (staticPaths.has(pWithoutQdata)) {`);
162
- c.push(` return true;`);
163
- c.push(` }`);
164
- c.push(` }`);
165
- c.push(` return false;`);
166
- c.push(`}`);
167
- if (format === "cjs") {
168
- c.push("exports.isStaticPath = isStaticPath;");
169
- } else {
170
- c.push("export { isStaticPath };");
171
- }
172
- return c.join("\n");
118
+ function createStaticPathsCode(staticPaths) {
119
+ return JSON.stringify(Array.from(new Set(staticPaths)).sort()).slice(1, -1);
173
120
  }
121
+ var injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
122
+ const promises = /* @__PURE__ */ new Set();
123
+ const doReplace = async (path) => {
124
+ const code = await import_node_fs.default.promises.readFile(path, "utf-8");
125
+ let replaced = false;
126
+ const newCode = code.replace(
127
+ /(['"])__QWIK_ROUTER_(STATIC_PATHS|NOT_FOUND)_ARRAY__\1/g,
128
+ (_, _quote, type) => {
129
+ replaced = true;
130
+ return type === "STATIC_PATHS" ? staticPathsCode : notFoundPathsCode;
131
+ }
132
+ );
133
+ if (replaced) {
134
+ await import_node_fs.default.promises.writeFile(path, newCode);
135
+ }
136
+ };
137
+ const walk = async (dir) => {
138
+ const entries = await import_node_fs.default.promises.readdir(dir, { withFileTypes: true });
139
+ for (const entry of entries) {
140
+ if (entry.isDirectory()) {
141
+ await walk((0, import_node_path.join)(dir, entry.name));
142
+ } else if (entry.name.endsWith("js")) {
143
+ const p = doReplace((0, import_node_path.join)(dir, entry.name)).finally(() => {
144
+ promises.delete(p);
145
+ });
146
+ promises.add(p);
147
+ }
148
+ }
149
+ };
150
+ await walk(outDir);
151
+ await Promise.all(promises);
152
+ };
174
153
 
175
154
  // packages/qwik-router/src/adapters/shared/vite/index.ts
176
155
  function viteAdapter(opts) {
@@ -180,10 +159,9 @@ function viteAdapter(opts) {
180
159
  let renderModulePath = null;
181
160
  let qwikRouterConfigModulePath = null;
182
161
  let isSsrBuild = false;
183
- let format = "esm";
184
162
  const outputEntries = [];
185
163
  const plugin = {
186
- name: `vite-plugin-qwik-router-${opts.name}`,
164
+ name: `vite-plugin-qwik-router-ssg-${opts.name}`,
187
165
  enforce: "post",
188
166
  apply: "build",
189
167
  config(config) {
@@ -197,7 +175,7 @@ function viteAdapter(opts) {
197
175
  return config;
198
176
  },
199
177
  configResolved(config) {
200
- var _a, _b, _c, _d;
178
+ var _a, _b, _c;
201
179
  isSsrBuild = !!config.build.ssr;
202
180
  if (isSsrBuild) {
203
181
  qwikRouterPlugin = config.plugins.find(
@@ -223,9 +201,21 @@ function viteAdapter(opts) {
223
201
  `"build.rollupOptions.input" must be set in order to use the "${opts.name}" adapter.`
224
202
  );
225
203
  }
226
- if (((_d = config.ssr) == null ? void 0 : _d.format) === "cjs") {
227
- format = "cjs";
228
- }
204
+ }
205
+ },
206
+ buildStart() {
207
+ if (isSsrBuild && opts.ssg !== null) {
208
+ const { srcDir } = qwikVitePlugin.api.getOptions();
209
+ this.emitFile({
210
+ id: "@qwik-router-config",
211
+ type: "chunk",
212
+ fileName: "@qwik-router-config.js"
213
+ });
214
+ this.emitFile({
215
+ id: `${srcDir}/entry.ssr`,
216
+ type: "chunk",
217
+ fileName: "entry.ssr.js"
218
+ });
229
219
  }
230
220
  },
231
221
  generateBundle(_, bundles) {
@@ -242,23 +232,13 @@ function viteAdapter(opts) {
242
232
  }
243
233
  }
244
234
  }
245
- if (!renderModulePath) {
246
- throw new Error(
247
- 'Unable to find "entry.ssr" entry point. Did you forget to add it to "build.rollupOptions.input"?'
248
- );
249
- }
250
- if (!qwikRouterConfigModulePath) {
251
- throw new Error(
252
- 'Unable to find "@qwik-router-config" entry point. Did you forget to add it to "build.rollupOptions.input"?'
253
- );
254
- }
255
235
  }
256
236
  },
257
237
  closeBundle: {
258
238
  sequential: true,
259
239
  async handler() {
260
240
  var _a;
261
- if (isSsrBuild && opts.ssg !== null && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
241
+ if (isSsrBuild && serverOutDir && (qwikRouterPlugin == null ? void 0 : qwikRouterPlugin.api) && (qwikVitePlugin == null ? void 0 : qwikVitePlugin.api)) {
262
242
  const staticPaths = opts.staticPaths || [];
263
243
  const routes = qwikRouterPlugin.api.getRoutes();
264
244
  const basePathname = qwikRouterPlugin.api.getBasePathname();
@@ -266,7 +246,7 @@ function viteAdapter(opts) {
266
246
  const clientPublicOutDir = qwikVitePlugin.api.getClientPublicOutDir();
267
247
  const assetsDir = qwikVitePlugin.api.getAssetsDir();
268
248
  const rootDir = qwikVitePlugin.api.getRootDir() ?? void 0;
269
- if (renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
249
+ if (opts.ssg !== null && renderModulePath && qwikRouterConfigModulePath && clientOutDir && clientPublicOutDir) {
270
250
  let ssgOrigin = ((_a = opts.ssg) == null ? void 0 : _a.origin) ?? opts.origin;
271
251
  if (!ssgOrigin) {
272
252
  ssgOrigin = `https://yoursite.qwik.dev`;
@@ -279,13 +259,13 @@ function viteAdapter(opts) {
279
259
  }
280
260
  try {
281
261
  ssgOrigin = new URL(ssgOrigin).origin;
282
- } catch (e) {
262
+ } catch {
283
263
  this.warn(
284
264
  `Invalid "origin" option: "${ssgOrigin}". Using default origin: "https://yoursite.qwik.dev"`
285
265
  );
286
266
  ssgOrigin = `https://yoursite.qwik.dev`;
287
267
  }
288
- const staticGenerate = await import("../../../static/index.cjs");
268
+ const staticGenerate = await import("../../../ssg/index.cjs");
289
269
  const generateOpts = {
290
270
  maxWorkers: opts.maxWorkers,
291
271
  basePathname,
@@ -305,56 +285,45 @@ function viteAdapter(opts) {
305
285
  this.error(err);
306
286
  }
307
287
  staticPaths.push(...staticGenerateResult.staticPaths);
308
- const { staticPathsCode, notFoundPathsCode } = await postBuild(
288
+ }
289
+ await postBuild(
290
+ clientPublicOutDir,
291
+ serverOutDir,
292
+ assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname,
293
+ staticPaths,
294
+ !!opts.cleanStaticGenerated
295
+ );
296
+ if (typeof opts.generate === "function") {
297
+ await opts.generate({
298
+ outputEntries,
299
+ serverOutDir,
300
+ clientOutDir,
309
301
  clientPublicOutDir,
310
- assetsDir ? (0, import_node_path2.join)(basePathname, assetsDir) : basePathname,
311
- staticPaths,
312
- format,
313
- !!opts.cleanStaticGenerated
314
- );
315
- await Promise.all([
316
- import_node_fs2.default.promises.writeFile((0, import_node_path2.join)(serverOutDir, RESOLVED_STATIC_PATHS_ID), staticPathsCode),
317
- import_node_fs2.default.promises.writeFile(
318
- (0, import_node_path2.join)(serverOutDir, RESOLVED_NOT_FOUND_PATHS_ID),
319
- notFoundPathsCode
320
- )
321
- ]);
322
- if (typeof opts.generate === "function") {
323
- await opts.generate({
324
- outputEntries,
325
- serverOutDir,
326
- clientOutDir,
327
- clientPublicOutDir,
328
- basePathname,
329
- routes,
330
- assetsDir,
331
- warn: (message) => this.warn(message),
332
- error: (message) => this.error(message)
333
- });
334
- }
335
- this.warn(
336
- `
302
+ basePathname,
303
+ routes,
304
+ assetsDir,
305
+ warn: (message) => this.warn(message),
306
+ error: (message) => this.error(message)
307
+ });
308
+ }
309
+ this.warn(
310
+ `
337
311
  ==============================================
338
312
  Note: Make sure that you are serving the built files with proper cache headers.
339
313
  See https://qwik.dev/docs/deployments/#cache-headers for more information.
340
314
  ==============================================`
341
- );
342
- }
315
+ );
343
316
  }
344
317
  }
345
318
  }
346
319
  };
347
320
  return plugin;
348
321
  }
349
- var STATIC_PATHS_ID = "@qwik-router-static-paths";
350
- var RESOLVED_STATIC_PATHS_ID = `${STATIC_PATHS_ID}.js`;
351
- var NOT_FOUND_PATHS_ID = "@qwik-router-not-found-paths";
352
- var RESOLVED_NOT_FOUND_PATHS_ID = `${NOT_FOUND_PATHS_ID}.js`;
353
322
 
354
- // packages/qwik-router/src/adapters/static/vite/index.ts
355
- function staticAdapter(opts) {
323
+ // packages/qwik-router/src/adapters/ssg/vite/index.ts
324
+ function ssgAdapter(opts) {
356
325
  return viteAdapter({
357
- name: "static-generate",
326
+ name: "static-site-generation",
358
327
  origin: opts.origin,
359
328
  ssg: {
360
329
  include: ["/*"],
@@ -362,7 +331,9 @@ function staticAdapter(opts) {
362
331
  }
363
332
  });
364
333
  }
334
+ var staticAdapter = ssgAdapter;
365
335
  // Annotate the CommonJS export names for ESM import in node:
366
336
  0 && (module.exports = {
337
+ ssgAdapter,
367
338
  staticAdapter
368
339
  });
@@ -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 { }