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

Add FAQ #759

Merged
merged 5 commits into from
Aug 20, 2024
Merged

Add FAQ #759

merged 5 commits into from
Aug 20, 2024

Conversation

webpro
Copy link
Collaborator

@webpro webpro commented Aug 19, 2024

WIP

Copy link

netlify bot commented Aug 19, 2024

Deploy Preview for knip canceled.

Name Link
🔨 Latest commit 765de0e
🔍 Latest deploy log https://app.netlify.com/sites/knip/deploys/66c4f4c8a751010007290963

Copy link

pkg-pr-new bot commented Aug 19, 2024

commit: 765de0e

bun add https://pkg.pr.new/knip@759

Open in Stackblitz

@@ -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
Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

@jfmengels jfmengels Aug 19, 2024

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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
Copy link
Contributor

@jfmengels jfmengels Aug 19, 2024

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).

Copy link
Collaborator Author

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].
Copy link
Contributor

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.

Copy link
Collaborator Author

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)

@webpro webpro marked this pull request as ready for review August 20, 2024 19:55
@webpro webpro merged commit 4f2665f into main Aug 20, 2024
27 checks passed
@webpro webpro deleted the faq branch August 20, 2024 19:56
@webpro
Copy link
Collaborator Author

webpro commented Aug 21, 2024

🚀 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.

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.

2 participants