Skip to content
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

fix: allow absolute baseUrl in tsconfig.json #174

Merged
merged 7 commits into from May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/config-loader.ts
Expand Up @@ -85,7 +85,9 @@ export function configLoader({
}

const tsConfigDir = path.dirname(loadResult.tsConfigPath);
const absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);
const absoluteBaseUrl = path.isAbsolute(loadResult.baseUrl)
? loadResult.baseUrl
: path.join(tsConfigDir, loadResult.baseUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this instead please:

const absoluteBaseUrl = path.resolve(tsConfigDir, loadResult.baseUrl);

nwalters512 marked this conversation as resolved.
Show resolved Hide resolved

return {
resultType: "success",
Expand Down
16 changes: 16 additions & 0 deletions test/config-loader-tests.ts
Expand Up @@ -87,4 +87,20 @@ describe("config-loader", (): void => {
assert.equal(successResult.resultType, "success");
assert.equal(successResult.configFileAbsolutePath, configFile);
});

it("should allow an absolute baseUrl in tsconfig.json", () => {
const result = configLoader({
explicitParams: undefined,
cwd: "/baz",
// tslint:disable-next-line:no-any
tsConfigLoader: (_: any) => ({
tsConfigPath: "/baz/tsconfig.json",
baseUrl: "/baz",
paths: {},
}),
});

const successResult = result as ConfigLoaderSuccessResult;
assert.equal(successResult.absoluteBaseUrl, "/baz");
});
});