Skip to content

Commit

Permalink
fix: allow absolute baseUrl in tsconfig.json (#174)
Browse files Browse the repository at this point in the history
* Add test case

* Allow absolute baseUrl in tsconfig.json

* Apply suggestions from code review

* Add changelog entry
  • Loading branch information
nwalters512 committed May 2, 2022
1 parent e6bc84b commit 23ea90b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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");
});
});
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

0 comments on commit 23ea90b

Please sign in to comment.