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

Running in production mode doesn't allow for easy tagging of internal-only files (as opposed to internal exports) #745

Closed
bryan-codaio opened this issue Jul 31, 2024 · 5 comments
Labels
feature request Feature request

Comments

@bryan-codaio
Copy link

bryan-codaio commented Jul 31, 2024

Reproduction url

https://codesandbox.io/p/devbox/k23sxr

Description of the issue

In the above repro, you can see that in other_util.ts I was able to appease knip by tagging the test-specific export as /** @internal */. However, if every export (i.e. the entire file) is only used by tests, then there's no recourse I'm aware of (other than the ignore in the config) to allow knip to pass.

Ideally we could tag every export of test_util.ts with /** @internal */ and the result would be knip not reporting it as unused in production mode.

Please let me know if I'm somehow made a mistake in my configuration. I'm still wrapping my head around entry vs. project vs. ignore, and production vs. not.

This is related to #706 and there may be overlap, but my gut said the solution to the two issues would be separate.

@bryan-codaio bryan-codaio added the bug Something isn't working label Jul 31, 2024
@webpro
Copy link
Collaborator

webpro commented Aug 1, 2024

Oh no:

Devbox not found
It's likely that the Devbox you're trying to access doesn't exist or you don't have the required permissions to access it.

@bryan-codaio
Copy link
Author

Oh no:

Devbox not found
It's likely that the Devbox you're trying to access doesn't exist or you don't have the required permissions to access it.

my bad, changed sharing settings to public. First time dealing with a devbox via codesandbox 😅

@webpro
Copy link
Collaborator

webpro commented Aug 1, 2024

I think what you're after is to exclude test_util from the production project file set:

{
  "$schema": "https://unpkg.com/knip@5/schema.json",
  "entry": ["index.ts!", "test.ts"],
  "project": ["*.ts!", "!test_util.ts!"]
}

The general case with e.g. **/*.test.ts is handled automatically for plugins (i.e. they're excluded in production mode). This "test util" case is a weak spot indeed, yet can be overcome by manually excluding them in production mode using double exclamation marks.

@bryan-codaio
Copy link
Author

bryan-codaio commented Aug 1, 2024

I think what you're after is to exclude test_util from the production project file set:

we could do that, but I agree with the philosophy in #706 that ideally we wouldn't have a typical workflow that involves users changing arrays in config files.

That example ought to demonstrate what I see the issue being. For a file that's got internal and production exports i.e. other_util.ts, it suffices to add /** @internal */ to the one internal export testOnlyUtil. However, say someone comes along and refactors other_util.ts and removes usedUtil - it's awkward that it suddenly becomes a necessity to add this file to knip.json.

@webpro webpro added feature request Feature request and removed bug Something isn't working labels Aug 2, 2024
@webpro
Copy link
Collaborator

webpro commented Oct 31, 2024

Let's keep only #706 open for discussion.

@webpro webpro closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

2 participants