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

Many errors in standard output when using git sparse-checkout #1383

Closed
tpluscode opened this issue Jan 11, 2024 · 4 comments · Fixed by #1391
Closed

Many errors in standard output when using git sparse-checkout #1383

tpluscode opened this issue Jan 11, 2024 · 4 comments · Fixed by #1391

Comments

@tpluscode
Copy link

Description

I'm trying to set up lint-stage on https://github.com/DefinitelyTyped/DefinitelyTyped. Since that repo moved to pnpm as a monorepo, the recommended workflow is to use sparse checkout and only check out those types/* dirs which one is working on.

This apparently causes a ton of errors like this, for every single types/* directory which is not currently checked out.

[Error: ENOENT: no such file or directory, open '/Volumes/Home/projects/github/DefinitelyTyped/types/zxcvbn/package.json'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Volumes/Home/projects/github/DefinitelyTyped/types/zxcvbn/package.json'
}

Otherwise, linting succeeds

Steps to reproduce

  1. git clone --sparse --filter=blob:none --depth=1 git@github.com:tpluscode/DefinitelyTyped.git
  2. git switch lint-staged
  3. git sparse-checkout add types/node
  4. pnpm i
  5. Modify types/node/index.d.ts
  6. git add --sparse types/node/index.d.ts
  7. pnpm lint-staged
  8. Observe errors rolling in

Debug Logs

That repo produces a log so big that I just upload the whole thing:
log.log

Environment

  • OS: macOS Catalina
  • Node.js: 18.19.0
  • lint-staged: 15.2.0
@iiroj
Copy link
Member

iiroj commented Jan 12, 2024

Hey, looks like this might be related to the automatic monorepo features. Since all the type definition packages include a package.json in version control, lint-staged tries to read configuration from them.

It would probably be a lot faster to use a single explicit config file, if that's all you need:

npx lint-staged --config .lintstagedrc.js

This should hopefully make lint-staged skip trying to read every single possible config file.

@iiroj
Copy link
Member

iiroj commented Jan 12, 2024

We use git ls-files to list possible config files in the repo. I wonder if adding the --sparse flag here would help:

const EXEC_GIT = ['ls-files', '-z', '--full-name']

@tpluscode
Copy link
Author

This should hopefully make lint-staged skip trying to read every single possible config file.

Thank you, that did it! Now lint-staged succeeds without trying to access all those package.json which have not been checked out

We use git ls-files to list possible config files in the repo

Thanks for pointing this out. I found this SO answer, which suggests adding verbose flag to ls-files and filtering by the H flag.

tl;dr;, the above in shell

git ls-files -v | grep -e '^H' | grep 'package.json$'

tpluscode added a commit to tpluscode/DefinitelyTyped that referenced this issue Jan 12, 2024
@iiroj
Copy link
Member

iiroj commented Jan 12, 2024

Glad to hear it! For now I won't add this extra filtering, but if this issue surfaces again I will look at it again.

@iiroj iiroj closed this as completed Jan 12, 2024
typescript-bot pushed a commit to DefinitelyTyped/DefinitelyTyped that referenced this issue Jan 12, 2024
…nd lint-staged by @tpluscode

* style: optional formatting on pre-commit hook

* explicit lint-staged config (re lint-staged/lint-staged#1383)

* docs: mention checking out hooks, + tweak hook command

* chore: remove config (moved to .lintstagedrc.jsn)

* refactor: lint-staged everything

* Update README.md

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>

* docs: move git hook section

---------

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
@iiroj iiroj reopened this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants