Skip to content

Commit

Permalink
Wrap up astro plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 17, 2023
1 parent 5108806 commit 8a5efb1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ This is especially useful over time when such configuration files change (and th
Knip contains a growing list of plugins:

- [Angular][plugin-angular]
- [astro][plugin-astro]
- [Ava][plugin-ava]
- [Babel][plugin-babel]
- [Capacitor][plugin-capacitor]
Expand Down Expand Up @@ -898,6 +899,7 @@ Special thanks to the wonderful people who have contributed to this project:
[72]: https://github.com/webpro/knip/graphs/contributors
[73]: https://contrib.rocks/image?repo=webpro/knip
[plugin-angular]: ./src/plugins/angular
[plugin-astro]: ./src/plugins/astro
[plugin-ava]: ./src/plugins/ava
[plugin-babel]: ./src/plugins/babel
[plugin-capacitor]: ./src/plugins/capacitor
Expand Down
18 changes: 12 additions & 6 deletions src/plugins/astro/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# PLUGIN_TITLE
# astro

## Enabled

PLUGIN_ENABLER
This plugin is enabled when any of the following package names and/or regular expressions has a match in `dependencies`
or `devDependencies`:

- `astro`

## Default configuration

```json
{
"PLUGIN_NAME": {
"config": [],
"entry": [],
"project": []
"astro": {
"entry": [
"astro.config.{js,cjs,mjs,ts}",
"src/content/config.ts",
"src/pages/**/*.{astro,mdx,js,ts}",
"src/content/**/*.mdx"
]
}
}
```
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/astro/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { hasDependency } from '../../util/plugin.js';
import type { IsPluginEnabledCallback } from '../../types/plugins.js';
import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';

// https://docs.astro.build/en/reference/configuration-reference/

export const NAME = 'astro';
export const NAME = 'Astro';

/** @public */
export const ENABLERS = ['astro'];

export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS);

/** @public */
export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content/config.ts'];

/** @public */
export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx'];

export const PROJECT_FILE_PATTERNS = ['src/**/*'];
export const findDependencies: GenericPluginCallback = async () => {
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
};

0 comments on commit 8a5efb1

Please sign in to comment.