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 @@ -481,7 +481,7 @@ jobs:
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000

- name: Jest Unit Tests
- name: Unit Tests
run: yarn run test.unit

########### VALIDATE RUST ############
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"eslint-plugin-no-only-tests": "2.6.0",
"execa": "6.1.0",
"express": "4.18.1",
"headers-polyfill": "^3.0.10",
"mri": "1.2.0",
"node-fetch": "3.2.9",
"path-browserify": "1.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik-city/buildtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export async function buildFromUrlPathname(

if (sourceFiles.length > 0) {
const resolved = await resolveSourceFiles(ctx.opts, sourceFiles);
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.menus = resolved.menus;

for (const route of resolved.routes) {
const match = route.pattern.exec(pathname);
if (match) {
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.menus = resolved.menus;
return {
route,
params: getRouteParams(route.paramNames, match),
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-city/buildtime/markdown/menu.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { NormalizedPluginOptions, Menu, ParsedMenuItem, RouteSourceFile } from '../types';
import type { NormalizedPluginOptions, BuildMenu, ParsedMenuItem, RouteSourceFile } from '../types';
import { marked } from 'marked';
import { getMenuPathname, getMenuLinkHref } from '../utils/pathname';
import { createFileId } from '../utils/fs';

export function createMenu(opts: NormalizedPluginOptions, filePath: string) {
const menu: Menu = {
const menu: BuildMenu = {
pathname: getMenuPathname(opts, filePath),
filePath,
};
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik-city/buildtime/routing/resolve-source-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createFileId, isLayoutName, normalizePath, parseLayoutId } from '../uti
import { getPathnameFromFilePath } from '../utils/pathname';
import { parseRoutePathname } from './parse-pathname';

export function resolveLayout(routesDir: string, layoutSourceFile: RouteSourceFile) {
export function resolveLayout(opts: NormalizedPluginOptions, layoutSourceFile: RouteSourceFile) {
const dirName = layoutSourceFile.dirName;
const filePath = layoutSourceFile.filePath;
let dirPath = layoutSourceFile.dirPath;
Expand All @@ -25,7 +25,7 @@ export function resolveLayout(routesDir: string, layoutSourceFile: RouteSourceFi
}

const layout: BuildLayout = {
id: createFileId(routesDir, filePath),
id: createFileId(opts.routesDir, filePath),
filePath,
dirPath,
...layoutId,
Expand Down Expand Up @@ -76,7 +76,7 @@ export function resolveRoute(

const buildRoute: BuildRoute = {
type: sourceFile.type as any,
id: createFileId(routesDir, filePath),
id: createFileId(opts.routesDir, filePath),
filePath,
pathname,
layouts: layouts.reverse(),
Expand Down
4 changes: 1 addition & 3 deletions packages/qwik-city/buildtime/routing/source-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ export async function resolveSourceFiles(
opts: NormalizedPluginOptions,
sourceFiles: RouteSourceFile[]
) {
const routesDir = opts.routesDir;

const layouts = sourceFiles
.filter((s) => s.type === 'layout')
.map((s) => resolveLayout(routesDir, s))
.map((s) => resolveLayout(opts, s))
.sort((a, b) => {
if (a.id < b.id) return -1;
if (a.id > b.id) return 1;
Expand Down
4 changes: 2 additions & 2 deletions packages/qwik-city/buildtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface BuildContext {
opts: NormalizedPluginOptions;
routes: BuildRoute[];
layouts: BuildLayout[];
menus: Menu[];
menus: BuildMenu[];
frontmatter: Map<string, string[]>;
diagnostics: Diagnostic[];
target: 'ssr' | 'client';
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface BuildLayout extends ParsedLayoutId {
id: string;
}

export interface Menu {
export interface BuildMenu {
pathname: string;
filePath: string;
}
Expand Down
8 changes: 0 additions & 8 deletions packages/qwik-city/buildtime/utils/fs.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import { suite } from './test-suite';

const test = suite();

test('createFileId, Page index.tsx', () => {
const rootDir = tmpdir();
const routesDir = utils.normalizePath(join(rootDir, 'src', 'routes'));
const path = utils.normalizePath(join(routesDir, 'index.tsx'));
const p = utils.createFileId(routesDir, path);
assert.is(p, 'Index');
});

test('createFileId, Page dir/index.tsx', () => {
const rootDir = tmpdir();
const routesDir = utils.normalizePath(join(rootDir, 'src', 'routes'));
Expand Down
26 changes: 17 additions & 9 deletions packages/qwik-city/buildtime/vite/dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type { ViteDevServer } from 'vite';
import type { BuildContext } from '../types';
import type { HttpMethod } from '../../runtime/src/library/types';
import type { EndpointModule, HttpMethod } from '../../runtime/src/library/types';
import type { QwikViteDevResponse } from '../../../qwik/src/optimizer/src/plugins/vite';
import {
endpointHandler,
getEndpointResponse,
} from '../../middleware/request-handler/endpoint-handler';
import {
checkEndpointRedirect,
checkPageRedirect,
} from '../../middleware/request-handler/redirect-handler';
import { checkPageRedirect } from '../../middleware/request-handler/redirect-handler';
import { getQwikCityUserContext, isAcceptJsonOnly } from '../../middleware/request-handler/utils';
import { fromNodeRequest, toNodeResponse } from '../../middleware/express/utils';
import { buildFromUrlPathname } from '../build';
Expand Down Expand Up @@ -44,21 +41,32 @@ export function configureDevServer(ctx: BuildContext, server: ViteDevServer) {
}
}

const endpointModules: EndpointModule[] = [];
for (const layout of route.layouts) {
const layoutModule = await server.ssrLoadModule(layout.filePath, {
fixStacktrace: true,
});
endpointModules.push(layoutModule);
}
const endpointModule = await server.ssrLoadModule(route.filePath, {
fixStacktrace: true,
});
endpointModules.push(endpointModule);

const endpointResponse = await getEndpointResponse(
request,
method,
url,
params,
endpointModule
endpointModules
);

const endpointRedirectResponse = checkEndpointRedirect(endpointResponse);
if (endpointRedirectResponse) {
await toNodeResponse(endpointRedirectResponse, nodeRes);
if (endpointResponse.immediateCommitToNetwork) {
const response = new Response(endpointResponse.body, {
status: endpointResponse.status,
headers: endpointResponse.headers,
});
await toNodeResponse(response, nodeRes);
nodeRes.end();
return;
}
Expand Down
Loading