Skip to content

Commit

Permalink
🐛fix: api.userConfig type overload (#41)
Browse files Browse the repository at this point in the history
* fix: api.userConfig type overload

* fix: IApi.userConfig type overload

* fix: add type overload in template

---------

Co-authored-by: Yihong <[email protected]>
  • Loading branch information
SokuRitszZ and Yihong committed Jun 30, 2023
1 parent 1422d28 commit 56f844d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/create-doctor/templates/feature/src/type.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export type IApi = DoctorApi & {
};

addDoctor{{{ commandCamelCased }}}CheckEnd: (fn: () => void) => void;
} & {
userConfig: ConfigSchema;
};
2 changes: 2 additions & 0 deletions packages/npm-pkg/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type IApi = DoctorApi &
addDoctorNpmPkgCheckEnd: (
fn: (meta: Meta) => DoctorMeta[] | DoctorMeta | undefined
) => void;
} & {
userConfig: ConfigSchema;
};

export interface ConfigSchema {
Expand Down
12 changes: 7 additions & 5 deletions packages/npm-pkg/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IApi } from "@doctors/core";
import { globSync } from "glob";
import path from "path";
import fs from "fs";
import lodash from "lodash";
import sourceParser, { IDoctorSourceParseResult } from "./parser";
import { DEFAULT_SOURCE_IGNORES } from "./constants";
import { IApi } from "./type";

export interface SourceFile {
path?: string;
Expand All @@ -22,8 +22,8 @@ export function getSourceFiles(api: IApi) {
let files: string[] = [];
let compileFiles: string[] = [];

if (api.userConfig?.npmPkg?.compileFIles) {
compileFiles = Array.isArray(api.userConfig?.npmPkg?.compileFIles)
if (api.userConfig.npmPkg?.compileFiles) {
compileFiles = Array.isArray(api.userConfig?.npmPkg?.compileFiles)
? api.userConfig?.npmPkg?.compileFiles
: [api.userConfig?.npmPkg?.compileFiles];
}
Expand All @@ -48,7 +48,7 @@ export function getSourceFiles(api: IApi) {

const sourceDirs = getSourceDirs(files);

const allFiles: string[] = sourceDirs.reduce<string[]>(
let allFiles: string[] = sourceDirs.reduce<string[]>(
(ret: string[], dir: string) =>
ret.concat(
globSync(`${dir}/**/*.{ts,js}`, {
Expand All @@ -60,7 +60,9 @@ export function getSourceFiles(api: IApi) {
[]
);

return Array.from(new Set(allFiles)) || [];
allFiles = [...new Set(allFiles)];

return allFiles;
}

export async function getFilesWithImports(api: IApi) {
Expand Down
5 changes: 4 additions & 1 deletion packages/web-tools/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export interface DoctorLifeCycleApi {
addDoctorWebToolsCheckEnd: (fn: () => Awaitable<void>) => void;
}

export type IApi = DoctorApi & DoctorLifeCycleApi;
export type IApi = DoctorApi &
DoctorLifeCycleApi & {
userConfig: ConfigSchema;
};

0 comments on commit 56f844d

Please sign in to comment.