Skip to content
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

feat: add dependency-cruiser plugin #911

Merged
merged 7 commits into from
Jan 15, 2025

Conversation

filipw01
Copy link
Contributor

Fixes: #907

Copy link

pkg-pr-new bot commented Jan 13, 2025

Open in Stackblitz

npm i https://pkg.pr.new/knip@911

commit: b079529

Copy link
Collaborator

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Love that you also did the args thing :)

const config = ['.dependency-cruiser.{js,cjs,mjs,json}'];

const args = {
binaries: ['depcruise'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added the relevant ones

binaries: ['depcruise'],
alias: { config: ['c'] },
string: ['config'],
config: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting config: true is a shorthand that sets the alias and string options as well:

/**
* Define arguments that contain config file path.
* Usually you'll want to set aliases too. Use `true` for shorthand to set `alias` + `string` + `config`
*
* @example `config: ["p"]` for e.g. `tsc -p tsconfig.lib.json`
*
* @example `config: true` for e.g. `tsup --config tsup.client.json`
*
* @default undefined
*/
config?: ConfigArg;

just a heads-up, no need to change if you prefer explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't know that


// Check that dependencies are properly detected
assert(issues.devDependencies['package.json']['dependency-cruiser']);
assert(issues.binaries['package.json']['depcruise']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what i usually do is add the most minimal package in an actual node_modules folder with e.g. { "name": "dependency-cruiser", "bin": { ... } } in package.json and an empty index.js - that way, Knip does the full machinery and there should be no issues left (random example: https://github.com/webpro-nl/knip/tree/main/packages/knip/fixtures/plugins/angular/node_modules/@angular/cli).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome. I was a bit lost working on the test

@filipw01
Copy link
Contributor Author

@webpro Is there an option to colocate tests and fixtures? It was a bit annoying how far they were in the file structure when working on the test. I'm happy to open a PR moving it around

@filipw01 filipw01 requested a review from webpro January 13, 2025 17:36
@webpro
Copy link
Collaborator

webpro commented Jan 13, 2025

@webpro Is there an option to colocate tests and fixtures? It was a bit annoying how far they were in the file structure when working on the test. I'm happy to open a PR moving it around

Gotcha. I can relate, but overall this structure is very convenient to me.

@webpro webpro merged commit 8d206a0 into webpro-nl:main Jan 15, 2025
@filipw01
Copy link
Contributor Author

Thanks for taking care of that. Was a bit busy this week

@webpro
Copy link
Collaborator

webpro commented Jan 15, 2025

🚀 This pull request is included in v5.42.1. See Release 5.42.1 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

@webpro
Copy link
Collaborator

webpro commented Jan 15, 2025

No worries, was tiny change. Thanks again for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 Add support for dependency-cruiser
2 participants