@qwik.dev/router 2.0.0-beta.35 → 2.0.0-beta.37

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.
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import { join, relative } from 'node:path';
3
3
  import { n as normalizePathSlash } from '../../../chunks/fs.mjs';
4
+ import { e as ensureSlash } from '../../../chunks/pathname.mjs';
4
5
  import { viteAdapter } from '../../shared/vite/index.mjs';
5
6
 
6
7
  function cloudflarePagesAdapter(opts = {}) {
@@ -42,10 +43,7 @@ function cloudflarePagesAdapter(opts = {}) {
42
43
  const routesJsonPath = join(clientOutDir, "_routes.json");
43
44
  const hasRoutesJson = fs.existsSync(routesJsonPath);
44
45
  if (!hasRoutesJson && opts.functionRoutes !== false) {
45
- let pathName = assetsDir ? join(basePathname, assetsDir) : basePathname;
46
- if (!pathName.endsWith("/")) {
47
- pathName += "/";
48
- }
46
+ const pathName = ensureSlash(assetsDir ? join(basePathname, assetsDir) : basePathname);
49
47
  const routesJson = {
50
48
  version: 1,
51
49
  include: [
@@ -2,6 +2,8 @@ import { join, resolve, dirname, basename } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import fs from 'node:fs';
4
4
  import { g as getErrorHtml } from '../../../chunks/error-handler.mjs';
5
+ import { L as LOADER_REGEX } from '../../../chunks/request-path.mjs';
6
+ import { e as ensureSlash } from '../../../chunks/pathname.mjs';
5
7
 
6
8
  const SSG_WORKER_IMPORT_PREFIX = "@qwik-router-ssg-worker/";
7
9
  function ssgWorkerImportPlugin() {
@@ -24,12 +26,6 @@ function ssgWorkerImportPlugin() {
24
26
  };
25
27
  }
26
28
 
27
- function normalizeTrailingSlash(pathname) {
28
- if (!pathname.endsWith("/")) {
29
- return pathname + "/";
30
- }
31
- return pathname;
32
- }
33
29
  function createNotFoundPathsCode(basePathname, notFounds) {
34
30
  notFounds.sort((a, b) => {
35
31
  if (a[0].length > b[0].length) {
@@ -91,21 +87,22 @@ const injectStatics = async (staticPathsCode, notFoundPathsCode, outDir) => {
91
87
  };
92
88
  async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths, cleanStatic) {
93
89
  if (pathName && !pathName.endsWith("/")) {
94
- pathName += "/";
90
+ pathName = ensureSlash(pathName);
95
91
  }
92
+ const pathNameBase = pathName || "/";
96
93
  const ignorePathnames = /* @__PURE__ */ new Set([
97
- pathName + "/" + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
98
- pathName + "/" + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
94
+ pathNameBase + (globalThis.__QWIK_BUILD_DIR__ || "build") + "/",
95
+ pathNameBase + (globalThis.__QWIK_ASSETS_DIR__ || "assets") + "/"
99
96
  ]);
100
- const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
97
+ const staticPaths = new Set(userStaticPaths.map(ensureSlash));
101
98
  const notFounds = [];
102
99
  const loadItem = async (fsDir, fsName, pathname) => {
103
- pathname = normalizeTrailingSlash(pathname);
100
+ pathname = ensureSlash(pathname);
104
101
  if (ignorePathnames.has(pathname)) {
105
102
  return;
106
103
  }
107
104
  const fsPath = join(fsDir, fsName);
108
- if (fsName === "index.html" || fsName === "q-data.json") {
105
+ if (fsName === "index.html" || LOADER_REGEX.test("/" + fsName)) {
109
106
  if (!staticPaths.has(pathname) && cleanStatic) {
110
107
  await fs.promises.unlink(fsPath);
111
108
  }
@@ -121,7 +118,7 @@ async function postBuild(clientOutDir, serverOutDir, pathName, userStaticPaths,
121
118
  }
122
119
  const stat = await fs.promises.stat(fsPath);
123
120
  if (stat.isDirectory()) {
124
- await loadDir(fsPath, pathname + fsName + "/");
121
+ await loadDir(fsPath, ensureSlash(pathname + fsName));
125
122
  } else if (stat.isFile()) {
126
123
  staticPaths.add(pathname + fsName);
127
124
  }
@@ -227,16 +224,22 @@ function viteAdapter(opts) {
227
224
  `if (args.includes('--quiet')) ssgOpts.log = 'quiet';`,
228
225
  `if (args.includes('--debug')) ssgOpts.log = 'debug';`,
229
226
  ``,
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
- `}`
227
+ // Fire-and-forget instead of top-level await. On the worker/edge SSR target Vite
228
+ // inlines dynamic imports, and Rollup then reads the inlined `./system` namespace
229
+ // before it is initialized across a top-level await. See rollup/rollup#4166.
230
+ // runSsg/startWorker keep the process alive (worker handles) and call process.exit.
231
+ `const ssgRun = isMainThread`,
232
+ ` ? runSsg({`,
233
+ ` render,`,
234
+ ` qwikRouterConfig,`,
235
+ ` workerFilePath: new URL(import.meta.url).href,`,
236
+ ` ...ssgOpts,`,
237
+ ` })`,
238
+ ` : startWorker({ render, qwikRouterConfig });`,
239
+ `ssgRun.catch((err) => {`,
240
+ ` console.error(err);`,
241
+ ` process.exit(1);`,
242
+ `});`
240
243
  ].join("\n");
241
244
  },
242
245
  buildStart() {