@dr.pogodin/react-utils 1.54.2 → 1.55.0-alpha.1

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 (229) hide show
  1. package/__type_tests__/ts-compiler-behavior.ts +13 -0
  2. package/__type_tests__/type-exports.ts +17 -0
  3. package/babel.build.config.js +9 -0
  4. package/babel.config.js +2 -5
  5. package/babel.libweb.config.js +2 -3
  6. package/babel.scripts.config.js +5 -11
  7. package/bin/build.js +4 -21
  8. package/bin/release.sh +1 -1
  9. package/build/development/client/getInj.js +2 -9
  10. package/build/development/client/getInj.js.map +1 -1
  11. package/build/development/client/index.js.map +1 -1
  12. package/build/development/client/init.js +1 -3
  13. package/build/development/client/init.js.map +1 -1
  14. package/build/development/index.js.map +1 -1
  15. package/build/development/server/Cache.js.map +1 -1
  16. package/build/development/server/index.js.map +1 -1
  17. package/build/development/server/renderer.js +10 -24
  18. package/build/development/server/renderer.js.map +1 -1
  19. package/build/development/server/server.js +6 -8
  20. package/build/development/server/server.js.map +1 -1
  21. package/build/development/server/utils/errors.js +11 -11
  22. package/build/development/server/utils/errors.js.map +1 -1
  23. package/build/development/shared/components/Button/index.js.map +1 -1
  24. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  25. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  26. package/build/development/shared/components/Input/index.js.map +1 -1
  27. package/build/development/shared/components/Link.js.map +1 -1
  28. package/build/development/shared/components/Modal/index.js.map +1 -1
  29. package/build/development/shared/components/NavLink.js.map +1 -1
  30. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  31. package/build/development/shared/components/TextArea/index.js.map +1 -1
  32. package/build/development/shared/components/Throbber/index.js.map +1 -1
  33. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  34. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  35. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  36. package/build/development/shared/components/index.js.map +1 -1
  37. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +2 -5
  38. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  39. package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -4
  40. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  41. package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -5
  42. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  43. package/build/development/shared/components/selectors/Switch/index.js +2 -2
  44. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  45. package/build/development/shared/components/selectors/common.js.map +1 -1
  46. package/build/development/shared/components/selectors/index.js.map +1 -1
  47. package/build/development/shared/utils/config.js.map +1 -1
  48. package/build/development/shared/utils/globalState.js.map +1 -1
  49. package/build/development/shared/utils/index.js.map +1 -1
  50. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  51. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  52. package/build/development/shared/utils/isomorphy/index.js +4 -5
  53. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  54. package/build/development/shared/utils/jest/E2eSsrEnv/index.js +32 -71
  55. package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  56. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js +23 -0
  57. package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  58. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
  59. package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  60. package/build/development/shared/utils/jest/global.js.map +1 -1
  61. package/build/development/shared/utils/jest/index.js +3 -3
  62. package/build/development/shared/utils/jest/index.js.map +1 -1
  63. package/build/development/shared/utils/splitComponent.js +3 -16
  64. package/build/development/shared/utils/splitComponent.js.map +1 -1
  65. package/build/development/shared/utils/time.js +28 -65
  66. package/build/development/shared/utils/time.js.map +1 -1
  67. package/build/development/shared/utils/webpack.js +3 -5
  68. package/build/development/shared/utils/webpack.js.map +1 -1
  69. package/build/production/client/getInj.js +1 -1
  70. package/build/production/client/getInj.js.map +1 -1
  71. package/build/production/client/index.js.map +1 -1
  72. package/build/production/client/init.js.map +1 -1
  73. package/build/production/index.js.map +1 -1
  74. package/build/production/server/Cache.js.map +1 -1
  75. package/build/production/server/index.js.map +1 -1
  76. package/build/production/server/renderer.js +5 -5
  77. package/build/production/server/renderer.js.map +1 -1
  78. package/build/production/server/server.js +4 -4
  79. package/build/production/server/server.js.map +1 -1
  80. package/build/production/server/utils/errors.js +2 -2
  81. package/build/production/server/utils/errors.js.map +1 -1
  82. package/build/production/shared/components/Button/index.js.map +1 -1
  83. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  84. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  85. package/build/production/shared/components/Input/index.js.map +1 -1
  86. package/build/production/shared/components/Link.js.map +1 -1
  87. package/build/production/shared/components/Modal/index.js.map +1 -1
  88. package/build/production/shared/components/NavLink.js.map +1 -1
  89. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  90. package/build/production/shared/components/TextArea/index.js.map +1 -1
  91. package/build/production/shared/components/Throbber/index.js.map +1 -1
  92. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  93. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  94. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  95. package/build/production/shared/components/index.js.map +1 -1
  96. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  97. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  98. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  99. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  100. package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
  101. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  102. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  103. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/common.js.map +1 -1
  105. package/build/production/shared/components/selectors/index.js.map +1 -1
  106. package/build/production/shared/utils/config.js.map +1 -1
  107. package/build/production/shared/utils/globalState.js.map +1 -1
  108. package/build/production/shared/utils/index.js.map +1 -1
  109. package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
  110. package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
  111. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  112. package/build/production/shared/utils/jest/E2eSsrEnv/index.js +12 -37
  113. package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  114. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
  115. package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  116. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
  117. package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  118. package/build/production/shared/utils/jest/global.js.map +1 -1
  119. package/build/production/shared/utils/jest/index.js +3 -3
  120. package/build/production/shared/utils/jest/index.js.map +1 -1
  121. package/build/production/shared/utils/splitComponent.js +3 -3
  122. package/build/production/shared/utils/splitComponent.js.map +1 -1
  123. package/build/production/shared/utils/time.js +2 -2
  124. package/build/production/shared/utils/time.js.map +1 -1
  125. package/build/production/shared/utils/webpack.js +3 -3
  126. package/build/production/shared/utils/webpack.js.map +1 -1
  127. package/build/types-code/shared/utils/webpack.d.ts +2 -2
  128. package/build/web/client/getInj.js +2 -2
  129. package/build/web/client/getInj.js.map +1 -1
  130. package/build/web/client/index.js +1 -1
  131. package/build/web/client/index.js.map +1 -1
  132. package/build/web/client/init.js +1 -1
  133. package/build/web/client/init.js.map +1 -1
  134. package/build/web/index.js +1 -1
  135. package/build/web/index.js.map +1 -1
  136. package/build/web/server/Cache.js.map +1 -1
  137. package/build/web/server/index.js +1 -1
  138. package/build/web/server/index.js.map +1 -1
  139. package/build/web/server/renderer.js +6 -6
  140. package/build/web/server/renderer.js.map +1 -1
  141. package/build/web/server/server.js +5 -5
  142. package/build/web/server/server.js.map +1 -1
  143. package/build/web/server/utils/errors.js +2 -2
  144. package/build/web/server/utils/errors.js.map +1 -1
  145. package/build/web/server/utils/index.js +1 -1
  146. package/build/web/server/utils/index.js.map +1 -1
  147. package/build/web/shared/components/Button/index.js +1 -1
  148. package/build/web/shared/components/Button/index.js.map +1 -1
  149. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  150. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  151. package/build/web/shared/components/Input/index.js.map +1 -1
  152. package/build/web/shared/components/Link.js +1 -1
  153. package/build/web/shared/components/Link.js.map +1 -1
  154. package/build/web/shared/components/Modal/index.js.map +1 -1
  155. package/build/web/shared/components/NavLink.js +1 -1
  156. package/build/web/shared/components/NavLink.js.map +1 -1
  157. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  158. package/build/web/shared/components/TextArea/index.js.map +1 -1
  159. package/build/web/shared/components/Throbber/index.js.map +1 -1
  160. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  161. package/build/web/shared/components/WithTooltip/index.js +1 -1
  162. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  163. package/build/web/shared/components/YouTubeVideo/index.js +1 -1
  164. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  165. package/build/web/shared/components/index.js +1 -1
  166. package/build/web/shared/components/index.js.map +1 -1
  167. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  168. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  169. package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
  170. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  171. package/build/web/shared/components/selectors/NativeDropdown/index.js +3 -3
  172. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  173. package/build/web/shared/components/selectors/Switch/index.js +1 -1
  174. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  175. package/build/web/shared/components/selectors/common.js.map +1 -1
  176. package/build/web/shared/components/selectors/index.js +1 -1
  177. package/build/web/shared/components/selectors/index.js.map +1 -1
  178. package/build/web/shared/utils/config.js +1 -1
  179. package/build/web/shared/utils/config.js.map +1 -1
  180. package/build/web/shared/utils/globalState.js.map +1 -1
  181. package/build/web/shared/utils/index.js +1 -1
  182. package/build/web/shared/utils/index.js.map +1 -1
  183. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  184. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  185. package/build/web/shared/utils/isomorphy/index.js +1 -1
  186. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  187. package/build/web/shared/utils/jest/E2eSsrEnv/index.js +12 -37
  188. package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
  189. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
  190. package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
  191. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js +2 -2
  192. package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
  193. package/build/web/shared/utils/jest/global.js.map +1 -1
  194. package/build/web/shared/utils/jest/index.js +4 -4
  195. package/build/web/shared/utils/jest/index.js.map +1 -1
  196. package/build/web/shared/utils/splitComponent.js +3 -3
  197. package/build/web/shared/utils/splitComponent.js.map +1 -1
  198. package/build/web/shared/utils/time.js +2 -2
  199. package/build/web/shared/utils/time.js.map +1 -1
  200. package/build/web/shared/utils/webpack.js +4 -4
  201. package/build/web/shared/utils/webpack.js.map +1 -1
  202. package/config/babel/node-ssr.d.ts +2 -3
  203. package/config/babel/node-ssr.js +15 -55
  204. package/config/babel/webpack.d.ts +7 -5
  205. package/config/babel/webpack.js +19 -24
  206. package/config/eslint/default.mjs +1 -1
  207. package/config/jest/default.js +6 -7
  208. package/config/jest/resolver.js +1 -3
  209. package/config/jest/setup.js +2 -2
  210. package/config/stylelint/default.js +1 -4
  211. package/config/webpack/app-base.js +40 -41
  212. package/config/webpack/app-development.d.ts +1 -1
  213. package/config/webpack/app-development.js +12 -18
  214. package/config/webpack/app-production.d.ts +1 -1
  215. package/config/webpack/app-production.js +10 -16
  216. package/package.json +42 -39
  217. package/patches/jest-resolve+30.4.1.patch +29 -0
  218. package/tsconfig.configs.json +6 -1
  219. package/tsconfig.json +2 -1
  220. package/tsconfig.types.json +1 -0
  221. package/tstyche.json +1 -1
  222. package/babel.module.config.js +0 -11
  223. package/build/development/shared/utils/jest/E2eSsrEnv/register.js +0 -6
  224. package/build/development/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  225. package/build/production/shared/utils/jest/E2eSsrEnv/register.js +0 -3
  226. package/build/production/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  227. package/build/web/shared/utils/jest/E2eSsrEnv/register.js +0 -3
  228. package/build/web/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
  229. /package/build/types-code/shared/utils/jest/E2eSsrEnv/{register.d.ts → ssr-preload.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","useSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","assertClientSide","getBuildInfo","jsx","_jsx","clientChunkGroups","setClientChunkGroups","groups","refCounts","getPublicPath","publicPath","bookStyleSheet","name","loadedSheets","refCount","res","path","fullPath","document","location","origin","has","link","querySelector","createElement","setAttribute","head","appendChild","addEventListener","Error","resolve","current","getLoadedStyleSheets","Set","styleSheets","href","add","assertChunkName","chunkName","chunkGroups","bookStyleSheets","promises","assets","Promise","asset","endsWith","promise","push","length","allSettled","then","freeStyleSheets","pathRefCount","remove","splitComponent","getComponent","placeholder","LazyComponent","resolved","Component","default","Wrapper","t0","$","_c","children","ref","rest","t1","t2","t3","t4","CodeSplit","ssrContext","chunks","includes"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, useSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n assertClientSide,\n getBuildInfo,\n} from './isomorphy';\n\nlet clientChunkGroups: ChunkGroupsT | undefined;\n\nexport function setClientChunkGroups(groups: ChunkGroupsT): void {\n assertClientSide();\n clientChunkGroups = groups;\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\n// const usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // TODO: For now I commented out this safeguard check, as I am not sure how\n // to easily make it work: it should not be triggered in HMR mode, but if I\n // add the code relying on import.meta, it fails in Jest environment, because\n // Jest does not support ES modules yet, and import.meta is not support in\n // CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n // we use to workaround this issue for import.meta.dirname, etc. does not\n // transform import.meta.webpackHot\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n // if (usedChunkNames.has(chunkName)\n\n // When HMR happens splitComponent() ends up getting called again for some\n // chunks, thus we should not throw this error. Not sure, if we need to do\n // some additional handling in that case, or just not throwing is all we\n // need.\n // && !import.meta.webpackHot\n // ) {\n // throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n // } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT & {\n chunkGroups: ChunkGroupsT;\n }> = ({\n children,\n chunkGroups,\n ref,\n ...rest\n }) => {\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, chunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, chunkGroups);\n };\n }, [chunkGroups]);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => {\n let chunkGroups: ChunkGroupsT;\n\n const ssrContext = useSsrContext(false);\n\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n if (!ssrContext) throw Error('Internal error');\n ({ chunkGroups } = ssrContext);\n const { chunks } = ssrContext;\n\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n } else {\n if (!clientChunkGroups) {\n throw Error('Missing client-side chunk groups data');\n }\n chunkGroups = clientChunkGroups;\n }\n\n assertChunkName(chunkName, chunkGroups);\n\n return (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n\n chunkGroups={chunkGroups}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n };\n\n return CodeSplit;\n}\n"],"mappings":"2eAAA,qBAEA,OAKEA,QAAQ,CACRC,IAAI,CACJC,kBAAkB,KACb,OAAO,CAEd,OAASC,OAAO,KAAQ,sBAAsB,CAE9C,OAA4BC,aAAa,qBAEzC,OACEC,cAAc,CACdC,cAAc,CACdC,gBAAgB,CAChBC,YAAY,mBACO,OAAAC,GAAA,IAAAC,IAAA,yBAErB,GAAI,CAAAC,iBAA2C,CAE/C,MAAO,SAAS,CAAAC,oBAAoBA,CAACC,MAAoB,CAAQ,CAC/DN,gBAAgB,CAAC,CAAC,CAClBI,iBAAiB,CAAGE,MAAM,CAC5B,CAEA,KAAM,CAAAC,SAAiC,CAAG,CAAC,CAAC,CAE5C,QAAS,CAAAC,aAAaA,CAAA,CA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,EACpB,KAAM,CAAAwB,KAAK,CAAC,uCAAuC,CAAC,CAAC,CAEvDU,YAAclC,iBAAiB,CAApB,CAGbgC,eAAe,CAACC,SAAS,CAAEC,WAAW,CAAC,CAM7B,MAAA6B,EAAA,CAAAD,IAAI,CAAuC,IAAAE,EAAA,IAAAN,CAAA,MAAAE,QAAA,EAAAF,CAAA,MAAAxB,WAAA,EAAAwB,CAAA,MAAAK,EAAA,EAHnDC,EAAA,cAAAjE,IAAA,CAACV,QAAQ,EAAW8D,QAAW,CAAXA,WAAW,CAAAS,QAAA,cAC7B7D,IAAA,CAACqD,aAAa,KAERW,EAA2C,CAElC7B,WAAW,CAAXA,WAAW,CAAA0B,QAAA,CAEvBA,QAAQ,CACI,CAAC,CACR,CAAC,CAAAF,CAAA,IAAAE,QAAAF,CAAA,KAAAxB,WAAAwB,CAAA,KAAAK,EAAAL,CAAA,KAAAM,EAAA,MAAAA,EAAA,CAAAN,CAAA,UATX,CAAAM,EASW,CAEd,CAED,MAAO,CAAAG,SAAS,CAClB","ignoreList":[]}
1
+ {"version":3,"file":"splitComponent.js","names":["chunkGroups","placeholder"],"sources":["../../../../src/shared/utils/splitComponent.tsx"],"sourcesContent":["/* global document */\n\nimport {\n type ComponentType,\n type FunctionComponent,\n type ReactNode,\n type RefObject,\n Suspense,\n lazy,\n useInsertionEffect,\n} from 'react';\n\nimport { Barrier } from '@dr.pogodin/js-utils';\n\nimport { type ChunkGroupsT, useSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n assertClientSide,\n getBuildInfo,\n} from './isomorphy';\n\nlet clientChunkGroups: ChunkGroupsT | undefined;\n\nexport function setClientChunkGroups(groups: ChunkGroupsT): void {\n assertClientSide();\n clientChunkGroups = groups;\n}\n\nconst refCounts: Record<string, number> = {};\n\nfunction getPublicPath() {\n return getBuildInfo().publicPath;\n}\n\n/**\n * Client-side only! Ensures the specified CSS stylesheet is loaded into\n * the document; loads if it is missing; and does simple reference counting\n * to facilitate future clean-up.\n * @param name\n * @param loadedSheets\n * @param refCount\n * @return\n */\nfunction bookStyleSheet(\n name: string,\n loadedSheets: Set<string>,\n refCount: boolean,\n): Promise<void> | undefined {\n let res: Barrier<void> | undefined;\n const path = `${getPublicPath()}/${name}`;\n const fullPath = `${document.location.origin}${path}`;\n\n if (!loadedSheets.has(fullPath)) {\n let link = document.querySelector(`link[href=\"${path}\"]`);\n\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('href', path);\n document.head.appendChild(link);\n }\n\n res = new Barrier<void>();\n link.addEventListener('load', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n link.addEventListener('error', () => {\n if (!res) throw Error('Internal error');\n void res.resolve();\n });\n }\n\n if (refCount) {\n const current = refCounts[path] ?? 0;\n refCounts[path] = 1 + current;\n }\n\n return res;\n}\n\n/**\n * Generates the set of URLs for currently loaded, linked stylesheets.\n * @return\n */\nfunction getLoadedStyleSheets(): Set<string> {\n const res = new Set<string>();\n const { styleSheets } = document;\n for (const { href } of styleSheets) {\n if (href) res.add(href);\n }\n return res;\n}\n\nfunction assertChunkName(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n) {\n if (chunkGroups[chunkName]) return;\n throw Error(`Unknown chunk name \"${chunkName}\"`);\n}\n\n/**\n * Client-side only! Ensures all CSS stylesheets required for the specified\n * code chunk are loaded into the document; loads the missing ones; and does\n * simple reference counting to facilitate future clean-up.\n * @param chunkName Chunk name.\n * @param refCount\n * @return Resolves once all pending stylesheets, necessary for\n * the chunk, are either loaded, or failed to load.\n */\nexport async function bookStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n refCount: boolean,\n): Promise<void> {\n const promises = [];\n const assets = chunkGroups[chunkName];\n if (!assets) return Promise.resolve();\n\n const loadedSheets = getLoadedStyleSheets();\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const promise = bookStyleSheet(asset, loadedSheets, refCount);\n if (promise) promises.push(promise);\n }\n }\n\n return promises.length\n ? Promise.allSettled(promises).then()\n : Promise.resolve();\n}\n\n/**\n * Client-side only! Frees from the document all CSS stylesheets that are\n * required by the specified chunk, and have reference counter equal to one\n * (for chunks with larger reference counter values, it just decrements\n * the reference counter).\n * @param {string} chunkName\n */\nexport function freeStyleSheets(\n chunkName: string,\n chunkGroups: ChunkGroupsT,\n): void {\n const assets = chunkGroups[chunkName];\n if (!assets) return;\n\n for (const asset of assets) {\n if (asset.endsWith('.css')) {\n const path = `${getPublicPath()}/${asset}`;\n\n const pathRefCount = refCounts[path];\n if (pathRefCount) {\n if (pathRefCount <= 1) {\n document.head.querySelector(`link[href=\"${path}\"]`)!.remove();\n delete refCounts[path];\n } else refCounts[path] = pathRefCount - 1;\n }\n }\n }\n}\n\n// Holds the set of chunk names already used for splitComponent() calls.\n// const usedChunkNames = new Set();\n\ntype ComponentOrModule<PropsT> = ComponentType<PropsT> | {\n default: ComponentType<PropsT>;\n};\n\ntype GenericComponentPropsT = {\n children?: ReactNode;\n ref?: RefObject<unknown>;\n\n // NOTE: This is necessary, as without it this type (with only optional\n // fields) will be conisdered as \"weak\" by TypeScript, and it will be\n // a error to assign to it any type that does not use \"children\", or \"ref\".\n [propName: string]: unknown;\n};\n\n/**\n * Given an async component retrieval function `getComponent()` it creates\n * a special \"code split\" component, which uses <Suspense> to asynchronously\n * load on demand the code required by `getComponent()`.\n * @param options\n * @param options.chunkName\n * @param {function} options.getComponent\n * @param {React.Element} [options.placeholder]\n * @return {React.ElementType}\n */\nexport default function splitComponent<\n ComponentPropsT extends GenericComponentPropsT,\n>({\n chunkName,\n getComponent,\n placeholder,\n}: {\n chunkName: string;\n getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;\n placeholder?: ReactNode;\n}): FunctionComponent<ComponentPropsT> {\n // TODO: For now I commented out this safeguard check, as I am not sure how\n // to easily make it work: it should not be triggered in HMR mode, but if I\n // add the code relying on import.meta, it fails in Jest environment, because\n // Jest does not support ES modules yet, and import.meta is not support in\n // CommonJS modules, and the \"babel-plugin-transform-import-meta\" plugin\n // we use to workaround this issue for import.meta.dirname, etc. does not\n // transform import.meta.webpackHot\n\n // The correct usage of splitComponent() assumes a single call per chunk.\n // if (usedChunkNames.has(chunkName)\n\n // When HMR happens splitComponent() ends up getting called again for some\n // chunks, thus we should not throw this error. Not sure, if we need to do\n // some additional handling in that case, or just not throwing is all we\n // need.\n // && !import.meta.webpackHot\n // ) {\n // throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n // } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const resolved = await getComponent();\n const Component = 'default' in resolved ? resolved.default : resolved;\n\n // This pre-loads necessary stylesheets prior to the first mount of\n // the component (the lazy load function is executed by React one at\n // the frist mount).\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n await bookStyleSheets(chunkName, clientChunkGroups, false);\n }\n\n const Wrapper: FunctionComponent<ComponentPropsT & {\n chunkGroups: ChunkGroupsT;\n }> = ({\n children,\n chunkGroups,\n ref,\n ...rest\n }) => {\n // This takes care about stylesheets management every time an instance of\n // this component is mounted / unmounted.\n useInsertionEffect(() => {\n if (!clientChunkGroups) throw Error('Internal error');\n void bookStyleSheets(chunkName, chunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, chunkGroups);\n };\n }, [chunkGroups]);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(rest as unknown as ComponentPropsT)}\n ref={ref}\n >\n {children}\n </Component>\n );\n };\n\n return { default: Wrapper };\n });\n\n const CodeSplit: FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => {\n let chunkGroups: ChunkGroupsT;\n\n const ssrContext = useSsrContext(false);\n\n // On the server side we'll assert the chunk name here,\n // and also push it to the SSR chunks array.\n if (IS_SERVER_SIDE) {\n if (!ssrContext) throw Error('Internal error');\n ({ chunkGroups } = ssrContext);\n const { chunks } = ssrContext;\n\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n } else {\n if (!clientChunkGroups) {\n throw Error('Missing client-side chunk groups data');\n }\n chunkGroups = clientChunkGroups;\n }\n\n assertChunkName(chunkName, chunkGroups);\n\n return (\n <Suspense fallback={placeholder}>\n <LazyComponent\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...rest as Parameters<typeof LazyComponent>[0]}\n\n chunkGroups={chunkGroups}\n >\n {children}\n </LazyComponent>\n </Suspense>\n );\n };\n\n return CodeSplit;\n}\n"],"mappings":"oHAAA,qBAEA,OAKE,QAAQ,CACR,IAAI,CACJ,kBAAkB,KACb,OAAO,CAEd,OAAS,OAAO,KAAQ,sBAAsB,CAAC,OAEnB,aAAa,+BAGvC,cAAc,CACd,cAAc,CACd,gBAAgB,CAChB,YAAY,uEAGd,GAAI,kBAA2C,CAE/C,MAAO,SAAS,qBAAoB,CAAC,MAAoB,CAAQ,CAC/D,gBAAgB,CAAC,CAAC,CAClB,iBAAiB,CAAG,MAAM,CAC5B,CAEA,KAAM,UAAiC,CAAG,CAAC,CAAC,CAE5C,QAAS,cAAa,EAAG,CACvB,MAAO,aAAY,CAAC,CAAC,CAAC,UAAU,CAClC,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,eAAc,CACrB,IAAY,CACZ,YAAyB,CACzB,QAAiB,CACU,CAC3B,GAAI,IAA8B,CAClC,KAAM,KAAI,CAAG,GAAG,aAAa,CAAC,CAAC,IAAI,IAAI,EAAE,CACzC,KAAM,SAAQ,CAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,EAAE,CAErD,GAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAE,CAC/B,GAAI,KAAI,CAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,IAAI,IAAI,CAAC,CAEzD,GAAI,CAAC,IAAI,CAAE,CACT,IAAI,CAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC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EAAE,KAAM,MAAK,CAAC,gBAAgB,CAAC,CAAC,CAC9C,eAAkB,UAAU,EAC7B,cAAmB,UAAU,CAE7B,GAAI,CAAC,MAAM,SAAS,CAAC,SAAS,CAAC,EAAE,4BAAM,OAAN,MAAM,CAAM,SAAS,CAAC,CAAC,MAExD,GAAI,CAAC,iBAAiB,EACpB,KAAM,MAAK,CAAC,uCAAuC,CAAC,CAAC,CAEvD,WAAAA,CAAc,iBAAiB,CAApB,CAGb,eAAe,CAAC,SAAS,CAAE,WAAW,CAAC,CAM7B,aAAI,CAAuC,0DAHnD,qBAAC,QAAQ,EAAWC,QAAW,CAAX,WAAW,uBAC7B,KAAC,aAAa,KAER,EAA2C,CAElC,WAAW,CAAX,WAAW,UAEvB,QAAQ,CACI,CAAC,CACR,CAAC,mEATX,GASW,CAEd,CAED,MAAO,UAAS,CAClB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import{c as _c}from"react/compiler-runtime";import{stringifySetCookie}from"cookie";import dayjs from"dayjs";import{useEffect}from"react";import{DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,timer}from"@dr.pogodin/js-utils";import{useGlobalState}from"@dr.pogodin/react-global-state";import{useSsrContext}from"./globalState";/**
1
+ import{stringifySetCookie}from"cookie";import dayjs from"dayjs";import{useEffect}from"react";import{DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,timer}from"@dr.pogodin/js-utils";import{useGlobalState}from"@dr.pogodin/react-global-state";import{useSsrContext}from"./globalState.js";/**
2
2
  * This react hook wraps Date.now() function in a SSR friendly way,
3
3
  * ensuring that all calls to useCurrent() within the same render return
4
4
  * exactly the same time (which is retrieved from Date.now() first, and
@@ -17,5 +17,5 @@ export function useCurrent({autorefresh=false,globalStatePath="currentTime",prec
17
17
  * as the default value.
18
18
  */// TODO: Should we request the state type as generic parameter, to be able
19
19
  // to verify the give globalStatePath is correct?
20
- export function useTimezoneOffset(t0){const $=_c(9);let t1;if($[0]!==t0){t1=t0===undefined?{}:t0;$[0]=t0;$[1]=t1}else{t1=$[1]}const{cookieName:t2,globalStatePath:t3}=t1;const cookieName=t2===undefined?"timezoneOffset":t2;const globalStatePath=t3===undefined?"timezoneOffset":t3;const ssrContext=useSsrContext(false);let t4;if($[2]!==cookieName||$[3]!==ssrContext?.req){t4=()=>{const value=cookieName&&ssrContext?.req.cookies[cookieName];return value?parseInt(value):0};$[2]=cookieName;$[3]=ssrContext?.req;$[4]=t4}else{t4=$[4]}const[offset,setOffset]=useGlobalState(globalStatePath,t4);let t5;let t6;if($[5]!==cookieName||$[6]!==setOffset){t5=()=>{const date=new Date;const value_0=date.getTimezoneOffset();setOffset(value_0);if(cookieName){document.cookie=stringifySetCookie({name:cookieName,path:"/",value:value_0.toString()})}};t6=[cookieName,setOffset];$[5]=cookieName;$[6]=setOffset;$[7]=t5;$[8]=t6}else{t5=$[7];t6=$[8]}useEffect(t5,t6);return offset}const time={DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,now:Date.now,timer,useCurrent,useTimezoneOffset};export default Object.assign(dayjs,time);
20
+ export function useTimezoneOffset({cookieName="timezoneOffset",globalStatePath="timezoneOffset"}={}){const ssrContext=useSsrContext(false);const[offset,setOffset]=useGlobalState(globalStatePath,()=>{const value=cookieName&&ssrContext?.req.cookies[cookieName];return value?parseInt(value):0;});useEffect(()=>{const date=new Date;const value_0=date.getTimezoneOffset();setOffset(value_0);if(cookieName){document.cookie=stringifySetCookie({name:cookieName,path:"/",value:value_0.toString()});}},[cookieName,setOffset]);return offset;}const time={DAY_MS,HOUR_MS,MIN_MS,SEC_MS,YEAR_MS,now:Date.now,timer,useCurrent,useTimezoneOffset};export default Object.assign(dayjs,time);
21
21
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":["stringifySetCookie","dayjs","useEffect","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","useSsrContext","useCurrent","autorefresh","globalStatePath","precision","now","setter","Date","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","t0","$","_c","t1","undefined","cookieName","t2","t3","ssrContext","t4","req","value","cookies","parseInt","offset","setOffset","t5","t6","date","value_0","getTimezoneOffset","document","cookie","name","path","toString","time","Object","assign"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { stringifySetCookie } from 'cookie';\nimport dayjs from 'dayjs';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';\n\nimport { useSsrContext } from './globalState';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * SEC_MS,\n} = {}): number {\n const [now, setter] = useGlobalState<ForceT, number>(\n globalStatePath,\n Date.now,\n );\n useEffect(() => {\n let timerId: NodeJS.Timeout | undefined;\n const update = (): void => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return (): void => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}): number {\n const ssrContext = useSsrContext(false);\n const [offset, setOffset] = useGlobalState<ForceT, number>(\n globalStatePath,\n () => {\n const value = cookieName\n && ssrContext?.req.cookies[cookieName] as string;\n return value ? parseInt(value) : 0;\n },\n );\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = stringifySetCookie({\n name: cookieName,\n path: '/',\n value: value.toString(),\n });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nconst time = {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n};\n\nexport default Object.assign(dayjs, time);\n"],"mappings":"4CAAA,OAASA,kBAAkB,KAAQ,QAAQ,CAC3C,MAAO,CAAAC,KAAK,KAAM,OAAO,CACzB,OAASC,SAAS,KAAQ,OAAO,CAEjC,OACEC,MAAM,CACNC,OAAO,CACPC,MAAM,CACNC,MAAM,CACNC,OAAO,CACPC,KAAK,KACA,sBAAsB,CAE7B,OAAsBC,cAAc,KAAQ,gCAAgC,CAE5E,OAASC,aAAa,qBAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA;AACA;AACA,MAAO,SAAS,CAAAC,UAAUA,CAAC,CACzBC,WAAW,CAAG,KAAK,CACnBC,eAAe,CAAG,aAAa,CAC/BC,SAAS,CAAG,CAAC,CAAGR,MAClB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,CAACS,GAAG,CAAEC,MAAM,CAAC,CAAGP,cAAc,CAClCI,eAAe,CACfI,IAAI,CAACF,GACP,CAAC,CACDb,SAAS,CAAC,IAAM,CACd,GAAI,CAAAgB,OAAmC,CACvC,KAAM,CAAAC,MAAM,CAAGA,CAAA,GAAY,CACzBH,MAAM,CAAEI,GAAG,EAAK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M,CAACC,MAAM,CAACtD,KAAK,CAAEoD,IAAI,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"time.js","names":["value"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { stringifySetCookie } from 'cookie';\nimport dayjs from 'dayjs';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';\n\nimport { useSsrContext } from './globalState';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * SEC_MS,\n} = {}): number {\n const [now, setter] = useGlobalState<ForceT, number>(\n globalStatePath,\n Date.now,\n );\n useEffect(() => {\n let timerId: NodeJS.Timeout | undefined;\n const update = (): void => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return (): void => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n */\n// TODO: Should we request the state type as generic parameter, to be able\n// to verify the give globalStatePath is correct?\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}): number {\n const ssrContext = useSsrContext(false);\n const [offset, setOffset] = useGlobalState<ForceT, number>(\n globalStatePath,\n () => {\n const value = cookieName\n && ssrContext?.req.cookies[cookieName] as string;\n return value ? parseInt(value) : 0;\n },\n );\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = stringifySetCookie({\n name: cookieName,\n path: '/',\n value: value.toString(),\n });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nconst time = {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n};\n\nexport default Object.assign(dayjs, time);\n"],"mappings":"AAAA,OAAS,kBAAkB,KAAQ,QAAQ,CAC3C,MAAO,MAAK,KAAM,OAAO,CACzB,OAAS,SAAS,KAAQ,OAAO,CAEjC,OACE,MAAM,CACN,OAAO,CACP,MAAM,CACN,MAAM,CACN,OAAO,CACP,KAAK,KACA,sBAAsB,CAE7B,OAAsB,cAAc,KAAQ,gCAAgC,CAAC,OAEpE,aAAa,wBAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA;AACA;AACA,MAAO,SAAS,WAAU,CAAC,CACzB,WAAW,CAAG,KAAK,CACnB,eAAe,CAAG,aAAa,CAC/B,SAAS,CAAG,CAAC,CAAG,MAClB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,CAAC,GAAG,CAAE,MAAM,CAAC,CAAG,cAAc,CAClC,eAAe,CACf,IAAI,CAAC,GACP,CAAC,CACD,SAAS,CAAC,IAAM,CACd,GAAI,QAAmC,CACvC,KAAM,OAAM,CAAG,IAAY,CACzB,MAAM,CAAE,GAAG,EAAK,CACd,KAAM,IAAG,CAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CACtB,MAAO,KAAI,CAAC,GAAG,CAAC,GAAG,CAAG,GAAG,CAAC,CAAG,SAAS,CAAG,GAAG,CAAG,GAAG,CAC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O,CACP,GAAG,CAAE,IAAI,CAAC,GAAG,CACb,KAAK,CACL,UAAU,CACV,iBACF,CAAC,CAED,cAAe,OAAM,CAAC,MAAM,CAAC,KAAK,CAAE,IAAI,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
- import"core-js/modules/es.iterator.constructor.js";import"core-js/modules/es.iterator.for-each.js";// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports
2
- import{createRequire}from"module";import{IS_CLIENT_SIDE,IS_SERVER_SIDE}from"./isomorphy";let require;if(IS_SERVER_SIDE)require=createRequire(import.meta.url);/**
1
+ // eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports
2
+ import{createRequire}from"module";import{IS_CLIENT_SIDE,IS_SERVER_SIDE}from"./isomorphy/index.js";let require;if(IS_SERVER_SIDE)require=createRequire(import.meta.url);/**
3
3
  * Requires the specified module without including it into the bundle during
4
4
  * Webpack build.
5
5
  * @param modulePath
@@ -14,7 +14,7 @@ const{resolve}=require("node:path");const path=basePath?resolve(basePath,moduleP
14
14
  * Yes, the function itself just returns its argument to the caller, but Babel
15
15
  * is configured to resolve the first argument of resolveWeak(..) function, thus
16
16
  * the result will be the resolved path.
17
- * @param {string} modulePath
18
- * @return {string} Absolute or relative path to the module.
17
+ * @param modulePath
18
+ * @return Absolute or relative path to the module.
19
19
  */export function resolveWeak(modulePath){return modulePath;}
20
20
  //# sourceMappingURL=webpack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.js","names":["createRequire","IS_CLIENT_SIDE","IS_SERVER_SIDE","require","import","meta","url","requireWeak","modulePath","basePathOrOptions","basePath","ops","resolve","path","module","default","def","named","res","Object","entries","forEach","name","value","assigned","undefined","Error","resolveWeak"],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\n// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports\nimport { createRequire } from 'module';\n\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './isomorphy';\n\ntype RequireWeakOptionsT = {\n basePath?: string;\n};\n\ntype RequireWeakResT<T> = T extends { default: infer D }\n ? (D extends null | undefined ? T : D & Omit<T, 'default'>)\n : T;\n\nlet require: ((url: string) => unknown) | undefined;\n\nif (IS_SERVER_SIDE) require = createRequire(import.meta.url);\n\n/**\n * Requires the specified module without including it into the bundle during\n * Webpack build.\n * @param modulePath\n * @param [basePath]\n * @return Required module.\n */\nexport function requireWeak<T extends object>(\n modulePath: string,\n\n // TODO: For now `basePath` can be provided directly as a string here,\n // for backward compatibility. Deprecate it in future, if any other\n // breaking changes are done for requireWeak().\n basePathOrOptions?: RequireWeakOptionsT | string,\n): RequireWeakResT<T> | null {\n if (IS_CLIENT_SIDE) return null;\n\n let basePath: string | undefined;\n let ops: RequireWeakOptionsT;\n if (typeof basePathOrOptions === 'string') {\n basePath = basePathOrOptions;\n } else {\n ops = basePathOrOptions ?? {};\n ({ basePath } = ops);\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { resolve } = require!('node:path') as typeof PathNS;\n\n const path = basePath ? resolve(basePath, modulePath) : modulePath;\n\n const module = require!(path) as T;\n\n if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;\n\n const { default: def, ...named } = module;\n\n const res = def as RequireWeakResT<T>;\n\n Object.entries(named).forEach(([name, value]) => {\n const assigned = res[name as keyof RequireWeakResT<T>];\n if (assigned === undefined) {\n (res[name as keyof RequireWeakResT<T>] as unknown) = value;\n } else if (assigned !== value) {\n throw Error('Conflict between default and named exports');\n }\n });\n return res;\n}\n\n/**\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param {string} modulePath\n * @return {string} Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath: string): string {\n return modulePath;\n}\n"],"mappings":"mGAEA;AACA,OAASA,aAAa,KAAQ,QAAQ,CAEtC,OAASC,cAAc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AAeC,KAAK,CAC5D,CAAC,IAAM,IAAIC,QAAQ,GAAKD,KAAK,CAAE,CAC7B,KAAM,CAAAG,KAAK,CAAC,4CAA4C,CAAC,CAC3D,CACF,CAAC,CAAC,CACF,MAAO,CAAAR,GAAG,CACZ,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,CAAAS,WAAWA,CAACnB,UAAkB,CAAU,CACtD,MAAO,CAAAA,UAAU,CACnB","ignoreList":[]}
1
+ {"version":3,"file":"webpack.js","names":[],"sources":["../../../../src/shared/utils/webpack.ts"],"sourcesContent":["import type PathNS from 'node:path';\n\n// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports\nimport { createRequire } from 'module';\n\nimport { IS_CLIENT_SIDE, IS_SERVER_SIDE } from './isomorphy';\n\ntype RequireWeakOptionsT = {\n basePath?: string;\n};\n\ntype RequireWeakResT<T> = T extends { default: infer D }\n ? (D extends null | undefined ? T : D & Omit<T, 'default'>)\n : T;\n\nlet require: ((url: string) => unknown) | undefined;\n\nif (IS_SERVER_SIDE) require = createRequire(import.meta.url);\n\n/**\n * Requires the specified module without including it into the bundle during\n * Webpack build.\n * @param modulePath\n * @param [basePath]\n * @return Required module.\n */\nexport function requireWeak<T extends object>(\n modulePath: string,\n\n // TODO: For now `basePath` can be provided directly as a string here,\n // for backward compatibility. Deprecate it in future, if any other\n // breaking changes are done for requireWeak().\n basePathOrOptions?: RequireWeakOptionsT | string,\n): RequireWeakResT<T> | null {\n if (IS_CLIENT_SIDE) return null;\n\n let basePath: string | undefined;\n let ops: RequireWeakOptionsT;\n if (typeof basePathOrOptions === 'string') {\n basePath = basePathOrOptions;\n } else {\n ops = basePathOrOptions ?? {};\n ({ basePath } = ops);\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const { resolve } = require!('node:path') as typeof PathNS;\n\n const path = basePath ? resolve(basePath, modulePath) : modulePath;\n\n const module = require!(path) as T;\n\n if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;\n\n const { default: def, ...named } = module;\n\n const res = def as RequireWeakResT<T>;\n\n Object.entries(named).forEach(([name, value]) => {\n const assigned = res[name as keyof RequireWeakResT<T>];\n if (assigned === undefined) {\n (res[name as keyof RequireWeakResT<T>] as unknown) = value;\n } else if (assigned !== value) {\n throw Error('Conflict between default and named exports');\n }\n });\n return res;\n}\n\n/**\n * Resolves specified module path with help of Babel's module resolver.\n * Yes, the function itself just returns its argument to the caller, but Babel\n * is configured to resolve the first argument of resolveWeak(..) function, thus\n * the result will be the resolved path.\n * @param modulePath\n * @return Absolute or relative path to the module.\n */\nexport function resolveWeak(modulePath: string): string {\n return modulePath;\n}\n"],"mappings":"AAEA;AACA,OAAS,aAAa,KAAQ,QAAQ,CAAC,OAE9B,cAAc,CAAE,cAAc,4BAUvC,GAAI,QAA+C,CAEnD,GAAI,cAAc,CAAE,OAAO,CAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAE5D;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,YAAW,CACzB,UAAkB,CAElB;AACA;AACA;AACA,iBAAgD,CACrB,CAC3B,GAAI,cAAc,CAAE,MAAO,KAAI,CAE/B,GAAI,SAA4B,CAChC,GAAI,IAAwB,CAC5B,GAAI,MAAO,kBAAiB,GAAK,QAAQ,CAAE,CACzC,QAAQ,CAAG,iBAAiB,CAC9B,CAAC,IAAM,CACL,GAAG,CAAG,iBAAiB,EAAI,CAAC,CAAC,CAC7B,CAAC,CAAE,QAAS,CAAC,CAAG,GAAG,EACrB,CAEA;AACA,KAAM,CAAE,OAAQ,CAAC,CAAG,OAAO,CAAE,WAAW,CAAkB,CAE1D,KAAM,KAAI,CAAG,QAAQ,CAAG,OAAO,CAAC,QAAQ,CAAE,UAAU,CAAC,CAAG,UAAU,CAElE,KAAM,OAAM,CAAG,OAAO,CAAE,IAAI,CAAM,CAElC,GAAI,EAAE,SAAS,EAAI,OAAM,CAAC,EAAI,CAAC,MAAM,CAAC,OAAO,CAAE,MAAO,OAAM,CAE5D,KAAM,CAAE,OAAO,CAAE,GAAG,CAAE,GAAG,KAAM,CAAC,CAAG,MAAM,CAEzC,KAAM,IAAG,CAAG,GAAyB,CAErC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAE,KAAK,CAAC,GAAK,CAC/C,KAAM,SAAQ,CAAG,GAAG,CAAC,IAAI,CAA6B,CACtD,GAAI,QAAQ,GAAK,SAAS,CAAE,CACzB,GAAG,CAAC,IAAI,CAA6B,CAAe,KAAK,CAC5D,CAAC,IAAM,IAAI,QAAQ,GAAK,KAAK,CAAE,CAC7B,KAAM,MAAK,CAAC,4CAA4C,CAAC,CAC3D,CACF,CAAC,CAAC,CACF,MAAO,IAAG,CACZ,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,SAAS,YAAW,CAAC,UAAkB,CAAU,CACtD,MAAO,WAAU,CACnB","ignoreList":[]}
@@ -1,5 +1,4 @@
1
- import type { TransformOptions } from '@babel/core';
2
- import { type BabelCompilerI, type OptionsT as WebpackConfigOptionsT } from './webpack';
1
+ import { type BabelCompilerI, type ConfigurationT, type OptionsT as WebpackConfigOptionsT } from './webpack.js';
3
2
  type OptionsT = WebpackConfigOptionsT & {
4
3
  baseAssetsOutputPath?: string;
5
4
  };
@@ -14,5 +13,5 @@ type OptionsT = WebpackConfigOptionsT & {
14
13
  * assets.
15
14
  * @return Generated config.
16
15
  */
17
- export default function getConfig(babel: BabelCompilerI, ops?: OptionsT): TransformOptions;
16
+ export default function getConfig(babel: BabelCompilerI, ops?: OptionsT): ConfigurationT;
18
17
  export {};
@@ -1,77 +1,34 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.default = getConfig;
37
- const lodash_es_1 = require("lodash-es");
38
- const webpack_1 = __importStar(require("./webpack"));
1
+ import { pull } from 'lodash-es';
2
+ import getWebpackBabelConfig, { ENVIRONMENTS, } from './webpack.js';
39
3
  /**
40
4
  * Creates a new base config.
41
5
  * @param babel Babel compiler.
42
6
  * @param [options] It supports all options of our Babel config for Webpack,
43
- * but it overrides `targets` option with "current node" value, and further
44
- * accepts the following:
7
+ * and further accepts the following:
45
8
  * @param [options.baseAssetsOutputPath] Path prefix for emitted
46
9
  * image assets.
47
10
  * @return Created config object.
48
11
  */
49
12
  function newBase(babel, options = {}) {
50
13
  var _a;
51
- const config = (0, webpack_1.default)(babel, Object.assign({
52
- // NOTE: It make sense to have "modules": false here,
53
- // but it needs a bunch of build configuration updates,
54
- // and ends-up with conflict of Jest with ES modules (as now
55
- // Jest relies on babel.config.js, which transpiles everything
56
- // into CJS).
57
- modules: 'cjs', targets: 'node >= 22' }, options));
14
+ const config = getWebpackBabelConfig(babel, options);
58
15
  const baseAssetsOutputPath = (_a = options.baseAssetsOutputPath) !== null && _a !== void 0 ? _a : '';
59
16
  config.plugins.push(['@dr.pogodin/transform-assets', {
60
17
  extensions: ['gif', 'jpeg', 'jpg', 'png'],
61
18
  name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
62
19
  }]);
63
- if (options.modules === false) {
64
- config.plugins.push('babel-plugin-add-import-extension');
65
- }
66
- const moduleResolverPluginOps = config.plugins.find((x) => Array.isArray(x) && x[0] === 'module-resolver')[1];
20
+ const moduleResolverPlugin = config.plugins.find((x) => Array.isArray(x) && x[0] === 'module-resolver');
21
+ if (!Array.isArray(moduleResolverPlugin))
22
+ throw Error('Internal error');
23
+ const [, moduleResolverPluginOps] = moduleResolverPlugin;
67
24
  moduleResolverPluginOps.transformFunctions = [
68
25
  'requireWeak',
69
26
  'resolveWeak',
70
27
  'webpack.requireWeak',
71
28
  'webpack.resolveWeak',
72
29
  ];
73
- if (babel.env() === webpack_1.ENVIRONMENTS.DEV) {
74
- (0, lodash_es_1.pull)(config.plugins, 'react-refresh/babel');
30
+ if (babel.env() === ENVIRONMENTS.DEV) {
31
+ pull(config.plugins, 'react-refresh/babel');
75
32
  }
76
33
  return config;
77
34
  }
@@ -83,7 +40,10 @@ function newBase(babel, options = {}) {
83
40
  * @param config
84
41
  */
85
42
  function addStyling(config) {
86
- const cssModulesOps = config.plugins.find((item) => Array.isArray(item) && item[0] === '@dr.pogodin/react-css-modules')[1];
43
+ const cssModule = config.plugins.find((item) => Array.isArray(item) && item[0] === '@dr.pogodin/react-css-modules');
44
+ if (!Array.isArray(cssModule))
45
+ throw Error('Internal error');
46
+ const cssModulesOps = cssModule[1];
87
47
  cssModulesOps.replaceImport = true;
88
48
  return config;
89
49
  }
@@ -98,7 +58,7 @@ function addStyling(config) {
98
58
  * assets.
99
59
  * @return Generated config.
100
60
  */
101
- function getConfig(babel, ops = {}) {
61
+ export default function getConfig(babel, ops = {}) {
102
62
  const config = newBase(babel, ops);
103
63
  if (!ops.noStyling)
104
64
  addStyling(config);
@@ -1,4 +1,8 @@
1
- import type { TransformOptions } from '@babel/core';
1
+ import type { InputOptions, PluginItem, PresetItem } from '@babel/core';
2
+ export type ConfigurationT = InputOptions & {
3
+ plugins: PluginItem[];
4
+ presets: PresetItem[];
5
+ };
2
6
  export interface BabelCompilerI {
3
7
  env: () => string;
4
8
  }
@@ -12,11 +16,11 @@ export declare enum ENVIRONMENTS {
12
16
  }
13
17
  type ModuleT = 'amd' | 'auto' | 'cjs' | 'commonjs' | 'systemjs' | 'umd' | false;
14
18
  export type OptionsT = {
19
+ addImportExtensions?: boolean;
15
20
  modules?: ModuleT;
16
21
  noRR?: boolean;
17
22
  noReactCompiler?: boolean;
18
23
  noStyling?: boolean;
19
- targets?: Record<string, string> | string | string[];
20
24
  typescript?: boolean;
21
25
  };
22
26
  /**
@@ -27,9 +31,7 @@ export type OptionsT = {
27
31
  * included into config, no matter the environment.
28
32
  * @param [ops.noStyling] If truthy all setup related to styling
29
33
  * ((S)CSS processing) will be skipped.
30
- * @param [ops.targets=defaults] Targets for
31
- * `@babel/preset-env`.
32
34
  * @return Generated config.
33
35
  */
34
- export default function getPreset(babel: BabelCompilerI, ops?: OptionsT): TransformOptions;
36
+ export default function getPreset(babel: BabelCompilerI, ops?: OptionsT): ConfigurationT;
35
37
  export {};
@@ -1,50 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENVIRONMENTS = void 0;
4
- exports.default = getPreset;
5
- const utils_1 = require("@dr.pogodin/babel-plugin-react-css-modules/utils");
6
- const generateScopedNameDev = (0, utils_1.generateScopedNameFactory)('[package]___[path][name]___[local]___[hash:base64:6]');
7
- const generateScopedNameProd = (0, utils_1.generateScopedNameFactory)('[hash:base64:6]');
1
+ import { generateScopedNameFactory, } from '@dr.pogodin/babel-plugin-react-css-modules/utils';
2
+ const generateScopedNameDev = generateScopedNameFactory('[package]___[path][name]___[local]___[hash:base64:6]');
3
+ const generateScopedNameProd = generateScopedNameFactory('[hash:base64:6]');
8
4
  /**
9
5
  * Supported Babel environments.
10
6
  */
11
- var ENVIRONMENTS;
7
+ export var ENVIRONMENTS;
12
8
  (function (ENVIRONMENTS) {
13
9
  ENVIRONMENTS["DEV"] = "development";
14
10
  ENVIRONMENTS["PROD"] = "production";
15
11
  ENVIRONMENTS["TEST"] = "test";
16
- })(ENVIRONMENTS || (exports.ENVIRONMENTS = ENVIRONMENTS = {}));
12
+ })(ENVIRONMENTS || (ENVIRONMENTS = {}));
17
13
  /**
18
14
  * Creates a new base config.
19
15
  * @param [options] Base config options.
20
16
  * @return Generated config.
21
17
  */
22
18
  function newBaseConfig(options) {
23
- var _a, _b;
19
+ var _a;
24
20
  const plugins = [];
25
21
  if (!options.noReactCompiler)
26
22
  plugins.push('babel-plugin-react-compiler');
27
23
  plugins.push(['module-resolver', {
28
24
  extensions: ['.js', '.jsx', '.ts', '.tsx'],
29
25
  root: ['./src/shared', './src'],
30
- }], ['@babel/transform-runtime', {
31
- useESModules: true,
32
- }]);
26
+ }], '@babel/transform-runtime', ['polyfill-corejs3', { method: 'usage-pure', version: '3.49' }]);
27
+ if (options.addImportExtensions) {
28
+ plugins.push('@dr.pogodin/add-import-extension');
29
+ }
33
30
  return {
31
+ parserOpts: {
32
+ // TODO: This is a temporary workaround for babel-plugin-module-resolver
33
+ // not supporting Babel v8; see:
34
+ // https://github.com/tleunen/babel-plugin-module-resolver/issues/452,
35
+ // https://babeljs.io/docs/v8-migration-api#javascript-nodes.
36
+ createImportExpressions: false,
37
+ },
34
38
  plugins,
35
39
  presets: [
36
40
  ['@babel/env', {
37
- bugfixes: true,
38
- corejs: '3.49',
39
41
  // Leaves it to the Webpack to deal with modules.
40
42
  modules: (_a = options.modules) !== null && _a !== void 0 ? _a : false,
41
- targets: (_b = options.targets) !== null && _b !== void 0 ? _b : 'defaults',
42
- useBuiltIns: 'usage',
43
43
  }],
44
- // TODO: Starting from Babel 8, "automatic" will be the default runtime,
45
- // thus once upgraded to Babel 8, runtime should be removed from
46
- // @babel/react options below.
47
- ['@babel/react', { runtime: 'automatic' }],
44
+ '@babel/react',
48
45
  '@dr.pogodin/babel-preset-svgr',
49
46
  ],
50
47
  };
@@ -87,11 +84,9 @@ function addStyling(config, env) {
87
84
  * included into config, no matter the environment.
88
85
  * @param [ops.noStyling] If truthy all setup related to styling
89
86
  * ((S)CSS processing) will be skipped.
90
- * @param [ops.targets=defaults] Targets for
91
- * `@babel/preset-env`.
92
87
  * @return Generated config.
93
88
  */
94
- function getPreset(babel, ops = {}) {
89
+ export default function getPreset(babel, ops = {}) {
95
90
  const env = babel.env();
96
91
  const res = newBaseConfig(ops);
97
92
  if (!ops.noStyling)
@@ -16,7 +16,7 @@ export default defineConfig([
16
16
  eslintConfigs.configs.react,
17
17
  {
18
18
  extends: [eslintConfigs.configs.jest],
19
- files: ['__tests__/**'],
19
+ files: ['__tests__/**', '__type_tests__/**'],
20
20
  rules: {
21
21
  'jest/expect-expect': ['warn', {
22
22
  assertFunctionNames: ['expect', 'snapshot'],
@@ -1,9 +1,7 @@
1
- /* eslint-disable import/no-commonjs */
2
- /* global __dirname, module, process, require */
1
+ import { resolve } from 'node:path';
2
+ import { execPath } from 'node:process';
3
3
 
4
- const path = require('node:path');
5
-
6
- const globalLibDir = path.resolve(process.execPath, '../../lib/node_modules');
4
+ const globalLibDir = resolve(execPath, '../../lib/node_modules');
7
5
 
8
6
  const modulesToTransform = [
9
7
  '@dr.pogodin/react-global-state',
@@ -12,12 +10,13 @@ const modulesToTransform = [
12
10
  'lodash-es',
13
11
  ];
14
12
 
15
- module.exports = {
13
+ export default {
16
14
  collectCoverage: true,
17
15
  collectCoverageFrom: [
18
16
  'src/**/*.{js,jsx,ts,tsx}',
19
17
  ],
20
18
  coverageDirectory: '__coverage__',
19
+ extensionsToTreatAsEsm: ['.ts', '.tsx'],
21
20
  moduleDirectories: [
22
21
  'node_modules',
23
22
  globalLibDir,
@@ -26,7 +25,7 @@ module.exports = {
26
25
  '\\.(scss|css)$': 'identity-obj-proxy',
27
26
  },
28
27
  modulePathIgnorePatterns: ['<rootDir>/build/'],
29
- resolver: `${__dirname}/resolver.js`,
28
+ resolver: `${import.meta.dirname}/resolver.js`,
30
29
  rootDir: '../..',
31
30
  setupFilesAfterEnv: [
32
31
  '<rootDir>/config/jest/setup.js',
@@ -1,6 +1,4 @@
1
- /* global module */
2
-
3
- module.exports = (path, options) => {
1
+ export default (path, options) => {
4
2
  const ops = { ...options };
5
3
 
6
4
  // Appending "development" option we ensure that Jest tests use development
@@ -1,6 +1,7 @@
1
- /* global globalThis, require, window */
1
+ /* global globalThis, window */
2
2
 
3
3
  import { subtle } from 'node:crypto';
4
+ import { TextDecoder, TextEncoder } from 'node:util';
4
5
 
5
6
  // eslint-disable-next-line import/no-unassigned-import
6
7
  import 'raf/polyfill';
@@ -11,7 +12,6 @@ import { getMockUuid } from '@dr.pogodin/react-utils/jest';
11
12
  // as JSDom does not provide TextEncoder, see:
12
13
  // https://github.com/remix-run/react-router/issues/12363
13
14
  if (!globalThis.TextEncoder || !globalThis.TextDecoder) {
14
- const { TextDecoder, TextEncoder } = require('node:util');
15
15
  globalThis.TextEncoder = TextEncoder;
16
16
  globalThis.TextDecoder = TextDecoder;
17
17
  }
@@ -1,5 +1,3 @@
1
- /* global module */
2
-
3
1
  const camelCaseRegex = /^[a-z][a-zA-Z0-9]+$/;
4
2
  const kebabCase = /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/;
5
3
 
@@ -7,8 +5,7 @@ const namePattern = new RegExp(
7
5
  `(${camelCaseRegex.source})|(${kebabCase.source})`,
8
6
  );
9
7
 
10
- // eslint-disable-next-line import/no-commonjs
11
- module.exports = {
8
+ export default {
12
9
  extends: 'stylelint-config-standard-scss',
13
10
  rules: {
14
11
  'at-rule-no-unknown': [true, {