Skip to content

Commit

Permalink
Fix incorrect use of path lib in fs.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Feb 21, 2024
1 parent 2d1e35b commit 87de946
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/utils/src/fs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import assert from "assert";
import { join, relative, resolve, isAbsolute } from "path";
import systemPath, { posix as posixPath } from "path";
import getCacheDir = require("cachedir");
import { assertDefined } from "./assertions";
import fs from "fs";
import { readFileSync, readJsonSync } from "./io";

/** The directory to read/write suggestsions from */
export const suggestionsDir = join(getCacheDir("dts"), "suggestions");
export const suggestionsDir = systemPath.join(getCacheDir("dts"), "suggestions");

/** Convert a path to use "/" instead of "\\" for consistency. (This affects content hash.) */
export function normalizeSlashes(path: string): string {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class InMemoryFS implements FS {

private tryGetEntry(path: string): ReadonlyDir | string | undefined {
if (path[0] === "/") {
path = relative(this.rootPrefix, path);
path = posixPath.relative(this.rootPrefix, path);
}
if (path === "") {
return this.curDir;
Expand Down Expand Up @@ -162,7 +162,7 @@ export class InMemoryFS implements FS {

subDir(path: string): FS {
assert(path[0] !== "/", "Cannot use absolute paths with InMemoryFS.subDir");
return new InMemoryFS(this.getDir(path), resolve(this.rootPrefix, path));
return new InMemoryFS(this.getDir(path), posixPath.join(this.rootPrefix, path));
}

debugPath(): string {
Expand All @@ -179,12 +179,12 @@ export class InMemoryFS implements FS {

export class DiskFS implements FS {
constructor(private readonly rootPrefix: string) {
assert(isAbsolute(rootPrefix), "DiskFS must use absolute paths");
assert(systemPath.isAbsolute(rootPrefix), "DiskFS must use absolute paths");
this.rootPrefix = ensureTrailingSlash(rootPrefix);
}

private getPath(path: string | undefined): string {
return resolve(this.rootPrefix, path ?? "");
return systemPath.resolve(this.rootPrefix, path ?? "");
}

readdir(dirPath?: string): readonly string[] {
Expand Down

0 comments on commit 87de946

Please sign in to comment.