zcw-shared 1.29.0 → 1.31.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.
Files changed (182) hide show
  1. package/README.md +87 -55
  2. package/dist/functions/platform/tencent-cloud/deploy.tcb.d.ts +13 -0
  3. package/dist/functions/platform/tencent-cloud/deploy.tcb.js +46 -0
  4. package/dist/functions/platform/tencent-cloud/deploy.tcb.js.map +1 -0
  5. package/dist/functions/platform/tencent-cloud/getSecret.d.ts +4 -0
  6. package/dist/functions/platform/tencent-cloud/getSecret.js +19 -0
  7. package/dist/functions/platform/tencent-cloud/getSecret.js.map +1 -0
  8. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.d.ts +27 -0
  9. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js +287 -0
  10. package/dist/functions/platform/uniapp/app-plus/buildAndroidApp.js.map +1 -0
  11. package/dist/functions/platform/uniapp/build.d.ts +21 -0
  12. package/dist/functions/platform/uniapp/build.js +83 -0
  13. package/dist/functions/platform/uniapp/build.js.map +1 -0
  14. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.d.ts +11 -0
  15. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js +30 -0
  16. package/dist/functions/platform/uniapp/detectAndroidProjectStructure.js.map +1 -0
  17. package/dist/functions/platform/uniapp/detectProjectType.d.ts +20 -0
  18. package/dist/functions/platform/uniapp/detectProjectType.js +68 -0
  19. package/dist/functions/platform/uniapp/detectProjectType.js.map +1 -0
  20. package/dist/functions/platform/uniapp/parseManifest.d.ts +18 -0
  21. package/dist/functions/platform/uniapp/parseManifest.js +49 -0
  22. package/dist/functions/platform/uniapp/parseManifest.js.map +1 -0
  23. package/dist/functions/platform/uniapp/waitForPages.d.ts +7 -0
  24. package/dist/functions/platform/uniapp/waitForPages.js +20 -0
  25. package/dist/functions/platform/uniapp/waitForPages.js.map +1 -0
  26. package/dist/functions/string/visualizeRegexSteps.d.ts +39 -0
  27. package/dist/functions/string/visualizeRegexSteps.js +446 -0
  28. package/dist/functions/string/visualizeRegexSteps.js.map +1 -0
  29. package/dist/functions/utils/createI18n.d.ts +2 -0
  30. package/dist/functions/utils/createI18n.js +97 -0
  31. package/dist/functions/utils/createI18n.js.map +1 -0
  32. package/dist/functions/utils/formatString.d.ts +5 -0
  33. package/dist/functions/utils/formatString.js +9 -0
  34. package/dist/functions/utils/formatString.js.map +1 -0
  35. package/dist/functions/vue/dynamicMount.d.ts +6 -4
  36. package/dist/functions/vue/isVNode.d.ts +1 -1
  37. package/dist/functions/vue/isVueComponent.d.ts +1 -1
  38. package/dist/hooks/usePermission.d.ts +7 -0
  39. package/dist/hooks/usePermission.js +123 -0
  40. package/dist/hooks/usePermission.js.map +1 -0
  41. package/dist/vue-hooks/browser/useBattery.d.ts +1 -1
  42. package/dist/vue-hooks/browser/useBluetooth.d.ts +1 -1
  43. package/dist/vue-hooks/browser/useCamera.d.ts +1 -1
  44. package/dist/vue-hooks/browser/useClipboard.d.ts +1 -1
  45. package/dist/vue-hooks/browser/useFileUpload.d.ts +3 -2
  46. package/dist/vue-hooks/browser/useFileUpload.js +12 -1
  47. package/dist/vue-hooks/browser/useFileUpload.js.map +1 -1
  48. package/dist/vue-hooks/browser/useFullscreen.d.ts +1 -1
  49. package/dist/vue-hooks/browser/useGamepad.d.ts +1 -1
  50. package/dist/vue-hooks/browser/useGeolocation.d.ts +1 -1
  51. package/dist/vue-hooks/browser/useMediaSession.d.ts +1 -1
  52. package/dist/vue-hooks/browser/useMicrophone.d.ts +1 -1
  53. package/dist/vue-hooks/browser/useNetwork.d.ts +1 -1
  54. package/dist/vue-hooks/browser/useOrientation.d.ts +1 -1
  55. package/dist/vue-hooks/browser/usePageVisibility.d.ts +1 -1
  56. package/dist/vue-hooks/browser/useScreenOrientation.d.ts +1 -1
  57. package/dist/vue-hooks/browser/useScreenWakeLock.d.ts +1 -1
  58. package/dist/vue-hooks/browser/useShare.d.ts +1 -1
  59. package/dist/vue-hooks/browser/useVibration.d.ts +1 -1
  60. package/dist/vue-hooks/dom/useAutoUpdate.d.ts +1 -1
  61. package/dist/vue-hooks/dom/useClickOutside.d.ts +1 -1
  62. package/dist/vue-hooks/dom/useDraggable.d.ts +4 -4
  63. package/dist/vue-hooks/dom/useEventListener.d.ts +1 -1
  64. package/dist/vue-hooks/dom/useKeyboard.d.ts +29 -0
  65. package/dist/vue-hooks/dom/useKeyboard.js +129 -0
  66. package/dist/vue-hooks/dom/useKeyboard.js.map +1 -0
  67. package/dist/vue-hooks/dom/useResizable.d.ts +8 -3
  68. package/dist/vue-hooks/history/useDebouncedRefHistory.d.ts +1 -1
  69. package/dist/vue-hooks/history/useManualRefHistory.d.ts +1 -1
  70. package/dist/vue-hooks/history/useRefHistory.d.ts +1 -1
  71. package/dist/vue-hooks/state/injectLocal.d.ts +1 -1
  72. package/dist/vue-hooks/state/provideLocal.d.ts +1 -1
  73. package/dist/vue-hooks/state/useAsyncState.d.ts +1 -1
  74. package/dist/vue-hooks/state/useCounter.d.ts +1 -1
  75. package/dist/vue-hooks/state/useFileUpload.d.ts +23 -0
  76. package/dist/vue-hooks/state/useFileUpload.js +93 -0
  77. package/dist/vue-hooks/state/useFileUpload.js.map +1 -0
  78. package/dist/vue-hooks/state/useToggle.d.ts +1 -1
  79. package/dist/vue-hooks/time/useInterval.d.ts +1 -1
  80. package/dist/vue-hooks/time/useTimeout.d.ts +1 -1
  81. package/dist/vue-hooks/worker/useWebWorker.d.ts +4 -4
  82. package/dist/vue-hooks/worker/useWorkerFunction.d.ts +4 -4
  83. package/dist/vue-hooks/worker/useWorkerPool.d.ts +4 -4
  84. package/package.json +1 -1
  85. package/types/vue.d.ts +1 -1
  86. package/dist/functions/algorithm/lcsVisual.d.ts +0 -6
  87. package/dist/functions/algorithm/lcsVisual.js +0 -88
  88. package/dist/functions/algorithm/lcsVisual.js.map +0 -1
  89. package/dist/functions/algorithm/mergeSortVisual.d.ts +0 -5
  90. package/dist/functions/algorithm/mergeSortVisual.js +0 -103
  91. package/dist/functions/algorithm/mergeSortVisual.js.map +0 -1
  92. package/dist/functions/algorithm/nQueensVisual.d.ts +0 -14
  93. package/dist/functions/algorithm/nQueensVisual.js +0 -94
  94. package/dist/functions/algorithm/nQueensVisual.js.map +0 -1
  95. package/dist/functions/algorithm/numIslandsVisual.d.ts +0 -17
  96. package/dist/functions/algorithm/numIslandsVisual.js +0 -102
  97. package/dist/functions/algorithm/numIslandsVisual.js.map +0 -1
  98. package/dist/functions/algorithm/quickSortVisual.d.ts +0 -18
  99. package/dist/functions/algorithm/quickSortVisual.js +0 -104
  100. package/dist/functions/algorithm/quickSortVisual.js.map +0 -1
  101. package/dist/functions/browser/detectDevice.d.ts +0 -10
  102. package/dist/functions/browser/detectDevice.js +0 -49
  103. package/dist/functions/browser/detectDevice.js.map +0 -1
  104. package/dist/functions/cookie/getCookie.d.ts +0 -5
  105. package/dist/functions/cookie/getCookie.js +0 -14
  106. package/dist/functions/cookie/getCookie.js.map +0 -1
  107. package/dist/functions/cookie/removeCookie.d.ts +0 -8
  108. package/dist/functions/cookie/removeCookie.js +0 -12
  109. package/dist/functions/cookie/removeCookie.js.map +0 -1
  110. package/dist/functions/cookie/setCookie.d.ts +0 -11
  111. package/dist/functions/cookie/setCookie.js +0 -23
  112. package/dist/functions/cookie/setCookie.js.map +0 -1
  113. package/dist/functions/data-structures/EventEmitter.d.ts +0 -32
  114. package/dist/functions/data-structures/EventEmitter.js +0 -108
  115. package/dist/functions/data-structures/EventEmitter.js.map +0 -1
  116. package/dist/functions/data-structures/MyPromise.d.ts +0 -32
  117. package/dist/functions/data-structures/MyPromise.js +0 -254
  118. package/dist/functions/data-structures/MyPromise.js.map +0 -1
  119. package/dist/functions/reactive/useReactiveCookie.d.ts +0 -19
  120. package/dist/functions/reactive/useReactiveCookie.js +0 -84
  121. package/dist/functions/reactive/useReactiveCookie.js.map +0 -1
  122. package/dist/hooks/useClickOutside.d.ts +0 -12
  123. package/dist/hooks/useClickOutside.js +0 -16
  124. package/dist/hooks/useClickOutside.js.map +0 -1
  125. package/dist/hooks/useClipboard.d.ts +0 -20
  126. package/dist/hooks/useClipboard.js +0 -33
  127. package/dist/hooks/useClipboard.js.map +0 -1
  128. package/dist/hooks/useCounter.d.ts +0 -19
  129. package/dist/hooks/useCounter.js +0 -44
  130. package/dist/hooks/useCounter.js.map +0 -1
  131. package/dist/hooks/useEventListener.d.ts +0 -14
  132. package/dist/hooks/useEventListener.js +0 -18
  133. package/dist/hooks/useEventListener.js.map +0 -1
  134. package/dist/hooks/useInterval.d.ts +0 -19
  135. package/dist/hooks/useInterval.js +0 -33
  136. package/dist/hooks/useInterval.js.map +0 -1
  137. package/dist/hooks/useTimeout.d.ts +0 -20
  138. package/dist/hooks/useTimeout.js +0 -40
  139. package/dist/hooks/useTimeout.js.map +0 -1
  140. package/dist/hooks/useToggle.d.ts +0 -15
  141. package/dist/hooks/useToggle.js +0 -23
  142. package/dist/hooks/useToggle.js.map +0 -1
  143. package/dist/reactive/createGlobalState.d.ts +0 -2
  144. package/dist/reactive/createGlobalState.js +0 -11
  145. package/dist/reactive/createGlobalState.js.map +0 -1
  146. package/dist/reactive/createSharedComposable.d.ts +0 -2
  147. package/dist/reactive/createSharedComposable.js +0 -13
  148. package/dist/reactive/createSharedComposable.js.map +0 -1
  149. package/dist/reactive/errorManager.d.ts +0 -63
  150. package/dist/reactive/errorManager.js +0 -199
  151. package/dist/reactive/errorManager.js.map +0 -1
  152. package/dist/reactive/i18n.d.ts +0 -27
  153. package/dist/reactive/i18n.js +0 -119
  154. package/dist/reactive/i18n.js.map +0 -1
  155. package/dist/reactive/permission.d.ts +0 -40
  156. package/dist/reactive/permission.js +0 -189
  157. package/dist/reactive/permission.js.map +0 -1
  158. package/dist/reactive/pinia.d.ts +0 -52
  159. package/dist/reactive/pinia.js +0 -183
  160. package/dist/reactive/pinia.js.map +0 -1
  161. package/dist/reactive/useAltool.d.ts +0 -39
  162. package/dist/reactive/useAltool.js +0 -350
  163. package/dist/reactive/useAltool.js.map +0 -1
  164. package/dist/reactive/useCache.d.ts +0 -18
  165. package/dist/reactive/useCache.js +0 -82
  166. package/dist/reactive/useCache.js.map +0 -1
  167. package/dist/reactive/useLocalStorage.d.ts +0 -8
  168. package/dist/reactive/useLocalStorage.js +0 -101
  169. package/dist/reactive/useLocalStorage.js.map +0 -1
  170. package/dist/reactive/usePluginSystem.d.ts +0 -11
  171. package/dist/reactive/usePluginSystem.js +0 -34
  172. package/dist/reactive/usePluginSystem.js.map +0 -1
  173. package/dist/reactive/useSessionStorage.d.ts +0 -8
  174. package/dist/reactive/useSessionStorage.js +0 -101
  175. package/dist/reactive/useSessionStorage.js.map +0 -1
  176. package/dist/reactive/useStorage.d.ts +0 -13
  177. package/dist/reactive/useStorage.js +0 -62
  178. package/dist/reactive/useStorage.js.map +0 -1
  179. package/dist/reactive/useStorageWithIndexedDB.d.ts +0 -8
  180. package/dist/reactive/useStorageWithIndexedDB.js +0 -132
  181. package/dist/reactive/useStorageWithIndexedDB.js.map +0 -1
  182. package/references/vue.d.ts +0 -242
package/README.md CHANGED
@@ -71,11 +71,16 @@ playground/ # 测试和验证环境
71
71
  #### 规则 1:不直接导入第三方库
72
72
 
73
73
  ```typescript
74
- // ❌ 错误:直接导入 Vue
74
+ // ❌ 错误:直接导入 Vue 运行时函数
75
75
  import { ref, watch } from 'vue'
76
76
 
77
- // ✅ 正确:从 references 导入类型
77
+ // ✅ 正确:只能使用 import type 导入 Vue 类型
78
+ import type { Ref } from 'vue'
79
+
80
+ // ❌ 错误:不能从 references 导入 Vue 类型
78
81
  import type { Ref } from '../../references/vue.d'
82
+
83
+ // 注意:Vue 类型只能从 'vue' 包直接导入,因为 Vue 的类型系统过于复杂,难以在 references 中完整定义
79
84
  ```
80
85
 
81
86
  #### 规则 2:只传入实际使用的函数,不传入整个模块
@@ -121,7 +126,7 @@ export function myFunction(deps: MyFunctionDeps) {
121
126
  }
122
127
  ```
123
128
 
124
- #### 规则 4:类型定义在 references 中,使用 typeof 或索引访问提取
129
+ #### 规则 4:类型定义在 references 中,使用 typeof 或索引访问提取(Vue 类型除外)
125
130
 
126
131
  ```typescript
127
132
  // ❌ 错误:在函数中定义类型
@@ -139,6 +144,24 @@ export interface MyFunctionDeps {
139
144
  }
140
145
  ```
141
146
 
147
+ **Vue 类型特殊规则:**
148
+
149
+ Vue 的类型系统过于复杂,难以在 `references/` 中完整定义,因此 Vue 类型只能从 `'vue'` 包直接导入:
150
+
151
+ ```typescript
152
+ // ✅ 正确:Vue 类型只能从 'vue' 包直接导入
153
+ import type { Ref, Component, VNode } from 'vue'
154
+
155
+ export interface MyFunctionDeps {
156
+ ref: <T>(value: T) => Ref<T>
157
+ component: Component
158
+ node: VNode
159
+ }
160
+
161
+ // ❌ 错误:不能从 references 导入 Vue 类型
162
+ import type { Ref } from '../../references/vue.d' // Vue 没有 references 文件
163
+ ```
164
+
142
165
  #### 规则 5:每个函数维护自己完整的依赖,不要分散
143
166
 
144
167
  ```typescript
@@ -169,9 +192,13 @@ export function myFunction(path: string, deps: MyFunctionDeps) {
169
192
 
170
193
  不仅是 Node.js 和浏览器 API,第三方 SDK 对象(Vue、微信、UniApp 等)也要遵循同样的规则。
171
194
 
195
+ **Vue 特殊说明:**
196
+ - Vue 类型只能通过 `import type {} from 'vue'` 导入,不能从 `references/` 导入
197
+ - Vue 运行时函数仍然需要通过依赖注入传入,不能直接导入
198
+
172
199
  ```typescript
173
200
  // ❌ 错误:传入整个 Vue 运行时
174
- import type { VueRuntime } from '../../references/vue.d'
201
+ import type { VueRuntime } from 'vue'
175
202
 
176
203
  export interface DynamicMountOptions {
177
204
  vue: VueRuntime // 包含很多未使用的方法
@@ -182,8 +209,8 @@ export function dynamicMount(options: DynamicMountOptions) {
182
209
  options.vue.render(...)
183
210
  }
184
211
 
185
- // ✅ 正确:只传入使用的函数
186
- import type { VueRuntime } from '../../references/vue.d'
212
+ // ✅ 正确:只传入使用的函数,类型从 'vue' 导入
213
+ import type { VueRuntime } from 'vue'
187
214
 
188
215
  export interface DynamicMountDeps {
189
216
  createVNode: VueRuntime['createVNode']
@@ -279,6 +306,11 @@ export async function buildProject(
279
306
 
280
307
  **references/** 目录定义环境API的抽象类型(接口、类型别名等),所有基础类型都应在此定义:
281
308
 
309
+ **注意:Vue 类型例外**
310
+ - Vue 的类型系统过于复杂,难以在 `references/` 中完整定义
311
+ - Vue 类型只能从 `'vue'` 包直接导入,使用 `import type {} from 'vue'`
312
+ - Vue 运行时函数仍然需要通过依赖注入传入,不能直接导入
313
+
282
314
  ```typescript
283
315
  // references/node.d.ts
284
316
  export interface FileSystem {
@@ -314,13 +346,6 @@ export interface Document {
314
346
  head: HTMLElement
315
347
  }
316
348
 
317
- // references/vue.d.ts
318
- export interface Ref<T = any> {
319
- value: T
320
- }
321
-
322
- export type InjectionKey<T> = symbol
323
-
324
349
  // references/timer.d.ts
325
350
  export declare const setTimeout: (callback: (...args: any[]) => void, ms?: number, ...args: any[]) => any
326
351
  export declare const clearTimeout: (timeoutId: any) => void
@@ -372,9 +397,9 @@ const result = await buildProject(options, {
372
397
 
373
398
  // 浏览器 Vue 环境
374
399
  import { ref, shallowRef, watch } from 'vue'
375
- import { useAsyncState } from 'shared/hooks/useAsyncState'
400
+ import { useAsyncState } from 'shared/vue-hooks/state/useAsyncState'
376
401
 
377
- // 传入 Vue 运行时函数和浏览器 API
402
+ // 传入 Vue 运行时函数和浏览器 API(注意:运行时函数通过依赖注入传入,类型通过 import type 导入)
378
403
  const { state, isLoading } = useAsyncState(
379
404
  async () => fetch('/api/data').then(r => r.json()),
380
405
  {
@@ -382,7 +407,7 @@ const { state, isLoading } = useAsyncState(
382
407
  delay: 1000
383
408
  },
384
409
  {
385
- vue: { ref, shallowRef, watch }, // Vue Composition API 函数
410
+ vue: { ref, shallowRef, watch }, // Vue Composition API 运行时函数
386
411
  host: { setTimeout } // 浏览器定时器
387
412
  }
388
413
  )
@@ -703,19 +728,15 @@ export function newFunction(
703
728
  **Vue Hooks 开发模板:**
704
729
 
705
730
  ```typescript
706
- // src/hooks/useNewHook.ts
707
- import type { Ref } from '../../references/vue.d'
731
+ // src/vue-hooks/useNewHook.ts
732
+ // Vue 类型只能从 'vue' 直接导入
733
+ import type { Ref } from 'vue'
708
734
  import type { setTimeout } from '../../references/timer.d'
709
-
710
- export interface VueCompositionAPI {
711
- ref: <T>(value: T) => Ref<T>
712
- watch: (source: any, callback: () => void, options?: any) => void
713
- onMounted: (fn: () => void) => void
714
- onUnmounted: (fn: () => void) => void
715
- }
735
+ import type { VueCompositionAPI } from '../../types/vue.d'
716
736
 
717
737
  export interface NewHookEnvironment {
718
- vue: VueCompositionAPI
738
+ /** Vue Composition API 运行时函数(通过依赖注入传入) */
739
+ vue: Pick<Required<VueCompositionAPI>, 'ref' | 'watch' | 'onMounted' | 'onUnmounted'>
719
740
  host: {
720
741
  setTimeout: typeof setTimeout
721
742
  clearTimeout: typeof clearTimeout
@@ -750,13 +771,15 @@ export function useNewHook<T>(
750
771
  在提交代码前,请确保:
751
772
 
752
773
  #### ✅ 依赖注入检查
753
- - [ ] 没有直接 `import` 第三方库(如 `vue`、`react`)
774
+ - [ ] 没有直接 `import` 第三方库的运行时函数(如 `import { ref } from 'vue'`)
775
+ - [ ] Vue 类型只能使用 `import type {} from 'vue'` 导入,不能从 `references/` 导入
754
776
  - [ ] 没有直接使用全局对象(`window`、`document`、`global`、`process`)
755
777
  - [ ] 所有环境依赖都通过 `deps` 或 `env` 参数传入
756
778
  - [ ] 使用 `deps.` 前缀访问依赖,没有解构
757
779
 
758
780
  #### ✅ 类型定义检查
759
- - [ ] 类型从 `references/` 导入,使用 `import type`
781
+ - [ ] 类型从 `references/` 导入,使用 `import type`(Vue 类型除外)
782
+ - [ ] Vue 类型只能从 `'vue'` 包直接导入,使用 `import type {} from 'vue'`
760
783
  - [ ] 依赖接口命名为 `{FunctionName}Deps` 或 `{HookName}Environment`
761
784
  - [ ] 使用 `Interface['method']` 或 `typeof` 提取类型
762
785
  - [ ] 每个依赖都有清晰的 JSDoc 注释
@@ -816,10 +839,11 @@ npm run publish:major # 主要版本
816
839
 
817
840
  ### 依赖管理
818
841
 
819
- 1. **不导入第三方库**:不直接 `import { ref } from 'vue'`,而是通过 `env` 对象传入
820
- 2. **不依赖全局对象**:不直接使用 `window`、`document`、`global`
821
- 3. **接口命名规范**:`{FunctionName}Deps`,例如 `BuildProjectDeps`、`ModifyManifestDeps`
822
- 4. **使用 deps. 前缀**:所有依赖访问都使用 `deps.methodName()`,不解构
842
+ 1. **不导入第三方库运行时函数**:不直接 `import { ref } from 'vue'`,而是通过 `env` 对象传入
843
+ 2. **Vue 类型特殊规则**:Vue 类型只能使用 `import type {} from 'vue'` 导入,不能从 `references/` 导入
844
+ 3. **不依赖全局对象**:不直接使用 `window`、`document`、`global`
845
+ 4. **接口命名规范**:`{FunctionName}Deps`,例如 `BuildProjectDeps`、`ModifyManifestDeps`
846
+ 5. **使用 deps. 前缀**:所有依赖访问都使用 `deps.methodName()`,不解构
823
847
 
824
848
  ### 测试要求
825
849
 
@@ -833,12 +857,13 @@ npm run publish:major # 主要版本
833
857
  在编写新函数或修改现有函数时,快速检查以下要点:
834
858
 
835
859
  **✅ 6大核心规则:**
836
- 1. ❌ 不直接导入第三方库 → ✅ 从 `references/` 导入类型
837
- 2. ❌ 不传入整个模块对象 → ✅ 只传入实际使用的函数
838
- 3. ❌ 不解构 deps 对象 → ✅ 使用 `deps.` 前缀访问
839
- 4. ❌ 不重复定义类型 → ✅ 使用 `Interface['method']` 提取
840
- 5. ❌ 不分散依赖到多个参数 → ✅ 统一的 `Deps` 接口
841
- 6. ❌ 第三方 SDK 也不能整个传入 → ✅ Vue、Wx 等也要拆分
860
+ 1. ❌ 不直接导入第三方库运行时函数 → ✅ 从 `references/` 导入类型(Vue 类型除外)
861
+ 2. ❌ Vue 类型不能从 `references/` 导入 → ✅ 只能使用 `import type {} from 'vue'`
862
+ 3. ❌ 不传入整个模块对象 → ✅ 只传入实际使用的函数
863
+ 4. ❌ 不解构 deps 对象 → ✅ 使用 `deps.` 前缀访问
864
+ 5. ❌ 不重复定义类型 → ✅ 使用 `Interface['method']` 提取
865
+ 6. ❌ 不分散依赖到多个参数 → ✅ 统一的 `Deps` 接口
866
+ 7. ❌ 第三方 SDK 也不能整个传入 → ✅ Vue、Wx 等也要拆分
842
867
 
843
868
  **✅ 命名规范:**
844
869
  - 函数依赖接口:`{FunctionName}Deps`
@@ -853,23 +878,28 @@ npm run publish:major # 主要版本
853
878
 
854
879
  ### 常见错误和解决方案
855
880
 
856
- #### ❌ 错误 1:直接导入第三方库
881
+ #### ❌ 错误 1:直接导入第三方库运行时函数
857
882
  ```typescript
858
- import { ref, watch } from 'vue' // ❌ 错误
883
+ import { ref, watch } from 'vue' // ❌ 错误:导入了运行时函数
859
884
  ```
860
885
  **解决方案:**
861
886
  ```typescript
862
- import type { Ref } from '../../references/vue.d' // ✅ 正确
887
+ // 正确:Vue 类型只能从 'vue' 直接导入
888
+ import type { Ref } from 'vue'
889
+ import type { VueCompositionAPI } from '../../types/vue.d'
863
890
 
864
- export interface VueCompositionAPI {
865
- ref: <T>(value: T) => Ref<T>
866
- watch: (source: any, callback: () => void) => void
891
+ export interface UseMyHookEnvironment {
892
+ vue: Pick<Required<VueCompositionAPI>, 'ref' | 'watch'>
867
893
  }
868
894
 
869
- export function useMyHook(env: { vue: VueCompositionAPI }) {
870
- const state = env.vue.ref(0)
895
+ export function useMyHook(env: UseMyHookEnvironment) {
896
+ const state = env.vue.ref(0) // 运行时函数通过依赖注入传入
871
897
  env.vue.watch(state, () => {})
872
898
  }
899
+
900
+ // 使用时:
901
+ // import { ref, watch } from 'vue'
902
+ // const result = useMyHook({ vue: { ref, watch } })
873
903
  ```
874
904
 
875
905
  #### ❌ 错误 2:传入整个模块对象
@@ -942,7 +972,8 @@ export function myFunction(deps: MyFunctionDeps) {
942
972
 
943
973
  #### ❌ 错误 6:传入整个第三方 SDK 对象
944
974
  ```typescript
945
- import type { VueRuntime } from '../../references/vue.d'
975
+ // 错误:Vue 类型可以从 'vue' 导入,但不能传入整个运行时对象
976
+ import type { VueRuntime } from 'vue'
946
977
  import type { Wx } from '../../references/wechat.d'
947
978
 
948
979
  export interface MyFunctionDeps {
@@ -957,11 +988,12 @@ export function myFunction(deps: MyFunctionDeps) {
957
988
  ```
958
989
  **解决方案:**
959
990
  ```typescript
960
- import type { VueRuntime } from '../../references/vue.d'
991
+ // 正确:Vue 类型从 'vue' 导入,运行时函数通过依赖注入传入
992
+ import type { VueRuntime } from 'vue'
961
993
  import type { Wx } from '../../references/wechat.d'
962
994
 
963
995
  export interface MyFunctionDeps {
964
- createVNode: VueRuntime['createVNode'] // ✅ 正确
996
+ createVNode: VueRuntime['createVNode'] // ✅ 正确:只传入使用的函数
965
997
  downloadFile: Wx['downloadFile'] // ✅ 正确
966
998
  USER_DATA_PATH: Wx['env']['USER_DATA_PATH'] // ✅ 嵌套属性也要精确提取
967
999
  }
@@ -974,12 +1006,12 @@ export function myFunction(deps: MyFunctionDeps) {
974
1006
  ```
975
1007
 
976
1008
  **常见第三方 SDK 对象拆分:**
977
- - `VueRuntime` → 只传入 `createVNode`, `render` 等实际使用的方法
978
- - `Wx` (微信) → 只传入 `downloadFile`, `request` 等实际使用的方法
979
- - `UniApp` → 只传入 `getCurrentPages` 等实际使用的方法
980
- - `CryptoJS` → 只传入 `MD5`, `SHA256` 等实际使用的方法
981
- - `CloudBaseManager` → 只传入 `init` 等实际使用的方法
982
- - `Sharp` (图像处理) → 已经是函数,直接作为依赖
1009
+ - `VueRuntime` → 只传入 `createVNode`, `render` 等实际使用的方法(类型用 `import type {} from 'vue'` 导入)
1010
+ - `Wx` (微信) → 只传入 `downloadFile`, `request` 等实际使用的方法(类型从 `references/wechat.d` 导入)
1011
+ - `UniApp` → 只传入 `getCurrentPages` 等实际使用的方法(类型从 `references/uniapp.d` 导入)
1012
+ - `CryptoJS` → 只传入 `MD5`, `SHA256` 等实际使用的方法(类型从 `references/crypto-js.d` 导入)
1013
+ - `CloudBaseManager` → 只传入 `init` 等实际使用的方法(类型从 `references/tencent-cloud.d` 导入)
1014
+ - `Sharp` (图像处理) → 已经是函数,直接作为依赖(类型从 `references/sharp.d` 导入)
983
1015
 
984
1016
  ### 文档规范
985
1017
 
@@ -0,0 +1,13 @@
1
+ import type { DeployOptions, DeployResult, SecretType } from '../../../../types/tencent-cloud.d';
2
+ import type { TencentCloudSecret, CloudBaseManager } from '../../../../references/tencent-cloud.d';
3
+ import type { FileSystem } from '../../../../references/node.d';
4
+ import type { Console } from '../../../../references/console.d';
5
+ export interface DeployTCBDeps {
6
+ existsSync: FileSystem['existsSync'];
7
+ init: CloudBaseManager['init'];
8
+ log: Console['log'];
9
+ error: Console['error'];
10
+ getSecret: (type: SecretType) => TencentCloudSecret | null;
11
+ }
12
+ export declare function deployToTCB(options: DeployOptions, deps: DeployTCBDeps): Promise<DeployResult>;
13
+ export default deployToTCB;
@@ -0,0 +1,46 @@
1
+ export async function deployToTCB(options, deps) {
2
+ const { localPath, cloudPath = '/', envId, secretType, showProgress = true } = options;
3
+ try {
4
+ if (!deps.existsSync(localPath)) {
5
+ return {
6
+ success: false,
7
+ error: `本地路径不存在: ${localPath}`
8
+ };
9
+ }
10
+ const secret = deps.getSecret(secretType);
11
+ if (!secret || !secret.secretId || !secret.secretKey) {
12
+ return {
13
+ success: false,
14
+ error: `无效的密钥类型: ${secretType}`
15
+ };
16
+ }
17
+ const app = deps.init({
18
+ secretId: secret.secretId,
19
+ secretKey: secret.secretKey,
20
+ envId
21
+ });
22
+ const hosting = app.hosting;
23
+ await hosting.uploadFiles({
24
+ localPath,
25
+ cloudPath,
26
+ onProgress: showProgress ? (progressData) => {
27
+ deps.log(`上传进度: ${progressData.percent}%`);
28
+ } : undefined
29
+ });
30
+ deps.log('文件上传成功');
31
+ return {
32
+ success: true,
33
+ message: '部署成功'
34
+ };
35
+ }
36
+ catch (error) {
37
+ const errorMessage = error instanceof Error ? error.message : String(error);
38
+ deps.error('部署失败:', error);
39
+ return {
40
+ success: false,
41
+ error: `部署失败: ${errorMessage}`
42
+ };
43
+ }
44
+ }
45
+ export default deployToTCB;
46
+ //# sourceMappingURL=deploy.tcb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.tcb.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/deploy.tcb.ts"],"names":[],"mappings":"AAuDA,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAsB,EACtB,IAAmB;IAEnB,MAAM,EACJ,SAAS,EACT,SAAS,GAAG,GAAG,EACf,KAAK,EACL,UAAU,EACV,YAAY,GAAG,IAAI,EACpB,GAAG,OAAO,CAAA;IAEX,IAAI,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,SAAS,EAAE;aAC/B,CAAA;QACH,CAAC;QAGD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACzC,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACrD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,UAAU,EAAE;aAChC,CAAA;QACH,CAAC;QAGD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK;SACN,CAAC,CAAA;QAGF,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;QAG3B,MAAM,OAAO,CAAC,WAAW,CAAC;YACxB,SAAS;YACT,SAAS;YACT,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,YAAgC,EAAE,EAAE;gBAC7D,IAAI,CAAC,GAAG,CAAC,SAAS,YAAY,CAAC,OAAO,GAAG,CAAC,CAAA;YAC5C,CAAC,CAAC,CAAC,CAAC,SAAS;SACf,CAAC,CAAA;QAGF,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAClB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,MAAM;SAChB,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC1B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,SAAS,YAAY,EAAE;SAC/B,CAAA;IACH,CAAC;AACH,CAAC;AAQD,eAAe,WAAW,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { TencentCloudSecret } from '../../../../references/tencent-cloud.d';
2
+ import type { SecretType } from '../../../../types/tencent-cloud.d';
3
+ export declare function getSecret(type: SecretType): TencentCloudSecret;
4
+ export default getSecret;
@@ -0,0 +1,19 @@
1
+ const secretMap = {
2
+ personal: {
3
+ secretId: 'AKIDKVQ5VjiQu73j9IBnFRN2QYQ2MQEl22mI',
4
+ secretKey: 'IL7cqoWy94lDsGSXP9gxzkGXcSFrDJ8h',
5
+ },
6
+ individual: {
7
+ secretId: 'AKID2A6oIZcT5TcWBetteARULxKSM1ResARl',
8
+ secretKey: 'INFtISN3VmocDZgYBZicIitpWyEG4f2B',
9
+ },
10
+ enterprise: {
11
+ secretId: 'AKIDRhqpgKn46uVvACzd7ORGTbaLtHSSEn8H',
12
+ secretKey: '95tV4Ql02wpY5QaaOzTlrjOr8OQFsHUW',
13
+ },
14
+ };
15
+ export function getSecret(type) {
16
+ return secretMap[type];
17
+ }
18
+ export default getSecret;
19
+ //# sourceMappingURL=getSecret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSecret.js","sourceRoot":"","sources":["../../../../src/functions/platform/tencent-cloud/getSecret.ts"],"names":[],"mappings":"AAIA,MAAM,SAAS,GAA2C;IACxD,QAAQ,EAAE;QAER,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;IACD,UAAU,EAAE;QAEV,QAAQ,EAAE,sCAAsC;QAChD,SAAS,EAAE,kCAAkC;KAC9C;CACF,CAAA;AAoCD,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAKD,eAAe,SAAS,CAAA"}
@@ -0,0 +1,27 @@
1
+ import type { UniAppAndroidBuildOptions, UniAppAndroidBuildResult } from '../../../../../types/uniapp-android-build.d';
2
+ import type { FileSystem, Path, ChildProcess } from '../../../../../references/node.d';
3
+ import type { XMLParserConstructor, XMLSerializerConstructor } from '../../../../../references/xml.d';
4
+ import type { JSON5Parser } from '../../../../../references/json5.d';
5
+ import type { XPath } from '../../../../../references/xpath.d';
6
+ import type { setTimeout } from '../../../../../references/timer.d';
7
+ export interface BuildAndroidAppDeps {
8
+ existsSync: FileSystem['existsSync'];
9
+ readFileSync: FileSystem['readFileSync'];
10
+ writeFileSync: FileSystem['writeFileSync'];
11
+ copyFileSync: FileSystem['copyFileSync'];
12
+ mkdirSync: FileSystem['mkdirSync'];
13
+ readdirSync: FileSystem['readdirSync'];
14
+ statSync: FileSystem['statSync'];
15
+ cp: FileSystem['promises']['cp'];
16
+ join: Path['join'];
17
+ dirname: Path['dirname'];
18
+ basename: Path['basename'];
19
+ exec: ChildProcess['exec'];
20
+ platform: string;
21
+ parse: JSON5Parser['parse'];
22
+ xmlParser: XMLParserConstructor;
23
+ xmlSerializer: XMLSerializerConstructor;
24
+ xpath: XPath;
25
+ setTimeout: typeof setTimeout;
26
+ }
27
+ export declare function buildAndroidApp(options: UniAppAndroidBuildOptions, deps: BuildAndroidAppDeps): Promise<UniAppAndroidBuildResult>;