Skip to content

Commit

Permalink
Make plugins export default
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 16, 2024
1 parent 9482c09 commit d8babee
Show file tree
Hide file tree
Showing 102 changed files with 927 additions and 1,103 deletions.
13 changes: 8 additions & 5 deletions packages/docs/scripts/generate-plugin-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import remarkStringify from 'remark-stringify';
import { unified } from 'unified';
import { u } from 'unist-builder';
import { base } from '../config.js';
import type { Plugin } from '../../knip/src/types/plugins.js';
import type { Root } from 'mdast';
import type { Node } from 'unist';

Expand Down Expand Up @@ -50,24 +51,26 @@ for await (const dir of directories) {
if (dir.isDirectory() && dir.name !== '_template') {
const pluginName = dir.name;
const pluginDir = path.join(pluginsDir, pluginName);
const plugin: Plugin = (await import(path.join(pluginDir, 'index.ts'))).default;

const {
NAME,
ENABLERS,
CONFIG_FILE_PATTERNS: config,
ENTRY_FILE_PATTERNS: entry,
PRODUCTION_ENTRY_FILE_PATTERNS: production,
PROJECT_FILE_PATTERNS: project,
} = await import(path.join(pluginDir, 'index.ts'));
} = plugin;

plugins.push([NAME, pluginName]);

const frontmatter = u('yaml', `title: ${NAME}`);

const defaults: Record<string, string[]> = {};
if (config?.length > 0) defaults.config = config;
if (entry?.length > 0) defaults.entry = entry;
if (production?.length > 0) defaults.entry = [...(defaults.entry ?? []), ...production];
if (project?.length > 0) defaults.project = project;
if (config && config.length > 0) defaults.config = config;
if (entry && entry.length > 0) defaults.entry = entry;
if (production && production.length > 0) defaults.entry = [...(defaults.entry ?? []), ...production];
if (project && project.length > 0) defaults.project = project;

const en =
Array.isArray(ENABLERS) && ENABLERS.length > 0
Expand Down
13 changes: 6 additions & 7 deletions packages/docs/src/content/docs/guides/writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The name of the plugin to display in the [list of plugins][1] and in debug
output.

```ts title="src/plugins/cool-linter/index.ts"
export const NAME = 'Cool Linter';
const NAME = 'Cool Linter';
```

### `ENABLERS`
Expand All @@ -46,16 +46,15 @@ dependencies so the `isEnabled` function can determine whether the plugin should
be enabled or not. This is often a single package name, for example:

```ts title="src/plugins/cool-linter/index.ts"
export const ENABLERS = ['cool-linter'];
const ENABLERS = ['cool-linter'];
```

### `isEnabled`

This function can be fairly straightforward with the `hasDependency` helper:

```ts title="src/plugins/cool-linter/index.ts"
export const isEnabled = ({ dependencies }) =>
hasDependency(dependencies, ENABLERS);
const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
```

This will check whether a match is found in the `dependencies` or
Expand Down Expand Up @@ -98,7 +97,7 @@ configuration file:
And here's how we can define this config file pattern from the plugin:

```ts title="src/plugins/cool-linter/index.ts"
export const CONFIG_FILE_PATTERNS = ['cool-linter.config.{js,json}'];
const CONFIG_FILE_PATTERNS = ['cool-linter.config.{js,json}'];
```

For each configuration file with a match in `CONFIG_FILE_PATTERNS`, the
Expand Down Expand Up @@ -154,7 +153,7 @@ const findCoolLinterDependencies: GenericPluginCallback =
return [...addons, ...plugins];
};

export const findDependencies = timerify(findCoolLinterDependencies);
const findDependencies = timerify(findCoolLinterDependencies);
```

#### Notes
Expand Down Expand Up @@ -215,7 +214,7 @@ here they can be explicitly added, regardless of the user's `project` files
configuration.

```ts title="src/plugins/cool-linter/index.ts"
export const PROJECT_FILE_PATTERNS = ['.storybook/**/*.{js,jsx,ts,tsx}'];
const PROJECT_FILE_PATTERNS = ['.storybook/**/*.{js,jsx,ts,tsx}'];
```

Most plugins don't need to set this, since the [default configuration for
Expand Down
157 changes: 52 additions & 105 deletions packages/docs/src/content/docs/reference/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,57 @@ tableOfContents: false

:::section{.columns.min200}

- [Angular][1]
- [Astro][2]
- [Ava][3]
- [Babel][4]
- [Capacitor][5]
- [Changesets][6]
- [Commitizen][7]
- [commitlint][8]
- [cspell][9]
- [Cypress][10]
- [Drizzle][11]
- [Eleventy][12]
- [ESLint][13]
- [Gatsby][14]
- [GitHub Actions][15]
- [GraphQL Codegen][16]
- [husky][17]
- [Jest][18]
- [Lefthook][19]
- [lint-staged][20]
- [LintHTML][21]
- [markdownlint][22]
- [Mocha][23]
- [Next.js][24]
- [Node.js Test Runner][25]
- [npm-package-json-lint][26]
- [Nx][27]
- [nyc][28]
- [Playwright][29]
- [Playwright for components][30]
- [PostCSS][31]
- [Prettier][32]
- [Release It][33]
- [Remark][34]
- [Remix][35]
- [Rollup][36]
- [Semantic Release][37]
- [Sentry][38]
- [Storybook][39]
- [Stryker][40]
- [Stylelint][41]
- [Svelte][42]
- [Tailwind][43]
- [tsup][44]
- [TypeDoc][45]
- [TypeScript][46]
- [unbuild][47]
- [Vite][48]
- [Vitest][49]
- [Vue][50]
- [Webpack][51]
- [Wireit][52]
- [Angular](/reference/plugins/angular 'Angular')
- [Astro](/reference/plugins/astro 'Astro')
- [Ava](/reference/plugins/ava 'Ava')
- [Babel](/reference/plugins/babel 'Babel')
- [Capacitor](/reference/plugins/capacitor 'Capacitor')
- [Changesets](/reference/plugins/changesets 'Changesets')
- [Commitizen](/reference/plugins/commitizen 'Commitizen')
- [commitlint](/reference/plugins/commitlint 'commitlint')
- [cspell](/reference/plugins/cspell 'cspell')
- [Cypress](/reference/plugins/cypress 'Cypress')
- [Drizzle](/reference/plugins/drizzle 'Drizzle')
- [Eleventy](/reference/plugins/eleventy 'Eleventy')
- [ESLint](/reference/plugins/eslint 'ESLint')
- [Gatsby](/reference/plugins/gatsby 'Gatsby')
- [GitHub Actions](/reference/plugins/github-actions 'GitHub Actions')
- [GraphQL Codegen](/reference/plugins/graphql-codegen 'GraphQL Codegen')
- [husky](/reference/plugins/husky 'husky')
- [Jest](/reference/plugins/jest 'Jest')
- [Lefthook](/reference/plugins/lefthook 'Lefthook')
- [lint-staged](/reference/plugins/lint-staged 'lint-staged')
- [LintHTML](/reference/plugins/linthtml 'LintHTML')
- [markdownlint](/reference/plugins/markdownlint 'markdownlint')
- [Mocha](/reference/plugins/mocha 'Mocha')
- [Next.js](/reference/plugins/next 'Next.js')
- [Node.js Test Runner](/reference/plugins/node-test-runner 'Node.js Test Runner')
- [npm-package-json-lint](/reference/plugins/npm-package-json-lint 'npm-package-json-lint')
- [Nx](/reference/plugins/nx 'Nx')
- [nyc](/reference/plugins/nyc 'nyc')
- [Playwright](/reference/plugins/playwright 'Playwright')
- [Playwright for components](/reference/plugins/playwright-ct 'Playwright for components')
- [PostCSS](/reference/plugins/postcss 'PostCSS')
- [Prettier](/reference/plugins/prettier 'Prettier')
- [Release It](/reference/plugins/release-it 'Release It')
- [Remark](/reference/plugins/remark 'Remark')
- [Remix](/reference/plugins/remix 'Remix')
- [Rollup](/reference/plugins/rollup 'Rollup')
- [Semantic Release](/reference/plugins/semantic-release 'Semantic Release')
- [Sentry](/reference/plugins/sentry 'Sentry')
- [Storybook](/reference/plugins/storybook 'Storybook')
- [Stryker](/reference/plugins/stryker 'Stryker')
- [Stylelint](/reference/plugins/stylelint 'Stylelint')
- [Svelte](/reference/plugins/svelte 'Svelte')
- [Tailwind](/reference/plugins/tailwind 'Tailwind')
- [tsup](/reference/plugins/tsup 'tsup')
- [TypeDoc](/reference/plugins/typedoc 'TypeDoc')
- [TypeScript](/reference/plugins/typescript 'TypeScript')
- [unbuild](/reference/plugins/unbuild 'unbuild')
- [Vite](/reference/plugins/vite 'Vite')
- [Vitest](/reference/plugins/vitest 'Vitest')
- [Vue](/reference/plugins/vue 'Vue')
- [Webpack](/reference/plugins/webpack 'Webpack')
- [Wireit](/reference/plugins/wireit 'Wireit')

:::

[1]: /reference/plugins/angular 'Angular'
[2]: /reference/plugins/astro 'Astro'
[3]: /reference/plugins/ava 'Ava'
[4]: /reference/plugins/babel 'Babel'
[5]: /reference/plugins/capacitor 'Capacitor'
[6]: /reference/plugins/changesets 'Changesets'
[7]: /reference/plugins/commitizen 'Commitizen'
[8]: /reference/plugins/commitlint 'commitlint'
[9]: /reference/plugins/cspell 'cspell'
[10]: /reference/plugins/cypress 'Cypress'
[11]: /reference/plugins/drizzle 'Drizzle'
[12]: /reference/plugins/eleventy 'Eleventy'
[13]: /reference/plugins/eslint 'ESLint'
[14]: /reference/plugins/gatsby 'Gatsby'
[15]: /reference/plugins/github-actions 'GitHub Actions'
[16]: /reference/plugins/graphql-codegen 'GraphQL Codegen'
[17]: /reference/plugins/husky 'husky'
[18]: /reference/plugins/jest 'Jest'
[19]: /reference/plugins/lefthook 'Lefthook'
[20]: /reference/plugins/lint-staged 'lint-staged'
[21]: /reference/plugins/linthtml 'LintHTML'
[22]: /reference/plugins/markdownlint 'markdownlint'
[23]: /reference/plugins/mocha 'Mocha'
[24]: /reference/plugins/next 'Next.js'
[25]: /reference/plugins/node-test-runner 'Node.js Test Runner'
[26]: /reference/plugins/npm-package-json-lint 'npm-package-json-lint'
[27]: /reference/plugins/nx 'Nx'
[28]: /reference/plugins/nyc 'nyc'
[29]: /reference/plugins/playwright 'Playwright'
[30]: /reference/plugins/playwright-ct 'Playwright for components'
[31]: /reference/plugins/postcss 'PostCSS'
[32]: /reference/plugins/prettier 'Prettier'
[33]: /reference/plugins/release-it 'Release It'
[34]: /reference/plugins/remark 'Remark'
[35]: /reference/plugins/remix 'Remix'
[36]: /reference/plugins/rollup 'Rollup'
[37]: /reference/plugins/semantic-release 'Semantic Release'
[38]: /reference/plugins/sentry 'Sentry'
[39]: /reference/plugins/storybook 'Storybook'
[40]: /reference/plugins/stryker 'Stryker'
[41]: /reference/plugins/stylelint 'Stylelint'
[42]: /reference/plugins/svelte 'Svelte'
[43]: /reference/plugins/tailwind 'Tailwind'
[44]: /reference/plugins/tsup 'tsup'
[45]: /reference/plugins/typedoc 'TypeDoc'
[46]: /reference/plugins/typescript 'TypeScript'
[47]: /reference/plugins/unbuild 'unbuild'
[48]: /reference/plugins/vite 'Vite'
[49]: /reference/plugins/vitest 'Vitest'
[50]: /reference/plugins/vue 'Vue'
[51]: /reference/plugins/webpack 'Webpack'
[52]: /reference/plugins/wireit 'Wireit'
Loading

0 comments on commit d8babee

Please sign in to comment.