-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
no-extraneous-dependencies: Separate packageDir for devDependencies #1214
Comments
Initially this made sense to me, but after thinking about it - it doesn't. This is how we approach it: Monorepo Rootpackage.json
.eslintrc.js// These are allowed to require packages from devDependecies
const devScripts = [
'scripts/*.js',
'**/webpack.*.js',
'**/cosmos.proxies.js',
'**/*.fixture.jsx',
'**/next.config.js'
];
module.exports = {
rules: {
'import/no-extraneous-dependencies': [
'error',
{
// scripts that are allowed to import from devDependencies
devDependencies: devScripts
}
],
},
}; PackagesIn each package folder ( package.json
.eslintrc.jsconst { join } = require('path');
module.exports = {
rules: {
'import/no-extraneous-dependencies': [
'error',
// Use package.json from both this package folder and root.
{ packageDir: [__dirname, join(__dirname, '../../')] }
]
}
}; See more on this in #1302 (comment) |
I have ended up using an alternative using eslint overrides with the following features:
const path = require('path');
const devConfig = {
rules: {
'import/no-extraneous-dependencies': [
2,
{
// Dependencies must be specified in `devDependencies` in the monorepo root
devDependencies: true,
packageDir: __dirname,
},
],
},
};
const runtimeConfig = {
rules: {
// Dependencies must be specified in the projects package.json
'import/no-extraneous-dependencies': [
2,
{
devDependencies: false,
// default `packageDir` is the closest `package.json` to the file being linted
},
],
},
};
module.exports = {
...,
overrides: [
{
files: ['./packages/*/**/*'],
...runtimeConfig,
},
{
files: ['./packages/*/scripts/**/*', './packages/*/*.config.js'],
...devConfig,
},
]
}; |
This was referenced Sep 16, 2021
This was referenced Nov 30, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
I have a lerna monorepo and I like to install development only dependencies at the workspace root rather than in individual packages. This is because it is easier to maintain one set of versions for development tools rather than many, and it is not important that the development environment of each package is self contained - the monorepo IS the development environment.
After #1085, this is possible.
However, I still would like the published versions of my packages to have proper entries in
dependencies
for any other packages that it requires in order to work. Users of the package don't check out the monorepo, they install the package.Example
To illustrate, imagine the following project structure:
Suggestion
Allow both
devDependencies
andpackageDir
to be used only for specific files which are not used in production:The text was updated successfully, but these errors were encountered: