优化 vue 模板#5
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the plugin project discovery logic into a centralized discoverPluginProject module, supporting multiple layouts (src-ztools, root, and public), and updates the publish and pull workflows to use it. It also updates the Vue-Vite template's TypeScript configuration to use project references. The review feedback suggests adding defensive checks when parsing plugin.json to prevent runtime errors if the JSON is not an object, and removing trailing commas in tsconfig.node.json to ensure compatibility with strict JSON parsers.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function readPluginConfig(pluginJsonPath: string): PluginConfig { | ||
| try { | ||
| const content = fs.readFileSync(pluginJsonPath, 'utf-8') | ||
| return JSON.parse(content) as PluginConfig | ||
| } catch (error) { | ||
| throw new Error(`读取 plugin.json 失败: ${(error as Error).message}`) | ||
| } | ||
| } |
There was a problem hiding this comment.
在解析 plugin.json 时,JSON.parse 可能会返回 null、数组或非对象类型(例如,如果文件内容是 null 或非对象字符串)。建议在返回前添加防御性检查,确保解析后的内容是一个非空的键值对对象,以避免后续属性访问时抛出运行时错误。
function readPluginConfig(pluginJsonPath: string): PluginConfig {
try {
const content = fs.readFileSync(pluginJsonPath, 'utf-8')
const config = JSON.parse(content)
if (!config || typeof config !== 'object' || Array.isArray(config)) {
throw new Error('内容不是一个有效的 JSON 对象')
}
return config as PluginConfig
} catch (error) {
throw new Error(`读取 plugin.json 失败: ${(error as Error).message}`)
}
}| { | ||
| "extends": "@tsconfig/node22/tsconfig.json", | ||
| "include": [ | ||
| "vite.config.*", | ||
| "vitest.config.*", | ||
| "cypress.config.*", | ||
| "nightwatch.conf.*", | ||
| "playwright.config.*", | ||
| "eslint.config.*", | ||
| "uno.config.ts", | ||
| ], | ||
| "compilerOptions": { | ||
| "noEmit": true, | ||
| "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | ||
|
|
||
| "module": "ESNext", | ||
| "moduleResolution": "Bundler", | ||
| "types": ["node", "@ztools-center/ztools-api-types"], | ||
| } | ||
| } |
There was a problem hiding this comment.
在 tsconfig.node.json 中存在尾随逗号(如第 10 行和第 18 行)。虽然 TypeScript 编译器和部分现代工具支持带有尾随逗号的 JSON(JSONC),但标准的 JSON 规范并不允许尾随逗号。为了确保与所有第三方工具、IDE 以及严格的 JSON 解析器的最大兼容性,建议移除这些尾随逗号。
| { | |
| "extends": "@tsconfig/node22/tsconfig.json", | |
| "include": [ | |
| "vite.config.*", | |
| "vitest.config.*", | |
| "cypress.config.*", | |
| "nightwatch.conf.*", | |
| "playwright.config.*", | |
| "eslint.config.*", | |
| "uno.config.ts", | |
| ], | |
| "compilerOptions": { | |
| "noEmit": true, | |
| "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | |
| "module": "ESNext", | |
| "moduleResolution": "Bundler", | |
| "types": ["node", "@ztools-center/ztools-api-types"], | |
| } | |
| } | |
| { | |
| "extends": "@tsconfig/node22/tsconfig.json", | |
| "include": [ | |
| "vite.config.*", | |
| "vitest.config.*", | |
| "cypress.config.*", | |
| "nightwatch.conf.*", | |
| "playwright.config.*", | |
| "eslint.config.*", | |
| "uno.config.ts" | |
| ], | |
| "compilerOptions": { | |
| "noEmit": true, | |
| "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | |
| "module": "ESNext", | |
| "moduleResolution": "Bundler", | |
| "types": ["node", "@ztools-center/ztools-api-types"] | |
| } | |
| } |
No description provided.