-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cz-git): configure loader extract, perf load speed
use cosmiconfig extract common BREAKING CHANGE : No supprt typescript config define file. `commitlint.config.ts` link #24, #25
- Loading branch information
Showing
8 changed files
with
176 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,85 @@ | ||
export * from "./commitilint"; | ||
export * from "./commitizen"; | ||
import "@commitlint/types"; | ||
import resolveExtends from "@commitlint/resolve-extends"; | ||
import { cosmiconfig } from "cosmiconfig"; | ||
import path from "path"; | ||
|
||
export interface LoaderOptions { | ||
moduleName: string; | ||
cwd?: string; | ||
stopDir?: string; | ||
explicitPath?: string; | ||
searchPlaces?: string[]; | ||
packageProp?: string[]; | ||
} | ||
|
||
export const loader = async (options: LoaderOptions) => { | ||
const cwd = options.cwd || process.cwd(); | ||
const cosmiconfigFn = cosmiconfig(options.moduleName, { | ||
searchPlaces: options.searchPlaces || [], | ||
packageProp: options.packageProp || options.moduleName, | ||
stopDir: options.stopDir, | ||
ignoreEmptySearchPlaces: true, | ||
cache: true | ||
}); | ||
|
||
const resultPath = options.explicitPath ? path.resolve(cwd, options.explicitPath) : undefined; | ||
const resultFn = resultPath ? cosmiconfigFn.load : cosmiconfigFn.search; | ||
const searchPath = resultPath ? resultPath : cwd; | ||
const result = await resultFn(searchPath); | ||
|
||
return result ?? null; | ||
}; | ||
|
||
export const clLoader = async () => { | ||
const moduleName = "commitlint"; | ||
const options = { | ||
moduleName, | ||
searchPlaces: [ | ||
"package.json", | ||
`.${moduleName}rc`, | ||
`.${moduleName}rc.json`, | ||
`.${moduleName}rc.yaml`, | ||
`.${moduleName}rc.yml`, | ||
`.${moduleName}rc.js`, | ||
`.${moduleName}rc.cjs`, | ||
`${moduleName}.config.js`, | ||
`${moduleName}.config.cjs` | ||
] | ||
}; | ||
const data = await loader(options); | ||
if (data === null) return {}; | ||
|
||
// resolve extends | ||
const extended = resolveExtends(data.config, { | ||
prefix: "commitlint-config", | ||
cwd: data.filepath | ||
}); | ||
return extended; | ||
}; | ||
|
||
export const czLoader = async () => { | ||
const moduleName = "commitizen"; | ||
const options = { | ||
moduleName, | ||
searchPlaces: ["package.json", ".czrc", ".cz.json"], | ||
packageProp: ["config", "commitizen"] | ||
}; | ||
const data = await loader(options); | ||
return data === null ? {} : data.config || data; | ||
}; | ||
|
||
/** | ||
* @description: Main Func: both loader commitizen config and commitlint config | ||
*/ | ||
export const configLoader = async () => { | ||
return Promise.all([clLoader(), czLoader()]).then(([clData, czData]) => { | ||
const clPrompt = clData.prompt || {}; | ||
return { | ||
...clData, | ||
prompt: { | ||
...czData, | ||
...clPrompt | ||
} | ||
}; | ||
}); | ||
}; |
Oops, something went wrong.