@hubspot/cli 8.3.0 → 8.4.0-beta.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 (522) hide show
  1. package/bin/cli.js +2 -0
  2. package/commands/account/auth.js +12 -22
  3. package/commands/account/clean.js +5 -6
  4. package/commands/account/createOverride.js +7 -7
  5. package/commands/account/info.js +2 -1
  6. package/commands/account/list.js +3 -5
  7. package/commands/account/remove.js +2 -3
  8. package/commands/account/removeOverride.js +8 -10
  9. package/commands/account/rename.js +5 -6
  10. package/commands/account/use.js +8 -19
  11. package/commands/api.d.ts +10 -0
  12. package/commands/api.js +164 -0
  13. package/commands/app/migrate.js +8 -8
  14. package/commands/app/secret/add.js +6 -7
  15. package/commands/app/secret/delete.js +9 -10
  16. package/commands/app/secret/list.js +6 -7
  17. package/commands/app/secret/update.js +8 -9
  18. package/commands/auth.js +12 -12
  19. package/commands/cms/app/create.js +9 -5
  20. package/commands/cms/convertFields.js +8 -8
  21. package/commands/cms/delete.js +2 -3
  22. package/commands/cms/fetch.js +7 -7
  23. package/commands/cms/function/create.js +9 -5
  24. package/commands/cms/function/deploy.js +2 -3
  25. package/commands/cms/function/list.js +11 -7
  26. package/commands/cms/function/logs.js +17 -23
  27. package/commands/cms/function/server.js +2 -3
  28. package/commands/cms/getReactModule.js +7 -8
  29. package/commands/cms/lighthouseScore.js +25 -24
  30. package/commands/cms/lint.js +4 -5
  31. package/commands/cms/list.js +5 -6
  32. package/commands/cms/module/create.js +9 -5
  33. package/commands/cms/module/marketplace-validate.js +7 -8
  34. package/commands/cms/mv.js +2 -3
  35. package/commands/cms/template/create.js +10 -6
  36. package/commands/cms/theme/create.js +5 -5
  37. package/commands/cms/theme/generate-selectors.js +5 -4
  38. package/commands/cms/theme/marketplace-validate.js +8 -9
  39. package/commands/cms/theme/preview.js +16 -8
  40. package/commands/cms/upload.js +15 -12
  41. package/commands/cms/watch.js +5 -5
  42. package/commands/cms/webpack/create.js +5 -5
  43. package/commands/completion.js +3 -5
  44. package/commands/config/migrate.js +6 -7
  45. package/commands/config/set.js +5 -6
  46. package/commands/customObject/create.js +4 -5
  47. package/commands/customObject/createSchema.js +4 -5
  48. package/commands/customObject/deleteSchema.js +4 -5
  49. package/commands/customObject/fetchAllSchemas.js +2 -3
  50. package/commands/customObject/fetchSchema.js +2 -3
  51. package/commands/customObject/listSchemas.js +2 -3
  52. package/commands/customObject/updateSchema.js +4 -5
  53. package/commands/doctor.js +8 -8
  54. package/commands/feedback.js +6 -4
  55. package/commands/filemanager/fetch.js +5 -6
  56. package/commands/filemanager/upload.js +5 -5
  57. package/commands/getStarted.js +14 -16
  58. package/commands/hubdb/clear.js +5 -6
  59. package/commands/hubdb/create.js +4 -5
  60. package/commands/hubdb/delete.js +8 -9
  61. package/commands/hubdb/fetch.js +5 -6
  62. package/commands/hubdb/list.js +16 -14
  63. package/commands/init.js +14 -17
  64. package/commands/mcp/setup.js +5 -6
  65. package/commands/mcp/start.js +2 -3
  66. package/commands/open.js +4 -5
  67. package/commands/project/add.js +10 -5
  68. package/commands/project/create.js +10 -10
  69. package/commands/project/delete.d.ts +7 -0
  70. package/commands/project/delete.js +74 -0
  71. package/commands/project/deploy.js +36 -34
  72. package/commands/project/dev/deprecatedFlow.js +42 -15
  73. package/commands/project/dev/index.d.ts +3 -3
  74. package/commands/project/dev/index.js +24 -30
  75. package/commands/project/dev/unifiedFlow.js +37 -14
  76. package/commands/project/download.js +10 -11
  77. package/commands/project/info.d.ts +4 -0
  78. package/commands/project/info.js +67 -0
  79. package/commands/project/installDeps.js +9 -6
  80. package/commands/project/lint.js +11 -8
  81. package/commands/project/list.js +14 -14
  82. package/commands/project/listBuilds.js +8 -6
  83. package/commands/project/logs.js +5 -6
  84. package/commands/project/migrate.js +8 -8
  85. package/commands/project/open.js +5 -6
  86. package/commands/project/profile/add.js +12 -8
  87. package/commands/project/profile/delete.js +15 -11
  88. package/commands/project/updateDeps.js +9 -6
  89. package/commands/project/upload.js +31 -17
  90. package/commands/project/validate.js +11 -11
  91. package/commands/project/watch.js +20 -20
  92. package/commands/project.js +4 -0
  93. package/commands/sandbox/create.js +15 -15
  94. package/commands/sandbox/delete.js +13 -14
  95. package/commands/secret/addSecret.js +6 -7
  96. package/commands/secret/deleteSecret.js +5 -6
  97. package/commands/secret/listSecret.js +2 -3
  98. package/commands/secret/updateSecret.js +4 -5
  99. package/commands/testAccount/create.d.ts +1 -1
  100. package/commands/testAccount/create.js +20 -16
  101. package/commands/testAccount/createConfig.js +7 -8
  102. package/commands/testAccount/delete.js +27 -18
  103. package/commands/testAccount/importData.js +6 -7
  104. package/commands/upgrade.js +9 -10
  105. package/lang/en.d.ts +114 -5
  106. package/lang/en.js +111 -5
  107. package/lib/accountAuth.js +2 -2
  108. package/lib/buildAccount.js +3 -3
  109. package/lib/doctor/Diagnosis.js +5 -5
  110. package/lib/errorHandlers/index.js +4 -3
  111. package/lib/errorHandlers/suppressError.js +4 -0
  112. package/lib/errors/PromptExitError.d.ts +4 -2
  113. package/lib/errors/PromptExitError.js +3 -0
  114. package/lib/process.d.ts +1 -1
  115. package/lib/process.js +10 -3
  116. package/lib/projects/delete.d.ts +13 -0
  117. package/lib/projects/delete.js +193 -0
  118. package/lib/projects/localDev/AppDevModeInterface.js +11 -11
  119. package/lib/projects/localDev/DevServerManager_DEPRECATED.d.ts +3 -1
  120. package/lib/projects/localDev/DevServerManager_DEPRECATED.js +2 -2
  121. package/lib/projects/localDev/DevSessionManager.d.ts +6 -3
  122. package/lib/projects/localDev/DevSessionManager.js +31 -19
  123. package/lib/projects/localDev/LocalDevManager_DEPRECATED.d.ts +3 -0
  124. package/lib/projects/localDev/LocalDevManager_DEPRECATED.js +16 -12
  125. package/lib/projects/localDev/LocalDevProcess.js +6 -5
  126. package/lib/projects/localDev/LocalDevState.d.ts +3 -2
  127. package/lib/projects/localDev/LocalDevState.js +3 -1
  128. package/lib/projects/localDev/helpers/account.d.ts +4 -3
  129. package/lib/projects/localDev/helpers/account.js +16 -19
  130. package/lib/projects/localDev/helpers/process.d.ts +1 -1
  131. package/lib/projects/localDev/helpers/process.js +4 -10
  132. package/lib/projects/localDev/helpers/project.d.ts +4 -3
  133. package/lib/projects/localDev/helpers/project.js +31 -15
  134. package/lib/projects/projectInfo.d.ts +5 -0
  135. package/lib/projects/projectInfo.js +82 -0
  136. package/lib/projects/projectProfiles.d.ts +1 -2
  137. package/lib/projects/projectProfiles.js +5 -17
  138. package/lib/prompts/createApiSamplePrompt.js +4 -0
  139. package/lib/prompts/projectProfilePrompt.d.ts +2 -0
  140. package/lib/prompts/projectProfilePrompt.js +46 -0
  141. package/lib/prompts/promptUtils.js +3 -2
  142. package/lib/prompts/selectHubDBTablePrompt.js +2 -2
  143. package/lib/prompts/selectPublicAppForMigrationPrompt.js +2 -2
  144. package/lib/theme/cmsDevServerProcess.d.ts +2 -0
  145. package/lib/theme/cmsDevServerProcess.js +7 -6
  146. package/lib/ui/SpinniesManager.d.ts +1 -0
  147. package/lib/ui/SpinniesManager.js +20 -6
  148. package/lib/ui/spinniesUtils.d.ts +0 -1
  149. package/lib/ui/spinniesUtils.js +6 -16
  150. package/lib/usageTracking.d.ts +3 -4
  151. package/lib/yargs/makeYargsBuilder.d.ts +13 -0
  152. package/lib/yargs/makeYargsBuilder.js +33 -0
  153. package/lib/yargs/makeYargsHandlerWithUsageTracking.d.ts +3 -0
  154. package/lib/yargs/makeYargsHandlerWithUsageTracking.js +95 -0
  155. package/lib/yargs/strictEnforceBoolean.d.ts +1 -0
  156. package/lib/yargs/strictEnforceBoolean.js +13 -0
  157. package/lib/yargsUtils.d.ts +3 -16
  158. package/lib/yargsUtils.js +3 -48
  159. package/package.json +9 -4
  160. package/types/LocalDev.d.ts +5 -0
  161. package/types/Projects.d.ts +19 -0
  162. package/types/Yargs.d.ts +18 -1
  163. package/api/__tests__/migrate.test.d.ts +0 -1
  164. package/api/__tests__/migrate.test.js +0 -199
  165. package/commands/__tests__/account.test.d.ts +0 -1
  166. package/commands/__tests__/account.test.js +0 -69
  167. package/commands/__tests__/auth.test.d.ts +0 -1
  168. package/commands/__tests__/auth.test.js +0 -43
  169. package/commands/__tests__/cms.test.d.ts +0 -1
  170. package/commands/__tests__/cms.test.js +0 -87
  171. package/commands/__tests__/config.test.d.ts +0 -1
  172. package/commands/__tests__/config.test.js +0 -44
  173. package/commands/__tests__/customObject.test.d.ts +0 -1
  174. package/commands/__tests__/customObject.test.js +0 -68
  175. package/commands/__tests__/doctor.test.d.ts +0 -1
  176. package/commands/__tests__/doctor.test.js +0 -132
  177. package/commands/__tests__/feedback.test.d.ts +0 -1
  178. package/commands/__tests__/feedback.test.js +0 -24
  179. package/commands/__tests__/filemanager.test.d.ts +0 -1
  180. package/commands/__tests__/filemanager.test.js +0 -45
  181. package/commands/__tests__/getStarted.test.d.ts +0 -1
  182. package/commands/__tests__/getStarted.test.js +0 -173
  183. package/commands/__tests__/hubdb.test.d.ts +0 -1
  184. package/commands/__tests__/hubdb.test.js +0 -50
  185. package/commands/__tests__/init.test.d.ts +0 -1
  186. package/commands/__tests__/init.test.js +0 -42
  187. package/commands/__tests__/mcp.test.d.ts +0 -1
  188. package/commands/__tests__/mcp.test.js +0 -46
  189. package/commands/__tests__/open.test.d.ts +0 -1
  190. package/commands/__tests__/open.test.js +0 -58
  191. package/commands/__tests__/project.test.d.ts +0 -1
  192. package/commands/__tests__/project.test.js +0 -125
  193. package/commands/__tests__/sandbox.test.d.ts +0 -1
  194. package/commands/__tests__/sandbox.test.js +0 -44
  195. package/commands/__tests__/secret.test.d.ts +0 -1
  196. package/commands/__tests__/secret.test.js +0 -49
  197. package/commands/__tests__/testAccount.test.d.ts +0 -1
  198. package/commands/__tests__/testAccount.test.js +0 -57
  199. package/commands/__tests__/upgrade.test.d.ts +0 -1
  200. package/commands/__tests__/upgrade.test.js +0 -309
  201. package/commands/account/__tests__/auth.test.d.ts +0 -1
  202. package/commands/account/__tests__/auth.test.js +0 -206
  203. package/commands/account/__tests__/clean.test.d.ts +0 -1
  204. package/commands/account/__tests__/clean.test.js +0 -28
  205. package/commands/account/__tests__/createOverride.test.d.ts +0 -1
  206. package/commands/account/__tests__/createOverride.test.js +0 -32
  207. package/commands/account/__tests__/info.test.d.ts +0 -1
  208. package/commands/account/__tests__/info.test.js +0 -28
  209. package/commands/account/__tests__/list.test.d.ts +0 -1
  210. package/commands/account/__tests__/list.test.js +0 -153
  211. package/commands/account/__tests__/remove.test.d.ts +0 -1
  212. package/commands/account/__tests__/remove.test.js +0 -36
  213. package/commands/account/__tests__/removeOverride.d.ts +0 -1
  214. package/commands/account/__tests__/removeOverride.js +0 -25
  215. package/commands/account/__tests__/rename.test.d.ts +0 -1
  216. package/commands/account/__tests__/rename.test.js +0 -82
  217. package/commands/account/__tests__/use.test.d.ts +0 -1
  218. package/commands/account/__tests__/use.test.js +0 -170
  219. package/commands/app/__tests__/migrate.test.d.ts +0 -1
  220. package/commands/app/__tests__/migrate.test.js +0 -111
  221. package/commands/app/secret/__tests__/add.test.d.ts +0 -1
  222. package/commands/app/secret/__tests__/add.test.js +0 -140
  223. package/commands/app/secret/__tests__/delete.test.d.ts +0 -1
  224. package/commands/app/secret/__tests__/delete.test.js +0 -28
  225. package/commands/app/secret/__tests__/list.test.d.ts +0 -1
  226. package/commands/app/secret/__tests__/list.test.js +0 -25
  227. package/commands/app/secret/__tests__/update.test.d.ts +0 -1
  228. package/commands/app/secret/__tests__/update.test.js +0 -28
  229. package/commands/cms/__tests__/delete.test.d.ts +0 -1
  230. package/commands/cms/__tests__/delete.test.js +0 -39
  231. package/commands/cms/__tests__/fetch.test.d.ts +0 -1
  232. package/commands/cms/__tests__/fetch.test.js +0 -156
  233. package/commands/cms/__tests__/function.test.d.ts +0 -1
  234. package/commands/cms/__tests__/function.test.js +0 -50
  235. package/commands/cms/__tests__/lint.test.d.ts +0 -1
  236. package/commands/cms/__tests__/lint.test.js +0 -33
  237. package/commands/cms/__tests__/list.test.d.ts +0 -1
  238. package/commands/cms/__tests__/list.test.js +0 -42
  239. package/commands/cms/__tests__/module.test.d.ts +0 -1
  240. package/commands/cms/__tests__/module.test.js +0 -45
  241. package/commands/cms/__tests__/mv.test.d.ts +0 -1
  242. package/commands/cms/__tests__/mv.test.js +0 -46
  243. package/commands/cms/__tests__/theme.test.d.ts +0 -1
  244. package/commands/cms/__tests__/theme.test.js +0 -54
  245. package/commands/cms/__tests__/upload.test.d.ts +0 -1
  246. package/commands/cms/__tests__/upload.test.js +0 -312
  247. package/commands/cms/__tests__/watch.test.d.ts +0 -1
  248. package/commands/cms/__tests__/watch.test.js +0 -204
  249. package/commands/cms/function/__tests__/logs.test.d.ts +0 -1
  250. package/commands/cms/function/__tests__/logs.test.js +0 -70
  251. package/commands/cms/theme/__tests__/generate-selectors.test.d.ts +0 -1
  252. package/commands/cms/theme/__tests__/generate-selectors.test.js +0 -28
  253. package/commands/cms/theme/__tests__/marketplace-validate.test.d.ts +0 -1
  254. package/commands/cms/theme/__tests__/marketplace-validate.test.js +0 -36
  255. package/commands/cms/theme/__tests__/preview.test.d.ts +0 -1
  256. package/commands/cms/theme/__tests__/preview.test.js +0 -54
  257. package/commands/customObject/__tests__/create.test.d.ts +0 -1
  258. package/commands/customObject/__tests__/create.test.js +0 -40
  259. package/commands/customObject/__tests__/createSchema.test.d.ts +0 -1
  260. package/commands/customObject/__tests__/createSchema.test.js +0 -28
  261. package/commands/customObject/__tests__/deleteSchema.test.d.ts +0 -1
  262. package/commands/customObject/__tests__/deleteSchema.test.js +0 -42
  263. package/commands/customObject/__tests__/fetch-all-schemas.test.d.ts +0 -1
  264. package/commands/customObject/__tests__/fetch-all-schemas.test.js +0 -41
  265. package/commands/customObject/__tests__/fetchSchema.test.d.ts +0 -1
  266. package/commands/customObject/__tests__/fetchSchema.test.js +0 -45
  267. package/commands/customObject/__tests__/listSchemas.test.d.ts +0 -1
  268. package/commands/customObject/__tests__/listSchemas.test.js +0 -29
  269. package/commands/customObject/__tests__/updateSchema.test.d.ts +0 -1
  270. package/commands/customObject/__tests__/updateSchema.test.js +0 -40
  271. package/commands/filemanager/__tests__/fetch.test.d.ts +0 -1
  272. package/commands/filemanager/__tests__/fetch.test.js +0 -32
  273. package/commands/filemanager/__tests__/upload.test.d.ts +0 -1
  274. package/commands/filemanager/__tests__/upload.test.js +0 -191
  275. package/commands/hubdb/__tests__/clear.test.d.ts +0 -1
  276. package/commands/hubdb/__tests__/clear.test.js +0 -28
  277. package/commands/hubdb/__tests__/create.test.d.ts +0 -1
  278. package/commands/hubdb/__tests__/create.test.js +0 -28
  279. package/commands/hubdb/__tests__/delete.test.d.ts +0 -1
  280. package/commands/hubdb/__tests__/delete.test.js +0 -28
  281. package/commands/hubdb/__tests__/fetch.test.d.ts +0 -1
  282. package/commands/hubdb/__tests__/fetch.test.js +0 -28
  283. package/commands/hubdb/__tests__/list.test.d.ts +0 -1
  284. package/commands/hubdb/__tests__/list.test.js +0 -88
  285. package/commands/mcp/__tests__/setup.test.d.ts +0 -1
  286. package/commands/mcp/__tests__/setup.test.js +0 -26
  287. package/commands/mcp/__tests__/start.test.d.ts +0 -1
  288. package/commands/mcp/__tests__/start.test.js +0 -144
  289. package/commands/project/__tests__/add.test.d.ts +0 -1
  290. package/commands/project/__tests__/add.test.js +0 -107
  291. package/commands/project/__tests__/create.test.d.ts +0 -1
  292. package/commands/project/__tests__/create.test.js +0 -97
  293. package/commands/project/__tests__/deploy.test.d.ts +0 -1
  294. package/commands/project/__tests__/deploy.test.js +0 -307
  295. package/commands/project/__tests__/dev.test.d.ts +0 -1
  296. package/commands/project/__tests__/dev.test.js +0 -273
  297. package/commands/project/__tests__/devUnifiedFlow.test.d.ts +0 -1
  298. package/commands/project/__tests__/devUnifiedFlow.test.js +0 -434
  299. package/commands/project/__tests__/download.test.d.ts +0 -1
  300. package/commands/project/__tests__/download.test.js +0 -39
  301. package/commands/project/__tests__/installDeps.test.d.ts +0 -1
  302. package/commands/project/__tests__/installDeps.test.js +0 -140
  303. package/commands/project/__tests__/lint.test.d.ts +0 -1
  304. package/commands/project/__tests__/lint.test.js +0 -704
  305. package/commands/project/__tests__/list.test.d.ts +0 -1
  306. package/commands/project/__tests__/list.test.js +0 -31
  307. package/commands/project/__tests__/listBuilds.test.d.ts +0 -1
  308. package/commands/project/__tests__/listBuilds.test.js +0 -38
  309. package/commands/project/__tests__/logs.test.d.ts +0 -1
  310. package/commands/project/__tests__/logs.test.js +0 -202
  311. package/commands/project/__tests__/migrate.test.d.ts +0 -1
  312. package/commands/project/__tests__/migrate.test.js +0 -106
  313. package/commands/project/__tests__/open.test.d.ts +0 -1
  314. package/commands/project/__tests__/open.test.js +0 -39
  315. package/commands/project/__tests__/profile.test.d.ts +0 -1
  316. package/commands/project/__tests__/profile.test.js +0 -42
  317. package/commands/project/__tests__/updateDeps.test.d.ts +0 -1
  318. package/commands/project/__tests__/updateDeps.test.js +0 -140
  319. package/commands/project/__tests__/upload.test.d.ts +0 -1
  320. package/commands/project/__tests__/upload.test.js +0 -234
  321. package/commands/project/__tests__/validate.test.d.ts +0 -1
  322. package/commands/project/__tests__/validate.test.js +0 -381
  323. package/commands/project/__tests__/watch.test.d.ts +0 -1
  324. package/commands/project/__tests__/watch.test.js +0 -35
  325. package/commands/sandbox/__tests__/create.test.d.ts +0 -1
  326. package/commands/sandbox/__tests__/create.test.js +0 -198
  327. package/commands/sandbox/__tests__/delete.test.d.ts +0 -1
  328. package/commands/sandbox/__tests__/delete.test.js +0 -31
  329. package/commands/secret/__tests__/addSecret.test.d.ts +0 -1
  330. package/commands/secret/__tests__/addSecret.test.js +0 -162
  331. package/commands/secret/__tests__/deleteSecret.test.d.ts +0 -1
  332. package/commands/secret/__tests__/deleteSecret.test.js +0 -41
  333. package/commands/secret/__tests__/listSecret.test.d.ts +0 -1
  334. package/commands/secret/__tests__/listSecret.test.js +0 -29
  335. package/commands/secret/__tests__/updateSecret.test.d.ts +0 -1
  336. package/commands/secret/__tests__/updateSecret.test.js +0 -29
  337. package/commands/testAccount/__tests__/create.test.d.ts +0 -1
  338. package/commands/testAccount/__tests__/create.test.js +0 -106
  339. package/commands/testAccount/__tests__/createConfig.test.d.ts +0 -1
  340. package/commands/testAccount/__tests__/createConfig.test.js +0 -32
  341. package/commands/testAccount/__tests__/delete.test.d.ts +0 -1
  342. package/commands/testAccount/__tests__/delete.test.js +0 -29
  343. package/commands/testAccount/__tests__/importData.test.d.ts +0 -1
  344. package/commands/testAccount/__tests__/importData.test.js +0 -92
  345. package/lib/__tests__/CLIWebSocketServer.test.d.ts +0 -1
  346. package/lib/__tests__/CLIWebSocketServer.test.js +0 -252
  347. package/lib/__tests__/accountAuth.test.d.ts +0 -1
  348. package/lib/__tests__/accountAuth.test.js +0 -258
  349. package/lib/__tests__/accountTypes.test.d.ts +0 -1
  350. package/lib/__tests__/accountTypes.test.js +0 -98
  351. package/lib/__tests__/buildAccount.test.d.ts +0 -1
  352. package/lib/__tests__/buildAccount.test.js +0 -211
  353. package/lib/__tests__/cliUpgradeUtils.test.d.ts +0 -1
  354. package/lib/__tests__/cliUpgradeUtils.test.js +0 -131
  355. package/lib/__tests__/commandSuggestion.test.d.ts +0 -1
  356. package/lib/__tests__/commandSuggestion.test.js +0 -121
  357. package/lib/__tests__/commonOpts.test.d.ts +0 -1
  358. package/lib/__tests__/commonOpts.test.js +0 -80
  359. package/lib/__tests__/dependencyManagement.test.d.ts +0 -1
  360. package/lib/__tests__/dependencyManagement.test.js +0 -1067
  361. package/lib/__tests__/developerTestAccounts.test.d.ts +0 -1
  362. package/lib/__tests__/developerTestAccounts.test.js +0 -156
  363. package/lib/__tests__/hasFeature.test.d.ts +0 -1
  364. package/lib/__tests__/hasFeature.test.js +0 -167
  365. package/lib/__tests__/http.test.d.ts +0 -1
  366. package/lib/__tests__/http.test.js +0 -40
  367. package/lib/__tests__/importData.test.d.ts +0 -1
  368. package/lib/__tests__/importData.test.js +0 -98
  369. package/lib/__tests__/npmCli.test.d.ts +0 -1
  370. package/lib/__tests__/npmCli.test.js +0 -84
  371. package/lib/__tests__/oauth.test.d.ts +0 -1
  372. package/lib/__tests__/oauth.test.js +0 -109
  373. package/lib/__tests__/parsing.test.d.ts +0 -1
  374. package/lib/__tests__/parsing.test.js +0 -34
  375. package/lib/__tests__/polling.test.d.ts +0 -1
  376. package/lib/__tests__/polling.test.js +0 -76
  377. package/lib/__tests__/process.test.d.ts +0 -1
  378. package/lib/__tests__/process.test.js +0 -89
  379. package/lib/__tests__/sandboxes.test.d.ts +0 -1
  380. package/lib/__tests__/sandboxes.test.js +0 -128
  381. package/lib/__tests__/serverlessLogs.test.d.ts +0 -1
  382. package/lib/__tests__/serverlessLogs.test.js +0 -163
  383. package/lib/__tests__/usageTracking.test.d.ts +0 -1
  384. package/lib/__tests__/usageTracking.test.js +0 -197
  385. package/lib/__tests__/validation.test.d.ts +0 -1
  386. package/lib/__tests__/validation.test.js +0 -143
  387. package/lib/__tests__/yargsUtils.test.d.ts +0 -1
  388. package/lib/__tests__/yargsUtils.test.js +0 -124
  389. package/lib/app/__tests__/migrate.test.d.ts +0 -1
  390. package/lib/app/__tests__/migrate.test.js +0 -638
  391. package/lib/doctor/__tests__/Diagnosis.test.d.ts +0 -1
  392. package/lib/doctor/__tests__/Diagnosis.test.js +0 -84
  393. package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.d.ts +0 -1
  394. package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.js +0 -177
  395. package/lib/doctor/__tests__/Doctor.test.d.ts +0 -1
  396. package/lib/doctor/__tests__/Doctor.test.js +0 -560
  397. package/lib/errorHandlers/__tests__/index.test.d.ts +0 -1
  398. package/lib/errorHandlers/__tests__/index.test.js +0 -278
  399. package/lib/mcp/__tests__/setup.test.d.ts +0 -1
  400. package/lib/mcp/__tests__/setup.test.js +0 -523
  401. package/lib/middleware/__tests__/commandTargetingUtils.test.d.ts +0 -1
  402. package/lib/middleware/__tests__/commandTargetingUtils.test.js +0 -99
  403. package/lib/middleware/__tests__/configMiddleware.test.d.ts +0 -1
  404. package/lib/middleware/__tests__/configMiddleware.test.js +0 -118
  405. package/lib/middleware/__tests__/gitMiddleware.test.d.ts +0 -1
  406. package/lib/middleware/__tests__/gitMiddleware.test.js +0 -43
  407. package/lib/middleware/__tests__/requestMiddleware.test.d.ts +0 -1
  408. package/lib/middleware/__tests__/requestMiddleware.test.js +0 -15
  409. package/lib/middleware/__tests__/usageTrackingMiddleware.test.d.ts +0 -1
  410. package/lib/middleware/__tests__/usageTrackingMiddleware.test.js +0 -44
  411. package/lib/middleware/__tests__/yargsChecksMiddleware.test.d.ts +0 -1
  412. package/lib/middleware/__tests__/yargsChecksMiddleware.test.js +0 -39
  413. package/lib/projects/__tests__/AppDevModeInterface.test.d.ts +0 -1
  414. package/lib/projects/__tests__/AppDevModeInterface.test.js +0 -541
  415. package/lib/projects/__tests__/DevServerManager.test.d.ts +0 -1
  416. package/lib/projects/__tests__/DevServerManager.test.js +0 -185
  417. package/lib/projects/__tests__/DevSessionManager.test.d.ts +0 -1
  418. package/lib/projects/__tests__/DevSessionManager.test.js +0 -250
  419. package/lib/projects/__tests__/LocalDevProcess.test.d.ts +0 -1
  420. package/lib/projects/__tests__/LocalDevProcess.test.js +0 -481
  421. package/lib/projects/__tests__/LocalDevWebsocketServer.test.d.ts +0 -1
  422. package/lib/projects/__tests__/LocalDevWebsocketServer.test.js +0 -231
  423. package/lib/projects/__tests__/ProjectLogsManager.test.d.ts +0 -1
  424. package/lib/projects/__tests__/ProjectLogsManager.test.js +0 -302
  425. package/lib/projects/__tests__/UIExtensionsDevModeInterface.test.d.ts +0 -1
  426. package/lib/projects/__tests__/UIExtensionsDevModeInterface.test.js +0 -160
  427. package/lib/projects/__tests__/components.test.d.ts +0 -1
  428. package/lib/projects/__tests__/components.test.js +0 -440
  429. package/lib/projects/__tests__/deploy.test.d.ts +0 -1
  430. package/lib/projects/__tests__/deploy.test.js +0 -231
  431. package/lib/projects/__tests__/localDevProjectHelpers.test.d.ts +0 -1
  432. package/lib/projects/__tests__/localDevProjectHelpers.test.js +0 -120
  433. package/lib/projects/__tests__/platformVersion.test.d.ts +0 -1
  434. package/lib/projects/__tests__/platformVersion.test.js +0 -63
  435. package/lib/projects/__tests__/pollProjectBuildAndDeploy.test.d.ts +0 -1
  436. package/lib/projects/__tests__/pollProjectBuildAndDeploy.test.js +0 -328
  437. package/lib/projects/__tests__/projectProfiles.test.d.ts +0 -1
  438. package/lib/projects/__tests__/projectProfiles.test.js +0 -441
  439. package/lib/projects/__tests__/projects.test.d.ts +0 -1
  440. package/lib/projects/__tests__/projects.test.js +0 -58
  441. package/lib/projects/__tests__/structure.test.d.ts +0 -1
  442. package/lib/projects/__tests__/structure.test.js +0 -210
  443. package/lib/projects/__tests__/uieLinting.test.d.ts +0 -1
  444. package/lib/projects/__tests__/uieLinting.test.js +0 -631
  445. package/lib/projects/__tests__/upload.test.d.ts +0 -1
  446. package/lib/projects/__tests__/upload.test.js +0 -183
  447. package/lib/projects/add/__tests__/legacyAddComponent.test.d.ts +0 -1
  448. package/lib/projects/add/__tests__/legacyAddComponent.test.js +0 -245
  449. package/lib/projects/add/__tests__/v2AddComponent.test.d.ts +0 -1
  450. package/lib/projects/add/__tests__/v2AddComponent.test.js +0 -343
  451. package/lib/projects/create/__tests__/legacy.test.d.ts +0 -1
  452. package/lib/projects/create/__tests__/legacy.test.js +0 -72
  453. package/lib/projects/create/__tests__/v2.test.d.ts +0 -1
  454. package/lib/projects/create/__tests__/v2.test.js +0 -257
  455. package/lib/prompts/__tests__/createDeveloperTestAccountConfigPrompt.test.d.ts +0 -1
  456. package/lib/prompts/__tests__/createDeveloperTestAccountConfigPrompt.test.js +0 -157
  457. package/lib/prompts/__tests__/createFunctionPrompt.test.d.ts +0 -1
  458. package/lib/prompts/__tests__/createFunctionPrompt.test.js +0 -129
  459. package/lib/prompts/__tests__/createModulePrompt.test.d.ts +0 -1
  460. package/lib/prompts/__tests__/createModulePrompt.test.js +0 -187
  461. package/lib/prompts/__tests__/createTemplatePrompt.test.d.ts +0 -1
  462. package/lib/prompts/__tests__/createTemplatePrompt.test.js +0 -102
  463. package/lib/prompts/__tests__/downloadProjectPrompt.test.d.ts +0 -1
  464. package/lib/prompts/__tests__/downloadProjectPrompt.test.js +0 -31
  465. package/lib/prompts/__tests__/projectAddPrompt.test.d.ts +0 -1
  466. package/lib/prompts/__tests__/projectAddPrompt.test.js +0 -143
  467. package/lib/prompts/__tests__/projectsLogsPrompt.test.d.ts +0 -1
  468. package/lib/prompts/__tests__/projectsLogsPrompt.test.js +0 -37
  469. package/lib/prompts/__tests__/selectProjectTemplatePrompt.test.d.ts +0 -1
  470. package/lib/prompts/__tests__/selectProjectTemplatePrompt.test.js +0 -160
  471. package/lib/theme/__tests__/migrate.test.d.ts +0 -1
  472. package/lib/theme/__tests__/migrate.test.js +0 -247
  473. package/lib/ui/__tests__/SpinniesManager.test.d.ts +0 -1
  474. package/lib/ui/__tests__/SpinniesManager.test.js +0 -488
  475. package/lib/ui/__tests__/removeAnsiCodes.test.d.ts +0 -1
  476. package/lib/ui/__tests__/removeAnsiCodes.test.js +0 -84
  477. package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.d.ts +0 -1
  478. package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +0 -254
  479. package/mcp-server/tools/cms/__tests__/HsCreateModuleTool.test.d.ts +0 -1
  480. package/mcp-server/tools/cms/__tests__/HsCreateModuleTool.test.js +0 -227
  481. package/mcp-server/tools/cms/__tests__/HsCreateTemplateTool.test.d.ts +0 -1
  482. package/mcp-server/tools/cms/__tests__/HsCreateTemplateTool.test.js +0 -208
  483. package/mcp-server/tools/cms/__tests__/HsFunctionLogsTool.test.d.ts +0 -1
  484. package/mcp-server/tools/cms/__tests__/HsFunctionLogsTool.test.js +0 -186
  485. package/mcp-server/tools/cms/__tests__/HsListFunctionsTool.test.d.ts +0 -1
  486. package/mcp-server/tools/cms/__tests__/HsListFunctionsTool.test.js +0 -124
  487. package/mcp-server/tools/cms/__tests__/HsListTool.test.d.ts +0 -1
  488. package/mcp-server/tools/cms/__tests__/HsListTool.test.js +0 -124
  489. package/mcp-server/tools/project/__tests__/AddFeatureToProjectTool.test.d.ts +0 -1
  490. package/mcp-server/tools/project/__tests__/AddFeatureToProjectTool.test.js +0 -157
  491. package/mcp-server/tools/project/__tests__/CreateProjectTool.test.d.ts +0 -1
  492. package/mcp-server/tools/project/__tests__/CreateProjectTool.test.js +0 -131
  493. package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.d.ts +0 -1
  494. package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +0 -461
  495. package/mcp-server/tools/project/__tests__/DeployProjectTool.test.d.ts +0 -1
  496. package/mcp-server/tools/project/__tests__/DeployProjectTool.test.js +0 -125
  497. package/mcp-server/tools/project/__tests__/DocFetchTool.test.d.ts +0 -1
  498. package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +0 -125
  499. package/mcp-server/tools/project/__tests__/DocsSearchTool.test.d.ts +0 -1
  500. package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +0 -210
  501. package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.d.ts +0 -1
  502. package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +0 -146
  503. package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.d.ts +0 -1
  504. package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +0 -124
  505. package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.d.ts +0 -1
  506. package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.js +0 -307
  507. package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.d.ts +0 -1
  508. package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.js +0 -242
  509. package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.d.ts +0 -1
  510. package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +0 -209
  511. package/mcp-server/tools/project/__tests__/GuidedWalkthroughTool.test.d.ts +0 -1
  512. package/mcp-server/tools/project/__tests__/GuidedWalkthroughTool.test.js +0 -158
  513. package/mcp-server/tools/project/__tests__/UploadProjectTools.test.d.ts +0 -1
  514. package/mcp-server/tools/project/__tests__/UploadProjectTools.test.js +0 -187
  515. package/mcp-server/tools/project/__tests__/ValidateProjectTool.test.d.ts +0 -1
  516. package/mcp-server/tools/project/__tests__/ValidateProjectTool.test.js +0 -118
  517. package/mcp-server/utils/__tests__/command.test.d.ts +0 -1
  518. package/mcp-server/utils/__tests__/command.test.js +0 -275
  519. package/mcp-server/utils/__tests__/content.test.d.ts +0 -1
  520. package/mcp-server/utils/__tests__/content.test.js +0 -164
  521. package/mcp-server/utils/__tests__/feedbackTracking.test.d.ts +0 -1
  522. package/mcp-server/utils/__tests__/feedbackTracking.test.js +0 -69
@@ -1,1067 +0,0 @@
1
- import util from 'util';
2
- import { installPackages, updatePackages, getProjectPackageJsonLocations, isPackageInstalled, } from '../dependencyManagement.js';
3
- import { walk } from '@hubspot/local-dev-lib/fs';
4
- import path from 'path';
5
- import { getProjectConfig } from '../projects/config.js';
6
- import SpinniesManager from '../ui/SpinniesManager.js';
7
- import fs from 'fs';
8
- import { clearPackageJsonCache } from '../npm/packageJson.js';
9
- vi.mock('../projects/config');
10
- vi.mock('@hubspot/local-dev-lib/fs');
11
- vi.mock('fs');
12
- vi.mock('../ui/SpinniesManager', () => ({
13
- default: {
14
- init: vi.fn(),
15
- add: vi.fn(),
16
- succeed: vi.fn(),
17
- fail: vi.fn(),
18
- },
19
- }));
20
- const mockedFs = vi.mocked(fs);
21
- describe('lib/dependencyManagement', () => {
22
- let execMock;
23
- const projectDir = path.join('path', 'to', 'project');
24
- const srcDir = 'src';
25
- const appDir = path.join(projectDir, srcDir, 'app');
26
- const appFunctionsDir = path.join(appDir, 'app.functions');
27
- const extensionsDir = path.join(appDir, 'exensions');
28
- const projectName = 'super cool test project';
29
- const installLocations = [appFunctionsDir, extensionsDir];
30
- function mockedPromisify(execMock) {
31
- return vi
32
- .fn()
33
- .mockReturnValue(execMock);
34
- }
35
- const mockedWalk = walk;
36
- const mockedGetProjectConfig = getProjectConfig;
37
- beforeEach(() => {
38
- execMock = vi.fn();
39
- util.promisify = mockedPromisify(execMock);
40
- mockedGetProjectConfig.mockResolvedValue({
41
- projectDir,
42
- projectConfig: {
43
- srcDir,
44
- name: projectName,
45
- },
46
- });
47
- mockedFs.existsSync.mockReturnValue(true); // Default to true, override in specific tests
48
- clearPackageJsonCache();
49
- });
50
- describe('installPackages()', () => {
51
- it('should setup a loading spinner', async () => {
52
- const packages = ['package1', 'package2'];
53
- mockedWalk.mockResolvedValue(installLocations);
54
- await installPackages({ packages, installLocations });
55
- expect(SpinniesManager.add).toHaveBeenCalledTimes(installLocations.length);
56
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(installLocations.length);
57
- });
58
- it('should install the provided packages in all the provided install locations', async () => {
59
- mockedWalk.mockResolvedValue(installLocations);
60
- const packages = ['package1', 'package2'];
61
- await installPackages({ packages, installLocations });
62
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
63
- expect(SpinniesManager.add).toHaveBeenCalledTimes(installLocations.length);
64
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(installLocations.length);
65
- for (const location of installLocations) {
66
- expect(execMock).toHaveBeenCalledWith(`npm install package1 package2`, {
67
- cwd: location,
68
- });
69
- expect(SpinniesManager.add).toHaveBeenCalledWith(`installingDependencies-${location}`, {
70
- text: `Installing [package1, package2] in ${location}`,
71
- });
72
- expect(SpinniesManager.succeed).toHaveBeenCalledWith(`installingDependencies-${location}`, {
73
- text: `Installed dependencies in ${location}`,
74
- });
75
- }
76
- });
77
- it('should use the provided install locations', async () => {
78
- mockedWalk.mockResolvedValue(installLocations);
79
- await installPackages({ installLocations });
80
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
81
- expect(execMock).toHaveBeenCalledWith(`npm install `, {
82
- cwd: appFunctionsDir,
83
- });
84
- expect(execMock).toHaveBeenCalledWith(`npm install `, {
85
- cwd: extensionsDir,
86
- });
87
- });
88
- it('should locate the projects package.json files when install locations is not provided', async () => {
89
- const installLocations = [
90
- path.join(appFunctionsDir, 'package.json'),
91
- path.join(extensionsDir, 'package.json'),
92
- ];
93
- mockedWalk.mockResolvedValue(installLocations);
94
- mockedGetProjectConfig.mockResolvedValue({
95
- projectDir,
96
- projectConfig: {
97
- srcDir,
98
- },
99
- });
100
- await installPackages({});
101
- // It's called once per each install location, plus once to check if npm installed
102
- expect(execMock).toHaveBeenCalledTimes(installLocations.length + 1);
103
- expect(execMock).toHaveBeenCalledWith(`npm install `, {
104
- cwd: appFunctionsDir,
105
- });
106
- expect(execMock).toHaveBeenCalledWith(`npm install `, {
107
- cwd: extensionsDir,
108
- });
109
- });
110
- it('should install packages as dev dependencies when dev flag is true', async () => {
111
- const packages = ['eslint', 'prettier'];
112
- await installPackages({ packages, installLocations, dev: true });
113
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
114
- for (const location of installLocations) {
115
- expect(execMock).toHaveBeenCalledWith(`npm install --save-dev eslint prettier`, {
116
- cwd: location,
117
- });
118
- }
119
- });
120
- it('should install packages as regular dependencies when dev flag is false', async () => {
121
- const packages = ['react', 'react-dom'];
122
- await installPackages({ packages, installLocations, dev: false });
123
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
124
- for (const location of installLocations) {
125
- expect(execMock).toHaveBeenCalledWith(`npm install react react-dom`, {
126
- cwd: location,
127
- });
128
- }
129
- });
130
- it('should install packages as regular dependencies when dev flag is not provided', async () => {
131
- const packages = ['axios'];
132
- await installPackages({ packages, installLocations });
133
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
134
- for (const location of installLocations) {
135
- expect(execMock).toHaveBeenCalledWith(`npm install axios`, {
136
- cwd: location,
137
- });
138
- }
139
- });
140
- it('should not use --save-dev flag when dev is true but no packages are provided', async () => {
141
- mockedWalk.mockResolvedValue(installLocations);
142
- await installPackages({ installLocations, dev: true });
143
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
144
- for (let i = 0; i < installLocations.length; i++) {
145
- const installLocation = installLocations[i];
146
- expect(execMock.mock.calls[i]).toEqual([
147
- `npm install `,
148
- {
149
- cwd: installLocation,
150
- },
151
- ]);
152
- }
153
- });
154
- it('should not use --save-dev flag when dev is true but packages array is empty', async () => {
155
- await installPackages({ packages: [], installLocations, dev: true });
156
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
157
- for (let i = 0; i < installLocations.length; i++) {
158
- const installLocation = installLocations[i];
159
- expect(execMock.mock.calls[i]).toEqual([
160
- `npm install `,
161
- {
162
- cwd: installLocation,
163
- },
164
- ]);
165
- }
166
- });
167
- it('should throw an error when installing the dependencies fails', async () => {
168
- execMock = vi.fn().mockImplementation(command => {
169
- if (command === 'npm --version') {
170
- return;
171
- }
172
- throw new Error('OH NO');
173
- });
174
- util.promisify = mockedPromisify(execMock);
175
- // Mock walk to return the directory paths instead of package.json paths
176
- mockedWalk.mockResolvedValue([appFunctionsDir, extensionsDir]);
177
- mockedFs.existsSync.mockImplementation(filePath => {
178
- const pathStr = filePath.toString();
179
- if (pathStr === projectDir ||
180
- pathStr === path.join(projectDir, srcDir)) {
181
- return true;
182
- }
183
- return false;
184
- });
185
- await expect(() => installPackages({ installLocations: [appFunctionsDir, extensionsDir] })).rejects.toThrowError(`Installing dependencies for ${appFunctionsDir} failed`);
186
- expect(SpinniesManager.fail).toHaveBeenCalledTimes(installLocations.length);
187
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`installingDependencies-${appFunctionsDir}`, {
188
- text: `Installing dependencies for ${appFunctionsDir} failed`,
189
- });
190
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`installingDependencies-${extensionsDir}`, {
191
- text: `Installing dependencies for ${extensionsDir} failed`,
192
- });
193
- });
194
- });
195
- describe('updatePackages()', () => {
196
- it('should setup a loading spinner', async () => {
197
- mockedWalk.mockResolvedValue(installLocations);
198
- const packages = ['package1', 'package2'];
199
- await updatePackages({ packages, installLocations });
200
- expect(SpinniesManager.add).toHaveBeenCalledTimes(installLocations.length);
201
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(installLocations.length);
202
- });
203
- it('should update the provided packages in all the provided install locations', async () => {
204
- mockedWalk.mockResolvedValue(installLocations);
205
- const packages = ['package1', 'package2'];
206
- await updatePackages({ packages, installLocations });
207
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
208
- expect(SpinniesManager.add).toHaveBeenCalledTimes(installLocations.length);
209
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(installLocations.length);
210
- for (const location of installLocations) {
211
- expect(execMock).toHaveBeenCalledWith(`npm update package1 package2`, {
212
- cwd: location,
213
- });
214
- expect(SpinniesManager.add).toHaveBeenCalledWith(`updatingDependencies-${location}`, {
215
- text: `Updating [package1, package2] in ${location}`,
216
- });
217
- expect(SpinniesManager.succeed).toHaveBeenCalledWith(`updatingDependencies-${location}`, {
218
- text: `Updated dependencies in ${location}`,
219
- });
220
- }
221
- });
222
- it('should use the provided install locations', async () => {
223
- await updatePackages({ installLocations });
224
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
225
- expect(execMock).toHaveBeenCalledWith(`npm update `, {
226
- cwd: appFunctionsDir,
227
- });
228
- expect(execMock).toHaveBeenCalledWith(`npm update `, {
229
- cwd: extensionsDir,
230
- });
231
- });
232
- it('should locate the projects package.json files when install locations is not provided', async () => {
233
- const installLocations = [
234
- path.join(appFunctionsDir, 'package.json'),
235
- path.join(extensionsDir, 'package.json'),
236
- ];
237
- mockedWalk.mockResolvedValue(installLocations);
238
- mockedGetProjectConfig.mockResolvedValue({
239
- projectDir,
240
- projectConfig: {
241
- srcDir,
242
- },
243
- });
244
- await updatePackages({});
245
- // It's called once per each install location, plus once to check if npm installed
246
- expect(execMock).toHaveBeenCalledTimes(installLocations.length + 1);
247
- expect(execMock).toHaveBeenCalledWith(`npm update `, {
248
- cwd: appFunctionsDir,
249
- });
250
- expect(execMock).toHaveBeenCalledWith(`npm update `, {
251
- cwd: extensionsDir,
252
- });
253
- });
254
- it('should throw an error when updating the dependencies fails', async () => {
255
- execMock = vi.fn().mockImplementation(command => {
256
- if (command === 'npm --version') {
257
- return;
258
- }
259
- throw new Error('OH NO');
260
- });
261
- util.promisify = mockedPromisify(execMock);
262
- // Mock walk to return the directory paths instead of package.json paths
263
- mockedWalk.mockResolvedValue([appFunctionsDir, extensionsDir]);
264
- mockedFs.existsSync.mockImplementation(filePath => {
265
- const pathStr = filePath.toString();
266
- if (pathStr === projectDir ||
267
- pathStr === path.join(projectDir, srcDir)) {
268
- return true;
269
- }
270
- return false;
271
- });
272
- await expect(() => updatePackages({ installLocations: [appFunctionsDir, extensionsDir] })).rejects.toThrowError(`Updating dependencies for ${appFunctionsDir} failed`);
273
- expect(SpinniesManager.fail).toHaveBeenCalledTimes(installLocations.length);
274
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`updatingDependencies-${appFunctionsDir}`, {
275
- text: `Updating dependencies for ${appFunctionsDir} failed`,
276
- });
277
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`updatingDependencies-${extensionsDir}`, {
278
- text: `Updating dependencies for ${extensionsDir} failed`,
279
- });
280
- });
281
- });
282
- describe('getProjectPackageJsonFiles()', () => {
283
- it('should throw an error when ran outside the boundary of a project', async () => {
284
- mockedGetProjectConfig.mockResolvedValue({});
285
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError('No project detected. Run this command from a project directory.');
286
- });
287
- it('should throw an error if npm is not globally installed', async () => {
288
- execMock = vi.fn().mockImplementation(() => {
289
- throw new Error('OH NO');
290
- });
291
- util.promisify = mockedPromisify(execMock);
292
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(/This command depends on npm, install/);
293
- });
294
- it('should throw an error if the project directory does not exist', async () => {
295
- mockedFs.existsSync.mockReturnValueOnce(false);
296
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(new RegExp(`No dependencies to install. The project ${projectName} folder might be missing component or subcomponent files.`));
297
- });
298
- it('should throw "install" error message when isUpdate=false and no package.json files found', async () => {
299
- mockedWalk.mockResolvedValue([]);
300
- mockedFs.existsSync.mockImplementation(filePath => {
301
- const pathStr = filePath.toString();
302
- if (pathStr === projectDir ||
303
- pathStr === path.join(projectDir, srcDir)) {
304
- return true;
305
- }
306
- return false;
307
- });
308
- await expect(() => getProjectPackageJsonLocations(undefined, false)).rejects.toThrowError(new RegExp(`No dependencies to install. The project ${projectName} folder might be missing component or subcomponent files.`));
309
- });
310
- it('should throw "update" error message when isUpdate=true and no package.json files found', async () => {
311
- mockedWalk.mockResolvedValue([]);
312
- mockedFs.existsSync.mockImplementation(filePath => {
313
- const pathStr = filePath.toString();
314
- if (pathStr === projectDir ||
315
- pathStr === path.join(projectDir, srcDir)) {
316
- return true;
317
- }
318
- return false;
319
- });
320
- await expect(() => getProjectPackageJsonLocations(undefined, true)).rejects.toThrowError(new RegExp(`No dependencies to update. The project ${projectName} folder might be missing component or subcomponent files.`));
321
- });
322
- it('should ignore package.json files in certain directories', async () => {
323
- const nodeModulesDir = path.join(appDir, 'node_modules');
324
- const viteDir = path.join(appDir, '.vite');
325
- const installLocations = [
326
- path.join(appFunctionsDir, 'package.json'),
327
- path.join(extensionsDir, 'package.json'),
328
- path.join(viteDir, 'package.json'),
329
- path.join(nodeModulesDir, 'package.json'),
330
- ];
331
- mockedWalk.mockResolvedValue(installLocations);
332
- mockedFs.existsSync.mockImplementation(filePath => {
333
- // Return true for project directory and src directory
334
- const pathStr = filePath.toString();
335
- if (pathStr === projectDir ||
336
- pathStr === path.join(projectDir, srcDir)) {
337
- return true;
338
- }
339
- return false;
340
- });
341
- const actual = await getProjectPackageJsonLocations();
342
- expect(actual).toEqual([appFunctionsDir, extensionsDir]);
343
- });
344
- });
345
- describe('isPackageInstalled()', () => {
346
- const testDir = '/test/directory';
347
- const readFileSyncSpy = vi.spyOn(fs, 'readFileSync');
348
- const existsSyncSpy = vi.spyOn(fs, 'existsSync');
349
- function mockNodeModulesExists(packageName, exists = true) {
350
- existsSyncSpy.mockImplementation(filePath => {
351
- const pathStr = filePath.toString();
352
- return (exists && pathStr === path.join(testDir, 'node_modules', packageName));
353
- });
354
- }
355
- beforeEach(() => {
356
- readFileSyncSpy.mockReset();
357
- existsSyncSpy.mockReset();
358
- });
359
- it('should return true if package is in dependencies and in node_modules', () => {
360
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
361
- dependencies: {
362
- eslint: '^9.0.0',
363
- },
364
- }));
365
- mockNodeModulesExists('eslint', true);
366
- const result = isPackageInstalled(testDir, 'eslint');
367
- expect(result).toBe(true);
368
- expect(readFileSyncSpy).toHaveBeenCalledWith(path.join(testDir, 'package.json'), 'utf-8');
369
- expect(existsSyncSpy).toHaveBeenCalledWith(path.join(testDir, 'node_modules', 'eslint'));
370
- });
371
- it('should return true if package is in devDependencies and in node_modules', () => {
372
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
373
- devDependencies: {
374
- prettier: '^3.0.0',
375
- },
376
- }));
377
- mockNodeModulesExists('prettier', true);
378
- const result = isPackageInstalled(testDir, 'prettier');
379
- expect(result).toBe(true);
380
- });
381
- it('should return false if package is in package.json but not in node_modules', () => {
382
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
383
- dependencies: {
384
- react: '^18.0.0',
385
- },
386
- }));
387
- mockNodeModulesExists('react', false);
388
- const result = isPackageInstalled(testDir, 'react');
389
- expect(result).toBe(false);
390
- });
391
- it('should return false if package is not in package.json but is in node_modules', () => {
392
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
393
- dependencies: {
394
- typescript: '^5.0.0',
395
- },
396
- }));
397
- mockNodeModulesExists('lodash', true);
398
- const result = isPackageInstalled(testDir, 'lodash');
399
- expect(result).toBe(false);
400
- });
401
- it('should return false if package is not in package.json and not in node_modules', () => {
402
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
403
- dependencies: {},
404
- }));
405
- mockNodeModulesExists('nonexistent-package', false);
406
- const result = isPackageInstalled(testDir, 'nonexistent-package');
407
- expect(result).toBe(false);
408
- });
409
- it('should return false if package.json cannot be read', () => {
410
- readFileSyncSpy.mockImplementationOnce(() => {
411
- throw new Error('File not found');
412
- });
413
- const result = isPackageInstalled(testDir, 'eslint');
414
- expect(result).toBe(false);
415
- });
416
- it('should return false if package.json has invalid JSON', () => {
417
- readFileSyncSpy.mockReturnValueOnce('invalid json{');
418
- const result = isPackageInstalled(testDir, 'eslint');
419
- expect(result).toBe(false);
420
- });
421
- it('should return false if checking node_modules throws an error', () => {
422
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
423
- dependencies: {
424
- eslint: '^9.0.0',
425
- },
426
- }));
427
- existsSyncSpy.mockImplementation(() => {
428
- throw new Error('Permission denied');
429
- });
430
- const result = isPackageInstalled(testDir, 'eslint');
431
- expect(result).toBe(false);
432
- });
433
- it('should handle scoped packages correctly', () => {
434
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
435
- dependencies: {
436
- '@typescript-eslint/parser': '^8.0.0',
437
- },
438
- }));
439
- mockNodeModulesExists('@typescript-eslint/parser', true);
440
- const result = isPackageInstalled(testDir, '@typescript-eslint/parser');
441
- expect(result).toBe(true);
442
- expect(existsSyncSpy).toHaveBeenCalledWith(path.join(testDir, 'node_modules', '@typescript-eslint/parser'));
443
- });
444
- it('should check both dependencies and devDependencies', () => {
445
- readFileSyncSpy.mockReturnValueOnce(JSON.stringify({
446
- dependencies: {
447
- react: '^18.0.0',
448
- },
449
- devDependencies: {
450
- eslint: '^9.0.0',
451
- },
452
- }));
453
- mockNodeModulesExists('eslint', true);
454
- const result = isPackageInstalled(testDir, 'eslint');
455
- expect(result).toBe(true);
456
- });
457
- });
458
- describe('npm workspaces support', () => {
459
- const workspaceRoot = path.join(projectDir, 'workspace');
460
- const pkg1Dir = path.join(workspaceRoot, 'packages', 'pkg-a');
461
- const pkg2Dir = path.join(workspaceRoot, 'packages', 'pkg-b');
462
- const standaloneDir = path.join(projectDir, 'standalone');
463
- function mockWorkspaceSetup(workspaceRootPath, workspacePatterns, packageDirs) {
464
- const allPackageJsons = [
465
- path.join(workspaceRootPath, 'package.json'),
466
- ...packageDirs.map(d => path.join(d, 'package.json')),
467
- ];
468
- mockedWalk.mockResolvedValue(allPackageJsons);
469
- mockedFs.readFileSync.mockImplementation(filePath => {
470
- const pathStr = filePath.toString();
471
- if (pathStr === path.join(workspaceRootPath, 'package.json')) {
472
- return JSON.stringify({
473
- name: 'workspace-root',
474
- workspaces: workspacePatterns,
475
- });
476
- }
477
- // Default package.json for workspace members
478
- return JSON.stringify({
479
- name: path.basename(path.dirname(pathStr)),
480
- });
481
- });
482
- }
483
- describe('installPackages()', () => {
484
- describe('workspace detection', () => {
485
- it('should return workspace root when directory matches workspace pattern', async () => {
486
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
487
- await installPackages({
488
- packages: ['lodash'],
489
- installLocations: [pkg1Dir],
490
- });
491
- expect(execMock).toHaveBeenCalledTimes(1);
492
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-a lodash`, { cwd: workspaceRoot });
493
- });
494
- it('should handle packages without workspaces field as non-workspace', async () => {
495
- mockedWalk.mockResolvedValue([
496
- path.join(standaloneDir, 'package.json'),
497
- ]);
498
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
499
- await installPackages({
500
- packages: ['react'],
501
- installLocations: [standaloneDir],
502
- });
503
- expect(execMock).toHaveBeenCalledTimes(1);
504
- expect(execMock).toHaveBeenCalledWith('npm install react', {
505
- cwd: standaloneDir,
506
- });
507
- });
508
- it('should handle empty workspaces array as non-workspace', async () => {
509
- mockedWalk.mockResolvedValue([
510
- path.join(workspaceRoot, 'package.json'),
511
- ]);
512
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({
513
- name: 'workspace-root',
514
- workspaces: [],
515
- }));
516
- await installPackages({
517
- packages: ['test'],
518
- installLocations: [workspaceRoot],
519
- });
520
- expect(execMock).toHaveBeenCalledTimes(1);
521
- expect(execMock).toHaveBeenCalledWith('npm install test', {
522
- cwd: workspaceRoot,
523
- });
524
- });
525
- it('should match nested glob patterns like packages/**/*', async () => {
526
- const nestedDir = path.join(workspaceRoot, 'packages', 'frontend', 'ui');
527
- mockWorkspaceSetup(workspaceRoot, ['packages/**/*'], [nestedDir]);
528
- await installPackages({
529
- packages: ['axios'],
530
- installLocations: [nestedDir],
531
- });
532
- expect(execMock).toHaveBeenCalledTimes(1);
533
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/frontend/ui axios`, { cwd: workspaceRoot });
534
- });
535
- it('should match against multiple workspace patterns', async () => {
536
- const appsDir = path.join(workspaceRoot, 'apps', 'web');
537
- mockWorkspaceSetup(workspaceRoot, ['packages/*', 'apps/*'], [pkg1Dir, appsDir]);
538
- await installPackages({
539
- packages: ['typescript'],
540
- installLocations: [pkg1Dir, appsDir],
541
- });
542
- expect(execMock).toHaveBeenCalledTimes(2);
543
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-a typescript`, { cwd: workspaceRoot });
544
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=apps/web typescript`, { cwd: workspaceRoot });
545
- });
546
- it('should return null when directory does not match workspace patterns', async () => {
547
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], []);
548
- mockedWalk.mockResolvedValue([
549
- path.join(workspaceRoot, 'package.json'),
550
- path.join(standaloneDir, 'package.json'),
551
- ]);
552
- mockedFs.readFileSync.mockImplementation(filePath => {
553
- const pathStr = filePath.toString();
554
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
555
- return JSON.stringify({
556
- name: 'workspace',
557
- workspaces: ['packages/*'],
558
- });
559
- }
560
- return JSON.stringify({ name: 'standalone' });
561
- });
562
- await installPackages({
563
- packages: ['test'],
564
- installLocations: [standaloneDir],
565
- });
566
- expect(execMock).toHaveBeenCalledTimes(1);
567
- expect(execMock).toHaveBeenCalledWith('npm install test', {
568
- cwd: standaloneDir,
569
- });
570
- });
571
- });
572
- describe('installation behavior without specific packages', () => {
573
- it('should install at workspace root when no packages and directory is in workspace', async () => {
574
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir, pkg2Dir]);
575
- await installPackages({
576
- installLocations: [pkg1Dir, pkg2Dir],
577
- });
578
- // Should install once at workspace root
579
- expect(execMock).toHaveBeenCalledTimes(1);
580
- expect(execMock).toHaveBeenCalledWith('npm install ', {
581
- cwd: workspaceRoot,
582
- });
583
- });
584
- it('should install in each directory when not in workspace', async () => {
585
- const dir1 = path.join(projectDir, 'dir1');
586
- const dir2 = path.join(projectDir, 'dir2');
587
- mockedWalk.mockResolvedValue([
588
- path.join(dir1, 'package.json'),
589
- path.join(dir2, 'package.json'),
590
- ]);
591
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
592
- await installPackages({
593
- installLocations: [dir1, dir2],
594
- });
595
- expect(execMock).toHaveBeenCalledTimes(2);
596
- expect(execMock).toHaveBeenCalledWith('npm install ', { cwd: dir1 });
597
- expect(execMock).toHaveBeenCalledWith('npm install ', { cwd: dir2 });
598
- });
599
- it('should install at workspace roots and non-workspace directories', async () => {
600
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
601
- mockedWalk.mockResolvedValue([
602
- path.join(workspaceRoot, 'package.json'),
603
- path.join(pkg1Dir, 'package.json'),
604
- path.join(standaloneDir, 'package.json'),
605
- ]);
606
- mockedFs.readFileSync.mockImplementation(filePath => {
607
- const pathStr = filePath.toString();
608
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
609
- return JSON.stringify({
610
- name: 'workspace',
611
- workspaces: ['packages/*'],
612
- });
613
- }
614
- return JSON.stringify({ name: 'pkg' });
615
- });
616
- await installPackages({
617
- installLocations: [pkg1Dir, standaloneDir],
618
- });
619
- expect(execMock).toHaveBeenCalledTimes(2);
620
- expect(execMock).toHaveBeenCalledWith('npm install ', {
621
- cwd: workspaceRoot,
622
- });
623
- expect(execMock).toHaveBeenCalledWith('npm install ', {
624
- cwd: standaloneDir,
625
- });
626
- });
627
- });
628
- describe('installation behavior with specific packages', () => {
629
- it('should use --workspace flag when installing packages in workspace', async () => {
630
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
631
- await installPackages({
632
- packages: ['lodash', 'axios'],
633
- installLocations: [pkg1Dir],
634
- });
635
- expect(execMock).toHaveBeenCalledTimes(1);
636
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-a lodash axios`, { cwd: workspaceRoot });
637
- });
638
- it('should install packages normally in non-workspace directories', async () => {
639
- mockedWalk.mockResolvedValue([
640
- path.join(standaloneDir, 'package.json'),
641
- ]);
642
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
643
- await installPackages({
644
- packages: ['react', 'react-dom'],
645
- installLocations: [standaloneDir],
646
- });
647
- expect(execMock).toHaveBeenCalledTimes(1);
648
- expect(execMock).toHaveBeenCalledWith('npm install react react-dom', {
649
- cwd: standaloneDir,
650
- });
651
- });
652
- it('should handle multiple workspace packages with separate commands', async () => {
653
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir, pkg2Dir]);
654
- await installPackages({
655
- packages: ['typescript'],
656
- installLocations: [pkg1Dir, pkg2Dir],
657
- });
658
- expect(execMock).toHaveBeenCalledTimes(2);
659
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-a typescript`, { cwd: workspaceRoot });
660
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-b typescript`, { cwd: workspaceRoot });
661
- });
662
- it('should handle mixed workspace and non-workspace installations', async () => {
663
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
664
- mockedWalk.mockResolvedValue([
665
- path.join(workspaceRoot, 'package.json'),
666
- path.join(pkg1Dir, 'package.json'),
667
- path.join(standaloneDir, 'package.json'),
668
- ]);
669
- mockedFs.readFileSync.mockImplementation(filePath => {
670
- const pathStr = filePath.toString();
671
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
672
- return JSON.stringify({
673
- name: 'workspace',
674
- workspaces: ['packages/*'],
675
- });
676
- }
677
- return JSON.stringify({ name: 'pkg' });
678
- });
679
- await installPackages({
680
- packages: ['lodash'],
681
- installLocations: [pkg1Dir, standaloneDir],
682
- });
683
- expect(execMock).toHaveBeenCalledTimes(2);
684
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/pkg-a lodash`, { cwd: workspaceRoot });
685
- expect(execMock).toHaveBeenCalledWith('npm install lodash', {
686
- cwd: standaloneDir,
687
- });
688
- });
689
- });
690
- describe('command construction', () => {
691
- it('should combine --save-dev and --workspace flags correctly', async () => {
692
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
693
- await installPackages({
694
- packages: ['eslint', 'prettier'],
695
- installLocations: [pkg1Dir],
696
- dev: true,
697
- });
698
- expect(execMock).toHaveBeenCalledTimes(1);
699
- expect(execMock).toHaveBeenCalledWith(`npm install --save-dev --workspace=packages/pkg-a eslint prettier`, { cwd: workspaceRoot });
700
- });
701
- it('should not use --save-dev flag when dev is true but no packages provided', async () => {
702
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
703
- await installPackages({
704
- installLocations: [pkg1Dir],
705
- dev: true,
706
- });
707
- expect(execMock).toHaveBeenCalledTimes(1);
708
- expect(execMock).toHaveBeenCalledWith('npm install ', {
709
- cwd: workspaceRoot,
710
- });
711
- });
712
- it('should execute npm commands in workspace root directory for workspace packages', async () => {
713
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
714
- await installPackages({
715
- packages: ['test'],
716
- installLocations: [pkg1Dir],
717
- });
718
- expect(execMock).toHaveBeenCalledWith(expect.any(String), {
719
- cwd: workspaceRoot,
720
- });
721
- });
722
- it('should execute npm commands in package directory for non-workspace packages', async () => {
723
- mockedWalk.mockResolvedValue([
724
- path.join(standaloneDir, 'package.json'),
725
- ]);
726
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
727
- await installPackages({
728
- packages: ['test'],
729
- installLocations: [standaloneDir],
730
- });
731
- expect(execMock).toHaveBeenCalledWith(expect.any(String), {
732
- cwd: standaloneDir,
733
- });
734
- });
735
- });
736
- describe('edge cases', () => {
737
- it('should correctly calculate relative paths for deeply nested packages', async () => {
738
- const deeplyNestedDir = path.join(workspaceRoot, 'packages', 'frontend', 'components', 'ui');
739
- mockWorkspaceSetup(workspaceRoot, ['packages/**/*'], [deeplyNestedDir]);
740
- await installPackages({
741
- packages: ['test'],
742
- installLocations: [deeplyNestedDir],
743
- });
744
- expect(execMock).toHaveBeenCalledWith(`npm install --workspace=packages/frontend/components/ui test`, { cwd: workspaceRoot });
745
- });
746
- it('should handle invalid package.json gracefully', async () => {
747
- mockedWalk.mockResolvedValue([
748
- path.join(workspaceRoot, 'package.json'),
749
- ]);
750
- mockedFs.readFileSync.mockReturnValue('invalid json{');
751
- await installPackages({
752
- packages: ['test'],
753
- installLocations: [workspaceRoot],
754
- });
755
- // Should treat as non-workspace since parsing fails
756
- expect(execMock).toHaveBeenCalledWith('npm install test', {
757
- cwd: workspaceRoot,
758
- });
759
- });
760
- it('should show spinner for package directory not workspace root', async () => {
761
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
762
- await installPackages({
763
- packages: ['lodash'],
764
- installLocations: [pkg1Dir],
765
- });
766
- expect(SpinniesManager.add).toHaveBeenCalledWith(`installingDependencies-${pkg1Dir}`, expect.objectContaining({
767
- text: expect.stringContaining(path.relative(process.cwd(), pkg1Dir)),
768
- }));
769
- expect(SpinniesManager.succeed).toHaveBeenCalledWith(`installingDependencies-${pkg1Dir}`, expect.any(Object));
770
- });
771
- it('should report errors with correct directory even when using workspace root', async () => {
772
- execMock = vi.fn().mockImplementation(() => {
773
- throw new Error('Installation failed');
774
- });
775
- util.promisify = mockedPromisify(execMock);
776
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
777
- mockedFs.existsSync.mockReturnValue(true);
778
- await expect(installPackages({
779
- packages: ['test'],
780
- installLocations: [pkg1Dir],
781
- })).rejects.toThrowError();
782
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`installingDependencies-${pkg1Dir}`, expect.any(Object));
783
- });
784
- });
785
- });
786
- describe('updatePackages()', () => {
787
- describe('workspace detection', () => {
788
- it('should return workspace root when directory matches workspace pattern', async () => {
789
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
790
- await updatePackages({
791
- packages: ['lodash'],
792
- installLocations: [pkg1Dir],
793
- });
794
- expect(execMock).toHaveBeenCalledTimes(1);
795
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-a lodash`, { cwd: workspaceRoot });
796
- });
797
- it('should handle packages without workspaces field as non-workspace', async () => {
798
- mockedWalk.mockResolvedValue([
799
- path.join(standaloneDir, 'package.json'),
800
- ]);
801
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
802
- await updatePackages({
803
- packages: ['react'],
804
- installLocations: [standaloneDir],
805
- });
806
- expect(execMock).toHaveBeenCalledTimes(1);
807
- expect(execMock).toHaveBeenCalledWith('npm update react', {
808
- cwd: standaloneDir,
809
- });
810
- });
811
- it('should handle empty workspaces array as non-workspace', async () => {
812
- mockedWalk.mockResolvedValue([
813
- path.join(workspaceRoot, 'package.json'),
814
- ]);
815
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({
816
- name: 'workspace-root',
817
- workspaces: [],
818
- }));
819
- await updatePackages({
820
- packages: ['test'],
821
- installLocations: [workspaceRoot],
822
- });
823
- expect(execMock).toHaveBeenCalledTimes(1);
824
- expect(execMock).toHaveBeenCalledWith('npm update test', {
825
- cwd: workspaceRoot,
826
- });
827
- });
828
- it('should match nested glob patterns like packages/**/*', async () => {
829
- const nestedDir = path.join(workspaceRoot, 'packages', 'frontend', 'ui');
830
- mockWorkspaceSetup(workspaceRoot, ['packages/**/*'], [nestedDir]);
831
- await updatePackages({
832
- packages: ['axios'],
833
- installLocations: [nestedDir],
834
- });
835
- expect(execMock).toHaveBeenCalledTimes(1);
836
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/frontend/ui axios`, { cwd: workspaceRoot });
837
- });
838
- it('should match against multiple workspace patterns', async () => {
839
- const appsDir = path.join(workspaceRoot, 'apps', 'web');
840
- mockWorkspaceSetup(workspaceRoot, ['packages/*', 'apps/*'], [pkg1Dir, appsDir]);
841
- await updatePackages({
842
- packages: ['typescript'],
843
- installLocations: [pkg1Dir, appsDir],
844
- });
845
- expect(execMock).toHaveBeenCalledTimes(2);
846
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-a typescript`, { cwd: workspaceRoot });
847
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=apps/web typescript`, { cwd: workspaceRoot });
848
- });
849
- it('should return null when directory does not match workspace patterns', async () => {
850
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], []);
851
- mockedWalk.mockResolvedValue([
852
- path.join(workspaceRoot, 'package.json'),
853
- path.join(standaloneDir, 'package.json'),
854
- ]);
855
- mockedFs.readFileSync.mockImplementation(filePath => {
856
- const pathStr = filePath.toString();
857
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
858
- return JSON.stringify({
859
- name: 'workspace',
860
- workspaces: ['packages/*'],
861
- });
862
- }
863
- return JSON.stringify({ name: 'standalone' });
864
- });
865
- await updatePackages({
866
- packages: ['test'],
867
- installLocations: [standaloneDir],
868
- });
869
- expect(execMock).toHaveBeenCalledTimes(1);
870
- expect(execMock).toHaveBeenCalledWith('npm update test', {
871
- cwd: standaloneDir,
872
- });
873
- });
874
- });
875
- describe('update behavior without specific packages', () => {
876
- it('should update at workspace root when no packages and directory is in workspace', async () => {
877
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir, pkg2Dir]);
878
- await updatePackages({
879
- installLocations: [pkg1Dir, pkg2Dir],
880
- });
881
- expect(execMock).toHaveBeenCalledTimes(1);
882
- expect(execMock).toHaveBeenCalledWith('npm update ', {
883
- cwd: workspaceRoot,
884
- });
885
- });
886
- it('should update in each directory when not in workspace', async () => {
887
- const dir1 = path.join(projectDir, 'dir1');
888
- const dir2 = path.join(projectDir, 'dir2');
889
- mockedWalk.mockResolvedValue([
890
- path.join(dir1, 'package.json'),
891
- path.join(dir2, 'package.json'),
892
- ]);
893
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
894
- await updatePackages({
895
- installLocations: [dir1, dir2],
896
- });
897
- expect(execMock).toHaveBeenCalledTimes(2);
898
- expect(execMock).toHaveBeenCalledWith('npm update ', { cwd: dir1 });
899
- expect(execMock).toHaveBeenCalledWith('npm update ', { cwd: dir2 });
900
- });
901
- it('should update at workspace roots and non-workspace directories', async () => {
902
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
903
- mockedWalk.mockResolvedValue([
904
- path.join(workspaceRoot, 'package.json'),
905
- path.join(pkg1Dir, 'package.json'),
906
- path.join(standaloneDir, 'package.json'),
907
- ]);
908
- mockedFs.readFileSync.mockImplementation(filePath => {
909
- const pathStr = filePath.toString();
910
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
911
- return JSON.stringify({
912
- name: 'workspace',
913
- workspaces: ['packages/*'],
914
- });
915
- }
916
- return JSON.stringify({ name: 'pkg' });
917
- });
918
- await updatePackages({
919
- installLocations: [pkg1Dir, standaloneDir],
920
- });
921
- expect(execMock).toHaveBeenCalledTimes(2);
922
- expect(execMock).toHaveBeenCalledWith('npm update ', {
923
- cwd: workspaceRoot,
924
- });
925
- expect(execMock).toHaveBeenCalledWith('npm update ', {
926
- cwd: standaloneDir,
927
- });
928
- });
929
- });
930
- describe('update behavior with specific packages', () => {
931
- it('should use --workspace flag when updating packages in workspace', async () => {
932
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
933
- await updatePackages({
934
- packages: ['lodash', 'axios'],
935
- installLocations: [pkg1Dir],
936
- });
937
- expect(execMock).toHaveBeenCalledTimes(1);
938
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-a lodash axios`, { cwd: workspaceRoot });
939
- });
940
- it('should update packages normally in non-workspace directories', async () => {
941
- mockedWalk.mockResolvedValue([
942
- path.join(standaloneDir, 'package.json'),
943
- ]);
944
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
945
- await updatePackages({
946
- packages: ['react', 'react-dom'],
947
- installLocations: [standaloneDir],
948
- });
949
- expect(execMock).toHaveBeenCalledTimes(1);
950
- expect(execMock).toHaveBeenCalledWith('npm update react react-dom', {
951
- cwd: standaloneDir,
952
- });
953
- });
954
- it('should handle multiple workspace packages with separate commands', async () => {
955
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir, pkg2Dir]);
956
- await updatePackages({
957
- packages: ['typescript'],
958
- installLocations: [pkg1Dir, pkg2Dir],
959
- });
960
- expect(execMock).toHaveBeenCalledTimes(2);
961
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-a typescript`, { cwd: workspaceRoot });
962
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-b typescript`, { cwd: workspaceRoot });
963
- });
964
- it('should handle mixed workspace and non-workspace updates', async () => {
965
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
966
- mockedWalk.mockResolvedValue([
967
- path.join(workspaceRoot, 'package.json'),
968
- path.join(pkg1Dir, 'package.json'),
969
- path.join(standaloneDir, 'package.json'),
970
- ]);
971
- mockedFs.readFileSync.mockImplementation(filePath => {
972
- const pathStr = filePath.toString();
973
- if (pathStr === path.join(workspaceRoot, 'package.json')) {
974
- return JSON.stringify({
975
- name: 'workspace',
976
- workspaces: ['packages/*'],
977
- });
978
- }
979
- return JSON.stringify({ name: 'pkg' });
980
- });
981
- await updatePackages({
982
- packages: ['lodash'],
983
- installLocations: [pkg1Dir, standaloneDir],
984
- });
985
- expect(execMock).toHaveBeenCalledTimes(2);
986
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/pkg-a lodash`, { cwd: workspaceRoot });
987
- expect(execMock).toHaveBeenCalledWith('npm update lodash', {
988
- cwd: standaloneDir,
989
- });
990
- });
991
- });
992
- describe('command construction', () => {
993
- it('should execute npm commands in workspace root directory for workspace packages', async () => {
994
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
995
- await updatePackages({
996
- packages: ['test'],
997
- installLocations: [pkg1Dir],
998
- });
999
- expect(execMock).toHaveBeenCalledWith(expect.any(String), {
1000
- cwd: workspaceRoot,
1001
- });
1002
- });
1003
- it('should execute npm commands in package directory for non-workspace packages', async () => {
1004
- mockedWalk.mockResolvedValue([
1005
- path.join(standaloneDir, 'package.json'),
1006
- ]);
1007
- mockedFs.readFileSync.mockReturnValue(JSON.stringify({ name: 'standalone' }));
1008
- await updatePackages({
1009
- packages: ['test'],
1010
- installLocations: [standaloneDir],
1011
- });
1012
- expect(execMock).toHaveBeenCalledWith(expect.any(String), {
1013
- cwd: standaloneDir,
1014
- });
1015
- });
1016
- });
1017
- describe('edge cases', () => {
1018
- it('should correctly calculate relative paths for deeply nested packages', async () => {
1019
- const deeplyNestedDir = path.join(workspaceRoot, 'packages', 'frontend', 'components', 'ui');
1020
- mockWorkspaceSetup(workspaceRoot, ['packages/**/*'], [deeplyNestedDir]);
1021
- await updatePackages({
1022
- packages: ['test'],
1023
- installLocations: [deeplyNestedDir],
1024
- });
1025
- expect(execMock).toHaveBeenCalledWith(`npm update --workspace=packages/frontend/components/ui test`, { cwd: workspaceRoot });
1026
- });
1027
- it('should handle invalid package.json gracefully', async () => {
1028
- mockedWalk.mockResolvedValue([
1029
- path.join(workspaceRoot, 'package.json'),
1030
- ]);
1031
- mockedFs.readFileSync.mockReturnValue('invalid json{');
1032
- await updatePackages({
1033
- packages: ['test'],
1034
- installLocations: [workspaceRoot],
1035
- });
1036
- expect(execMock).toHaveBeenCalledWith('npm update test', {
1037
- cwd: workspaceRoot,
1038
- });
1039
- });
1040
- it('should show spinner for package directory not workspace root', async () => {
1041
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
1042
- await updatePackages({
1043
- packages: ['lodash'],
1044
- installLocations: [pkg1Dir],
1045
- });
1046
- expect(SpinniesManager.add).toHaveBeenCalledWith(`updatingDependencies-${pkg1Dir}`, expect.objectContaining({
1047
- text: expect.stringContaining(path.relative(process.cwd(), pkg1Dir)),
1048
- }));
1049
- expect(SpinniesManager.succeed).toHaveBeenCalledWith(`updatingDependencies-${pkg1Dir}`, expect.any(Object));
1050
- });
1051
- it('should report errors with correct directory even when using workspace root', async () => {
1052
- execMock = vi.fn().mockImplementation(() => {
1053
- throw new Error('Update failed');
1054
- });
1055
- util.promisify = mockedPromisify(execMock);
1056
- mockWorkspaceSetup(workspaceRoot, ['packages/*'], [pkg1Dir]);
1057
- mockedFs.existsSync.mockReturnValue(true);
1058
- await expect(updatePackages({
1059
- packages: ['test'],
1060
- installLocations: [pkg1Dir],
1061
- })).rejects.toThrowError();
1062
- expect(SpinniesManager.fail).toHaveBeenCalledWith(`updatingDependencies-${pkg1Dir}`, expect.any(Object));
1063
- });
1064
- });
1065
- });
1066
- });
1067
- });