Skip to content

Commit 3eda0e4

Browse files
committed
feat: 更新 package.json 和 README.md,添加 ECMAScript 语法检查功能,支持 Vite、Webpack 和 Rspack 构建工具,更新依赖项版本。
1 parent 7887e86 commit 3eda0e4

8 files changed

Lines changed: 2625 additions & 2443 deletions

File tree

README.md

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,125 @@
1-
# winjs-plugin-example
1+
# @winner-fed/plugin-check-syntax
22

3-
Example plugin for WinJS.
3+
WinJS plugin for checking ECMAScript syntax compatibility using `@winner-fed/unplugin-check-syntax`.
44

55
<p>
6-
<a href="https://npmjs.com/package/winjs-plugin-example">
7-
<img src="https://img.shields.io/npm/v/winjs-plugin-example?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
6+
<a href="https://npmjs.com/package/@winner-fed/plugin-check-syntax">
7+
<img src="https://img.shields.io/npm/v/@winner-fed/plugin-check-syntax?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
88
</a>
99
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10-
<a href="https://npmcharts.com/compare/winjs-plugin-example?minimal=true"><img src="https://img.shields.io/npm/dm/winjs-plugin-example.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
10+
<a href="https://npmcharts.com/compare/@winner-fed/plugin-check-syntax?minimal=true"><img src="https://img.shields.io/npm/dm/@winner-fed/plugin-check-syntax.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
1111
</p>
1212

13-
## Usage
13+
## 功能特性
1414

15-
Install:
15+
- 🔍 检查 ECMAScript 语法兼容性
16+
- 🎯 支持自定义目标浏览器范围
17+
- 📦 支持 Vite、Webpack、Rspack 构建工具
18+
- ⚙️ 灵活的配置选项
19+
- 🚫 支持排除特定文件
20+
21+
## 安装
1622

1723
```bash
18-
npm add winjs-plugin-example -D
24+
npm add @winner-fed/plugin-check-syntax -D
1925
```
2026

21-
Add plugin to your `.winrc.ts`:
27+
## 使用方法
28+
29+
`.winrc.ts` 配置文件中添加插件:
2230

2331
```ts
2432
// .winrc.ts
2533
export default {
26-
plugins: ['winjs-plugin-example'],
27-
// 开启配置
28-
example: {}
34+
plugins: ['@winner-fed/plugin-check-syntax'],
35+
// 启用语法检查
36+
checkSyntax: {
37+
// 目标浏览器范围
38+
targets: ['> 1%', 'last 2 versions'],
39+
40+
// 排除文件
41+
exclude: ['node_modules', '\\.min\\.js$'],
42+
43+
// ECMAScript 版本
44+
ecmaVersion: 2018
45+
}
2946
};
3047
```
3148

32-
## Options
49+
## 配置选项
50+
51+
### targets
52+
53+
指定项目的目标浏览器范围,值为标准的 browserslist 数组。
54+
55+
- 类型: `string[]`
56+
- 默认值: `undefined`
57+
- 示例:
58+
59+
```js
60+
export default {
61+
plugins: ['@winner-fed/plugin-check-syntax'],
62+
checkSyntax: {
63+
targets: ['> 1%', 'last 2 versions', 'not ie <= 8']
64+
}
65+
};
66+
```
67+
68+
### exclude
69+
70+
用于在检测期间排除部分源文件。可以传入一个或多个正则表达式来匹配源文件的路径。
71+
72+
- 类型: `string | string[]`
73+
- 默认值: `undefined`
74+
- 示例:
3375

34-
### foo
76+
```js
77+
export default {
78+
plugins: ['@winner-fed/plugin-check-syntax'],
79+
checkSyntax: {
80+
exclude: [
81+
'node_modules',
82+
'\\.min\\.js$',
83+
'vendor/'
84+
]
85+
}
86+
};
87+
```
88+
89+
### ecmaVersion
3590

36-
Some description.
91+
指定构建产物中可以使用的最低 ECMAScript 语法版本。`ecmaVersion` 的优先级高于 `targets`
3792

38-
- Type: `string`
39-
- Default: `undefined`
40-
- Example:
93+
- 类型: `3 | 5 | 6 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 'latest'`
94+
- 默认值: `undefined`
95+
- 示例:
4196

4297
```js
4398
export default {
44-
plugins: ['winjs-plugin-example'],
45-
// 开启配置
46-
example: {
47-
foo: 'bar'
99+
plugins: ['@winner-fed/plugin-check-syntax'],
100+
checkSyntax: {
101+
ecmaVersion: 2018
48102
}
49103
};
50104
```
51105

106+
## 简单配置
107+
108+
如果你只想启用默认的语法检查,可以直接设置为 `true`
109+
110+
```ts
111+
export default {
112+
plugins: ['@winner-fed/plugin-check-syntax'],
113+
checkSyntax: true
114+
};
115+
```
116+
117+
## 支持的构建工具
118+
119+
- ✅ Vite
120+
- ✅ Webpack
121+
- ✅ Rspack
122+
52123
## License
53124

54125
[MIT](./LICENSE).

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"name": "winjs-plugin-example",
2+
"name": "@winner-fed/plugin-check-syntax",
33
"version": "0.0.0",
4-
"repository": "https://github.com/winjs-dev/winjs-plugin-template",
4+
"description": "WinJS plugin for checking ECMAScript syntax compatibility",
5+
"repository": "https://github.com/winjs-dev/winjs-plugin-check-syntax",
56
"license": "MIT",
67
"type": "module",
78
"exports": {
@@ -30,18 +31,21 @@
3031
"devDependencies": {
3132
"@biomejs/biome": "^1.9.4",
3233
"@playwright/test": "^1.49.0",
33-
"@winner-fed/winjs": "^0.11.21",
34-
"@winner-fed/utils": "^0.11.21",
34+
"@winner-fed/winjs": "^0.15.0",
35+
"@winner-fed/utils": "^0.15.0",
3536
"@rslib/core": "^0.1.1",
3637
"@types/node": "^22.10.1",
3738
"playwright": "^1.49.0",
3839
"simple-git-hooks": "^2.11.1",
3940
"typescript": "^5.7.2"
4041
},
42+
"dependencies": {
43+
"@winner-fed/unplugin-check-syntax": "^1.0.0"
44+
},
4145
"peerDependencies": {
4246
"@rsbuild/core": "1.x",
43-
"@winner-fed/winjs": "^0.11.21",
44-
"@winner-fed/utils": "^0.11.21"
47+
"@winner-fed/winjs": "^0.15.0",
48+
"@winner-fed/utils": "^0.15.0"
4549
},
4650
"peerDependenciesMeta": {
4751
"@rsbuild/core": {

playground/.winrc.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { defineConfig } from 'win';
22

33
export default defineConfig({
4-
plugins: ['../src'],
5-
example: {
6-
foo: 'bar',
4+
plugins: ['@winner-fed/plugin-check-syntax'], // 使用相对路径引用本地开发的插件
5+
targets: { chrome: 60, ie: 11 },
6+
jsMinifier: 'terser',
7+
// 测试 checkSyntax 默认值逻辑
8+
// checkSyntax: true,
9+
// checkSyntax: {},
10+
// 也可以测试对象配置
11+
checkSyntax: {
12+
ecmaVersion: 5, // 只配置 ecmaVersion,targets 应该使用默认值
713
},
14+
rsbuild: {},
815
});

playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@winner-fed/winjs": "*"
1515
},
1616
"devDependencies": {
17-
"typescript": "^5.0.3"
17+
"typescript": "^5.0.3",
18+
"@winner-fed/plugin-check-syntax": "workspace:*"
1819
}
1920
}

playground/plugin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ export default (api: IApi) => {
44
api.modifyHTML(($) => {
55
return $;
66
});
7+
8+
api.addHTMLHeadScripts(
9+
() => `
10+
// 可选链和空值合并 (ES2020)
11+
const config = {
12+
theme: 'dark'
13+
};
14+
const selectedTheme = config?.theme ?? 'light';
15+
`,
16+
);
717
};

playground/src/app.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// 使用 ES2015+ 语法来演示语法检查功能
2+
3+
// 箭头函数 (ES2015)
4+
const greet = (name: string) => `Hello, ${name}!`;
5+
6+
// 模板字符串 (ES2015)
7+
const message = `Welcome to syntax checking demo!`;
8+
9+
// const/let (ES2015)
10+
const numbers = [1, 2, 3, 4, 5];
11+
12+
// 解构赋值 (ES2015)
13+
const [first, ...rest] = numbers;
14+
15+
// 展开运算符 (ES2015)
16+
const moreNumbers = [...numbers, 6, 7, 8];
17+
18+
// 默认参数 (ES2015)
19+
function add(a: number, b = 0) {
20+
return a + b;
21+
}
22+
23+
// async/await (ES2017)
24+
async function fetchData() {
25+
try {
26+
const response = await fetch('/api/data');
27+
return await response.json();
28+
} catch (error) {
29+
console.error('Error fetching data:', error);
30+
}
31+
}
32+
33+
// 可选链 (ES2020)
34+
const user = {
35+
profile: {
36+
name: 'John',
37+
},
38+
};
39+
const userName = user?.profile?.name;
40+
41+
// 空值合并 (ES2020)
42+
const defaultName = userName ?? 'Anonymous';
43+
44+
// 类 (ES2015)
45+
class Calculator {
46+
private result = 0;
47+
48+
// 私有字段 (ES2022)
49+
#history: number[] = [];
50+
51+
add(value: number) {
52+
this.result += value;
53+
this.#history.push(this.result);
54+
return this;
55+
}
56+
57+
getResult() {
58+
return this.result;
59+
}
60+
}
61+
62+
// 使用示例
63+
const calc = new Calculator();
64+
calc.add(5).add(3);
65+
66+
console.log(greet('World'));
67+
console.log(message);
68+
console.log('First number:', first);
69+
console.log('Calculator result:', calc.getResult());
70+
console.log('User name:', defaultName);
71+
72+
// 导出一些内容
73+
export { greet, Calculator };
74+
export default message;

0 commit comments

Comments
 (0)