From 76a06371669dfbf1e0f572527045602841595afa Mon Sep 17 00:00:00 2001 From: HiiiiD Date: Tue, 15 Nov 2022 11:45:06 +0100 Subject: [PATCH 1/2] Fix path generation --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 9a1637cfa..45e6ef3e8 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -108,7 +108,7 @@ async function generateSchema(pathToSpec) { let outputFilePath = new URL(flags.output, CWD); // note: may be directory const isDir = fs.existsSync(outputFilePath) && fs.lstatSync(outputFilePath).isDirectory(); if (isDir) { - const filename = pathToSpec.replace(EXT_RE, ".ts"); + const filename = pathToSpec.replace(EXT_RE, ".ts").replace(/^https?:\/\//, ''); outputFilePath = new URL(filename, outputFilePath); } From 5f20b220c3d6556b6035fee28ee4dfd9a56e25ab Mon Sep 17 00:00:00 2001 From: HiiiiD Date: Wed, 16 Nov 2022 21:10:02 +0100 Subject: [PATCH 2/2] Fix file path --- bin/cli.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 45e6ef3e8..5b789eae1 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -108,8 +108,12 @@ async function generateSchema(pathToSpec) { let outputFilePath = new URL(flags.output, CWD); // note: may be directory const isDir = fs.existsSync(outputFilePath) && fs.lstatSync(outputFilePath).isDirectory(); if (isDir) { - const filename = pathToSpec.replace(EXT_RE, ".ts").replace(/^https?:\/\//, ''); - outputFilePath = new URL(filename, outputFilePath); + const filename = pathToSpec.replace(EXT_RE, ".ts"); + const originalOutputFilePath = outputFilePath; + outputFilePath = new URL(filename, originalOutputFilePath); + if (outputFilePath.protocol !== 'file') { + outputFilePath = new URL(outputFilePath.host.replace(EXT_RE, ".ts"), originalOutputFilePath); + } } fs.writeFileSync(outputFilePath, result, "utf8");