-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
Add FAQ #759
Conversation
✅ Deploy Preview for knip canceled.
|
commit:
|
@@ -74,8 +74,8 @@ messages like this: | |||
``` | |||
|
|||
The first number in `P1/1` is the number of the program, the second number | |||
indicates additional entry files were found in the previous round so it does | |||
another round of analysis on those files. | |||
indicates additional entry files were found so it does another round of analysis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not related to these changes) but I don't get this part
The first number in
P1/1
is the number of the program
What is "the number of the program"? Is it an id representing an "instance" of Knip associated with a given tsconfig.json
, or is it something else entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully answered here in the FAQ now: https://github.com/webpro-nl/knip/blob/8df0855f645e026e6e3e379ffb14c72147212afc/packages/docs/src/content/docs/reference/faq.md#why-doesnt-knip-match-my-typescript-project-structure
Another take on this, in short:
- workspace: dir with
package.json
(package manager concept) - project: dir with
tsconfig.json
(typescript concept) - not relevant here - program: Knip creates a typescript program and then adds as many workspaces as its config allows
Guess this is worth another entry in the FAQ, I'll keep it in mind.
|
||
Runtimes like Node.js provide `require.resolve` and `import.meta.resolve`. | ||
TypeScript comes with module resolution built-in. More module resolvers are out | ||
there and bundlers are known to use or come with module resolvers. None of them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, some people customize module resolutions through tools like Webpack or Babel. (Not sure it's worth mentioning, but that's the first thing I thought of)
Nevermind, I see you reference this problem in a later section anyway.
## How does Knip handle non-standard import syntax? | ||
|
||
Knip tries to be resilient against import syntax like what's used by e.g. | ||
Webpack loaders or Vite asset imports. Knip strips off the prefixes and suffixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to its documentation, webpack
is not capitalized (https://webpack.js.org/guides/getting-started/), as shown for instance by this sentence in their docs.
Let's use webpack to manage these scripts instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, indeed
`setupFiles: ['@org/shared/jest-setup.ts']`. Those entry files may also contain | ||
imports of internal modules or external dependencies, and so on. | ||
|
||
With an easy-to-use plugin API, many plugins have been created by contributors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very polite of you to not say it's because the JS/TS ecosystem has plenty of tools that each have their own configuration files, source files, standard and non-standard syntax, and reference magic 😄
I think it's probably worth mentioning that the variety of approaches in the ecosystem does create this need for plugins. It also relates to the next question in that it impacts the engineering of Knip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to address this in the introduction of this page, but indeed could be emphasized better I guess.
|
||
Knip comes with basic "compilers" for a few common non-standard file types. | ||
They're not actual compilers, they're regular expressions only to extract import | ||
statements. Override the built-in Svelte "compilers" with the real one in your |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the suggested solution probably deserves a bit more hold-handing/explanations (unless you believe it's clear enough). A link to a more comprehensive solution is also fine (or even better).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's a link to https://knip.dev/features/compilers - this FAQ item is merely to illustrate the main idea.
tooling, including most issues found in production mode. This mode has the | ||
most impact on DX, for the same reason. | ||
|
||
Also see [production mode][9]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you not thinking of having Knip run both types of analysis all the time? I remember we talked about this at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but doesn't seem feasible other than actually running it twice. We've discussed it here as well: #583 (comment)
Co-authored-by: Jeroen Engels <[email protected]>
🚀 This pull request is included in v5.27.3. See Release 5.27.3 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
WIP