-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Bundle() does not restore CWD call when baseDir is used #166
Comments
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request. |
Please copy&paste this compiled index.js"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.originDir = void 0;
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const util_1 = require("./util");
const document_1 = require("./document");
const parser_1 = require("./parser");
exports.originDir = String(process.env.PWD);
async function bundle(files, options = {}) {
// if one string was passed, convert it to an array
if (typeof files === 'string') {
files = Array.from(files.split(' '));
}
if (options.baseDir && typeof options.baseDir === 'string') {
process.chdir(path_1.default.resolve(exports.originDir, options.baseDir));
}
else if (options.baseDir && Array.isArray(options.baseDir)) {
process.chdir(path_1.default.resolve(exports.originDir, String(options.baseDir[0]))); // guard against passing an array
}
const readFiles = files.map(file => (0, fs_1.readFileSync)(file, 'utf-8')); // eslint-disable-line
const parsedJsons = readFiles.map(file => (0, util_1.toJS)(file));
const majorVersion = (0, util_1.versionCheck)(parsedJsons);
if (typeof options.base !== 'undefined') {
if (typeof options.base === 'string') {
options.base = (0, fs_1.readFileSync)(options.base, 'utf-8'); // eslint-disable-line
}
else if (Array.isArray(options.base)) {
options.base = (0, fs_1.readFileSync)(String(options.base[0]), 'utf-8'); // eslint-disable-line
}
options.base = (0, util_1.toJS)(options.base);
await (0, parser_1.parse)(options.base, majorVersion, options);
}
const resolvedJsons = await (0, util_1.resolve)(parsedJsons, majorVersion, options);
process.chdir(exports.originDir);
return new document_1.Document(resolvedJsons, options.base);
}
exports.default = bundle;
// 'module.exports' is added to maintain backward compatibility with Node.js
// projects, that use CJS module system.
module.exports = bundle; |
I can confirm that worked :) |
@g-radam |
@aeworxet I've validated that the issue is fixed in v0.5.2! :) Many thanks aeworxet! |
Describe the bug.
Invoking the
bundle()
function with abaseDir
option provided will have the working directory changed, but will not be changed back on function exit. Successive calls to this method where each call provides a relative pathbaseDir
option will fail, specifically on the 2nd call, since the original relative path no longer makes sense in the CWD.Error:
The lines in question are:
bundler/src/index.ts
Line 90 in c9ae036
bundler/src/index.ts
Line 92 in c9ae036
The function will need to copy the CWD, and restore it prior to exiting. In cases where the function body throws, the exception should most likely be caught, the CWD reverted, and the exception be propagated as per normal.
Expected behavior
Invoking the bundle restores the CWD.
Screenshots
N/A
How to Reproduce
🥦 Browser
None
👀 Have you checked for similar open issues?
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue ?
Yes I am willing to submit a PR!
The text was updated successfully, but these errors were encountered: