diff --git a/CHANGELOG.md b/CHANGELOG.md index a480126..abf034b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,16 @@ 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) +### 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 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") {