From db3fe4033fc64483e4e5f72543bb8cd23cdb7a9e Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Sun, 3 Nov 2024 08:09:09 +0100 Subject: [PATCH] Minor doc edits, formatting --- .../src/content/docs/features/reporters.md | 17 ++++++---- packages/docs/src/content/docs/index.mdx | 6 ++-- .../docs/src/content/docs/reference/faq.md | 33 ++++++++++++------- packages/docs/src/pages/sponsors.astro | 8 ++--- packages/docs/src/styles/content.css | 27 +++++++++++++++ packages/knip/src/manifest/helpers.ts | 5 --- 6 files changed, 66 insertions(+), 30 deletions(-) diff --git a/packages/docs/src/content/docs/features/reporters.md b/packages/docs/src/content/docs/features/reporters.md index e799244b5..465c10427 100644 --- a/packages/docs/src/content/docs/features/reporters.md +++ b/packages/docs/src/content/docs/features/reporters.md @@ -8,9 +8,9 @@ Knip provides the following built-in reporters: - `codeowners` - `compact` -- [`disclosure`](#disclosure) -- [`json`](#json) -- [`markdown`](#markdown) +- [`disclosure`][1] +- [`json`][2] +- [`markdown`][3] - `symbol` (default) Example usage: @@ -71,7 +71,7 @@ object per file structured like this: } ``` -The keys match the [reported issue types][1]. Example usage: +The keys match the [reported issue types][4]. Example usage: ```sh knip --reporter json @@ -137,7 +137,7 @@ The above can be copy-pasted where HTML and Markdown is supported, such as a GitHub issue or pull request, and renders like so:
-Unused files (2) + Unused files (2) ``` unused.ts @@ -147,7 +147,7 @@ dangling.js
-Unused dependencies (2) + Unused dependencies (2) ``` unused-dep package.json @@ -251,4 +251,7 @@ Example usage: knip --preprocessor ./preprocess.ts ``` -[1]: ../reference/issue-types.md +[1]: #disclosure +[2]: #json +[3]: #markdown +[4]: ../reference/issue-types.md diff --git a/packages/docs/src/content/docs/index.mdx b/packages/docs/src/content/docs/index.mdx index 8d05ea5f0..2ab5cdbf4 100644 --- a/packages/docs/src/content/docs/index.mdx +++ b/packages/docs/src/content/docs/index.mdx @@ -30,8 +30,8 @@ import Contributors from '../../components/Contributors.astro'; - Knip finds and fixes unused files, exports and dependencies. Use it for enhanced - code and dependency management. + Knip finds and fixes unused files, exports and dependencies. Use it for + enhanced code and dependency management. Read the full explanation: [why should I use Knip?][1] @@ -54,7 +54,7 @@ import Contributors from '../../components/Contributors.astro'; :::div{.sponsor} -[Support Knip!][2] +Enjoying Knip? [Support it!][2] ::: diff --git a/packages/docs/src/content/docs/reference/faq.md b/packages/docs/src/content/docs/reference/faq.md index 9e50dac30..0a0e35b29 100644 --- a/packages/docs/src/content/docs/reference/faq.md +++ b/packages/docs/src/content/docs/reference/faq.md @@ -124,6 +124,16 @@ This graph allows to report more interesting details, such as: - List of all binaries used - List of all used (OS) binaries not installed in `node_modules` +### Why doesn't Knip just read the lockfile? + +Knip reads the `package.json` file of each dependency. Most of the information +required is in the lockfile as well, which would be more efficient. However, +there are a few issues with this approach: + +- It requires lockfile parsing for each lockfile format and version of each + package manager. +- The lockfile doesn't contain whether the package [has types included][4]. + ## Module Resolution ### Why doesn't Knip use an existing module resolver? @@ -143,7 +153,7 @@ seem to meet all requirements to be usable on its own by Knip: `module.js` A few strategies have been tried and tweaked, and Knip currently uses a -combination of [enhanced-resolve][4], the TypeScript module resolver and a few +combination of [enhanced-resolve][5], the TypeScript module resolver and a few customizations. This single custom module resolver function is hooked into the TypeScript compiler and language service hosts. @@ -179,7 +189,7 @@ file. They're not a concept in Knip. A TypeScript program has a 1-to-1 relationship with workspaces if they're analyzed in isolation. However, by default Knip optimizes for performance and -utilizes [workspace sharing][5]. That's why debug output contains messages like +utilizes [workspace sharing][6]. That's why debug output contains messages like "Installed 2 programs for 29 workspaces". ### Why doesn't Knip match my TypeScript project structure? @@ -211,7 +221,7 @@ Knip shares the files of multiple workspaces in a single program if their configuration allows it. This optimization is enabled by default, while it also allows the module resolver (one per program) to do some more caching. -Also see [workspace sharing][5]. +Also see [workspace sharing][6]. ### Why doesn't Knip just use `ts.findReferences`? @@ -293,7 +303,7 @@ other file types. 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 Vue "compiler" with the real one in your -project. Also see the answer to the previous question and [Compilers][6]. +project. Also see the answer to the previous question and [Compilers][7]. ## Miscellaneous @@ -322,7 +332,7 @@ Which mode should've been the default? They both have their merits: tooling, including most issues found in production mode. This mode has the most impact on DX, for the same reason. -Also see [production mode][7]. +Also see [production mode][8]. ### Why doesn't Knip have...? @@ -346,13 +356,14 @@ Examples of features that have been requested include: These are all interesting ideas, but most increase the API surface area, and all require more development efforts and maintenance. Time is limited and -[sponsorships][8] currently don't cover - this can change though! +[sponsorships][9] currently don't cover - this can change though! [1]: ../guides/handling-issues.mdx#external-libraries [2]: ../explanations/why-use-knip.md#comprehensive [3]: ../features/script-parser.md -[4]: https://www.npmjs.com/package/enhanced-resolve -[5]: ../guides/performance.md#workspace-sharing -[6]: ../features/compilers.md -[7]: ../features/production-mode.md -[8]: /sponsors +[4]: ../guides/handling-issues.mdx#types-packages +[5]: https://www.npmjs.com/package/enhanced-resolve +[6]: ../guides/performance.md#workspace-sharing +[7]: ../features/compilers.md +[8]: ../features/production-mode.md +[9]: /sponsors diff --git a/packages/docs/src/pages/sponsors.astro b/packages/docs/src/pages/sponsors.astro index 787a70309..306ec43a2 100644 --- a/packages/docs/src/pages/sponsors.astro +++ b/packages/docs/src/pages/sponsors.astro @@ -10,12 +10,12 @@ import SponsorsComponent from '../components/Sponsors.astro';

Knip is a powerful tool that helps thousands of developers keep their - JavaScript and TypeScript projects lean and maintainable. By identifying - unused files, dependencies and exports, Knip saves teams valuable time. + JavaScript and TypeScript projects lean and maintainable. Knip saves + teams valuable time and resources.

- As the creator and primary maintainer, I (Lars Kappert) am dedicated to the continued + As the creator and primary maintainer, I'm dedicated to the continued development and support of Knip. With my deep expertise in JavaScript and TypeScript, its ecosystem, frameworks and tooling, I ensure Knip remains best-in-class. @@ -43,7 +43,7 @@ import SponsorsComponent from '../components/Sponsors.astro';

You or your company logo will be added to this page if you decide to support the project on an ongoing basis. Eternal gratitude to the - companies and people that are already supporting me: + companies and people that are already supporters:

diff --git a/packages/docs/src/styles/content.css b/packages/docs/src/styles/content.css index a5abf84df..54e44baf0 100644 --- a/packages/docs/src/styles/content.css +++ b/packages/docs/src/styles/content.css @@ -142,3 +142,30 @@ section.plugins li { border-color: var(--sl-color-black); } } + +#starlight__search .pagefind-ui__result-title:not(:where(.pagefind-ui__result-nested *)):focus-within, +#starlight__search .pagefind-ui__result-nested:focus-within { + .pagefind-ui__result-link, + .pagefind-ui__result-excerpt, + .pagefind-ui__result-excerpt mark { + color: var(--sl-color-text-accent); + } +} + +:root[data-theme='light'] { + #starlight__search .pagefind-ui__result-title:not(:where(.pagefind-ui__result-nested *)):focus-within, + #starlight__search .pagefind-ui__result-nested:focus-within { + .pagefind-ui__result-link, + .pagefind-ui__result-excerpt, + .pagefind-ui__result-excerpt mark { + color: var(--sl-color-black); + } + } +} + +.social-icons a:hover { + opacity: 1; + svg { + color: var(--sl-color-bright-orange); + } +} diff --git a/packages/knip/src/manifest/helpers.ts b/packages/knip/src/manifest/helpers.ts index 04dd3a3c6..547d37ed2 100644 --- a/packages/knip/src/manifest/helpers.ts +++ b/packages/knip/src/manifest/helpers.ts @@ -21,11 +21,6 @@ export const loadPackageManifest = ({ dir, packageName, cwd }: LoadPackageManife } }; -// type GetFilteredScriptsOptions = { -// isProduction: boolean; -// scripts?: Scripts; -// }; - export const getFilteredScripts = (scripts: Scripts) => { if (!scripts) return [{}, {}];