| 1 | import { resolve } from 'node:path'; |
| 2 | import dts from 'vite-plugin-dts'; |
| 3 | import { rewriteLegacyPluginDtsPath } from '../build/dts-paths.ts'; |
| 4 | |
| 5 | export function createPluginDts(pluginName: string) { |
| 6 | return dts({ |
| 7 | include: [`plugin/${pluginName}/index.ts`], |
| 8 | entryRoot: 'plugin', |
| 9 | outDir: 'dist/plugin', |
| 10 | beforeWriteFile(filePath, content) { |
| 11 | const rewrittenPath = rewriteLegacyPluginDtsPath(filePath, pluginName); |
| 12 | |
| 13 | if (!rewrittenPath) { |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | return { |
| 18 | filePath: resolve(rewrittenPath), |
| 19 | content, |
| 20 | }; |
| 21 | }, |
| 22 | }); |
| 23 | } |
| 24 |