From 8799c9de06252387ad586f3bfedb366c6aaa8622 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 1/6] chore: update changelog and readme --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a480126..17ba5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - 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). +### 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 From c97096d1bb7360f8b5714fcbf8c8151ede8ac979 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:08:48 -0400 Subject: [PATCH 2/6] refactor: move minimist usage into register.js --- register.js | 14 +++++++++++++- src/config-loader.ts | 9 ++++----- src/options.ts | 19 ------------------- src/register.ts | 3 +-- 4 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 src/options.ts diff --git a/register.js b/register.js index c366c40..5d9f28b 100644 --- a/register.js +++ b/register.js @@ -1 +1,13 @@ -require("./").register(); +const minimist = require("minimist"); + +const argv = minimist(process.argv.slice(2), { + // eslint-disable-next-line id-denylist + string: ["project"], + alias: { + project: ["P"], + }, +}); + +require("./").register({ + cwd: argv.project, +}); diff --git a/src/config-loader.ts b/src/config-loader.ts index 3b5c7dc..7c79bfc 100644 --- a/src/config-loader.ts +++ b/src/config-loader.ts @@ -1,6 +1,5 @@ import * as TsConfigLoader2 from "./tsconfig-loader"; import * as path from "path"; -import { options } from "./options"; export interface ExplicitParams { baseUrl: string; @@ -14,7 +13,7 @@ export type TsConfigLoader = ( ) => TsConfigLoader2.TsConfigLoaderResult; export interface ConfigLoaderParams { - cwd: string; + cwd?: string; explicitParams?: ExplicitParams; tsConfigLoader?: TsConfigLoader; } @@ -38,12 +37,12 @@ export type ConfigLoaderResult = | ConfigLoaderSuccessResult | ConfigLoaderFailResult; -export function loadConfig(cwd: string = options.cwd): ConfigLoaderResult { - return configLoader({ cwd: cwd }); +export function loadConfig(cwd?: string): ConfigLoaderResult { + return configLoader({ cwd }); } export function configLoader({ - cwd, + cwd = process.cwd(), explicitParams, tsConfigLoader = TsConfigLoader2.tsConfigLoader, }: ConfigLoaderParams): ConfigLoaderResult { diff --git a/src/options.ts b/src/options.ts deleted file mode 100644 index 877e8fd..0000000 --- a/src/options.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as minimist from "minimist"; - -const argv = minimist(process.argv.slice(2), { - // eslint-disable-next-line id-denylist - string: ["project"], - alias: { - project: ["P"], - }, -}); - -const project = argv && argv.project; - -export interface Options { - cwd: string; -} - -export const options: Options = { - cwd: project || process.cwd(), -}; diff --git a/src/register.ts b/src/register.ts index 8812b51..5138719 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,6 +1,5 @@ import { createMatchPath } from "./match-path-sync"; import { configLoader, ExplicitParams } from "./config-loader"; -import { options } from "./options"; const noOp = (): void => void 0; @@ -58,7 +57,7 @@ export interface RegisterParams extends ExplicitParams { */ export function register(params?: RegisterParams): () => void { const configLoaderResult = configLoader({ - cwd: params?.cwd ?? options.cwd, + cwd: params?.cwd, explicitParams: params && (params.baseUrl || params.paths) ? params : undefined, }); From 53560d5b1ea7420681eceb1fcbdc60eadb4ea2d4 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:20:03 -0400 Subject: [PATCH 3/6] Revert "refactor: move minimist usage into register.js" This reverts commit 3bc36fbfd00770faeabd4eea38cd86994744fa4c. --- register.js | 14 +------------- src/config-loader.ts | 9 +++++---- src/options.ts | 19 +++++++++++++++++++ src/register.ts | 3 ++- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/options.ts diff --git a/register.js b/register.js index 5d9f28b..c366c40 100644 --- a/register.js +++ b/register.js @@ -1,13 +1 @@ -const minimist = require("minimist"); - -const argv = minimist(process.argv.slice(2), { - // eslint-disable-next-line id-denylist - string: ["project"], - alias: { - project: ["P"], - }, -}); - -require("./").register({ - cwd: argv.project, -}); +require("./").register(); diff --git a/src/config-loader.ts b/src/config-loader.ts index 7c79bfc..3b5c7dc 100644 --- a/src/config-loader.ts +++ b/src/config-loader.ts @@ -1,5 +1,6 @@ import * as TsConfigLoader2 from "./tsconfig-loader"; import * as path from "path"; +import { options } from "./options"; export interface ExplicitParams { baseUrl: string; @@ -13,7 +14,7 @@ export type TsConfigLoader = ( ) => TsConfigLoader2.TsConfigLoaderResult; export interface ConfigLoaderParams { - cwd?: string; + cwd: string; explicitParams?: ExplicitParams; tsConfigLoader?: TsConfigLoader; } @@ -37,12 +38,12 @@ export type ConfigLoaderResult = | ConfigLoaderSuccessResult | ConfigLoaderFailResult; -export function loadConfig(cwd?: string): ConfigLoaderResult { - return configLoader({ cwd }); +export function loadConfig(cwd: string = options.cwd): ConfigLoaderResult { + return configLoader({ cwd: cwd }); } export function configLoader({ - cwd = process.cwd(), + cwd, explicitParams, tsConfigLoader = TsConfigLoader2.tsConfigLoader, }: ConfigLoaderParams): ConfigLoaderResult { diff --git a/src/options.ts b/src/options.ts new file mode 100644 index 0000000..877e8fd --- /dev/null +++ b/src/options.ts @@ -0,0 +1,19 @@ +import * as minimist from "minimist"; + +const argv = minimist(process.argv.slice(2), { + // eslint-disable-next-line id-denylist + string: ["project"], + alias: { + project: ["P"], + }, +}); + +const project = argv && argv.project; + +export interface Options { + cwd: string; +} + +export const options: Options = { + cwd: project || process.cwd(), +}; diff --git a/src/register.ts b/src/register.ts index 5138719..8812b51 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,5 +1,6 @@ import { createMatchPath } from "./match-path-sync"; import { configLoader, ExplicitParams } from "./config-loader"; +import { options } from "./options"; const noOp = (): void => void 0; @@ -57,7 +58,7 @@ export interface RegisterParams extends ExplicitParams { */ export function register(params?: RegisterParams): () => void { const configLoaderResult = configLoader({ - cwd: params?.cwd, + cwd: params?.cwd ?? options.cwd, explicitParams: params && (params.baseUrl || params.paths) ? params : undefined, }); From 8d8d10d1bcc07f5019d04e38f89bc5202de3d8e5 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:26:13 -0400 Subject: [PATCH 4/6] refactor: avoid minimist if `register` receives explicit options --- src/config-loader.ts | 5 ++--- src/options.ts | 19 ------------------- src/register.ts | 26 ++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 src/options.ts diff --git a/src/config-loader.ts b/src/config-loader.ts index 3b5c7dc..5c2185d 100644 --- a/src/config-loader.ts +++ b/src/config-loader.ts @@ -1,6 +1,5 @@ import * as TsConfigLoader2 from "./tsconfig-loader"; import * as path from "path"; -import { options } from "./options"; export interface ExplicitParams { baseUrl: string; @@ -38,8 +37,8 @@ export type ConfigLoaderResult = | ConfigLoaderSuccessResult | ConfigLoaderFailResult; -export function loadConfig(cwd: string = options.cwd): ConfigLoaderResult { - return configLoader({ cwd: cwd }); +export function loadConfig(cwd: string = process.cwd()): ConfigLoaderResult { + return configLoader({ cwd }); } export function configLoader({ diff --git a/src/options.ts b/src/options.ts deleted file mode 100644 index 877e8fd..0000000 --- a/src/options.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as minimist from "minimist"; - -const argv = minimist(process.argv.slice(2), { - // eslint-disable-next-line id-denylist - string: ["project"], - alias: { - project: ["P"], - }, -}); - -const project = argv && argv.project; - -export interface Options { - cwd: string; -} - -export const options: Options = { - cwd: project || process.cwd(), -}; diff --git a/src/register.ts b/src/register.ts index 8812b51..bf81052 100644 --- a/src/register.ts +++ b/src/register.ts @@ -1,6 +1,5 @@ import { createMatchPath } from "./match-path-sync"; import { configLoader, ExplicitParams } from "./config-loader"; -import { options } from "./options"; const noOp = (): void => void 0; @@ -57,10 +56,29 @@ export interface RegisterParams extends ExplicitParams { * Returns a function to undo paths registration. */ export function register(params?: RegisterParams): () => void { + let cwd: string | undefined; + let explicitParams: ExplicitParams | undefined; + if (params) { + cwd = params.cwd; + if (params.baseUrl || params.paths) { + explicitParams = params; + } + } else { + // eslint-disable-next-line + const minimist = require("minimist"); + const argv = minimist(process.argv.slice(2), { + // eslint-disable-next-line id-denylist + string: ["project"], + alias: { + project: ["P"], + }, + }); + cwd = argv.project; + } + const configLoaderResult = configLoader({ - cwd: params?.cwd ?? options.cwd, - explicitParams: - params && (params.baseUrl || params.paths) ? params : undefined, + cwd: cwd ?? process.cwd(), + explicitParams, }); if (configLoaderResult.resultType === "failed") { From 50607531055f891fc762de459fd7c2902edd5791 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 2 May 2022 13:19:56 -0400 Subject: [PATCH 5/6] chore: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17ba5ba..446d877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - 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). +### 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). From 8a90968dd83ed8745d43cceb06ab50adf868e2e6 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Mon, 2 May 2022 13:22:04 -0400 Subject: [PATCH 6/6] chore: clean up changelog --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 446d877..abf034b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -- Ability to use absolute paths. [#184](https://github.com/dividab/tsconfig-paths/pull/184) - -- 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). +- 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