@@ -9,6 +9,7 @@ import type {
99 OpenApiLatest_Schema ,
1010} from './helpers' ;
1111import type { PrinterConfigs , PrinterOptions , PrintResults } from './types' ;
12+ import { isPackageExists } from 'local-pkg' ;
1213import { pkgName , pkgVersion } from '../const' ;
1314import { OpenAPIVersion } from '../types/openapi' ;
1415import { toImportPath , toRelative } from '../utils/path' ;
@@ -304,22 +305,22 @@ export class Printer {
304305 main : {
305306 lang : 'ts' ,
306307 code : this . #mainContent. print ( ) ,
307- errors : [ ] ,
308+ errors : this . #mainContent . errors ,
308309 } ,
309310 type : {
310311 lang : 'ts' ,
311312 code : this . #typeContent. print ( ) ,
312- errors : [ ] ,
313+ errors : this . #typeContent . errors ,
313314 } ,
314315 zod : {
315316 lang : 'ts' ,
316317 code : this . #zodContent. print ( ) ,
317- errors : [ ] ,
318+ errors : this . #zodContent . errors ,
318319 } ,
319320 mock : {
320321 lang : 'ts' ,
321322 code : this . #mockContent. print ( ) ,
322- errors : [ ] ,
323+ errors : this . #mockContent . errors ,
323324 } ,
324325 } ;
325326 }
@@ -389,6 +390,20 @@ export class Printer {
389390 `import type * as ${ TYPE_FILE_EXPORT_NAME } from "${ toRelative ( typeFile , mainFile ) } ";` ,
390391 ] ) ;
391392
393+ // 依赖 axios
394+ if ( ! axiosImportFile || axiosImportFile === AXIOS_IMPORT_FILE ) {
395+ if ( ! isPackageExists ( AXIOS_IMPORT_FILE ) ) {
396+ this . #mockContent. pushError ( `需要安装 ${ AXIOS_IMPORT_FILE } ` ) ;
397+ }
398+ }
399+
400+ // 依赖 zod
401+ if ( ( runtimeValidate || runtimeMock ) && ( ! zodImportFile || zodImportFile === ZOD_IMPORT_FILE ) ) {
402+ if ( ! isPackageExists ( ZOD_IMPORT_FILE ) ) {
403+ this . #zodContent. errors . push ( `需要安装 ${ ZOD_IMPORT_FILE } ` ) ;
404+ }
405+ }
406+
392407 if ( runtimeValidate ) {
393408 const zodNames = [ ...this . #pathZodNames. values ( ) ] . join ( ',' ) ;
394409 this . #mainContent. push ( 'import' , [
@@ -408,6 +423,20 @@ export class Printer {
408423 toImportString ( FAKER_IMPORT_NAME , fakerImportName , fakerImportPath ) ,
409424 `import {${ zodNames } } from "${ toRelative ( zodFile , mainFile ) } ";` ,
410425 ] ) ;
426+
427+ if ( ! fakerImportFile || fakerImportFile === FAKER_IMPORT_FILE ) {
428+ if ( ! isPackageExists ( FAKER_IMPORT_FILE ) ) {
429+ this . #mockContent. pushError ( `需要安装 ${ FAKER_IMPORT_FILE } ` ) ;
430+ }
431+ }
432+
433+ if ( ! isPackageExists ( '@anatine/zod-mock' ) ) {
434+ this . #mockContent. pushError ( `需要安装 @anatine/zod-mock` ) ;
435+ }
436+
437+ if ( ! isPackageExists ( 'axios-mock-adapter' ) ) {
438+ this . #mockContent. pushError ( `需要安装 axios-mock-adapter` ) ;
439+ }
411440 }
412441
413442 this . #zodContent. push ( 'import' , toImportString ( ZOD_IMPORT_NAME , zodImportName , zodImportPath ) ) ;
0 commit comments