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
Make lint-staged more compatible with git sparse checkout feature #1390
Comments
A possible solution to this issue could be reading the file content of missing package.json from git as well, since the existence of those package.json are read from git. It could happen at this line of code: Line 83 in 999dcce
I would like to put my psedocode here to show the idea: BEFORE: const loadConfigByExt = async (filepath) => {
// ...
const content = await readFile(filepath);
// ...
} AFTER: const loadConfigByExt = async (filepath) => {
// ...
const content = fs.exists(filepath) ? await readFile(filepath) : await readFileFromGit(filepath) ;
// ...
}
function readFileFromGit(filepath) {
const relativeFilepath = getRelativeFilepathSomehow(filepath):
const content = exec(`git show HEAD:${relativeFilepath}`);
return content;
} |
Related issue with a proposed solution that doesn't require file system operations: #1383 Thanks! I will provide a fix now that there's multiple issues. |
@chengcyber would you mind testing the linked PR in your setup? |
@iiroj Sure. I am glad to test it. Is there a specific prerelease version I can run locally? |
Sorry no, easiest is to copy/paste the changes into your |
I tested it locally and yes it has been fixed and no more errors. The debug log is as follows:
|
Description
Now,
lint-staged
has compatibility issue when developing in a monorepo with git sparse checkout feature enabled. It throws errors for loading config from package.json files out side of sparse checkout folders.Steps to reproduce
I created a repo to show the idea at https://github.com/chengcyber/lint-staged-sparse-issue
NOTE: make sure the git version supports "git sparse checkout" and "--sparse" parameter in "git clone". The git version in my end is 2.43.0. I believe >=2.25.0 should be fine.
However,
npx lint-staged
complains:Debug Logs
expand to view
Environment
lint-staged
: 15.2.1 (latest)The text was updated successfully, but these errors were encountered: