fix: types for rollup

This commit is contained in:
hypercross 2026-04-04 16:55:17 +08:00
parent 08cac3965e
commit 8bf28c8aed
1 changed files with 25 additions and 2 deletions

View File

@ -1,4 +1,3 @@
import type { Plugin } from 'rollup';
import type { CsvLoaderOptions } from './loader.js';
import { csvToModule } from './loader.js';
import * as path from 'path';
@ -25,11 +24,35 @@ function matchesPattern(
});
}
interface TransformResult {
code: string;
map: null;
}
interface EmitFileOptions {
type: 'asset';
fileName: string;
source: string;
}
interface PluginContext {
emitFile: (options: EmitFileOptions) => string;
}
interface RollupPlugin {
name: string;
transform: (
this: PluginContext,
code: string,
id: string
) => TransformResult | null;
}
/**
* Rollup plugin for loading CSV files with inline-schema validation.
* Works with both Vite and Tsup (esbuild).
*/
export function csvLoader(options: CsvRollupOptions = {}): Plugin {
export function csvLoader(options: CsvRollupOptions = {}): RollupPlugin {
const {
include = /\.csv$/,
exclude,