Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ jobs:

- run: pnpm install
- if: matrix.settings.wasm
run: pnpm install wasm-pack
run: pnpm install -w wasm-pack

- name: Lint check
if: matrix.settings.wasm
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,22 @@
"prettier-plugin-tailwindcss": "0.6.14",
"pretty-quick": "4.2.2",
"prompts": "2.4.2",
"rollup": "4.52.3",
"rollup": "4.52.4",
"semver": "7.7.2",
"simple-git-hooks": "2.13.1",
"snoop": "1.0.4",
"source-map": "0.7.6",
"svgo": "3.3.2",
"syncpack": "13.0.4",
"terser": "5.43.1",
"terser": "5.44.0",
"tmp": "0.2.5",
"tree-kill": "1.2.2",
"tsx": "4.20.5",
"typescript": "5.9.2",
"typescript-eslint": "8.41.0",
"tsx": "4.20.6",
"typescript": "5.9.3",
"typescript-eslint": "8.45.0",
"vfile": "6.0.3",
"vite": "7.1.7",
"vite-imagetools": "8.0.0",
"vite": "7.1.9",
"vite-imagetools": "9.0.0",
"vite-plugin-dts": "4.5.4",
"vite-tsconfig-paths": "5.1.4",
"vitest": "3.2.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@qwik.dev/partytown": "0.11.2",
"@qwik.dev/react": "workspace:*",
"@qwik.dev/router": "workspace:*",
"@rolldown/browser": "1.0.0-beta.36",
"@rolldown/browser": "1.0.0-beta.41",
"@shikijs/colorized-brackets": "3.12.2",
"@shikijs/langs": "3.12.2",
"@shikijs/rehype": "3.12.2",
Expand Down Expand Up @@ -51,11 +51,11 @@
"shiki": "3.12.2",
"snarkdown": "2.0.0",
"tailwindcss": "4.1.12",
"terser": "5.43.1",
"terser": "5.44.0",
"tsm": "2.3.0",
"typescript": "5.9.2",
"typescript": "5.9.3",
"valibot": "0.33.3",
"vite": "7.1.7",
"vite": "7.1.9",
"vite-plugin-inspect": "11.3.3",
"vite-tsconfig-paths": "5.1.4",
"wrangler": "3.65.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-router/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type RouteData = [routeName: string, loaders: ModuleLoader[]] | [\n routeName: string,\n loaders: ModuleLoader[],\n originalPathname: string,\n routeBundleNames: string[]\n];\n```",
"content": "```typescript\nexport type RouteData = [\n routeName: string,\n moduleLoaders: ModuleLoader[]\n] | [\n routeName: string,\n moduleLoaders: ModuleLoader[],\n originalPathname: string,\n routeBundleNames: string[]\n];\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-router/src/runtime/src/types.ts",
"mdFile": "router.routedata.md"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik-router/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1854,10 +1854,10 @@ routeAction$: ActionConstructor;

```typescript
export type RouteData =
| [routeName: string, loaders: ModuleLoader[]]
| [routeName: string, moduleLoaders: ModuleLoader[]]
| [
routeName: string,
loaders: ModuleLoader[],
moduleLoaders: ModuleLoader[],
originalPathname: string,
routeBundleNames: string[],
];
Expand Down
6 changes: 3 additions & 3 deletions packages/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"prettier": "3.6.2",
"prettier-plugin-tailwindcss": "0.6.14",
"tailwindcss": "4.1.12",
"typescript": "5.9.2",
"typescript-eslint": "8.41.0",
"vite": "7.1.7",
"typescript": "5.9.3",
"typescript-eslint": "8.45.0",
"vite": "7.1.9",
"vite-tsconfig-paths": "5.1.4",
"vitest": "3.2.4",
"zod": "3.25.48"
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@types/react-dom": "19.1.7",
"react": "19.1.1",
"react-dom": "19.1.1",
"typescript": "5.9.2",
"vite": "7.1.7"
"typescript": "5.9.3",
"vite": "7.1.9"
},
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"set-cookie-parser": "^2.7.1",
"source-map": "^0.7.6",
"svgo": "^3.3.2",
"typescript": "5.9.2",
"typescript": "5.9.3",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"valibot": ">=0.36.0 <2",
"vfile": "6.0.3",
"vite-imagetools": "^8.0.0",
"vite-imagetools": "^9.0.0",
"yaml": "^2.8.1",
"zod": "^3.25.40"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/src/adapters/shared/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { StaticGenerateOptions, SsgRenderOptions } from 'packages/qwik-rout
import type { QwikRouterPlugin } from '@qwik.dev/router/vite';
import { basename, dirname, join, resolve } from 'node:path';
import type { Plugin, UserConfig } from 'vite';
import type { BuildRoute } from '../../../buildtime/types';
import type { BuiltRoute } from '../../../buildtime/types';
import { postBuild } from './post-build';

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ interface ViteAdapterPluginOptions {
clientPublicOutDir: string;
serverOutDir: string;
basePathname: string;
routes: BuildRoute[];
routes: BuiltRoute[];
assetsDir?: string;
warn: (message: string) => void;
error: (message: string) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getErrorHtml } from '@qwik.dev/router/middleware/request-handler';
import fs from 'node:fs';
import { join } from 'node:path';
import { getErrorHtml } from '../../../middleware/request-handler/error-handler';

/** Cleans the client output SSG results if needed and injects the SSG metadata into the build output */
export async function postBuild(
Expand Down
65 changes: 30 additions & 35 deletions packages/qwik-router/src/buildtime/build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { addError, addWarning } from '../utils/format';
import { resolveSourceFiles } from './routing/resolve-source-file';
import { routeSortCompare } from './routing/sort-routes';
import { walkRoutes } from './routing/walk-routes-dir';
import { walkServerPlugins } from './routing/walk-server-plugins';
import type { BuildContext, BuildRoute, RewriteRouteOption } from './types';
import type { RoutingContext, BuiltRoute, RewriteRouteOption } from './types';

export async function build(ctx: BuildContext) {
export async function parseRoutesDir(ctx: RoutingContext) {
try {
await updateBuildContext(ctx);
await updateRoutingContext(ctx);
validateBuild(ctx);
} catch (e) {
addError(ctx, e);
Expand All @@ -21,46 +22,40 @@ export async function build(ctx: BuildContext) {
}
}

export async function updateBuildContext(ctx: BuildContext) {
if (!ctx.activeBuild) {
ctx.activeBuild = new Promise<void>((resolve, reject) => {
walkServerPlugins(ctx.opts)
.then((serverPlugins) => {
ctx.serverPlugins = serverPlugins;
return walkRoutes(ctx.opts.routesDir);
})
.then((sourceFiles) => {
const resolved = resolveSourceFiles(ctx.opts, sourceFiles);
rewriteRoutes(ctx, resolved);
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.entries = resolved.entries;
ctx.serviceWorkers = resolved.serviceWorkers;
ctx.menus = resolved.menus;
resolve();
}, reject)
.finally(() => {
ctx.activeBuild = null;
});
});
}
export function updateRoutingContext(ctx: RoutingContext) {
ctx.activeBuild ||= _updateRoutingContext(ctx).finally(() => {
ctx.activeBuild = null;
});
return ctx.activeBuild;
}

function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resolveSourceFiles>) {
if (!ctx.opts.rewriteRoutes || !resolvedFiles.routes) {
return;
async function _updateRoutingContext(ctx: RoutingContext) {
const serverPlugins = await walkServerPlugins(ctx.opts);
const sourceFiles = await walkRoutes(ctx.opts.routesDir);
const resolved = resolveSourceFiles(ctx.opts, sourceFiles);
resolved.routes = rewriteRoutes(ctx, resolved.routes);
ctx.serverPlugins = serverPlugins;
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.entries = resolved.entries;
ctx.serviceWorkers = resolved.serviceWorkers;
ctx.menus = resolved.menus;
}

function rewriteRoutes(ctx: RoutingContext, routes: BuiltRoute[]) {
if (!ctx.opts.rewriteRoutes) {
return routes;
}

const translatedRoutes: BuildRoute[] = [];
const translatedRoutes: BuiltRoute[] = [];

let segmentsToTranslate = ctx.opts.rewriteRoutes.flatMap((rewriteConfig) => {
return Object.keys(rewriteConfig.paths || {});
});

segmentsToTranslate = Array.from(new Set(segmentsToTranslate));

resolvedFiles.routes.forEach((route) => {
routes.forEach((route) => {
// always push the original route
translatedRoutes.push(route);

Expand Down Expand Up @@ -91,14 +86,14 @@ function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resol
}
});

resolvedFiles.routes = translatedRoutes;
return translatedRoutes.sort(routeSortCompare);
}

function translateRoute(
route: BuildRoute,
route: BuiltRoute,
config: RewriteRouteOption,
configIndex: number
): BuildRoute {
): BuiltRoute {
const replacePath = (part: string) => (config.paths || {})[part] ?? part;

const pathnamePrefix = config.prefix ? '/' + config.prefix : '';
Expand Down Expand Up @@ -156,7 +151,7 @@ function translateRoute(
return routeToPush;
}

function validateBuild(ctx: BuildContext) {
function validateBuild(ctx: RoutingContext) {
const pathnames = Array.from(new Set(ctx.routes.map((r) => r.pathname))).sort();

for (const pathname of pathnames) {
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik-router/src/buildtime/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isAbsolute, resolve } from 'node:path';
import { normalizePath } from '../utils/fs';
import type { BuildContext, NormalizedPluginOptions, PluginOptions } from './types';
import type { RoutingContext, NormalizedPluginOptions, PluginOptions } from './types';

export function createBuildContext(
rootDir: string,
Expand All @@ -9,7 +9,7 @@ export function createBuildContext(
target?: 'ssr' | 'client',
dynamicImports?: boolean
) {
const ctx: BuildContext = {
const ctx: RoutingContext = {
rootDir: normalizePath(rootDir),
opts: normalizeOptions(rootDir, viteBasePath, userOpts),
routes: [],
Expand All @@ -28,7 +28,7 @@ export function createBuildContext(
return ctx;
}

export function resetBuildContext(ctx: BuildContext | null) {
export function resetBuildContext(ctx: RoutingContext | null) {
if (ctx) {
ctx.routes.length = 0;
ctx.layouts.length = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/src/buildtime/markdown/frontmatter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Transformer } from 'unified';
import type { BuildContext, FrontmatterAttrs } from '../types';
import type { RoutingContext, FrontmatterAttrs } from '../types';
import { normalizePath } from '../../utils/fs';
import { visit } from 'unist-util-visit';
import { parse as parseYaml } from 'yaml';
import type { ResolvedDocumentHead } from '../../runtime/src';
import type { DocumentMeta, Editable } from '../../runtime/src/types';

export function parseFrontmatter(ctx: BuildContext): Transformer {
export function parseFrontmatter(ctx: RoutingContext): Transformer {
return (mdast, vfile) => {
const attrs: FrontmatterAttrs = {};

Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/src/buildtime/markdown/mdx.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { CompileOptions } from '@mdx-js/mdx';
import { SourceMapGenerator } from 'source-map';
import { getExtension } from '../../utils/fs';
import type { BuildContext } from '../types';
import type { RoutingContext } from '../types';
import { parseFrontmatter } from './frontmatter';
import { rehypePage, rehypeSlug, renameClassname, wrapTableWithDiv } from './rehype';
import { rehypeSyntaxHighlight } from './syntax-highlight';

export async function createMdxTransformer(ctx: BuildContext): Promise<MdxTransform> {
export async function createMdxTransformer(ctx: RoutingContext): Promise<MdxTransform> {
const { compile } = await import('@mdx-js/mdx');
const { default: remarkFrontmatter } = await import('remark-frontmatter');
const { default: remarkGfm } = await import('remark-gfm');
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/src/buildtime/markdown/menu.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { NormalizedPluginOptions, BuildMenu, ParsedMenuItem, RouteSourceFile } from '../types';
import type { NormalizedPluginOptions, BuiltMenu, ParsedMenuItem, RouteSourceFile } from '../types';
import { marked } from 'marked';
import { createFileId, getMenuPathname } from '../../utils/fs';
import { getMarkdownRelativeUrl } from './markdown-url';

export function createMenu(opts: NormalizedPluginOptions, filePath: string) {
const menu: BuildMenu = {
const menu: BuiltMenu = {
pathname: getMenuPathname(opts, filePath),
filePath,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik-router/src/buildtime/markdown/rehype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { headingRank } from 'hast-util-heading-rank';
import { toString } from 'hast-util-to-string';
import { visit } from 'unist-util-visit';
import type { ContentHeading } from '../../runtime/src';
import type { BuildContext, NormalizedPluginOptions } from '../types';
import type { RoutingContext, NormalizedPluginOptions } from '../types';
import { getExtension, isMarkdownExt, normalizePath } from '../../utils/fs';
import { frontmatterAttrsToDocumentHead } from './frontmatter';
import { isSameOriginUrl } from '../../utils/pathname';
Expand All @@ -31,7 +31,7 @@ export function rehypeSlug(): Transformer {
};
}

export function rehypePage(ctx: BuildContext): Transformer {
export function rehypePage(ctx: RoutingContext): Transformer {
return (ast, vfile) => {
const mdast = ast as Root;
const sourcePath = normalizePath(vfile.path);
Expand Down Expand Up @@ -96,12 +96,12 @@ function updateContentLinks(mdast: Root, opts: NormalizedPluginOptions, sourcePa
});
}

function exportFrontmatter(ctx: BuildContext, mdast: Root, sourcePath: string) {
function exportFrontmatter(ctx: RoutingContext, mdast: Root, sourcePath: string) {
const attrs = ctx.frontmatter.get(sourcePath);
createExport(mdast, 'frontmatter', attrs);
}

function exportContentHead(ctx: BuildContext, mdast: Root, sourcePath: string) {
function exportContentHead(ctx: RoutingContext, mdast: Root, sourcePath: string) {
const attrs = ctx.frontmatter.get(sourcePath);
const head = frontmatterAttrsToDocumentHead(attrs);
if (head) {
Expand Down
Loading
Loading