From 9d2005ebf91e93b7bc484653185730d342677111 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:30:46 -0400 Subject: [PATCH 1/2] feat(register): add `cwd` param --- src/register.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/register.ts b/src/register.ts index 929b7a0..8812b51 100644 --- a/src/register.ts +++ b/src/register.ts @@ -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") { From 09cd805c51fafa2353c630cb4bb0a13814d00876 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:02:08 -0400 Subject: [PATCH 2/2] chore: update changelog and readme --- CHANGELOG.md | 4 ++++ README.md | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd484c..ecf4fde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 768119e..d8df439 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ export interface ExplicitParams { paths: { [key: string]: Array }; mainFields?: Array; addMatchAll?: boolean; + cwd?: string; } /**