@@ -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,20 @@ 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 = Array . isArray ( header )
64+ ? header . flatMap ( ( line ) => line . split ( / \r ? \n / ) )
65+ : header . split ( / \r ? \n / ) ;
66+ const content = lines . join ( '\n' ) ;
67+ return content ? `${ content } \n\n` : '' ;
68+ }
69+
5670/**
5771 * Returns absolute path to the client folder. This is hard-coded for now.
5872 */
@@ -114,11 +128,13 @@ function renameFile({
114128
115129function replaceImports ( {
116130 filePath,
131+ header,
117132 isDevMode,
118133 meta,
119134 renamed,
120135} : {
121136 filePath : string ;
137+ header ?: string ;
122138 isDevMode ?: boolean ;
123139 meta : ProjectRenderMeta ;
124140 renamed : Map < string , string > ;
@@ -148,9 +164,10 @@ function replaceImports({
148164 return replacedMatch ;
149165 } ) ;
150166
151- const header = '// This file is auto-generated by @hey-api/openapi-ts\n\n' ;
167+ const fileHeader =
168+ header !== undefined ? header : '// This file is auto-generated by @hey-api/openapi-ts\n\n' ;
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