Skip to content

Commit

Permalink
fix(other): window path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
songyf committed Sep 8, 2023
1 parent 7427077 commit 986b2cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/core/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ElegantRouterOption } from '../types';
import { normalizeWindowsPath } from './path';

/**
* create the plugin options
Expand All @@ -24,7 +25,7 @@ export function createPluginOptions(options?: Partial<ElegantRouterOption>): Ele
};

// normalize the path if it is windows
opts.cwd = opts.cwd.replace(/\\/g, '/');
opts.cwd = normalizeWindowsPath(opts.cwd);

return opts;
}
8 changes: 8 additions & 0 deletions packages/core/src/core/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ import path from 'node:path';
export function getFullPathOfPageGlob(glob: string, pageDir: string, cwd: string) {
return path.posix.join(cwd, pageDir, glob);
}

/**
* get the full path of the page glob
* @param normalPath the normal path
*/
export function normalizeWindowsPath(normalPath: string) {
return normalPath.replace(/\\/g, '/');
}
9 changes: 7 additions & 2 deletions packages/core/src/core/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { watch } from 'chokidar';
import { log } from './log';
import { normalizeWindowsPath } from './path';

export function setupWatcher(
watchDir: string,
Expand All @@ -14,9 +15,11 @@ export function setupWatcher(
});

const stacks: string[] = [];

function addStack(path: string) {
stacks.push(path);
}

function clearStack() {
stacks.length = 0;
}
Expand All @@ -41,11 +44,13 @@ export function setupWatcher(
log('watcher ready', 'start', showLog);
});
watcher.on('add', path => {
addStack(path);
const normalPath = normalizeWindowsPath(path);
addStack(normalPath);
handleStack();
});
watcher.on('unlink', path => {
addStack(path);
const normalPath = normalizeWindowsPath(path);
addStack(normalPath);
handleStack();
});

Expand Down

0 comments on commit 986b2cf

Please sign in to comment.