Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: change route data and router config names
  • Loading branch information
Varixo authored and wmertens committed Sep 21, 2025
commit e94dc523bee86d408c6511584198decf9c49da62
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
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 @@ -262,7 +262,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
18 changes: 9 additions & 9 deletions packages/qwik-router/src/buildtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { addError, addWarning } from '../utils/format';
import { resolveSourceFiles } from './routing/resolve-source-file';
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,7 +21,7 @@ export async function build(ctx: BuildContext) {
}
}

export async function updateBuildContext(ctx: BuildContext) {
export async function updateRoutingContext(ctx: RoutingContext) {
if (!ctx.activeBuild) {
ctx.activeBuild = new Promise<void>((resolve, reject) => {
walkServerPlugins(ctx.opts)
Expand All @@ -47,12 +47,12 @@ export async function updateBuildContext(ctx: BuildContext) {
return ctx.activeBuild;
}

function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resolveSourceFiles>) {
function rewriteRoutes(ctx: RoutingContext, resolvedFiles: ReturnType<typeof resolveSourceFiles>) {
if (!ctx.opts.rewriteRoutes || !resolvedFiles.routes) {
return;
}

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

let segmentsToTranslate = ctx.opts.rewriteRoutes.flatMap((rewriteConfig) => {
return Object.keys(rewriteConfig.paths || {});
Expand Down Expand Up @@ -95,10 +95,10 @@ function rewriteRoutes(ctx: BuildContext, resolvedFiles: ReturnType<typeof resol
}

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 +156,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
24 changes: 12 additions & 12 deletions packages/qwik-router/src/buildtime/routing/resolve-source-file.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { dirname } from 'node:path';
import { resolveMenu } from '../markdown/menu';
import type {
BuildEntry,
BuildLayout,
BuildRoute,
BuildServerPlugin,
BuiltEntry,
BuiltLayout,
BuiltRoute,
BuiltServerPlugin,
NormalizedPluginOptions,
RouteSourceFile,
} from '../types';
Expand Down Expand Up @@ -93,7 +93,7 @@ export function resolveLayout(opts: NormalizedPluginOptions, layoutSourceFile: R
layoutName = '';
}

const layout: BuildLayout = {
const layout: BuiltLayout = {
id: createFileId(opts.routesDir, filePath),
filePath,
dirPath,
Expand All @@ -110,11 +110,11 @@ const LAYOUT_TOP_SUFFIX = '!';

export function resolveRoute(
opts: NormalizedPluginOptions,
appLayouts: BuildLayout[],
appLayouts: BuiltLayout[],
sourceFile: RouteSourceFile
) {
const filePath = sourceFile.filePath;
const layouts: BuildLayout[] = [];
const layouts: BuiltLayout[] = [];
const routesDir = opts.routesDir;
const { layoutName, layoutStop } = parseRouteIndexName(sourceFile.extlessName);
let pathname = getPathnameFromDirPath(opts, sourceFile.dirPath);
Expand All @@ -129,7 +129,7 @@ export function resolveRoute(
const hasNamedLayout = layoutName !== '';

for (let i = 0; i < 20; i++) {
let layout: BuildLayout | undefined = undefined;
let layout: BuiltLayout | undefined = undefined;

if (hasNamedLayout && !hasFoundNamedLayout) {
layout = appLayouts.find((l) => l.dirPath === currentDir && l.layoutName === layoutName);
Expand All @@ -155,7 +155,7 @@ export function resolveRoute(
}
}

const buildRoute: BuildRoute = {
const buildRoute: BuiltRoute = {
id: createFileId(opts.routesDir, filePath, 'Route'),
filePath,
pathname,
Expand All @@ -169,7 +169,7 @@ export function resolveRoute(

export function resolveServerPlugin(opts: NormalizedPluginOptions, sourceFile: RouteSourceFile) {
const filePath = sourceFile.filePath;
const buildRoute: BuildServerPlugin = {
const buildRoute: BuiltServerPlugin = {
id: createFileId(opts.serverPluginsDir, filePath, 'Plugin'),
filePath,
ext: sourceFile.ext,
Expand All @@ -181,7 +181,7 @@ function resolveEntry(opts: NormalizedPluginOptions, sourceFile: RouteSourceFile
const pathname = getPathnameFromDirPath(opts, sourceFile.dirPath);
const chunkFileName = pathname.slice(opts.basePathname.length);

const buildEntry: BuildEntry = {
const buildEntry: BuiltEntry = {
id: createFileId(opts.routesDir, sourceFile.filePath, 'Route'),
filePath: sourceFile.filePath,
chunkFileName,
Expand All @@ -196,7 +196,7 @@ function resolveServiceWorkerEntry(opts: NormalizedPluginOptions, sourceFile: Ro
const pathname = dirPathname + sourceFile.extlessName + '.js';
const chunkFileName = pathname.slice(opts.basePathname.length);

const buildEntry: BuildEntry = {
const buildEntry: BuiltEntry = {
id: createFileId(opts.routesDir, sourceFile.filePath, 'ServiceWorker'),
filePath: sourceFile.filePath,
chunkFileName,
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-router/src/buildtime/routing/sort-routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildRoute } from '../types';
import type { BuiltRoute } from '../types';

export function routeSortCompare(a: BuildRoute, b: BuildRoute) {
export function routeSortCompare(a: BuiltRoute, b: BuiltRoute) {
const maxSegments = Math.max(a.segments.length, b.segments.length);

for (let i = 0; i < maxSegments; i += 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BuildRoute } from '../types';
import type { BuiltRoute } from '../types';
import { createFileId } from '../../utils/fs';
import { parseRoutePathname } from './parse-pathname';
import { routeSortCompare } from './sort-routes';
Expand Down Expand Up @@ -44,7 +44,7 @@ test('routeSortCompare', () => {

function route(r: TestRoute) {
const pathname = r.pathname || '/';
const route: BuildRoute = {
const route: BuiltRoute = {
id: createFileId('', pathname, 'Route'),
filePath: pathname,
pathname,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import { join } from 'node:path';
import type { BuildServerPlugin, NormalizedPluginOptions } from '../types';
import type { BuiltServerPlugin, NormalizedPluginOptions } from '../types';
import {
createFileId,
getExtension,
Expand All @@ -14,7 +14,7 @@ import {
export async function walkServerPlugins(opts: NormalizedPluginOptions) {
const dirPath = opts.serverPluginsDir;
const dirItemNames = await fs.promises.readdir(dirPath);
const sourceFiles: BuildServerPlugin[] = [];
const sourceFiles: BuiltServerPlugin[] = [];
await Promise.all(
dirItemNames.map(async (itemName) => {
const itemPath = normalizePath(join(dirPath, itemName));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BuildContext } from '../types';
import type { RoutingContext } from '../types';

export function createEntries(ctx: BuildContext, c: string[]) {
export function createEntries(ctx: RoutingContext, c: string[]) {
const isClient = ctx.target === 'client';

const entries = [...ctx.entries, ...ctx.serviceWorkers];
Expand All @@ -14,7 +14,7 @@ export function createEntries(ctx: BuildContext, c: string[]) {
}
}

export function generateQwikRouterEntries(ctx: BuildContext) {
export function generateQwikRouterEntries(ctx: RoutingContext) {
// generate @qwik-router-entries
const c: string[] = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { createFileId } from '../../utils/fs';
import type { BuildContext } from '../types';
import type { RoutingContext } from '../types';
import { getImportPath } from './utils';

export function createMenus(ctx: BuildContext, c: string[], esmImports: string[], isSSR: boolean) {
export function createMenus(
ctx: RoutingContext,
c: string[],
esmImports: string[],
isSSR: boolean
) {
c.push(`\n/** Qwik Router Menus (${ctx.menus.length}) */`);
c.push(`export const menus = [`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { QwikVitePlugin } from '@qwik.dev/core/optimizer';
import type { BuildContext } from '../types';
import type { RoutingContext } from '../types';
import { createEntries } from './generate-entries';
import { createMenus } from './generate-menus';
import { createRoutes } from './generate-routes';
import { createServerPlugins } from './generate-server-plugins';

/** Generates the Qwik Router Config runtime code */
export function generateQwikRouterConfig(
ctx: BuildContext,
ctx: RoutingContext,
qwikPlugin: QwikVitePlugin,
isSSR: boolean
) {
Expand Down
Loading