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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { RUNTIME_MODULE_ID, type ChunkFileNamesFunction, type PreRenderedChunk,} from 'rolldown'import { exactRegex } from 'rolldown/filter'import type { LanguageContext } from './custom-language.ts'
export const RE_JS: RegExp = /\.([cm]?)jsx?$/export const RE_TS: RegExp = /\.([cm]?)tsx?$/export const RE_DTS: RegExp = /\.d\.([cm]?)ts$/export const RE_DTS_MAP: RegExp = /\.d\.([cm]?)ts\.map$/export const RE_NODE_MODULES: RegExp = /[\\/]node_modules[\\/]/export const RE_CSS: RegExp = /\.(?:css|scss|sass|less|styl|stylus)$/export const RE_JSON: RegExp = /\.json$/export const RE_ROLLDOWN_RUNTIME: RegExp = exactRegex(RUNTIME_MODULE_ID)
export function filename_js_to_dts(id: string): string { return id.replace(RE_JS, '.d.$1ts')}export function filename_to_dts( id: string, languageContext?: LanguageContext,): string { id = languageContext?.toTsFilename?.(id) ?? id return id .replace(RE_TS, '.d.$1ts') .replace(RE_JS, '.d.$1ts') .replace(RE_JSON, '.json.d.ts')}export function filename_dts_to(id: string, ext: 'js' | 'ts'): string { return id.replace(RE_DTS, `.$1${ext}`)}
export function resolveTemplateFn( fn: string | ChunkFileNamesFunction, chunk: PreRenderedChunk,): string { return typeof fn === 'function' ? fn(chunk) : fn}
export function replaceTemplateName(template: string, name: string): string { return template.replaceAll('[name]', name)}