Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(tools): windows path

forehalo4ec02dbb39db
diff --git a/tools/utils/src/path.ts b/tools/utils/src/path.ts
index 953f97a21c..30486345b9 100644
--- a/tools/utils/src/path.ts
+++ b/tools/utils/src/path.ts
@@ -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;
}
}