Skip to content

Commit

Permalink
refactor: move minimist usage into register.js
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Apr 15, 2022
1 parent 09cd805 commit 3bc36fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
14 changes: 13 additions & 1 deletion register.js
Original file line number Diff line number Diff line change
@@ -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,
});
9 changes: 4 additions & 5 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 All @@ -14,7 +13,7 @@ export type TsConfigLoader = (
) => TsConfigLoader2.TsConfigLoaderResult;

export interface ConfigLoaderParams {
cwd: string;
cwd?: string;
explicitParams?: ExplicitParams;
tsConfigLoader?: TsConfigLoader;
}
Expand All @@ -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 {
Expand Down
19 changes: 0 additions & 19 deletions src/options.ts

This file was deleted.

3 changes: 1 addition & 2 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 @@ -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,
});
Expand Down

0 comments on commit 3bc36fb

Please sign in to comment.