Skip to content

Commit

Permalink
Fix: electron asar - failed to open spec dir (#531)
Browse files Browse the repository at this point in the history
* 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 <cdimasci@amazon.com>
  • Loading branch information
phpfs and cdimascio committed Feb 3, 2021
1 parent 17e923e commit d09f1a2
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/framework/index.ts
Expand Up @@ -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}`,
Expand Down

0 comments on commit d09f1a2

Please sign in to comment.