Skip to content

Commit

Permalink
fix: tolerate an undefined baseUrl compiler option (#208)
Browse files Browse the repository at this point in the history
* fix: tolerate an undefined `baseUrl` compiler option

* chore: clean up changelog

* chore: update changelog

Co-authored-by: Jonas Kello <jonaskello@users.noreply.github.com>
  • Loading branch information
aleclarson and jonaskello committed May 2, 2022
1 parent 1081597 commit 25496bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Expand Up @@ -7,19 +7,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

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

### Changed

- Ignore `--project`/`-P` CLI flag when explicit options are passed to `register`. See PR [#206](https://github.com/dividab/tsconfig-paths/pull/206).

### Added

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

### Fixed

- Tolerate an undefined `baseUrl` compiler option. See PR [#208](https://github.com/dividab/tsconfig-paths/pull/208).

## [3.14.1] - 2022-03-22

Expand Down
18 changes: 6 additions & 12 deletions src/config-loader.ts
Expand Up @@ -21,7 +21,7 @@ export interface ConfigLoaderParams {
export interface ConfigLoaderSuccessResult {
resultType: "success";
configFileAbsolutePath: string;
baseUrl: string;
baseUrl?: string;
absoluteBaseUrl: string;
paths: { [key: string]: Array<string> };
mainFields?: Array<string>;
Expand Down Expand Up @@ -75,21 +75,15 @@ export function configLoader({
};
}

if (!loadResult.baseUrl) {
return {
resultType: "failed",
message: "Missing baseUrl in compilerOptions",
};
}

const tsConfigDir = path.dirname(loadResult.tsConfigPath);
const absoluteBaseUrl = path.join(tsConfigDir, loadResult.baseUrl);

return {
resultType: "success",
configFileAbsolutePath: loadResult.tsConfigPath,
baseUrl: loadResult.baseUrl,
absoluteBaseUrl,
absoluteBaseUrl: path.join(
path.dirname(loadResult.tsConfigPath),
loadResult.baseUrl || ""
),
paths: loadResult.paths || {},
addMatchAll: loadResult.baseUrl !== undefined,
};
}

0 comments on commit 25496bb

Please sign in to comment.