@@ -48,7 +48,12 @@ export class KbnClientImportExport {
4848 path = `${ path } .json` ;
4949 }
5050
51- const absolutePath = Path . resolve ( this . baseDir , path ) ;
51+ return Path . resolve ( this . baseDir , path ) ;
52+ }
53+
54+ private resolveAndValidatePath ( path : string ) {
55+ const absolutePath = this . resolvePath ( path ) ;
56+
5257 if ( ! existsSync ( absolutePath ) ) {
5358 throw new Error (
5459 `unable to resolve path [${ path } ] to import/export, resolved relative to [${ this . baseDir } ]`
@@ -59,7 +64,7 @@ export class KbnClientImportExport {
5964 }
6065
6166 async load ( path : string , options ?: { space ?: string } ) {
62- const src = this . resolvePath ( path ) ;
67+ const src = this . resolveAndValidatePath ( path ) ;
6368 this . log . debug ( 'resolved import for' , path , 'to' , src ) ;
6469
6570 const objects = await parseArchive ( src ) ;
@@ -94,7 +99,7 @@ export class KbnClientImportExport {
9499 }
95100
96101 async unload ( path : string , options ?: { space ?: string } ) {
97- const src = this . resolvePath ( path ) ;
102+ const src = this . resolveAndValidatePath ( path ) ;
98103 this . log . debug ( 'unloading docs from archive at' , src ) ;
99104
100105 const objects = await parseArchive ( src ) ;
@@ -143,6 +148,7 @@ export class KbnClientImportExport {
143148 } )
144149 . join ( '\n\n' ) ;
145150
151+ await Fs . mkdir ( Path . dirname ( dest ) , { recursive : true } ) ;
146152 await Fs . writeFile ( dest , fileContents , 'utf-8' ) ;
147153
148154 this . log . success ( 'Exported' , objects . length , 'saved objects to' , dest ) ;
0 commit comments