Skip to content

Commit

Permalink
feat(plugins): add plugin for syncpack config (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMK85 authored May 11, 2024
1 parent da2a5c8 commit 44005ef
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugins/syncpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@fixtures/syncpack",
"version": "*",
"devDependencies": {
"syncpack": "*"
}
}
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/ConfigurationValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const pluginsSchema = z.object({
stryker: pluginSchema,
stylelint: pluginSchema,
svelte: pluginSchema,
syncpack: pluginSchema,
tailwind: pluginSchema,
tsup: pluginSchema,
typedoc: pluginSchema,
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
20 changes: 20 additions & 0 deletions packages/knip/src/plugins/syncpack/index.ts
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions packages/knip/test/plugins/syncpack.test.ts
Original file line number Diff line number Diff line change
@@ -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,
});
});

0 comments on commit 44005ef

Please sign in to comment.