Plugin API
Plugins can hook into the build lifecycle to customize behavior.
TshipPlugin Interface
interface TshipPlugin {
name: string;
onPostEmit?: (ctx: PostEmitContext) => void | Promise<void>;
onBuildEnd?: (ctx: BuildEndContext) => void | Promise<void>;
}Hooks
onPostEmit
Called after a single format has been emitted.
Context
format– The format just built ("cjs"|"esm")outDir– Absolute output directoryfiles– List of all emitted filesrootDir– Source root directory
onBuildEnd
Called after all formats have been built.
Context
formats– All built formatsoutputs– Map of format to output directoryduration– Total build time in ms
Example Plugin
import type { TshipPlugin } from '@jstility/tship';
export function bannerPlugin(text: string): TshipPlugin {
return {
name: 'banner',
async onPostEmit(ctx) {
for (const file of ctx.files) {
const content = await fs.readFile(file, 'utf-8');
await fs.writeFile(file, `/* ${text} */\n${content}`);
}
}
};
}