Skip to content

Commit 89743a2

Browse files
committed
fix(imports): remove node imports to fix browser bundle
1 parent 3824ed7 commit 89743a2

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

‎lib/resolvers/file.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from "fs";
21
import * as url from "../util/url.js";
32
import { ResolverError } from "../util/errors.js";
43
import type { JSONSchema, ResolverOptions } from "../types/index.js";
@@ -24,6 +23,7 @@ export default {
2423
*/
2524
async read(file: FileInfo): Promise<Buffer> {
2625
let path: string | undefined;
26+
const fs = await import("fs");
2727
try {
2828
path = url.toFileSystemPath(file.url);
2929
} catch (err: any) {

‎lib/util/convert-path-to-posix.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from "path";
2-
31
const win32Sep = "\\";
42
export default function convertPathToPosix(filePath: string) {
53
const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
@@ -8,5 +6,5 @@ export default function convertPathToPosix(filePath: string) {
86
return filePath;
97
}
108

11-
return filePath.split(win32Sep).join(path?.posix?.sep ?? "/");
9+
return filePath.split(win32Sep).join("/");
1210
}

‎lib/util/url.ts‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import convertPathToPosix from "./convert-path-to-posix.js";
2-
import path from "path";
32

43
const forwardSlashPattern = /\//g;
54
const protocolPattern = /^(\w{2,}):\/\//i;
65
const jsonPointerSlash = /~1/g;
76
const jsonPointerTilde = /~0/g;
87

9-
import { join } from "path";
108
import { isWindows } from "./is-windows.js";
119

1210
const isAbsoluteWin32Path = /^[a-zA-Z]:\\/;
@@ -399,6 +397,13 @@ export function fromFileSystemPath(path: string) {
399397
path.startsWith("file://");
400398

401399
if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
400+
const join = (a: string, b: string) => {
401+
if (a.endsWith("/") || a.endsWith("\\")) {
402+
return a + b;
403+
} else {
404+
return a + "/" + b;
405+
}
406+
};
402407
path = join(projectDir, path);
403408
}
404409
path = convertPathToPosix(path);
@@ -487,15 +492,3 @@ export function safePointerToPath(pointer: string) {
487492
return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
488493
});
489494
}
490-
491-
export function relative(from: string, to: string) {
492-
if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
493-
return resolve(from, to);
494-
}
495-
496-
const fromDir = path.dirname(stripHash(from));
497-
const toPath = stripHash(to);
498-
499-
const result = path.relative(fromDir, toPath);
500-
return result + getHash(to);
501-
}

0 commit comments

Comments
 (0)