-
Notifications
You must be signed in to change notification settings - Fork 278
Description
Context
I'd like to be able to pass module names to dependency-cruiser, instead of paths to node modules, so that I can match those without having to list all potential paths.
I'm using the JS API, and want to support user input in my wrapper. The below references to "chalk" are just for example.
Expected Behavior
In this scenario, I want to find all modules that reach chalk, but not modules within chalk that reference other chalk modules.
const options = {
reaches: ['^chalk$'],
doNotFollow: ['^chalk$'],
};Current Behavior
The example above returns no matches. With pnpm (7.x, 8.x), I need to use the following to get the example above to work.
const options = {
reaches: [^node_modules/.pnpm/chalk@5.2.0/node_modules/chalk'],
doNotFollow: [^node_modules/.pnpm/chalk@5.2.0/node_modules/chalk'],
};If someone installed a new version of chalk in the monorepo, this wouldn't catch that version.
Possible Solution
I think adding moduleNames (or modules) alongside paths might be a good solution here.
const options = {
reaches: {
moduleNames: ['^chalk$'],
},
doNotFollow: {
moduleNames: ['^chalk$'],
},
};Considered alternatives
I realise that I can just pass the string, but this would match any package with "chalk" in its name, i.e. definitely-not-chalk.
const options = {
reaches: {
moduleNames: ['chalk'],
},
doNotFollow: {
moduleNames: ['chalk'],
},
};I could also pass with slashes, but that could match an internal directory of the same name, i.e. utils/chalk/wrapper.ts.
const options = {
reaches: {
moduleNames: ['/chalk/'],
},
doNotFollow: {
moduleNames: ['/chalk/'],
},
};