@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.11
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.
- package/babel.config.js +1 -0
- package/babel.libweb.config.js +16 -0
- package/babel.module.config.js +11 -0
- package/bin/build.js +21 -11
- package/bin/setup.js +11 -9
- package/build/development/client/getInj.js +57 -44
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +15 -21
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +2 -6
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +3 -177
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +1 -8
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +22 -45
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +84 -86
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +58 -60
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +8 -31
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/server/utils/index.js +2 -9
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +15 -22
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +14 -21
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +9 -11
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +21 -27
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +6 -13
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +24 -28
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +6 -13
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +13 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +28 -31
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +13 -20
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +13 -18
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +23 -30
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +19 -26
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +16 -130
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +19 -20
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +35 -39
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +31 -31
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +19 -24
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +1 -7
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js +3 -27
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js +40 -21
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +3 -8
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +12 -89
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +2 -9
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +2 -8
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +7 -32
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +34 -37
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/global.js +1 -7
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +20 -44
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +54 -45
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +22 -31
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +17 -16
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +13 -11
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +3 -3
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -2
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -3
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js +3 -3
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js +8 -8
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +24 -25
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +9 -11
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +9 -9
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/server/utils/index.js +2 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +4 -4
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +4 -4
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +5 -5
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js +3 -3
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +7 -7
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +2 -2
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +5 -5
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +4 -4
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +4 -4
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +4 -4
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +3 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +4 -4
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js +2 -2
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/components/selectors/index.js +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js +8 -6
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js +2 -2
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js +3 -3
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js +3 -3
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js +4 -4
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv.js +16 -15
- package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/production/shared/utils/jest/global.js +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +11 -11
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +11 -22
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +3 -3
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +6 -6
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +1 -2
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +1 -7
- package/build/types-code/server/index.d.ts +6 -11
- package/build/types-code/server/utils/index.d.ts +1 -1
- package/build/types-code/shared/utils/config.d.ts +4 -2
- package/build/types-code/shared/utils/index.d.ts +2 -2
- package/build/types-code/shared/utils/splitComponent.d.ts +6 -4
- package/build/web/client/getInj.js +65 -0
- package/build/web/client/getInj.js.map +1 -0
- package/{src/client/index.tsx → build/web/client/index.js} +13 -24
- package/build/web/client/index.js.map +1 -0
- package/{src/client/init.ts → build/web/client/init.js} +9 -14
- package/build/web/client/init.js.map +1 -0
- package/build/web/index.js +11 -0
- package/build/web/index.js.map +1 -0
- package/{src/server/Cache.ts → build/web/server/Cache.js} +15 -22
- package/build/web/server/Cache.js.map +1 -0
- package/{src/server/index.ts → build/web/server/index.js} +32 -81
- package/build/web/server/index.js.map +1 -0
- package/{src/server/renderer.tsx → build/web/server/renderer.js} +188 -333
- package/build/web/server/renderer.js.map +1 -0
- package/{src/server/server.ts → build/web/server/server.js} +82 -182
- package/build/web/server/server.js.map +1 -0
- package/{src/server/utils/errors.ts → build/web/server/utils/errors.js} +6 -25
- package/build/web/server/utils/errors.js.map +1 -0
- package/build/web/server/utils/index.js +4 -0
- package/build/web/server/utils/index.js.map +1 -0
- package/build/web/shared/components/Button/index.js +90 -0
- package/build/web/shared/components/Button/index.js.map +1 -0
- package/build/web/shared/components/Checkbox/index.js +35 -0
- package/build/web/shared/components/Checkbox/index.js.map +1 -0
- package/{src/shared/components/GenericLink/index.tsx → build/web/shared/components/GenericLink/index.js} +44 -78
- package/build/web/shared/components/GenericLink/index.js.map +1 -0
- package/build/web/shared/components/Input/index.js +71 -0
- package/build/web/shared/components/Input/index.js.map +1 -0
- package/build/web/shared/components/Link.js +20 -0
- package/build/web/shared/components/Link.js.map +1 -0
- package/{src → build/web}/shared/components/Modal/base-theme.scss +1 -1
- package/build/web/shared/components/Modal/index.js +128 -0
- package/build/web/shared/components/Modal/index.js.map +1 -0
- package/build/web/shared/components/NavLink.js +13 -0
- package/build/web/shared/components/NavLink.js.map +1 -0
- package/{src → build/web}/shared/components/PageLayout/base-theme.scss +1 -1
- package/{src/shared/components/PageLayout/index.tsx → build/web/shared/components/PageLayout/index.js} +20 -33
- package/build/web/shared/components/PageLayout/index.js.map +1 -0
- package/build/web/shared/components/TextArea/index.js +106 -0
- package/build/web/shared/components/TextArea/index.js.map +1 -0
- package/build/web/shared/components/Throbber/index.js +26 -0
- package/build/web/shared/components/Throbber/index.js.map +1 -0
- package/{src/shared/components/WithTooltip/Tooltip.tsx → build/web/shared/components/WithTooltip/Tooltip.js} +61 -109
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
- package/build/web/shared/components/WithTooltip/index.js +117 -0
- package/build/web/shared/components/WithTooltip/index.js.map +1 -0
- package/{src/shared/components/YouTubeVideo/index.tsx → build/web/shared/components/YouTubeVideo/index.js} +23 -40
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
- package/build/web/shared/components/index.js +18 -0
- package/build/web/shared/components/index.js.map +1 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +82 -0
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
- package/{src/shared/components/selectors/CustomDropdown/index.tsx → build/web/shared/components/selectors/CustomDropdown/index.js} +56 -80
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
- package/{src/shared/components/selectors/NativeDropdown/index.tsx → build/web/shared/components/selectors/NativeDropdown/index.js} +39 -44
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
- package/build/web/shared/components/selectors/Switch/index.js +50 -0
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
- package/build/web/shared/components/selectors/common.js +12 -0
- package/build/web/shared/components/selectors/common.js.map +1 -0
- package/build/web/shared/components/selectors/index.js +4 -0
- package/build/web/shared/components/selectors/index.js.map +1 -0
- package/build/web/shared/utils/config.js +45 -0
- package/build/web/shared/utils/config.js.map +1 -0
- package/build/web/shared/utils/globalState.js +15 -0
- package/build/web/shared/utils/globalState.js.map +1 -0
- package/build/web/shared/utils/index.js +13 -0
- package/build/web/shared/utils/index.js.map +1 -0
- package/{src/shared/utils/isomorphy/buildInfo.ts → build/web/shared/utils/isomorphy/buildInfo.js} +4 -10
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
- package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
- package/{src/shared/utils/isomorphy/index.ts → build/web/shared/utils/isomorphy/index.js} +6 -6
- package/build/web/shared/utils/isomorphy/index.js.map +1 -0
- package/{src/shared/utils/jest/E2eSsrEnv.ts → build/web/shared/utils/jest/E2eSsrEnv.js} +73 -140
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
- package/build/web/shared/utils/jest/global.js +4 -0
- package/build/web/shared/utils/jest/global.js.map +1 -0
- package/{src/shared/utils/jest/index.ts → build/web/shared/utils/jest/index.js} +33 -83
- package/build/web/shared/utils/jest/index.js.map +1 -0
- package/{src/shared/utils/splitComponent.tsx → build/web/shared/utils/splitComponent.js} +77 -124
- package/build/web/shared/utils/splitComponent.js.map +1 -0
- package/{src/shared/utils/time.ts → build/web/shared/utils/time.js} +21 -37
- package/build/web/shared/utils/time.js.map +1 -0
- package/build/web/shared/utils/webpack.js +67 -0
- package/build/web/shared/utils/webpack.js.map +1 -0
- package/config/babel/node-ssr.js +12 -3
- package/config/babel/webpack.js +6 -1
- package/config/jest/default.js +8 -2
- package/config/jest/setup.js +8 -1
- package/config/webpack/app-base.js +25 -14
- package/config/webpack/app-development.js +2 -2
- package/config/webpack/lib-base.js +1 -2
- package/package.json +41 -42
- package/types.d.ts +1 -6
- package/build/development/__chunk_groups__.json +0 -6
- package/build/development/style.css +0 -909
- package/build/development/web.bundle.js +0 -752
- package/build/production/__chunk_groups__.json +0 -6
- package/build/production/style.css +0 -2
- package/build/production/style.css.map +0 -1
- package/build/production/web.bundle.js +0 -3
- package/build/production/web.bundle.js.LICENSE.txt +0 -9
- package/build/production/web.bundle.js.map +0 -1
- package/dev-styles.js +0 -1
- package/node-entry.js +0 -15
- package/null.js +0 -1
- package/prod-styles.js +0 -1
- package/src/client/getInj.ts +0 -51
- package/src/index.ts +0 -73
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -28
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/webpack.ts +0 -74
- /package/{src → build/web}/shared/components/Button/style.scss +0 -0
- /package/{src → build/web}/shared/components/Checkbox/theme.scss +0 -0
- /package/{src → build/web}/shared/components/GenericLink/style.scss +0 -0
- /package/{src → build/web}/shared/components/Input/theme.scss +0 -0
- /package/{src → build/web}/shared/components/Modal/styles.scss +0 -0
- /package/{src → build/web}/shared/components/TextArea/style.scss +0 -0
- /package/{src → build/web}/shared/components/Throbber/theme.scss +0 -0
- /package/{src → build/web}/shared/components/WithTooltip/default-theme.scss +0 -0
- /package/{src → build/web}/shared/components/YouTubeVideo/base.scss +0 -0
- /package/{src → build/web}/shared/components/YouTubeVideo/throbber.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/CustomDropdown/Options/style.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/CustomDropdown/theme.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/NativeDropdown/theme.scss +0 -0
- /package/{src → build/web}/shared/components/selectors/Switch/theme.scss +0 -0
- /package/{src → build/web}/styles/_global/reset.css +0 -0
- /package/{src → build/web}/styles/_mixins/fonts.scss +0 -0
- /package/{src → build/web}/styles/_mixins/media.scss +0 -0
- /package/{src → build/web}/styles/_mixins/typography.scss +0 -0
- /package/{src → build/web}/styles/global.scss +0 -0
- /package/{src → build/web}/styles/mixins.scss +0 -0
|
@@ -1,46 +1,30 @@
|
|
|
1
|
+
import "core-js/modules/es.array.push.js";
|
|
2
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/es.set.difference.v2.js";
|
|
4
|
+
import "core-js/modules/es.set.intersection.v2.js";
|
|
5
|
+
import "core-js/modules/es.set.is-disjoint-from.v2.js";
|
|
6
|
+
import "core-js/modules/es.set.is-subset-of.v2.js";
|
|
7
|
+
import "core-js/modules/es.set.is-superset-of.v2.js";
|
|
8
|
+
import "core-js/modules/es.set.symmetric-difference.v2.js";
|
|
9
|
+
import "core-js/modules/es.set.union.v2.js";
|
|
1
10
|
/* global document */
|
|
2
11
|
|
|
3
|
-
import {
|
|
4
|
-
type ComponentType,
|
|
5
|
-
type FunctionComponent,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
type RefObject,
|
|
8
|
-
Suspense,
|
|
9
|
-
lazy,
|
|
10
|
-
useInsertionEffect,
|
|
11
|
-
} from 'react';
|
|
12
|
-
|
|
12
|
+
import { Suspense, lazy, useInsertionEffect } from 'react';
|
|
13
13
|
import { Barrier } from '@dr.pogodin/js-utils';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
IS_CLIENT_SIDE
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// needed on the server side, we'll fetch it differently.
|
|
27
|
-
let clientChunkGroups: ChunkGroupsT;
|
|
28
|
-
|
|
29
|
-
if (IS_CLIENT_SIDE) {
|
|
30
|
-
// TODO: Rewrite to avoid these overrides of ESLint rules.
|
|
31
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment,
|
|
32
|
-
@typescript-eslint/no-require-imports,
|
|
33
|
-
@typescript-eslint/no-unsafe-call,
|
|
34
|
-
@typescript-eslint/no-unsafe-member-access */
|
|
35
|
-
clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS ?? {};
|
|
36
|
-
/* eslint-enable @typescript-eslint/no-unsafe-assignment,
|
|
37
|
-
@typescript-eslint/no-require-imports,
|
|
38
|
-
@typescript-eslint/no-unsafe-call,
|
|
39
|
-
@typescript-eslint/no-unsafe-member-access */
|
|
14
|
+
import { getSsrContext } from "./globalState";
|
|
15
|
+
import { IS_CLIENT_SIDE, IS_SERVER_SIDE, getBuildInfo } from "./isomorphy";
|
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
function getClientChunkGroups() {
|
|
18
|
+
if (!IS_CLIENT_SIDE) return undefined;
|
|
19
|
+
return (async () => {
|
|
20
|
+
const {
|
|
21
|
+
default: getInj
|
|
22
|
+
} = await import(/* webpackChunkName: "react-utils-client-side-code" */"../../client/getInj");
|
|
23
|
+
const inj = await getInj();
|
|
24
|
+
return inj.CHUNK_GROUPS ?? {};
|
|
25
|
+
})();
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
const refCounts: Record<string, number> = {};
|
|
43
|
-
|
|
27
|
+
const refCounts = {};
|
|
44
28
|
function getPublicPath() {
|
|
45
29
|
return getBuildInfo().publicPath;
|
|
46
30
|
}
|
|
@@ -54,26 +38,19 @@ function getPublicPath() {
|
|
|
54
38
|
* @param refCount
|
|
55
39
|
* @return
|
|
56
40
|
*/
|
|
57
|
-
function bookStyleSheet(
|
|
58
|
-
|
|
59
|
-
loadedSheets: Set<string>,
|
|
60
|
-
refCount: boolean,
|
|
61
|
-
): Promise<void> | undefined {
|
|
62
|
-
let res: Barrier<void> | undefined;
|
|
41
|
+
function bookStyleSheet(name, loadedSheets, refCount) {
|
|
42
|
+
let res;
|
|
63
43
|
const path = `${getPublicPath()}/${name}`;
|
|
64
44
|
const fullPath = `${document.location.origin}${path}`;
|
|
65
|
-
|
|
66
45
|
if (!loadedSheets.has(fullPath)) {
|
|
67
46
|
let link = document.querySelector(`link[href="${path}"]`);
|
|
68
|
-
|
|
69
47
|
if (!link) {
|
|
70
48
|
link = document.createElement('link');
|
|
71
49
|
link.setAttribute('rel', 'stylesheet');
|
|
72
50
|
link.setAttribute('href', path);
|
|
73
51
|
document.head.appendChild(link);
|
|
74
52
|
}
|
|
75
|
-
|
|
76
|
-
res = new Barrier<void>();
|
|
53
|
+
res = new Barrier();
|
|
77
54
|
link.addEventListener('load', () => {
|
|
78
55
|
if (!res) throw Error('Internal error');
|
|
79
56
|
void res.resolve();
|
|
@@ -83,12 +60,10 @@ function bookStyleSheet(
|
|
|
83
60
|
void res.resolve();
|
|
84
61
|
});
|
|
85
62
|
}
|
|
86
|
-
|
|
87
63
|
if (refCount) {
|
|
88
64
|
const current = refCounts[path] ?? 0;
|
|
89
65
|
refCounts[path] = 1 + current;
|
|
90
66
|
}
|
|
91
|
-
|
|
92
67
|
return res;
|
|
93
68
|
}
|
|
94
69
|
|
|
@@ -96,19 +71,19 @@ function bookStyleSheet(
|
|
|
96
71
|
* Generates the set of URLs for currently loaded, linked stylesheets.
|
|
97
72
|
* @return
|
|
98
73
|
*/
|
|
99
|
-
function getLoadedStyleSheets()
|
|
100
|
-
const res = new Set
|
|
101
|
-
const {
|
|
102
|
-
|
|
74
|
+
function getLoadedStyleSheets() {
|
|
75
|
+
const res = new Set();
|
|
76
|
+
const {
|
|
77
|
+
styleSheets
|
|
78
|
+
} = document;
|
|
79
|
+
for (const {
|
|
80
|
+
href
|
|
81
|
+
} of styleSheets) {
|
|
103
82
|
if (href) res.add(href);
|
|
104
83
|
}
|
|
105
84
|
return res;
|
|
106
85
|
}
|
|
107
|
-
|
|
108
|
-
function assertChunkName(
|
|
109
|
-
chunkName: string,
|
|
110
|
-
chunkGroups: ChunkGroupsT,
|
|
111
|
-
) {
|
|
86
|
+
function assertChunkName(chunkName, chunkGroups) {
|
|
112
87
|
if (chunkGroups[chunkName]) return;
|
|
113
88
|
throw Error(`Unknown chunk name "${chunkName}"`);
|
|
114
89
|
}
|
|
@@ -122,27 +97,18 @@ function assertChunkName(
|
|
|
122
97
|
* @return Resolves once all pending stylesheets, necessary for
|
|
123
98
|
* the chunk, are either loaded, or failed to load.
|
|
124
99
|
*/
|
|
125
|
-
export async function bookStyleSheets(
|
|
126
|
-
chunkName: string,
|
|
127
|
-
chunkGroups: ChunkGroupsT,
|
|
128
|
-
refCount: boolean,
|
|
129
|
-
): Promise<void> {
|
|
100
|
+
export async function bookStyleSheets(chunkName, chunkGroups, refCount) {
|
|
130
101
|
const promises = [];
|
|
131
102
|
const assets = chunkGroups[chunkName];
|
|
132
103
|
if (!assets) return Promise.resolve();
|
|
133
|
-
|
|
134
104
|
const loadedSheets = getLoadedStyleSheets();
|
|
135
|
-
|
|
136
105
|
for (const asset of assets) {
|
|
137
106
|
if (asset.endsWith('.css')) {
|
|
138
107
|
const promise = bookStyleSheet(asset, loadedSheets, refCount);
|
|
139
108
|
if (promise) promises.push(promise);
|
|
140
109
|
}
|
|
141
110
|
}
|
|
142
|
-
|
|
143
|
-
return promises.length
|
|
144
|
-
? Promise.allSettled(promises).then()
|
|
145
|
-
: Promise.resolve();
|
|
111
|
+
return promises.length ? Promise.allSettled(promises).then() : Promise.resolve();
|
|
146
112
|
}
|
|
147
113
|
|
|
148
114
|
/**
|
|
@@ -152,21 +118,16 @@ export async function bookStyleSheets(
|
|
|
152
118
|
* the reference counter).
|
|
153
119
|
* @param {string} chunkName
|
|
154
120
|
*/
|
|
155
|
-
export function freeStyleSheets(
|
|
156
|
-
chunkName: string,
|
|
157
|
-
chunkGroups: ChunkGroupsT,
|
|
158
|
-
): void {
|
|
121
|
+
export function freeStyleSheets(chunkName, chunkGroups) {
|
|
159
122
|
const assets = chunkGroups[chunkName];
|
|
160
123
|
if (!assets) return;
|
|
161
|
-
|
|
162
124
|
for (const asset of assets) {
|
|
163
125
|
if (asset.endsWith('.css')) {
|
|
164
126
|
const path = `${getPublicPath()}/${asset}`;
|
|
165
|
-
|
|
166
127
|
const pathRefCount = refCounts[path];
|
|
167
128
|
if (pathRefCount) {
|
|
168
129
|
if (pathRefCount <= 1) {
|
|
169
|
-
document.head.querySelector(`link[href="${path}"]`)
|
|
130
|
+
document.head.querySelector(`link[href="${path}"]`).remove();
|
|
170
131
|
delete refCounts[path];
|
|
171
132
|
} else refCounts[path] = pathRefCount - 1;
|
|
172
133
|
}
|
|
@@ -176,11 +137,6 @@ export function freeStyleSheets(
|
|
|
176
137
|
|
|
177
138
|
// Holds the set of chunk names already used for splitComponent() calls.
|
|
178
139
|
const usedChunkNames = new Set();
|
|
179
|
-
|
|
180
|
-
type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
|
|
181
|
-
default: ComponentType<PropsT>;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
140
|
/**
|
|
185
141
|
* Given an async component retrieval function `getComponent()` it creates
|
|
186
142
|
* a special "code split" component, which uses <Suspense> to asynchronously
|
|
@@ -191,26 +147,23 @@ type ComponentOrModule<PropsT> = ComponentType<PropsT> | {
|
|
|
191
147
|
* @param {React.Element} [options.placeholder]
|
|
192
148
|
* @return {React.ElementType}
|
|
193
149
|
*/
|
|
194
|
-
export default function splitComponent
|
|
195
|
-
ComponentPropsT extends { children?: ReactNode; ref?: RefObject<unknown> },
|
|
196
|
-
>({
|
|
150
|
+
export default function splitComponent({
|
|
197
151
|
chunkName,
|
|
198
152
|
getComponent,
|
|
199
|
-
placeholder
|
|
200
|
-
}
|
|
201
|
-
chunkName: string;
|
|
202
|
-
getComponent: () => Promise<ComponentOrModule<ComponentPropsT>>;
|
|
203
|
-
placeholder?: ReactNode;
|
|
204
|
-
}): FunctionComponent<ComponentPropsT> {
|
|
205
|
-
// On the client side we can check right away if the chunk name is known.
|
|
206
|
-
if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);
|
|
207
|
-
|
|
153
|
+
placeholder
|
|
154
|
+
}) {
|
|
208
155
|
// The correct usage of splitComponent() assumes a single call per chunk.
|
|
209
156
|
if (usedChunkNames.has(chunkName)) {
|
|
210
157
|
throw Error(`Repeated splitComponent() call for the chunk "${chunkName}"`);
|
|
211
158
|
} else usedChunkNames.add(chunkName);
|
|
159
|
+
const LazyComponent = /*#__PURE__*/lazy(async () => {
|
|
160
|
+
const clientChunkGroups = await getClientChunkGroups();
|
|
212
161
|
|
|
213
|
-
|
|
162
|
+
// On the client side we can check right away if the chunk name is known.
|
|
163
|
+
if (IS_CLIENT_SIDE) {
|
|
164
|
+
if (!clientChunkGroups) throw Error('Internal error');
|
|
165
|
+
assertChunkName(chunkName, clientChunkGroups);
|
|
166
|
+
}
|
|
214
167
|
const resolved = await getComponent();
|
|
215
168
|
const Component = 'default' in resolved ? resolved.default : resolved;
|
|
216
169
|
|
|
@@ -218,10 +171,10 @@ export default function splitComponent<
|
|
|
218
171
|
// the component (the lazy load function is executed by React one at
|
|
219
172
|
// the frist mount).
|
|
220
173
|
if (IS_CLIENT_SIDE) {
|
|
174
|
+
if (!clientChunkGroups) throw Error('Internal error');
|
|
221
175
|
await bookStyleSheets(chunkName, clientChunkGroups, false);
|
|
222
176
|
}
|
|
223
|
-
|
|
224
|
-
const Wrapper: FunctionComponent<ComponentPropsT> = ({
|
|
177
|
+
const Wrapper = ({
|
|
225
178
|
children,
|
|
226
179
|
ref,
|
|
227
180
|
...rest
|
|
@@ -229,7 +182,10 @@ export default function splitComponent<
|
|
|
229
182
|
// On the server side we'll assert the chunk name here,
|
|
230
183
|
// and also push it to the SSR chunks array.
|
|
231
184
|
if (IS_SERVER_SIDE) {
|
|
232
|
-
const {
|
|
185
|
+
const {
|
|
186
|
+
chunkGroups,
|
|
187
|
+
chunks
|
|
188
|
+
} = getSsrContext();
|
|
233
189
|
assertChunkName(chunkName, chunkGroups);
|
|
234
190
|
if (!chunks.includes(chunkName)) chunks.push(chunkName);
|
|
235
191
|
}
|
|
@@ -237,39 +193,36 @@ export default function splitComponent<
|
|
|
237
193
|
// This takes care about stylesheets management every time an instance of
|
|
238
194
|
// this component is mounted / unmounted.
|
|
239
195
|
useInsertionEffect(() => {
|
|
196
|
+
if (!clientChunkGroups) throw Error('Internal error');
|
|
240
197
|
void bookStyleSheets(chunkName, clientChunkGroups, true);
|
|
241
198
|
return () => {
|
|
242
199
|
freeStyleSheets(chunkName, clientChunkGroups);
|
|
243
200
|
};
|
|
244
201
|
}, []);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
202
|
+
return /*#__PURE__*/_jsx(Component
|
|
203
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
204
|
+
, {
|
|
205
|
+
...rest,
|
|
206
|
+
ref: ref,
|
|
207
|
+
children: children
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
default: Wrapper
|
|
255
212
|
};
|
|
256
|
-
|
|
257
|
-
return { default: Wrapper };
|
|
258
213
|
});
|
|
259
|
-
|
|
260
|
-
const CodeSplit: React.FunctionComponent<ComponentPropsT> = ({
|
|
214
|
+
const CodeSplit = ({
|
|
261
215
|
children,
|
|
262
216
|
...rest
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
273
|
-
|
|
217
|
+
}) => /*#__PURE__*/_jsx(Suspense, {
|
|
218
|
+
fallback: placeholder,
|
|
219
|
+
children: /*#__PURE__*/_jsx(LazyComponent
|
|
220
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
221
|
+
, {
|
|
222
|
+
...rest,
|
|
223
|
+
children: children
|
|
224
|
+
})
|
|
225
|
+
});
|
|
274
226
|
return CodeSplit;
|
|
275
227
|
}
|
|
228
|
+
//# sourceMappingURL=splitComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splitComponent.js","names":["Suspense","lazy","useInsertionEffect","Barrier","getSsrContext","IS_CLIENT_SIDE","IS_SERVER_SIDE","getBuildInfo","jsx","_jsx","getClientChunkGroups","undefined","default","getInj","inj","CHUNK_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","usedChunkNames","splitComponent","getComponent","placeholder","LazyComponent","clientChunkGroups","resolved","Component","Wrapper","children","ref","rest","chunks","includes","CodeSplit","fallback"],"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, getSsrContext } from './globalState';\n\nimport {\n IS_CLIENT_SIDE,\n IS_SERVER_SIDE,\n getBuildInfo,\n} from './isomorphy';\n\nfunction getClientChunkGroups(): Promise<ChunkGroupsT> | undefined {\n if (!IS_CLIENT_SIDE) return undefined;\n\n return (async () => {\n const { default: getInj } = await import(/* webpackChunkName: \"react-utils-client-side-code\" */ '../../client/getInj');\n\n const inj = await getInj();\n return inj.CHUNK_GROUPS ?? {};\n })();\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.\nconst 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 // The correct usage of splitComponent() assumes a single call per chunk.\n if (usedChunkNames.has(chunkName)) {\n throw Error(`Repeated splitComponent() call for the chunk \"${chunkName}\"`);\n } else usedChunkNames.add(chunkName);\n\n const LazyComponent = lazy(async () => {\n const clientChunkGroups = await getClientChunkGroups();\n\n // On the client side we can check right away if the chunk name is known.\n if (IS_CLIENT_SIDE) {\n if (!clientChunkGroups) throw Error('Internal error');\n assertChunkName(chunkName, clientChunkGroups);\n }\n\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 children,\n ref,\n ...rest\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 const { chunkGroups, chunks } = getSsrContext()!;\n assertChunkName(chunkName, chunkGroups);\n if (!chunks.includes(chunkName)) chunks.push(chunkName);\n }\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, clientChunkGroups, true);\n return () => {\n freeStyleSheets(chunkName, clientChunkGroups);\n };\n }, []);\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: React.FunctionComponent<ComponentPropsT> = ({\n children,\n ...rest\n }: ComponentPropsT) => (\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 {children}\n </LazyComponent>\n </Suspense>\n );\n\n return CodeSplit;\n}\n"],"mappings":";;;;;;;;;AAAA;;AAEA,SAKEA,QAAQ,EACRC,IAAI,EACJC,kBAAkB,QACb,OAAO;AAEd,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,SAA4BC,aAAa;AAEzC,SACEC,cAAc,EACdC,cAAc,EACdC,YAAY;AACO,SAAAC,GAAA,IAAAC,IAAA;AAErB,SAASC,oBAAoBA,CAAA,EAAsC;EACjE,IAAI,CAACL,cAAc,EAAE,OAAOM,SAAS;EAErC,OAAO,CAAC,YAAY;IAClB,MAAM;MAAEC,OAAO,EAAEC;IAAO,CAAC,GAAG,MAAM,MAAM,CAAC,2EAA4E,CAAC;IAEtH,MAAMC,GAAG,GAAG,MAAMD,MAAM,CAAC,CAAC;IAC1B,OAAOC,GAAG,CAACC,YAAY,IAAI,CAAC,CAAC;EAC/B,CAAC,EAAE,CAAC;AACN;AAEA,MAAMC,SAAiC,GAAG,CAAC,CAAC;AAE5C,SAASC,aAAaA,CAAA,EAAG;EACvB,OAAOV,YAA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CAAC;IAEhB,CAAC;IAED,OAAO;MAAE3D,OAAO,EAAE0D;IAAQ,CAAC;EAC7B,CAAC,CAAC;EAEF,MAAMM,SAAmD,GAAGA,CAAC;IAC3DL,QAAQ;IACR,GAAGE;EACY,CAAC,kBAChBhE,IAAA,CAACT,QAAQ;IAAC6E,QAAQ,EAAEZ,WAAY;IAAAM,QAAA,eAC9B9D,IAAA,CAACyD;IACC;IAAA;MAAA,GACIO,IAAI;MAAAF,QAAA,EAEPA;IAAQ,CACI;EAAC,CACR,CACX;EAED,OAAOK,SAAS;AAClB","ignoreList":[]}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { serialize } from 'cookie';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
HOUR_MS,
|
|
8
|
-
MIN_MS,
|
|
9
|
-
SEC_MS,
|
|
10
|
-
YEAR_MS,
|
|
11
|
-
timer,
|
|
12
|
-
} from '@dr.pogodin/js-utils';
|
|
13
|
-
|
|
14
|
-
import { type ForceT, useGlobalState } from '@dr.pogodin/react-global-state';
|
|
15
|
-
|
|
16
|
-
import { getSsrContext } from './globalState';
|
|
4
|
+
import { DAY_MS, HOUR_MS, MIN_MS, SEC_MS, YEAR_MS, timer } from '@dr.pogodin/js-utils';
|
|
5
|
+
import { useGlobalState } from '@dr.pogodin/react-global-state';
|
|
6
|
+
import { getSsrContext } from "./globalState";
|
|
17
7
|
|
|
18
8
|
/**
|
|
19
9
|
* This react hook wraps Date.now() function in a SSR friendly way,
|
|
@@ -28,23 +18,20 @@ import { getSsrContext } from './globalState';
|
|
|
28
18
|
export function useCurrent({
|
|
29
19
|
autorefresh = false,
|
|
30
20
|
globalStatePath = 'currentTime',
|
|
31
|
-
precision = 5 * SEC_MS
|
|
32
|
-
} = {})
|
|
33
|
-
const [now, setter] = useGlobalState
|
|
34
|
-
globalStatePath,
|
|
35
|
-
Date.now,
|
|
36
|
-
);
|
|
21
|
+
precision = 5 * SEC_MS
|
|
22
|
+
} = {}) {
|
|
23
|
+
const [now, setter] = useGlobalState(globalStatePath, Date.now);
|
|
37
24
|
useEffect(() => {
|
|
38
|
-
let timerId
|
|
39
|
-
const update = ()
|
|
40
|
-
setter(
|
|
25
|
+
let timerId;
|
|
26
|
+
const update = () => {
|
|
27
|
+
setter(old => {
|
|
41
28
|
const neu = Date.now();
|
|
42
29
|
return Math.abs(neu - old) > precision ? neu : old;
|
|
43
30
|
});
|
|
44
31
|
if (autorefresh) timerId = setTimeout(update, precision);
|
|
45
32
|
};
|
|
46
33
|
update();
|
|
47
|
-
return ()
|
|
34
|
+
return () => {
|
|
48
35
|
if (timerId) clearTimeout(timerId);
|
|
49
36
|
};
|
|
50
37
|
}, [autorefresh, precision, setter]);
|
|
@@ -64,28 +51,25 @@ export function useCurrent({
|
|
|
64
51
|
// to verify the give globalStatePath is correct?
|
|
65
52
|
export function useTimezoneOffset({
|
|
66
53
|
cookieName = 'timezoneOffset',
|
|
67
|
-
globalStatePath = 'timezoneOffset'
|
|
68
|
-
} = {})
|
|
54
|
+
globalStatePath = 'timezoneOffset'
|
|
55
|
+
} = {}) {
|
|
69
56
|
const ssrContext = getSsrContext(false);
|
|
70
|
-
const [offset, setOffset] = useGlobalState
|
|
71
|
-
|
|
72
|
-
()
|
|
73
|
-
|
|
74
|
-
&& ssrContext?.req.cookies[cookieName] as string;
|
|
75
|
-
return value ? parseInt(value) : 0;
|
|
76
|
-
},
|
|
77
|
-
);
|
|
57
|
+
const [offset, setOffset] = useGlobalState(globalStatePath, () => {
|
|
58
|
+
const value = cookieName && ssrContext?.req.cookies[cookieName];
|
|
59
|
+
return value ? parseInt(value) : 0;
|
|
60
|
+
});
|
|
78
61
|
useEffect(() => {
|
|
79
62
|
const date = new Date();
|
|
80
63
|
const value = date.getTimezoneOffset();
|
|
81
64
|
setOffset(value);
|
|
82
65
|
if (cookieName) {
|
|
83
|
-
document.cookie = serialize(cookieName, value.toString(), {
|
|
66
|
+
document.cookie = serialize(cookieName, value.toString(), {
|
|
67
|
+
path: '/'
|
|
68
|
+
});
|
|
84
69
|
}
|
|
85
70
|
}, [cookieName, setOffset]);
|
|
86
71
|
return offset;
|
|
87
72
|
}
|
|
88
|
-
|
|
89
73
|
const time = {
|
|
90
74
|
DAY_MS,
|
|
91
75
|
HOUR_MS,
|
|
@@ -95,7 +79,7 @@ const time = {
|
|
|
95
79
|
now: Date.now,
|
|
96
80
|
timer,
|
|
97
81
|
useCurrent,
|
|
98
|
-
useTimezoneOffset
|
|
82
|
+
useTimezoneOffset
|
|
99
83
|
};
|
|
100
|
-
|
|
101
84
|
export default Object.assign(dayjs, time);
|
|
85
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","names":["serialize","useEffect","dayjs","DAY_MS","HOUR_MS","MIN_MS","SEC_MS","YEAR_MS","timer","useGlobalState","getSsrContext","useCurrent","autorefresh","globalStatePath","precision","now","setter","Date","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","toString","path","time","Object","assign"],"sources":["../../../../src/shared/utils/time.ts"],"sourcesContent":["import { serialize } from 'cookie';\nimport { useEffect } from 'react';\nimport dayjs from 'dayjs';\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 { getSsrContext } 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 = getSsrContext(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 = serialize(cookieName, value.toString(), { path: '/' });\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,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,SAAS,QAAQ,OAAO;AACjC,OAAOC,KAAK,MAAM,OAAO;AAEzB,SACEC,MAAM,EACNC,O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M,CAACmB,MAAM,EAAEC,SAAS,CAAC,GAAGrB,cAAc,CACxCI,eAAe,EACf,MAAM;IACJ,MAAMkB,KAAK,GAAGJ,UAAU,IACnBC,UAAU,EAAEI,GAAG,CAACC,OAAO,CAACN,UAAU,CAAW;IAClD,OAAOI,KAAK,GAAGG,QAAQ,CAACH,KAAK,CAAC,GAAG,CAAC;EACpC,CACF,CAAC;EACD9B,SAAS,CAAC,MAAM;IACd,MAAMkC,IAAI,GAAG,IAAIlB,IAAI,CAAC,CAAC;IACvB,MAAMc,KAAK,GAAGI,IAAI,CAACC,iBAAiB,CAAC,CAAC;IACtCN,SAAS,CAACC,KAAK,CAAC;IAChB,IAAIJ,UAAU,EAAE;MACdU,QAAQ,CAACC,MAAM,GAAGtC,SAAS,CAAC2B,UAAU,EAAEI,KAAK,CAACQ,QAAQ,CAAC,CAAC,EAAE;QAAEC,IAAI,EAAE;MAAI,CAAC,CAAC;IAC1E;EACF,CAAC,EAAE,CAACb,UAAU,EAAEG,SAAS,CAAC,CAAC;EAC3B,OAAOD,MAAM;AACf;AAEA,MAAMY,IAAI,GAAG;EACXtC,MAAM;EACNC,OAAO;EACPC,MAAM;EACNC,MAAM;EACNC,OAAO;EACPQ,GAAG,EAAEE,IAAI,CAACF,GAAG;EACbP,KAAK;EACLG,UAAU;EACVe;AACF,CAAC;AAED,eAAegB,MAAM,CAACC,MAAM,CAACzC,KAAK,EAAEuC,IAAI,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import "core-js/modules/es.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/es.iterator.for-each.js";
|
|
3
|
+
// eslint-disable-next-line import/enforce-node-protocol-usage
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import { IS_CLIENT_SIDE, IS_SERVER_SIDE } from "./isomorphy";
|
|
6
|
+
let require;
|
|
7
|
+
if (IS_SERVER_SIDE) require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Requires the specified module without including it into the bundle during
|
|
11
|
+
* Webpack build.
|
|
12
|
+
* @param modulePath
|
|
13
|
+
* @param [basePath]
|
|
14
|
+
* @return Required module.
|
|
15
|
+
*/
|
|
16
|
+
export function requireWeak(modulePath,
|
|
17
|
+
// TODO: For now `basePath` can be provided directly as a string here,
|
|
18
|
+
// for backward compatibility. Deprecate it in future, if any other
|
|
19
|
+
// breaking changes are done for requireWeak().
|
|
20
|
+
basePathOrOptions) {
|
|
21
|
+
if (IS_CLIENT_SIDE) return null;
|
|
22
|
+
let basePath;
|
|
23
|
+
let ops;
|
|
24
|
+
if (typeof basePathOrOptions === 'string') {
|
|
25
|
+
basePath = basePathOrOptions;
|
|
26
|
+
} else {
|
|
27
|
+
ops = basePathOrOptions ?? {};
|
|
28
|
+
({
|
|
29
|
+
basePath
|
|
30
|
+
} = ops);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
34
|
+
const {
|
|
35
|
+
resolve
|
|
36
|
+
} = require('node:path');
|
|
37
|
+
const path = basePath ? resolve(basePath, modulePath) : modulePath;
|
|
38
|
+
const module = require(path);
|
|
39
|
+
if (!('default' in module) || !module.default) return module;
|
|
40
|
+
const {
|
|
41
|
+
default: def,
|
|
42
|
+
...named
|
|
43
|
+
} = module;
|
|
44
|
+
const res = def;
|
|
45
|
+
Object.entries(named).forEach(([name, value]) => {
|
|
46
|
+
const assigned = res[name];
|
|
47
|
+
if (assigned === undefined) {
|
|
48
|
+
res[name] = value;
|
|
49
|
+
} else if (assigned !== value) {
|
|
50
|
+
throw Error('Conflict between default and named exports');
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolves specified module path with help of Babel's module resolver.
|
|
58
|
+
* Yes, the function itself just returns its argument to the caller, but Babel
|
|
59
|
+
* is configured to resolve the first argument of resolveWeak(..) function, thus
|
|
60
|
+
* the result will be the resolved path.
|
|
61
|
+
* @param {string} modulePath
|
|
62
|
+
* @return {string} Absolute or relative path to the module.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveWeak(modulePath) {
|
|
65
|
+
return modulePath;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +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\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?: string | RequireWeakOptionsT,\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":";;AAEA;AACA,SAASA,aAAa,QAAQ,QAAQ;AAEtC,SAASC,cAAc,EAAEC,cAAc;AAUvC,IAAIC,OAA+C;AAEnD,IAAID,cAAc,EAAEC,OAAO,GAAGH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CACzBC,UAAkB;AAElB;AACA;AACA;AACAC,iBAAgD,EACrB;EAC3B,IAAIR,cAAc,EAAE,OAAO,IAAI;EAE/B,IAAIS,QAA4B;EAChC,IAAIC,GAAwB;EAC5B,IAAI,OAAOF,iBAAiB,KAAK,QAAQ,EAAE;IACzCC,QAAQ,GAAGD,iBAAiB;EAC9B,CAAC,MAAM;IACLE,GAAG,GAAGF,iBAAiB,IAAI,CAAC,CAAC;IAC7B,CAAC;MAAEC;IAAS,CAAC,GAAGC,GAAG;EACrB;;EAEA;EACA,MAAM;IAAEC;EAAQ,CAAC,GAAGT,OAAO,CAAE,WAAW,CAAkB;EAE1D,MAAMU,IAAI,GAAGH,QAAQ,GAAGE,OAAO,CAACF,QAAQ,EAAEF,UAAU,CAAC,GAAGA,UAAU;EAElE,MAAMM,MAAM,GAAGX,OAAO,CAAEU,IAAI,CAAM;EAElC,IAAI,EAAE,SAAS,IAAIC,MAAM,CAAC,IAAI,CAACA,MAAM,CAACC,OAAO,EAAE,OAAOD,MAAM;EAE5D,MAAM;IAAEC,OAAO,EAAEC,GAAG;IAAE,GAAGC;EAAM,CAAC,GAAGH,MAAM;EAEzC,MAAMI,GAAG,GAAGF,GAAyB;EAErCG,MAAM,CAACC,OAAO,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,CAAC,CAACC,IAAI,EAAEC,KAAK,CAAC,KAAK;IAC/C,MAAMC,QAAQ,GAAGN,GAAG,CAACI,IAAI,CAA6B;IACtD,IAAIE,QAAQ,KAAKC,SAAS,EAAE;MACzBP,GAAG,CAACI,IAAI,CAA6B,GAAeC,KAAK;IAC5D,CAAC,MAAM,IAAIC,QAAQ,KAAKD,KAAK,EAAE;MAC7B,MAAMG,KAAK,CAAC,4CAA4C,CAAC;IAC3D;EACF,CAAC,CAAC;EACF,OAAOR,GAAG;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,WAAWA,CAACnB,UAAkB,EAAU;EACtD,OAAOA,UAAU;AACnB","ignoreList":[]}
|
package/config/babel/node-ssr.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.default = getConfig;
|
|
37
|
-
const
|
|
37
|
+
const lodash_es_1 = require("lodash-es");
|
|
38
38
|
const webpack_1 = __importStar(require("./webpack"));
|
|
39
39
|
/**
|
|
40
40
|
* Creates a new base config.
|
|
@@ -48,12 +48,21 @@ const webpack_1 = __importStar(require("./webpack"));
|
|
|
48
48
|
*/
|
|
49
49
|
function newBase(babel, options = {}) {
|
|
50
50
|
var _a;
|
|
51
|
-
const config = (0, webpack_1.default)(babel, Object.assign({
|
|
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: 'maintained node versions' }, options));
|
|
52
58
|
const baseAssetsOutputPath = (_a = options.baseAssetsOutputPath) !== null && _a !== void 0 ? _a : '';
|
|
53
59
|
config.plugins.push(['@dr.pogodin/transform-assets', {
|
|
54
60
|
extensions: ['gif', 'jpeg', 'jpg', 'png'],
|
|
55
61
|
name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
|
|
56
62
|
}]);
|
|
63
|
+
if (options.modules === false) {
|
|
64
|
+
config.plugins.push('babel-plugin-add-import-extension');
|
|
65
|
+
}
|
|
57
66
|
const moduleResolverPluginOps = config.plugins.find((x) => Array.isArray(x) && x[0] === 'module-resolver')[1];
|
|
58
67
|
moduleResolverPluginOps.transformFunctions = [
|
|
59
68
|
'requireWeak',
|
|
@@ -62,7 +71,7 @@ function newBase(babel, options = {}) {
|
|
|
62
71
|
'webpack.resolveWeak',
|
|
63
72
|
];
|
|
64
73
|
if (babel.env() === webpack_1.ENVIRONMENTS.DEV) {
|
|
65
|
-
(0,
|
|
74
|
+
(0, lodash_es_1.pull)(config.plugins, 'react-refresh/babel');
|
|
66
75
|
}
|
|
67
76
|
return config;
|
|
68
77
|
}
|
package/config/babel/webpack.js
CHANGED
|
@@ -30,13 +30,18 @@ function newBaseConfig(options) {
|
|
|
30
30
|
'./src',
|
|
31
31
|
],
|
|
32
32
|
}],
|
|
33
|
-
'@babel/transform-runtime',
|
|
33
|
+
['@babel/transform-runtime', {
|
|
34
|
+
useESModules: true,
|
|
35
|
+
}],
|
|
34
36
|
],
|
|
35
37
|
presets: [
|
|
36
38
|
['@babel/env', {
|
|
39
|
+
bugfixes: true,
|
|
40
|
+
corejs: '3.46',
|
|
37
41
|
// Leaves it to the Webpack to deal with modules.
|
|
38
42
|
modules: (_a = options.modules) !== null && _a !== void 0 ? _a : false,
|
|
39
43
|
targets: (_b = options.targets) !== null && _b !== void 0 ? _b : 'defaults',
|
|
44
|
+
useBuiltIns: 'usage',
|
|
40
45
|
}],
|
|
41
46
|
// TODO: Starting from Babel 8, "automatic" will be the default runtime,
|
|
42
47
|
// thus once upgraded to Babel 8, runtime should be removed from
|
package/config/jest/default.js
CHANGED
|
@@ -5,6 +5,13 @@ const path = require('node:path');
|
|
|
5
5
|
|
|
6
6
|
const globalLibDir = path.resolve(process.execPath, '../../lib/node_modules');
|
|
7
7
|
|
|
8
|
+
const modulesToTransform = [
|
|
9
|
+
'@dr.pogodin/react-global-state',
|
|
10
|
+
'@dr.pogodin/react-utils',
|
|
11
|
+
'lodash-es',
|
|
12
|
+
'uuid',
|
|
13
|
+
];
|
|
14
|
+
|
|
8
15
|
module.exports = {
|
|
9
16
|
collectCoverage: true,
|
|
10
17
|
collectCoverageFrom: [
|
|
@@ -36,7 +43,6 @@ module.exports = {
|
|
|
36
43
|
'\\.((j|t)sx?|svg)$': 'babel-jest',
|
|
37
44
|
},
|
|
38
45
|
transformIgnorePatterns: [
|
|
39
|
-
|
|
46
|
+
`/node_modules/(?!${modulesToTransform.join('|')})`,
|
|
40
47
|
],
|
|
41
|
-
|
|
42
48
|
};
|
package/config/jest/setup.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/* global globalThis, require */
|
|
1
|
+
/* global globalThis, require, window */
|
|
2
|
+
|
|
3
|
+
import { subtle } from 'node:crypto';
|
|
2
4
|
|
|
3
5
|
// eslint-disable-next-line import/no-unassigned-import
|
|
4
6
|
import 'raf/polyfill';
|
|
@@ -11,3 +13,8 @@ if (!globalThis.TextEncoder || !globalThis.TextDecoder) {
|
|
|
11
13
|
globalThis.TextEncoder = TextEncoder;
|
|
12
14
|
globalThis.TextDecoder = TextDecoder;
|
|
13
15
|
}
|
|
16
|
+
|
|
17
|
+
// Polyfill of crypto.subtle in JSDOM environments.
|
|
18
|
+
if (typeof window !== 'undefined') {
|
|
19
|
+
window.crypto.subtle = subtle;
|
|
20
|
+
}
|