Skip to content

Commit e65f709

Browse files
committed
Reuse existing entry/production patterns in astro plugin
1 parent 021ecff commit e65f709

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

packages/knip/src/plugins/astro/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ const production = [
2424

2525
const resolveFromAST: ResolveFromAST = sourceFile => {
2626
const srcDir = getSrcDir(sourceFile);
27+
const setSrcDir = (entry: string) => entry.replace(/^`src\//, `${srcDir}/`);
2728

2829
return [
29-
...[`${srcDir}/content/config.ts`, `${srcDir}/content.config.ts`].map(path => toEntry(path)),
30-
31-
...[
32-
`${srcDir}/pages/**/*.{astro,mdx,js,ts}`,
33-
`${srcDir}/content/**/*.mdx`,
34-
`${srcDir}/middleware.{js,ts}`,
35-
`${srcDir}/actions/index.{js,ts}`,
36-
].map(path => toProductionEntry(path)),
30+
...entry.map(setSrcDir).map(path => toEntry(path)),
31+
...production.map(setSrcDir).map(path => toProductionEntry(path)),
3732
];
3833
};
3934

packages/knip/src/plugins/astro/resolveFromAST.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ export const getSrcDir = (sourceFile: ts.SourceFile): string => {
2525
return result;
2626
}
2727

28-
const foundValue = visit(sourceFile);
29-
return foundValue ?? srcDir;
28+
return visit(sourceFile) ?? srcDir;
3029
};

0 commit comments

Comments
 (0)