Skip to content

Commit

Permalink
Merge branch 'main' into tanstack-router
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrttn authored Nov 26, 2024
2 parents 16d6a8f + 6e62de8 commit 8392b38
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 40 deletions.
Binary file modified bun.lockb
Binary file not shown.
18 changes: 3 additions & 15 deletions packages/docs/src/components/Sponsors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ const { direction = 'column', showAll = true } = Astro.props;
{showAll &&

<a href="https://forge42.dev">
<img
src="/sponsors/f42.png"
alt="Forge 42"
class="w150"
/>
<img src="/sponsors/f42.png" alt="Forge 42" class="w150" />
</a>

<a href="https://webdriver.io">
Expand Down Expand Up @@ -114,18 +110,10 @@ const { direction = 'column', showAll = true } = Astro.props;
</a>

<a href="https://understandlegacycode.com">
<img
src="/sponsors/nicoespeon.png"
alt="Nicolas Carlo"
class="w150"
/>
<img src="/sponsors/nicoespeon.png" alt="Nicolas Carlo" class="w150" />
</a>

<a href="https://kodfabrik.se">
<img
src="/sponsors/voxpelli.png"
alt="Pelle Wessman"
class="w150"
/>
<img src="/sponsors/voxpelli.png" alt="Pelle Wessman" class="w150" />
</a>}
</div>
26 changes: 26 additions & 0 deletions packages/docs/src/components/SponsorsPast.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="sponsors column">

<a href="https://github.com/hyoban">
<img src="/sponsors/hyoban.png" alt="Hyoban" class="w150" />
</a>

<a href="https://sentry.io">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 44" class="w300">
<style>
.fill {
fill: var(--sl-color-white);
}
@media (prefers-color-scheme: light) {
.fill {
fill: var(--sl-color-black);
}
}
</style>
<path
class="fill"
d="M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z"
></path>
</svg>
</a>

</div>
17 changes: 17 additions & 0 deletions packages/docs/src/content/docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ We can distinguish two types of issues:
Also see the [debug][3] and [trace][4] options below that can help to
troubleshoot issues.

:::note

The JavaScript/TypeScript ecosystem has a vast amount of frameworks and tools,
and even more ways to configure those. Files and dependencies can be referenced
in many ways, not just through static import statements. In short: "it's
complicated". Knip and documentation are always a work in progress.

If it doesn't come your way at the first try, please understand this also shows
the dynamic and innovative nature of the ecosystem. Often only small changes go
a long way towards success. Consider
[opening an issue](https://github.com/webpro-nl/knip/issues/new/choose) and/or
[ask away on Discord](https://discord.gg/r5uXTtbTpc). With the help of the
community (that's you!) we can improve Knip for everyone and make project
maintenance easier and more fun!

:::

## Lint issues reported by Knip

Knip reports lint issues in your codebase. See [handling issues][5] to deal with
Expand Down
6 changes: 5 additions & 1 deletion packages/docs/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ Array of workspaces to ignore, globs allowed. Example:

```json title="knip.json"
{
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
"ignoreWorkspaces": [
"packages/go-server",
"packages/flat/*"
"packages/deep/**"
]
}
```

Expand Down
62 changes: 47 additions & 15 deletions packages/docs/src/content/docs/reference/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,53 @@ Knip finds and removes unused files, dependencies and exports. As a "kitchen
sink" in the npm ecosystem, it creates a comprehensive module and dependency
graph of your project.

The JavaScript ecosystem has a vast amount of frameworks and tools, and even
more ways to configure those. Files and dependencies can be referenced in many
ways, not just through import statements. This FAQ is an attempt to provide some
perspective on a few design decisions and why certain things work the way they
do. Here and there it's intentionally a bit more in-depth than the rest of the
docs.
:::note

The JavaScript/TypeScript ecosystem has a vast amount of frameworks and tools,
and even more ways to configure those. Files and dependencies can be referenced
in many ways, not just through static import statements. In short: "it's
complicated". Knip and documentation are always a work in progress.

:::

This FAQ is an attempt to provide some perspective on a few design decisions and
why certain things work the way they do. Here and there it's intentionally a bit
more in-depth than the rest of the docs.

## Comparison

### Why isn't Knip an ESLint plugin?

Linters like ESLint analyze files separately, while Knip lints projects as a
whole.

Knip requires a full module and dependency graph to find clutter across the
project. Creating this comprehensive graph is not a trivial task and it seems no
such tool exists today, even more so when it comes to monorepos.

File-oriented linters like ESLint and Knip are complementary tools.

### Isn't tree-shaking enough?

In short: no. They share an important goal: improve UX by removing unused code.
The main takeaway here is that tree-shaking and Knip are different and
complementary tools.

Tree-shaking is a build or compile-time activity to reduce production bundle
size. It typically operates on bundled production code, which might include
external/third-party code. An optimization in the build process, "out of your
hands".

On the other hand, Knip is a project linter that should be part of QA. It lints,
reports and fixes only your own source code. A linter reporting issues hands
control back to you (unless you [auto-fix](../features/auto-fix.mdx)
everything).

Besides those differences, Knip has a broader scope:

- Improve DX (see [less is more](../explanations/why-use-knip.md#less-is-more)).
- Include non-production code and dependencies in the process by default.
- Report more [issue types](./issue-types.md) (such as unlisted dependencies).

## Synergy

Expand Down Expand Up @@ -307,15 +348,6 @@ project. Also see the answer to the previous question and [Compilers][7].

## Miscellaneous

### Why isn't Knip an ESLint plugin?

Linters like ESLint analyze files separately, while Knip lints projects as a
whole.

Knip requires a full module and dependency graph to find clutter across the
project. Creating this comprehensive graph is not a trivial task and it seems no
such tool exists today, even more so when it comes to monorepos.

### Why isn't production mode the default?

The default mode of Knip includes all source files, tests, dependencies, dev
Expand Down
9 changes: 9 additions & 0 deletions packages/docs/src/pages/sponsors.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import Posts from '../components/Posts.astro';
import Projects from '../components/Projects.astro';
import SponsorsComponent from '../components/Sponsors.astro';
import SponsorsPast from '../components/SponsorsPast.astro';
---

<StarlightPage frontmatter={{ title: 'Become a sponsor!', template: 'splash' }}>
Expand Down Expand Up @@ -56,6 +57,14 @@ import SponsorsComponent from '../components/Sponsors.astro';

</article>

<h2 id="projects-using-knip">🧡 Past Sponsors</h2>

<div class="sponsors">

<SponsorsPast />

</div>

<h2 id="projects-using-knip">🧡 Projects using Knip</h2>

<section class="columns min300">
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/src/styles/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
}
}

:root[data-theme='dark'] {
.card {
border: none;
}
}

:root[data-theme='light'] {
.card .title .icon {
color: var(--sl-color-black);
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/styles/sponsors.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
justify-content: start;
align-items: center;
gap: 5rem;
margin-bottom: 3rem;
Expand Down
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/knip/fixtures/plugins/plop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@fixtures/plop",
"version": "*",
"type": "module",
"scripts": {
"plop": "plop"
},
"dependencies": {
"plop": "*"
}
}
27 changes: 27 additions & 0 deletions packages/knip/fixtures/plugins/plop/plopfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const page = {
description: 'Create a documentation page',

prompts: [
{
type: 'input',
name: 'name',
message: 'What is the page name',
},
],

actions(prompts) {
return [
{
type: 'add',
path: `./doc/{{ dashCase name }}.md`,
templateFile: 'template.hbs',
},
];
},
};

function plopConfig(plop) {
plop.setGenerator('Page', page);
}

export default plopConfig;
1 change: 1 addition & 0 deletions packages/knip/fixtures/plugins/plop/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# {{ name }}
6 changes: 5 additions & 1 deletion packages/knip/fixtures/workspaces-ignored/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"packages/c",
"packages/d*",
"packages/f",
"packages/g"
"packages/g",
"packages/deep/**",
"packages/flat/*",
"packages/un/**/used",
"packages/wut/*"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@workspaces-ignored/deep-h2",
"scripts": {
"start": "ignored"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@workspaces-ignored/flat-i1",
"scripts": {
"start": "ignored"
}
}
2 changes: 2 additions & 0 deletions packages/knip/fixtures/workspaces-ignored/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
packages:
- 'packages/*'
- 'packages/flat/*'
- 'packages/deep/er/*'
- '!packages/a'
- '!packages/b*'
4 changes: 2 additions & 2 deletions packages/knip/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "knip",
"version": "5.37.2",
"version": "5.38.0",
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
"homepage": "https://knip.dev",
"repository": {
Expand Down Expand Up @@ -69,7 +69,7 @@
"picocolors": "^1.1.0",
"picomatch": "^4.0.1",
"pretty-ms": "^9.0.0",
"smol-toml": "^1.3.0",
"smol-toml": "^1.3.1",
"strip-json-comments": "5.0.1",
"summary": "2.1.0",
"zod": "^3.22.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/knip/src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ export class ConfigurationChief {
const ignoredWorkspacesManifest = this.getListedWorkspaces()
.filter(name => name.startsWith('!'))
.map(name => name.replace(/^!/, ''));
const ignoredWorkspacesConfig = this.config.ignoreWorkspaces.map(name => name.replace(/\/\*$/, ''));
return [...ignoredWorkspacesManifest, ...ignoredWorkspacesConfig];
return [...ignoredWorkspacesManifest, ...this.config.ignoreWorkspaces];
}

private getConfiguredWorkspaceKeys() {
Expand Down
2 changes: 2 additions & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { default as oclif } from './oclif/index.js';
import { default as playwrightCt } from './playwright-ct/index.js';
import { default as playwrightTest } from './playwright-test/index.js';
import { default as playwright } from './playwright/index.js';
import { default as plop } from './plop/index.js';
import { default as postcss } from './postcss/index.js';
import { default as preconstruct } from './preconstruct/index.js';
import { default as prettier } from './prettier/index.js';
Expand Down Expand Up @@ -133,6 +134,7 @@ export const Plugins = {
playwright,
'playwright-ct': playwrightCt,
'playwright-test': playwrightTest,
plop,
postcss,
preconstruct,
prettier,
Expand Down
19 changes: 19 additions & 0 deletions packages/knip/src/plugins/plop/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { IsPluginEnabled, Plugin } from '../../types/config.js';
import { hasDependency } from '../../util/plugin.js';

// https://github.com/plopjs/plop/blob/main/README.md

const title = 'Plop';

const enablers = ['plop'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config = ['plopfile.{cjs,mjs,js,ts}'];

export default {
title,
enablers,
isEnabled,
config,
} satisfies Plugin;
2 changes: 1 addition & 1 deletion packages/knip/src/plugins/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Argv, Env, WebpackConfig } from './types.js';

// https://webpack.js.org/configuration/

const title = 'Webpack';
const title = 'webpack';

const enablers = ['webpack', 'webpack-cli'];

Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/schema/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const pluginsSchema = z.object({
playwright: pluginSchema,
'playwright-ct': pluginSchema,
'playwright-test': pluginSchema,
plop: pluginSchema,
postcss: pluginSchema,
preconstruct: pluginSchema,
prettier: pluginSchema,
Expand Down
2 changes: 2 additions & 0 deletions packages/knip/src/types/PluginNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type PluginName =
| 'playwright'
| 'playwright-ct'
| 'playwright-test'
| 'plop'
| 'postcss'
| 'preconstruct'
| 'prettier'
Expand Down Expand Up @@ -133,6 +134,7 @@ export const pluginNames = [
'playwright',
'playwright-ct',
'playwright-test',
'plop',
'postcss',
'preconstruct',
'prettier',
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '5.37.2';
export const version = '5.38.0';
Loading

0 comments on commit 8392b38

Please sign in to comment.