@@ -78,6 +78,18 @@ const flags = parser(args, {
78
78
} ,
79
79
} ) ;
80
80
81
+ /**
82
+ * Normalize the output path into a file URL.
83
+ * @param {string } output - The output path to be transformed.
84
+ * @returns {URL } The transformed file URL.
85
+ */
86
+ function normalizeOutput ( output ) {
87
+ if ( path . isAbsolute ( output ) ) {
88
+ return new URL ( `file://${ output } }` ) ;
89
+ }
90
+ return new URL ( output , CWD ) ;
91
+ }
92
+
81
93
/**
82
94
* @param {string | URL } schema
83
95
* @param {@type import('@redocly/openapi-core').Config } redocly
@@ -179,7 +191,7 @@ async function main() {
179
191
// if stdout, (still) don’t log anything to console!
180
192
process . stdout . write ( result ) ;
181
193
} else {
182
- const outFile = new URL ( flags . output , CWD ) ;
194
+ const outFile = normalizeOutput ( flags . output ) ;
183
195
fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
184
196
fs . writeFileSync ( outFile , result , "utf8" ) ;
185
197
done ( "stdin" , flags . output , performance . now ( ) - timeStart ) ;
@@ -202,7 +214,7 @@ async function main() {
202
214
// if stdout, (still) don’t log anything to console!
203
215
process . stdout . write ( result ) ;
204
216
} else {
205
- const outFile = new URL ( flags . output , CWD ) ;
217
+ const outFile = normalizeOutput ( flags . output ) ;
206
218
fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
207
219
fs . writeFileSync ( outFile , result , "utf8" ) ;
208
220
done ( input , flags . output , performance . now ( ) - timeStart ) ;
0 commit comments