@@ -3,7 +3,7 @@ import path from 'node:path';
33import { fileURLToPath } from 'node:url' ;
44
55import type { IProject , ProjectRenderMeta } from '@hey-api/codegen-core' ;
6- import type { DefinePlugin } from '@hey-api/shared' ;
6+ import type { DefinePlugin , OutputHeader } from '@hey-api/shared' ;
77import { ensureDirSync } from '@hey-api/shared' ;
88
99import type { Config } from '../config/types' ;
@@ -53,6 +53,21 @@ function getClientBundlePaths(pluginName: string): {
5353 } ;
5454}
5555
56+ /**
57+ * Converts an {@link OutputHeader} value to a string prefix for file content.
58+ * Returns an empty string when the header is null, undefined, or a function
59+ * (functions require a render context which is not available for bundled files).
60+ */
61+ function outputHeaderToPrefix ( header : OutputHeader ) : string {
62+ if ( header == null || typeof header === 'function' ) return '' ;
63+ const lines =
64+ typeof header === 'string'
65+ ? header . split ( / \r ? \n / )
66+ : header . flatMap ( ( line ) => line . split ( / \r ? \n / ) ) ;
67+ const content = lines . join ( '\n' ) ;
68+ return content ? `${ content } \n\n` : '' ;
69+ }
70+
5671/**
5772 * Returns absolute path to the client folder. This is hard-coded for now.
5873 */
@@ -114,11 +129,13 @@ function renameFile({
114129
115130function replaceImports ( {
116131 filePath,
132+ header,
117133 isDevMode,
118134 meta,
119135 renamed,
120136} : {
121137 filePath : string ;
138+ header ?: string ;
122139 isDevMode ?: boolean ;
123140 meta : ProjectRenderMeta ;
124141 renamed : Map < string , string > ;
@@ -148,9 +165,9 @@ function replaceImports({
148165 return replacedMatch ;
149166 } ) ;
150167
151- const header = '// This file is auto-generated by @hey-api/openapi-ts\n\n ';
168+ const fileHeader = header ?? ' ';
152169
153- content = `${ header } ${ content } ` ;
170+ content = `${ fileHeader } ${ content } ` ;
154171
155172 fs . writeFileSync ( filePath , content , 'utf8' ) ;
156173}
@@ -159,18 +176,21 @@ function replaceImports({
159176 * Creates a `client` folder containing the same modules as the client package.
160177 */
161178export function generateClientBundle ( {
179+ header,
162180 meta,
163181 outputPath,
164182 plugin,
165183 project,
166184} : {
185+ header ?: OutputHeader ;
167186 meta : ProjectRenderMeta ;
168187 outputPath : string ;
169188 plugin : DefinePlugin < Client . Config & { name : string } > [ 'Config' ] ;
170189 project ?: IProject ;
171190} ) : Map < string , string > | undefined {
172191 const renamed = new Map < string , string > ( ) ;
173192 const devMode = isDevMode ( ) ;
193+ const headerPrefix = outputHeaderToPrefix ( header ) ;
174194
175195 // copy Hey API clients to output
176196 const isHeyApiClientPlugin = plugin . name . startsWith ( '@hey-api/client-' ) ;
@@ -211,6 +231,7 @@ export function generateClientBundle({
211231 for ( const file of coreFiles ) {
212232 replaceImports ( {
213233 filePath : path . resolve ( coreOutputPath , file ) ,
234+ header : headerPrefix ,
214235 isDevMode : devMode ,
215236 meta,
216237 renamed,
@@ -221,6 +242,7 @@ export function generateClientBundle({
221242 for ( const file of clientFiles ) {
222243 replaceImports ( {
223244 filePath : path . resolve ( clientOutputPath , file ) ,
245+ header : headerPrefix ,
224246 isDevMode : devMode ,
225247 meta,
226248 renamed,
0 commit comments