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

feat(register): add cwd param #205

Merged
merged 2 commits into from Apr 21, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ 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).

## [3.14.1] - 2022-03-22

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -148,6 +148,7 @@ export interface ExplicitParams {
paths: { [key: string]: Array<string> };
mainFields?: Array<string>;
addMatchAll?: boolean;
cwd?: string;
}

/**
Expand Down
14 changes: 11 additions & 3 deletions src/register.ts
Expand Up @@ -45,14 +45,22 @@ function getCoreModules(
return coreModules;
}

export interface RegisterParams extends ExplicitParams {
/**
* Defaults to `--project` CLI flag or `process.cwd()`
*/
cwd?: string;
}

/**
* Installs a custom module load function that can adhere to paths in tsconfig.
* Returns a function to undo paths registration.
*/
export function register(explicitParams: ExplicitParams): () => void {
export function register(params?: RegisterParams): () => void {
const configLoaderResult = configLoader({
cwd: options.cwd,
explicitParams,
cwd: params?.cwd ?? options.cwd,
explicitParams:
params && (params.baseUrl || params.paths) ? params : undefined,
});

if (configLoaderResult.resultType === "failed") {
Expand Down