@secret-momo/toolchain-config 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -3
- package/package.json +13 -3
- package/prettier.config.d.mts +5 -0
- package/prettier.config.mjs +22 -0
- package/tsconfig/base.json +1 -0
package/README.md
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
# @secret-momo/toolchain-config
|
|
2
2
|
|
|
3
|
-
跨项目共享的 TypeScript 配置。需要 Node.js 26
|
|
3
|
+
跨项目共享的 TypeScript 和 Prettier 配置。需要 Node.js 26+,按需安装所用工具。
|
|
4
|
+
|
|
5
|
+
## Prettier 预设
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @secret-momo/toolchain-config prettier@^3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
在项目的 `package.json` 中引用预设。
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"prettier": "@secret-momo/toolchain-config/prettier.config.mjs"
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
预设使用 120 列目标行宽和多行尾逗号。JavaScript 和 TypeScript 字符串优先使用单引号,包括 JSX 表达式、Vue 的 `<script>` 以及模板绑定表达式中的字符串。JSX 字符串属性和 Vue 模板属性的外层使用双引号。
|
|
20
|
+
|
|
21
|
+
`*.md` 和 `*.markdown` 不自动折行,也不限制行宽。`*.jsonc` 禁用尾逗号。
|
|
22
|
+
|
|
23
|
+
需要调整规则时,可在项目的 `prettier.config.mjs` 或 `prettier.config.mts` 中继承预设,例如将代码行宽设为 100。
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import config from '@secret-momo/toolchain-config/prettier.config.mjs';
|
|
27
|
+
|
|
28
|
+
export default { ...config, printWidth: 100 };
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## TypeScript 预设
|
|
4
32
|
|
|
5
33
|
```bash
|
|
6
34
|
pnpm add -D @secret-momo/toolchain-config typescript@~6.0.3
|
|
@@ -12,8 +40,6 @@ pnpm add -D @secret-momo/toolchain-config typescript@~6.0.3
|
|
|
12
40
|
pnpm add -D @types/node@26
|
|
13
41
|
```
|
|
14
42
|
|
|
15
|
-
## TypeScript 预设
|
|
16
|
-
|
|
17
43
|
在 `tsconfig.json` 的 `extends` 中使用 `@secret-momo/toolchain-config/` 加下表中的入口。
|
|
18
44
|
|
|
19
45
|
| 入口 | 适用场景 |
|
|
@@ -35,6 +61,8 @@ Node、工具和打包场景统一使用 `ESNext` 的编译目标与标准库类
|
|
|
35
61
|
|
|
36
62
|
基础预设启用 `noEmitOnError`,编译报错时跳过 JavaScript 和声明文件输出。
|
|
37
63
|
|
|
64
|
+
基础预设启用 `noPropertyAccessFromIndexSignature`。仅由索引签名提供的键须用方括号访问,例如 `process.env['RUN_URL']`。类型中显式声明的属性仍可用点语法。迁移期间可在项目的 `compilerOptions` 中将该选项设为 `false`。
|
|
65
|
+
|
|
38
66
|
`node-check.json`、`node-native.json`、`bundler.json`、`node-bundler.json` 和 `tool.json` 默认只做类型检查。除通用的 `bundler.json` 外,这些入口和 `node-library.json` 都从消费项目加载 `@types/node`。
|
|
39
67
|
|
|
40
68
|
单独继承 `node.json` 时,TypeScript 6 使用包含 DOM 的默认标准库,并由项目显式设置所需的 `types`。需要一套完整的 Node 类型检查配置时,使用 `node-check.json`。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/toolchain-config",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "跨项目共享的 TypeScript 配置。",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "跨项目共享的 TypeScript 和 Prettier 配置。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"directory": "packages/toolchain-config"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
|
+
"./prettier.config.mjs": {
|
|
14
|
+
"types": "./prettier.config.d.mts",
|
|
15
|
+
"default": "./prettier.config.mjs"
|
|
16
|
+
},
|
|
13
17
|
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
14
18
|
"./tsconfig/node.json": "./tsconfig/node.json",
|
|
15
19
|
"./tsconfig/browser.json": "./tsconfig/browser.json",
|
|
@@ -24,7 +28,9 @@
|
|
|
24
28
|
"./tsconfig/declarations.json": "./tsconfig/declarations.json"
|
|
25
29
|
},
|
|
26
30
|
"files": [
|
|
27
|
-
"
|
|
31
|
+
"prettier.config.mjs",
|
|
32
|
+
"prettier.config.d.mts",
|
|
33
|
+
"tsconfig/**/*.json"
|
|
28
34
|
],
|
|
29
35
|
"engines": {
|
|
30
36
|
"node": ">=26"
|
|
@@ -34,9 +40,13 @@
|
|
|
34
40
|
"registry": "https://registry.npmjs.org/"
|
|
35
41
|
},
|
|
36
42
|
"peerDependencies": {
|
|
43
|
+
"prettier": "^3.0.0",
|
|
37
44
|
"typescript": "~6.0.3"
|
|
38
45
|
},
|
|
39
46
|
"peerDependenciesMeta": {
|
|
47
|
+
"prettier": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
40
50
|
"typescript": {
|
|
41
51
|
"optional": true
|
|
42
52
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** @type {import('prettier').Config} */
|
|
2
|
+
const config = {
|
|
3
|
+
singleQuote: true,
|
|
4
|
+
jsxSingleQuote: false,
|
|
5
|
+
trailingComma: 'all',
|
|
6
|
+
printWidth: 120,
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ['*.md', '*.markdown'],
|
|
10
|
+
options: {
|
|
11
|
+
printWidth: Number.POSITIVE_INFINITY,
|
|
12
|
+
proseWrap: 'never',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
files: '*.jsonc',
|
|
17
|
+
options: { trailingComma: 'none' },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default config;
|