@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/cache-client.js +55 -54
  3. package/dist/cjs/client/constants.js +7 -7
  4. package/dist/cjs/client/edge-proxy.js +24 -22
  5. package/dist/cjs/client/index.js +15 -15
  6. package/dist/cjs/client/models.js +2 -2
  7. package/dist/cjs/client/sitecore-client.js +421 -419
  8. package/dist/cjs/client/utils.js +47 -46
  9. package/dist/cjs/config/define-config.js +194 -193
  10. package/dist/cjs/config/index.js +7 -7
  11. package/dist/cjs/config/models.js +12 -11
  12. package/dist/cjs/config-cli/define-cli-config.js +23 -22
  13. package/dist/cjs/config-cli/index.js +7 -7
  14. package/dist/cjs/config-cli/models.js +8 -7
  15. package/dist/cjs/constants.js +49 -17
  16. package/dist/cjs/debug.js +48 -46
  17. package/dist/cjs/editing/codegen/index.js +14 -9
  18. package/dist/cjs/editing/codegen/preview.js +277 -193
  19. package/dist/cjs/editing/component-layout-service.js +62 -61
  20. package/dist/cjs/editing/design-library.js +183 -126
  21. package/dist/cjs/editing/editing-service.js +75 -74
  22. package/dist/cjs/editing/index.js +33 -27
  23. package/dist/cjs/editing/metadata.js +42 -42
  24. package/dist/cjs/editing/models.js +44 -38
  25. package/dist/cjs/editing/utils.js +108 -90
  26. package/dist/cjs/form/form.js +81 -78
  27. package/dist/cjs/form/index.js +7 -7
  28. package/dist/cjs/graphql-request-client.js +108 -107
  29. package/dist/cjs/i18n/dictionary-service.js +122 -121
  30. package/dist/cjs/i18n/index.js +7 -7
  31. package/dist/cjs/i18n/utils.js +16 -15
  32. package/dist/cjs/index.js +60 -60
  33. package/dist/cjs/layout/content-styles.js +72 -71
  34. package/dist/cjs/layout/index.js +24 -24
  35. package/dist/cjs/layout/layout-service.js +62 -57
  36. package/dist/cjs/layout/models.js +39 -34
  37. package/dist/cjs/layout/themes.js +76 -75
  38. package/dist/cjs/layout/utils.js +117 -110
  39. package/dist/cjs/media/index.js +38 -38
  40. package/dist/cjs/media/media-api.js +100 -96
  41. package/dist/cjs/models.js +2 -2
  42. package/dist/cjs/native-fetcher.js +194 -179
  43. package/dist/cjs/personalize/index.js +15 -15
  44. package/dist/cjs/personalize/layout-personalizer.js +98 -97
  45. package/dist/cjs/personalize/personalize-service.js +98 -94
  46. package/dist/cjs/personalize/utils.js +143 -136
  47. package/dist/cjs/retries.js +43 -42
  48. package/dist/cjs/site/error-pages-service.js +65 -64
  49. package/dist/cjs/site/index.js +26 -26
  50. package/dist/cjs/site/models.js +2 -2
  51. package/dist/cjs/site/redirects-service.js +94 -81
  52. package/dist/cjs/site/robots-service.js +66 -65
  53. package/dist/cjs/site/site-resolver.js +73 -72
  54. package/dist/cjs/site/siteinfo-service.js +84 -80
  55. package/dist/cjs/site/sitemap-xml-service.js +84 -83
  56. package/dist/cjs/site/sitepath-service.js +165 -164
  57. package/dist/cjs/site/utils.js +55 -47
  58. package/dist/cjs/sitecore-service-base.js +36 -36
  59. package/dist/cjs/tools/auth/flow.js +65 -64
  60. package/dist/cjs/tools/auth/index.js +5 -5
  61. package/dist/cjs/tools/auth/models.js +2 -2
  62. package/dist/cjs/tools/auth/tenant-store.js +38 -38
  63. package/dist/cjs/tools/codegen/component-generation.js +52 -50
  64. package/dist/cjs/tools/codegen/extract-files.js +105 -107
  65. package/dist/cjs/tools/codegen/import-map.js +401 -349
  66. package/dist/cjs/tools/codegen/utils.js +418 -418
  67. package/dist/cjs/tools/generate-map.js +2 -2
  68. package/dist/cjs/tools/generateMetadata.js +36 -35
  69. package/dist/cjs/tools/generateSites.js +59 -58
  70. package/dist/cjs/tools/index.js +75 -73
  71. package/dist/cjs/tools/scaffold.js +60 -59
  72. package/dist/cjs/tools/templating/components.js +96 -266
  73. package/dist/cjs/tools/templating/index.js +11 -14
  74. package/dist/cjs/tools/templating/plugins.js +80 -78
  75. package/dist/cjs/tools/templating/utils.js +67 -66
  76. package/dist/cjs/utils/ensurePath.js +20 -20
  77. package/dist/cjs/utils/env.js +28 -27
  78. package/dist/cjs/utils/globalCache.js +55 -0
  79. package/dist/cjs/utils/index.js +26 -21
  80. package/dist/cjs/utils/is-server.js +11 -10
  81. package/dist/cjs/utils/normalize-url.js +5 -5
  82. package/dist/cjs/utils/timeout-promise.js +31 -31
  83. package/dist/cjs/utils/utils.js +254 -229
  84. package/dist/esm/cache-client.js +51 -50
  85. package/dist/esm/client/constants.js +4 -4
  86. package/dist/esm/client/edge-proxy.js +19 -17
  87. package/dist/esm/client/index.js +5 -5
  88. package/dist/esm/client/models.js +1 -1
  89. package/dist/esm/client/sitecore-client.js +414 -412
  90. package/dist/esm/client/utils.js +43 -42
  91. package/dist/esm/config/define-config.js +188 -187
  92. package/dist/esm/config/index.js +2 -2
  93. package/dist/esm/config/models.js +9 -8
  94. package/dist/esm/config-cli/define-cli-config.js +19 -18
  95. package/dist/esm/config-cli/index.js +2 -2
  96. package/dist/esm/config-cli/models.js +5 -4
  97. package/dist/esm/constants.js +46 -14
  98. package/dist/esm/debug.js +41 -39
  99. package/dist/esm/editing/codegen/index.js +1 -1
  100. package/dist/esm/editing/codegen/preview.js +263 -185
  101. package/dist/esm/editing/component-layout-service.js +55 -54
  102. package/dist/esm/editing/design-library.js +171 -117
  103. package/dist/esm/editing/editing-service.js +68 -67
  104. package/dist/esm/editing/index.js +6 -5
  105. package/dist/esm/editing/metadata.js +39 -39
  106. package/dist/esm/editing/models.js +41 -35
  107. package/dist/esm/editing/utils.js +98 -80
  108. package/dist/esm/form/form.js +72 -69
  109. package/dist/esm/form/index.js +1 -1
  110. package/dist/esm/graphql-request-client.js +101 -100
  111. package/dist/esm/i18n/dictionary-service.js +115 -114
  112. package/dist/esm/i18n/index.js +2 -2
  113. package/dist/esm/i18n/utils.js +13 -12
  114. package/dist/esm/index.js +13 -13
  115. package/dist/esm/layout/content-styles.js +64 -63
  116. package/dist/esm/layout/index.js +6 -6
  117. package/dist/esm/layout/layout-service.js +55 -50
  118. package/dist/esm/layout/models.js +36 -31
  119. package/dist/esm/layout/themes.js +71 -70
  120. package/dist/esm/layout/utils.js +109 -102
  121. package/dist/esm/media/index.js +2 -2
  122. package/dist/esm/media/media-api.js +90 -86
  123. package/dist/esm/models.js +1 -1
  124. package/dist/esm/native-fetcher.js +187 -172
  125. package/dist/esm/personalize/index.js +3 -3
  126. package/dist/esm/personalize/layout-personalizer.js +93 -92
  127. package/dist/esm/personalize/personalize-service.js +91 -87
  128. package/dist/esm/personalize/utils.js +135 -128
  129. package/dist/esm/retries.js +39 -38
  130. package/dist/esm/site/error-pages-service.js +58 -57
  131. package/dist/esm/site/index.js +8 -8
  132. package/dist/esm/site/models.js +1 -1
  133. package/dist/esm/site/redirects-service.js +87 -74
  134. package/dist/esm/site/robots-service.js +59 -58
  135. package/dist/esm/site/site-resolver.js +69 -68
  136. package/dist/esm/site/siteinfo-service.js +77 -73
  137. package/dist/esm/site/sitemap-xml-service.js +77 -76
  138. package/dist/esm/site/sitepath-service.js +157 -156
  139. package/dist/esm/site/utils.js +49 -41
  140. package/dist/esm/sitecore-service-base.js +29 -29
  141. package/dist/esm/tools/auth/flow.js +62 -61
  142. package/dist/esm/tools/auth/index.js +1 -1
  143. package/dist/esm/tools/auth/models.js +1 -1
  144. package/dist/esm/tools/auth/tenant-store.js +35 -35
  145. package/dist/esm/tools/codegen/component-generation.js +44 -42
  146. package/dist/esm/tools/codegen/extract-files.js +99 -101
  147. package/dist/esm/tools/codegen/import-map.js +358 -306
  148. package/dist/esm/tools/codegen/utils.js +373 -373
  149. package/dist/esm/tools/generate-map.js +1 -1
  150. package/dist/esm/tools/generateMetadata.js +29 -28
  151. package/dist/esm/tools/generateSites.js +52 -51
  152. package/dist/esm/tools/index.js +28 -27
  153. package/dist/esm/tools/scaffold.js +52 -51
  154. package/dist/esm/tools/templating/components.js +59 -223
  155. package/dist/esm/tools/templating/index.js +3 -3
  156. package/dist/esm/tools/templating/plugins.js +72 -70
  157. package/dist/esm/tools/templating/utils.js +59 -58
  158. package/dist/esm/utils/ensurePath.js +13 -13
  159. package/dist/esm/utils/env.js +24 -23
  160. package/dist/esm/utils/globalCache.js +49 -0
  161. package/dist/esm/utils/index.js +4 -3
  162. package/dist/esm/utils/is-server.js +9 -8
  163. package/dist/esm/utils/normalize-url.js +1 -1
  164. package/dist/esm/utils/timeout-promise.js +28 -28
  165. package/dist/esm/utils/utils.js +238 -213
  166. package/package.json +73 -5
  167. package/types/cache-client.d.ts +68 -64
  168. package/types/cache-client.d.ts.map +1 -0
  169. package/types/client/constants.d.ts +5 -4
  170. package/types/client/constants.d.ts.map +1 -0
  171. package/types/client/edge-proxy.d.ts +18 -15
  172. package/types/client/edge-proxy.d.ts.map +1 -0
  173. package/types/client/index.d.ts +8 -7
  174. package/types/client/index.d.ts.map +1 -0
  175. package/types/client/models.d.ts +21 -19
  176. package/types/client/models.d.ts.map +1 -0
  177. package/types/client/sitecore-client.d.ts +338 -327
  178. package/types/client/sitecore-client.d.ts.map +1 -0
  179. package/types/client/utils.d.ts +15 -9
  180. package/types/client/utils.d.ts.map +1 -0
  181. package/types/config/define-config.d.ts +20 -18
  182. package/types/config/define-config.d.ts.map +1 -0
  183. package/types/config/index.d.ts +3 -2
  184. package/types/config/index.d.ts.map +1 -0
  185. package/types/config/models.d.ts +287 -268
  186. package/types/config/models.d.ts.map +1 -0
  187. package/types/config-cli/define-cli-config.d.ts +9 -7
  188. package/types/config-cli/define-cli-config.d.ts.map +1 -0
  189. package/types/config-cli/index.d.ts +3 -2
  190. package/types/config-cli/index.d.ts.map +1 -0
  191. package/types/config-cli/models.d.ts +6 -4
  192. package/types/config-cli/models.d.ts.map +1 -0
  193. package/types/constants.d.ts +44 -11
  194. package/types/constants.d.ts.map +1 -0
  195. package/types/debug.d.ts +35 -28
  196. package/types/debug.d.ts.map +1 -0
  197. package/types/editing/codegen/index.d.ts +2 -1
  198. package/types/editing/codegen/index.d.ts.map +1 -0
  199. package/types/editing/codegen/preview.d.ts +256 -195
  200. package/types/editing/codegen/preview.d.ts.map +1 -0
  201. package/types/editing/component-layout-service.d.ts +84 -80
  202. package/types/editing/component-layout-service.d.ts.map +1 -0
  203. package/types/editing/design-library.d.ts +111 -63
  204. package/types/editing/design-library.d.ts.map +1 -0
  205. package/types/editing/editing-service.d.ts +72 -62
  206. package/types/editing/editing-service.d.ts.map +1 -0
  207. package/types/editing/index.d.ts +7 -6
  208. package/types/editing/index.d.ts.map +1 -0
  209. package/types/editing/metadata.d.ts +8 -7
  210. package/types/editing/metadata.d.ts.map +1 -0
  211. package/types/editing/models.d.ts +103 -92
  212. package/types/editing/models.d.ts.map +1 -0
  213. package/types/editing/utils.d.ts +91 -74
  214. package/types/editing/utils.d.ts.map +1 -0
  215. package/types/form/form.d.ts +25 -21
  216. package/types/form/form.d.ts.map +1 -0
  217. package/types/form/index.d.ts +2 -1
  218. package/types/form/index.d.ts.map +1 -0
  219. package/types/graphql-request-client.d.ts +112 -105
  220. package/types/graphql-request-client.d.ts.map +1 -0
  221. package/types/i18n/dictionary-service.d.ts +135 -131
  222. package/types/i18n/dictionary-service.d.ts.map +1 -0
  223. package/types/i18n/index.d.ts +3 -2
  224. package/types/i18n/index.d.ts.map +1 -0
  225. package/types/i18n/utils.d.ts +9 -7
  226. package/types/i18n/utils.d.ts.map +1 -0
  227. package/types/index.d.ts +13 -12
  228. package/types/index.d.ts.map +1 -0
  229. package/types/layout/content-styles.d.ts +20 -18
  230. package/types/layout/content-styles.d.ts.map +1 -0
  231. package/types/layout/index.d.ts +6 -5
  232. package/types/layout/index.d.ts.map +1 -0
  233. package/types/layout/layout-service.d.ts +45 -35
  234. package/types/layout/layout-service.d.ts.map +1 -0
  235. package/types/layout/models.d.ts +174 -151
  236. package/types/layout/models.d.ts.map +1 -0
  237. package/types/layout/themes.d.ts +13 -11
  238. package/types/layout/themes.d.ts.map +1 -0
  239. package/types/layout/utils.d.ts +56 -41
  240. package/types/layout/utils.d.ts.map +1 -0
  241. package/types/media/index.d.ts +3 -2
  242. package/types/media/index.d.ts.map +1 -0
  243. package/types/media/media-api.d.ts +60 -55
  244. package/types/media/media-api.d.ts.map +1 -0
  245. package/types/models.d.ts +94 -84
  246. package/types/models.d.ts.map +1 -0
  247. package/types/native-fetcher.d.ts +124 -114
  248. package/types/native-fetcher.d.ts.map +1 -0
  249. package/types/personalize/index.d.ts +4 -3
  250. package/types/personalize/index.d.ts.map +1 -0
  251. package/types/personalize/layout-personalizer.d.ts +29 -27
  252. package/types/personalize/layout-personalizer.d.ts.map +1 -0
  253. package/types/personalize/personalize-service.d.ts +90 -80
  254. package/types/personalize/personalize-service.d.ts.map +1 -0
  255. package/types/personalize/utils.d.ts +78 -69
  256. package/types/personalize/utils.d.ts.map +1 -0
  257. package/types/retries.d.ts +26 -24
  258. package/types/retries.d.ts.map +1 -0
  259. package/types/site/error-pages-service.d.ts +64 -57
  260. package/types/site/error-pages-service.d.ts.map +1 -0
  261. package/types/site/index.d.ts +10 -9
  262. package/types/site/index.d.ts.map +1 -0
  263. package/types/site/models.d.ts +23 -18
  264. package/types/site/models.d.ts.map +1 -0
  265. package/types/site/redirects-service.d.ts +92 -69
  266. package/types/site/redirects-service.d.ts.map +1 -0
  267. package/types/site/robots-service.d.ts +57 -50
  268. package/types/site/robots-service.d.ts.map +1 -0
  269. package/types/site/site-resolver.d.ts +28 -26
  270. package/types/site/site-resolver.d.ts.map +1 -0
  271. package/types/site/siteinfo-service.d.ts +65 -52
  272. package/types/site/siteinfo-service.d.ts.map +1 -0
  273. package/types/site/sitemap-xml-service.d.ts +63 -56
  274. package/types/site/sitemap-xml-service.d.ts.map +1 -0
  275. package/types/site/sitepath-service.d.ts +137 -134
  276. package/types/site/sitepath-service.d.ts.map +1 -0
  277. package/types/site/utils.d.ts +41 -28
  278. package/types/site/utils.d.ts.map +1 -0
  279. package/types/sitecore-service-base.d.ts +31 -30
  280. package/types/sitecore-service-base.d.ts.map +1 -0
  281. package/types/tools/auth/flow.d.ts +29 -27
  282. package/types/tools/auth/flow.d.ts.map +1 -0
  283. package/types/tools/auth/index.d.ts +2 -1
  284. package/types/tools/auth/index.d.ts.map +1 -0
  285. package/types/tools/auth/models.d.ts +35 -33
  286. package/types/tools/auth/models.d.ts.map +1 -0
  287. package/types/tools/auth/tenant-store.d.ts +12 -11
  288. package/types/tools/auth/tenant-store.d.ts.map +1 -0
  289. package/types/tools/codegen/component-generation.d.ts +50 -47
  290. package/types/tools/codegen/component-generation.d.ts.map +1 -0
  291. package/types/tools/codegen/extract-files.d.ts +24 -22
  292. package/types/tools/codegen/extract-files.d.ts.map +1 -0
  293. package/types/tools/codegen/import-map.d.ts +103 -70
  294. package/types/tools/codegen/import-map.d.ts.map +1 -0
  295. package/types/tools/codegen/utils.d.ts +76 -75
  296. package/types/tools/codegen/utils.d.ts.map +1 -0
  297. package/types/tools/generate-map.d.ts +36 -26
  298. package/types/tools/generate-map.d.ts.map +1 -0
  299. package/types/tools/generateMetadata.d.ts +24 -22
  300. package/types/tools/generateMetadata.d.ts.map +1 -0
  301. package/types/tools/generateSites.d.ts +25 -22
  302. package/types/tools/generateSites.d.ts.map +1 -0
  303. package/types/tools/index.d.ts +22 -20
  304. package/types/tools/index.d.ts.map +1 -0
  305. package/types/tools/scaffold.d.ts +27 -25
  306. package/types/tools/scaffold.d.ts.map +1 -0
  307. package/types/tools/templating/components.d.ts +104 -103
  308. package/types/tools/templating/components.d.ts.map +1 -0
  309. package/types/tools/templating/index.d.ts +4 -3
  310. package/types/tools/templating/index.d.ts.map +1 -0
  311. package/types/tools/templating/plugins.d.ts +71 -67
  312. package/types/tools/templating/plugins.d.ts.map +1 -0
  313. package/types/tools/templating/utils.d.ts +42 -40
  314. package/types/tools/templating/utils.d.ts.map +1 -0
  315. package/types/utils/ensurePath.d.ts +7 -6
  316. package/types/utils/ensurePath.d.ts.map +1 -0
  317. package/types/utils/env.d.ts +9 -7
  318. package/types/utils/env.d.ts.map +1 -0
  319. package/types/utils/globalCache.d.ts +37 -0
  320. package/types/utils/globalCache.d.ts.map +1 -0
  321. package/types/utils/index.d.ts +5 -3
  322. package/types/utils/index.d.ts.map +1 -0
  323. package/types/utils/is-server.d.ts +8 -6
  324. package/types/utils/is-server.d.ts.map +1 -0
  325. package/types/utils/normalize-url.d.ts +2 -1
  326. package/types/utils/normalize-url.d.ts.map +1 -0
  327. package/types/utils/timeout-promise.d.ts +18 -17
  328. package/types/utils/timeout-promise.d.ts.map +1 -0
  329. package/types/utils/utils.d.ts +104 -79
  330. package/types/utils/utils.d.ts.map +1 -0
  331. package/client.js +0 -1
  332. package/codegen.js +0 -1
  333. package/config-cli.js +0 -1
  334. package/config.js +0 -1
  335. package/editing.js +0 -1
  336. package/i18n.js +0 -1
  337. package/layout.js +0 -1
  338. package/media.js +0 -1
  339. package/personalize.js +0 -1
  340. package/site.js +0 -1
  341. package/tools.js +0 -1
  342. package/utils.js +0 -1
@@ -1,373 +1,373 @@
1
- /* eslint-disable jsdoc/require-jsdoc */
2
- import chalk from 'chalk';
3
- import path from 'path';
4
- import fs from 'fs';
5
- import * as ts from 'typescript';
6
- import debug from './../../debug';
7
- import { isBuiltin } from 'module';
8
- /**
9
- * Parse the generated component-map file and return all referenced modules
10
- * per map entry (handles both single identifiers and spread objects).
11
- * @param {string} appRoot path to the JSS app root
12
- * @param {string} componentMapPath path to the component map file
13
- * @returns map of component names and their respective import strings
14
- */
15
- export let resolveComponentImportFiles = _resolveComponentImportFiles;
16
- /**
17
- * Reads the named exports from a TypeScript file.
18
- * @param {ExtractedFile} filePath absolute path to a .ts/.tsx file
19
- * @returns {string[]} list of named exports found in the file
20
- */
21
- export let readNamedExports = _readNamedExports;
22
- /**
23
- * Sends the extracted code to the specified target URL.
24
- * @param {object} params - The parameters object.
25
- * @param {ExtractedFile} params.file - The file to be sent.
26
- * @param {string} params.token - The access token for authentication.
27
- * @param {string} params.targetUrl - The target URL to send the file to.
28
- * @param {Record<string, unknown>} [params.extraLabels] - Additional labels to include in the payload.
29
- * @returns {Promise<string | null>} - The path of the sent file or null if sending failed.
30
- */
31
- export let sendCode = _sendCode;
32
- export const utilsUnitMocks = {
33
- set xmCloudDeploy(mockImpl) {
34
- utils.xmCloudDeploy = mockImpl;
35
- },
36
- get xmCloudDeploy() {
37
- return _xmCloudDeploy;
38
- },
39
- set resolveComponentImportFiles(mockImpl) {
40
- resolveComponentImportFiles = mockImpl;
41
- },
42
- get resolveComponentImportFiles() {
43
- return _resolveComponentImportFiles;
44
- },
45
- set readNamedExports(mockImpl) {
46
- readNamedExports = mockImpl;
47
- },
48
- get readNamedExports() {
49
- return _readNamedExports;
50
- },
51
- set sendCode(mockImpl) {
52
- sendCode = mockImpl;
53
- },
54
- get sendCode() {
55
- return _sendCode;
56
- },
57
- };
58
- /**
59
- * Type of file to be sent to the mesh endpoint
60
- */
61
- export var ExtractedFileType;
62
- (function (ExtractedFileType) {
63
- ExtractedFileType["Component"] = "component";
64
- ExtractedFileType["Variant"] = "variant";
65
- ExtractedFileType["Json"] = "json";
66
- ExtractedFileType["PackageJson"] = "package.json";
67
- })(ExtractedFileType || (ExtractedFileType = {}));
68
- export const utils = {
69
- xmCloudDeploy: (...args) => _xmCloudDeploy(...args),
70
- };
71
- export const _xmCloudDeploy = () => !!process.env.SITECORE && !!process.env.SITECORE_BUILD;
72
- // workaround, Vercel does not have variables that are only accessible at build time
73
- const vercelDeploy = () => !!process.env.VERCEL && !process.env.VERCEL_REGION;
74
- const netlifyDeploy = () => !!process.env.NETLIFY && !!process.env.BUILD_ID;
75
- /**
76
- * Validates if the current operation is done in Vercel, Netlify or XMCloud
77
- * deploy context
78
- * @returns {boolean} - true if in deploy context, false otherwise
79
- */
80
- export function validateDeployContext() {
81
- return _xmCloudDeploy() || vercelDeploy() || netlifyDeploy();
82
- }
83
- /*
84
- * Load and parse the tsconfig.json file from the specified app path.
85
- */
86
- function loadCompilerOptions(appPathAbs) {
87
- const configPath = ts.findConfigFile(appPathAbs, ts.sys.fileExists, 'tsconfig.json');
88
- if (!configPath) {
89
- // Sane defaults if no tsconfig exists
90
- return {
91
- jsx: ts.JsxEmit.Preserve,
92
- allowJs: true,
93
- module: ts.ModuleKind.ESNext,
94
- moduleResolution: ts.ModuleResolutionKind.NodeNext,
95
- target: ts.ScriptTarget.ES2020,
96
- baseUrl: appPathAbs,
97
- noEmit: true,
98
- };
99
- }
100
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
101
- if (configFile.error) {
102
- throw new Error(`Error reading tsconfig at ${configPath}: ${configFile.error.messageText}`);
103
- }
104
- const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
105
- // Merge with a few safe fallbacks/overrides
106
- return Object.assign({ jsx: ts.JsxEmit.Preserve, allowJs: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.NodeNext, target: ts.ScriptTarget.ES2020, baseUrl: appPathAbs, noEmit: true }, parsed.options);
107
- }
108
- /*
109
- * Resolve a module specifier using tsconfig options (fast, no Program needed).
110
- */
111
- function resolveWithTs(spec, fromFile, options) {
112
- var _a, _b;
113
- const host = {
114
- fileExists: ts.sys.fileExists,
115
- readFile: ts.sys.readFile,
116
- directoryExists: ts.sys.directoryExists,
117
- getCurrentDirectory: ts.sys.getCurrentDirectory,
118
- getDirectories: ts.sys.getDirectories,
119
- realpath: ts.sys.realpath,
120
- };
121
- const result = ts.resolveModuleName(spec, fromFile, options, host);
122
- return (_b = (_a = result.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName) !== null && _b !== void 0 ? _b : null;
123
- }
124
- function _resolveComponentImportFiles(appRoot, componentMapPath = './.sitecore/component-map.ts') {
125
- const appPath = path.isAbsolute(appRoot) ? appRoot : path.resolve(process.cwd(), appRoot);
126
- const mapPath = path.isAbsolute(componentMapPath)
127
- ? componentMapPath
128
- : path.resolve(appPath, componentMapPath);
129
- if (!fs.existsSync(mapPath)) {
130
- throw new ReferenceError(`Failed to find file ${mapPath}`);
131
- }
132
- // 1) Load tsconfig (simple + safe). Use appPath as baseUrl fallback.
133
- const compilerOptions = loadCompilerOptions(appPath);
134
- // Read & parse the map file to an AST (SourceFile)
135
- const mapText = fs.readFileSync(mapPath, 'utf8');
136
- const source = ts.createSourceFile(mapPath, mapText, ts.ScriptTarget.Latest, true);
137
- const getFileType = (absPath) => {
138
- const base = path.basename(absPath); // "PromoBlock.extra.tsx"
139
- const name = base.replace(/\.[^.]+$/, ''); // "PromoBlock.extra"
140
- return name.includes('.') ? ExtractedFileType.Variant : ExtractedFileType.Component;
141
- };
142
- // 1) Collect import (import %importString% from %importModule%) strings
143
- const componentMapImports = new Map();
144
- source.forEachChild((node) => {
145
- if (ts.isImportDeclaration(node) && node.importClause) {
146
- const importString = node.importClause.getText();
147
- const importModule = node.moduleSpecifier.text;
148
- componentMapImports.set(importString, importModule);
149
- }
150
- });
151
- // 2) Find the map literal: new Map([...]) and collect entries
152
- // Also capture subsequent mutations: <mapIdent>.set('Key', Value)
153
- const results = [];
154
- const mapIdentifiers = new Set(); // all identifiers bound to the Map we care about
155
- // Given an import and an expression (identifier or object literal with spreads),
156
- // resolve the module(s) to absolute file paths and append normalized entries to `results`.
157
- const resolveAndRecordEntry = (importStringsEntry, mapEntry) => {
158
- // small guard to record a resolved path if valid
159
- const recordIfValid = (spec) => {
160
- // ignore Node built-ins and node: protocol up front
161
- if (isBuiltin(spec) || isNodeProtocol(spec))
162
- return;
163
- const fileAbs = resolveWithTs(spec, mapPath, compilerOptions);
164
- if (!fileAbs)
165
- return;
166
- // ignore node_modules and *.d.ts after resolution
167
- if (inNodeModules(fileAbs) || isDeclarationFile(fileAbs))
168
- return;
169
- results.push({
170
- componentKey: importStringsEntry,
171
- filePath: toPosixPath(fileAbs),
172
- fileType: getFileType(fileAbs),
173
- });
174
- };
175
- // Helper to find the matching import statement for a given component/module name
176
- const getImportPathForModule = (componentModuleName) => {
177
- let result = componentMapImports.get(componentModuleName);
178
- if (!result) {
179
- for (const key of componentMapImports.keys()) {
180
- const matcher = new RegExp(`\\b(${componentModuleName})\\b`);
181
- if (key.match(matcher) !== null) {
182
- return componentMapImports.get(key);
183
- }
184
- }
185
- return null;
186
- }
187
- return result;
188
- };
189
- // Case A: ['Key', Identifier]
190
- if (ts.isIdentifier(mapEntry)) {
191
- const componentEntryName = mapEntry.text;
192
- const importPathString = getImportPathForModule(componentEntryName);
193
- if (!importPathString)
194
- return;
195
- recordIfValid(importPathString);
196
- return;
197
- }
198
- // Case B: ['Key', { ...A, ...B, ...C }]
199
- if (ts.isObjectLiteralExpression(mapEntry)) {
200
- mapEntry.properties.forEach((prop) => {
201
- if (ts.isSpreadAssignment(prop) && ts.isIdentifier(prop.expression)) {
202
- const componentEntryName = prop.expression.text;
203
- const importPathString = getImportPathForModule(componentEntryName);
204
- if (!importPathString)
205
- return;
206
- recordIfValid(importPathString);
207
- }
208
- });
209
- }
210
- };
211
- // Walk the `new Map([...])` array literal and feed each ['Key', Value] into
212
- // `resolveAndRecordEntry` (only when the key is a string literal).
213
- const collectArrayEntries = (arrayArg) => {
214
- arrayArg.elements.forEach((el) => {
215
- if (ts.isArrayLiteralExpression(el)) {
216
- const [keyNode, valNode] = el.elements;
217
- if (keyNode && valNode && ts.isStringLiteral(keyNode)) {
218
- resolveAndRecordEntry(keyNode.text, valNode);
219
- }
220
- }
221
- });
222
- };
223
- // If this `new Map([...])` is bound to a variable (via decl or assignment),
224
- // record the identifier name so we can catch later `<id>.set(...)` mutations.
225
- const captureMapIdentifier = (node) => {
226
- // const m = new Map([...])
227
- const parent = node.parent;
228
- // Variable declaration with initializer new Map(...)
229
- if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
230
- mapIdentifiers.add(parent.name.text);
231
- return;
232
- }
233
- // Assignment: m = new Map([...])
234
- if (parent &&
235
- ts.isBinaryExpression(parent) &&
236
- parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
237
- ts.isIdentifier(parent.left)) {
238
- mapIdentifiers.add(parent.left.text);
239
- return;
240
- }
241
- // Exported variable declaration: export const componentMap = new Map([...])
242
- if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
243
- mapIdentifiers.add(parent.name.text);
244
- return;
245
- }
246
- };
247
- const traverseAst = (node) => {
248
- var _a;
249
- // A) Initial literal: new Map([...])
250
- if (ts.isNewExpression(node) &&
251
- node.expression.getText(source) === 'Map' &&
252
- node.arguments &&
253
- node.arguments.length > 0) {
254
- const firstArg = node.arguments[0];
255
- if (ts.isArrayLiteralExpression(firstArg)) {
256
- collectArrayEntries(firstArg);
257
- }
258
- captureMapIdentifier(node);
259
- }
260
- // B) Mutations: <mapIdent>.set('Key', Value)
261
- if (ts.isCallExpression(node) &&
262
- ts.isPropertyAccessExpression(node.expression) &&
263
- node.expression.name.text === 'set') {
264
- const target = node.expression.expression;
265
- if (ts.isIdentifier(target) && mapIdentifiers.has(target.text)) {
266
- const [keyArg, valArg] = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
267
- if (keyArg && ts.isStringLiteral(keyArg) && valArg) {
268
- resolveAndRecordEntry(keyArg.text, valArg);
269
- }
270
- }
271
- }
272
- ts.forEachChild(node, traverseAst);
273
- };
274
- ts.forEachChild(source, traverseAst);
275
- return results.filter((r) => !isDeclarationFile(r.filePath));
276
- }
277
- function _readNamedExports(filePath) {
278
- const code = fs.readFileSync(filePath, 'utf8');
279
- const sf = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
280
- const names = new Set();
281
- const visit = (node) => {
282
- var _a, _b;
283
- // export const X = ...
284
- if (ts.isVariableStatement(node) &&
285
- ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))) {
286
- node.declarationList.declarations.forEach((d) => {
287
- if (ts.isIdentifier(d.name))
288
- names.add(d.name.text);
289
- });
290
- }
291
- // export function X() {}
292
- if (ts.isFunctionDeclaration(node) &&
293
- ((_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) &&
294
- node.name) {
295
- names.add(node.name.text);
296
- }
297
- // export { A, B as C }
298
- if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) {
299
- node.exportClause.elements.forEach((e) => names.add(e.name.text));
300
- }
301
- // export default ...
302
- if (ts.isExportAssignment(node)) {
303
- names.add('Default');
304
- }
305
- ts.forEachChild(node, visit);
306
- };
307
- ts.forEachChild(sf, visit);
308
- return Array.from(names);
309
- }
310
- async function _sendCode({ file, token, targetUrl, }) {
311
- const apiEndpoint = `${targetUrl}/mesh/push/api/v1/contentsdk/code/extracted`;
312
- if (!fs.existsSync(file.path)) {
313
- console.error(chalk.red(`File not found: ${file.path}`));
314
- return null;
315
- }
316
- const code = fs.readFileSync(file.path);
317
- // Merge base labels with any extra labels (variants, componentName, etc.)
318
- const labels = Object.assign({ type: file.type }, (file.labels || {}));
319
- try {
320
- const response = await fetch(apiEndpoint, {
321
- method: 'POST',
322
- headers: {
323
- Authorization: `Bearer ${token}`,
324
- 'Content-Type': 'application/json',
325
- },
326
- body: JSON.stringify({
327
- EnvironmentId: 'ContentSDK',
328
- name: file.name,
329
- content: code.toString(),
330
- labels,
331
- }),
332
- });
333
- if (!response.ok) {
334
- console.error(chalk.red(`Failed to send extracted code from ${file.path}: ${response.statusText}`));
335
- debug.http('Error details: %o', {
336
- status: response.status,
337
- text: await response.text(),
338
- url: response.url,
339
- headers: response.headers,
340
- });
341
- return null;
342
- }
343
- }
344
- catch (error) {
345
- console.error(chalk.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
346
- return null;
347
- }
348
- return file.path;
349
- }
350
- const NODE_PROTOCOL = 'node:';
351
- function isNodeProtocol(specifier) {
352
- return specifier.startsWith(NODE_PROTOCOL);
353
- }
354
- function isDeclarationFile(p) {
355
- return p.endsWith('.d.ts');
356
- }
357
- function inNodeModules(p) {
358
- return p.replace(/\\/g, '/').includes('/node_modules/');
359
- }
360
- // Normalize path separators to POSIX-style "/" for cross-platform consistency.
361
- export function toPosixPath(p) {
362
- if (/^\\\\\?\\/.test(p))
363
- return p;
364
- return p.replace(/\\/g, '/');
365
- }
366
- export const stripExtension = (p) => p.replace(/\.(tsx?|jsx?|mjs|cjs)$/, '');
367
- // Convert an absolute file path into an relative module specifier (POSIX)
368
- export const getRelativeImportPath = (absFile, appPath) => {
369
- let rel = toPosixPath(path.relative(appPath, absFile));
370
- return stripExtension(rel);
371
- };
372
- // Determine if a specifier is bare/aliased (i.e., not relative "./" or "../" and not absolute "/").
373
- export const isNodeModuleImport = (name) => !name.startsWith('./') && !name.startsWith('../') && !name.startsWith('/');
1
+ /* eslint-disable jsdoc/require-jsdoc */
2
+ import chalk from 'chalk';
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ import * as ts from 'typescript';
6
+ import debug from './../../debug';
7
+ import { isBuiltin } from 'module';
8
+ /**
9
+ * Parse the generated component-map file and return all referenced modules
10
+ * per map entry (handles both single identifiers and spread objects).
11
+ * @param {string} appRoot path to the JSS app root
12
+ * @param {string} componentMapPath path to the component map file
13
+ * @returns map of component names and their respective import strings
14
+ */
15
+ export let resolveComponentImportFiles = _resolveComponentImportFiles;
16
+ /**
17
+ * Reads the named exports from a TypeScript file.
18
+ * @param {ExtractedFile} filePath absolute path to a .ts/.tsx file
19
+ * @returns {string[]} list of named exports found in the file
20
+ */
21
+ export let readNamedExports = _readNamedExports;
22
+ /**
23
+ * Sends the extracted code to the specified target URL.
24
+ * @param {object} params - The parameters object.
25
+ * @param {ExtractedFile} params.file - The file to be sent.
26
+ * @param {string} params.token - The access token for authentication.
27
+ * @param {string} params.targetUrl - The target URL to send the file to.
28
+ * @param {Record<string, unknown>} [params.extraLabels] - Additional labels to include in the payload.
29
+ * @returns {Promise<string | null>} - The path of the sent file or null if sending failed.
30
+ */
31
+ export let sendCode = _sendCode;
32
+ export const utilsUnitMocks = {
33
+ set xmCloudDeploy(mockImpl) {
34
+ utils.xmCloudDeploy = mockImpl;
35
+ },
36
+ get xmCloudDeploy() {
37
+ return _xmCloudDeploy;
38
+ },
39
+ set resolveComponentImportFiles(mockImpl) {
40
+ resolveComponentImportFiles = mockImpl;
41
+ },
42
+ get resolveComponentImportFiles() {
43
+ return _resolveComponentImportFiles;
44
+ },
45
+ set readNamedExports(mockImpl) {
46
+ readNamedExports = mockImpl;
47
+ },
48
+ get readNamedExports() {
49
+ return _readNamedExports;
50
+ },
51
+ set sendCode(mockImpl) {
52
+ sendCode = mockImpl;
53
+ },
54
+ get sendCode() {
55
+ return _sendCode;
56
+ },
57
+ };
58
+ /**
59
+ * Type of file to be sent to the mesh endpoint
60
+ */
61
+ export var ExtractedFileType;
62
+ (function (ExtractedFileType) {
63
+ ExtractedFileType["Component"] = "component";
64
+ ExtractedFileType["Variant"] = "variant";
65
+ ExtractedFileType["Json"] = "json";
66
+ ExtractedFileType["PackageJson"] = "package.json";
67
+ })(ExtractedFileType || (ExtractedFileType = {}));
68
+ export const utils = {
69
+ xmCloudDeploy: (...args) => _xmCloudDeploy(...args),
70
+ };
71
+ export const _xmCloudDeploy = () => !!process.env.SITECORE && !!process.env.SITECORE_BUILD;
72
+ // workaround, Vercel does not have variables that are only accessible at build time
73
+ const vercelDeploy = () => !!process.env.VERCEL && !process.env.VERCEL_REGION;
74
+ const netlifyDeploy = () => !!process.env.NETLIFY && !!process.env.BUILD_ID;
75
+ /**
76
+ * Validates if the current operation is done in Vercel, Netlify or XMCloud
77
+ * deploy context
78
+ * @returns {boolean} - true if in deploy context, false otherwise
79
+ */
80
+ export function validateDeployContext() {
81
+ return _xmCloudDeploy() || vercelDeploy() || netlifyDeploy();
82
+ }
83
+ /*
84
+ * Load and parse the tsconfig.json file from the specified app path.
85
+ */
86
+ function loadCompilerOptions(appPathAbs) {
87
+ const configPath = ts.findConfigFile(appPathAbs, ts.sys.fileExists, 'tsconfig.json');
88
+ if (!configPath) {
89
+ // Sane defaults if no tsconfig exists
90
+ return {
91
+ jsx: ts.JsxEmit.Preserve,
92
+ allowJs: true,
93
+ module: ts.ModuleKind.ESNext,
94
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
95
+ target: ts.ScriptTarget.ES2020,
96
+ baseUrl: appPathAbs,
97
+ noEmit: true,
98
+ };
99
+ }
100
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
101
+ if (configFile.error) {
102
+ throw new Error(`Error reading tsconfig at ${configPath}: ${configFile.error.messageText}`);
103
+ }
104
+ const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
105
+ // Merge with a few safe fallbacks/overrides
106
+ return Object.assign({ jsx: ts.JsxEmit.Preserve, allowJs: true, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.NodeNext, target: ts.ScriptTarget.ES2020, baseUrl: appPathAbs, noEmit: true }, parsed.options);
107
+ }
108
+ /*
109
+ * Resolve a module specifier using tsconfig options (fast, no Program needed).
110
+ */
111
+ function resolveWithTs(spec, fromFile, options) {
112
+ var _a, _b;
113
+ const host = {
114
+ fileExists: ts.sys.fileExists,
115
+ readFile: ts.sys.readFile,
116
+ directoryExists: ts.sys.directoryExists,
117
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
118
+ getDirectories: ts.sys.getDirectories,
119
+ realpath: ts.sys.realpath,
120
+ };
121
+ const result = ts.resolveModuleName(spec, fromFile, options, host);
122
+ return (_b = (_a = result.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName) !== null && _b !== void 0 ? _b : null;
123
+ }
124
+ function _resolveComponentImportFiles(appRoot, componentMapPath = './.sitecore/component-map.ts') {
125
+ const appPath = path.isAbsolute(appRoot) ? appRoot : path.resolve(process.cwd(), appRoot);
126
+ const mapPath = path.isAbsolute(componentMapPath)
127
+ ? componentMapPath
128
+ : path.resolve(appPath, componentMapPath);
129
+ if (!fs.existsSync(mapPath)) {
130
+ throw new ReferenceError(`Failed to find file ${mapPath}`);
131
+ }
132
+ // 1) Load tsconfig (simple + safe). Use appPath as baseUrl fallback.
133
+ const compilerOptions = loadCompilerOptions(appPath);
134
+ // Read & parse the map file to an AST (SourceFile)
135
+ const mapText = fs.readFileSync(mapPath, 'utf8');
136
+ const source = ts.createSourceFile(mapPath, mapText, ts.ScriptTarget.Latest, true);
137
+ const getFileType = (absPath) => {
138
+ const base = path.basename(absPath); // "PromoBlock.extra.tsx"
139
+ const name = base.replace(/\.[^.]+$/, ''); // "PromoBlock.extra"
140
+ return name.includes('.') ? ExtractedFileType.Variant : ExtractedFileType.Component;
141
+ };
142
+ // 1) Collect import (import %importString% from %importModule%) strings
143
+ const componentMapImports = new Map();
144
+ source.forEachChild((node) => {
145
+ if (ts.isImportDeclaration(node) && node.importClause) {
146
+ const importString = node.importClause.getText();
147
+ const importModule = node.moduleSpecifier.text;
148
+ componentMapImports.set(importString, importModule);
149
+ }
150
+ });
151
+ // 2) Find the map literal: new Map([...]) and collect entries
152
+ // Also capture subsequent mutations: <mapIdent>.set('Key', Value)
153
+ const results = [];
154
+ const mapIdentifiers = new Set(); // all identifiers bound to the Map we care about
155
+ // Given an import and an expression (identifier or object literal with spreads),
156
+ // resolve the module(s) to absolute file paths and append normalized entries to `results`.
157
+ const resolveAndRecordEntry = (importStringsEntry, mapEntry) => {
158
+ // small guard to record a resolved path if valid
159
+ const recordIfValid = (spec) => {
160
+ // ignore Node built-ins and node: protocol up front
161
+ if (isBuiltin(spec) || isNodeProtocol(spec))
162
+ return;
163
+ const fileAbs = resolveWithTs(spec, mapPath, compilerOptions);
164
+ if (!fileAbs)
165
+ return;
166
+ // ignore node_modules and *.d.ts after resolution
167
+ if (inNodeModules(fileAbs) || isDeclarationFile(fileAbs))
168
+ return;
169
+ results.push({
170
+ componentKey: importStringsEntry,
171
+ filePath: toPosixPath(fileAbs),
172
+ fileType: getFileType(fileAbs),
173
+ });
174
+ };
175
+ // Helper to find the matching import statement for a given component/module name
176
+ const getImportPathForModule = (componentModuleName) => {
177
+ let result = componentMapImports.get(componentModuleName);
178
+ if (!result) {
179
+ for (const key of componentMapImports.keys()) {
180
+ const matcher = new RegExp(`\\b(${componentModuleName})\\b`);
181
+ if (key.match(matcher) !== null) {
182
+ return componentMapImports.get(key);
183
+ }
184
+ }
185
+ return null;
186
+ }
187
+ return result;
188
+ };
189
+ // Case A: ['Key', Identifier]
190
+ if (ts.isIdentifier(mapEntry)) {
191
+ const componentEntryName = mapEntry.text;
192
+ const importPathString = getImportPathForModule(componentEntryName);
193
+ if (!importPathString)
194
+ return;
195
+ recordIfValid(importPathString);
196
+ return;
197
+ }
198
+ // Case B: ['Key', { ...A, ...B, ...C }]
199
+ if (ts.isObjectLiteralExpression(mapEntry)) {
200
+ mapEntry.properties.forEach((prop) => {
201
+ if (ts.isSpreadAssignment(prop) && ts.isIdentifier(prop.expression)) {
202
+ const componentEntryName = prop.expression.text;
203
+ const importPathString = getImportPathForModule(componentEntryName);
204
+ if (!importPathString)
205
+ return;
206
+ recordIfValid(importPathString);
207
+ }
208
+ });
209
+ }
210
+ };
211
+ // Walk the `new Map([...])` array literal and feed each ['Key', Value] into
212
+ // `resolveAndRecordEntry` (only when the key is a string literal).
213
+ const collectArrayEntries = (arrayArg) => {
214
+ arrayArg.elements.forEach((el) => {
215
+ if (ts.isArrayLiteralExpression(el)) {
216
+ const [keyNode, valNode] = el.elements;
217
+ if (keyNode && valNode && ts.isStringLiteral(keyNode)) {
218
+ resolveAndRecordEntry(keyNode.text, valNode);
219
+ }
220
+ }
221
+ });
222
+ };
223
+ // If this `new Map([...])` is bound to a variable (via decl or assignment),
224
+ // record the identifier name so we can catch later `<id>.set(...)` mutations.
225
+ const captureMapIdentifier = (node) => {
226
+ // const m = new Map([...])
227
+ const parent = node.parent;
228
+ // Variable declaration with initializer new Map(...)
229
+ if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
230
+ mapIdentifiers.add(parent.name.text);
231
+ return;
232
+ }
233
+ // Assignment: m = new Map([...])
234
+ if (parent &&
235
+ ts.isBinaryExpression(parent) &&
236
+ parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
237
+ ts.isIdentifier(parent.left)) {
238
+ mapIdentifiers.add(parent.left.text);
239
+ return;
240
+ }
241
+ // Exported variable declaration: export const componentMap = new Map([...])
242
+ if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)) {
243
+ mapIdentifiers.add(parent.name.text);
244
+ return;
245
+ }
246
+ };
247
+ const traverseAst = (node) => {
248
+ var _a;
249
+ // A) Initial literal: new Map([...])
250
+ if (ts.isNewExpression(node) &&
251
+ node.expression.getText(source) === 'Map' &&
252
+ node.arguments &&
253
+ node.arguments.length > 0) {
254
+ const firstArg = node.arguments[0];
255
+ if (ts.isArrayLiteralExpression(firstArg)) {
256
+ collectArrayEntries(firstArg);
257
+ }
258
+ captureMapIdentifier(node);
259
+ }
260
+ // B) Mutations: <mapIdent>.set('Key', Value)
261
+ if (ts.isCallExpression(node) &&
262
+ ts.isPropertyAccessExpression(node.expression) &&
263
+ node.expression.name.text === 'set') {
264
+ const target = node.expression.expression;
265
+ if (ts.isIdentifier(target) && mapIdentifiers.has(target.text)) {
266
+ const [keyArg, valArg] = (_a = node.arguments) !== null && _a !== void 0 ? _a : [];
267
+ if (keyArg && ts.isStringLiteral(keyArg) && valArg) {
268
+ resolveAndRecordEntry(keyArg.text, valArg);
269
+ }
270
+ }
271
+ }
272
+ ts.forEachChild(node, traverseAst);
273
+ };
274
+ ts.forEachChild(source, traverseAst);
275
+ return results.filter((r) => !isDeclarationFile(r.filePath));
276
+ }
277
+ function _readNamedExports(filePath) {
278
+ const code = fs.readFileSync(filePath, 'utf8');
279
+ const sf = ts.createSourceFile(filePath, code, ts.ScriptTarget.Latest, true);
280
+ const names = new Set();
281
+ const visit = (node) => {
282
+ var _a, _b;
283
+ // export const X = ...
284
+ if (ts.isVariableStatement(node) &&
285
+ ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((m) => m.kind === ts.SyntaxKind.ExportKeyword))) {
286
+ node.declarationList.declarations.forEach((d) => {
287
+ if (ts.isIdentifier(d.name))
288
+ names.add(d.name.text);
289
+ });
290
+ }
291
+ // export function X() {}
292
+ if (ts.isFunctionDeclaration(node) &&
293
+ ((_b = node.modifiers) === null || _b === void 0 ? void 0 : _b.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) &&
294
+ node.name) {
295
+ names.add(node.name.text);
296
+ }
297
+ // export { A, B as C }
298
+ if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) {
299
+ node.exportClause.elements.forEach((e) => names.add(e.name.text));
300
+ }
301
+ // export default ...
302
+ if (ts.isExportAssignment(node)) {
303
+ names.add('Default');
304
+ }
305
+ ts.forEachChild(node, visit);
306
+ };
307
+ ts.forEachChild(sf, visit);
308
+ return Array.from(names);
309
+ }
310
+ async function _sendCode({ file, token, targetUrl, }) {
311
+ const apiEndpoint = `${targetUrl}/mesh/push/api/v1/contentsdk/code/extracted`;
312
+ if (!fs.existsSync(file.path)) {
313
+ console.error(chalk.red(`File not found: ${file.path}`));
314
+ return null;
315
+ }
316
+ const code = fs.readFileSync(file.path);
317
+ // Merge base labels with any extra labels (variants, componentName, etc.)
318
+ const labels = Object.assign({ type: file.type }, (file.labels || {}));
319
+ try {
320
+ const response = await fetch(apiEndpoint, {
321
+ method: 'POST',
322
+ headers: {
323
+ Authorization: `Bearer ${token}`,
324
+ 'Content-Type': 'application/json',
325
+ },
326
+ body: JSON.stringify({
327
+ EnvironmentId: 'ContentSDK',
328
+ name: file.name,
329
+ content: code.toString(),
330
+ labels,
331
+ }),
332
+ });
333
+ if (!response.ok) {
334
+ console.error(chalk.red(`Failed to send extracted code from ${file.path}: ${response.statusText}`));
335
+ debug.http('Error details: %o', {
336
+ status: response.status,
337
+ text: await response.text(),
338
+ url: response.url,
339
+ headers: response.headers,
340
+ });
341
+ return null;
342
+ }
343
+ }
344
+ catch (error) {
345
+ console.error(chalk.red(`Fetch request to send extracted code from ${file.path} failed: ${JSON.stringify(error)}`));
346
+ return null;
347
+ }
348
+ return file.path;
349
+ }
350
+ const NODE_PROTOCOL = 'node:';
351
+ function isNodeProtocol(specifier) {
352
+ return specifier.startsWith(NODE_PROTOCOL);
353
+ }
354
+ function isDeclarationFile(p) {
355
+ return p.endsWith('.d.ts');
356
+ }
357
+ function inNodeModules(p) {
358
+ return p.replace(/\\/g, '/').includes('/node_modules/');
359
+ }
360
+ // Normalize path separators to POSIX-style "/" for cross-platform consistency.
361
+ export function toPosixPath(p) {
362
+ if (/^\\\\\?\\/.test(p))
363
+ return p;
364
+ return p.replace(/\\/g, '/');
365
+ }
366
+ export const stripExtension = (p) => p.replace(/\.(tsx?|jsx?|mjs|cjs)$/, '');
367
+ // Convert an absolute file path into an relative module specifier (POSIX)
368
+ export const getRelativeImportPath = (absFile, appPath) => {
369
+ let rel = toPosixPath(path.relative(appPath, absFile));
370
+ return stripExtension(rel);
371
+ };
372
+ // Determine if a specifier is bare/aliased (i.e., not relative "./" or "../" and not absolute "/").
373
+ export const isNodeModuleImport = (name) => !name.startsWith('./') && !name.startsWith('../') && !name.startsWith('/');