Skip to content

Commit

Permalink
fix: chdir back to the starting directory before exit
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed May 24, 2024
1 parent c9ae036 commit 3be5473
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { readFileSync } from 'fs';
import path from 'path';
import { toJS, resolve, versionCheck } from './util';
import { Document } from './document';
import { parse } from './parser';

import type { AsyncAPIObject } from './spec-types';

// remember the directory where execution of the program started
export const originDir: string = String(process.env.PWD);

Check failure on line 10 in src/index.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Type string trivially inferred from a string literal, remove type annotation

/**
*
* @param {string | string[]} files One or more relative/absolute paths to
Expand Down Expand Up @@ -87,9 +91,9 @@ export default async function bundle(
}

if (options.baseDir && typeof options.baseDir === 'string') {
process.chdir(options.baseDir);
process.chdir(path.resolve(originDir, options.baseDir));
} else if (options.baseDir && Array.isArray(options.baseDir)) {
process.chdir(String(options.baseDir[0])); // guard against passing an array
process.chdir(path.resolve(originDir, String(options.baseDir[0]))); // guard against passing an array
}

const readFiles = files.map(file => readFileSync(file, 'utf-8')); // eslint-disable-line
Expand All @@ -114,6 +118,9 @@ export default async function bundle(
options
);

// return to the starting directory before finishing the execution
process.chdir(originDir);

return new Document(resolvedJsons, options.base);
}

Expand Down

0 comments on commit 3be5473

Please sign in to comment.