@@ -105,101 +105,108 @@ export const fromTypes =
105105 `Couldn't find "${ targetFilePath } " from ${ projectRoot } `
106106 )
107107
108- if ( existsSync ( tmpRoot ) )
109- rmSync ( tmpRoot , { recursive : true , force : true } )
110-
111- mkdirSync ( tmpRoot , { recursive : true } )
112-
113- const tsconfig = tsconfigPath . startsWith ( '/' )
114- ? tsconfigPath
115- : join ( projectRoot , tsconfigPath )
116-
117- const extendsRef = existsSync ( tsconfig )
118- ? `"extends": "${ join ( projectRoot , 'tsconfig.json' ) } ",`
119- : ''
120-
121- writeFileSync (
122- join ( tmpRoot , 'tsconfig.json' ) ,
123- `{
124- ${ extendsRef }
125- "compilerOptions": {
126- "lib": ["ESNext"],
127- "module": "ESNext",
128- "noEmit": false,
129- "declaration": true,
130- "emitDeclarationOnly": true,
131- "moduleResolution": "bundler",
132- "skipLibCheck": true,
133- "skipDefaultLibCheck": true,
134- "outDir": "./dist"
135- },
136- "include": ["${ src } "]
137- }`
138- )
139-
140- spawnSync ( `tsc` , {
141- shell : true ,
142- cwd : tmpRoot ,
143- stdio : debug ? 'inherit' : undefined
144- } )
145-
146- const fileName = targetFilePath
147- . replace ( / .t s x $ / , '.ts' )
148- . replace ( / .t s $ / , '.d.ts' )
149-
150- let targetFile =
151- ( overrideOutputPath
152- ? typeof overrideOutputPath === 'string'
153- ? overrideOutputPath . startsWith ( '/' )
154- ? overrideOutputPath
155- : join ( tmpRoot , 'dist' , overrideOutputPath )
156- : overrideOutputPath ( tmpRoot )
157- : undefined ) ??
158- join (
159- tmpRoot ,
160- 'dist' ,
161- // remove leading like src or something similar
162- fileName . slice ( fileName . indexOf ( '/' ) + 1 )
108+ let targetFile : string
109+
110+ // Since it's already a declaration file
111+ // We can just read it directly
112+ if ( targetFilePath . endsWith ( '.d.ts' ) ) targetFile = targetFilePath
113+ else {
114+ if ( existsSync ( tmpRoot ) )
115+ rmSync ( tmpRoot , { recursive : true , force : true } )
116+
117+ mkdirSync ( tmpRoot , { recursive : true } )
118+
119+ const tsconfig = tsconfigPath . startsWith ( '/' )
120+ ? tsconfigPath
121+ : join ( projectRoot , tsconfigPath )
122+
123+ const extendsRef = existsSync ( tsconfig )
124+ ? `"extends": "${ join ( projectRoot , 'tsconfig.json' ) } ",`
125+ : ''
126+
127+ writeFileSync (
128+ join ( tmpRoot , 'tsconfig.json' ) ,
129+ `{
130+ ${ extendsRef }
131+ "compilerOptions": {
132+ "lib": ["ESNext"],
133+ "module": "ESNext",
134+ "noEmit": false,
135+ "declaration": true,
136+ "emitDeclarationOnly": true,
137+ "moduleResolution": "bundler",
138+ "skipLibCheck": true,
139+ "skipDefaultLibCheck": true,
140+ "outDir": "./dist"
141+ },
142+ "include": ["${ src } "]
143+ }`
163144 )
164145
165- let existed = existsSync ( targetFile )
146+ spawnSync ( `tsc` , {
147+ shell : true ,
148+ cwd : tmpRoot ,
149+ stdio : debug ? 'inherit' : undefined
150+ } )
151+
152+ const fileName = targetFilePath
153+ . replace ( / .t s x $ / , '.ts' )
154+ . replace ( / .t s $ / , '.d.ts' )
155+
156+ targetFile =
157+ ( overrideOutputPath
158+ ? typeof overrideOutputPath === 'string'
159+ ? overrideOutputPath . startsWith ( '/' )
160+ ? overrideOutputPath
161+ : join ( tmpRoot , 'dist' , overrideOutputPath )
162+ : overrideOutputPath ( tmpRoot )
163+ : undefined ) ??
164+ join (
165+ tmpRoot ,
166+ 'dist' ,
167+ // remove leading like src or something similar
168+ fileName . slice ( fileName . indexOf ( '/' ) + 1 )
169+ )
166170
167- if ( ! existed && overrideOutputPath ) {
168- targetFile = join (
169- tmpRoot ,
170- 'dist' ,
171- // use original file name as-is eg. in monorepo
172- fileName
173- )
171+ let existed = existsSync ( targetFile )
174172
175- existed = existsSync ( targetFile )
176- }
173+ if ( ! existed && ! overrideOutputPath ) {
174+ targetFile = join (
175+ tmpRoot ,
176+ 'dist' ,
177+ // use original file name as-is eg. in monorepo
178+ fileName
179+ )
180+
181+ existed = existsSync ( targetFile )
182+ }
177183
178- if ( ! existed ) {
179- rmSync ( join ( tmpRoot , 'tsconfig.json' ) )
184+ if ( ! existed ) {
185+ rmSync ( join ( tmpRoot , 'tsconfig.json' ) )
180186
181- console . warn (
182- '[@elysiajs/openapi/gen] Failed to generate OpenAPI schema'
183- )
184- console . warn ( "Couldn't find generated declaration file" )
185-
186- if ( existsSync ( join ( tmpRoot , 'dist' ) ) ) {
187- const tempFiles = readdirSync ( join ( tmpRoot , 'dist' ) , {
188- recursive : true
189- } )
190- . filter ( ( x ) => x . toString ( ) . endsWith ( '.d.ts' ) )
191- . map ( ( x ) => `- ${ x } ` )
192- . join ( '\n' )
193-
194- if ( tempFiles ) {
195- console . warn (
196- 'You can override with `overrideOutputPath` with one of the following:'
197- )
198- console . warn ( tempFiles )
187+ console . warn (
188+ '[@elysiajs/openapi/gen] Failed to generate OpenAPI schema'
189+ )
190+ console . warn ( "Couldn't find generated declaration file" )
191+
192+ if ( existsSync ( join ( tmpRoot , 'dist' ) ) ) {
193+ const tempFiles = readdirSync ( join ( tmpRoot , 'dist' ) , {
194+ recursive : true
195+ } )
196+ . filter ( ( x ) => x . toString ( ) . endsWith ( '.d.ts' ) )
197+ . map ( ( x ) => `- ${ x } ` )
198+ . join ( '\n' )
199+
200+ if ( tempFiles ) {
201+ console . warn (
202+ 'You can override with `overrideOutputPath` with one of the following:'
203+ )
204+ console . warn ( tempFiles )
205+ }
199206 }
200- }
201207
202- return
208+ return
209+ }
203210 }
204211
205212 const declaration = readFileSync ( targetFile , 'utf8' )
0 commit comments