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
Monorepo with project-level lint-staged config not running commands with correct cwd #1194
Comments
Hello, if you don't mind doing some manual debugging, it's probably around here: The |
Oof, yep, that was the problem, there was only one. Thanks for the reply. I had created a client |
The behavior is not perfectly intuitive, but "fixing" it would be a breaking change for single-config scenarios where the CWD is not in the config dir. |
I'm stumbling on a similar use-case - Unfortunately, There's not an "easy" configuration option to tell lint staged to try to run whatever it runs from the context of whatever subpackage the matched file is under. This being said, I am quite sure that I can write a function-based config that does the following: // lint-staged.config.mjs
import path from 'path';
// npm install --save-dev pkg-up
import { pkgUpSync } from 'pkg-up';
export default {
'*.md' : 'prettier',
'*.{js,ts}' : (filenames /*: string[]*/) => {
const root = process.cwd();
var srcByPkg = {};
var pkgPrefixes = [];
filenames.forEach(file => {
const pkgPath = pkgUpSync({ cwd: path.dirname(file) });
if (! pkgPath ) return;
const pkgPrefix = path.dirname(pkgPath);
if (! srcByPkg[pkgPrefix] ) {
srcByPkg[pkgPrefix] = [];
pkgPrefixes = pkgPrefixes.concat([pkgPrefix]);
}
srcByPkg[pkgPrefix] = srcByPkg[pkgPrefix].concat([file]);
});
return pkgPrefixes.map(pkgPrefix => {
const toLint = srcByPkg[pkgPrefix];
return `npm --prefix ${pkgPrefix} exec -- eslint --max-warnings 0 ${toLint.join(' ')}`;
});
},
} I'm hoping this is good enough to run whatever eslint should run within whatever package |
@matthewstrasiotto Might the
https://eslint.org/docs/latest/user-guide/configuring/configuration-files#using-configuration-files |
I think you're right, but in adding some devX tools, I'd rather not force that change for every project in my monorepo. |
What exactly is an empty config file and can this be documented? If I create an empty If I modify the
Then lint-staged fail to start and it doesn't print an error. If I actually put a pattern
Then |
I have the same problem as @Tri125, and adding this to root
|
Description
For us monorepo-ers, #1106 was good progress and allows for the
.lintstagedrc
to be in the project folders of a monorepo instead of the root. #1091 also added running commands in the cwd of the configuration, but that doesn't seem to be working.Commands still seem to run in the root folder instead of using the
.lintstagedrc
folder as the working directory. For monorepos that aren't all javascript, there is also no top-level workspace command and they aren't going to havepackage.json
.Steps to reproduce
Example repo: https://github.com/bbugh/lint-staged-example
yarn install
cd api
bundle install
git add Gemfile
cd ..
yarn lint-staged
Debug Logs
expand to view
For example
api
is a Rails-only project with nopackage.json
:This error happens because the command is not running in the working directory in the config folder location, as it seems like it should from reading #1091.
Environment
lint-staged
: 13.0.3The text was updated successfully, but these errors were encountered: