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 all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add `cwd` option to `register` function that overrides where the `tsconfig.json` search begins. See PR [#205](https://github.com/dividab/tsconfig-paths/pull/205).
- Add support for `jsconfig.json`. See PR [#199](https://github.com/dividab/tsconfig-paths/pull/199). Thanks to [@F3n67u](https://github.com/F3n67u) for this PR!
- Let `paths` mappings be absolute paths. See PR [#184](https://github.com/dividab/tsconfig-paths/pull/184).
- Allow `baseUrl` in `tsconfig.json` to be an absolute path. See PR [#174](https://github.com/dividab/tsconfig-paths/pull/174). Thanks to [@nwalters512](https://github.com/nwalters512) for this PR!

### Fixed

Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/config-loader.test.ts
Expand Up @@ -97,4 +97,20 @@ describe("config-loader", (): void => {
expect(successResult.resultType).toBe("success");
expect(successResult.configFileAbsolutePath).toBe(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");
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, this is using assert which is undefined.

@jonaskello Would be nice to run test CI on PRs!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Looks like my PR predated the move to Jest in #186. I can patch up this test if you aren't already working on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll let you handle it, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

@aleclarson Yes, definitely would be nice to run the tests in CI :-). It used to work but perhaps it was broken by the move to github actions. I'll see if I can get that running again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR with passing test suite: #211

});
});
2 changes: 1 addition & 1 deletion src/config-loader.ts
Expand Up @@ -79,7 +79,7 @@ export function configLoader({
resultType: "success",
configFileAbsolutePath: loadResult.tsConfigPath,
baseUrl: loadResult.baseUrl,
absoluteBaseUrl: path.join(
absoluteBaseUrl: path.resolve(
path.dirname(loadResult.tsConfigPath),
loadResult.baseUrl || ""
),
Expand Down