Skip to content

Commit

Permalink
fix: 修复 tsc 异常;修复 jira check 多次执行格式重复处理的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Oct 23, 2024
1 parent 3a64f84 commit 302e0a4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 41 deletions.
3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

node cjs/cli.js --commitlint
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

node bin/flh.js --tscheck --eslint --jest --only-changes --fix
node bin/flh.js --prettier --only-changes --fix
git add --update
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"flh": "bin/flh.js"
},
"scripts": {
"prepare": "husky install",
"prepare": "husky || true",
"dev": "npm run watch:build",
"start": "npm run watch",
"build": "run-s clean && run-p build:*",
Expand Down Expand Up @@ -67,41 +67,41 @@
"bin"
],
"dependencies": {
"@lzwme/fe-utils": "^1.7.3",
"@lzwme/fe-utils": "^1.7.5",
"commander": "^12.1.0",
"console-log-colors": "^0.5.0",
"enquirer": "^2.4.1",
"fast-glob": "^3.3.2",
"micromatch": "^4.0.7"
"micromatch": "^4.0.8"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@eslint/js": "^9.13.0",
"@jest/core": "^29.7.0",
"@jest/test-result": "^29.7.0",
"@jest/types": "^29.6.3",
"@node-rs/deno-lint": "^1.20.4",
"@types/eslint": "^8.56.10",
"@types/jest": "^29.5.12",
"@types/micromatch": "^4.0.7",
"@types/node": "^20.14.1",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^9.4.0",
"@types/eslint": "^9.6.1",
"@types/jest": "^29.5.14",
"@types/micromatch": "^4.0.9",
"@types/node": "^22.7.9",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^9.0.11",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unicorn": "^56.0.0",
"husky": "^9.1.6",
"jest": "^29.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.0",
"prettier": "^3.3.3",
"standard-version": "^9.5.0",
"stylelint": "^16.6.1",
"ts-jest": "^29.1.4",
"stylelint": "^16.10.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typescript": "^5.4.5",
"typescript-eslint": "^7.12.0"
"typedoc": "^0.26.10",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0"
},
"peerDependencies": {
"@jest/core": "*"
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: lzw
* @Date: 2021-09-25 16:15:03
* @LastEditors: renxia
* @LastEditTime: 2024-06-14 14:35:30
* @LastEditTime: 2024-10-23 15:57:19
* @Description:
*/

Expand Down Expand Up @@ -56,6 +56,7 @@ export const config: FlhConfig = {
warningTip: `[errors-必须修复;warnings-历史文件选择性处理(对于历史文件慎重修改 == 类问题)]`,
mode: 'proc',
eslintOptions: {
// @ts-ignore-next-line
extensions: ['ts', 'tsx', 'js', 'jsx', 'cts', 'mts'],
errorOnUnmatchedPattern: false,
},
Expand Down Expand Up @@ -138,7 +139,7 @@ export function getConfig(options?: FlhConfig, useCache = true) {

if (existsSync(config.configPath)) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const d = require(config.configPath);
assign(config, d);
} catch {
Expand Down
5 changes: 3 additions & 2 deletions src/lint/eslint-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: lzw
* @Date: 2021-08-15 22:39:01
* @LastEditors: renxia
* @LastEditTime: 2024-04-10 10:51:34
* @LastEditTime: 2024-10-23 15:49:18
* @Description: eslint check
*/

Expand Down Expand Up @@ -56,6 +56,7 @@ export class ESLintCheck extends LintBase<ESLintCheckConfig, ESLintCheckResult>
/** 配置参数格式化 */
public override parseConfig(config: ESLintCheckConfig) {
config = super.parseConfig(config);
// @ts-ignore-next
this.config.extensions = config.extensions || config.eslintOptions.extensions || ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'];

return this.config;
Expand Down Expand Up @@ -87,7 +88,7 @@ export class ESLintCheck extends LintBase<ESLintCheckConfig, ESLintCheckResult>
return false;
});

if (isV9) {
if (isV9 && 'extensions' in option) {
delete option.extensions;
}

Expand Down
8 changes: 5 additions & 3 deletions src/lint/jira-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: lzw
* @Date: 2021-08-15 22:39:01
* @LastEditors: renxia
* @LastEditTime: 2024-10-23 14:57:12
* @LastEditTime: 2024-10-23 15:41:46
* @Description: Jira check
*/

Expand Down Expand Up @@ -337,7 +337,7 @@ export class JiraCheck extends LintBase<JiraCheckConfig, JiraCheckResult> {
/** 智能匹配正则表达式,commit覆盖, JIRA号后需要输入至少一个中文、【|[、英文或者空格进行隔开 例子: JGCPS-1234测试提交123 或 [JGCPS-1234] 测试提交123 => JGCPS-1234 [ET][2.9.1][feature]测试提交123 */
const smartRegWithMessage = new RegExp(`^\\[?${issuePrefix}\\d+\\]?\\s*([A-Za-z\\u4e00-\\u9fa5\\s【\\[]+.+)`);
/** 智能匹配正则表达式,单纯匹配jira 例子: JGCPS-1234 或 [JGCPS-1234] => JGCPS-1234 [ET][2.9.1][feature]JIRA本身的标题 */
const smartRegWithJIRA = new RegExp(`^\\[?${issuePrefix}(\\d+)\\]?`, 'g');
const smartRegWithJIRA = new RegExp(`^\\[?${issuePrefix}(\\d+)\\]?$`, 'g');
const issueTypeList = await this.getIssueType();
/** 禁止提交的类型 */
const noAllowIssueType: number[] = [];
Expand Down Expand Up @@ -398,7 +398,9 @@ export class JiraCheck extends LintBase<JiraCheckConfig, JiraCheckResult> {
smartCommit = commitMessage;

// 如果匹配到commit中包含中文,则保留提交信息
if (smartRegWithMessage.test(commitMessage)) {
if (commitMessage.startsWith(`${jiraID} ${config.commitMsgPrefix}[${versionName}][${issueText}]`)) {
smartCommit = commitMessage;
} else if (smartRegWithMessage.test(commitMessage)) {
// 如果用户需要手动填入commit信息
const message = commitMessage.match(smartRegWithMessage)[1].trim();
smartCommit = `${jiraID} ${config.commitMsgPrefix}[${versionName}][${issueText}] ${message}`;
Expand Down
6 changes: 3 additions & 3 deletions src/worker/fork.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: lzw
* @Date: 2021-08-25 10:12:21
* @LastEditors: lzw
* @LastEditTime: 2022-11-01 11:10:55
* @LastEditors: renxia
* @LastEditTime: 2024-10-23 15:59:26
* @Description: 在 fork 子进程中执行 Check 任务
*/

Expand Down Expand Up @@ -44,7 +44,7 @@ export function createForkThread<T, C = unknown>(
worker.on('error', error => logger.log(`[worker][${options.type}]err:`, error));
worker.on('exit', code => {
if (options.debug) logger.debug(`[worker][${options.type}]exit worker`, code);
if (code !== 0) reject(code);
if (code !== 0) reject(new Error(`[createForkThread][exit]: ${code}`));
});

if (options.debug) {
Expand Down
8 changes: 4 additions & 4 deletions src/worker/worker-threads.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: lzw
* @Date: 2021-08-25 10:12:21
* @LastEditors: lzw
* @LastEditTime: 2022-11-01 11:13:55
* @LastEditors: renxia
* @LastEditTime: 2024-10-23 15:17:21
* @Description: worker_threads 实现在 worker 线程中执行
*
* - worker_threads 比 child_process 和 cluster 更为轻量级的并行性,而且 worker_threads 可有效地共享内存
Expand All @@ -27,7 +27,7 @@ export function createWorkerThreads<T, C = unknown>(
onMessage?: (d: WorkerMessageBody<T>) => void
): Promise<T> {
return new Promise((rs, reject) => {
if (!isMainThread) return reject(-2);
if (!isMainThread) return reject(new Error('[createWorkerThreads]worker thread can not create worker thread'));
const _filename = resolve(flhSrcDir, './worker/worker-threads.js');
const worker = new Worker(_filename, {
workerData: handlerForCTOptions(options, 'send'),
Expand All @@ -47,7 +47,7 @@ export function createWorkerThreads<T, C = unknown>(

worker.on('exit', code => {
getLogger().debug(`[${options.type}] exit worker with code:`, code);
if (code !== 0) reject(code);
if (code !== 0) reject(new Error(`[createWorkerThreads][${options.type}] worker exit with code: ${code}`));
});
});
}
Expand Down

0 comments on commit 302e0a4

Please sign in to comment.