Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Dec 20, 2023
1 parent 17e3b10 commit 251c8e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/parse-tsconfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const resolveExtends = (
extendsPath: string,
fromDirectoryPath: string,
circularExtendsTracker: Set<string>,
cache?: Cache,
cache?: Cache<string>,
) => {
const resolvedExtendsPath = resolveExtendsPath(
extendsPath,
Expand Down Expand Up @@ -79,7 +79,7 @@ const resolveExtends = (

const _parseTsconfig = (
tsconfigPath: string,
cache?: Cache,
cache?: Cache<string>,
circularExtendsTracker = new Set<string>(),
): TsConfigJsonResolved => {
let realTsconfigPath: string;
Expand Down Expand Up @@ -213,5 +213,5 @@ const _parseTsconfig = (

export const parseTsconfig = (
tsconfigPath: string,
cache: Cache = new Map(),
cache: Cache<string> = new Map(),
): TsConfigJsonResolved => _parseTsconfig(tsconfigPath, cache);
4 changes: 2 additions & 2 deletions src/parse-tsconfig/resolve-extends-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const resolveFromPackageJsonPath = (
packageJsonPath: string,
subpath: string,
ignoreExports?: boolean,
cache?: Cache,
cache?: Cache<string>,
) => {
const cacheKey = `resolveFromPackageJsonPath:${packageJsonPath}:${subpath}:${ignoreExports}`;
if (cache?.has(cacheKey)) {
Expand Down Expand Up @@ -67,7 +67,7 @@ const TS_CONFIG_JSON = 'tsconfig.json';
export const resolveExtendsPath = (
requestedPath: string,
directoryPath: string,
cache?: Cache,
cache?: Cache<string>,
) => {
let filePath = requestedPath;

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export type TsConfigResult = {
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Cache = Map<string, any>;
export type Cache<value = any> = Map<string, value>;
6 changes: 4 additions & 2 deletions src/utils/fs-cached.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const cacheFs = <MethodName extends keyof FsMethods>(
name: MethodName,
) => {
const method = fs[name];
type FsReturnType = ReturnType<FsMethods[MethodName]>;

return (
cache?: Cache,
...args: any[]
): ReturnType<FsMethods[MethodName]> => {
): FsReturnType => {
const cacheKey = `${name}:${args.join(':')}`;
let result = cache?.get(cacheKey);
let result = cache?.get(cacheKey) as FsReturnType;

if (result === undefined) {
result = Reflect.apply(method, fs, args);
Expand Down

0 comments on commit 251c8e3

Please sign in to comment.