Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/rolldown-plugin-dts. A Rolldown plugin to generate and bundle dts files.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114import { isLegacyTsgo } from '../tsgo.ts'import { OxcGenerator } from './oxc.ts'import { TscGenerator } from './tsc.ts'import { TsgoCliGenerator } from './tsgo-cli.ts'import { TsgoGenerator } from './tsgo.ts'import type { OptionsResolved } from '../options.ts'import type { RollupError, SourceMapInput } from 'rolldown'
export interface GeneratorResult { /** Generated declaration code. */ code?: string /** Source map for the generated declaration. */ map?: SourceMapInput /** Error reported through Rolldown when declaration generation fails. */ error?: RollupError | string}
/** A declaration generator used by the dts plugin. */export interface Generator { /** Initializes resources at the start of each build. */ init?: () => void | Promise<void> /** Registers transformed source code before declaration generation. */ addFile?: (code: string, fileName: string) => void /** Generates a declaration for a source file. */ emit: ( code: string, fileName: string, ) => GeneratorResult | Promise<GeneratorResult> /** Releases resources at the end of each build. */ dispose?: () => void | Promise<void> /** Invalidates cached state for a changed file in watch mode. */ invalidate?: (fileName: string) => void}
export function createGenerator( { generator, tsconfig, tsconfigRaw, cwd, oxc, languageContext, tsc, tsgo, tsrs, sourcemap, typecheck, }: Pick< OptionsResolved, | 'generator' | 'tsconfig' | 'tsconfigRaw' | 'cwd' | 'oxc' | 'languageContext' | 'tsc' | 'tsgo' | 'tsrs' | 'sourcemap' | 'typecheck' >, getEntries: () => string[] | undefined, loadSource?: (fileName: string) => Promise<void>,): Generator { if (typeof generator !== 'string') return generator
if (generator === 'oxc') { return new OxcGenerator(oxc, languageContext) }
if (generator === 'tsgo' && isLegacyTsgo(tsgo.moduleUrl)) { return new TsgoCliGenerator({ tsgoPath: tsgo.path!, tsconfig: tsconfig!, sourcemap, typecheck, languageContext, }) }
if (generator === 'tsgo' || generator === 'tsrs') { const native = generator === 'tsrs' ? tsrs : tsgo return new TsgoGenerator({ compiler: generator, moduleUrl: native.moduleUrl, tsgoPath: native.path, runExternalCode: native.runExternalCode, cwd, tsconfig: tsconfig!, vfs: !!native.vfs, typecheck, languageContext, loadSource, }) }
return new TscGenerator({ tsconfig, tsconfigRaw, build: tsc.build, incremental: tsc.incremental, cwd, sourcemap, typecheck, languageContext, vue: tsc.vue, parallel: tsc.parallel, newContext: tsc.newContext, getEntries, })}
export { OxcGenerator, TscGenerator, TsgoCliGenerator, TsgoGenerator }