Skip to content

Commit d4fbdd4

Browse files
committed
docs(index.ts): 完善语法检查配置的文档描述
ci(release.yml): 更新 CI 工作流配置和发布流程 更新语法检查插件的配置项文档描述,使其更清晰详细 升级 actions/checkout 到 v5 并更新 Node.js 版本至 22 优化发布流程,添加版本和标签存在性检查
1 parent d518050 commit d4fbdd4

2 files changed

Lines changed: 78 additions & 55 deletions

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ jobs:
2121

2222
steps:
2323
- name: 检出代码
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v5
2525
with:
2626
fetch-depth: 0
2727

2828
- name: 设置 Node.js
2929
uses: actions/setup-node@v4
3030
with:
31-
node-version: '18'
31+
node-version: 22
3232
registry-url: 'https://registry.npmjs.org'
3333

3434
- name: 安装 pnpm
@@ -77,48 +77,50 @@ jobs:
7777
- name: 更新版本号 (手动触发时)
7878
if: github.event_name == 'workflow_dispatch'
7979
run: |
80-
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
81-
git config --local user.email "action@github.com"
82-
git config --local user.name "GitHub Action"
83-
git add package.json
84-
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
85-
git tag ${{ steps.get_version.outputs.tag_name }}
86-
git push origin HEAD:${{ github.ref_name }}
87-
git push origin ${{ steps.get_version.outputs.tag_name }}
80+
# 检查 tag 是否已经存在
81+
if git show-ref --tags --verify --quiet "refs/tags/${{ steps.get_version.outputs.tag_name }}"; then
82+
echo "⚠️ Tag ${{ steps.get_version.outputs.tag_name }} 已存在,跳过创建"
83+
else
84+
npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
85+
git config --local user.email "action@github.com"
86+
git config --local user.name "GitHub Action"
87+
git add package.json
88+
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
89+
git tag ${{ steps.get_version.outputs.tag_name }}
90+
git push origin HEAD:${{ github.ref_name }}
91+
git push origin ${{ steps.get_version.outputs.tag_name }}
92+
fi
8893
8994
- name: 生成变更日志
9095
id: changelog
96+
run: npx changelogithub
97+
continue-on-error: true
98+
env:
99+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
100+
101+
- name: 发布到 npm
91102
run: |
92-
# 获取上一个标签
93-
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
103+
# 检查版本是否已经发布到 npm
104+
PACKAGE_NAME=$(node -p "require('./package.json').name")
105+
CURRENT_VERSION=$(node -p "require('./package.json').version")
94106
95-
if [ -z "$PREV_TAG" ]; then
96-
# 如果没有上一个标签,获取所有提交
97-
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
107+
# 尝试获取 npm 上的版本信息
108+
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version 2>/dev/null; then
109+
echo "⚠️ 版本 ${CURRENT_VERSION} 已存在于 npm,跳过发布"
98110
else
99-
# 获取两个标签之间的提交
100-
CHANGELOG=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
111+
echo "📦 发布版本 ${CURRENT_VERSION} 到 npm..."
112+
pnpm publish --no-git-checks
101113
fi
102-
103-
# 保存到文件以避免特殊字符问题
104-
echo "$CHANGELOG" > changelog.txt
105-
echo "changelog_file=changelog.txt" >> $GITHUB_OUTPUT
106-
107-
- name: 发布到 npm
108-
run: pnpm publish --no-git-checks
109114
env:
110115
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
111116

112-
- name: 创建 GitHub Release
113-
uses: actions/create-release@v1
114-
env:
115-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
- name: Create GitHub Release
118+
uses: ncipollo/release-action@v1
116119
with:
117-
tag_name: ${{ steps.get_version.outputs.tag_name }}
118-
release_name: Release ${{ steps.get_version.outputs.tag_name }}
119-
body_path: ${{ steps.changelog.outputs.changelog_file }}
120-
draft: false
121-
prerelease: false
120+
generateReleaseNotes: "true"
121+
allowUpdates: true
122+
skipIfReleaseExists: false
123+
omitBodyDuringUpdate: false
122124

123125
- name: 通知发布成功
124126
run: |

src/index.ts

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,49 @@ export default (api: IApi) => {
1212
key: 'checkSyntax',
1313
config: {
1414
schema({ zod }) {
15-
return zod.union([
16-
zod.boolean(),
17-
zod.object({
18-
/**
19-
* The target browser range of the project.
20-
* Its value is a standard browserslist array.
21-
*/
22-
targets: zod.array(zod.string()).optional(),
23-
/**
24-
* Used to exclude a portion of source files during detection.
25-
* You can pass in one or more regular expressions to match the paths of source files.
26-
*/
27-
exclude: zod
28-
.union([zod.string(), zod.array(zod.string())])
29-
.optional(),
30-
/**
31-
* The minimum ECMAScript syntax version that can be used in the build artifact.
32-
* The priority of `ecmaVersion` is higher than `targets`.
33-
*/
34-
ecmaVersion: zod.union([zod.string(), zod.number()]).optional(),
35-
}),
36-
]);
15+
return zod
16+
.union([
17+
zod
18+
.boolean()
19+
.describe(
20+
'是否启用语法检查。设为 true 启用默认配置的语法检查,false 禁用语法检查功能。',
21+
),
22+
zod
23+
.object({
24+
targets: zod
25+
.array(zod.string())
26+
.describe(
27+
'目标浏览器兼容性范围配置。使用标准的 browserslist 格式数组,如 ["chrome >= 90", "firefox >= 88", "safari >= 14"]。插件将检查构建产物中的 JavaScript 语法是否与指定的浏览器兼容。如未配置,将使用项目根配置中的 targets 作为默认值。',
28+
)
29+
.optional(),
30+
exclude: zod
31+
.union([zod.string(), zod.array(zod.string())])
32+
.describe(
33+
'排除语法检查的文件路径模式。支持单个正则表达式字符串或字符串数组,用于匹配需要跳过检查的源文件路径。例如:"/node_modules/" 或 ["/vendor/", "\\.min\\.js$"]。被排除的文件不会进行语法兼容性检查。',
34+
)
35+
.optional(),
36+
ecmaVersion: zod
37+
.union([
38+
zod
39+
.string()
40+
.regex(
41+
/^es(3|5|6|20\d{2}|\d+)$/i,
42+
'ECMAScript版本格式无效,支持格式:es3, es5, es6, es2015, es2016, es2017等',
43+
),
44+
zod.number().min(3),
45+
])
46+
.describe(
47+
'允许使用的最低 ECMAScript 语法版本。可以是字符串格式(如 "es5", "es2015", "es2020", "es2023")或数字格式(如 5, 2015, 2020, 2023)。此配置的优先级高于 targets 配置。用于限制构建产物中可使用的 JavaScript 语法特性,确保代码在目标环境中正常运行。',
48+
)
49+
.optional(),
50+
})
51+
.describe(
52+
'语法检查详细配置对象。用于自定义目标浏览器、排除文件和ECMAScript版本等检查参数。',
53+
),
54+
])
55+
.describe(
56+
'代码语法兼容性检查插件配置。基于 unplugin-check-syntax,在构建过程中检测 JavaScript/TypeScript 代码是否包含目标浏览器不支持的语法特性,支持 Vite、Webpack 和 Rspack 构建工具,帮助确保应用在指定浏览器环境中的兼容性。插件默认在非开发环境下启用。',
57+
);
3758
},
3859
},
3960
enableBy: () => {

0 commit comments

Comments
 (0)