Skip to content

Commit 348af4a

Browse files
committed
✨ new features
1 parent 7f2f9df commit 348af4a

18 files changed

+1854
-471
lines changed

eslint.config.mjs

+22-23
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@ import globals from "globals";
22
import pluginJs from "@eslint/js";
33
import tseslint from "typescript-eslint";
44

5-
65
export default [
7-
{files: ["**/*.{js,mjs,cjs,ts}"]},
8-
{ignores: ["dist/*"]},
9-
{languageOptions: {globals: {...globals.browser, ...globals.node}}},
10-
pluginJs.configs.recommended,
11-
12-
{
13-
rules: {
14-
// 警告未使用的变量,但忽略以 "_" 开头的变量
15-
"no-unused-vars": ["warn", {"varsIgnorePattern": "^_", "argsIgnorePattern": "^_"}],
16-
// 如果有超过 1 行的连续空行则报错
17-
"no-multiple-empty-lines": ["error", {"max": 1}],
18-
// 如果行尾有空格则报错
19-
"no-trailing-spaces": "error",
20-
// 强制在语句末尾使用分号
21-
"semi": ["error", "always"],
22-
// 强制使用双引号
23-
"quotes": ["error", "double"],
24-
// 禁止在对象和数组的最后一个元素后面使用逗号
25-
"comma-dangle": ["error", "never"]
26-
}
27-
},
28-
...tseslint.configs.recommended
6+
{files: ["**/*.{js,mjs,cjs,ts}"]},
7+
{ignores: ["dist/*"]},
8+
{languageOptions: {globals: {...globals.browser, ...globals.node}}},
9+
pluginJs.configs.recommended,
10+
...tseslint.configs.recommended,
11+
{
12+
rules: {
13+
// 警告未使用的变量,但忽略以 "_" 开头的变量
14+
"no-unused-vars": ["warn", {"varsIgnorePattern": "^_", "argsIgnorePattern": "^_"}],
15+
// 如果有超过 1 行的连续空行则报错
16+
"no-multiple-empty-lines": ["error", {"max": 1}],
17+
// 如果行尾有空格则报错
18+
"no-trailing-spaces": "error",
19+
// 强制在语句末尾使用分号
20+
"semi": ["error", "always"],
21+
// 强制使用双引号
22+
"quotes": ["error", "double"],
23+
// 禁止在对象和数组的最后一个元素后面使用逗号
24+
"comma-dangle": ["error", "never"],
25+
"@typescript-eslint/no-explicit-any": "off"
26+
}
27+
}
2928
];

generateIndex.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# 指定源目录和目标 index.ts 文件的路径
4+
SRC_DIR="./src"
5+
INDEX_PATH="$SRC_DIR/index.ts"
6+
7+
# 清空 index.ts 文件
8+
echo "" > "$INDEX_PATH"
9+
10+
# 获取所有 TypeScript 文件并生成 export 语句
11+
find "$SRC_DIR" -type f -name "*.ts" ! -name "index.ts" | while read -r file; do
12+
# 生成相对路径
13+
relative_path="${file#./src/}" # 去掉前缀 ./src/
14+
# 去掉文件扩展名
15+
file_name=$(basename "$file" .ts)
16+
# 写入 export 语句
17+
echo "export { default as $file_name } from \"./${relative_path%.ts}\";" >> "$INDEX_PATH"
18+
done
19+
20+
echo "Generated $INDEX_PATH"

jest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* https://jestjs.io/docs/configuration
44
*/
55

6-
import type {Config} from 'jest';
6+
import type {Config} from "jest";
77

88
const config: Config = {
99
// All imported modules in your tests should be mocked automatically
@@ -146,7 +146,7 @@ const config: Config = {
146146
// snapshotSerializers: [],
147147

148148
// 用于测试的测试环境
149-
testEnvironment: "jsdom",
149+
testEnvironment: "jsdom"
150150

151151
// 将传递给testEnvironment的选项
152152
// testEnvironmentOptions: {},

package.json

+35-9
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,53 @@
22
"name": "js_utils",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "./dist/cjs/index.cjs",
6+
"module": "./dist/esm/index.mjs",
7+
"types": "./dist/types/index.d.ts",
8+
"exports": {
9+
".": {
10+
"types": "./dist/types/index.d.ts",
11+
"import": "./dist/esm/index.mjs",
12+
"require": "./dist/cjs/index.cjs",
13+
"default": "./dist/cjs/index.cjs"
14+
}
15+
},
16+
"files": [
17+
"dist"
18+
],
619
"scripts": {
7-
"build": "tsc",
20+
"build": "bash generateIndex.sh && rollup -c",
821
"lint:fix": "eslint --fix",
922
"test": "jest",
1023
"preversion": "npm run lint:fix && npm run build && npm run test"
1124
},
12-
"keywords": [],
13-
"author": "",
14-
"license": "ISC",
25+
"keywords": [
26+
"javascript",
27+
"utils"
28+
],
29+
"author": "coderlzw",
30+
"license": "MIT",
1531
"devDependencies": {
16-
"@eslint/js": "^9.9.1",
32+
"@eslint/js": "^9.12.0",
1733
"@types/jest": "^29.5.12",
1834
"@types/node": "^22.5.0",
19-
"eslint": "^9.9.1",
20-
"globals": "^15.9.0",
35+
"eslint": "^9.12.0",
36+
"globals": "^15.10.0",
2137
"jest": "^29.7.0",
2238
"jest-environment-jsdom": "^29.7.0",
39+
"rollup": "^4.24.0",
40+
"rollup-plugin-delete": "^2.1.0",
41+
"rollup-plugin-terser": "^7.0.2",
42+
"rollup-plugin-typescript2": "^0.36.0",
2343
"ts-jest": "^29.2.5",
2444
"ts-node": "^10.9.2",
45+
"tslib": "^2.7.0",
2546
"typescript": "^5.5.4",
26-
"typescript-eslint": "^8.3.0"
47+
"typescript-eslint": "^8.8.0",
48+
"vite": "^5.4.8"
49+
},
50+
"packageManager": "[email protected]+sha256.a61b67ff6cc97af864564f4442556c22a04f2e5a7714fbee76a1011361d9b726",
51+
"engines": {
52+
"node": ">=16.13.0"
2753
}
2854
}

0 commit comments

Comments
 (0)