Skip to content

Commit

Permalink
feat(register): add cwd param (#205)
Browse files Browse the repository at this point in the history
* feat(register): add `cwd` param

* chore: update changelog and readme
  • Loading branch information
aleclarson committed Apr 21, 2022
1 parent 9a6d9f8 commit fc7cd60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- 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!

### 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

0 comments on commit fc7cd60

Please sign in to comment.