Skip to content

Commit

Permalink
fix: normalize all routes, error while running in Window environment
Browse files Browse the repository at this point in the history
  • Loading branch information
shuaiqidekaige committed Sep 22, 2022
1 parent f5c6a94 commit 7294335
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/node/plugin-routes/RouteService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { normalizePath } from 'vite';
import fastGlob from 'fast-glob';
import fs from 'fs-extra';
import { RUNTIME_BUNDLE_OUTDIR } from '../constants';
Expand Down Expand Up @@ -42,12 +43,16 @@ export class RouteService {
}

addRoute(filePath: string) {
const fileRelativePath = path.relative(this.scanDir, filePath);
const fileRelativePath = normalizePath(
path.relative(this.scanDir, filePath)
);
const routePath = normalizeRoutePath(fileRelativePath);
const absolutePath = path.join(this.scanDir, fileRelativePath);

this.#routeData.push({
routePath,
basePath: this.scanDir,
absolutePath: path.join(this.scanDir, fileRelativePath)
absolutePath: normalizePath(absolutePath)
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/plugin-routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { PageModule } from '../../shared/types';
import type { Plugin } from 'vite';
import { normalizePath } from 'vite';
import { RouteService } from './RouteService';
import { normalizePath } from '../utils';

/**
* How does the conventional route work?
Expand Down
4 changes: 0 additions & 4 deletions src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ export const createHash = (info: string): string => {
}
return createHashFunc('sha256').update(info).digest('hex').slice(0, 8);
};

export const normalizePath = (url: string, sep = '/') => {
return url.replace(/\\/g, sep);
};

0 comments on commit 7294335

Please sign in to comment.