Skip to content

Commit

Permalink
added isWindows check, support resolving windows paths for cache obje…
Browse files Browse the repository at this point in the history
…ct creation
  • Loading branch information
dbehmoaras committed Oct 29, 2024
1 parent 1ecf821 commit 15b3248
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/knip/src/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import parsedArgValues from './cli-arguments.js';

const { directory } = parsedArgValues;

const isWindows = () => process.platform === 'win32';

export const isAbsolute = path.isAbsolute;

export const dirname = path.posix.dirname;
Expand All @@ -18,8 +20,10 @@ export const toPosix = (value: string) => value.split(path.sep).join(path.posix.

export const cwd = directory ? path.posix.resolve(directory) : toPosix(process.cwd());

export const resolve = (...paths: string[]) =>
paths.length === 1 ? path.posix.join(cwd, paths[0]) : path.posix.resolve(...paths);
export const resolve = (...paths: string[]) => {
const pathResolver = isWindows() ? path.win32 : path.posix;
return paths.length === 1 ? pathResolver.join(cwd, paths[0]) : pathResolver.resolve(...paths);
}

export const relative = (from: string, to?: string) => toPosix(path.relative(to ? from : cwd, to ?? from));

Expand Down

0 comments on commit 15b3248

Please sign in to comment.