Skip to content

Commit

Permalink
fix(vite-plugin-nitro): normalize page handler path for Windows (#591) (
Browse files Browse the repository at this point in the history
  • Loading branch information
omarbelkhodja authored Aug 16, 2023
1 parent 599ee7c commit a265229
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/vite-plugin-nitro/src/lib/plugins/page-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { normalizePath } from 'vite';
import { buildSync } from 'esbuild';
import { normalizePath } from 'vite';

export function pageEndpointsPlugin() {
return {
name: 'analogjs-vite-plugin-nitro-rollup-page-endpoint',
async transform(_code: string, id: string) {
if (
id.includes(normalizePath('src/app/pages')) &&
normalizePath(id).includes('src/app/pages') &&
id.endsWith('.server.ts')
) {
const compiled = buildSync({
Expand Down
11 changes: 8 additions & 3 deletions packages/vite-plugin-nitro/src/lib/utils/get-page-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { NitroEventHandler } from 'nitropack';
import * as path from 'path';

import { NitroEventHandler } from 'nitropack';
import { normalizePath } from 'vite';

type GetHandlersArgs = {
workspaceRoot: string;
rootDir: string;
};

export function getPageHandlers({ workspaceRoot, rootDir }: GetHandlersArgs) {
const fg = require('fast-glob');
const root = path.resolve(workspaceRoot, rootDir);
const root = normalizePath(path.resolve(workspaceRoot, rootDir));

const endpointFiles: string[] = fg.sync(
[`${root}/src/app/pages/**/*.server.ts`],
Expand All @@ -17,7 +19,10 @@ export function getPageHandlers({ workspaceRoot, rootDir }: GetHandlersArgs) {

const handlers: NitroEventHandler[] = endpointFiles.map((endpointFile) => {
const route = endpointFile
.replace(path.resolve(workspaceRoot, rootDir, 'src/app'), '')
.replace(
normalizePath(path.resolve(workspaceRoot, rootDir, 'src/app')),
''
)
.replace(/\.server\.ts$/, '')
.replace(/\[\.{3}(.+)\]/g, '**:$1')
.replace(/\[\.{3}(\w+)\]/g, '**:$1')
Expand Down

0 comments on commit a265229

Please sign in to comment.