aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.24k stars 43 forks source link

Use `exclude` config on `findProjects` #49

Closed igor-ribeiro closed 1 year ago

igor-ribeiro commented 2 years ago

When using this Remix template a folder called postgres-data is created at the root and this plugins tries to scan that folder even if I add it to exclude config.

EACCES: permission denied, scandir '/home/iribeiro/code/ribeirolabs/mecontrole/postgres-data/'
at Object.readdirSync (node:fs:1390:3)
at Object.readdir (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/recrawl-sync/lib/fs.js:6:25)
at crawl (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/recrawl-sync/lib/recrawl.js:46:35)
at crawl (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/recrawl-sync/lib/recrawl.js:67:25)
at /home/iribeiro/code/ribeirolabs/mecontrole/node_modules/recrawl-sync/lib/recrawl.js:85:9
at exports.crawl (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/recrawl-sync/lib/recrawl.js:15:51)
at findProjects (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/vite-tsconfig-paths/dist/index.js:210:35)
at Object.configResolved (/home/iribeiro/code/ribeirolabs/mecontrole/node_modules/vite-tsconfig-paths/dist/index.js:68:24)
at /home/iribeiro/code/ribeirolabs/mecontrole/node_modules/vite/dist/node/chunks/dep-9c153816.js:71065:78
at Array.map (<anonymous>) {
  errno: -13,
  syscall: 'scandir',
  code: 'EACCES',
  path: '/home/iribeiro/code/ribeirolabs/mecontrole/postgres-data/'
}

Debugging I found that the folders to skip are hardcoded here https://github.com/aleclarson/vite-tsconfig-paths/blob/master/src/index.ts#L208

We should be allowed to control which folders to skip.

aleclarson commented 2 years ago

Controlling which folders are skipped sounds like a good idea. PR welcome!

I've updated the recrawl-sync package to swallow permission errors, so that erasing your lockfile and re-installing should fix that error for you in the meantime.

igor-ribeiro commented 2 years ago

I can do it. Do we have access to vitest configuration? It looks like this:

export default defineConfig({
  plugins: [react(), tsconfigPaths()],
  test: {
    globals: true,
    environment: "happy-dom",
    setupFiles: ["./test/setup-test-env.ts"],
    exclude: ["**/node_modules/**", "**/postgres-data/**"],
  },
});

https://vitest.dev/config/#configuration

aleclarson commented 2 years ago

Try reinstalling your dependencies (after deleting lockfile, eg package-lock.json) first, then we can talk about where the exclude globs should be obtained from.