diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000000..669fcd6cfb --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +pnpm exec commitlint --config commitlint.config.js --edit "${1}" diff --git a/.husky/pre-push-todo-open b/.husky/pre-push-todo-open deleted file mode 100755 index d1096ab18a..0000000000 --- a/.husky/pre-push-todo-open +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npm run test diff --git a/commitlint.config.js b/commitlint.config.js index d6eb398c90..4e1cb60b45 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,110 +1,3 @@ -'use strict' -const { execSync } = require('child_process') -const fg = require('fast-glob') - -const getPackages = (packagePath) => - fg.sync('*', { cwd: packagePath, onlyDirectories: true }) - -const scopes = [ - ...getPackages('packages'), - ...getPackages('internal'), - 'docs', - 'play', - 'project', - 'core', - 'style', - 'ci', - 'dev', - 'deploy', - 'other', - 'typography', - 'color', - 'border', - 'var', - 'ssr', -] - -const gitStatus = execSync('git status --porcelain || true') - .toString() - .trim() - .split('\n') - -const scopeComplete = gitStatus - .find((r) => ~r.indexOf('M packages')) - ?.replace(/\//g, '%%') - ?.match(/packages%%((\w|-)*)/)?.[1] - -const subjectComplete = gitStatus - .find((r) => ~r.indexOf('M packages/components')) - ?.replace(/\//g, '%%') - ?.match(/packages%%components%%((\w|-)*)/)?.[1] - -module.exports = { - rules: { - /** - * type[scope]: [function] description - * ^^^^^ - */ - 'scope-enum': [2, 'always', scopes], - /** - * type[scope]: [function] description - * - * ^^^^^^^^^^^^^^ empty line. - * - Something here - */ - 'body-leading-blank': [1, 'always'], - /** - * type[scope]: [function] description - * - * - something here - * - * ^^^^^^^^^^^^^^ - */ - 'footer-leading-blank': [1, 'always'], - /** - * type[scope]: [function] description [No more than 72 characters] - * ^^^^^ - */ - 'header-max-length': [2, 'always', 72], - 'scope-case': [2, 'always', 'lower-case'], - 'subject-case': [ - 1, - 'never', - ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], - ], - 'subject-empty': [2, 'never'], - 'subject-full-stop': [2, 'never', '.'], - 'type-case': [2, 'always', 'lower-case'], - 'type-empty': [2, 'never'], - /** - * type[scope]: [function] description - * ^^^^ - */ - 'type-enum': [ - 2, - 'always', - [ - 'build', - 'chore', - 'ci', - 'docs', - 'feat', - 'fix', - 'perf', - 'refactor', - 'revert', - 'release', - 'style', - 'test', - 'improvement', - ], - ], - }, - prompt: { - defaultScope: scopeComplete, - customScopesAlign: !scopeComplete ? 'top' : 'bottom', - defaultSubject: subjectComplete && `[${subjectComplete}] `, - allowCustomIssuePrefixs: false, - allowEmptyIssuePrefixs: false, - }, -} +// commitlint uses `ts-node` to load typescript config, it's too slow. So we replace it with `esbuild`. +require('@esbuild-kit/cjs-loader') +module.exports = require('./commitlint.config.ts').default diff --git a/commitlint.config.ts b/commitlint.config.ts new file mode 100644 index 0000000000..1649323d89 --- /dev/null +++ b/commitlint.config.ts @@ -0,0 +1,109 @@ +import { execSync } from 'child_process' +import fg from 'fast-glob' + +const getPackages = (packagePath) => + fg.sync('*', { cwd: packagePath, onlyDirectories: true }) + +const scopes = [ + ...getPackages('packages'), + ...getPackages('internal'), + 'docs', + 'play', + 'project', + 'core', + 'style', + 'ci', + 'dev', + 'deploy', + 'other', + 'typography', + 'color', + 'border', + 'var', + 'ssr', +] + +const gitStatus = execSync('git status --porcelain || true') + .toString() + .trim() + .split('\n') + +const scopeComplete = gitStatus + .find((r) => ~r.indexOf('M packages')) + ?.replace(/\//g, '%%') + ?.match(/packages%%((\w|-)*)/)?.[1] + +const subjectComplete = gitStatus + .find((r) => ~r.indexOf('M packages/components')) + ?.replace(/\//g, '%%') + ?.match(/packages%%components%%((\w|-)*)/)?.[1] + +export default { + rules: { + /** + * type[scope]: [function] description + * ^^^^^ + */ + 'scope-enum': [2, 'always', scopes], + /** + * type[scope]: [function] description + * + * ^^^^^^^^^^^^^^ empty line. + * - Something here + */ + 'body-leading-blank': [1, 'always'], + /** + * type[scope]: [function] description + * + * - something here + * + * ^^^^^^^^^^^^^^ + */ + 'footer-leading-blank': [1, 'always'], + /** + * type[scope]: [function] description [No more than 72 characters] + * ^^^^^ + */ + 'header-max-length': [2, 'always', 72], + 'scope-case': [2, 'always', 'lower-case'], + 'subject-case': [ + 1, + 'never', + ['sentence-case', 'start-case', 'pascal-case', 'upper-case'], + ], + 'subject-empty': [2, 'never'], + 'subject-full-stop': [2, 'never', '.'], + 'type-case': [2, 'always', 'lower-case'], + 'type-empty': [2, 'never'], + /** + * type[scope]: [function] description + * ^^^^ + */ + 'type-enum': [ + 2, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'release', + 'style', + 'test', + 'improvement', + ], + ], + }, + prompt: { + defaultScope: scopeComplete, + customScopesAlign: !scopeComplete ? 'top' : 'bottom', + defaultSubject: subjectComplete && `[${subjectComplete}] `, + allowCustomIssuePrefixs: false, + allowEmptyIssuePrefixs: false, + }, +} diff --git a/package.json b/package.json index 399f807c0e..e9cc714cce 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@element-plus/build": "workspace:^0.0.1", "@element-plus/build-utils": "workspace:^0.0.1", "@element-plus/eslint-config": "workspace:*", + "@esbuild-kit/cjs-loader": "^2.0.1", "@pnpm/find-workspace-packages": "^4.0.10", "@pnpm/logger": "^4.0.0", "@pnpm/types": "^8.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e4c43bf88..a058570256 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,7 @@ importers: '@element-plus/theme-chalk': workspace:* '@element-plus/tokens': workspace:* '@element-plus/utils': workspace:* + '@esbuild-kit/cjs-loader': ^2.0.1 '@floating-ui/dom': ^0.5.2 '@pnpm/find-workspace-packages': ^4.0.10 '@pnpm/logger': ^4.0.0 @@ -106,6 +107,7 @@ importers: '@element-plus/build': link:internal/build '@element-plus/build-utils': link:internal/build-utils '@element-plus/eslint-config': link:internal/eslint-config + '@esbuild-kit/cjs-loader': 2.0.1 '@pnpm/find-workspace-packages': 4.0.10_@pnpm+logger@4.0.0 '@pnpm/logger': 4.0.0 '@pnpm/types': 8.0.1