From d09f1a2e68e997a73e2e2582e338c2c88a7fd8bd Mon Sep 17 00:00:00 2001 From: phpfs Date: Wed, 3 Feb 2021 03:47:37 +0100 Subject: [PATCH] Fix: electron asar - failed to open spec dir (#531) * Remove (hopefully) unnecessary cwd changes For electron-based apps, it is not possible to change the current working directory as all source is packaged within an asar. Therefore, we suggest to remove these calls. * Fix try finally clause * Remove unnecessary const * remove try finally Co-authored-by: Carmine DiMascio --- src/framework/index.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/framework/index.ts b/src/framework/index.ts index 5c807201..2e3fe0de 100644 --- a/src/framework/index.ts +++ b/src/framework/index.ts @@ -79,18 +79,12 @@ export class OpenAPIFramework { // We need this workaround ( use '$RefParser.dereference' instead of '$RefParser.bundle' ) if asked by user if (typeof filePath === 'string') { const origCwd = process.cwd(); - const specDir = path.resolve(origCwd, path.dirname(filePath)); const absolutePath = path.resolve(origCwd, filePath); if (fs.existsSync(absolutePath)) { // Get document, or throw exception on error - try { - process.chdir(specDir); - return $refParser.mode === 'dereference' - ? $RefParser.dereference(absolutePath) - : $RefParser.bundle(absolutePath); - } finally { - process.chdir(origCwd); - } + return $refParser.mode === 'dereference' + ? $RefParser.dereference(absolutePath) + : $RefParser.bundle(absolutePath); } else { throw new Error( `${this.loggingPrefix}spec could not be read at ${filePath}`,