Skip to content

Commit

Permalink
fix: chdir back to the starting directory before exit (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed May 27, 2024
1 parent c9ae036 commit 047ebcb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 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
const originDir = String(process.cwd());

/**
*
* @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,11 @@ export default async function bundle(
options
);

// return to the starting directory before finishing the execution
if (options.baseDir) {
process.chdir(originDir);
}

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

Expand Down

0 comments on commit 047ebcb

Please sign in to comment.