Skip to content

Commit e81eac3

Browse files
lishaduckwebpro
andauthored
feat: pnpm plugin (#1219)
Co-authored-by: Lars Kappert <[email protected]>
1 parent 165c9ea commit e81eac3

File tree

9 files changed

+47
-0
lines changed

9 files changed

+47
-0
lines changed

packages/knip/fixtures/plugins/pnpm/.pnpmfile.cjs

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"packageManager": "[email protected]"
3+
}

packages/knip/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@
547547
"title": "playwright-test plugin configuration (https://knip.dev/reference/plugins/playwright-test)",
548548
"$ref": "#/definitions/plugin"
549549
},
550+
"pnpm": {
551+
"title": "pnpm plugin configuration (https://knip.dev/reference/plugins/pnpm)",
552+
"$ref": "#/definitions/plugin"
553+
},
550554
"postcss": {
551555
"title": "PostCSS plugin configuration (https://knip.dev/reference/plugins/postcss)",
552556
"$ref": "#/definitions/plugin"

packages/knip/src/plugins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import { default as playwrightCt } from './playwright-ct/index.js';
6262
import { default as playwrightTest } from './playwright-test/index.js';
6363
import { default as playwright } from './playwright/index.js';
6464
import { default as plop } from './plop/index.js';
65+
import { default as pnpm } from './pnpm/index.js';
6566
import { default as postcss } from './postcss/index.js';
6667
import { default as preconstruct } from './preconstruct/index.js';
6768
import { default as prettier } from './prettier/index.js';
@@ -175,6 +176,7 @@ export const Plugins = {
175176
'playwright-ct': playwrightCt,
176177
'playwright-test': playwrightTest,
177178
plop,
179+
pnpm,
178180
postcss,
179181
preconstruct,
180182
prettier,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { IsPluginEnabled, Plugin } from '../../types/config.js';
2+
3+
// https://pnpm.io/pnpmfile
4+
5+
const title = 'pnpm';
6+
7+
const isEnabled: IsPluginEnabled = ({ manifest }) => Boolean(manifest.packageManager?.startsWith('pnpm@'));
8+
9+
const config: string[] = ['.pnpmfile.cjs'];
10+
11+
export default {
12+
title,
13+
isEnabled,
14+
config,
15+
} satisfies Plugin;

packages/knip/src/schema/plugins.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const pluginsSchema = z.object({
7676
'playwright-ct': pluginSchema,
7777
'playwright-test': pluginSchema,
7878
plop: pluginSchema,
79+
pnpm: pluginSchema,
7980
postcss: pluginSchema,
8081
preconstruct: pluginSchema,
8182
prettier: pluginSchema,

packages/knip/src/types/PluginNames.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type PluginName =
6363
| 'playwright-ct'
6464
| 'playwright-test'
6565
| 'plop'
66+
| 'pnpm'
6667
| 'postcss'
6768
| 'preconstruct'
6869
| 'prettier'
@@ -176,6 +177,7 @@ export const pluginNames = [
176177
'playwright-ct',
177178
'playwright-test',
178179
'plop',
180+
'pnpm',
179181
'postcss',
180182
'preconstruct',
181183
'prettier',

packages/knip/src/types/package-json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type PackageJson = {
4646
browser?: string;
4747
types?: string;
4848
typings?: string;
49+
packageManager?: string;
4950
} & Plugins;
5051

5152
export type WorkspacePackage = {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { createOptions } from '../../src/util/create-options.js';
5+
import baseCounters from '../helpers/baseCounters.js';
6+
import { resolve } from '../helpers/resolve.js';
7+
8+
const cwd = resolve('fixtures/plugins/pnpm');
9+
10+
test('Find dependencies with the pnpm plugin', async () => {
11+
const options = await createOptions({ cwd });
12+
const { counters } = await main(options);
13+
14+
assert.deepEqual(counters, {
15+
...baseCounters,
16+
processed: 1,
17+
total: 1,
18+
});
19+
});

0 commit comments

Comments
 (0)