@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,316 +1,368 @@
1
- import * as ts from 'typescript';
2
- import path from 'path';
3
- import fs from 'fs';
4
- import { getComponentList } from './../templating';
5
- import debug from './../../debug';
6
- import crypto from 'crypto';
7
- import { isNodeModuleImport, stripExtension, getRelativeImportPath, toPosixPath } from './utils';
8
- let _getComponentList = getComponentList;
9
- const aliasImport = /^([a-zA-Z0-9]+) as .+$/;
10
- export const unitMocks = ({ getComponentListStub, }) => {
11
- getComponentListStub && (_getComponentList = getComponentListStub);
12
- };
13
- /**
14
- * Gets a Map object with import modules and their respective exports present throughout the paths specified
15
- * @param {string} paths paths to files to be processed for import-map
16
- * @returns {Map<string, ImportModule>} collection of keys and values, where keys refer to modules being processed and values are collections of exports for each module
17
- */
18
- export let getImportMap = _getImportMap;
19
- /**
20
- * Builds file contents for component map based on the default template
21
- * @param {Map<string, ImportModule>} indexedImportMap map to be processed into final component-map.ts file
22
- * @returns {string} file code for component-map.ts
23
- */
24
- export let nextJsMapTemplate = _nextJsMapTemplate;
25
- export const importUnitMocks = {
26
- set getImportMap(mockImplementation) {
27
- getImportMap = mockImplementation;
28
- },
29
- get getImportMap() {
30
- return _getImportMap;
31
- },
32
- set nextJsMapTemplate(mockImplementation) {
33
- nextJsMapTemplate = mockImplementation;
34
- },
35
- get nextJsMapTemplate() {
36
- return _nextJsMapTemplate;
37
- },
38
- };
39
- /**
40
- * Parses and AST import node and extracts all imported values from it
41
- * @param {ts.ImportDeclaration} importNode import node to be parsed
42
- * @returns {ImportNames | null} object with named, default and namespace imported values, or null if import node is not valid
43
- */
44
- export const getImportedValues = (importNode) => {
45
- const importClause = importNode.importClause;
46
- if (!importClause) {
47
- console.warn('Cannot parse import string from: %s', importNode.getText());
48
- return null;
49
- }
50
- const result = {
51
- named: [],
52
- default: null,
53
- namespace: null,
54
- };
55
- importClause.getChildren().forEach((child) => {
56
- if (child.kind === ts.SyntaxKind.NamedImports) {
57
- // import [...,]{a,b,c}
58
- child.forEachChild((namedChild) => {
59
- const importText = namedChild.getText().trim();
60
- const aliasMatch = aliasImport.exec(importText);
61
- result.named.push(aliasMatch ? aliasMatch[1] : importText);
62
- });
63
- }
64
- else if (child.kind === ts.SyntaxKind.NamespaceImport) {
65
- // * as coolName
66
- result.namespace = child.getText().replace('* as ', '');
67
- }
68
- else if (child.kind === ts.SyntaxKind.Identifier) {
69
- // import coolName
70
- result.default = child.getText();
71
- }
72
- });
73
- return result;
74
- };
75
- // return alias-like name for an import value/variable name
76
- // this helps alleviate duplicate import names in import-map.ts
77
- export const getImportValueAlias = (importValue, moduleName, importType) => {
78
- if (process.env.IMPORT_ALIAS_STRATEGY === 'plain')
79
- return importValue;
80
- // Add extra uniqueness since the same alias can be used for different import types
81
- const importTypeId = importType === 'named' ? 'n' : importType === 'default' ? 'd' : 'ns';
82
- const suffix = crypto.hash('sha1', `${moduleName}_${importTypeId}`);
83
- return `${importValue}_${suffix}`;
84
- };
85
- // eslint-disable-next-line jsdoc/require-jsdoc
86
- function _getImportMap(paths) {
87
- // make preparations for handling ts/js files
88
- const appPath = process.cwd();
89
- let cliCompilerOptions = {
90
- baseUrl: appPath,
91
- allowJs: true,
92
- target: ts.ScriptTarget.ESNext,
93
- };
94
- const tsConfig = ts.readConfigFile(path.resolve(appPath, 'tsconfig.json'), ts.sys.readFile);
95
- if (tsConfig.error) {
96
- console.warn(`[Codegen] Error reading tsconfig.json from app root: ${tsConfig.error.messageText}`);
97
- }
98
- else {
99
- cliCompilerOptions = Object.assign(Object.assign({}, tsConfig.config.compilerOptions), cliCompilerOptions);
100
- }
101
- const tsHost = ts.createCompilerHost(cliCompilerOptions, true);
102
- // indexed version of import map - we will store and aggregate unique import paths and their imports here
103
- const importMap = new Map();
104
- // index to keep track of unique import values imported from different modules
105
- // helps avoid duplicate import names in the final import-map.ts file
106
- const importsList = [];
107
- paths.forEach((codeFilePath) => {
108
- const codeFileFullPath = path.isAbsolute(codeFilePath)
109
- ? codeFilePath
110
- : path.resolve(appPath, codeFilePath);
111
- // attempt to parse current file to extract imports from
112
- const tsCodeSource = tsHost.getSourceFile(codeFileFullPath, ts.ScriptTarget.Latest, (msg) => {
113
- throw new Error(`[Codegen] Failed to parse ${codeFileFullPath}: ${msg}`);
114
- });
115
- if (!tsCodeSource)
116
- throw ReferenceError(`[Codegen] Failed to find file ${codeFileFullPath}`);
117
- // By transpiling the code from current file to JS we get rid of unused imports and the type imports
118
- const jsCode = ts.transpileModule(tsCodeSource.getFullText(), {
119
- compilerOptions: cliCompilerOptions,
120
- });
121
- // despite the name, ts.createSourceFile only creates SourceFile instance in runtime. Go figure ¯\_(ツ)_/¯
122
- const jsCodeSource = ts.createSourceFile('code.js', jsCode.outputText, ts.ScriptTarget.ESNext, true);
123
- // finally, we parse the final, trasformed js code and process import statements
124
- ts.forEachChild(jsCodeSource, (childNode) => {
125
- var _a;
126
- if (ts.isImportDeclaration(childNode) && childNode.importClause) {
127
- const imports = getImportedValues(childNode);
128
- if (!imports) {
129
- return;
130
- }
131
- // import path is extracted
132
- const moduleName = childNode.moduleSpecifier.getText().replace(/['"]/g, '');
133
- const resolvedModule = ts.nodeModuleNameResolver(moduleName, codeFileFullPath, cliCompilerOptions, tsHost);
134
- // get import path and check if its import target exists
135
- const resolvedImportPath = (_a = resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName;
136
- if (!resolvedImportPath) {
137
- console.warn('[Codegen] Could not resolve a file for import %s', moduleName);
138
- return;
139
- }
140
- let importModuleName;
141
- if (resolvedImportPath.includes('node_modules') ||
142
- resolvedImportPath.endsWith('.d.ts') ||
143
- !toPosixPath(resolvedImportPath).startsWith(toPosixPath(appPath) + '/')) {
144
- // if import path points to a file in local app - process import path to the file (i.e. ./myComponent)
145
- // if it points to node_modules or a file in monorepo - parse import path as dependency module name (i.e. React)
146
- // external dependency keep as-is
147
- importModuleName = isNodeModuleImport(moduleName)
148
- ? stripExtension(moduleName)
149
- : getRelativeImportPath(resolvedImportPath, appPath);
150
- }
151
- else {
152
- // local file
153
- importModuleName = isNodeModuleImport(moduleName)
154
- ? stripExtension(moduleName)
155
- : getRelativeImportPath(resolvedImportPath, appPath);
156
- }
157
- // Set module import info in the map. If module import exists - add entries to existing entry
158
- // Otherwise, add new entry
159
- if (!importMap.has(importModuleName)) {
160
- importMap.set(importModuleName, {
161
- namedExports: new Map(),
162
- defaultExport: null,
163
- namespaceExport: null,
164
- });
165
- }
166
- const moduleEntry = importMap.get(importModuleName);
167
- imports.named.forEach((importEntry) => {
168
- const sameModuleNamedAlready = moduleEntry.namedExports.has(importEntry);
169
- if (sameModuleNamedAlready) {
170
- return;
171
- }
172
- const nameTaken = importsList.includes(importEntry);
173
- const importValue = nameTaken
174
- ? getImportValueAlias(importEntry, importModuleName, 'named')
175
- : importEntry;
176
- moduleEntry.namedExports.set(importEntry, importValue);
177
- importsList.push(importEntry);
178
- });
179
- if (imports.namespace) {
180
- const sameModuleNamedAlready = moduleEntry.namespaceExport;
181
- if (sameModuleNamedAlready) {
182
- return;
183
- }
184
- const nameTaken = importsList.includes(imports.namespace);
185
- const importValue = nameTaken
186
- ? getImportValueAlias(imports.namespace, importModuleName, 'namespace')
187
- : imports.namespace;
188
- moduleEntry.namespaceExport = importValue;
189
- importsList.push(importValue);
190
- }
191
- if (imports.default) {
192
- const sameModuleNamedAlready = moduleEntry.defaultExport;
193
- if (sameModuleNamedAlready) {
194
- return;
195
- }
196
- const nameTaken = importsList.includes(imports.default);
197
- const importValue = nameTaken
198
- ? getImportValueAlias(imports.default, importModuleName, 'default')
199
- : imports.default;
200
- moduleEntry.defaultExport = importValue;
201
- importsList.push(importValue);
202
- }
203
- }
204
- });
205
- });
206
- return importMap;
207
- }
208
- /**
209
- * Entry point function for generating import-map. Parses provided paths and outputs the modules and imports from those files into .sitecore/import-map.ts
210
- * @param {WriteImportMapArgs} args include/exclude paths settings to be processed for import-map, and the Sitecore configuration
211
- */
212
- export const writeImportMap = (args) => {
213
- return async ({ scConfig } = {}) => {
214
- var _a;
215
- const config = (_a = args.scConfig) !== null && _a !== void 0 ? _a : scConfig;
216
- if (!config) {
217
- throw new Error('Sitecore configuration is required to be provided');
218
- }
219
- if (config.disableCodeGeneration) {
220
- debug.common('Skipping import map generation. Code generation functionality is disabled.');
221
- return;
222
- }
223
- const paths = _getComponentList(args.paths, args.exclude).map((entry) => entry.filePath);
224
- const importMapFile = path.join(process.cwd(), '.sitecore', 'import-map.ts');
225
- console.log(`[Codegen] Generating import map: ${JSON.stringify({
226
- paths: args.paths,
227
- exclude: args.exclude,
228
- })}.\n Writing into ${importMapFile} ...`);
229
- // get generated map and combine with default one
230
- const importMap = getImportMap(paths);
231
- const importMapContent = nextJsMapTemplate(importMap);
232
- try {
233
- fs.writeFileSync(importMapFile, importMapContent, {
234
- encoding: 'utf8',
235
- });
236
- }
237
- catch (error) {
238
- console.error(`[Codegen] Import Map generation failed. Error writing to file ${importMapFile}:`, error);
239
- throw error;
240
- }
241
- };
242
- };
243
- // eslint-disable-next-line jsdoc/require-jsdoc
244
- function _nextJsMapTemplate(indexedImportMap) {
245
- const outputExportEntries = (entry) => {
246
- return ([...entry.namedExports, entry.defaultExport, entry.namespaceExport]
247
- .filter((entry) => entry.value !== null)
248
- .map((namedExport) => ` { name: '${namedExport.name}', value: ${namedExport.value} }`)
249
- .join(',\n') + ',');
250
- };
251
- const importStatements = [];
252
- const importMapArray = Array.from(indexedImportMap);
253
- // get import map entries after
254
- const finalImportMap = importMapArray.map(([modulePath, imports]) => {
255
- const defaultExport = {
256
- name: 'default',
257
- value: imports.defaultExport,
258
- };
259
- const namedExports = Array.from(imports.namedExports).map(([name, value]) => {
260
- return {
261
- name,
262
- value,
263
- };
264
- });
265
- const namespaceExport = {
266
- name: '*',
267
- value: imports.namespaceExport,
268
- };
269
- return {
270
- module: modulePath,
271
- defaultExport,
272
- namedExports,
273
- namespaceExport,
274
- };
275
- });
276
- finalImportMap.forEach((entry) => {
277
- if (entry.namedExports.length > 0) {
278
- const namedExports = entry.namedExports
279
- .map((entry) => {
280
- return entry.name !== entry.value ? `${entry.name} as ${entry.value}` : entry.name;
281
- })
282
- .join(', ');
283
- importStatements.push(`import { ${namedExports} } from '${entry.module}';`);
284
- }
285
- if (entry.defaultExport.value) {
286
- importStatements.push(`import ${entry.defaultExport.value} from '${entry.module}';`);
287
- }
288
- if (entry.namespaceExport.value) {
289
- importStatements.push(`import * as ${entry.namespaceExport.value} from '${entry.module}';`);
290
- }
291
- });
1
+ import * as ts from 'typescript';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import { getComponentList } from './../templating';
5
+ import debug from './../../debug';
6
+ import crypto from 'crypto';
7
+ import { isNodeModuleImport, stripExtension, getRelativeImportPath, toPosixPath } from './utils';
8
+ let _getComponentList = getComponentList;
9
+ const aliasImport = /^([a-zA-Z0-9]+) as .+$/;
10
+ export const unitMocks = ({ getComponentListStub, }) => {
11
+ getComponentListStub && (_getComponentList = getComponentListStub);
12
+ };
13
+ /**
14
+ * Gets a Map object with import modules and their respective exports present throughout the paths specified
15
+ * @param {string} paths paths to files to be processed for import-map
16
+ * @returns {Map<string, ImportModule>} collection of keys and values, where keys refer to modules being processed and values are collections of exports for each module
17
+ */
18
+ export let getImportMap = _getImportMap;
19
+ /**
20
+ * Builds file contents for component map based on the default template
21
+ * @param {Map<string, ImportModule>} indexedImportMap map to be processed into final component-map.ts file
22
+ * @returns {string} file code for component-map.ts
23
+ * @internal
24
+ */
25
+ export let defaultMapTemplate = _defaultMapTemplate;
26
+ export const importUnitMocks = {
27
+ set getImportMap(mockImplementation) {
28
+ getImportMap = mockImplementation;
29
+ },
30
+ get getImportMap() {
31
+ return _getImportMap;
32
+ },
33
+ set defaultMapTemplate(mockImplementation) {
34
+ defaultMapTemplate = mockImplementation;
35
+ },
36
+ get defaultMapTemplate() {
37
+ return _defaultMapTemplate;
38
+ },
39
+ };
40
+ /**
41
+ * Parses and AST import node and extracts all imported values from it
42
+ * @param {ts.ImportDeclaration} importNode import node to be parsed
43
+ * @returns {ImportNames | null} object with named, default and namespace imported values, or null if import node is not valid
44
+ */
45
+ export const getImportedValues = (importNode) => {
46
+ const importClause = importNode.importClause;
47
+ if (!importClause) {
48
+ console.warn('Cannot parse import string from: %s', importNode.getText());
49
+ return null;
50
+ }
51
+ const result = {
52
+ named: [],
53
+ default: null,
54
+ namespace: null,
55
+ };
56
+ importClause.getChildren().forEach((child) => {
57
+ if (child.kind === ts.SyntaxKind.NamedImports) {
58
+ // import [...,]{a,b,c}
59
+ child.forEachChild((namedChild) => {
60
+ const importText = namedChild.getText().trim();
61
+ const aliasMatch = aliasImport.exec(importText);
62
+ result.named.push(aliasMatch ? aliasMatch[1] : importText);
63
+ });
64
+ }
65
+ else if (child.kind === ts.SyntaxKind.NamespaceImport) {
66
+ // * as coolName
67
+ result.namespace = child.getText().replace('* as ', '');
68
+ }
69
+ else if (child.kind === ts.SyntaxKind.Identifier) {
70
+ // import coolName
71
+ result.default = child.getText();
72
+ }
73
+ });
74
+ return result;
75
+ };
76
+ // return alias-like name for an import value/variable name
77
+ // this helps alleviate duplicate import names in import-map.ts
78
+ export const getImportValueAlias = (importValue, moduleName, importType) => {
79
+ if (process.env.IMPORT_ALIAS_STRATEGY === 'plain')
80
+ return importValue;
81
+ // Add extra uniqueness since the same alias can be used for different import types
82
+ const importTypeId = importType === 'named' ? 'n' : importType === 'default' ? 'd' : 'ns';
83
+ const suffix = crypto.hash('sha1', `${moduleName}_${importTypeId}`);
84
+ return `${importValue}_${suffix}`;
85
+ };
86
+ // eslint-disable-next-line jsdoc/require-jsdoc
87
+ function _getImportMap(paths) {
88
+ // make preparations for handling ts/js files
89
+ const appPath = process.cwd();
90
+ let cliCompilerOptions = {
91
+ baseUrl: appPath,
92
+ allowJs: true,
93
+ target: ts.ScriptTarget.ESNext,
94
+ };
95
+ const tsConfig = ts.readConfigFile(path.resolve(appPath, 'tsconfig.json'), ts.sys.readFile);
96
+ if (tsConfig.error) {
97
+ console.warn(`[Codegen] Error reading tsconfig.json from app root: ${tsConfig.error.messageText}`);
98
+ }
99
+ else {
100
+ cliCompilerOptions = Object.assign(Object.assign({}, tsConfig.config.compilerOptions), cliCompilerOptions);
101
+ }
102
+ const tsHost = ts.createCompilerHost(cliCompilerOptions, true);
103
+ // indexed version of import map - we will store and aggregate unique import paths and their imports here
104
+ const importMap = new Map();
105
+ // index to keep track of unique import values imported from different modules
106
+ // helps avoid duplicate import names in the final import-map.ts file
107
+ const importsList = [];
108
+ paths.forEach((codeFilePath) => {
109
+ const codeFileFullPath = path.isAbsolute(codeFilePath)
110
+ ? codeFilePath
111
+ : path.resolve(appPath, codeFilePath);
112
+ // attempt to parse current file to extract imports from
113
+ const tsCodeSource = tsHost.getSourceFile(codeFileFullPath, ts.ScriptTarget.Latest, (msg) => {
114
+ throw new Error(`[Codegen] Failed to parse ${codeFileFullPath}: ${msg}`);
115
+ });
116
+ if (!tsCodeSource)
117
+ throw ReferenceError(`[Codegen] Failed to find file ${codeFileFullPath}`);
118
+ // By transpiling the code from current file to JS we get rid of unused imports and the type imports
119
+ const jsCode = ts.transpileModule(tsCodeSource.getFullText(), {
120
+ compilerOptions: cliCompilerOptions,
121
+ });
122
+ // despite the name, ts.createSourceFile only creates SourceFile instance in runtime. Go figure ¯\_(ツ)_/¯
123
+ const jsCodeSource = ts.createSourceFile('code.js', jsCode.outputText, ts.ScriptTarget.ESNext, true);
124
+ // finally, we parse the final, trasformed js code and process import statements
125
+ ts.forEachChild(jsCodeSource, (childNode) => {
126
+ var _a;
127
+ if (ts.isImportDeclaration(childNode) && childNode.importClause) {
128
+ const imports = getImportedValues(childNode);
129
+ if (!imports) {
130
+ return;
131
+ }
132
+ // import path is extracted
133
+ const moduleName = childNode.moduleSpecifier.getText().replace(/['"]/g, '');
134
+ const resolvedModule = ts.nodeModuleNameResolver(moduleName, codeFileFullPath, cliCompilerOptions, tsHost);
135
+ // get import path and check if its import target exists
136
+ const resolvedImportPath = (_a = resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName;
137
+ if (!resolvedImportPath) {
138
+ console.warn('[Codegen] Could not resolve a file for import %s', moduleName);
139
+ return;
140
+ }
141
+ let importModuleName;
142
+ if (resolvedImportPath.includes('node_modules') ||
143
+ resolvedImportPath.endsWith('.d.ts') ||
144
+ !toPosixPath(resolvedImportPath).startsWith(toPosixPath(appPath) + '/')) {
145
+ // if import path points to a file in local app - process import path to the file (i.e. ./myComponent)
146
+ // if it points to node_modules or a file in monorepo - parse import path as dependency module name (i.e. React)
147
+ // external dependency → keep as-is
148
+ importModuleName = isNodeModuleImport(moduleName)
149
+ ? stripExtension(moduleName)
150
+ : getRelativeImportPath(resolvedImportPath, appPath);
151
+ }
152
+ else {
153
+ // local file
154
+ importModuleName = isNodeModuleImport(moduleName)
155
+ ? stripExtension(moduleName)
156
+ : getRelativeImportPath(resolvedImportPath, appPath);
157
+ }
158
+ // Set module import info in the map. If module import exists - add entries to existing entry
159
+ // Otherwise, add new entry
160
+ if (!importMap.has(importModuleName)) {
161
+ importMap.set(importModuleName, {
162
+ namedExports: new Map(),
163
+ defaultExport: null,
164
+ namespaceExport: null,
165
+ });
166
+ }
167
+ const moduleEntry = importMap.get(importModuleName);
168
+ imports.named.forEach((importEntry) => {
169
+ const sameModuleNamedAlready = moduleEntry.namedExports.has(importEntry);
170
+ if (sameModuleNamedAlready) {
171
+ return;
172
+ }
173
+ const nameTaken = importsList.includes(importEntry);
174
+ const importValue = nameTaken
175
+ ? getImportValueAlias(importEntry, importModuleName, 'named')
176
+ : importEntry;
177
+ moduleEntry.namedExports.set(importEntry, importValue);
178
+ importsList.push(importEntry);
179
+ });
180
+ if (imports.namespace) {
181
+ const sameModuleNamedAlready = moduleEntry.namespaceExport;
182
+ if (sameModuleNamedAlready) {
183
+ return;
184
+ }
185
+ const nameTaken = importsList.includes(imports.namespace);
186
+ const importValue = nameTaken
187
+ ? getImportValueAlias(imports.namespace, importModuleName, 'namespace')
188
+ : imports.namespace;
189
+ moduleEntry.namespaceExport = importValue;
190
+ importsList.push(importValue);
191
+ }
192
+ if (imports.default) {
193
+ const sameModuleNamedAlready = moduleEntry.defaultExport;
194
+ if (sameModuleNamedAlready) {
195
+ return;
196
+ }
197
+ const nameTaken = importsList.includes(imports.default);
198
+ const importValue = nameTaken
199
+ ? getImportValueAlias(imports.default, importModuleName, 'default')
200
+ : imports.default;
201
+ moduleEntry.defaultExport = importValue;
202
+ importsList.push(importValue);
203
+ }
204
+ }
205
+ });
206
+ });
207
+ return importMap;
208
+ }
209
+ const prepImportMaps = async (paths, separateMaps) => {
210
+ const importMapFileDefault = path.join(process.cwd(), '.sitecore', 'import-map.ts');
211
+ if (!separateMaps) {
212
+ return [{ map: getImportMap(paths), path: importMapFileDefault }];
213
+ }
214
+ const appPath = process.cwd();
215
+ const serverPaths = [];
216
+ const clientPaths = [];
217
+ const importMapFileClient = path.join(process.cwd(), '.sitecore', 'import-map.client.ts');
218
+ const importMapFileServer = path.join(process.cwd(), '.sitecore', 'import-map.server.ts');
219
+ for (const componentPath of paths) {
220
+ const fullPath = path.isAbsolute(componentPath)
221
+ ? componentPath
222
+ : path.resolve(appPath, componentPath);
223
+ // read the start of the file that may be 'use client'
224
+ const firstLine = await new Promise((resolve) => {
225
+ let readBuffer = '';
226
+ const stream = fs.createReadStream(fullPath, { end: 12 });
227
+ stream
228
+ .on('data', async (chunk) => {
229
+ readBuffer += chunk.toString();
230
+ })
231
+ .on('close', () => resolve(readBuffer))
232
+ .on('error', () => resolve(''));
233
+ });
234
+ if (!firstLine)
235
+ continue;
236
+ if (firstLine.match(/['"]use client['"]/)) {
237
+ clientPaths.push(fullPath);
238
+ }
239
+ else {
240
+ serverPaths.push(fullPath);
241
+ }
242
+ }
243
+ return [
244
+ { map: getImportMap(serverPaths), path: importMapFileServer },
245
+ { map: getImportMap(clientPaths), path: importMapFileClient, isClient: true },
246
+ ];
247
+ };
248
+ /**
249
+ * Entry point function for generating import-map. Parses provided paths and outputs the modules and imports from those files into .sitecore/import-map.ts
250
+ * @param {WriteImportMapArgsInternal} args include/exclude paths settings to be processed for import-map, and the Sitecore configuration.
251
+ * @public
252
+ */
253
+ export const writeImportMap = (args) => {
254
+ return async ({ scConfig } = {}) => {
255
+ var _a;
256
+ const config = (_a = args.scConfig) !== null && _a !== void 0 ? _a : scConfig;
257
+ const defaultTemplate = args.serverTemplate || defaultMapTemplate;
258
+ const clientTemplate = args.clientTemplate || defaultMapTemplate;
259
+ if (!config) {
260
+ throw new Error('Sitecore configuration is required to be provided');
261
+ }
262
+ if (config.disableCodeGeneration) {
263
+ debug.common('Skipping import map generation. Code generation functionality is disabled.');
264
+ return;
265
+ }
266
+ const paths = _getComponentList(args.paths, args.exclude).map((entry) => entry.filePath);
267
+ // TODO: don't run in pages router
268
+ const importMaps = await prepImportMaps(paths, args.separateServerClientMaps);
269
+ for (const importMap of importMaps) {
270
+ console.log(`[Codegen] Generating import map: ${JSON.stringify({
271
+ paths: args.paths,
272
+ exclude: args.exclude,
273
+ })}.\n Writing into ${importMap.path} ...`);
274
+ // get generated map and combine with default one
275
+ // can be expanded when adding support for non-react frameworks
276
+ const importMapContent = importMap.isClient
277
+ ? clientTemplate(importMap.map)
278
+ : defaultTemplate(importMap.map);
279
+ try {
280
+ fs.writeFileSync(importMap.path, importMapContent, {
281
+ encoding: 'utf8',
282
+ });
283
+ }
284
+ catch (error) {
285
+ console.error(`[Codegen] Import Map generation failed. Error writing to file ${importMap.path}:`, error);
286
+ throw error;
287
+ }
288
+ }
289
+ };
290
+ };
291
+ // eslint-disable-next-line jsdoc/require-jsdoc
292
+ function _defaultMapTemplate(indexedImportMap, framework = 'core') {
293
+ const importStatements = [];
294
+ const importMapArray = Array.from(indexedImportMap);
295
+ // get import map entries after
296
+ const finalImportMap = importMapArray.map(([modulePath, imports]) => {
297
+ const defaultExport = {
298
+ name: 'default',
299
+ value: imports.defaultExport,
300
+ };
301
+ const namedExports = Array.from(imports.namedExports).map(([name, value]) => {
302
+ return {
303
+ name,
304
+ value,
305
+ };
306
+ });
307
+ const namespaceExport = {
308
+ name: '*',
309
+ value: imports.namespaceExport,
310
+ };
311
+ return {
312
+ module: modulePath,
313
+ defaultExport,
314
+ namedExports,
315
+ namespaceExport,
316
+ };
317
+ });
318
+ finalImportMap.forEach((entry) => {
319
+ if (entry.namedExports.length > 0) {
320
+ const namedExports = entry.namedExports
321
+ .map((entry) => {
322
+ return entry.name !== entry.value ? `${entry.name} as ${entry.value}` : entry.name;
323
+ })
324
+ .join(', ');
325
+ importStatements.push(`import { ${namedExports} } from '${entry.module}';`);
326
+ }
327
+ if (entry.defaultExport.value) {
328
+ importStatements.push(`import ${entry.defaultExport.value} from '${entry.module}';`);
329
+ }
330
+ if (entry.namespaceExport.value) {
331
+ importStatements.push(`import * as ${entry.namespaceExport.value} from '${entry.module}';`);
332
+ }
333
+ });
334
+ const outputExportEntries = (entry) => {
335
+ return ([...entry.namedExports, entry.defaultExport, entry.namespaceExport]
336
+ .filter((entry) => entry.value !== null)
337
+ .map((namedExport) => ` { name: '${namedExport.name}', value: ${namedExport.value} }`)
338
+ .join(',\n') + ',');
339
+ };
292
340
  return `// This file is auto-generated by the Sitecore Content SDK.
293
341
  // Below are built-in Content SDK imports neccessary for the import map
294
- import { combineImportEntries, defaultImportEntries } from '@sitecore-content-sdk/nextjs/codegen';
342
+ import {
343
+ combineImportEntries,
344
+ defaultImportEntries,
345
+ ImportEntry,
346
+ } from '@sitecore-content-sdk/${framework}/codegen';
295
347
  // end of built-in imports
296
348
 
297
349
  ${importStatements.join('\n')}
298
350
 
299
351
  const importMap = [
300
- ${finalImportMap
301
- .map((entry) => [
302
- ' {',
303
- ` module: '${entry.module}',`,
304
- ' exports: [',
305
- outputExportEntries(entry),
306
- ' ]',
307
- ' }',
308
- ]
309
- .filter(Boolean)
310
- .join('\n'))
352
+ ${finalImportMap
353
+ .map((entry) => [
354
+ ' {',
355
+ ` module: '${entry.module}',`,
356
+ ' exports: [',
357
+ outputExportEntries(entry),
358
+ ' ]',
359
+ ' }',
360
+ ]
361
+ .filter(Boolean)
362
+ .join('\n'))
311
363
  .join(',\n')}
312
- ];
364
+ ] as ImportEntry[];
313
365
 
314
366
  export default combineImportEntries(defaultImportEntries, importMap);
315
- `;
316
- }
367
+ `;
368
+ }