Skip to content

Commit

Permalink
refactor: avoid minimist if register receives explicit options
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Apr 20, 2022
1 parent d956c7e commit 6bf2596
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/config-loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as TsConfigLoader2 from "./tsconfig-loader";
import * as path from "path";
import { options } from "./options";

export interface ExplicitParams {
baseUrl: string;
Expand Down Expand Up @@ -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({
Expand Down
19 changes: 0 additions & 19 deletions src/options.ts

This file was deleted.

26 changes: 22 additions & 4 deletions src/register.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit 6bf2596

Please sign in to comment.