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

Update knip + config #2647

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update knip + config #2647

wants to merge 2 commits into from

Conversation

webpro
Copy link

@webpro webpro commented Nov 5, 2024

What does this PR do?

Ref: https://twitter.com/chronark_/status/1853744727037780324

Knip has a lot of defaults and heuristics to fill out the entry points for you.

I went through all apps/* folders, removed all config and added back a little (for the same results). I did not go through internal/*, packages/* and tools/*.

Lots of results, and a quick scan tell me they're mostly not false positives.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

Since the monorepo is pretty large, it might be worthwhile to pick one workspace at a time, eg:

knip -W apps/billing

This will take into account dependent and depending workspaces as well. So e.g. if a workspace references a dependency that's only listed in the root package.json then it won't be reported (unless using --strict mode).

There's a lot more to it, the docs should cover plenty. Yes, it takes a bit of effort in a monorepo like this, but long-term it should def be worth it. Key takeaway: results are usually suspicious: deal with the reported thing, add as entry, or report bug in Knip :)

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Updated configuration to streamline workspace management and improve project structure.
  • Bug Fixes

    • Resolved issues related to ignored dependencies and workspaces for better clarity in configuration.
  • Chores

    • Upgraded the knip package to the latest version for enhanced functionality.
    • Removed outdated workspace entries to simplify project management.

Copy link

changeset-bot bot commented Nov 5, 2024

⚠️ No Changeset found

Latest commit: 8a9bdc9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

vercel bot commented Nov 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 11:01am

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes primarily involve updates to the knip.ts configuration file and the package.json file. In knip.ts, the KnipConfig object has been modified to consolidate ignored paths and restructure workspace entries, reflecting a simplified project focus. In package.json, the workspaces field has been removed, and the version of the knip package has been updated from ^5.11.0 to ^5.36.2. These modifications indicate a shift in project management and configuration.

Changes

File Change Summary
knip.ts Updated KnipConfig: replaced ignoreDependencies and ignoreWorkspaces with ignore array; added entry for apps/agent; restructured workspaces to remove several entries and add apps/billing and apps/dashboard.
package.json Removed "workspaces" field; updated knip version from ^5.11.0 to ^5.36.2 in devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Config as KnipConfig
    participant Package as package.json

    Config->>Config: Update ignore paths
    Config->>Config: Restructure workspaces
    Package->>Package: Remove workspaces field
    Package->>Package: Update knip version
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Nov 5, 2024

@webpro is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Nov 5, 2024

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.
Here is an example:

<type>[optional scope]: <description>
fix: I fixed something for Unkey

Details:

No release type found in pull request title "Update knip + config". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@@ -1,6 +1,5 @@
{
"name": "unkey",
"workspaces": ["apps/*", "packages/*"],
Copy link
Author

Choose a reason for hiding this comment

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

This confused Knip. Can it be removed?


const config: KnipConfig = {
ignoreWorkspaces: ["packages/nuxt"],
ignoreDependencies: ["cz-conventional-changelog"],
Copy link
Author

Choose a reason for hiding this comment

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

Add commitizen explicitly to activate the plugin and this wouldn't be reported.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
knip.ts (1)

1-34: Consider enhancing Knip plugin ecosystem

The configuration relies on manual entry point specification for trigger.dev and trpc due to missing Knip plugins. Consider:

  1. Contributing plugins for trigger.dev and trpc to the Knip ecosystem
  2. Documenting the manual entry point patterns in a central location for maintainability
  3. Setting up automated validation of entry point coverage

This would improve maintainability and reduce the risk of missing important entry points.

package.json (1)

Line range hint 1-58: Critical: Restore the "workspaces" field

The removal of the "workspaces" field is concerning as it's essential for pnpm to manage dependencies in a monorepo setup. This could break the workspace management and inter-package dependencies.

Apply this diff to restore the workspaces configuration:

{
  "name": "unkey",
  "private": true,
+ "workspaces": [
+   "apps/*",
+   "packages/*"
+ ],
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between aec5dc6 and 0ef7c6a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • knip.ts (1 hunks)
  • package.json (1 hunks)
🔇 Additional comments (8)
knip.ts (7)

1-3: LGTM: Clean type import and configuration setup


11-13: LGTM: Root workspace configuration

The root workspace entry point is clearly defined.


29-31: LGTM: K6 tool configuration

The k6 tool entry point is clearly defined and specific.


7-9: Verify other non-JS/TS applications

The comment indicates that apps/agent is ignored as it's a Golang app. Let's verify if there are other non-JS/TS applications that should be ignored.

#!/bin/bash
# Description: Find directories that might contain non-JS/TS applications

# Look for Go files
echo "Directories with Go files:"
fd -e go . apps internal packages tools -x dirname {} \; | sort -u

# Look for other common non-JS/TS project indicators
echo -e "\nDirectories with other language indicators:"
fd -e rs -e py -e rb -e java -e cpp . apps internal packages tools -x dirname {} \; | sort -u

21-28: Verify trpc entry points coverage

The broad glob patterns for the dashboard app might include unnecessary files or miss important ones. Let's verify the coverage.

#!/bin/bash
# Description: Verify TRPC-related files coverage

# Find all TypeScript files in app directory
echo "TypeScript files in dashboard app directory:"
fd -e ts -e tsx . apps/dashboard/app

# Find files with TRPC imports or usage
echo -e "\nFiles with TRPC imports or usage:"
rg -l "@trpc|createTRPCNext|createTRPCProxyClient" apps/dashboard

# Verify lib/trpc paths
echo -e "\nVerify lib/trpc structure:"
ls -la apps/dashboard/lib/trpc/

14-20: Verify trigger.dev entry points coverage

The comment indicates that Knip lacks a trigger.dev plugin, leading to manual entry point specification. Let's verify the coverage of trigger-related files.

#!/bin/bash
# Description: Verify trigger.dev related files coverage

echo "Trigger-related files in apps/billing:"
rg -t ts -l "trigger" apps/billing

echo -e "\nCompare with specified patterns:"
echo "- trigger.config.ts"
echo "- src/trigger/*.ts"

4-6: Verify other workspaces without package.json

The comment indicates that artillery is ignored due to missing package.json. Let's verify there aren't other similar cases that should be included.

✅ Verification successful

Artillery is indeed the only workspace without package.json

The verification confirms that among the tools directories, only tools/artillery/ lacks a package.json file, while all other directories (k6, local, and migrate) have one. This validates the current ignore configuration as correct and complete.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find directories that might be workspaces but lack package.json files

# Search for potential workspace directories (excluding node_modules and common build directories)
echo "Directories without package.json that might need to be ignored:"
fd --type d --min-depth 1 --max-depth 2 \
   --exclude 'node_modules' --exclude 'dist' --exclude '.next' \
   . apps tools internal packages \
   --exec sh -c '[ ! -f "{}/package.json" ] && echo "{}"'

Length of output: 597


Script:

#!/bin/bash
# Let's try a different approach to find directories without package.json
# First, let's list all directories in tools/ to understand the structure
echo "Directories in tools/:"
fd --type d --max-depth 1 . tools/

echo -e "\nChecking each directory in tools/ for package.json:"
for dir in $(fd --type d --max-depth 1 . tools/); do
    if [ -f "$dir/package.json" ]; then
        echo "$dir (has package.json)"
    else
        echo "$dir (no package.json)"
    fi
done

Length of output: 978

package.json (1)

30-30: Verify compatibility with updated knip version

The knip package has been updated from ^5.11.0 to ^5.36.2. While this is a minor version bump, it's a significant jump that could introduce breaking changes.

Let's verify the changelog and potential breaking changes:

✅ Verification successful

Knip update appears safe to proceed

The update from 5.11.0 to 5.36.2 appears safe as:

  • The project uses a simple knip configuration with basic flags (--include files,dependencies)
  • No custom knip configuration files are present
  • The usage is limited to a single npm script for dependency analysis
  • The version bump follows semver (^5.x.x), indicating no breaking changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential breaking changes in knip updates

# Test 1: Check if knip is used in any npm scripts across workspaces
echo "Checking knip usage in package.json files..."
fd package.json --exec rg -l "knip"

# Test 2: Check for any custom knip configurations that might need updates
echo "Checking for knip config files..."
fd -e ts -e json -e yaml -e yml --exec rg -l "knip.*config"

# Test 3: Verify if the new version is compatible with the current Node.js version
echo "Checking knip peer dependencies..."
rg '"engines"' package.json -A 5

Length of output: 402


Script:

#!/bin/bash
# Let's check the actual usage and configuration of knip

# Check package.json content for knip scripts and config
echo "Checking package.json content..."
cat package.json

# Check for .knip.json or knip.json
echo -e "\nChecking for knip configuration files..."
fd knip.json

# Check for any knip configuration in package.json
echo -e "\nChecking for knip configuration patterns in package.json..."
rg '"knip":' package.json -A 10

Length of output: 2650

entry: ["lib/trpc/index.ts", "trpc.config.ts"],
},
"apps/api": {
entry: ["**/*.test.ts", "src/pkg/testutil/*.ts", "src/worker.ts", "./vitest.*.ts"],
Copy link
Author

Choose a reason for hiding this comment

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

Good example of entry files Knip figures out itself, none of those are needed :)

@chronark chronark self-assigned this Nov 5, 2024
@chronark
Copy link
Collaborator

thanks @webpro
I'd love to merge this, could you sign the CLA above?
otherwise I can also create a new PR with these changes, up to you.

@webpro
Copy link
Author

webpro commented Nov 13, 2024

There you go

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.

3 participants