Feature Request: Option to exclude barrel files from output.banner
Problem
When using pluginClient with output.banner: "'use server'" for Next.js Server Actions, all generated files receive this directive, including:
- Barrel files (
index.ts) - only do re-exports
- Group aggregation files (
stocks/stocks.ts, broker/broker.ts, etc.) - generated when using group option
These files should NOT have "use server" because:
- Barrel files only re-export, they don't define server actions
- Aggregation files return function references which cannot be serialized in server actions
Current Workaround
We have to use hooks.done with a post-processing script to remove "use server" from barrel files:
// kubb.config.ts
export default defineConfig({
hooks: {
done: ['bash scripts/remove-use-server-from-barrels.sh'],
},
plugins: [
pluginClient({
output: {
path: './api',
banner: "'use server'",
barrelType: 'named',
},
group: { type: 'tag', name: ({ group }) => camelCase(group) },
}),
],
});
# remove-use-server-from-barrels.sh
# Remove "use server" from dir/dir.ts pattern files
find src/actions-generated/api -regex '.*/\([^/]*\)/\1\.ts' -exec perl -i -pe 's/"use server";//' {} \;
Proposed Solution
Add an option to exclude barrel/aggregation files from banner injection:
Option A: bannerExcludeBarrel
pluginClient({
output: {
path: './api',
banner: "'use server'",
bannerExcludeBarrel: true, // Don't add banner to index.ts and dir/dir.ts files
},
}),
Option B: banner as function with file context
pluginClient({
output: {
path: './api',
banner: ({ isBarrel, isAggregation, filePath }) => {
if (isBarrel || isAggregation) return '';
return "'use server'";
},
},
}),
Option C: Separate barrelBanner option
pluginClient({
output: {
path: './api',
banner: "'use server'",
barrelBanner: '', // Override banner for barrel files
},
}),
Environment
- Kubb version: 4.12.15
- Framework: Next.js 16.1 (App Router with Server Actions)
- Plugins:
@kubb/plugin-client, @kubb/plugin-ts, @kubb/plugin-zod
Additional Context
This is a common use case for Next.js users who want to:
- Generate type-safe API clients with Kubb
- Use them as Server Actions (requires
"use server" directive)
- Organize code with
group option for better structure
The current workaround requires platform-specific scripts (bash/perl) which is not ideal for cross-platform development.
Feature Request: Option to exclude barrel files from
output.bannerProblem
When using
pluginClientwithoutput.banner: "'use server'"for Next.js Server Actions, all generated files receive this directive, including:index.ts) - only do re-exportsstocks/stocks.ts,broker/broker.ts, etc.) - generated when usinggroupoptionThese files should NOT have
"use server"because:Current Workaround
We have to use
hooks.donewith a post-processing script to remove"use server"from barrel files:Proposed Solution
Add an option to exclude barrel/aggregation files from banner injection:
Option A:
bannerExcludeBarrelOption B:
banneras function with file contextOption C: Separate
barrelBanneroptionEnvironment
@kubb/plugin-client,@kubb/plugin-ts,@kubb/plugin-zodAdditional Context
This is a common use case for Next.js users who want to:
"use server"directive)groupoption for better structureThe current workaround requires platform-specific scripts (bash/perl) which is not ideal for cross-platform development.