From 3be54734a59b28033e45d4c3714cf674d74275f7 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 1/8] fix: chdir back to the starting directory before exit --- src/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f5e6d39..fca96bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); + /** * * @param {string | string[]} files One or more relative/absolute paths to @@ -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 @@ -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); } From 3b9e3869aa861a0984ef51217d33dce408cc2c51 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 2/8] fix: chdir back to the starting directory before exit --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index fca96bc..07cb7e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ 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); +export const originDir = String(process.env.PWD); /** * From 4594d7912381f713c25b6ef33521d7c8ef7bf00e Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 3/8] fix: chdir back to the starting directory before exit --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 07cb7e9..3d5fe31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,7 +119,9 @@ export default async function bundle( ); // return to the starting directory before finishing the execution - process.chdir(originDir); + if (options.baseDir) { + process.chdir(originDir); + } return new Document(resolvedJsons, options.base); } From f2403f7587f3b122ccff295dcba4301e19c2515b Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 4/8] fix: chdir back to the starting directory before exit --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3d5fe31..4d5fe67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -91,9 +91,9 @@ export default async function bundle( } if (options.baseDir && typeof options.baseDir === 'string') { - process.chdir(path.resolve(originDir, options.baseDir)); + process.chdir(options.baseDir); } else if (options.baseDir && Array.isArray(options.baseDir)) { - process.chdir(path.resolve(originDir, String(options.baseDir[0]))); // guard against passing an array + process.chdir(String(options.baseDir[0])); // guard against passing an array } const readFiles = files.map(file => readFileSync(file, 'utf-8')); // eslint-disable-line From cc59d5e67f9bb1894c568f50997bbc7392dd67d0 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 5/8] fix: chdir back to the starting directory before exit --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4d5fe67..be9339c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import { readFileSync } from 'fs'; -import path from 'path'; import { toJS, resolve, versionCheck } from './util'; import { Document } from './document'; import { parse } from './parser'; From 49530f32f230fb3d53df06906cbdb7269b42847a Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 6/8] fix: chdir back to the starting directory before exit --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index be9339c..1f17151 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,6 @@ import { parse } from './parser'; import type { AsyncAPIObject } from './spec-types'; -// remember the directory where execution of the program started -export const originDir = String(process.env.PWD); - /** * * @param {string | string[]} files One or more relative/absolute paths to @@ -84,6 +81,9 @@ export default async function bundle( files: string[] | string, options: any = {} ) { + // remember the directory where execution of the program started + const originDir = String(process.env.PWD); + // if one string was passed, convert it to an array if (typeof files === 'string') { files = Array.from(files.split(' ')); @@ -119,7 +119,7 @@ export default async function bundle( // return to the starting directory before finishing the execution if (options.baseDir) { - process.chdir(originDir); + process.chdir(originDir); } return new Document(resolvedJsons, options.base); From 2c2aca530e6c6e063def96d055a686cd71da40dc Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 7/8] fix: chdir back to the starting directory before exit --- src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1f17151..3bc0e73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,9 @@ 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 @@ -81,9 +84,6 @@ export default async function bundle( files: string[] | string, options: any = {} ) { - // remember the directory where execution of the program started - const originDir = String(process.env.PWD); - // if one string was passed, convert it to an array if (typeof files === 'string') { files = Array.from(files.split(' ')); From 028eccf66577791fccb7e3bb15f6ec6c941cd4a5 Mon Sep 17 00:00:00 2001 From: Viacheslav Turovskyi Date: Fri, 24 May 2024 06:07:43 +0000 Subject: [PATCH 8/8] fix: chdir back to the starting directory before exit --- src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3bc0e73..7b8e480 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { readFileSync } from 'fs'; +import path from 'path'; import { toJS, resolve, versionCheck } from './util'; import { Document } from './document'; import { parse } from './parser'; @@ -90,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