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

Conversation

nwalters512
Copy link
Contributor

configLoader assumed that baseUrl would always be relative path, but the TypeScript compiler allows baseUrl to be an absolute path as well. This PR updates the configLoader to correctly compute absoluteBaseUrl if the baseUrl in the TypeScript config file is already absolute.

Note that the same thing was already being done if explicitParams was provided.

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);

src/config-loader.ts Outdated Show resolved Hide resolved
@jonaskello
Copy link
Member

@nwalters512 Could you also add an entry for this PR in the CHANGELOG under unreleased heading ? With that it should be good to merge.

@aleclarson
Copy link
Contributor

Hey @nwalters512, would you mind adding this to CHANGELOG.md and pushing it?

## [Unreleased]

### Fixed

- Let `baseUrl` in tsconfig be an absolute path. See PR [#174](https://github.com/dividab/tsconfig-paths/pull/174). Thanks to @nwalters512!

@nwalters512
Copy link
Contributor Author

I'm on it! Thanks for getting this reviewed.

@aleclarson
Copy link
Contributor

@jonaskello LGTM

@jonaskello jonaskello merged commit 23ea90b into dividab:master May 2, 2022
});

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

@nwalters512 nwalters512 deleted the fix/absolute-base-url branch May 2, 2022 18:36
@nwalters512 nwalters512 mentioned this pull request May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants