mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(tools): windows path
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
import { join, relative } from 'node:path/posix';
|
||||
import { join, relative, sep } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
export class Path {
|
||||
private readonly path: string;
|
||||
|
||||
static dir(url: string) {
|
||||
return new Path(fileURLToPath(url)).join('..');
|
||||
}
|
||||
@@ -17,9 +15,7 @@ export class Path {
|
||||
return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path.replaceAll('\\', '/');
|
||||
}
|
||||
constructor(private readonly path: string) {}
|
||||
|
||||
join(...paths: string[]) {
|
||||
return new Path(join(this.path, ...paths));
|
||||
@@ -29,6 +25,14 @@ export class Path {
|
||||
return this.join('..');
|
||||
}
|
||||
|
||||
toPosixString() {
|
||||
if (sep === '\\') {
|
||||
return this.path.replaceAll('\\', '/');
|
||||
}
|
||||
|
||||
return this.path;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.path;
|
||||
}
|
||||
@@ -54,7 +58,12 @@ export class Path {
|
||||
}
|
||||
|
||||
relative(to: string) {
|
||||
return relative(this.value, to);
|
||||
const re = relative(this.value, to);
|
||||
if (sep === '\\') {
|
||||
return re.replaceAll('\\', '/');
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user