用途
tsconfigs 技能用于在 RedisInsight 项目中定位和修改 TypeScript 配置。当需要添加路径别名、引入新的 TypeScript 区域,或调试 webpack / ts-node / ESLint 的路径解析问题时可以使用。
配置布局
RedisInsight 没有根 tsconfig.json,配置按区域拆分,每个区域拥有自己的 paths、includes 和使用方。ESLint 使用 parserOptions.project: true 为每个被 lint 的文件自动发现最近的 tsconfig。
各配置文件及其负责范围与消费者:
- redisinsight/ui/tsconfig.json:负责 UI 源码、uiSrc/*、apiClient 路径;消费者为 Vite(UI 构建)、ESLint 的 UI override、npm run type-check:ui。
- redisinsight/api/tsconfig.json:负责 API 源码、src/、tests/ 路径;消费者为 NestJS 构建、ESLint 的 API override。
- redisinsight/api/tsconfig.check.json:与基础配置相同,另加 strict: true(其中 strictPropertyInitialization 和 useUnknownInCatchVariables 关闭)和 noEmit: true;仅由 npm run type-check:api 使用,单独拆分以避免 strict 模式破坏 nest build。可参考 type-check-baselines 技能。
- redisinsight/desktop/tsconfig.json:负责 Desktop 源码,配置 desktopSrc/、apiSrc/、uiSrc/、apiClient、apiClient/ 路径,供 TypeScript / IDE intellisense 使用;消费者为针对 desktop 文件的 ESLint、TS 语言服务器。
- configs/tsconfig.json:包含供 ts-node 加载 .ts webpack 配置使用的编译选项(module: CommonJS、esModuleInterop);消费者为通过 build:main / build:main:stage / build:stage 中设置的 TS_NODE_PROJECT 调用的 ts-node。
- .storybook/tsconfig.json:负责 Storybook 框架文件,继承 UI tsconfig;消费者为 Storybook 与 ESLint。
- stories/tsconfig.json:负责 Story 文件,继承 UI tsconfig,并将 uiSrc/* 重写为从 redisinsight/ui 解析;消费者为 Storybook 与 ESLint。
- tests/e2e-playwright/tsconfig.json:负责 Playwright 端到端测试套件;消费者为 E2E runner(一个拥有自己 package.json 的子项目,在根目录被 ESLint 忽略)。
Webpack 路径解析
Webpack 使用显式的 resolve.alias 条目(而非 tsconfig-paths-webpack-plugin),示例配置如下:
alias: {
desktopSrc: webpackPaths.desktopSrcPath,
apiSrc: resolve(webpackPaths.apiPath, 'src'),
uiSrc: webpackPaths.uiSrcPath,
apiClient: resolve(webpackPaths.riPath, 'api-client'),
// ...
}
如果新增了 desktop 代码使用的路径别名,需要同时在两处添加:redisinsight/desktop/tsconfig.json(供 TypeScript / ESLint / IDE 使用)和 configs/webpack.config.base.ts 的 resolve.alias(供 electron 打包使用)。
ts-node 与 webpack 的 TS 配置
configs/ 中的 webpack 配置是带类型注解的 .ts 文件。当运行 webpack --config ./configs/*.ts 时,由 ts-node 编译它们。有三个 package.json 脚本设置了 TS_NODE_PROJECT=./configs/tsconfig.json,以使 ts-node 使用正确的编译选项:
- build:main
- build:main:stage
- build:stage
configs/tsconfig.json 有意不设置 allowJs。scripts/ 或 configs/ 内的任何 .js 文件都必须是 CommonJS(require / module.exports)——Node 22 的模块语法检测会把使用 ESM 语法的 .js 文件当作 ESM,从而破坏对 __dirname 的引用。基于这一原因已转换的两个脚本为:scripts/prebuild.js、scripts/DeleteSourceMaps.js。
ESLint
.eslintrc.js 的规则:
- 根级 parserOptions.project: true——为每个文件自动发现最近的 tsconfig。
- API override:parserOptions.project 显式设置为 redisinsight/api/tsconfig.json。
- UI override:parserOptions.project 显式设置为 redisinsight/ui/tsconfig.json。
- .storybook/、.github/ 等目录下的文件不会被 eslint . 检查,因为 ESLint 在展开目录时会跳过点号前缀的路径。
- 如果新增了一个 ESLint 会触及的顶层 TS 文件夹,需要在该文件夹中放置一个 tsconfig,否则 parserOptions.project: true 会找不到配置文件而报错。
常见任务
添加 desktop / electron 使用的路径别名
- 将该别名添加到 redisinsight/desktop/tsconfig.json 的 compilerOptions.paths。
- 如果该别名也被 UI 代码使用,添加到 redisinsight/ui/tsconfig.json。
- 如果该别名也被 API 代码使用,添加到 redisinsight/api/tsconfig.json。
- 对于 electron 包使用的别名(任何从 redisinsight/desktop/** 导入的内容),还需将该别名镜像到 configs/webpack.config.base.ts 的 resolve.alias。Vite 会自动从 redisinsight/ui/tsconfig.json 解析 UI 别名。
添加新的顶层 TS 文件夹
在其中创建 tsconfig.json,最小内容如下:
{
"extends": "../redisinsight/ui/tsconfig.json",
"include": ["**/*"]
}
如果没有该文件,ESLint 的 parserOptions.project: true 会在这些文件上报错。
在 configs/ 下添加新的 .ts webpack 配置
无需额外操作——configs/tsconfig.json 已包含 **/*。
添加无需 ts-node 即可运行的 Node 脚本
放在 scripts/ 下,使用 CommonJS(require/module.exports)。不要使用 ESM 语法——configs/tsconfig.json 不再设置 allowJs,Node 22 会把使用 ESM 语法的 .js 文件作为 ESM 加载(没有 __dirname)。
限制
以上内容均基于项目配置说明,关于该技能的收费、价格、平台、效果或其他未在资料中提及的功能,暂未提供。