@tachybase/module-cloud-component 1.6.1 → 1.6.2

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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/client.d.ts +2 -2
  3. package/client.js +1 -1
  4. package/dist/externalVersion.js +3 -3
  5. package/dist/locale/en-US.json +64 -64
  6. package/dist/locale/zh-CN.json +65 -65
  7. package/dist/node_modules/@babel/core/lib/index.js +8 -8
  8. package/dist/node_modules/@babel/core/node_modules/.bin/json5 +2 -2
  9. package/dist/node_modules/@babel/core/node_modules/.bin/json5.CMD +12 -0
  10. package/dist/node_modules/@babel/core/node_modules/.bin/json5.ps1 +41 -0
  11. package/dist/node_modules/@babel/core/node_modules/.bin/parser +2 -2
  12. package/dist/node_modules/@babel/core/node_modules/.bin/parser.CMD +12 -0
  13. package/dist/node_modules/@babel/core/node_modules/.bin/parser.ps1 +41 -0
  14. package/dist/node_modules/@babel/core/node_modules/.bin/semver +2 -2
  15. package/dist/node_modules/@babel/core/node_modules/.bin/semver.CMD +12 -0
  16. package/dist/node_modules/@babel/core/node_modules/.bin/semver.ps1 +41 -0
  17. package/dist/node_modules/@babel/core/package.json +1 -1
  18. package/dist/node_modules/@babel/parser/package.json +1 -1
  19. package/dist/node_modules/@babel/preset-env/lib/index.js +22 -22
  20. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver +2 -2
  21. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver.CMD +12 -0
  22. package/dist/node_modules/@babel/preset-env/node_modules/.bin/semver.ps1 +41 -0
  23. package/dist/node_modules/@babel/preset-env/package.json +1 -1
  24. package/dist/node_modules/@babel/preset-react/lib/index.js +10 -10
  25. package/dist/node_modules/@babel/preset-react/package.json +1 -1
  26. package/dist/node_modules/@babel/preset-typescript/lib/index.js +8 -8
  27. package/dist/node_modules/@babel/preset-typescript/package.json +1 -1
  28. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser +2 -2
  29. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser.CMD +12 -0
  30. package/dist/node_modules/@babel/traverse/node_modules/.bin/parser.ps1 +41 -0
  31. package/dist/node_modules/@babel/traverse/package.json +1 -1
  32. package/dist/node_modules/@hapi/topo/package.json +1 -1
  33. package/docs/CODE_BRANCH_PATH_LOGIC.md +140 -140
  34. package/docs/OPTIMIZATION_PLAN.md +109 -109
  35. package/docs/README.md +21 -21
  36. package/docs/REMOTE_CODE_GUIDE.md +183 -183
  37. package/docs/TESTING_AUTHENTICATION.md +128 -128
  38. package/package.json +6 -6
  39. package/server.d.ts +2 -2
  40. package/server.js +1 -1
@@ -1 +1 @@
1
- {"name":"@babel/preset-typescript","version":"7.27.1","description":"Babel preset for TypeScript.","repository":{"type":"git","url":"https://github.com/babel/babel.git","directory":"packages/babel-preset-typescript"},"license":"MIT","publishConfig":{"access":"public"},"main":"./lib/index.js","keywords":["babel-preset","typescript"],"dependencies":{"@babel/helper-plugin-utils":"^7.27.1","@babel/helper-validator-option":"^7.27.1","@babel/plugin-syntax-jsx":"^7.27.1","@babel/plugin-transform-modules-commonjs":"^7.27.1","@babel/plugin-transform-typescript":"^7.27.1"},"peerDependencies":{"@babel/core":"^7.0.0-0"},"devDependencies":{"@babel/core":"^7.27.1","@babel/helper-plugin-test-runner":"^7.27.1"},"homepage":"https://babel.dev/docs/en/next/babel-preset-typescript","bugs":"https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22area%3A%20typescript%22+is%3Aopen","engines":{"node":">=6.9.0"},"author":"The Babel Team (https://babel.dev/team)","type":"commonjs","_lastModified":"2025-12-05T07:10:29.158Z"}
1
+ {"name":"@babel/preset-typescript","version":"7.27.1","description":"Babel preset for TypeScript.","repository":{"type":"git","url":"https://github.com/babel/babel.git","directory":"packages/babel-preset-typescript"},"license":"MIT","publishConfig":{"access":"public"},"main":"./lib/index.js","keywords":["babel-preset","typescript"],"dependencies":{"@babel/helper-plugin-utils":"^7.27.1","@babel/helper-validator-option":"^7.27.1","@babel/plugin-syntax-jsx":"^7.27.1","@babel/plugin-transform-modules-commonjs":"^7.27.1","@babel/plugin-transform-typescript":"^7.27.1"},"peerDependencies":{"@babel/core":"^7.0.0-0"},"devDependencies":{"@babel/core":"^7.27.1","@babel/helper-plugin-test-runner":"^7.27.1"},"homepage":"https://babel.dev/docs/en/next/babel-preset-typescript","bugs":"https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22area%3A%20typescript%22+is%3Aopen","engines":{"node":">=6.9.0"},"author":"The Babel Team (https://babel.dev/team)","type":"commonjs","_lastModified":"2025-12-05T11:15:09.558Z"}
@@ -10,9 +10,9 @@ case `uname` in
10
10
  esac
11
11
 
12
12
  if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/bin/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/node_modules"
13
+ export NODE_PATH="/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/bin/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/node_modules"
14
14
  else
15
- export NODE_PATH="/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/bin/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules:/home/runner/work/tego-standard/tego-standard/node_modules/.pnpm/node_modules:$NODE_PATH"
15
+ export NODE_PATH="/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/bin/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/node_modules:$NODE_PATH"
16
16
  fi
17
17
  if [ -x "$basedir/node" ]; then
18
18
  exec "$basedir/node" "$basedir/../../../../../../@babel+parser@7.27.5/node_modules/@babel/parser/bin/babel-parser.js" "$@"
@@ -0,0 +1,12 @@
1
+ @SETLOCAL
2
+ @IF NOT DEFINED NODE_PATH (
3
+ @SET "NODE_PATH=D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\bin\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\node_modules"
4
+ ) ELSE (
5
+ @SET "NODE_PATH=D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\bin\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\node_modules;%NODE_PATH%"
6
+ )
7
+ @IF EXIST "%~dp0\node.exe" (
8
+ "%~dp0\node.exe" "%~dp0\..\..\..\..\..\..\@babel+parser@7.27.5\node_modules\@babel\parser\bin\babel-parser.js" %*
9
+ ) ELSE (
10
+ @SET PATHEXT=%PATHEXT:;.JS;=;%
11
+ node "%~dp0\..\..\..\..\..\..\@babel+parser@7.27.5\node_modules\@babel\parser\bin\babel-parser.js" %*
12
+ )
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env pwsh
2
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
+
4
+ $exe=""
5
+ $pathsep=":"
6
+ $env_node_path=$env:NODE_PATH
7
+ $new_node_path="D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\bin\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\parser\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules\@babel\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\@babel+parser@7.27.5\node_modules;D:\Dev\TegoJS\tego-standard\node_modules\.pnpm\node_modules"
8
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
9
+ # Fix case when both the Windows and Linux builds of Node
10
+ # are installed in the same directory
11
+ $exe=".exe"
12
+ $pathsep=";"
13
+ } else {
14
+ $new_node_path="/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/bin/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/parser/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules/@babel/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/@babel+parser@7.27.5/node_modules:/mnt/d/Dev/TegoJS/tego-standard/node_modules/.pnpm/node_modules"
15
+ }
16
+ if ([string]::IsNullOrEmpty($env_node_path)) {
17
+ $env:NODE_PATH=$new_node_path
18
+ } else {
19
+ $env:NODE_PATH="$new_node_path$pathsep$env_node_path"
20
+ }
21
+
22
+ $ret=0
23
+ if (Test-Path "$basedir/node$exe") {
24
+ # Support pipeline input
25
+ if ($MyInvocation.ExpectingInput) {
26
+ $input | & "$basedir/node$exe" "$basedir/../../../../../../@babel+parser@7.27.5/node_modules/@babel/parser/bin/babel-parser.js" $args
27
+ } else {
28
+ & "$basedir/node$exe" "$basedir/../../../../../../@babel+parser@7.27.5/node_modules/@babel/parser/bin/babel-parser.js" $args
29
+ }
30
+ $ret=$LASTEXITCODE
31
+ } else {
32
+ # Support pipeline input
33
+ if ($MyInvocation.ExpectingInput) {
34
+ $input | & "node$exe" "$basedir/../../../../../../@babel+parser@7.27.5/node_modules/@babel/parser/bin/babel-parser.js" $args
35
+ } else {
36
+ & "node$exe" "$basedir/../../../../../../@babel+parser@7.27.5/node_modules/@babel/parser/bin/babel-parser.js" $args
37
+ }
38
+ $ret=$LASTEXITCODE
39
+ }
40
+ $env:NODE_PATH=$env_node_path
41
+ exit $ret
@@ -1 +1 @@
1
- {"name":"@babel/traverse","version":"7.27.4","description":"The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes","author":"The Babel Team (https://babel.dev/team)","homepage":"https://babel.dev/docs/en/next/babel-traverse","bugs":"https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen","license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"https://github.com/babel/babel.git","directory":"packages/babel-traverse"},"main":"./lib/index.js","dependencies":{"@babel/code-frame":"^7.27.1","@babel/generator":"^7.27.3","@babel/parser":"^7.27.4","@babel/template":"^7.27.2","@babel/types":"^7.27.3","debug":"^4.3.1","globals":"^11.1.0"},"devDependencies":{"@babel/core":"^7.27.4","@babel/helper-plugin-test-runner":"^7.27.1"},"engines":{"node":">=6.9.0"},"type":"commonjs","_lastModified":"2025-12-05T07:10:34.530Z"}
1
+ {"name":"@babel/traverse","version":"7.27.4","description":"The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes","author":"The Babel Team (https://babel.dev/team)","homepage":"https://babel.dev/docs/en/next/babel-traverse","bugs":"https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen","license":"MIT","publishConfig":{"access":"public"},"repository":{"type":"git","url":"https://github.com/babel/babel.git","directory":"packages/babel-traverse"},"main":"./lib/index.js","dependencies":{"@babel/code-frame":"^7.27.1","@babel/generator":"^7.27.3","@babel/parser":"^7.27.4","@babel/template":"^7.27.2","@babel/types":"^7.27.3","debug":"^4.3.1","globals":"^11.1.0"},"devDependencies":{"@babel/core":"^7.27.4","@babel/helper-plugin-test-runner":"^7.27.1"},"engines":{"node":">=6.9.0"},"type":"commonjs","_lastModified":"2025-12-05T11:15:12.968Z"}
@@ -1 +1 @@
1
- {"name":"@hapi/topo","description":"Topological sorting with grouping support","version":"6.0.2","repository":"git://github.com/hapijs/topo","main":"lib/index.js","types":"lib/index.d.ts","files":["lib"],"keywords":["topological","sort","toposort","topsort"],"eslintConfig":{"extends":["plugin:@hapi/module"]},"dependencies":{"@hapi/hoek":"^11.0.2"},"devDependencies":{"@hapi/code":"^9.0.3","@hapi/eslint-plugin":"*","@hapi/lab":"^25.1.2","@types/node":"^17.0.31","typescript":"~4.6.4"},"scripts":{"test":"lab -a @hapi/code -t 100 -L -Y","test-cov-html":"lab -a @hapi/code -t 100 -L -r html -o coverage.html"},"license":"BSD-3-Clause","_lastModified":"2025-12-05T07:10:34.733Z"}
1
+ {"name":"@hapi/topo","description":"Topological sorting with grouping support","version":"6.0.2","repository":"git://github.com/hapijs/topo","main":"lib/index.js","types":"lib/index.d.ts","files":["lib"],"keywords":["topological","sort","toposort","topsort"],"eslintConfig":{"extends":["plugin:@hapi/module"]},"dependencies":{"@hapi/hoek":"^11.0.2"},"devDependencies":{"@hapi/code":"^9.0.3","@hapi/eslint-plugin":"*","@hapi/lab":"^25.1.2","@types/node":"^17.0.31","typescript":"~4.6.4"},"scripts":{"test":"lab -a @hapi/code -t 100 -L -Y","test-cov-html":"lab -a @hapi/code -t 100 -L -r html -o coverage.html"},"license":"BSD-3-Clause","_lastModified":"2025-12-05T11:15:13.147Z"}
@@ -1,140 +1,140 @@
1
- # codeBranch 和 codePath 获取逻辑分析
2
-
3
- ## 当前实现逻辑
4
-
5
- ### 1. 数据获取流程
6
-
7
- #### 从数据库读取 (`cloud-libraries-service.ts`)
8
- ```typescript
9
- const {
10
- codeBranch = 'main', // 默认值:'main'
11
- codePath, // 可选,可能为 undefined
12
- // ...
13
- } = lib;
14
- ```
15
-
16
- #### 传递给远程获取服务
17
- ```typescript
18
- code = await this.remoteCodeFetcher.fetchCode(
19
- codeUrl,
20
- codeType,
21
- codeBranch, // 如果未设置,使用默认值 'main'
22
- codePath // 如果未设置,为 undefined
23
- );
24
- ```
25
-
26
- ### 2. fetchFromGit 方法中的处理逻辑
27
-
28
- ```typescript
29
- private async fetchFromGit(
30
- url: string,
31
- branch: string = 'main', // 默认值:'main'
32
- path?: string // 可选参数
33
- ): Promise<string>
34
- ```
35
-
36
- #### codeBranch 的处理:
37
- - **默认值**:如果未提供,使用 `'main'`
38
- - **来源优先级**:
39
- 1. 数据库中的 `codeBranch` 字段值
40
- 2. 如果为空,使用默认值 `'main'`
41
-
42
- #### codePath 的处理:
43
- - **GitHub**:
44
- ```typescript
45
- const filePath = path || pathParts.slice(2).join('/') || 'index.tsx';
46
- ```
47
- - 优先使用传入的 `path` 参数
48
- - 如果未提供,尝试从 URL 路径中解析(`pathParts.slice(2)`)
49
- - 如果都为空,使用默认值 `'index.tsx'`
50
-
51
- - **GitLab**:
52
- ```typescript
53
- const filePath = path || pathParts.slice(2).join('/') || 'index.tsx';
54
- ```
55
- - 同样的逻辑
56
-
57
- ### 3. 问题分析
58
-
59
- #### 当前逻辑的问题:
60
-
61
- 1. **codePath 的自动解析可能不符合预期**
62
- - 如果用户没有填写 `codePath`,系统会尝试从 URL 中解析
63
- - 例如:`https://github.com/owner/repo/tree/main/src/components/Button.tsx`
64
- - 会解析出 `tree/main/src/components/Button.tsx`,这不是有效的文件路径
65
-
66
- 2. **默认值 'index.tsx' 可能不合适**
67
- - 如果用户没有提供 `codePath`,使用 `'index.tsx'` 作为默认值
68
- - 但实际项目中可能没有这个文件
69
-
70
- 3. **codeBranch 的默认值处理**
71
- - 多层默认值:数据库默认值 → 解构默认值 → 函数参数默认值
72
- - 可能导致逻辑不清晰
73
-
74
- ## 建议的改进方案
75
-
76
- ### 方案 1:明确要求 codePath(推荐)
77
-
78
- ```typescript
79
- private async fetchFromGit(
80
- url: string,
81
- branch: string = 'main',
82
- path?: string
83
- ): Promise<string> {
84
- if (!path) {
85
- throw new Error('codePath is required for Git repositories');
86
- }
87
- // ... 使用 path
88
- }
89
- ```
90
-
91
- ### 方案 2:改进自动解析逻辑
92
-
93
- ```typescript
94
- private async fetchFromGit(
95
- url: string,
96
- branch: string = 'main',
97
- path?: string
98
- ): Promise<string> {
99
- let filePath = path;
100
-
101
- // 如果未提供 path,尝试从 URL 中智能解析
102
- if (!filePath) {
103
- const urlObj = new URL(url);
104
- const pathParts = urlObj.pathname.split('/').filter(Boolean);
105
-
106
- // 移除 'tree'、'blob' 等 Git 路径标识
107
- const cleanParts = pathParts.filter(
108
- part => !['tree', 'blob'].includes(part)
109
- );
110
-
111
- // 如果 URL 中包含分支名,移除它
112
- // 然后使用剩余部分作为文件路径
113
- if (cleanParts.length > 2) {
114
- filePath = cleanParts.slice(2).join('/');
115
- }
116
- }
117
-
118
- if (!filePath) {
119
- throw new Error('codePath is required. Please specify the file path in the repository.');
120
- }
121
-
122
- // ... 使用 filePath
123
- }
124
- ```
125
-
126
- ### 方案 3:支持多种 URL 格式
127
-
128
- ```typescript
129
- // 支持以下格式:
130
- // 1. https://github.com/owner/repo (需要 codePath)
131
- // 2. https://github.com/owner/repo/blob/main/src/Component.tsx (自动解析)
132
- // 3. https://github.com/owner/repo/tree/main/src (需要 codePath 指定文件)
133
- ```
134
-
135
- ## 当前代码位置
136
-
137
- 1. **数据读取**:`packages/module-cloud-component/src/server/services/cloud-libraries-service.ts:45-46`
138
- 2. **Git 获取逻辑**:`packages/module-cloud-component/src/server/services/remote-code-fetcher.ts:65-103`
139
- 3. **字段定义**:`packages/module-cloud-component/src/server/collections/cloud-libraries.ts:41-49`
140
-
1
+ # codeBranch 和 codePath 获取逻辑分析
2
+
3
+ ## 当前实现逻辑
4
+
5
+ ### 1. 数据获取流程
6
+
7
+ #### 从数据库读取 (`cloud-libraries-service.ts`)
8
+ ```typescript
9
+ const {
10
+ codeBranch = 'main', // 默认值:'main'
11
+ codePath, // 可选,可能为 undefined
12
+ // ...
13
+ } = lib;
14
+ ```
15
+
16
+ #### 传递给远程获取服务
17
+ ```typescript
18
+ code = await this.remoteCodeFetcher.fetchCode(
19
+ codeUrl,
20
+ codeType,
21
+ codeBranch, // 如果未设置,使用默认值 'main'
22
+ codePath // 如果未设置,为 undefined
23
+ );
24
+ ```
25
+
26
+ ### 2. fetchFromGit 方法中的处理逻辑
27
+
28
+ ```typescript
29
+ private async fetchFromGit(
30
+ url: string,
31
+ branch: string = 'main', // 默认值:'main'
32
+ path?: string // 可选参数
33
+ ): Promise<string>
34
+ ```
35
+
36
+ #### codeBranch 的处理:
37
+ - **默认值**:如果未提供,使用 `'main'`
38
+ - **来源优先级**:
39
+ 1. 数据库中的 `codeBranch` 字段值
40
+ 2. 如果为空,使用默认值 `'main'`
41
+
42
+ #### codePath 的处理:
43
+ - **GitHub**:
44
+ ```typescript
45
+ const filePath = path || pathParts.slice(2).join('/') || 'index.tsx';
46
+ ```
47
+ - 优先使用传入的 `path` 参数
48
+ - 如果未提供,尝试从 URL 路径中解析(`pathParts.slice(2)`)
49
+ - 如果都为空,使用默认值 `'index.tsx'`
50
+
51
+ - **GitLab**:
52
+ ```typescript
53
+ const filePath = path || pathParts.slice(2).join('/') || 'index.tsx';
54
+ ```
55
+ - 同样的逻辑
56
+
57
+ ### 3. 问题分析
58
+
59
+ #### 当前逻辑的问题:
60
+
61
+ 1. **codePath 的自动解析可能不符合预期**
62
+ - 如果用户没有填写 `codePath`,系统会尝试从 URL 中解析
63
+ - 例如:`https://github.com/owner/repo/tree/main/src/components/Button.tsx`
64
+ - 会解析出 `tree/main/src/components/Button.tsx`,这不是有效的文件路径
65
+
66
+ 2. **默认值 'index.tsx' 可能不合适**
67
+ - 如果用户没有提供 `codePath`,使用 `'index.tsx'` 作为默认值
68
+ - 但实际项目中可能没有这个文件
69
+
70
+ 3. **codeBranch 的默认值处理**
71
+ - 多层默认值:数据库默认值 → 解构默认值 → 函数参数默认值
72
+ - 可能导致逻辑不清晰
73
+
74
+ ## 建议的改进方案
75
+
76
+ ### 方案 1:明确要求 codePath(推荐)
77
+
78
+ ```typescript
79
+ private async fetchFromGit(
80
+ url: string,
81
+ branch: string = 'main',
82
+ path?: string
83
+ ): Promise<string> {
84
+ if (!path) {
85
+ throw new Error('codePath is required for Git repositories');
86
+ }
87
+ // ... 使用 path
88
+ }
89
+ ```
90
+
91
+ ### 方案 2:改进自动解析逻辑
92
+
93
+ ```typescript
94
+ private async fetchFromGit(
95
+ url: string,
96
+ branch: string = 'main',
97
+ path?: string
98
+ ): Promise<string> {
99
+ let filePath = path;
100
+
101
+ // 如果未提供 path,尝试从 URL 中智能解析
102
+ if (!filePath) {
103
+ const urlObj = new URL(url);
104
+ const pathParts = urlObj.pathname.split('/').filter(Boolean);
105
+
106
+ // 移除 'tree'、'blob' 等 Git 路径标识
107
+ const cleanParts = pathParts.filter(
108
+ part => !['tree', 'blob'].includes(part)
109
+ );
110
+
111
+ // 如果 URL 中包含分支名,移除它
112
+ // 然后使用剩余部分作为文件路径
113
+ if (cleanParts.length > 2) {
114
+ filePath = cleanParts.slice(2).join('/');
115
+ }
116
+ }
117
+
118
+ if (!filePath) {
119
+ throw new Error('codePath is required. Please specify the file path in the repository.');
120
+ }
121
+
122
+ // ... 使用 filePath
123
+ }
124
+ ```
125
+
126
+ ### 方案 3:支持多种 URL 格式
127
+
128
+ ```typescript
129
+ // 支持以下格式:
130
+ // 1. https://github.com/owner/repo (需要 codePath)
131
+ // 2. https://github.com/owner/repo/blob/main/src/Component.tsx (自动解析)
132
+ // 3. https://github.com/owner/repo/tree/main/src (需要 codePath 指定文件)
133
+ ```
134
+
135
+ ## 当前代码位置
136
+
137
+ 1. **数据读取**:`packages/module-cloud-component/src/server/services/cloud-libraries-service.ts:45-46`
138
+ 2. **Git 获取逻辑**:`packages/module-cloud-component/src/server/services/remote-code-fetcher.ts:65-103`
139
+ 3. **字段定义**:`packages/module-cloud-component/src/server/collections/cloud-libraries.ts:41-49`
140
+
@@ -1,109 +1,109 @@
1
- # 云组件插件优化计划 / Cloud Component Plugin Optimization Plan
2
-
3
- ## 高优先级任务(立即处理) / High Priority Tasks (Immediate)
4
-
5
- ### 1. 修复资源泄漏问题 / Fix Resource Leak Issues ✅
6
- - [x] 修复 Preview 组件中 Blob URL 未清理的问题 / Fix Blob URL not cleaned up in Preview component
7
- - [x] 修复客户端库加载时 Promise 未加入 waitlist 的问题 / Fix Promise not added to waitlist when loading client libraries
8
- - [x] 添加组件卸载时的资源清理逻辑 / Add resource cleanup logic on component unmount
9
-
10
- ### 2. 统一错误处理机制 / Unified Error Handling ✅
11
- - [x] 服务端:将所有 console.error 替换为 logger / Server: Replace all console.error with logger
12
- - [x] 客户端:实现统一的错误上报机制(改进错误处理,开发环境输出) / Client: Implement unified error reporting mechanism (improved error handling, dev environment output)
13
- - [x] 改进编译错误信息展示(包含行号、列号) / Improve compilation error display (including line and column numbers)
14
- - [x] 在编辑器中高亮错误位置 / Highlight error locations in editor
15
-
16
- ### 3. 增强 VM 沙箱安全性 / Enhance VM Sandbox Security ✅
17
- - [x] 限制沙箱可用 API(移除危险全局对象) / Restrict sandbox available APIs (remove dangerous global objects)
18
- - [x] 添加执行时间监控(虽然无法真正中断,但可以监控) / Add execution time monitoring (cannot truly interrupt, but can monitor)
19
- - [x] 添加资源限制(通过限制 API 实现) / Add resource limits (implemented by restricting APIs)
20
- - [x] 改进错误处理和日志记录 / Improve error handling and logging
21
-
22
- ### 4. 修复客户端插件加载问题 / Fix Client Plugin Loading Issues ✅
23
- - [x] 将客户端插件加载 Promise 加入 waitlist / Add client plugin loading Promise to waitlist
24
- - [x] 添加错误处理和重试机制 / Add error handling and retry mechanism
25
-
26
- ## 中优先级任务(近期处理) / Medium Priority Tasks (Near-term)
27
-
28
- ### 5. 编译性能优化 / Compilation Performance Optimization ✅
29
- - [x] 为编译添加防抖(800ms) / Add debounce for compilation (800ms)
30
- - [x] 实现编译结果缓存 / Implement compilation result caching
31
- - [ ] 大文件使用 Web Worker 编译(可选,待实现) / Use Web Worker for large file compilation (optional, pending)
32
-
33
- ### 6. 模块映射配置化 / Module Mapping Configuration ✅
34
- - [x] 创建模块映射配置表或配置文件 / Create module mapping configuration table or config file
35
- - [x] 重构 contextRequire 使用配置化映射 / Refactor contextRequire to use configured mapping
36
- - [ ] 提供模块映射管理界面(可选,低优先级) / Provide module mapping management UI (optional, low priority)
37
-
38
- ### 7. 类型安全改进 / Type Safety Improvements ✅
39
- - [x] 定义云组件接口类型 / Define cloud component interface types
40
- - [x] 定义编译结果类型 / Define compilation result types
41
- - [x] 减少 any 类型使用 / Reduce any type usage
42
-
43
- ### 8. 版本管理功能实现 / Version Management Feature Implementation
44
- - [ ] 实现版本历史查看功能 / Implement version history viewing
45
- - [ ] 实现版本回滚功能 / Implement version rollback
46
- - [ ] 实现版本对比功能 / Implement version comparison
47
- - [ ] 添加语义化版本号支持 / Add semantic versioning support
48
-
49
- ## 低优先级任务(长期规划) / Low Priority Tasks (Long-term Planning)
50
-
51
- ### 9. 代码混淆支持 / Code Obfuscation Support
52
- - [ ] 集成代码混淆工具(terser) / Integrate code obfuscation tool (terser)
53
- - [ ] 提供混淆配置选项 / Provide obfuscation configuration options
54
- - [ ] 生产环境自动启用混淆 / Automatically enable obfuscation in production
55
-
56
- ### 10. 监控与调试工具 / Monitoring and Debugging Tools
57
- - [ ] 添加编译性能监控 / Add compilation performance monitoring
58
- - [ ] 添加组件加载时间统计 / Add component loading time statistics
59
- - [ ] 添加错误上报和统计 / Add error reporting and statistics
60
- - [ ] 提供调试模式(保留源码映射) / Provide debug mode (preserve source maps)
61
-
62
- ### 11. 用户体验增强 / User Experience Enhancements
63
- - [ ] 显示编译进度和耗时 / Display compilation progress and duration
64
- - [ ] 提供编译历史记录 / Provide compilation history
65
- - [ ] 支持组件属性配置预览 / Support component property configuration preview
66
- - [ ] 支持模拟数据预览 / Support mock data preview
67
- - [ ] 支持响应式预览 / Support responsive preview
68
-
69
- ---
70
-
71
- ## 实施顺序 / Implementation Order
72
-
73
- 1. **第一阶段 / Phase 1**:高优先级任务(1-4) / High priority tasks (1-4) ✅
74
- 2. **第二阶段 / Phase 2**:中优先级任务(5-8) / Medium priority tasks (5-8) ✅
75
- 3. **第三阶段 / Phase 3**:低优先级任务(9-11) / Low priority tasks (9-11)
76
-
77
- 每个任务完成后,在对应的复选框前打勾 ✅ / Check the checkbox when each task is completed ✅
78
-
79
- ---
80
-
81
- ## 完成状态总结 / Completion Status Summary
82
-
83
- ### 已完成 / Completed ✅
84
- - **高优先级任务 / High Priority**: 4/4 (100%)
85
- - **中优先级任务 / Medium Priority**: 3/4 (75%)
86
- - **总计 / Total**: 7/8 (87.5%)
87
-
88
- ### 待完成 / Pending
89
- - 版本管理功能实现 / Version management feature implementation
90
- - 低优先级任务 / Low priority tasks (9-11)
91
-
92
- ---
93
-
94
- ## 优化成果 / Optimization Results
95
-
96
- ### 性能提升 / Performance Improvements
97
- - ✅ 编译防抖和缓存机制,减少重复编译 / Compilation debounce and caching, reducing redundant compilation
98
- - ✅ 资源泄漏修复,提升内存使用效率 / Resource leak fixes, improved memory efficiency
99
-
100
- ### 安全性增强 / Security Enhancements
101
- - ✅ VM 沙箱 API 限制,防止危险操作 / VM sandbox API restrictions, preventing dangerous operations
102
- - ✅ 执行时间监控,及时发现性能问题 / Execution time monitoring, timely detection of performance issues
103
-
104
- ### 代码质量 / Code Quality
105
- - ✅ 类型安全改进,减少运行时错误 / Type safety improvements, reducing runtime errors
106
- - ✅ 模块映射配置化,提高可维护性 / Module mapping configuration, improving maintainability
107
- - ✅ 统一错误处理,提升调试体验 / Unified error handling, better debugging experience
108
- - ✅ 国际化支持,多语言友好 / Internationalization support, multi-language friendly
109
-
1
+ # 云组件插件优化计划 / Cloud Component Plugin Optimization Plan
2
+
3
+ ## 高优先级任务(立即处理) / High Priority Tasks (Immediate)
4
+
5
+ ### 1. 修复资源泄漏问题 / Fix Resource Leak Issues ✅
6
+ - [x] 修复 Preview 组件中 Blob URL 未清理的问题 / Fix Blob URL not cleaned up in Preview component
7
+ - [x] 修复客户端库加载时 Promise 未加入 waitlist 的问题 / Fix Promise not added to waitlist when loading client libraries
8
+ - [x] 添加组件卸载时的资源清理逻辑 / Add resource cleanup logic on component unmount
9
+
10
+ ### 2. 统一错误处理机制 / Unified Error Handling ✅
11
+ - [x] 服务端:将所有 console.error 替换为 logger / Server: Replace all console.error with logger
12
+ - [x] 客户端:实现统一的错误上报机制(改进错误处理,开发环境输出) / Client: Implement unified error reporting mechanism (improved error handling, dev environment output)
13
+ - [x] 改进编译错误信息展示(包含行号、列号) / Improve compilation error display (including line and column numbers)
14
+ - [x] 在编辑器中高亮错误位置 / Highlight error locations in editor
15
+
16
+ ### 3. 增强 VM 沙箱安全性 / Enhance VM Sandbox Security ✅
17
+ - [x] 限制沙箱可用 API(移除危险全局对象) / Restrict sandbox available APIs (remove dangerous global objects)
18
+ - [x] 添加执行时间监控(虽然无法真正中断,但可以监控) / Add execution time monitoring (cannot truly interrupt, but can monitor)
19
+ - [x] 添加资源限制(通过限制 API 实现) / Add resource limits (implemented by restricting APIs)
20
+ - [x] 改进错误处理和日志记录 / Improve error handling and logging
21
+
22
+ ### 4. 修复客户端插件加载问题 / Fix Client Plugin Loading Issues ✅
23
+ - [x] 将客户端插件加载 Promise 加入 waitlist / Add client plugin loading Promise to waitlist
24
+ - [x] 添加错误处理和重试机制 / Add error handling and retry mechanism
25
+
26
+ ## 中优先级任务(近期处理) / Medium Priority Tasks (Near-term)
27
+
28
+ ### 5. 编译性能优化 / Compilation Performance Optimization ✅
29
+ - [x] 为编译添加防抖(800ms) / Add debounce for compilation (800ms)
30
+ - [x] 实现编译结果缓存 / Implement compilation result caching
31
+ - [ ] 大文件使用 Web Worker 编译(可选,待实现) / Use Web Worker for large file compilation (optional, pending)
32
+
33
+ ### 6. 模块映射配置化 / Module Mapping Configuration ✅
34
+ - [x] 创建模块映射配置表或配置文件 / Create module mapping configuration table or config file
35
+ - [x] 重构 contextRequire 使用配置化映射 / Refactor contextRequire to use configured mapping
36
+ - [ ] 提供模块映射管理界面(可选,低优先级) / Provide module mapping management UI (optional, low priority)
37
+
38
+ ### 7. 类型安全改进 / Type Safety Improvements ✅
39
+ - [x] 定义云组件接口类型 / Define cloud component interface types
40
+ - [x] 定义编译结果类型 / Define compilation result types
41
+ - [x] 减少 any 类型使用 / Reduce any type usage
42
+
43
+ ### 8. 版本管理功能实现 / Version Management Feature Implementation
44
+ - [ ] 实现版本历史查看功能 / Implement version history viewing
45
+ - [ ] 实现版本回滚功能 / Implement version rollback
46
+ - [ ] 实现版本对比功能 / Implement version comparison
47
+ - [ ] 添加语义化版本号支持 / Add semantic versioning support
48
+
49
+ ## 低优先级任务(长期规划) / Low Priority Tasks (Long-term Planning)
50
+
51
+ ### 9. 代码混淆支持 / Code Obfuscation Support
52
+ - [ ] 集成代码混淆工具(terser) / Integrate code obfuscation tool (terser)
53
+ - [ ] 提供混淆配置选项 / Provide obfuscation configuration options
54
+ - [ ] 生产环境自动启用混淆 / Automatically enable obfuscation in production
55
+
56
+ ### 10. 监控与调试工具 / Monitoring and Debugging Tools
57
+ - [ ] 添加编译性能监控 / Add compilation performance monitoring
58
+ - [ ] 添加组件加载时间统计 / Add component loading time statistics
59
+ - [ ] 添加错误上报和统计 / Add error reporting and statistics
60
+ - [ ] 提供调试模式(保留源码映射) / Provide debug mode (preserve source maps)
61
+
62
+ ### 11. 用户体验增强 / User Experience Enhancements
63
+ - [ ] 显示编译进度和耗时 / Display compilation progress and duration
64
+ - [ ] 提供编译历史记录 / Provide compilation history
65
+ - [ ] 支持组件属性配置预览 / Support component property configuration preview
66
+ - [ ] 支持模拟数据预览 / Support mock data preview
67
+ - [ ] 支持响应式预览 / Support responsive preview
68
+
69
+ ---
70
+
71
+ ## 实施顺序 / Implementation Order
72
+
73
+ 1. **第一阶段 / Phase 1**:高优先级任务(1-4) / High priority tasks (1-4) ✅
74
+ 2. **第二阶段 / Phase 2**:中优先级任务(5-8) / Medium priority tasks (5-8) ✅
75
+ 3. **第三阶段 / Phase 3**:低优先级任务(9-11) / Low priority tasks (9-11)
76
+
77
+ 每个任务完成后,在对应的复选框前打勾 ✅ / Check the checkbox when each task is completed ✅
78
+
79
+ ---
80
+
81
+ ## 完成状态总结 / Completion Status Summary
82
+
83
+ ### 已完成 / Completed ✅
84
+ - **高优先级任务 / High Priority**: 4/4 (100%)
85
+ - **中优先级任务 / Medium Priority**: 3/4 (75%)
86
+ - **总计 / Total**: 7/8 (87.5%)
87
+
88
+ ### 待完成 / Pending
89
+ - 版本管理功能实现 / Version management feature implementation
90
+ - 低优先级任务 / Low priority tasks (9-11)
91
+
92
+ ---
93
+
94
+ ## 优化成果 / Optimization Results
95
+
96
+ ### 性能提升 / Performance Improvements
97
+ - ✅ 编译防抖和缓存机制,减少重复编译 / Compilation debounce and caching, reducing redundant compilation
98
+ - ✅ 资源泄漏修复,提升内存使用效率 / Resource leak fixes, improved memory efficiency
99
+
100
+ ### 安全性增强 / Security Enhancements
101
+ - ✅ VM 沙箱 API 限制,防止危险操作 / VM sandbox API restrictions, preventing dangerous operations
102
+ - ✅ 执行时间监控,及时发现性能问题 / Execution time monitoring, timely detection of performance issues
103
+
104
+ ### 代码质量 / Code Quality
105
+ - ✅ 类型安全改进,减少运行时错误 / Type safety improvements, reducing runtime errors
106
+ - ✅ 模块映射配置化,提高可维护性 / Module mapping configuration, improving maintainability
107
+ - ✅ 统一错误处理,提升调试体验 / Unified error handling, better debugging experience
108
+ - ✅ 国际化支持,多语言友好 / Internationalization support, multi-language friendly
109
+