Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect .gitignore files above the CWD #5

Open
thernstig opened this issue May 7, 2021 · 5 comments
Open

Respect .gitignore files above the CWD #5

thernstig opened this issue May 7, 2021 · 5 comments

Comments

@thernstig
Copy link

Hi!

I tried to run this and got:

Error running find-unused-exports:

  SyntaxError: /home/userA/code/projectA/server/node_modules/mkdirp/bin/cmd.js: 'return' outside of function. (13:4)

    11 | if (argv.help) {
    12 |     fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout);
  > 13 |     return;
       |     ^
    14 | }
@jaydenseric
Copy link
Owner

mkdirp is not a part of the find-unused-exports dependency graph, so I think that error is not from the find-unused-exports trying to do it's job, but rather it's trying to analyze your node_modules searching for unused exports and it's encountered a module that it can't parse due to that return being used outside of a function.

You don't want to analyze node_modules; make sure it's in your project's .gitignore file:

https://github.com/jaydenseric/find-unused-exports#ignoring-unused-exports

@thernstig
Copy link
Author

It is gitignored, but in a directory above from where I ran the command, I suppose the script is not traversing upwards to include parenet .gitignore(s)?

@jaydenseric
Copy link
Owner

The problem is that the .gitignore feature is implemented using globby, which searches for .gitignore files down from the CWD. They have an open issue to respect .gitignore files above the CWD:

sindresorhus/globby#86

For now we wait for it to be resolved upstream in globby. In the mean time, you can place .gitignore files containing node_modules in the package directories you want to run find-unused-exports. Git repos are designed to be able to have multiple .gitignore files, and I actually prefer for each project in a monorepo to be completely self contained like this - in theory in any of my mono repos you could cut a package directory out and paste it as a standalone repo without any problems.

@jaydenseric jaydenseric changed the title 'return' outside of function Respect .gitignore files above the CWD May 9, 2021
@thernstig
Copy link
Author

Thanks, I will wait for the upstream fix. Should this stay open to track that one? Otherwise I am ok with you closing it, all up to you.

@jaydenseric
Copy link
Owner

For now we can keep it open here; if this is an issue people run into a lot and globby takes too long to fix it we can look into an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants