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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import { createDebug } from 'obug'import { requireTSApi } from '../utils/require.ts'import type { System } from 'typescript'
const debug = createDebug('rolldown-plugin-dts:tsc-system')const ts = requireTSApi()
/** * A system that writes files to both memory and disk. It will try read files * from memory firstly and fallback to disk if not found. */export function createFsSystem(files: Map<string, string>): System { return { ...ts.sys,
// Hide the output of tsc by default write(message: string): void { debug(message) },
// Copied from // https://github.com/microsoft/TypeScript-Website/blob/b0e9a5c0/packages/typescript-vfs/src/index.ts#L571-L574 resolvePath(path) { if (files.has(path)) { return path } return ts.sys.resolvePath(path) },
// Copied from // https://github.com/microsoft/TypeScript-Website/blob/b0e9a5c0/packages/typescript-vfs/src/index.ts#L532C1-L534C8 directoryExists(directory) { if (files.keys().some((path) => path.startsWith(directory))) { return true } return ts.sys.directoryExists(directory) },
fileExists(fileName) { if (files.has(fileName)) { return true } return ts.sys.fileExists(fileName) },
readFile(fileName, ...args) { if (files.has(fileName)) { return files.get(fileName) } return ts.sys.readFile(fileName, ...args) },
writeFile(path, data, ...args) { files.set(path, data) ts.sys.writeFile(path, data, ...args) },
deleteFile(fileName, ...args) { files.delete(fileName) ts.sys.deleteFile?.(fileName, ...args) }, }}
// A system that only writes files to memory. It will read files from both// memory and disk.export function createMemorySystem(files: Map<string, string>): System { return { ...createFsSystem(files),
writeFile(path, data) { files.set(path, data) },
deleteFile(fileName) { files.delete(fileName) }, }}