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

Improve knip reports by using a single config with workspaces #28491

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Pike
Copy link
Contributor

@Pike Pike commented Jan 15, 2025

Also move the dependency from the workspace into repo-tools.

The run with a configured workspace is slower, so I had to bump the timeout.

Hey, I just made a Pull Request!

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Jan 15, 2025

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/repo-tools packages/repo-tools patch v0.12.1

@github-actions github-actions bot added area:catalog Related to the Catalog Project Area auth area:techdocs Related to the TechDocs Project Area area:kubernetes Related to the Kubernetes Project Area - not deploying Backstage with k8s. search Things related to Search homepage Features for the composable homepage area:scaffolder Everything and all things related to the scaffolder project area area:permission Related to the Permission Project Area area:events Related to the Events Project Area area:home area:search labels Jan 15, 2025
@Pike Pike force-pushed the knip-workspace-config branch from 1862ff0 to 845e2b7 Compare January 15, 2025 15:28
@Pike Pike marked this pull request as ready for review January 15, 2025 15:29
@Pike Pike requested review from benjdlambert and vinzscam January 15, 2025 15:29
@Pike
Copy link
Contributor Author

Pike commented Jan 15, 2025

This only includes a changeset for repo-tools, as I'm only changing the knip-report files in the other packages. Given that those are not exposed on npm, I don't rev those packages.

Actually addressing the unused deps would be in follow-up PRs.

CC @freben, we quickly talked about the knip false-positives on discord. Not quite yet at the point where there are none, but much closer.

@Pike
Copy link
Contributor Author

Pike commented Jan 15, 2025

PS: the following packages don't have reports at all yet, not sure if it's good to add them in this PR:

packages/backend-common
packages/frontend-defaults
packages/yarn-plugin
packages/canon
packages/frontend-internal
packages/scaffolder-internal
packages/opaque-internal
plugins/auth-backend-module-bitbucket-provider
plugins/catalog-unprocessed-entities-common
plugins/proxy-node
plugins/app
plugins/user-settings-common
plugins/auth-backend-module-bitbucket-server-provider
plugins/notifications-backend-module-email
plugins/catalog-backend-module-gitlab-org
plugins/auth-backend-module-azure-easyauth-provider
plugins/catalog-backend-module-logs
plugins/techdocs-common
plugins/scaffolder-backend-module-notifications
plugins/auth-backend-module-auth0-provider
plugins/auth-react

entry: [
'dev/index.{ts,tsx}',
'src/index.{ts,tsx}',
'src/alpha.{ts,tsx}',
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to generate this based on the actual package.json files. Some packages have MANY entrypoints (notably backend-defaults).

Regarding extensions, we're adding more in #19855

Copy link
Contributor Author

Choose a reason for hiding this comment

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

entrypoints work, I just cross-checked backend-defaults.

This fixes alpha, we only have two packages (I think), which don't expose an existing src/alpha.ts:

grep -L ./alpha `ls p*/*/src/alpha.ts|sed -e s'|src/alpha.ts|package.json|'`
packages/cli/package.json
plugins/scaffolder-backend-module-sentry/package.json

The scaffolder one is empty, not sure about the cli one?

This won't cover the dev directories for the dev server, though.

I tested dropping src/index.{ts,tsx}, but that triggered more false positives. I didn't dig in deep, but repo-tools is one of them. It only exposes the dist cjs, which one may not have. This might need some more dedicated research.

Re extensions, is that the right PR? That's 2023?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh no I meant #28308

Copy link
Member

Choose a reason for hiding this comment

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

What I meant with the entrypoints is, does it understand that for example this file is an entirely separate entrypoint too, and that any dependencies it uses need to be taken into account as well, in addition to the root index?

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, excerpt from running knip --debug:

[packages/backend-defaults] Finding package.json entry paths
{
  patterns: [
    'packages/backend-defaults/package.json',
    'packages/backend-defaults/src/entrypoints/userInfo/index.ts',
    'packages/backend-defaults/src/entrypoints/urlReader/index.ts',
    'packages/backend-defaults/src/entrypoints/scheduler/index.ts',
    'packages/backend-defaults/src/entrypoints/rootLogger/index.ts',
    'packages/backend-defaults/src/entrypoints/rootLifecycle/index.ts',
    'packages/backend-defaults/src/entrypoints/rootHttpRouter/index.ts',
    'packages/backend-defaults/src/entrypoints/rootHealth/index.ts',
    'packages/backend-defaults/src/entrypoints/rootConfig/index.ts',
    'packages/backend-defaults/src/entrypoints/permissions/index.ts',
    'packages/backend-defaults/src/entrypoints/permissionsRegistry/index.ts',
    'packages/backend-defaults/src/entrypoints/logger/index.ts',
    'packages/backend-defaults/src/entrypoints/lifecycle/index.ts',
    'packages/backend-defaults/src/entrypoints/httpRouter/index.ts',
    'packages/backend-defaults/src/entrypoints/httpAuth/index.ts',
    'packages/backend-defaults/src/entrypoints/discovery/index.ts',
    'packages/backend-defaults/src/entrypoints/database/index.ts',
    'packages/backend-defaults/src/entrypoints/cache/index.ts',
    'packages/backend-defaults/src/entrypoints/auth/index.ts',
    'packages/backend-defaults/src/index.ts'
  ],
...
  paths: [
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/package.json',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/userInfo/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/urlReader/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/scheduler/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/rootLogger/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/rootLifecycle/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/rootHttpRouter/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/rootHealth/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/rootConfig/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/permissions/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/permissionsRegistry/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/logger/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/lifecycle/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/httpRouter/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/httpAuth/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/discovery/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/database/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/cache/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/entrypoints/auth/index.ts',
    '/Users/54717/src/backstage/backstage/packages/backend-defaults/src/index.ts'
  ]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rebased this ontop of #28308 now that that's merged, and I needed some adjustment for the tests.

Otherwise, this works like expected, I think.


| Name | Location | Severity |
| :----------------- | :-------------------------------- | :------- |
| @internal/frontend | src/app/createExtensionTester.tsx | error |
Copy link
Member

Choose a reason for hiding this comment

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

Would be neat to not list the internal ones. They are marked as such in package.json, which is a better way of detect them than by name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think this is something we need to discuss. This might be a topic to bring up with the knip folks upstream.

I wonder if a mono-repo and "private": true, in package.json would be enough of a signal. Though, looking at https://github.com/search?q=repo%3Awebpro-nl%2Fknip+private+path%3A%2F%5Epackages%5C%2Fknip%5C%2Ffixtures%5C%2F%2F&type=code it seems that that signal is already used in their test fixtures.

The

  "backstage": {
    "role": "web-library",
    "inline": true
  },

part would only be available to plugins, which need to be upstream. And I don't see a way to extend ignored dependencies from those. Another thing to check.

Should I just add something name-based for now?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it's the Backstage specific "online" concept I meant indeed.

Maybe let's leave it as a future improvement. It's still a lot better than before either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with a regexp on the name for now.

@Pike Pike force-pushed the knip-workspace-config branch from 7578146 to 8e0de41 Compare January 16, 2025 10:53
Pike added 8 commits January 16, 2025 14:36
Also move the dependency from the workspace into repo-tools.

The run with a configured workspace is slower, so I had to bump the timeout.

Signed-off-by: Axel Hecht <axel@pike.org>
Also remove a stray one

Signed-off-by: Axel Hecht <axel@pike.org>
Let's figure out later what triggers those

Signed-off-by: Axel Hecht <axel@pike.org>
Signed-off-by: Axel Hecht <axel@pike.org>
Signed-off-by: Axel Hecht <axel@pike.org>
Using just the naming convention for now.

Signed-off-by: Axel Hecht <axel@pike.org>
Canon uses a different setup for storybook

Signed-off-by: Axel Hecht <axel@pike.org>
Signed-off-by: Axel Hecht <axel@pike.org>
@Pike Pike force-pushed the knip-workspace-config branch from 8e0de41 to 7e5fa38 Compare January 16, 2025 14:39
@Pike
Copy link
Contributor Author

Pike commented Jan 16, 2025

PS: the following packages don't have reports at all yet, not sure if it's good to add them in this PR:

I back-filled the missing reports now, too. Only canon is not done, because that has a storybook setup that differs from the rest, so I'd recommend that to be done in a follow-up.
I also enabled the techdocs-cli-embed one again, I couldn't reproduce the problem that was suggested in the comment to disable it.

@freben , this should be ready for another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area area:events Related to the Events Project Area area:home area:kubernetes Related to the Kubernetes Project Area - not deploying Backstage with k8s. area:permission Related to the Permission Project Area area:scaffolder Everything and all things related to the scaffolder project area area:search area:techdocs Related to the TechDocs Project Area auth homepage Features for the composable homepage search Things related to Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants