@secret-momo/toolchain-config 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +83 -2
- package/package.json +41 -3
- package/tsconfig/base.json +11 -0
- package/tsconfig/browser.json +8 -0
- package/tsconfig/bundler.json +9 -0
- package/tsconfig/declarations.json +8 -0
- package/tsconfig/internal/esnext.json +6 -0
- package/tsconfig/internal/node-runtime.json +8 -0
- package/tsconfig/node-bundler.json +3 -0
- package/tsconfig/node-check.json +3 -0
- package/tsconfig/node-library.json +7 -0
- package/tsconfig/node-native.json +7 -0
- package/tsconfig/node.json +7 -0
- package/tsconfig/react.json +6 -0
- package/tsconfig/tool.json +6 -0
- package/tsconfig/typecheck.json +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 secretmomo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @secret-momo/toolchain-config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
跨项目共享的 TypeScript 配置。需要 Node.js 26+ 和 TypeScript `~6.0.3`。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add -D @secret-momo/toolchain-config typescript@~6.0.3
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
使用自动加载 Node 环境类型的预设时,再安装与目标 Node.js 主版本对应的类型。以 Node.js 26 为例。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add -D @types/node@26
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## TypeScript 预设
|
|
16
|
+
|
|
17
|
+
在 `tsconfig.json` 的 `extends` 中使用 `@secret-momo/toolchain-config/` 加下表中的入口。
|
|
18
|
+
|
|
19
|
+
| 入口 | 适用场景 |
|
|
20
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------- |
|
|
21
|
+
| `tsconfig/base.json` | 只复用通用严格检查和模块语法规则 |
|
|
22
|
+
| `tsconfig/node.json` | 只复用 NodeNext 模块与解析规则,自行配置 `lib`、`types` 和输出策略 |
|
|
23
|
+
| `tsconfig/node-check.json` | 仅检查 NodeNext 项目,加载 Node 环境类型 |
|
|
24
|
+
| `tsconfig/browser.json` | 使用 Bundler 模块解析的浏览器项目,提供 DOM 类型 |
|
|
25
|
+
| `tsconfig/react.json` | 使用 `react-jsx` 的浏览器项目 |
|
|
26
|
+
| `tsconfig/node-library.json` | 检查索引访问和成员覆盖,用 `tsc` 构建 NodeNext 库并输出 JavaScript 和类型声明 |
|
|
27
|
+
| `tsconfig/node-native.json` | 由 Node.js 直接运行 TypeScript,允许 `.ts` 扩展名导入并检查语法可擦除性 |
|
|
28
|
+
| `tsconfig/bundler.json` | 由打包器或其他工具处理输出,使用 Preserve/Bundler 并允许 `.ts` 扩展名导入 |
|
|
29
|
+
| `tsconfig/node-bundler.json` | 为 Node.js 项目提供 Preserve/Bundler 类型检查,加载 Node 环境类型并检查索引访问和成员覆盖 |
|
|
30
|
+
| `tsconfig/tool.json` | 检查 Node.js 运行的工具配置和脚本,允许 `.ts` 扩展名导入,只接受可擦除的 TypeScript 语法 |
|
|
31
|
+
| `tsconfig/typecheck.json` | 叠加在项目预设之后,只做类型检查 |
|
|
32
|
+
| `tsconfig/declarations.json` | 叠加在项目预设之后,只生成类型声明 |
|
|
33
|
+
|
|
34
|
+
Node、工具和打包场景统一使用 `ESNext` 的编译目标与标准库类型,浏览器和 React 预设额外加载 DOM 类型。`ESNext` 随项目使用的 TypeScript 版本更新。
|
|
35
|
+
|
|
36
|
+
基础预设启用 `noEmitOnError`,编译报错时跳过 JavaScript 和声明文件输出。
|
|
37
|
+
|
|
38
|
+
`node-check.json`、`node-native.json`、`bundler.json`、`node-bundler.json` 和 `tool.json` 默认只做类型检查。除通用的 `bundler.json` 外,这些入口和 `node-library.json` 都从消费项目加载 `@types/node`。
|
|
39
|
+
|
|
40
|
+
单独继承 `node.json` 时,TypeScript 6 使用包含 DOM 的默认标准库,并由项目显式设置所需的 `types`。需要一套完整的 Node 类型检查配置时,使用 `node-check.json`。
|
|
41
|
+
|
|
42
|
+
## 使用示例
|
|
43
|
+
|
|
44
|
+
下面的 NodeNext 库示例用于 ESM。使用普通 `.ts` 文件编写 `import` 和 `export` 时,在消费项目的 `package.json` 中设置 `"type": "module"`。单个 ESM 文件也可以用 `.mts` 扩展名。项目的 `tsconfig.json` 负责指定源码范围和输出目录。
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"extends": "@secret-momo/toolchain-config/tsconfig/node-library.json",
|
|
49
|
+
"compilerOptions": {
|
|
50
|
+
"rootDir": "src",
|
|
51
|
+
"outDir": "dist"
|
|
52
|
+
},
|
|
53
|
+
"include": ["src"]
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
用打包器构建 Node 库时,可继承 `node-bundler.json` 进行类型检查。由 `tsc` 生成声明时,在构建配置中把 `declarations.json` 放在最后。
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"extends": ["@secret-momo/toolchain-config/tsconfig/node-bundler.json", "@secret-momo/toolchain-config/tsconfig/declarations.json"],
|
|
62
|
+
"compilerOptions": {
|
|
63
|
+
"rootDir": "src",
|
|
64
|
+
"outDir": ".cache/declarations"
|
|
65
|
+
},
|
|
66
|
+
"include": ["src"],
|
|
67
|
+
"exclude": ["src/**/*.test.ts"]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Bundler 解析允许省略相对导入的扩展名,生成的 `.d.ts` 可能保留这些导入。发布前用 NodeNext 消费项目检查最终声明。可在源码中使用带 `.js` 扩展名的相对导入,或用 `rollup-plugin-dts` 等工具合并声明并检查合并后的入口。
|
|
72
|
+
|
|
73
|
+
工具配置可以直接继承 `tool.json`,并通过 `include` 指定文件范围。
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"extends": "@secret-momo/toolchain-config/tsconfig/tool.json",
|
|
78
|
+
"include": ["*.config.mts", "scripts/**/*.ts"]
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
单独使用 `browser.json` 或 `react.json` 时,`tsc` 默认会输出文件,且没有模块标记的普通 `.ts` 文件可能共享全局作用域。使用 Vite 等打包器并希望 `tsc` 只检查类型、把每个文件视为模块时,先继承 `bundler.json`,再继承 `browser.json` 或 `react.json`。
|
|
83
|
+
|
|
84
|
+
在 monorepo 中,可以由仓库根目录的配置为各场景选用预设,再让子包继承相应的根文件。在消费项目中设置 `include`、`exclude`、`paths` 和预设之外的环境类型。React 项目需安装 `react` 和 `@types/react`,Vite 项目可按需在 `types` 中加入 `vite/client`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/toolchain-config",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "跨项目共享的 TypeScript 配置。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/secretmomo/npm-packages.git",
|
|
10
|
+
"directory": "packages/toolchain-config"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
14
|
+
"./tsconfig/node.json": "./tsconfig/node.json",
|
|
15
|
+
"./tsconfig/browser.json": "./tsconfig/browser.json",
|
|
16
|
+
"./tsconfig/react.json": "./tsconfig/react.json",
|
|
17
|
+
"./tsconfig/node-check.json": "./tsconfig/node-check.json",
|
|
18
|
+
"./tsconfig/node-library.json": "./tsconfig/node-library.json",
|
|
19
|
+
"./tsconfig/node-native.json": "./tsconfig/node-native.json",
|
|
20
|
+
"./tsconfig/bundler.json": "./tsconfig/bundler.json",
|
|
21
|
+
"./tsconfig/node-bundler.json": "./tsconfig/node-bundler.json",
|
|
22
|
+
"./tsconfig/tool.json": "./tsconfig/tool.json",
|
|
23
|
+
"./tsconfig/typecheck.json": "./tsconfig/typecheck.json",
|
|
24
|
+
"./tsconfig/declarations.json": "./tsconfig/declarations.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"tsconfig"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=26"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"typescript": "~6.0.3"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"typescript": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
6
44
|
}
|