webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
7.03k stars 174 forks source link

Support caching results on Win32-based systems #832

Open dbehmoaras opened 1 week ago

dbehmoaras commented 1 week ago

…ct creation

webpro commented 1 week ago

Thanks for your PR, @dbehmoaras! This is the central function to normalize paths to posix format. So I'm not sure whether this is the right location to fix the issue. What's the exact issue you're trying to solve here?

dbehmoaras commented 1 week ago

Thanks for your PR, @dbehmoaras! This is the central function to normalize paths to posix format. So I'm not sure whether this is the right location to fix the issue. What's the exact issue you're trying to solve here?

Hmm - I see your point. Maybe then it should be addressed in file that handles the caching of the results ? The issue we run into is that Knip fails to update the cache on windows systems because it resolves a posix file path when windows env expects a win32 path from node.js - see permalink below:

https://github.com/webpro-nl/knip/blob/2ad6583ab4198761126ff0c7d461cff7450e87c5/packages/knip/src/util/file-entry-cache.ts#L41

Is there a separate file that handles win32 file paths ? Open to any approach

webpro commented 1 week ago

Alright, clear.

Maybe you can import path from 'node:path in file-entry-cache.ts and take it from there? Fix this.filePath with path.resolve, etc.

dbehmoaras commented 1 week ago

Ok let me try that

webpro commented 1 week ago

Great, I'm asking so you can directly test it works properly on Windows. If you update the PR, you will automatically get a new version that you can npm install anywhere, if that helps.

pkg-pr-new[bot] commented 1 week ago

Open in Stackblitz

bun add https://pkg.pr.new/knip@832

commit: 473ba49