Skip to content

Commit 69f0628

Browse files
authored
fix: resolve issue with saving output using full file paths (openapi-ts#1747)
* fix: resolve issue with saving output using full file paths * chore: lint code * fix: normalizeOutput
1 parent 35bd412 commit 69f0628

File tree

1 file changed

+14
-2
lines changed
  • packages/openapi-typescript/bin

1 file changed

+14
-2
lines changed

packages/openapi-typescript/bin/cli.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ const flags = parser(args, {
7878
},
7979
});
8080

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+
8193
/**
8294
* @param {string | URL} schema
8395
* @param {@type import('@redocly/openapi-core').Config} redocly
@@ -179,7 +191,7 @@ async function main() {
179191
// if stdout, (still) don’t log anything to console!
180192
process.stdout.write(result);
181193
} else {
182-
const outFile = new URL(flags.output, CWD);
194+
const outFile = normalizeOutput(flags.output);
183195
fs.mkdirSync(new URL(".", outFile), { recursive: true });
184196
fs.writeFileSync(outFile, result, "utf8");
185197
done("stdin", flags.output, performance.now() - timeStart);
@@ -202,7 +214,7 @@ async function main() {
202214
// if stdout, (still) don’t log anything to console!
203215
process.stdout.write(result);
204216
} else {
205-
const outFile = new URL(flags.output, CWD);
217+
const outFile = normalizeOutput(flags.output);
206218
fs.mkdirSync(new URL(".", outFile), { recursive: true });
207219
fs.writeFileSync(outFile, result, "utf8");
208220
done(input, flags.output, performance.now() - timeStart);

0 commit comments

Comments
 (0)