fix(tools): windows path
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import { existsSync, statSync } from 'node:fs';
|
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';
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||||
|
|
||||||
export class Path {
|
export class Path {
|
||||||
private readonly path: string;
|
|
||||||
|
|
||||||
static dir(url: string) {
|
static dir(url: string) {
|
||||||
return new Path(fileURLToPath(url)).join('..');
|
return new Path(fileURLToPath(url)).join('..');
|
||||||
}
|
}
|
||||||
@@ -17,9 +15,7 @@ export class Path {
|
|||||||
return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/');
|
return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(path: string) {
|
constructor(private readonly path: string) {}
|
||||||
this.path = path.replaceAll('\\', '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
join(...paths: string[]) {
|
join(...paths: string[]) {
|
||||||
return new Path(join(this.path, ...paths));
|
return new Path(join(this.path, ...paths));
|
||||||
@@ -29,6 +25,14 @@ export class Path {
|
|||||||
return this.join('..');
|
return this.join('..');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toPosixString() {
|
||||||
|
if (sep === '\\') {
|
||||||
|
return this.path.replaceAll('\\', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.path;
|
||||||
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
@@ -54,7 +58,12 @@ export class Path {
|
|||||||
}
|
}
|
||||||
|
|
||||||
relative(to: string) {
|
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