diff --git a/packages/knip/fixtures/plugins/syncpack/package.json b/packages/knip/fixtures/plugins/syncpack/package.json new file mode 100644 index 000000000..2983d87bc --- /dev/null +++ b/packages/knip/fixtures/plugins/syncpack/package.json @@ -0,0 +1,7 @@ +{ + "name": "@fixtures/syncpack", + "version": "*", + "devDependencies": { + "syncpack": "*" + } +} diff --git a/packages/knip/schema.json b/packages/knip/schema.json index e57fee421..a182df258 100644 --- a/packages/knip/schema.json +++ b/packages/knip/schema.json @@ -459,6 +459,10 @@ "title": "svelte plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/svelte/README.md)", "$ref": "#/definitions/plugin" }, + "syncpack": { + "title": "syncpack plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/syncpack/README.md)", + "$ref": "#/definitions/plugin" + }, "tailwind": { "title": "tailwind plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/tailwind/README.md)", "$ref": "#/definitions/plugin" diff --git a/packages/knip/src/ConfigurationValidator.ts b/packages/knip/src/ConfigurationValidator.ts index a81858b7e..8435812b3 100644 --- a/packages/knip/src/ConfigurationValidator.ts +++ b/packages/knip/src/ConfigurationValidator.ts @@ -123,6 +123,7 @@ const pluginsSchema = z.object({ stryker: pluginSchema, stylelint: pluginSchema, svelte: pluginSchema, + syncpack: pluginSchema, tailwind: pluginSchema, tsup: pluginSchema, typedoc: pluginSchema, diff --git a/packages/knip/src/plugins/index.ts b/packages/knip/src/plugins/index.ts index d8c18f918..ce3c4f73e 100644 --- a/packages/knip/src/plugins/index.ts +++ b/packages/knip/src/plugins/index.ts @@ -45,6 +45,7 @@ export { default as storybook } from './storybook/index.js'; export { default as stryker } from './stryker/index.js'; export { default as stylelint } from './stylelint/index.js'; export { default as svelte } from './svelte/index.js'; +export { default as syncpack } from './syncpack/index.js'; export { default as tailwind } from './tailwind/index.js'; export { default as tsup } from './tsup/index.js'; export { default as typedoc } from './typedoc/index.js'; diff --git a/packages/knip/src/plugins/syncpack/index.ts b/packages/knip/src/plugins/syncpack/index.ts new file mode 100644 index 000000000..0100a486b --- /dev/null +++ b/packages/knip/src/plugins/syncpack/index.ts @@ -0,0 +1,20 @@ +import type { EnablerPatterns } from '#p/types/config.js'; +import type { IsPluginEnabled, Plugin } from '#p/types/plugins.js'; +import { hasDependency } from '#p/util/plugin.js'; + +// link to syncpack docs https://jamiemason.github.io/syncpack/config/syncpackrc/ + +const title = 'Syncpack'; + +const enablers: EnablerPatterns = ['syncpack']; + +const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); + +const config = ['.syncpackrc', '.syncpackrc.{json,yaml,yml,js,cjs}', '.syncpack.config.{js,cjs}']; + +export default { + title, + enablers, + isEnabled, + config, +} satisfies Plugin; diff --git a/packages/knip/test/plugins/syncpack.test.ts b/packages/knip/test/plugins/syncpack.test.ts new file mode 100644 index 000000000..8820d9335 --- /dev/null +++ b/packages/knip/test/plugins/syncpack.test.ts @@ -0,0 +1,22 @@ +import { test } from 'bun:test'; +import assert from 'node:assert/strict'; +import { main } from '../../src/index.js'; +import { resolve } from '../../src/util/path.js'; +import baseArguments from '../helpers/baseArguments.js'; +import baseCounters from '../helpers/baseCounters.js'; + +const cwd = resolve('fixtures/plugins/syncpack'); + +test('Find dependencies with the Syncpack plugin', async () => { + const { counters } = await main({ + ...baseArguments, + cwd, + }); + + assert.deepEqual(counters, { + ...baseCounters, + devDependencies: 1, + processed: 0, + total: 0, + }); +});