From 8a5efb18b4ff8ce85ab244496cd905b7a139fcd1 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Tue, 17 Oct 2023 12:42:48 +0200 Subject: [PATCH] Wrap up astro plugin --- README.md | 2 ++ src/plugins/astro/README.md | 18 ++++++++++++------ src/plugins/astro/index.ts | 11 ++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e27ec405d..a65f012c4 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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 diff --git a/src/plugins/astro/README.md b/src/plugins/astro/README.md index 1415dd0d8..a2e6b4202 100644 --- a/src/plugins/astro/README.md +++ b/src/plugins/astro/README.md @@ -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" + ] } } ``` diff --git a/src/plugins/astro/index.ts b/src/plugins/astro/index.ts index 080f45d3b..009b5a06c 100644 --- a/src/plugins/astro/index.ts +++ b/src/plugins/astro/index.ts @@ -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)]; +};