diff --git a/fixtures/plugins/astro/package.json b/fixtures/plugins/astro/package.json index 304895195..3e912aa11 100644 --- a/fixtures/plugins/astro/package.json +++ b/fixtures/plugins/astro/package.json @@ -7,12 +7,16 @@ "start": "astro dev", "build": "astro build", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "check": "astro check" }, "dependencies": { "@astrojs/mdx": "*", "@astrojs/rss": "*", "@astrojs/sitemap": "*", "astro": "*" + }, + "devDependencies": { + "@astrojs/check": "*" } } \ No newline at end of file diff --git a/src/plugins/astro/index.ts b/src/plugins/astro/index.ts index bf240822a..d8ae984cb 100644 --- a/src/plugins/astro/index.ts +++ b/src/plugins/astro/index.ts @@ -18,9 +18,15 @@ export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx']; export const findDependencies: GenericPluginCallback = async (configFilePath, options) => { - const { config } = options; + const { config, manifest } = options; - return config.entry + const dependencies = config.entry ? config.entry.map(toProductionEntryPattern) : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)]; + + if (manifest.scripts && Object.values(manifest.scripts).some(script => /astro (--.+ )?check/.test(script))) { + dependencies.push('@astrojs/check'); + } + + return dependencies; }; diff --git a/test/plugins/astro.test.ts b/test/plugins/astro.test.ts index 990cb9a31..0166b3517 100644 --- a/test/plugins/astro.test.ts +++ b/test/plugins/astro.test.ts @@ -8,11 +8,13 @@ import baseCounters from '../helpers/baseCounters.js'; const cwd = resolve('fixtures/plugins/astro'); test('Find dependencies in Astro configuration', async () => { - const { counters } = await main({ + const { issues, counters } = await main({ ...baseArguments, cwd, }); + assert(!issues.devDependencies['package.json']['@astrojs/check']); + assert.deepEqual(counters, { ...baseCounters, processed: 18,