Monorepo support?
See original GitHub issueFeature request description
I am wondering if we want to support monorepos out of the box. We could look for all package.json files.
Code snippets (if applicable)
#!/usr/bin/env node
const depcheck = require('depcheck');
const glob = require('globby');
const fs = require('fs');
const path = require('path');
const IGNORE_PACKAGES = [
];
const rootDir = path.resolve(__dirname, '../');
const getPackages = async () => {
const packages = await glob('**/package.json', { ignore: ['**/node_modules/**'] });
if (packages.length === 0) {
throw new Error('Did not find \'packages\'');
}
const PackageContent = [];
packages.forEach(packagePath => {
try {
const packageJsonString = fs.readFileSync(packagePath, 'utf8');
const packageJson = JSON.parse(packageJsonString);
const pathToPackageJson = `${rootDir}/${packagePath}`;
const pkg = {
location: path.dirname(pathToPackageJson),
name: packageJson.name,
};
PackageContent.push(pkg);
} catch (err) {
console.log(`Couldn't find a 'package.json' for ${packagePath}. Skipping. ${err}`);
}
});
return PackageContent;
};
(async () => {
console.log('*** NOTE: Double check usage before removing a package***');
const packages = await getPackages().catch(err => {
console.log(`Error in getPackages ${err}`);
});
const unusedPackages = [];
for (const pkg of packages) {
console.log(`\nChecking ${pkg.name} for unused deps.`);
const opts = {
};
const results = await depcheck(pkg.location, opts);
const individualPackageDeps = results.dependencies.filter(dep => !IGNORE_PACKAGES.includes(dep));
if (individualPackageDeps.length !== 0) {
console.log(individualPackageDeps.join('\r\n'));
unusedPackages.push(...individualPackageDeps);
}
}
if (unusedPackages.length !== 0 ) {
console.log(`\nYou have unused packages: \n${unusedPackages.join('\r\n')}\n` );
process.exit(1);
}
})().catch(err => { console.log(err);});
Any extra info
We could either just include this example in the docs or make it the default functionality. What do you think?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
What is monorepo? (and should you use it?) - Semaphore CI
A monorepo is a version-controlled code repository that holds many projects. While these projects may be related, they are often logically ...
Read more >Monorepo Explained
Gradle Build Tool provides support for parallel tasks via configuration, and task orchestration through its flexible Groovy or Kotlin DSL. natively supported ......
Read more >Monorepos in Git | Atlassian Git Tutorial
A monorepo is a repository that contains more than one logical project. Read here to learn about conceptual challenges, performance issues and more....
Read more >Monorepo Support | Render · Cloud Hosting for Developers
Monorepo Support helps you deploy just the services you need to eliminate unnecessary deploys, control build costs, and ship faster. Monorepo Support offers...
Read more >A Guide to Monorepos for Front-end Code - Toptal
A monorepo or monorepository is a code management and architectural concept whereby you keep all your isolated bits of code inside one super...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Wait what, no! I mean yeah, we can close this one since it’s a duplicate of #245 but we should support yarn workspaces, I’m OK if we support only the mode 1 that @benjie suggested.
I suggest you only support mode 1. Typically mode 2 is only used for repo-wide tooling such as
lerna
itself,eslint
, etc. Mode 2 is actually super dangerous to support if you’re planning to publish to npm because it can hide the fact that dependencies are missing on individual packages.I don’t think we need support for lerna; I use it with graphile-engine but I don’t think depcheck would even need to know it exists to validate the repo with yarn workspaces.