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: tolerate an undefined baseUrl compiler option #208

Merged
merged 4 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
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is why it's a breaking change

Choose a reason for hiding this comment

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

Making a previously required property optional is not a breaking change IMO, especially in this case:

  • It won't change anything for projects having a baseUrl
  • There's virtually no projects using tsconfig-paths that currently do not have a baseUrl, because it was basically broken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR introduces a compiler error into any downstream package that happens to use loadConfig and expects the baseUrl property to only ever be a string. If a change can cause downstream compiler errors, I consider it breaking.

Choose a reason for hiding this comment

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

Oh I was not aware of the public API, my bad!

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,
};
}