@dr.pogodin/react-utils 1.25.6 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/babel.config.js +3 -1
  2. package/bin/build.js +18 -4
  3. package/build/development/client/getInj.js +9 -8
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +6 -3
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/client/init.js +4 -0
  8. package/build/development/client/init.js.map +1 -1
  9. package/build/development/index.js +166 -38
  10. package/build/development/index.js.map +1 -1
  11. package/build/development/server/Cache.js +13 -13
  12. package/build/development/server/Cache.js.map +1 -1
  13. package/build/development/server/index.js +16 -23
  14. package/build/development/server/index.js.map +1 -1
  15. package/build/development/server/renderer.js +56 -43
  16. package/build/development/server/renderer.js.map +1 -1
  17. package/build/development/server/server.js +9 -5
  18. package/build/development/server/server.js.map +1 -1
  19. package/build/development/server/utils/errors.js +12 -9
  20. package/build/development/server/utils/errors.js.map +1 -1
  21. package/build/development/server/utils/index.js +2 -2
  22. package/build/development/server/utils/index.js.map +1 -1
  23. package/build/development/shared/components/Button/index.js +7 -5
  24. package/build/development/shared/components/Button/index.js.map +1 -1
  25. package/build/development/shared/components/Checkbox/index.js +24 -26
  26. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  27. package/build/development/shared/components/Dropdown/index.js +24 -17
  28. package/build/development/shared/components/Dropdown/index.js.map +1 -1
  29. package/build/development/shared/components/GenericLink/index.js +44 -37
  30. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  31. package/build/development/shared/components/Input/index.js +7 -7
  32. package/build/development/shared/components/Input/index.js.map +1 -1
  33. package/build/development/shared/components/Link.js +10 -9
  34. package/build/development/shared/components/Link.js.map +1 -1
  35. package/build/development/shared/components/MetaTags.js +22 -18
  36. package/build/development/shared/components/MetaTags.js.map +1 -1
  37. package/build/development/shared/components/Modal/index.js +16 -16
  38. package/build/development/shared/components/Modal/index.js.map +1 -1
  39. package/build/development/shared/components/NavLink.js +10 -9
  40. package/build/development/shared/components/NavLink.js.map +1 -1
  41. package/build/development/shared/components/PageLayout/index.js +16 -18
  42. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  43. package/build/development/shared/components/ScalableRect/index.js +27 -7
  44. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  45. package/build/development/shared/components/Throbber/index.js +14 -22
  46. package/build/development/shared/components/Throbber/index.js.map +1 -1
  47. package/build/development/shared/components/WithTooltip/Tooltip.js +19 -21
  48. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  49. package/build/development/shared/components/WithTooltip/index.js +11 -10
  50. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  51. package/build/development/shared/components/YouTubeVideo/index.js +15 -13
  52. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  53. package/build/development/shared/components/index.js +2 -2
  54. package/build/development/shared/components/index.js.map +1 -1
  55. package/build/development/shared/utils/config.js.map +1 -1
  56. package/build/development/shared/utils/globalState.js +15 -0
  57. package/build/development/shared/utils/globalState.js.map +1 -0
  58. package/build/development/shared/utils/index.js +13 -10
  59. package/build/development/shared/utils/index.js.map +1 -1
  60. package/build/development/shared/utils/isomorphy/buildInfo.js +7 -3
  61. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  62. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  63. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  64. package/build/development/shared/utils/jest/E2eSsrEnv.js +35 -28
  65. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  66. package/build/development/shared/utils/jest/global.js +17 -0
  67. package/build/development/shared/utils/jest/global.js.map +1 -0
  68. package/build/development/shared/utils/jest/index.js +17 -9
  69. package/build/development/shared/utils/jest/index.js.map +1 -1
  70. package/build/development/shared/utils/splitComponent.js +25 -34
  71. package/build/development/shared/utils/splitComponent.js.map +1 -1
  72. package/build/development/shared/utils/time.js +16 -12
  73. package/build/development/shared/utils/time.js.map +1 -1
  74. package/build/development/shared/utils/webpack.js +3 -3
  75. package/build/development/shared/utils/webpack.js.map +1 -1
  76. package/build/development/web.bundle.js +92 -82
  77. package/build/production/client/getInj.js +1 -1
  78. package/build/production/client/getInj.js.map +1 -1
  79. package/build/production/client/index.js +4 -4
  80. package/build/production/client/index.js.map +1 -1
  81. package/build/production/client/init.js +3 -1
  82. package/build/production/client/init.js.map +1 -1
  83. package/build/production/index.js +1 -1
  84. package/build/production/index.js.map +1 -1
  85. package/build/production/server/Cache.js +7 -8
  86. package/build/production/server/Cache.js.map +1 -1
  87. package/build/production/server/index.js +5 -4
  88. package/build/production/server/index.js.map +1 -1
  89. package/build/production/server/renderer.js +32 -30
  90. package/build/production/server/renderer.js.map +1 -1
  91. package/build/production/server/server.js +7 -5
  92. package/build/production/server/server.js.map +1 -1
  93. package/build/production/server/utils/errors.js +9 -10
  94. package/build/production/server/utils/errors.js.map +1 -1
  95. package/build/production/server/utils/index.js +1 -1
  96. package/build/production/server/utils/index.js.map +1 -1
  97. package/build/production/shared/components/Button/index.js +3 -3
  98. package/build/production/shared/components/Button/index.js.map +1 -1
  99. package/build/production/shared/components/Checkbox/index.js +11 -11
  100. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  101. package/build/production/shared/components/Dropdown/index.js +11 -11
  102. package/build/production/shared/components/Dropdown/index.js.map +1 -1
  103. package/build/production/shared/components/GenericLink/index.js +25 -20
  104. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  105. package/build/production/shared/components/Input/index.js +7 -7
  106. package/build/production/shared/components/Input/index.js.map +1 -1
  107. package/build/production/shared/components/Link.js +2 -2
  108. package/build/production/shared/components/Link.js.map +1 -1
  109. package/build/production/shared/components/MetaTags.js +10 -10
  110. package/build/production/shared/components/MetaTags.js.map +1 -1
  111. package/build/production/shared/components/Modal/index.js +2 -2
  112. package/build/production/shared/components/Modal/index.js.map +1 -1
  113. package/build/production/shared/components/NavLink.js +1 -1
  114. package/build/production/shared/components/NavLink.js.map +1 -1
  115. package/build/production/shared/components/PageLayout/index.js +2 -2
  116. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  117. package/build/production/shared/components/ScalableRect/index.js +7 -3
  118. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  119. package/build/production/shared/components/Throbber/index.js +2 -2
  120. package/build/production/shared/components/Throbber/index.js.map +1 -1
  121. package/build/production/shared/components/WithTooltip/Tooltip.js +13 -13
  122. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  123. package/build/production/shared/components/WithTooltip/index.js +3 -3
  124. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  125. package/build/production/shared/components/YouTubeVideo/index.js +7 -7
  126. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  127. package/build/production/shared/components/index.js +1 -1
  128. package/build/production/shared/components/index.js.map +1 -1
  129. package/build/production/shared/utils/config.js.map +1 -1
  130. package/build/production/shared/utils/globalState.js +3 -0
  131. package/build/production/shared/utils/globalState.js.map +1 -0
  132. package/build/production/shared/utils/index.js +2 -2
  133. package/build/production/shared/utils/index.js.map +1 -1
  134. package/build/production/shared/utils/isomorphy/buildInfo.js +7 -4
  135. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  136. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  137. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  138. package/build/production/shared/utils/jest/E2eSsrEnv.js +9 -9
  139. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  140. package/build/production/shared/utils/jest/global.js +2 -0
  141. package/build/production/shared/utils/jest/global.js.map +1 -0
  142. package/build/production/shared/utils/jest/index.js +5 -5
  143. package/build/production/shared/utils/jest/index.js.map +1 -1
  144. package/build/production/shared/utils/splitComponent.js +16 -16
  145. package/build/production/shared/utils/splitComponent.js.map +1 -1
  146. package/build/production/shared/utils/time.js +12 -8
  147. package/build/production/shared/utils/time.js.map +1 -1
  148. package/build/production/shared/utils/webpack.js +3 -3
  149. package/build/production/shared/utils/webpack.js.map +1 -1
  150. package/build/production/web.bundle.js +1 -1
  151. package/build/production/web.bundle.js.map +1 -1
  152. package/build/types-code/client/getInj.d.ts +3 -0
  153. package/build/types-code/client/index.d.ts +11 -0
  154. package/build/types-code/client/init.d.ts +9 -0
  155. package/build/types-code/index.d.ts +10 -0
  156. package/build/types-code/server/Cache.d.ts +37 -0
  157. package/build/types-code/server/index.d.ts +145 -0
  158. package/build/types-code/server/renderer.d.ts +106 -0
  159. package/build/types-code/server/server.d.ts +41 -0
  160. package/build/types-code/server/utils/errors.d.ts +104 -0
  161. package/build/types-code/server/utils/index.d.ts +1 -0
  162. package/build/types-code/shared/components/Button/index.d.ts +27 -0
  163. package/build/types-code/shared/components/Checkbox/index.d.ts +21 -0
  164. package/build/types-code/shared/components/Dropdown/index.d.ts +23 -0
  165. package/build/types-code/shared/components/GenericLink/index.d.ts +61 -0
  166. package/build/types-code/shared/components/Input/index.d.ts +11 -0
  167. package/build/types-code/shared/components/Link.d.ts +12 -0
  168. package/build/types-code/shared/components/MetaTags.d.ts +68 -0
  169. package/build/types-code/shared/components/Modal/index.d.ts +26 -0
  170. package/build/types-code/shared/components/NavLink.d.ts +5 -0
  171. package/build/types-code/shared/components/PageLayout/index.d.ts +16 -0
  172. package/build/types-code/shared/components/ScalableRect/index.d.ts +19 -0
  173. package/build/types-code/shared/components/Throbber/index.d.ts +9 -0
  174. package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +23 -0
  175. package/build/types-code/shared/components/WithTooltip/index.d.ts +17 -0
  176. package/build/types-code/shared/components/YouTubeVideo/index.d.ts +13 -0
  177. package/build/types-code/shared/components/index.d.ts +16 -0
  178. package/build/types-code/shared/utils/config.d.ts +2 -0
  179. package/build/types-code/shared/utils/globalState.d.ts +20 -0
  180. package/build/types-code/shared/utils/index.d.ts +52 -0
  181. package/build/types-code/shared/utils/isomorphy/buildInfo.d.ts +23 -0
  182. package/build/types-code/shared/utils/isomorphy/environment-check.d.ts +11 -0
  183. package/build/types-code/shared/utils/isomorphy/index.d.ts +20 -0
  184. package/build/types-code/shared/utils/jest/E2eSsrEnv.d.ts +31 -0
  185. package/build/types-code/shared/utils/jest/global.d.ts +12 -0
  186. package/build/types-code/shared/utils/jest/index.d.ts +85 -0
  187. package/build/types-code/shared/utils/splitComponent.d.ts +41 -0
  188. package/build/types-code/shared/utils/time.d.ts +62 -0
  189. package/build/types-code/shared/utils/webpack.d.ts +18 -0
  190. package/build/types-scss/__tests__/js/config/publicPath support/__assets__/style.scss.d.ts +1 -0
  191. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
  192. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
  193. package/build/types-scss/__tests__/js/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
  194. package/build/types-scss/__tests__/js/shared/components/NavLink/styles.scss.d.ts +1 -0
  195. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
  196. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
  197. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
  198. package/build/types-scss/__tests__/js/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
  199. package/build/types-scss/__tests__/ts/config/publicPath support/__assets__/style.scss.d.ts +1 -0
  200. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageA/TestComponent/style.scss.d.ts +1 -0
  201. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/MockPackageB/TestComponent/style.scss.d.ts +1 -0
  202. package/build/types-scss/__tests__/ts/config/stylename-generation/__assets__/style.scss.d.ts +1 -0
  203. package/build/types-scss/__tests__/ts/shared/components/NavLink/styles.scss.d.ts +1 -0
  204. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentA/style.scss.d.ts +1 -0
  205. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentB/style.scss.d.ts +1 -0
  206. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/ComponentC/style.scss.d.ts +1 -0
  207. package/build/types-scss/__tests__/ts/shared/utils/splitComponent/__assets__/SampleScene/style.scss.d.ts +1 -0
  208. package/build/types-scss/src/shared/components/Button/style.scss.d.ts +6 -0
  209. package/build/types-scss/src/shared/components/Checkbox/theme.scss.d.ts +6 -0
  210. package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +9 -0
  211. package/build/types-scss/src/shared/components/GenericLink/style.scss.d.ts +1 -0
  212. package/build/types-scss/src/shared/components/Input/theme.scss.d.ts +6 -0
  213. package/build/types-scss/src/shared/components/Modal/base-theme.scss.d.ts +5 -0
  214. package/build/types-scss/src/shared/components/PageLayout/base-theme.scss.d.ts +6 -0
  215. package/build/types-scss/src/shared/components/ScalableRect/style.scss.d.ts +2 -0
  216. package/build/types-scss/src/shared/components/Throbber/theme.scss.d.ts +6 -0
  217. package/build/types-scss/src/shared/components/WithTooltip/default-theme.scss.d.ts +7 -0
  218. package/build/types-scss/src/shared/components/YouTubeVideo/base.scss.d.ts +5 -0
  219. package/build/types-scss/src/shared/components/YouTubeVideo/throbber.scss.d.ts +4 -0
  220. package/config/eslint/jest.json +3 -2
  221. package/config/eslint/typescript.js +34 -0
  222. package/config/jest/default.js +3 -3
  223. package/package.json +74 -32
  224. package/src/client/getInj.ts +43 -0
  225. package/src/client/index.tsx +40 -0
  226. package/src/client/init.ts +47 -0
  227. package/src/index.ts +58 -0
  228. package/src/server/Cache.ts +68 -0
  229. package/src/server/index.ts +230 -0
  230. package/src/server/renderer.tsx +604 -0
  231. package/src/server/server.ts +309 -0
  232. package/src/server/utils/errors.ts +135 -0
  233. package/src/server/utils/index.ts +3 -0
  234. package/src/shared/components/Button/index.tsx +146 -0
  235. package/src/shared/components/Button/style.scss +53 -0
  236. package/src/shared/components/Checkbox/index.tsx +71 -0
  237. package/src/shared/components/Checkbox/theme.scss +43 -0
  238. package/src/shared/components/Dropdown/index.tsx +144 -0
  239. package/src/shared/components/Dropdown/theme.scss +63 -0
  240. package/src/shared/components/GenericLink/index.tsx +157 -0
  241. package/src/shared/components/GenericLink/style.scss +3 -0
  242. package/src/shared/components/Input/index.tsx +59 -0
  243. package/src/shared/components/Input/theme.scss +27 -0
  244. package/src/shared/components/Link.tsx +21 -0
  245. package/src/shared/components/MetaTags.tsx +170 -0
  246. package/src/shared/components/Modal/base-theme.scss +38 -0
  247. package/src/shared/components/Modal/index.tsx +144 -0
  248. package/src/shared/components/Modal/styles.scss +5 -0
  249. package/src/shared/components/NavLink.tsx +13 -0
  250. package/src/shared/components/PageLayout/base-theme.scss +30 -0
  251. package/src/shared/components/PageLayout/index.tsx +76 -0
  252. package/src/shared/components/ScalableRect/index.tsx +84 -0
  253. package/src/shared/components/ScalableRect/style.scss +10 -0
  254. package/src/shared/components/Throbber/index.tsx +43 -0
  255. package/src/shared/components/Throbber/theme.scss +26 -0
  256. package/src/shared/components/WithTooltip/Tooltip.tsx +353 -0
  257. package/src/shared/components/WithTooltip/default-theme.scss +36 -0
  258. package/src/shared/components/WithTooltip/index.tsx +204 -0
  259. package/src/shared/components/YouTubeVideo/base.scss +13 -0
  260. package/src/shared/components/YouTubeVideo/index.tsx +96 -0
  261. package/src/shared/components/YouTubeVideo/throbber.scss +11 -0
  262. package/src/shared/components/index.ts +17 -0
  263. package/src/shared/utils/config.ts +21 -0
  264. package/src/shared/utils/globalState.ts +29 -0
  265. package/src/shared/utils/index.ts +105 -0
  266. package/src/shared/utils/isomorphy/buildInfo.ts +54 -0
  267. package/src/shared/utils/isomorphy/environment-check.ts +18 -0
  268. package/src/shared/utils/isomorphy/index.ts +38 -0
  269. package/src/shared/utils/jest/E2eSsrEnv.ts +250 -0
  270. package/src/shared/utils/jest/global.ts +19 -0
  271. package/src/shared/utils/jest/index.tsx +157 -0
  272. package/src/shared/utils/splitComponent.tsx +255 -0
  273. package/src/shared/utils/time.ts +118 -0
  274. package/src/shared/utils/webpack.ts +45 -0
  275. package/src/styles/_global/reset.css +52 -0
  276. package/src/styles/global.scss +11 -0
  277. package/tsconfig.configs.json +18 -0
  278. package/tsconfig.json +27 -0
  279. package/tsconfig.types.json +53 -0
  280. package/typed-scss-modules.config.ts +9 -0
  281. package/types.d.ts +37 -0
  282. package/{webpack.config.js → webpack.config.ts} +7 -3
  283. package/config/babel/node-ssr.js +0 -85
  284. package/config/babel/webpack.js +0 -123
  285. package/config/webpack/app-base.js +0 -330
  286. package/config/webpack/app-development.js +0 -80
  287. package/config/webpack/app-production.js +0 -60
  288. package/config/webpack/lib-base.js +0 -155
  289. package/config/webpack/lib-development.js +0 -45
  290. package/config/webpack/lib-production.js +0 -44
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_reactThemes","_interopRequireWildcard","require","_config","_interopRequireDefault","isomorphy","exports","_time","webpack","_jsUtils","_splitComponent","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","themed","COMPOSE","PRIORITY","NODE_CONFIG_ENV","process","env","NODE_ENV","JU","requireWeak","__dirname","withRetries","action","maxRetries","interval","n","error","time","timer"],"sources":["../../../../src/shared/utils/index.js"],"sourcesContent":["import themed, {\n COMPOSE,\n PRIORITY,\n ThemeProvider,\n} from '@dr.pogodin/react-themes';\n\nimport config from './config';\nimport * as isomorphy from './isomorphy';\nimport time from './time';\nimport * as webpack from './webpack';\n\nexport { Barrier, Emitter, Semaphore } from '@dr.pogodin/js-utils';\n\nexport { default as splitComponent } from './splitComponent';\n\nthemed.COMPOSE = COMPOSE;\nthemed.PRIORITY = PRIORITY;\n\n// Note: it should be done this way, as in some environments\n// \"process\" might not exist, and process.env.NODE_CONFIG_ENV\n// not injected by Webpack.\nlet NODE_CONFIG_ENV;\ntry {\n NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV;\n} catch { /* noop */ }\n\nconst env = NODE_CONFIG_ENV || process.env.NODE_ENV;\nconst JU = env !== 'production' && webpack.requireWeak('./jest', __dirname);\n\n/**\n * @category Utilities\n * @global\n * @func withRetries\n * @desc\n * ```js\n * import { withRetries } from '@dr.pogodin/react-utils';\n * ```\n * Attempts to perform given asynchronous `action` up to `maxRetries` times,\n * with the given `interval` between attempts. If any attempt is successful,\n * the result is returned immediately, with no further attempts done;\n * otherwise, if all attempts fail, the result Promise rejects after the last\n * attempt.\n * @param {function} action\n * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults\n * to 5 attempts.\n * @param {number} [interval=1000] Optional. Interval between retries [ms].\n * Defaults to 1 second.\n * @return {Promise} Resolves to the result of successful operation, or\n * rejects with the error from the latst failed attempt.\n * @example\n * import { withRetries } from '@dr.pogodin/react-utils';\n *\n * let firstCall = true;\n *\n * function sampleAction() {\n * if (!firstCall) return 'success';\n * firstCall = false;\n * throw Error('The first call to this method fails');\n * }\n *\n * withRetries(sampleAction).then(console.log);\n * // It will print 'success' after one second, once the second attempt\n * // is performed.\n */\nexport async function withRetries(action, maxRetries = 5, interval = 1000) {\n /* eslint-disable no-await-in-loop */\n for (let n = 1; ; ++n) {\n try {\n return await action();\n } catch (error) {\n if (n < maxRetries) await time.timer(interval);\n else throw error;\n }\n }\n /* eslint-enable no-await-in-loop */\n}\n\nexport {\n config,\n isomorphy,\n JU,\n themed,\n ThemeProvider,\n time,\n webpack,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,uBAAA,CAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG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AA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAE7DW,oBAAM,CAACC,OAAO,GAAGA,oBAAO;AACxBD,oBAAM,CAACE,QAAQ,GAAGA,qBAAQ;;AAE1B;AACA;AACA;AACA,IAAIC,eAAe;AACnB,IAAI;EACFA,eAAe,GAAGC,OAAO,CAACC,GAAG,CAACF,eAAe;AAC/C,CAAC,CAAC,MAAM,CAAE;AAEV,MAAME,GAAG,GAAGF,eAAe,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ;AACnD,MAAMC,EAAE,GAAAlC,OAAA,CAAAkC,EAAA,GAAGF,GAAG,KAAK,YAAY,IAAI9B,OAAO,CAACiC,WAAW,WAAWC,SAAS,CAAC;;AAE3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,WAAWA,CAACC,MAAM,EAAEC,UAAU,GAAG,CAAC,EAAEC,QAAQ,GAAG,IAAI,EAAE;EACzE;EACA,KAAK,IAAIC,CAAC,GAAG,CAAC,GAAI,EAAEA,CAAC,EAAE;IACrB,IAAI;MACF,OAAO,MAAMH,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,IAAID,CAAC,GAAGF,UAAU,EAAE,MAAMI,aAAI,CAACC,KAAK,CAACJ,QAAQ,CAAC,CAAC,KAC1C,MAAME,KAAK;IAClB;EACF;EACA;AACF"}
1
+ {"version":3,"file":"index.js","names":["_reactThemes","_interopRequireWildcard","require","_config","_interopRequireDefault","isomorphy","exports","_time","webpack","_jsUtils","_globalState","_splitComponent","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","themed","themedImpl","COMPOSE","PRIORITY","NODE_CONFIG_ENV","process","env","NODE_ENV","JU","requireWeak","__dirname","withRetries","action","maxRetries","interval","error","time","timer"],"sources":["../../../../src/shared/utils/index.ts"],"sourcesContent":["import themedImpl, {\n type Theme,\n COMPOSE,\n PRIORITY,\n ThemeProvider,\n} from '@dr.pogodin/react-themes';\n\nimport config from './config';\nimport * as isomorphy from './isomorphy';\nimport time from './time';\nimport * as webpack from './webpack';\n\nimport type * as JuT from './jest';\n\nexport { Barrier, Emitter, Semaphore } from '@dr.pogodin/js-utils';\n\nexport { getSsrContext } from './globalState';\nexport { default as splitComponent } from './splitComponent';\n\ntype ThemedT = typeof themedImpl & {\n COMPOSE: typeof COMPOSE;\n PRIORITY: typeof PRIORITY;\n};\n\nconst themed: ThemedT = themedImpl as ThemedT;\n\nthemed.COMPOSE = COMPOSE;\nthemed.PRIORITY = PRIORITY;\n\n// Note: it should be done this way, as in some environments\n// \"process\" might not exist, and process.env.NODE_CONFIG_ENV\n// not injected by Webpack.\nlet NODE_CONFIG_ENV;\ntry {\n NODE_CONFIG_ENV = process.env.NODE_CONFIG_ENV;\n} catch { /* noop */ }\n\nconst env = NODE_CONFIG_ENV || process.env.NODE_ENV;\n\nconst JU: typeof JuT | null = env !== 'production'\n ? webpack.requireWeak('./jest', __dirname) as typeof JuT | null\n : null;\n\n/**\n * @category Utilities\n * @global\n * @func withRetries\n * @desc\n * ```js\n * import { withRetries } from '@dr.pogodin/react-utils';\n * ```\n * Attempts to perform given asynchronous `action` up to `maxRetries` times,\n * with the given `interval` between attempts. If any attempt is successful,\n * the result is returned immediately, with no further attempts done;\n * otherwise, if all attempts fail, the result Promise rejects after the last\n * attempt.\n * @param {function} action\n * @param {number} [maxRetries=5] Optional. Maximum number of retries. Defaults\n * to 5 attempts.\n * @param {number} [interval=1000] Optional. Interval between retries [ms].\n * Defaults to 1 second.\n * @return {Promise} Resolves to the result of successful operation, or\n * rejects with the error from the latst failed attempt.\n * @example\n * import { withRetries } from '@dr.pogodin/react-utils';\n *\n * let firstCall = true;\n *\n * function sampleAction() {\n * if (!firstCall) return 'success';\n * firstCall = false;\n * throw Error('The first call to this method fails');\n * }\n *\n * withRetries(sampleAction).then(console.log);\n * // It will print 'success' after one second, once the second attempt\n * // is performed.\n */\nexport async function withRetries(\n action: () => Promise<unknown>,\n maxRetries = 5,\n interval = 1000,\n) {\n /* eslint-disable no-await-in-loop */\n for (let n = 1; ; ++n) {\n try {\n return await action();\n } catch (error) {\n if (n < maxRetries) await time.timer(interval);\n else throw error;\n }\n }\n /* eslint-enable no-await-in-loop */\n}\n\nexport {\n type Theme,\n config,\n isomorphy,\n JU,\n themed,\n ThemeProvider,\n time,\n webpack,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,uBAAA,CAAAC,OAAA;AAOA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAJ,uBAAA,CAAAC,OAAA;AAAyCI,OAAA,CAAAD,SAAA,GAAAA,SAAA;AACzC,IAAAE,KAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,OAAA,GAAAP,uBAAA,CAAAC,OAAA;AAAqCI,OAAA,CAAAE,OAAA,GAAAA,OAAA;AAIrC,IAAAC,QAAA,GAAAP,OAAA;AAEA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,eAAA,GAAAP,sBAAA,CAAAF,OAAA;AAA6D,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAZ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C,GAAG,CAACC,QAAQ;AAEnD,MAAMC,EAAqB,GAAAnC,OAAA,CAAAmC,EAAA,GAAGF,GAAG,KAAK,YAAY,GAC9C/B,OAAO,CAACkC,WAAW,WAAWC,SAAS,CAAC,GACxC,IAAI;;AAER;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,WAAWA,CAC/BC,MAA8B,EAC9BC,UAAU,GAAG,CAAC,EACdC,QAAQ,GAAG,IAAI,EACf;EACA;EACA,KAAK,IAAI1B,CAAC,GAAG,CAAC,GAAI,EAAEA,CAAC,EAAE;IACrB,IAAI;MACF,OAAO,MAAMwB,MAAM,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOG,KAAK,EAAE;MACd,IAAI3B,CAAC,GAAGyB,UAAU,EAAE,MAAMG,aAAI,CAACC,KAAK,CAACH,QAAQ,CAAC,CAAC,KAC1C,MAAMC,KAAK;IAClB;EACF;EACA;AACF"}
@@ -9,6 +9,10 @@ exports.setBuildInfo = setBuildInfo;
9
9
 
10
10
  /* global BUILD_INFO */
11
11
 
12
+ // BEWARE: This should match the type of build info object generated by
13
+ // Webpack build (see "/config/webpack/app-base.js"), and currently this
14
+ // match is not checked automatically.
15
+
12
16
  let buildInfo;
13
17
 
14
18
  // On the client side "BUILD_INFO" should be injected by Webpack. Note, however,
@@ -22,8 +26,8 @@ if (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;
22
26
  * tests, etc.) we expect the host codebase to explicitly set it before it is
23
27
  * ever requested. As a precaution, this function throws if build info has been
24
28
  * set already, unless `force` flag is explicitly set.
25
- * @param {object} info
26
- * @param {boolean} [force=false]
29
+ * @param info
30
+ * @param force
27
31
  */
28
32
  function setBuildInfo(info, force = false) {
29
33
  if (buildInfo !== undefined && !force) {
@@ -34,7 +38,7 @@ function setBuildInfo(info, force = false) {
34
38
 
35
39
  /**
36
40
  * Returns "Build Info" object; throws if it has not been initialized yet.
37
- * @returns {object}
41
+ * @returns
38
42
  */
39
43
  function getBuildInfo() {
40
44
  if (buildInfo === undefined) {
@@ -1 +1 @@
1
- {"version":3,"file":"buildInfo.js","names":["buildInfo","BUILD_INFO","setBuildInfo","info","force","undefined","Error","getBuildInfo"],"sources":["../../../../../src/shared/utils/isomorphy/buildInfo.js"],"sourcesContent":["// Encapsulates access to \"Build Info\" data.\n\n/* global BUILD_INFO */\n\nlet buildInfo;\n\n// On the client side \"BUILD_INFO\" should be injected by Webpack. Note, however,\n// that in test environment we may need situations were environment is mocked as\n// client-side, although no proper Webpack compilation is executed, thus no info\n// injected; because of this we don't do a hard environment check here.\nif (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;\n\n/**\n * In scenarious where \"BUILD_INFO\" is not injected by Webpack (server-side,\n * tests, etc.) we expect the host codebase to explicitly set it before it is\n * ever requested. As a precaution, this function throws if build info has been\n * set already, unless `force` flag is explicitly set.\n * @param {object} info\n * @param {boolean} [force=false]\n */\nexport function setBuildInfo(info, force = false) {\n if (buildInfo !== undefined && !force) {\n throw Error('\"Build Info\" is already initialized');\n }\n buildInfo = info;\n}\n\n/**\n * Returns \"Build Info\" object; throws if it has not been initialized yet.\n * @returns {object}\n */\nexport function getBuildInfo() {\n if (buildInfo === undefined) {\n throw Error('\"Build Info\" has not been initialized yet');\n }\n return buildInfo;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA,IAAIA,SAAS;;AAEb;AACA;AACA;AACA;AACA,IAAI,OAAOC,UAAU,KAAK,WAAW,EAAED,SAAS,GAAGC,UAAU;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAACC,IAAI,EAAEC,KAAK,GAAG,KAAK,EAAE;EAChD,IAAIJ,SAAS,KAAKK,SAAS,IAAI,CAACD,KAAK,EAAE;IACrC,MAAME,KAAK,CAAC,qCAAqC,CAAC;EACpD;EACAN,SAAS,GAAGG,IAAI;AAClB;;AAEA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAAA,EAAG;EAC7B,IAAIP,SAAS,KAAKK,SAAS,EAAE;IAC3B,MAAMC,KAAK,CAAC,2CAA2C,CAAC;EAC1D;EACA,OAAON,SAAS;AAClB"}
1
+ {"version":3,"file":"buildInfo.js","names":["buildInfo","BUILD_INFO","setBuildInfo","info","force","undefined","Error","getBuildInfo"],"sources":["../../../../../src/shared/utils/isomorphy/buildInfo.ts"],"sourcesContent":["// Encapsulates access to \"Build Info\" data.\n\n/* global BUILD_INFO */\n\n// BEWARE: This should match the type of build info object generated by\n// Webpack build (see \"/config/webpack/app-base.js\"), and currently this\n// match is not checked automatically.\nexport type BuildInfoT = {\n key: string;\n publicPath: string;\n timestamp: string;\n useServiceWorker: boolean;\n};\n\ndeclare global {\n // Depending on the build mode & environment, BUILD_INFO is either a global\n // variable defined at the app launch, or it is replaced by the actual value\n // by the Webpack build.\n const BUILD_INFO: BuildInfoT | undefined;\n}\n\nlet buildInfo: BuildInfoT | undefined;\n\n// On the client side \"BUILD_INFO\" should be injected by Webpack. Note, however,\n// that in test environment we may need situations were environment is mocked as\n// client-side, although no proper Webpack compilation is executed, thus no info\n// injected; because of this we don't do a hard environment check here.\nif (typeof BUILD_INFO !== 'undefined') buildInfo = BUILD_INFO;\n\n/**\n * In scenarious where \"BUILD_INFO\" is not injected by Webpack (server-side,\n * tests, etc.) we expect the host codebase to explicitly set it before it is\n * ever requested. As a precaution, this function throws if build info has been\n * set already, unless `force` flag is explicitly set.\n * @param info\n * @param force\n */\nexport function setBuildInfo(info?: BuildInfoT, force = false) {\n if (buildInfo !== undefined && !force) {\n throw Error('\"Build Info\" is already initialized');\n }\n buildInfo = info;\n}\n\n/**\n * Returns \"Build Info\" object; throws if it has not been initialized yet.\n * @returns\n */\nexport function getBuildInfo(): BuildInfoT {\n if (buildInfo === undefined) {\n throw Error('\"Build Info\" has not been initialized yet');\n }\n return buildInfo;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;AACA;AACA;;AAeA,IAAIA,SAAiC;;AAErC;AACA;AACA;AACA;AACA,IAAI,OAAOC,UAAU,KAAK,WAAW,EAAED,SAAS,GAAGC,UAAU;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAACC,IAAiB,EAAEC,KAAK,GAAG,KAAK,EAAE;EAC7D,IAAIJ,SAAS,KAAKK,SAAS,IAAI,CAACD,KAAK,EAAE;IACrC,MAAME,KAAK,CAAC,qCAAqC,CAAC;EACpD;EACAN,SAAS,GAAGG,IAAI;AAClB;;AAEA;AACA;AACA;AACA;AACO,SAASI,YAAYA,CAAA,EAAe;EACzC,IAAIP,SAAS,KAAKK,SAAS,EAAE;IAC3B,MAAMC,KAAK,CAAC,2CAA2C,CAAC;EAC1D;EACA,OAAON,SAAS;AAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"environment-check.js","names":["IS_CLIENT_SIDE","exports","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","IS_SERVER_SIDE"],"sources":["../../../../../src/shared/utils/isomorphy/environment-check.js"],"sourcesContent":["// Checks for client- vs. server-side environment detection.\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE = typeof process !== 'object'\n || !process.versions || !process.versions.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE = !IS_CLIENT_SIDE;\n"],"mappings":";;;;;;AAAA;;AAEA;AACA;AACA;AACO,MAAMA,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAG,OAAOE,OAAO,KAAK,QAAQ,IACpD,CAACA,OAAO,CAACC,QAAQ,IAAI,CAACD,OAAO,CAACC,QAAQ,CAACC,IAAI,IAC3C,CAAC,CAACC,MAAM,CAACC,6BAA6B;;AAE3C;AACA;AACA;AACO,MAAMC,cAAc,GAAAN,OAAA,CAAAM,cAAA,GAAG,CAACP,cAAc"}
1
+ {"version":3,"file":"environment-check.js","names":["IS_CLIENT_SIDE","exports","process","versions","node","global","REACT_UTILS_FORCE_CLIENT_SIDE","IS_SERVER_SIDE"],"sources":["../../../../../src/shared/utils/isomorphy/environment-check.ts"],"sourcesContent":["// Checks for client- vs. server-side environment detection.\n\ndeclare global {\n // eslint-disable-next-line no-var, vars-on-top\n var REACT_UTILS_FORCE_CLIENT_SIDE: boolean | undefined;\n}\n\n/**\n * `true` within client-side environment (browser), `false` at server-side.\n */\nexport const IS_CLIENT_SIDE: boolean = typeof process !== 'object'\n || !process.versions || !process.versions.node\n || !!global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n/**\n * `true` within the server-side environment (node), `false` at client-side.\n */\nexport const IS_SERVER_SIDE: boolean = !IS_CLIENT_SIDE;\n"],"mappings":";;;;;;AAAA;;AAOA;AACA;AACA;AACO,MAAMA,cAAuB,GAAAC,OAAA,CAAAD,cAAA,GAAG,OAAOE,OAAO,KAAK,QAAQ,IAC7D,CAACA,OAAO,CAACC,QAAQ,IAAI,CAACD,OAAO,CAACC,QAAQ,CAACC,IAAI,IAC3C,CAAC,CAACC,MAAM,CAACC,6BAA6B;;AAE3C;AACA;AACA;AACO,MAAMC,cAAuB,GAAAN,OAAA,CAAAM,cAAA,GAAG,CAACP,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_buildInfo","require","_environmentCheck","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","getBuildInfo","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.js"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n\nexport { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA,SAASE,OAAOA,CAAA,EAAG;EACjB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAOJ,OAAO,CAAC,CAAC,KAAK,aAAa;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASK,WAAWA,CAAA,EAAG;EAC5B,OAAOL,OAAO,CAAC,CAAC,KAAK,YAAY;AACnC;;AAEA;AACA;AACA;AACA;AACO,SAASM,cAAcA,CAAA,EAAG;EAC/B,OAAO,IAAAC,uBAAY,EAAC,CAAC,CAACC,SAAS;AACjC"}
1
+ {"version":3,"file":"index.js","names":["_buildInfo","require","_environmentCheck","getMode","process","env","NODE_ENV","isDevBuild","isProdBuild","buildTimestamp","getBuildInfo","timestamp"],"sources":["../../../../../src/shared/utils/isomorphy/index.ts"],"sourcesContent":["import { getBuildInfo } from './buildInfo';\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './environment-check';\n\n/**\n * @ignore\n * @return {string} Code mode: \"development\" or \"production\".\n */\nfunction getMode() {\n return process.env.NODE_ENV;\n}\n\n/**\n * Returns `true` if development version of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isDevBuild() {\n return getMode() === 'development';\n}\n\n/**\n * Returns `true` if production build of the code is running;\n * `false` otherwise.\n * @return {boolean}\n */\nexport function isProdBuild() {\n return getMode() === 'production';\n}\n\n/**\n * Returns build timestamp of the front-end JS bundle.\n * @return {string} ISO date/time string.\n */\nexport function buildTimestamp() {\n return getBuildInfo().timestamp;\n}\n\nexport { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA,SAASE,OAAOA,CAAA,EAAG;EACjB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAA,EAAG;EAC3B,OAAOJ,OAAO,CAAC,CAAC,KAAK,aAAa;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASK,WAAWA,CAAA,EAAG;EAC5B,OAAOL,OAAO,CAAC,CAAC,KAAK,YAAY;AACnC;;AAEA;AACA;AACA;AACA;AACO,SAASM,cAAcA,CAAA,EAAG;EAC/B,OAAO,IAAAC,uBAAY,EAAC,CAAC,CAACC,SAAS;AACjC"}
@@ -39,14 +39,15 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
39
39
  * webpackConfig object.
40
40
  */
41
41
  loadWebpackConfig() {
42
- let options = this.pragmas['webpack-config-options'];
43
- options = options ? JSON.parse(options) : {};
42
+ const optionsString = this.pragmas['webpack-config-options'];
43
+ const options = optionsString ? JSON.parse(optionsString) : {};
44
44
  (0, _lodash.defaults)(options, {
45
45
  context: this.testFolder,
46
46
  fs: this.global.webpackOutputFs
47
47
  });
48
- let factory = this.pragmas['webpack-config-factory'] || '';
49
- factory = require(_path.default.resolve(this.rootDir, factory));
48
+ const factoryPath = this.pragmas['webpack-config-factory'];
49
+ let factory = require(_path.default.resolve(this.rootDir, factoryPath));
50
+ factory = 'default' in factory ? factory.default : factory;
50
51
  this.global.webpackConfig = factory(options);
51
52
  const fs = this.global.webpackOutputFs;
52
53
  let buildInfo = `${options.context}/.build-info`;
@@ -67,11 +68,12 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
67
68
  return new Promise((done, fail) => {
68
69
  compiler.run((err, stats) => {
69
70
  if (err) fail(err);
70
- if (stats.hasErrors()) {
71
+ if (stats?.hasErrors()) {
72
+ // eslint-disable-next-line no-console
71
73
  console.error(stats.toJson().errors);
72
74
  fail(Error('Webpack compilation failed'));
73
75
  }
74
- this.global.webpackStats = stats.toJson();
76
+ this.global.webpackStats = stats?.toJson();
75
77
 
76
78
  // Keeps reference to the raw Webpack stats object, which should be
77
79
  // explicitly passed to the server-side renderer alongside the request,
@@ -82,8 +84,8 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
82
84
  });
83
85
  }
84
86
  async runSsr() {
85
- let options = this.pragmas['ssr-options'];
86
- options = options ? JSON.parse(options) : {};
87
+ const optionsString = this.pragmas['ssr-options'];
88
+ const options = optionsString ? JSON.parse(optionsString) : {};
87
89
 
88
90
  // TODO: This is temporary to shortcut the logging added to SSR.
89
91
  if (options.logger === undefined) {
@@ -94,27 +96,13 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
94
96
  warn: _lodash.noop
95
97
  };
96
98
  }
97
- let root;
98
- switch (options.root) {
99
- case 'TEST':
100
- root = this.testFolder;
101
- break;
102
- default:
103
- root = process.cwd();
104
- }
105
-
106
- // Note: This enables Babel transformation for the code dynamically loaded
107
- // below, as the usual Jest Babel setup does not seem to apply to
108
- // the environment code, and imports from it.
109
- (0, _experimentalWorker.default)({
110
- envName: options.babelEnv,
111
- extensions: ['.js', '.jsx', '.svg'],
112
- root
113
- });
114
99
  if (!options.buildInfo) options.buildInfo = this.global.buildInfo;
100
+ let cleanup;
115
101
  if (options.entry) {
116
102
  const p = _path.default.resolve(this.testFolder, options.entry);
117
- options.Application = require(p)[options.entryExportName || 'default'];
103
+ const module = require(p);
104
+ cleanup = module.cleanup;
105
+ options.Application = module[options.entryExportName || 'default'];
118
106
  }
119
107
  const renderer = (0, _renderer.default)(this.global.webpackConfig, options);
120
108
  let status = 200; // OK
@@ -147,11 +135,12 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
147
135
  this.global.ssrMarkup = markup;
148
136
  this.global.ssrOptions = options;
149
137
  this.global.ssrStatus = status;
138
+ if (cleanup) cleanup();
150
139
  }
151
140
  constructor(config, context) {
152
141
  const pragmas = context.docblockPragmas;
153
- let request = pragmas['ssr-request'];
154
- request = request ? JSON.parse(request) : {};
142
+ const requestString = pragmas['ssr-request'];
143
+ const request = requestString ? JSON.parse(requestString) : {};
155
144
  if (!request.url) request.url = '/';
156
145
  request.csrfToken = _lodash.noop;
157
146
 
@@ -170,6 +159,24 @@ class E2eSsrEnv extends _jestEnvironmentJsdom.default {
170
159
  this.withSsr = !pragmas['no-ssr'];
171
160
  this.ssrRequest = request;
172
161
  this.pragmas = pragmas;
162
+
163
+ // The usual "babel-jest" transformation setup does not apply to
164
+ // the environment code and imports from it, this workaround enables it.
165
+ const optionsString = this.pragmas['ssr-options'];
166
+ const options = optionsString ? JSON.parse(optionsString) : {};
167
+ let root;
168
+ switch (options.root) {
169
+ case 'TEST':
170
+ root = this.testFolder;
171
+ break;
172
+ default:
173
+ root = process.cwd();
174
+ }
175
+ (0, _experimentalWorker.default)({
176
+ envName: options.babelEnv,
177
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
178
+ root
179
+ });
173
180
  }
174
181
  async setup() {
175
182
  await super.setup();
@@ -1 +1 @@
1
- {"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_lodash","_experimentalWorker","_jestEnvironmentJsdom","_memfs","_webpack","_renderer","E2eSsrEnv","JsdomEnv","loadWebpackConfig","options","pragmas","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factory","path","resolve","rootDir","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","root","process","cwd","register","envName","babelEnv","extensions","entry","p","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports","default"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.js"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\n\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register/experimental-worker';\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nimport ssrFactory from 'server/renderer';\n\nexport default class E2eSsrEnv extends JsdomEnv {\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n let options = this.pragmas['webpack-config-options'];\n options = options ? JSON.parse(options) : {};\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n let factory = this.pragmas['webpack-config-factory'] || '';\n factory = require(path.resolve(this.rootDir, factory));\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8');\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats.hasErrors()) {\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n let options = this.pragmas['ssr-options'];\n options = options ? JSON.parse(options) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n\n // Note: This enables Babel transformation for the code dynamically loaded\n // below, as the usual Jest Babel setup does not seem to apply to\n // the environment code, and imports from it.\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.svg'],\n root,\n });\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n options.Application = require(p)[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig, options);\n let status = 200; // OK\n const markup = await new Promise((done, fail) => {\n renderer(\n this.ssrRequest,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n {\n cookie: noop,\n send: done,\n set: noop,\n status: (value) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n },\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n }\n\n constructor(config, context) {\n const pragmas = context.docblockPragmas;\n let request = pragmas['ssr-request'];\n request = request ? JSON.parse(request) : {};\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAKA,IAAAE,mBA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OAAO,CAAC,QAAQ,CAAC;IACjC,IAAI,CAACyD,UAAU,GAAGa,OAAO;IACzB,IAAI,CAACtE,OAAO,GAAGA,OAAO;EACxB;EAEA,MAAMgF,KAAKA,CAAA,EAAG;IACZ,MAAM,KAAK,CAACA,KAAK,CAAC,CAAC;IACnB,MAAM,IAAI,CAAC/D,UAAU,CAAC,CAAC;IACvB,IAAI,IAAI,CAAC8D,OAAO,EAAE,MAAM,IAAI,CAAC7C,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC3B,MAAM,CAAC0E,6BAA6B,GAAG,IAAI;EAClD;EAEA,MAAMC,QAAQA,CAAA,EAAG;IACf,OAAO,IAAI,CAAC3E,MAAM,CAAC0E,6BAA6B;;IAEhD;IACA;IACA;IACA;IACA;IACA;IACAE,MAAM,CAACC,IAAI,CAAC/F,OAAO,CAACgG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOlG,OAAO,CAACgG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACF1C,2BAAQ,CAAC2C,MAAM,CAAC,CAAC;IACjB,KAAK,CAACN,QAAQ,CAAC,CAAC;EAClB;AACF;AAACO,OAAA,CAAAC,OAAA,GAAA9F,SAAA"}
1
+ {"version":3,"file":"E2eSsrEnv.js","names":["_path","_interopRequireDefault","require","_lodash","_experimentalWorker","_jestEnvironmentJsdom","_memfs","_webpack","_renderer","E2eSsrEnv","JsdomEnv","loadWebpackConfig","optionsString","pragmas","options","JSON","parse","defaults","context","testFolder","fs","global","webpackOutputFs","factoryPath","factory","path","resolve","rootDir","default","webpackConfig","buildInfo","existsSync","readFileSync","runWebpack","compiler","webpack","outputFileSystem","Promise","done","fail","run","err","stats","hasErrors","console","error","toJson","errors","Error","webpackStats","runSsr","logger","undefined","debug","noop","info","log","warn","cleanup","entry","p","module","Application","entryExportName","renderer","ssrFactory","status","markup","ssrRequest","cookie","send","set","value","locals","devMiddleware","ssrMarkup","ssrOptions","ssrStatus","constructor","config","docblockPragmas","requestString","request","url","csrfToken","projectConfig","dom","createFsFromVolume","Volume","dirname","testPath","withSsr","root","process","cwd","register","envName","babelEnv","extensions","setup","REACT_UTILS_FORCE_CLIENT_SIDE","teardown","Object","keys","cache","forEach","key","revert","exports"],"sources":["../../../../../src/shared/utils/jest/E2eSsrEnv.ts"],"sourcesContent":["/**\n * Jest environment for end-to-end SSR and client-side testing. It relies on\n * the standard react-utils mechanics to execute SSR of given scene, and also\n * Webpack build of the code for client-side execution, it further exposes\n * Jsdom environment for the client-side testing of the outcomes.\n */\n/* eslint-disable global-require, import/no-dynamic-require */\n\n// BEWARE: The module is not imported into the JU module / the main assembly of\n// the library, because doing so easily breaks stuff:\n// 1) This module depends on Node-specific modules, which would make JU\n// incompatible with JsDom if included into JU.\n// 2) If this module is weakly imported from somewhere else in the lib,\n// it seems to randomly break tests using it for a different reason,\n// probably some sort of a require-loop, or some issues with weak\n// require in that scenario.\n\nimport path from 'path';\n\nimport type { Request, Response } from 'express';\nimport { defaults, noop, set } from 'lodash';\n\n// As this environment is a part of the Jest testing utils,\n// we assume development dependencies are available when it is used.\n/* eslint-disable import/no-extraneous-dependencies */\nimport register from '@babel/register/experimental-worker';\n\nimport JsdomEnv from 'jest-environment-jsdom';\nimport { type IFs, createFsFromVolume, Volume } from 'memfs';\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\nimport ssrFactory from 'server/renderer';\n\nimport type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\n\nexport default class E2eSsrEnv extends JsdomEnv {\n pragmas: Record<string, string | string[]>;\n\n ssrRequest: object;\n\n rootDir: string;\n\n testFolder: string;\n\n withSsr: boolean;\n\n webpackStats?: webpack.StatsCompilation;\n\n /**\n * Loads Webpack config, and exposes it to the environment via global\n * webpackConfig object.\n */\n loadWebpackConfig() {\n const optionsString = this.pragmas['webpack-config-options'] as string;\n\n const options = (optionsString\n ? JSON.parse(optionsString) : {}) as webpack.Configuration;\n\n defaults(options, {\n context: this.testFolder,\n fs: this.global.webpackOutputFs,\n });\n\n const factoryPath = this.pragmas['webpack-config-factory'] as string;\n let factory = require(path.resolve(this.rootDir, factoryPath));\n factory = 'default' in factory ? factory.default : factory;\n\n this.global.webpackConfig = factory(options);\n\n const fs = this.global.webpackOutputFs as IFs;\n let buildInfo = `${options.context}/.build-info`;\n if (fs.existsSync(buildInfo)) {\n buildInfo = fs.readFileSync(buildInfo, 'utf8') as string;\n this.global.buildInfo = JSON.parse(buildInfo);\n }\n }\n\n /**\n * Executes Webpack build.\n * @return {Promise}\n */\n async runWebpack() {\n this.loadWebpackConfig();\n\n const compiler = webpack(this.global.webpackConfig as webpack.Configuration);\n compiler.outputFileSystem = this.global.webpackOutputFs;\n return new Promise<void>((done, fail) => {\n compiler.run((err, stats) => {\n if (err) fail(err);\n if (stats?.hasErrors()) {\n // eslint-disable-next-line no-console\n console.error(stats.toJson().errors);\n fail(Error('Webpack compilation failed'));\n }\n\n this.global.webpackStats = stats?.toJson();\n\n // Keeps reference to the raw Webpack stats object, which should be\n // explicitly passed to the server-side renderer alongside the request,\n // so that it can to pick up asset paths for different named chunks.\n this.webpackStats = stats;\n\n done();\n });\n });\n }\n\n async runSsr() {\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString ? JSON.parse(optionsString) : {};\n\n // TODO: This is temporary to shortcut the logging added to SSR.\n if (options.logger === undefined) {\n options.logger = {\n debug: noop,\n info: noop,\n log: noop,\n warn: noop,\n };\n }\n\n if (!options.buildInfo) options.buildInfo = this.global.buildInfo;\n\n let cleanup: (() => void) | undefined;\n\n if (options.entry) {\n const p = path.resolve(this.testFolder, options.entry);\n const module = require(p);\n cleanup = module.cleanup;\n options.Application = module[options.entryExportName || 'default'];\n }\n\n const renderer = ssrFactory(this.global.webpackConfig!, options);\n let status = 200; // OK\n const markup = await new Promise<string>((done, fail) => {\n renderer(\n this.ssrRequest as Request,\n\n // TODO: This will do for now, with the current implementation of\n // the renderer, but it will require a rework once the renderer is\n // updated to do streaming.\n ({\n cookie: noop,\n send: done,\n set: noop,\n status: (value: number) => {\n status = value;\n },\n\n // This is how up-to-date Webpack stats are passed to the server in\n // development mode, and we use this here always, instead of having\n // to pass some information via filesystem.\n locals: {\n webpack: {\n devMiddleware: {\n stats: this.webpackStats,\n },\n },\n },\n } as unknown) as Response,\n\n (error) => {\n if (error) fail(error);\n else done('');\n },\n );\n });\n\n this.global.ssrMarkup = markup;\n this.global.ssrOptions = options;\n this.global.ssrStatus = status;\n\n if (cleanup) cleanup();\n }\n\n constructor(\n config: JestEnvironmentConfig,\n context: EnvironmentContext,\n ) {\n const pragmas = context.docblockPragmas;\n\n const requestString = pragmas['ssr-request'] as string;\n const request = requestString ? JSON.parse(requestString) : {};\n\n if (!request.url) request.url = '/';\n request.csrfToken = noop;\n\n // This ensures the initial JsDom URL matches the value we use for SSR.\n set(\n config.projectConfig,\n 'testEnvironmentOptions.url',\n `http://localhost${request.url}`,\n );\n\n super(config, context);\n\n this.global.dom = this.dom;\n this.global.webpackOutputFs = createFsFromVolume(new Volume());\n\n // Extracts necessary settings from config and context.\n const { projectConfig } = config;\n this.rootDir = projectConfig.rootDir;\n this.testFolder = path.dirname(context.testPath);\n this.withSsr = !pragmas['no-ssr'];\n this.ssrRequest = request;\n this.pragmas = pragmas;\n\n // The usual \"babel-jest\" transformation setup does not apply to\n // the environment code and imports from it, this workaround enables it.\n const optionsString = this.pragmas['ssr-options'] as string;\n const options = optionsString ? JSON.parse(optionsString) : {};\n let root;\n switch (options.root) {\n case 'TEST': root = this.testFolder; break;\n default: root = process.cwd();\n }\n register({\n envName: options.babelEnv,\n extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],\n root,\n });\n }\n\n async setup() {\n await super.setup();\n await this.runWebpack();\n if (this.withSsr) await this.runSsr();\n this.global.REACT_UTILS_FORCE_CLIENT_SIDE = true;\n }\n\n async teardown() {\n delete this.global.REACT_UTILS_FORCE_CLIENT_SIDE;\n\n // Resets module cache and @babel/register. Effectively this ensures that\n // the next time an instance of this environment is set up, all modules are\n // transformed by Babel from scratch, thus taking into account the latest\n // Babel config (which may change between different environment instances,\n // which does not seem to be taken into account by Babel / Node caches\n // automatically).\n Object.keys(require.cache).forEach((key) => {\n delete require.cache[key];\n });\n register.revert();\n super.teardown();\n }\n}\n"],"mappings":";;;;;;;AAiBA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,OAAA,GAAAD,OAAA;AAKA,IAAAE,mBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,qBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AAGA,IAAAM,SAAA,GAAAP,sBAAA,CAAAC,OAAA;AAhCA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AAMA;AASe,MAAMO,SAAS,SAASC,6BAAQ,CAAC;EAa9C;AACF;AACA;AACA;EACEC,iBAAiBA,CAAA,EAAG;IAClB,MAAMC,aAAa,GAAG,IAAI,CAACC,OAAO,CAAC,wBAAwB,CAAW;IAEtE,MAAMC,OAAO,GAAIF,aAAa,GAC1BG,IAAI,CAACC,KAAK,CAACJ,aAAa,CAAC,GAAG,CAAC,CAA2B;IAE5D,IAAAK,gBAAQ,EAACH,OAAO,EAAE;MAChBI,OAAO,EAAE,IAAI,CAACC,UAAU;MACxBC,EAAE,EAAE,IAAI,CAACC,MAAM,CAACC;IAClB,CAAC,CAAC;IAEF,MAAMC,WAAW,GAAG,IAAI,CAACV,OAAO,CAAC,wBAAwB,CAAW;IACpE,IAAIW,OAAO,GAAGtB,OAAO,CAACuB,aAAI,CAACC,OAAO,CAAC,IAAI,CAACC,OAAO,EAAEJ,WAAW,CAAC,CAAC;IAC9DC,OAAO,GAAG,SAAS,IAAIA,OAAO,GAAGA,O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E,MAAM,CAACC,IAAI,CAACrG,OAAO,CAACsG,KAAK,CAAC,CAACC,OAAO,CAAEC,GAAG,IAAK;MAC1C,OAAOxG,OAAO,CAACsG,KAAK,CAACE,GAAG,CAAC;IAC3B,CAAC,CAAC;IACFX,2BAAQ,CAACY,MAAM,CAAC,CAAC;IACjB,KAAK,CAACN,QAAQ,CAAC,CAAC;EAClB;AACF;AAACO,OAAA,CAAAhF,OAAA,GAAAnB,SAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = getGlobal;
8
+ require("memfs");
9
+ var _webpack = _interopRequireDefault(require("webpack"));
10
+ /* eslint-disable import/no-extraneous-dependencies */
11
+
12
+ /* eslint-enable import/no-extraneous-dependencies */
13
+
14
+ function getGlobal() {
15
+ return global;
16
+ }
17
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","names":["require","_webpack","_interopRequireDefault","getGlobal","global"],"sources":["../../../../../src/shared/utils/jest/global.ts"],"sourcesContent":["import { type IFs } from 'memfs';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport webpack from 'webpack';\n/* eslint-enable import/no-extraneous-dependencies */\n\ndeclare global {\n interface Window {\n ssrMarkup: string | undefined;\n ssrStatus: number | undefined;\n webpackConfig: webpack.Configuration | undefined;\n webpackOutputFs: IFs;\n webpackStats?: webpack.StatsCompilation;\n }\n}\n\nexport default function getGlobal(): Window {\n return global as any;\n}\n"],"mappings":";;;;;;;AAAAA,OAAA;AAGA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AADA;;AAEA;;AAYe,SAASG,SAASA,CAAA,EAAW;EAC1C,OAAOC,MAAM;AACf"}
@@ -10,6 +10,12 @@ Object.defineProperty(exports, "act", {
10
10
  return _testUtils.act;
11
11
  }
12
12
  });
13
+ Object.defineProperty(exports, "getGlobal", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _global.default;
17
+ }
18
+ });
13
19
  exports.getMockUuid = getMockUuid;
14
20
  exports.mockClientSide = mockClientSide;
15
21
  exports.mockTimer = mockTimer;
@@ -21,12 +27,14 @@ exports.simulate = void 0;
21
27
  exports.snapshot = snapshot;
22
28
  exports.unmockClientSide = unmockClientSide;
23
29
  var _mockdate = _interopRequireDefault(require("mockdate"));
30
+ require("react");
24
31
  var _client = require("react-dom/client");
25
32
  var _testUtils = _interopRequireWildcard(require("react-dom/test-utils"));
26
33
  var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
27
- var _shallow = _interopRequireDefault(require("react-test-renderer/shallow"));
28
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
34
+ var _shallow = require("react-test-renderer/shallow");
35
+ var _global = _interopRequireDefault(require("./global"));
36
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
37
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
30
38
  /* global expect, jest, document */
31
39
  /* eslint-disable import/no-extraneous-dependencies */
32
40
 
@@ -82,17 +90,17 @@ async function mockTimer(time) {
82
90
  _mockdate.default.set(time + Date.now());
83
91
  jest.advanceTimersByTime(time);
84
92
  }
85
-
86
93
  /**
87
94
  * Mounts `scene` to the DOM, and returns the root scene element.
88
- * @param {React.ReactNode} scene
89
- * @return {HTMLElement} Created container DOM element with destroy() function
95
+ * @param scene
96
+ * @return Created container DOM element with destroy() function
90
97
  * attached.
91
98
  */
92
99
  function mount(scene) {
93
100
  let root;
94
- const res = document.createElement('div');
95
- document.body.appendChild(res);
101
+ const element = document.createElement('div');
102
+ document.body.appendChild(element);
103
+ const res = element;
96
104
  res.destroy = () => {
97
105
  (0, _testUtils.act)(() => root.unmount());
98
106
  res.remove();
@@ -127,7 +135,7 @@ function render(component) {
127
135
  * @return {object} JSON representation of the shallow component's render tree.
128
136
  */
129
137
  function shallowRender(component) {
130
- const renderer = new _shallow.default();
138
+ const renderer = (0, _shallow.createRenderer)();
131
139
  renderer.render(component);
132
140
  return renderer.getRenderOutput();
133
141
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","res","document","createElement","body","appendChild","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","ShallowRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","exports","TU","Simulate"],"sources":["../../../../../src/shared/utils/jest/index.jsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport ShallowRenderer from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param {React.ReactNode} scene\n * @return {HTMLElement} Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene) {\n let root;\n const res = document.createElement('div');\n document.body.appendChild(res);\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component) {\n const renderer = new ShallowRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AAGA,IAAAI,kBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AAA0D,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAA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,GAAGe,aAAa,CAACJ,SAAS,CAAC;EACpCS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,CAAC,CAAC;EAC7B,OAAOrB,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASsB,QAAQA,CAACX,SAAS,EAAE;EAClC,MAAMX,GAAG,GAAGU,MAAM,CAACC,SAAS,CAAC;EAC7BS,MAAM,CAACpB,GAAG,CAAC,CAACqB,eAAe,CAAC,CAAC;EAC7B,OAAOrB,GAAG;AACZ;AAEO,MAAMuB,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGE,kBAAE,CAACC,QAAQ"}
1
+ {"version":3,"file":"index.js","names":["_mockdate","_interopRequireDefault","require","_client","_testUtils","_interopRequireWildcard","_reactTestRenderer","_shallow","_global","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","global","IS_REACT_ACT_ENVIRONMENT","originalProcessVersions","process","versions","mockClientSide","value","unmockClientSide","writable","getMockUuid","seed","x","toString","padStart","slice","mockTimer","time","mockdate","Date","now","jest","advanceTimersByTime","mount","scene","root","element","document","createElement","body","appendChild","res","destroy","act","unmount","remove","createRoot","render","component","Renderer","create","toJSON","shallowRender","renderer","createRenderer","getRenderOutput","shallowSnapshot","expect","toMatchSnapshot","snapshot","simulate","exports","TU","Simulate"],"sources":["../../../../../src/shared/utils/jest/index.tsx"],"sourcesContent":["/* global expect, jest, document */\n/* eslint-disable import/no-extraneous-dependencies */\n\nimport mockdate from 'mockdate';\nimport { type ReactElement, type ReactNode } from 'react';\nimport { type Root, createRoot } from 'react-dom/client';\nimport TU, { act } from 'react-dom/test-utils';\n\n/* eslint-disable import/no-extraneous-dependencies */\nimport Renderer from 'react-test-renderer';\nimport { type ShallowRenderer, createRenderer } from 'react-test-renderer/shallow';\n/* eslint-enable import/no-extraneous-dependencies */\n\n/**\n * An alias for [act(..)](https://reactjs.org/docs/test-utils.html#act)\n * from `react-dom/test-utils`.\n * @param {function} action\n */\nexport { act };\n\nexport { default as getGlobal } from './global';\n\ndeclare global {\n // eslint-disable-next-line no-var, vars-on-top\n var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;\n}\n\nglobal.IS_REACT_ACT_ENVIRONMENT = true;\n\nconst originalProcessVersions = process.versions;\n\n/**\n * Tricks **react-utils** into thinking the test is running within client-side\n * (browser) environment.\n */\nexport function mockClientSide() {\n Object.defineProperty(process, 'versions', { value: null });\n}\n\n/**\n * Reverts the effect of {@link module:JU.mockClientSide mockClientSide(..)}.\n */\nexport function unmockClientSide() {\n Object.defineProperty(process, 'versions', {\n value: originalProcessVersions,\n writable: false,\n });\n}\n\n/**\n * Generates a mock UUID, or better said it determenistically transforms given\n * `seed` number into a UUID-formatted string.\n * @param {number} seed\n * @return {string}\n */\nexport function getMockUuid(seed = 0) {\n const x = seed.toString(16).padStart(32, '0');\n return `${x.slice(0, 8)}-${x.slice(8, 12)}-${x.slice(12, 16)}-${x.slice(16, 20)}-${x.slice(20)}`;\n}\n\n/**\n * Advances mock timers, and mock date by the specified time.\n * @param {number} time Time step [ms].\n * @returns {Promise} Wait for this to \"jump after\" any async code which should\n * be executed because of the mock time movement.\n */\nexport async function mockTimer(time: number) {\n mockdate.set(time + Date.now());\n jest.advanceTimersByTime(time);\n}\n\nexport type MountedSceneT = HTMLElement & {\n destroy: () => void;\n};\n\n/**\n * Mounts `scene` to the DOM, and returns the root scene element.\n * @param scene\n * @return Created container DOM element with destroy() function\n * attached.\n */\nexport function mount(scene: ReactNode): MountedSceneT {\n let root: Root;\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const res: MountedSceneT = (element as unknown) as MountedSceneT;\n res.destroy = () => {\n act(() => root.unmount());\n res.remove();\n };\n\n act(() => {\n root = createRoot(res);\n root.render(scene);\n });\n return res;\n}\n\n/* OLD STUFF BELOW THIS MARK */\n\n/**\n * Renders provided ReactJS component into JSON representation of the component\n * tree, using [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the rendered tree.\n * @example\n * import { JU } from '@dr.pogodin/react-utils';\n * console.log(JU.render(<div>Example</div>));\n */\nexport function render(component: ReactElement) {\n return Renderer.create(component).toJSON();\n}\n\n/**\n * Generates a shallow render of given ReactJS component, using\n * [react-test-renderer/shallow](https://reactjs.org/docs/shallow-renderer.html)\n * and returns the result.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of the shallow component's render tree.\n */\nexport function shallowRender(component: ReactElement) {\n const renderer: ShallowRenderer = createRenderer();\n renderer.render(component);\n return renderer.getRenderOutput();\n}\n\n/**\n * Makes a shallow snapshot test of the given ReactJS component, and also\n * returns JSON representation of the rendered component tree. Under the hood\n * it uses {@link module:JU.shallowRender shallowRender(..)} to generate\n * the render, then executes `expect(RENDER_RESULT).toMatchSnapshot()`,\n * and finally returns the `RENDER_RESULT` to the caller.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON representation of shallow render.\n */\nexport function shallowSnapshot(component: ReactElement) {\n const res = shallowRender(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\n/**\n * Makes snapshot test of the given ReactJS component, and also returns JSON\n * representation of the rendered component tree. Under the hood, it uses\n * {@link module:JU.render render(..)} to render it, then executes\n * `expect(RENDER_RESULT).toMatchSnapshot()`, and then returns `RENDER_RESULT`.\n * @param {object} component ReactJS component to render.\n * @return {object} JSON render of the component.\n */\nexport function snapshot(component: ReactElement) {\n const res = render(component);\n expect(res).toMatchSnapshot();\n return res;\n}\n\nexport const simulate = TU.Simulate;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACAA,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,uBAAA,CAAAH,OAAA;AAGA,IAAAI,kBAAA,GAAAL,sBAAA,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CAAC,CAACiB,eAAe,CAAC,CAAC;EAC7B,OAAOjB,GAAG;AACZ;AAEO,MAAMmB,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGE,kBAAE,CAACC,QAAQ"}
@@ -10,7 +10,7 @@ exports.freeStyleSheets = freeStyleSheets;
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
  var _react = require("react");
12
12
  var _jsUtils = require("@dr.pogodin/js-utils");
13
- var _reactGlobalState = require("@dr.pogodin/react-global-state");
13
+ var _globalState = require("./globalState");
14
14
  var _isomorphy = require("./isomorphy");
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
16
  /* eslint-disable react/jsx-props-no-spreading */
@@ -34,10 +34,10 @@ function getPublicPath() {
34
34
  * Client-side only! Ensures the specified CSS stylesheet is loaded into
35
35
  * the document; loads if it is missing; and does simple reference counting
36
36
  * to facilitate future clean-up.
37
- * @param {string} name
38
- * @param {Set} loadedSheets
39
- * @param {boolean} refCount
40
- * @return {Promise}
37
+ * @param name
38
+ * @param loadedSheets
39
+ * @param refCount
40
+ * @return
41
41
  */
42
42
  function bookStyleSheet(name, loadedSheets, refCount) {
43
43
  let res;
@@ -52,8 +52,8 @@ function bookStyleSheet(name, loadedSheets, refCount) {
52
52
  document.head.appendChild(link);
53
53
  }
54
54
  res = new _jsUtils.Barrier();
55
- link.addEventListener('load', res.resolve);
56
- link.addEventListener('error', res.resolve);
55
+ link.addEventListener('load', () => res.resolve());
56
+ link.addEventListener('error', () => res.resolve());
57
57
  }
58
58
  if (refCount) {
59
59
  const current = refCounts[path] || 0;
@@ -64,7 +64,7 @@ function bookStyleSheet(name, loadedSheets, refCount) {
64
64
 
65
65
  /**
66
66
  * Generates the set of URLs for currently loaded, linked stylesheets.
67
- * @return {Set}
67
+ * @return
68
68
  */
69
69
  function getLoadedStyleSheets() {
70
70
  const res = new Set();
@@ -88,9 +88,9 @@ function assertChunkName(chunkName, chunkGroups) {
88
88
  * Client-side only! Ensures all CSS stylesheets required for the specified
89
89
  * code chunk are loaded into the document; loads the missing ones; and does
90
90
  * simple reference counting to facilitate future clean-up.
91
- * @param {string} chunkName Chunk name.
92
- * @param {boolean} refCount
93
- * @return {Promise} Resolves once all pending stylesheets, necessary for
91
+ * @param chunkName Chunk name.
92
+ * @param refCount
93
+ * @return Resolves once all pending stylesheets, necessary for
94
94
  * the chunk, are either loaded, or failed to load.
95
95
  */
96
96
  function bookStyleSheets(chunkName, chunkGroups, refCount) {
@@ -104,7 +104,7 @@ function bookStyleSheets(chunkName, chunkGroups, refCount) {
104
104
  if (promise) promises.push(promise);
105
105
  }
106
106
  }
107
- return promises.length ? Promise.allSettled(promises) : Promise.resolve();
107
+ return promises.length ? Promise.allSettled(promises).then() : Promise.resolve();
108
108
  }
109
109
 
110
110
  /**
@@ -129,13 +129,12 @@ function freeStyleSheets(chunkName, chunkGroups) {
129
129
 
130
130
  // Holds the set of chunk names already used for splitComponent() calls.
131
131
  const usedChunkNames = new Set();
132
-
133
132
  /**
134
133
  * Given an async component retrieval function `getComponent()` it creates
135
134
  * a special "code split" component, which uses <Suspense> to asynchronously
136
135
  * load on demand the code required by `getComponent()`.
137
- * @param {object} options
138
- * @param {string} options.chunkName
136
+ * @param options
137
+ * @param options.chunkName
139
138
  * @param {function} options.getComponent
140
139
  * @param {React.Element} [options.placeholder]
141
140
  * @return {React.ElementType}
@@ -153,8 +152,8 @@ function splitComponent({
153
152
  throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
154
153
  } else usedChunkNames.add(chunkName);
155
154
  const LazyComponent = /*#__PURE__*/(0, _react.lazy)(async () => {
156
- let Component = await getComponent();
157
- if (Component.default) Component = Component.default;
155
+ const resolved = await getComponent();
156
+ const Component = 'default' in resolved ? resolved.default : resolved;
158
157
 
159
158
  // This pre-loads necessary stylesheets prior to the first mount of
160
159
  // the component (the lazy load function is executed by React one at
@@ -172,7 +171,7 @@ function splitComponent({
172
171
  const {
173
172
  chunkGroups,
174
173
  chunks
175
- } = (0, _reactGlobalState.getSsrContext)();
174
+ } = (0, _globalState.getSsrContext)();
176
175
  assertChunkName(chunkName, chunkGroups);
177
176
  if (!chunks.includes(chunkName)) chunks.push(chunkName);
178
177
  }
@@ -189,28 +188,20 @@ function splitComponent({
189
188
  children: children
190
189
  });
191
190
  });
192
- Wrapper.propTypes = {
193
- children: _propTypes.default.node
194
- };
195
- Wrapper.defaultProps = {
196
- children: undefined
197
- };
198
191
  return {
199
192
  default: Wrapper
200
193
  };
201
194
  });
202
- function CodeSplit({
195
+ const CodeSplit = ({
203
196
  children,
204
197
  ...rest
205
- }) {
206
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Suspense, {
207
- fallback: placeholder,
208
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LazyComponent, {
209
- ...rest,
210
- children: children
211
- })
212
- });
213
- }
198
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Suspense, {
199
+ fallback: placeholder,
200
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LazyComponent, {
201
+ ...rest,
202
+ children: children
203
+ })
204
+ });
214
205
  CodeSplit.propTypes = {
215
206
  children: _propTypes.default.node
216
207
  };