@@ -2,7 +2,7 @@ import type { ReadStream } from 'fs';
22import type { Operation } from 'oas' ;
33import type { ParameterObject , SchemaObject } from 'oas/dist/rmoas.types' ;
44
5- import fs from 'fs/promises ' ;
5+ import fs from 'fs' ;
66import path from 'path' ;
77import stream from 'stream' ;
88
@@ -81,33 +81,34 @@ function processFile(
8181 // In order to support relative pathed files, we need to attempt to resolve them.
8282 const resolvedFile = path . resolve ( file ) ;
8383
84- return fs
85- . stat ( resolvedFile )
86- . then ( ( ) => datauri ( resolvedFile ) )
87- . then ( fileMetadata => {
84+ return new Promise ( ( resolve , reject ) => {
85+ fs . stat ( resolvedFile , async err => {
86+ if ( err ) {
87+ if ( err . code === 'ENOENT' ) {
88+ // It's less than ideal for us to handle files that don't exist like this but because
89+ // `file` is a string it might actually be the full text contents of the file and not
90+ // actually a path.
91+ //
92+ // We also can't really regex to see if `file` *looks*` like a path because one should be
93+ // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
94+ // doesn't *look* like a path, it is one that should still work.
95+ return resolve ( undefined ) ;
96+ }
97+
98+ return reject ( err ) ;
99+ }
100+
101+ const fileMetadata = await datauri ( resolvedFile ) ;
88102 const payloadFilename = encodeURIComponent ( path . basename ( resolvedFile ) ) ;
89103
90- return {
104+ return resolve ( {
91105 paramName,
92106 base64 : fileMetadata . content . replace ( ';base64' , `;name=${ payloadFilename } ;base64` ) ,
93107 filename : payloadFilename ,
94108 buffer : fileMetadata . buffer ,
95- } ;
96- } )
97- . catch ( err => {
98- if ( err . code === 'ENOENT' ) {
99- // It's less than ideal for us to handle files that don't exist like this but because
100- // `file` is a string it might actually be the full text contents of the file and not
101- // actually a path.
102- //
103- // We also can't really regex to see if `file` *looks*` like a path because one should be
104- // able to pass in a relative `owlbert.png` (instead of `./owlbert.png`) and though that
105- // doesn't *look* like a path, it is one that should still work.
106- return undefined ;
107- }
108-
109- throw err ;
109+ } ) ;
110110 } ) ;
111+ } ) ;
111112 } else if ( file instanceof stream . Readable ) {
112113 return getStream . buffer ( file ) . then ( buffer => {
113114 const filePath = file . path as string ;
0 commit comments