diff --git a/packages/knip/fixtures/plugins/plop/package.json b/packages/knip/fixtures/plugins/plop/package.json new file mode 100644 index 000000000..770530197 --- /dev/null +++ b/packages/knip/fixtures/plugins/plop/package.json @@ -0,0 +1,11 @@ +{ + "name": "@fixtures/plop", + "version": "*", + "type": "module", + "scripts": { + "plop": "plop" + }, + "dependencies": { + "plop": "*" + } +} diff --git a/packages/knip/fixtures/plugins/plop/plopfile.js b/packages/knip/fixtures/plugins/plop/plopfile.js new file mode 100644 index 000000000..7e814427f --- /dev/null +++ b/packages/knip/fixtures/plugins/plop/plopfile.js @@ -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; \ No newline at end of file diff --git a/packages/knip/fixtures/plugins/plop/template.hbs b/packages/knip/fixtures/plugins/plop/template.hbs new file mode 100644 index 000000000..abe95b32c --- /dev/null +++ b/packages/knip/fixtures/plugins/plop/template.hbs @@ -0,0 +1 @@ +# {{ name }} diff --git a/packages/knip/src/plugins/index.ts b/packages/knip/src/plugins/index.ts index 4d4bcdfd7..ef662e4af 100644 --- a/packages/knip/src/plugins/index.ts +++ b/packages/knip/src/plugins/index.ts @@ -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'; @@ -132,6 +133,7 @@ export const Plugins = { playwright, 'playwright-ct': playwrightCt, 'playwright-test': playwrightTest, + plop, postcss, preconstruct, prettier, diff --git a/packages/knip/src/plugins/plop/index.ts b/packages/knip/src/plugins/plop/index.ts new file mode 100644 index 000000000..4c51d4a02 --- /dev/null +++ b/packages/knip/src/plugins/plop/index.ts @@ -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; diff --git a/packages/knip/src/schema/plugins.ts b/packages/knip/src/schema/plugins.ts index d6ed7d286..9d9f9c176 100644 --- a/packages/knip/src/schema/plugins.ts +++ b/packages/knip/src/schema/plugins.ts @@ -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, diff --git a/packages/knip/src/types/PluginNames.ts b/packages/knip/src/types/PluginNames.ts index eefe407c9..f60c603e7 100644 --- a/packages/knip/src/types/PluginNames.ts +++ b/packages/knip/src/types/PluginNames.ts @@ -46,6 +46,7 @@ export type PluginName = | 'playwright' | 'playwright-ct' | 'playwright-test' + | 'plop' | 'postcss' | 'preconstruct' | 'prettier' @@ -133,6 +134,7 @@ export const pluginNames = [ 'playwright', 'playwright-ct', 'playwright-test', + 'plop', 'postcss', 'preconstruct', 'prettier', diff --git a/packages/knip/test/plugins/plop.test.ts b/packages/knip/test/plugins/plop.test.ts new file mode 100644 index 000000000..767c50bfd --- /dev/null +++ b/packages/knip/test/plugins/plop.test.ts @@ -0,0 +1,23 @@ +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/plop'); + +test('Find dependencies with the plop plugin', async () => { + const { counters } = await main({ + ...baseArguments, + cwd, + }); + + assert.deepEqual(counters, { + ...baseCounters, + binaries: 1, + dependencies: 1, + processed: 1, + total: 1, + }); +});