@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.
- package/__type_tests__/ts-compiler-behavior.ts +13 -0
- package/__type_tests__/type-exports.ts +17 -0
- package/babel.build.config.js +9 -0
- package/babel.config.js +2 -5
- package/babel.libweb.config.js +2 -3
- package/babel.scripts.config.js +5 -11
- package/bin/build.js +4 -21
- package/bin/release.sh +1 -1
- package/build/development/client/getInj.js +2 -9
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +1 -3
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +10 -24
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +6 -8
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +11 -11
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +2 -5
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -4
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -5
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +2 -2
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/components/selectors/index.js.map +1 -1
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +4 -5
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv/index.js +32 -71
- package/build/development/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js +23 -0
- package/build/development/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
- package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
- package/build/development/shared/utils/jest/global.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +3 -3
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +3 -16
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +28 -65
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +3 -5
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/server/Cache.js.map +1 -1
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +5 -5
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +4 -4
- package/build/production/server/server.js.map +1 -1
- package/build/production/server/utils/errors.js +2 -2
- package/build/production/server/utils/errors.js.map +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Link.js.map +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +2 -2
- 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.map +1 -1
- package/build/production/shared/components/selectors/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/production/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/production/shared/utils/isomorphy/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv/index.js +12 -37
- package/build/production/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
- package/build/production/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
- package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js +1 -1
- package/build/production/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
- package/build/production/shared/utils/jest/global.js.map +1 -1
- package/build/production/shared/utils/jest/index.js +3 -3
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +3 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +2 -2
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js +3 -3
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/shared/utils/webpack.d.ts +2 -2
- package/build/web/client/getInj.js +2 -2
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +1 -1
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +1 -1
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +1 -1
- package/build/web/index.js.map +1 -1
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/index.js +1 -1
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +6 -6
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +5 -5
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +2 -2
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/index.js +1 -1
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +1 -1
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +1 -1
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +1 -1
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +1 -1
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/index.js +1 -1
- package/build/web/shared/components/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +3 -3
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/components/selectors/common.js.map +1 -1
- package/build/web/shared/components/selectors/index.js +1 -1
- package/build/web/shared/components/selectors/index.js.map +1 -1
- package/build/web/shared/utils/config.js +1 -1
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -1
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/web/shared/utils/isomorphy/index.js +1 -1
- package/build/web/shared/utils/isomorphy/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv/index.js +12 -37
- package/build/web/shared/utils/jest/E2eSsrEnv/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js +5 -0
- package/build/web/shared/utils/jest/E2eSsrEnv/ssr-preload.js.map +1 -0
- package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js +2 -2
- package/build/web/shared/utils/jest/E2eSsrEnv/ssr.js.map +1 -1
- package/build/web/shared/utils/jest/global.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +4 -4
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +3 -3
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +2 -2
- package/build/web/shared/utils/time.js.map +1 -1
- package/build/web/shared/utils/webpack.js +4 -4
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/node-ssr.d.ts +2 -3
- package/config/babel/node-ssr.js +15 -55
- package/config/babel/webpack.d.ts +7 -5
- package/config/babel/webpack.js +19 -24
- package/config/eslint/default.mjs +1 -1
- package/config/jest/default.js +6 -7
- package/config/jest/resolver.js +1 -3
- package/config/jest/setup.js +2 -2
- package/config/stylelint/default.js +1 -4
- package/config/webpack/app-base.js +40 -41
- package/config/webpack/app-development.d.ts +1 -1
- package/config/webpack/app-development.js +12 -18
- package/config/webpack/app-production.d.ts +1 -1
- package/config/webpack/app-production.js +10 -16
- package/package.json +42 -39
- package/patches/jest-resolve+30.4.1.patch +29 -0
- package/tsconfig.configs.json +6 -1
- package/tsconfig.json +2 -1
- package/tsconfig.types.json +1 -0
- package/tstyche.json +1 -1
- package/babel.module.config.js +0 -11
- package/build/development/shared/utils/jest/E2eSsrEnv/register.js +0 -6
- package/build/development/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
- package/build/production/shared/utils/jest/E2eSsrEnv/register.js +0 -3
- package/build/production/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
- package/build/web/shared/utils/jest/E2eSsrEnv/register.js +0 -3
- package/build/web/shared/utils/jest/E2eSsrEnv/register.js.map +0 -1
- /package/build/types-code/shared/utils/jest/E2eSsrEnv/{register.d.ts → ssr-preload.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
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(
|
|
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":[
|
|
1
|
+
{"version":3,"file":"time.js","names":[],"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,CACpD,CAAC,CAAC,CACF,GAAI,WAAW,CAAE,OAAO,CAAG,UAAU,CAAC,MAAM,CAAE,SAAS,CAAC,CAC1D,CAAC,CACD,MAAM,CAAC,CAAC,CACR,MAAO,IAAY,CACjB,GAAI,OAAO,CAAE,YAAY,CAAC,OAAO,CAAC,CACpC,CAAC,CACH,CAAC,CAAE,CAAC,WAAW,CAAE,SAAS,CAAE,MAAM,CAAC,CAAC,CACpC,MAAO,IAAG,CACZ,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA;AACA;AACA,MAAO,SAAS,kBAAiB,CAAC,CAChC,UAAU,CAAG,gBAAgB,CAC7B,eAAe,CAAG,gBACpB,CAAC,CAAG,CAAC,CAAC,CAAU,CACd,KAAM,WAAU,CAAG,aAAa,CAAC,KAAK,CAAC,CACvC,KAAM,CAAC,MAAM,CAAE,SAAS,CAAC,CAAG,cAAc,CACxC,eAAe,CACf,IAAM,CACJ,KAAM,MAAK,CAAG,UAAU,EACnB,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,CAAW,CAClD,MAAO,MAAK,CAAG,QAAQ,CAAC,KAAK,CAAC,CAAG,CAAC,CACpC,CACF,CAAC,CACD,SAAS,CAAC,IAAM,CACd,KAAM,KAAI,CAAG,GAAI,KAAM,CACvB,KAAM,QAAK,CAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC,CACtC,SAAS,CAAC,OAAK,CAAC,CAChB,GAAI,UAAU,CAAE,CACd,QAAQ,CAAC,MAAM,CAAG,kBAAkB,CAAC,CACnC,IAAI,CAAE,UAAU,CAChB,IAAI,CAAE,GAAG,CACT,KAAK,CAAE,OAAK,CAAC,QAAQ,CAAC,CACxB,CAAC,CAAC,CACJ,CACF,CAAC,CAAE,CAAC,UAAU,CAAE,SAAS,CAAC,CAAC,CAC3B,MAAO,OAAM,CACf,CAEA,KAAM,KAAI,CAAG,CACX,MAAM,CACN,OAAO,CACP,MAAM,CACN,MAAM,CACN,OAAO,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,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// eslint-disable-next-line import/enforce-node-protocol-usage, perfectionist/sort-imports
|
|
2
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.
|
|
@@ -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
|
|
18
|
-
* @return
|
|
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":[
|
|
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":[]}
|
|
@@ -17,8 +17,8 @@ export declare function requireWeak<T extends object>(modulePath: string, basePa
|
|
|
17
17
|
* Yes, the function itself just returns its argument to the caller, but Babel
|
|
18
18
|
* is configured to resolve the first argument of resolveWeak(..) function, thus
|
|
19
19
|
* the result will be the resolved path.
|
|
20
|
-
* @param
|
|
21
|
-
* @return
|
|
20
|
+
* @param modulePath
|
|
21
|
+
* @return Absolute or relative path to the module.
|
|
22
22
|
*/
|
|
23
23
|
export declare function resolveWeak(modulePath: string): string;
|
|
24
24
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
/* global document */import{SEC_MS,timer}from"@dr.pogodin/js-utils";import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo";let inj;export default function getInj(){inj??=(async()=>{const metaElement=typeof document==="undefined"?null:document.querySelector("meta[itemprop=\"drpruinj\"]");if(metaElement){metaElement.remove();// NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
|
|
1
|
+
// Encapsulates retrieval of server-side data injection into HTML template.
|
|
2
|
+
/* global document */import{SEC_MS,timer}from"@dr.pogodin/js-utils";import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo.js";let inj;export default function getInj(){inj??=(async()=>{const metaElement=typeof document==="undefined"?null:document.querySelector("meta[itemprop=\"drpruinj\"]");if(metaElement){metaElement.remove();// NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
|
|
3
3
|
// preferred, but it is not supported by older environments yet.
|
|
4
4
|
const data=atob(metaElement.content);if(!window.isSecureContext){if(window.location.protocol==="https:"){throw Error("Loaded via HTTPS, but it is not considered a secure context");}else if(window.location.protocol!=="http:"){throw Error("Unexpected protocol");}const target=window.location.href.replace(/^http:/,"https:");window.location.replace(target);await timer(3*SEC_MS);throw Error("Failed to move into secure context");}const{key}=getBuildInfo();const code=x=>x.charCodeAt(0);const dataBuffer=Uint8Array.from(data.slice(16),code);const ivBuffer=Uint8Array.from(data.slice(0,16),code);const keyBuffer=Uint8Array.from(atob(key),code);const cKey=await window.crypto.subtle.importKey("raw",keyBuffer,{name:"AES-CBC"},false,["decrypt"]);const buffer=await window.crypto.subtle.decrypt({iv:ivBuffer,name:"AES-CBC"},cKey,dataBuffer);const decoder=new TextDecoder;// eslint-disable-next-line no-eval
|
|
5
5
|
const res=eval(`(${decoder.decode(buffer)})`);// NOTE: This is important, to be able to return the injection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInj.js","names":[
|
|
1
|
+
{"version":3,"file":"getInj.js","names":[],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport { SEC_MS, timer } from '@dr.pogodin/js-utils';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n if (!window.isSecureContext) {\n if (window.location.protocol === 'https:') {\n throw Error('Loaded via HTTPS, but it is not considered a secure context');\n } else if (window.location.protocol !== 'http:') {\n throw Error('Unexpected protocol');\n }\n\n const target = window.location.href.replace(/^http:/, 'https:');\n window.location.replace(target);\n\n await timer(3 * SEC_MS);\n throw Error('Failed to move into secure context');\n }\n\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n return {};\n })();\n\n return inj;\n}\n"],"mappings":"AAAA;AAEA,qBAEA,OAAS,MAAM,CAAE,KAAK,KAAQ,sBAAsB,CAAC,OAI5C,YAAY,8CAErB,GAAI,IAAqC,CAEzC,cAAe,SAAS,OAAM,EAAyB,CACrD,GAAG,GAAK,CAAC,SAAY,CACnB,KAAM,YAAmC,CAAG,MAAO,SAAQ,GAAK,WAAW,CACvE,IAAI,CAAG,QAAQ,CAAC,aAAa,CAAC,6BAA2B,CAAC,CAE9D,GAAI,WAAW,CAAE,CACf,WAAW,CAAC,MAAM,CAAC,CAAC,CAEpB;AACA;AACA,KAAM,KAAI,CAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAEtC,GAAI,CAAC,MAAM,CAAC,eAAe,CAAE,CAC3B,GAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAK,QAAQ,CAAE,CACzC,KAAM,MAAK,CAAC,6DAA6D,CAAC,CAC5E,CAAC,IAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAK,OAAO,CAAE,CAC/C,KAAM,MAAK,CAAC,qBAAqB,CAAC,CACpC,CAEA,KAAM,OAAM,CAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAE,QAAQ,CAAC,CAC/D,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAE/B,KAAM,MAAK,CAAC,CAAC,CAAG,MAAM,CAAC,CACvB,KAAM,MAAK,CAAC,oCAAoC,CAAC,CACnD,CAEA,KAAM,CAAE,GAAI,CAAC,CAAG,YAAY,CAAC,CAAC,CAE9B,KAAM,KAAI,CAAI,CAAS,EAAK,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAC3C,KAAM,WAAU,CAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAE,IAAI,CAAC,CACxD,KAAM,SAAQ,CAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC,CAAE,IAAI,CAAC,CACzD,KAAM,UAAS,CAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,IAAI,CAAC,CAElD,KAAM,KAAI,CAAG,KAAM,OAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC/C,KAAK,CACL,SAAS,CACT,CAAE,IAAI,CAAE,SAAU,CAAC,CACnB,KAAK,CACL,CAAC,SAAS,CACZ,CAAC,CAED,KAAM,OAAM,CAAG,KAAM,OAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAChD,EAAE,CAAE,QAAQ,CACZ,IAAI,CAAE,SACR,CAAC,CAAE,IAAI,CAAE,UAAU,CAAC,CAEpB,KAAM,QAAO,CAAG,GAAI,YAAa,CAEjC;AACA,KAAM,IAAG,CAAG,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAS,CAEvD;AACA;AACA,GAAG,CAAG,GAAG,CAET,MAAO,IAAG,CACZ,CAAC,IAAM,IAAI,MAAO,OAAM,GAAK,WAAW,EAAI,MAAM,CAAC,qBAAqB,CAAE,CACxE,KAAM,IAAG,CAAG,MAAM,CAAC,qBAAqB,CACxC,MAAO,OAAM,CAAC,qBAAqB,CACnC,MAAO,IAAG,CACZ,CAEA;AACA;AACA;AACA,MAAO,CAAC,CAAC,CACX,CAAC,EAAE,CAAC,CAEJ,MAAO,IAAG,CACZ","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Initialization of client-side code.
|
|
2
|
-
/* global document */import{createRoot,hydrateRoot}from"react-dom/client";import{BrowserRouter}from"react-router";import{GlobalStateProvider}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import{setClientChunkGroups}from"../shared/utils/splitComponent";import getInj from"./getInj";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
2
|
+
/* global document */import{createRoot,hydrateRoot}from"react-dom/client";import{BrowserRouter}from"react-router";import{GlobalStateProvider}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import{setClientChunkGroups}from"../shared/utils/splitComponent.js";import getInj from"./getInj.js";import{jsx as _jsx}from"react/jsx-runtime";/**
|
|
3
3
|
* Prepares and launches the app at client side.
|
|
4
4
|
* @param Application Root application component
|
|
5
5
|
* @param [options={}] Optional. Additional settings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/client/index.tsx"],"sourcesContent":["// Initialization of client-side code.\n/* global document */\n\nimport type { ComponentType } from 'react';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\nimport { HelmetProvider } from '@dr.pogodin/react-helmet';\n\nimport { setClientChunkGroups } from 'utils/splitComponent';\n\nimport getInj from './getInj';\n\ntype OptionsT = {\n dontHydrate?: boolean;\n initialState?: unknown;\n};\n\n/**\n * Prepares and launches the app at client side.\n * @param Application Root application component\n * @param [options={}] Optional. Additional settings.\n */\nexport async function launchClient(\n Application: ComponentType,\n options: OptionsT = {},\n): Promise<void> {\n const inj = await getInj();\n\n setClientChunkGroups(inj.CHUNK_GROUPS ?? {});\n\n const container = document.getElementById('react-view');\n if (!container) throw Error('Failed to find container for React app');\n const scene = (\n <GlobalStateProvider initialState={inj.ISTATE ?? options.initialState}>\n <BrowserRouter>\n <HelmetProvider>\n <Application />\n </HelmetProvider>\n </BrowserRouter>\n </GlobalStateProvider>\n );\n\n if (options.dontHydrate) {\n const root = createRoot(container);\n root.render(scene);\n } else hydrateRoot(container, scene);\n}\n"],"mappings":"AAAA;AACA,qBAGA,OAAS,UAAU,CAAE,WAAW,KAAQ,kBAAkB,CAC1D,OAAS,aAAa,KAAQ,cAAc,CAE5C,OAAS,mBAAmB,KAAQ,gCAAgC,CACpE,OAAS,cAAc,KAAQ,0BAA0B,CAAC,OAEjD,oBAAoB,+CAEtB,OAAM,8DAOb;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,aAAY,CAChC,WAA0B,CAC1B,OAAiB,CAAG,CAAC,CAAC,CACP,CACf,KAAM,IAAG,CAAG,KAAM,OAAM,CAAC,CAAC,CAE1B,oBAAoB,CAAC,GAAG,CAAC,YAAY,EAAI,CAAC,CAAC,CAAC,CAE5C,KAAM,UAAS,CAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAAC,CACvD,GAAI,CAAC,SAAS,CAAE,KAAM,MAAK,CAAC,wCAAwC,CAAC,CACrE,KAAM,MAAK,cACT,KAAC,mBAAmB,EAAC,YAAY,CAAE,GAAG,CAAC,MAAM,EAAI,OAAO,CAAC,YAAa,uBACpE,KAAC,aAAa,wBACZ,KAAC,cAAc,wBACb,KAAC,WAAW,GAAE,CAAC,CACD,CAAC,CACJ,CAAC,CACG,CACtB,CAED,GAAI,OAAO,CAAC,WAAW,CAAE,CACvB,KAAM,KAAI,CAAG,UAAU,CAAC,SAAS,CAAC,CAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CACpB,CAAC,IAAM,YAAW,CAAC,SAAS,CAAE,KAAK,CAAC,CACtC","ignoreList":[]}
|
package/build/web/client/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Initialization of client-side environment.
|
|
3
|
-
*//* global window */import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo";const buildInfo=getBuildInfo();// TODO: Should be moved into buildInfo module?
|
|
3
|
+
*//* global window */import{getBuildInfo}from"../shared/utils/isomorphy/buildInfo.js";const buildInfo=getBuildInfo();// TODO: Should be moved into buildInfo module?
|
|
4
4
|
if(process.env.NODE_ENV!=="production"){// eslint-disable-next-line no-console
|
|
5
5
|
console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\"");// eslint-disable-next-line no-underscore-dangle
|
|
6
6
|
window.__DEV_BUILD_INFO__=BUILD_INFO;}/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */const{useServiceWorker}=buildInfo;if(useServiceWorker){const{navigator}=window;if("serviceWorker"in navigator){window.addEventListener("load",()=>{void(async()=>{try{// Note: no matter the "publicPath", we want to serve the service worker
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":[
|
|
1
|
+
{"version":3,"file":"init.js","names":[],"sources":["../../../src/client/init.ts"],"sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global window */\n\nimport { type BuildInfoT, getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nconst buildInfo = getBuildInfo();\n\n// TODO: Should be moved into buildInfo module?\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface Window {\n __DEV_BUILD_INFO__: BuildInfoT | undefined;\n }\n}\n\ndeclare const BUILD_INFO: BuildInfoT | undefined;\n\nif (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('Dev mode: \"BUILD_INFO\" attached to the global \"window\"');\n\n // eslint-disable-next-line no-underscore-dangle\n window.__DEV_BUILD_INFO__ = BUILD_INFO;\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\nconst { useServiceWorker } = buildInfo;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', () => {\n void (async () => {\n try {\n // Note: no matter the \"publicPath\", we want to serve the service worker\n // from the web app root, to allow it control any and all pages of the\n // web app (otherwise, it will be restricted to the scope of its path).\n // The server takes it into account.\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n // eslint-disable-next-line no-console\n console.log('SW registered:', reg);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.log('SW registration failed:', err);\n }\n })();\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA,GAEA,0BAE0B,YAAY,8CAEtC,KAAM,UAAS,CAAG,YAAY,CAAC,CAAC,CAEhC;AAUA,GAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAK,YAAY,CAAE,CACzC;AACA,OAAO,CAAC,IAAI,CAAC,4DAAwD,CAAC,CAEtE;AACA,MAAM,CAAC,kBAAkB,CAAG,UAAU,CACxC,CAEA,yEACA,KAAM,CAAE,gBAAiB,CAAC,CAAG,SAAS,CACtC,GAAI,gBAAgB,CAAE,CACpB,KAAM,CAAE,SAAU,CAAC,CAAG,MAAM,CAC5B,GAAI,eAAe,EAAI,UAAS,CAAE,CAChC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAE,IAAM,CACpC,IAAK,CAAC,SAAY,CAChB,GAAI,CACF;AACA;AACA;AACA;AACA,KAAM,IAAG,CAAG,KAAM,UAAS,CACxB,aAAa,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CACjD;AACA,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAE,GAAG,CAAC,CACpC,CAAE,MAAO,GAAG,CAAE,CACZ;AACA,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAE,GAAG,CAAC,CAC7C,CACF,CAAC,EAAE,CAAC,CACN,CAAC,CAAC,CACJ,CACF","ignoreList":[]}
|
package/build/web/index.js
CHANGED
|
@@ -27,5 +27,5 @@ if (import.meta.webpackHot) {
|
|
|
27
27
|
delete global.REACT_UTILS_LIBRARY_LOADED;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
*/export{GlobalStateProvider,newAsyncDataEnvelope,useAsyncCollection,useAsyncData,useGlobalState,useGlobalStateObject,withGlobalStateType}from"@dr.pogodin/react-global-state";export*from"./shared/components";export{Barrier,Cached,Emitter,Semaphore,THEME_COMPOSE,THEME_PRIORITY,ThemeProvider,assertEmptyObject,getConfig,setClientChunkGroups,splitComponent,time,useSsrContext,useTheme,webpack,withRetries}from"./shared/utils";export*from"./shared/utils/isomorphy";
|
|
30
|
+
*/export{GlobalStateProvider,newAsyncDataEnvelope,useAsyncCollection,useAsyncData,useGlobalState,useGlobalStateObject,withGlobalStateType}from"@dr.pogodin/react-global-state";export*from"./shared/components/index.js";export{Barrier,Cached,Emitter,Semaphore,THEME_COMPOSE,THEME_PRIORITY,ThemeProvider,assertEmptyObject,getConfig,setClientChunkGroups,splitComponent,time,useSsrContext,useTheme,webpack,withRetries}from"./shared/utils/index.js";export*from"./shared/utils/isomorphy/index.js";
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
package/build/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["// 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// It is a safeguard against multiple instances / versions of the library\n// being loaded into environment by mistake (e.g. because of different\n// packages pinning down different exact versions of the lib, thus preventing\n// a proper dedupe and using a single common library version).\n// if (global.REACT_UTILS_LIBRARY_LOADED) {\n// throw Error('React utils library is already loaded');\n// } else global.REACT_UTILS_LIBRARY_LOADED = true;\n\n/*\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions\n interface ImportMeta {\n webpackHot?: {\n dispose(cb: () => void): void;\n };\n }\n}\n\nif (import.meta.webpackHot) {\n import.meta.webpackHot.dispose(() => {\n delete global.REACT_UTILS_LIBRARY_LOADED;\n });\n}\n*/\n\nexport {\n type AsyncCollectionLoaderT,\n type AsyncCollectionT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n GlobalStateProvider,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n useGlobalStateObject,\n withGlobalStateType,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\n\nexport {\n type BeforeRenderResT,\n type BeforeRenderT,\n type ConfigT,\n type ServerSsrContext,\n type ServerT,\n} from './server';\n\nexport {\n Barrier,\n Cached,\n Emitter,\n type Listener,\n type ObjectKey,\n Semaphore,\n THEME_COMPOSE,\n THEME_PRIORITY,\n type Theme,\n ThemeProvider,\n assertEmptyObject,\n getConfig,\n setClientChunkGroups,\n splitComponent,\n time,\n useSsrContext,\n useTheme,\n webpack,\n withRetries,\n} from 'utils';\n\nexport * from 'utils/isomorphy';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAEA,OAME,mBAAmB,CAKnB,oBAAoB,CACpB,kBAAkB,CAClB,YAAY,CACZ,cAAc,CACd,oBAAoB,CACpB,mBAAmB,KACd,gCAAgC,CAAC,iDAatC,OAAO,CACP,MAAM,CACN,OAAO,CAGP,SAAS,CACT,aAAa,CACb,cAAc,CAEd,aAAa,CACb,iBAAiB,CACjB,SAAS,CACT,oBAAoB,CACpB,cAAc,CACd,IAAI,CACJ,aAAa,CACb,QAAQ,CACR,OAAO,CACP,WAAW","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","names":[
|
|
1
|
+
{"version":3,"file":"Cache.js","names":[],"sources":["../../../src/server/Cache.ts"],"sourcesContent":["type CachedItemT<DatumT> = {\n data: DatumT;\n size: number;\n timestamp: number;\n};\n\n/**\n * Implements the static cache.\n */\nexport default class Cache<DatumT> {\n private items: Record<string, CachedItemT<DatumT>> = {};\n\n private size = 0;\n\n constructor(private maxSize: number) { }\n\n /**\n * Cache lookup.\n * @param key Item key to look for.\n * @param [maxage=Number.MAX_VALUE] Optional. The maximum age of\n * cached item to serve. Default to infinite.\n * @returns Cached item, or null if the item is absent in cache,\n * or stale.\n */\n get({\n key,\n maxage = Number.MAX_VALUE,\n }: {\n key: string;\n maxage?: number;\n }): DatumT | null {\n const item = this.items[key];\n return item && Date.now() - item.timestamp < maxage ? item.data : null;\n }\n\n /**\n * Adds item to cache.\n * @param data Item to add.\n * @param key Key to store the item at.\n * @param size Byte size of the item.\n */\n add(data: DatumT, key: string, size: number): void {\n const cached = this.items[key];\n if (cached) this.size -= cached.size;\n\n this.items[key] = { data, size, timestamp: Date.now() };\n this.size += size;\n\n if (this.size > this.maxSize) {\n const entries = Object.entries(this.items);\n entries.sort((a, b) => a[1].timestamp - b[1].timestamp);\n\n for (const entry of entries) {\n const [itemKey, item] = entry;\n delete this.items[itemKey];\n this.size -= item.size;\n if (this.size < this.maxSize / 2) break;\n }\n }\n }\n}\n"],"mappings":"AAMA;AACA;AACA,GACA,cAAe,MAAM,MAAc,CACzB,KAAK,CAAwC,CAAC,CAAC,CAE/C,IAAI,CAAG,CAAC,CAEhB,WAAW,CAAS,OAAe,CAAE,MAAjB,OAAe,CAAf,OAAmB,CAEvC;AACF;AACA;AACA;AACA;AACA;AACA;AACA,KACE,GAAG,CAAC,CACF,GAAG,CACH,MAAM,CAAG,MAAM,CAAC,SAIlB,CAAC,CAAiB,CAChB,KAAM,KAAI,CAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAC5B,MAAO,KAAI,EAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAG,IAAI,CAAC,SAAS,CAAG,MAAM,CAAG,IAAI,CAAC,IAAI,CAAG,IAAI,CACxE,CAEA;AACF;AACA;AACA;AACA;AACA,KACE,GAAG,CAAC,IAAY,CAAE,GAAW,CAAE,IAAY,CAAQ,CACjD,KAAM,OAAM,CAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAC9B,GAAI,MAAM,CAAE,IAAI,CAAC,IAAI,EAAI,MAAM,CAAC,IAAI,CAEpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAG,CAAE,IAAI,CAAE,IAAI,CAAE,SAAS,CAAE,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,CACvD,IAAI,CAAC,IAAI,EAAI,IAAI,CAEjB,GAAI,IAAI,CAAC,IAAI,CAAG,IAAI,CAAC,OAAO,CAAE,CAC5B,KAAM,QAAO,CAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,GAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAEvD,IAAK,KAAM,MAAK,GAAI,QAAO,CAAE,CAC3B,KAAM,CAAC,OAAO,CAAE,IAAI,CAAC,CAAG,KAAK,CAC7B,MAAO,KAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAC1B,IAAI,CAAC,IAAI,EAAI,IAAI,CAAC,IAAI,CACtB,GAAI,IAAI,CAAC,IAAI,CAAG,IAAI,CAAC,OAAO,CAAG,CAAC,CAAE,MACpC,CACF,CACF,CACF","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import"source-map-support/register.js";import http from"node:http";import https from"node:https";import{cloneDeep,defaults}from"lodash-es";// Polyfill required by ReactJS.
|
|
3
3
|
// TODO: Double-check, if it is still required by React v19?
|
|
4
4
|
// eslint-disable-next-line import/no-unassigned-import
|
|
5
|
-
import"raf/polyfill.js";import{SCRIPT_LOCATIONS,newDefaultLogger}from"./renderer";import serverFactory,{getDefaultCspSettings}from"./server";export*from"./utils";export{SCRIPT_LOCATIONS,getDefaultCspSettings};/**
|
|
5
|
+
import"raf/polyfill.js";import{SCRIPT_LOCATIONS,newDefaultLogger}from"./renderer.js";import serverFactory,{getDefaultCspSettings}from"./server.js";export*from"./utils/index.js";export{SCRIPT_LOCATIONS,getDefaultCspSettings};/**
|
|
6
6
|
* Normalizes a port into a number, string, or false.
|
|
7
7
|
* TODO: Drop this function?
|
|
8
8
|
* @param value Port name or number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["http","https","cloneDeep","defaults","SCRIPT_LOCATIONS","newDefaultLogger","serverFactory","getDefaultCspSettings","normalizePort","value","port","parseInt","Number","isFinite","launchServer","webpackConfig","options","ops","process","env","PORT","httpsRedirect","logger","defaultLogLevel","defaultLoggerLogLevel","expressServer","httpServer","createServer","cert","key","on","error","syscall","bind","code","exit","undefined","addr","address","info","NODE_ENV","listen"],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register.js';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport { cloneDeep, defaults } from 'lodash-es';\n\n// Polyfill required by ReactJS.\n// TODO: Double-check, if it is still required by React v19?\n// eslint-disable-next-line import/no-unassigned-import\nimport 'raf/polyfill.js';\n\nimport type { Configuration } from 'webpack';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nexport * from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport {\n SCRIPT_LOCATIONS,\n type ServerT,\n getDefaultCspSettings,\n};\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @param value Port name or number.\n * @return Port number (Number), name (String).\n */\nfunction normalizePort(value: number | string) {\n const port = typeof value === 'string' ? parseInt(value) : value;\n if (Number.isFinite(port)) return port; /* port number */\n return value; /* named pipe */\n}\n\ntype OptionsT = ServerOptionsT & {\n https?: {\n cert: string;\n key: string;\n };\n\n // TODO: Should we limit it to number | string, and throw if it is different value?\n port?: false | number | string;\n};\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return Resolves to an object with created Express and HTTP servers.\n */\nexport async function launchServer(\n webpackConfig: Configuration,\n options: OptionsT = {},\n): Promise<{\n expressServer: ServerT;\n httpServer: http.Server;\n}> {\n /* Options normalization. */\n const ops = cloneDeep(options);\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n // TODO: Need a separate type for normalized options, which guarantees\n // the logger is set!\n ops.logger ??= newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer: http.Server;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer as unknown as () => void);\n } else httpServer = http.createServer(expressServer as unknown as () => void);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error: Error) => {\n if ((error as { syscall?: string }).syscall !== 'listen') throw error;\n const bind = typeof ops.port === 'string' ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch ((error as { code?: string }).code) {\n case 'EACCES':\n ops.logger!.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger!.error(`${bind} is already in use`);\n return process.exit(1);\n case undefined:\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address()!;\n const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger!.info(`Server listening on ${bind} in ${\n process.env.NODE_ENV} mode`);\n });\n\n httpServer.listen(ops.port);\n\n return {\n expressServer,\n httpServer,\n };\n}\n"],"mappings":"AAAA;AACA,MAAO,gCAAgC,CAEvC,MAAO,CAAAA,IAAI,KAAM,WAAW,CAC5B,MAAO,CAAAC,KAAK,KAAM,YAAY,CAE9B,OAASC,SAAS,CAAEC,QAAQ,KAAQ,WAAW,CAE/C;AACA;AACA;AACA,MAAO,iBAAiB,CAIxB,OAASC,gBAAgB,CAAEC,gBAAgB,kBAE3C,MAAO,CAAAC,aAAa,EAGlBC,qBAAqB,gBAGvB,qBASA,OACEH,gBAAgB,CAEhBG,qBAAqB,EAGvB;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,CAAAC,aAAaA,CAACC,KAAsB,CAAE,CAC7C,KAAM,CAAAC,IAAI,CAAG,MAAO,CAAAD,KAAK,GAAK,QAAQ,CAAGE,QAAQ,CAACF,KAAK,CAAC,CAAGA,KAAK,CAChE,GAAIG,MAAM,CAACC,QAAQ,CAACH,IAAI,CAAC,CAAE,MAAO,CAAAA,IAAI,CAAE,iBACxC,MAAO,CAAAD,KAAK,CAAE,gBAChB,CAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,CAAAK,YAAYA,CAChCC,aAA4B,CAC5BC,OAAiB,CAAG,CAAC,CAAC,CAIrB,CACD,4BACA,KAAM,CAAAC,GAAG,CAAGf,SAAS,CAACc,OAAO,CAAC,CAE9B;AACAC,GAAG,CAACP,IAAI,CAAGF,aAAa,CAACS,GAAG,CAACP,IAAI,EAAIQ,OAAO,CAACC,GAAG,CAACC,IAAI,EAAI,IAAI,CAAC,CAC9DjB,QAAQ,CAACc,GAAG,CAAE,CAAEI,aAAa,CAAE,IAAK,CAAC,CAAC,CAEtC;AACA;AACAJ,GAAG,CAACK,MAAM,GAAKjB,gBAAgB,CAAC,CAC9BkB,eAAe,CAAEN,GAAG,CAACO,qBACvB,CAAC,CAAC,CAEF,kDACA,KAAM,CAAAC,aAAa,CAAG,KAAM,CAAAnB,aAAa,CAACS,aAAa,CAAEE,GAAG,CAAC,CAE7D,GAAI,CAAAS,UAAuB,CAC3B,GAAIT,GAAG,CAAChB,KAAK,CAAE,CACbyB,UAAU,CAAGzB,KAAK,CAAC0B,YAAY,CAAC,CAC9BC,IAAI,CAAEX,GAAG,CAAChB,KAAK,CAAC2B,IAAI,CACpBC,GAAG,CAAEZ,GAAG,CAAChB,KAAK,CAAC4B,GACjB,CAAC,CAAEJ,aAAsC,CAAC,CAC5C,CAAC,IAAM,CAAAC,UAAU,CAAG1B,IAAI,CAAC2B,YAAY,CAACF,aAAsC,CAAC,CAE7E,4CACAC,UAAU,CAACI,EAAE,CAAC,OAAO,CAAGC,KAAY,EAAK,CACvC,GAAKA,KAAK,CAA0BC,OAAO,GAAK,QAAQ,CAAE,KAAM,CAAAD,KAAK,CACrE,KAAM,CAAAE,IAAI,CAAG,MAAO,CAAAhB,GAAG,CAACP,IAAI,GAAK,QAAQ,CAAG,QAAQO,GAAG,CAACP,IAAI,EAAE,CAAG,QAAQO,GAAG,CAACP,IAAI,EAAE,CAEnF,6DACA,OAASqB,KAAK,CAAuBG,IAAI,EACvC,IAAK,QAAQ,CACXjB,GAAG,CAACK,MAAM,CAAES,KAAK,CAAC,GAAGE,IAAI,+BAA+B,CAAC,CACzD,MAAO,CAAAf,OAAO,CAACiB,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,YAAY,CACflB,GAAG,CAACK,MAAM,CAAES,KAAK,CAAC,GAAGE,IAAI,oBAAoB,CAAC,CAC9C,MAAO,CAAAf,OAAO,CAACiB,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,CAAAC,SAAS,CACd,QACE,KAAM,CAAAL,KAAK,CACf,CACF,CAAC,CAAC,CAEF,iDACAL,UAAU,CAACI,EAAE,CAAC,WAAW,CAAE,IAAM,CAC/B,KAAM,CAAAO,IAAI,CAAGX,UAAU,CAACY,OAAO,CAAC,CAAE,CAClC,KAAM,CAAAL,IAAI,CAAG,MAAO,CAAAI,IAAI,GAAK,QAAQ,CAAG,QAAQA,IAAI,EAAE,CAAG,QAAQA,IAAI,CAAC3B,IAAI,EAAE,CAC5EO,GAAG,CAACK,MAAM,CAAEiB,IAAI,CAAC,uBAAuBN,IAAI,OAC1Cf,OAAO,CAACC,GAAG,CAACqB,QAAQ,OAAO,CAAC,CAChC,CAAC,CAAC,CAEFd,UAAU,CAACe,MAAM,CAACxB,GAAG,CAACP,IAAI,CAAC,CAE3B,MAAO,CACLe,aAAa,CACbC,UACF,CAAC,CACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register.js';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport { cloneDeep, defaults } from 'lodash-es';\n\n// Polyfill required by ReactJS.\n// TODO: Double-check, if it is still required by React v19?\n// eslint-disable-next-line import/no-unassigned-import\nimport 'raf/polyfill.js';\n\nimport type { Configuration } from 'webpack';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nexport * from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport {\n SCRIPT_LOCATIONS,\n type ServerT,\n getDefaultCspSettings,\n};\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @param value Port name or number.\n * @return Port number (Number), name (String).\n */\nfunction normalizePort(value: number | string) {\n const port = typeof value === 'string' ? parseInt(value) : value;\n if (Number.isFinite(port)) return port; /* port number */\n return value; /* named pipe */\n}\n\ntype OptionsT = ServerOptionsT & {\n https?: {\n cert: string;\n key: string;\n };\n\n // TODO: Should we limit it to number | string, and throw if it is different value?\n port?: false | number | string;\n};\n\n/**\n * Creates and launches web-server for ReactJS application. Allows zero\n * or detailed configuration, supports server-side rendering,\n * and development tools, including Hot Module Reloading (HMR).\n *\n * NOTE: Many of options defined below are passed down to the server and\n * renderer factories, and their declared default values are set in those\n * factories, rather than here.\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel='info'] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return Resolves to an object with created Express and HTTP servers.\n */\nexport async function launchServer(\n webpackConfig: Configuration,\n options: OptionsT = {},\n): Promise<{\n expressServer: ServerT;\n httpServer: http.Server;\n}> {\n /* Options normalization. */\n const ops = cloneDeep(options);\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n defaults(ops, { httpsRedirect: true });\n\n // TODO: Need a separate type for normalized options, which guarantees\n // the logger is set!\n ops.logger ??= newDefaultLogger({\n defaultLogLevel: ops.defaultLoggerLogLevel,\n });\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer: http.Server;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer as unknown as () => void);\n } else httpServer = http.createServer(expressServer as unknown as () => void);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error: Error) => {\n if ((error as { syscall?: string }).syscall !== 'listen') throw error;\n const bind = typeof ops.port === 'string' ? `Pipe ${ops.port}` : `Port ${ops.port}`;\n\n /* Human-readable message for some specific listen errors. */\n switch ((error as { code?: string }).code) {\n case 'EACCES':\n ops.logger!.error(`${bind} requires elevated privileges`);\n return process.exit(1);\n case 'EADDRINUSE':\n ops.logger!.error(`${bind} is already in use`);\n return process.exit(1);\n case undefined:\n default:\n throw error;\n }\n });\n\n /* Listening event handler for HTTP(S) server. */\n httpServer.on('listening', () => {\n const addr = httpServer.address()!;\n const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;\n ops.logger!.info(`Server listening on ${bind} in ${\n process.env.NODE_ENV} mode`);\n });\n\n httpServer.listen(ops.port);\n\n return {\n expressServer,\n httpServer,\n };\n}\n"],"mappings":"AAAA;AACA,MAAO,gCAAgC,CAEvC,MAAO,KAAI,KAAM,WAAW,CAC5B,MAAO,MAAK,KAAM,YAAY,CAE9B,OAAS,SAAS,CAAE,QAAQ,KAAQ,WAAW,CAE/C;AACA;AACA;AACA,MAAO,iBAAiB,CAAC,OAIhB,gBAAgB,CAAE,gBAAgB,2BAEpC,cAAa,EAGlB,qBAAqB,iDAYvB,OACE,gBAAgB,CAEhB,qBAAqB,EAGvB;AACA;AACA;AACA;AACA;AACA,GACA,QAAS,cAAa,CAAC,KAAsB,CAAE,CAC7C,KAAM,KAAI,CAAG,MAAO,MAAK,GAAK,QAAQ,CAAG,QAAQ,CAAC,KAAK,CAAC,CAAG,KAAK,CAChE,GAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAE,MAAO,KAAI,CAAE,iBACxC,MAAO,MAAK,CAAE,gBAChB,CAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAO,eAAe,aAAY,CAChC,aAA4B,CAC5B,OAAiB,CAAG,CAAC,CAAC,CAIrB,CACD,4BACA,KAAM,IAAG,CAAG,SAAS,CAAC,OAAO,CAAC,CAE9B;AACA,GAAG,CAAC,IAAI,CAAG,aAAa,CAAC,GAAG,CAAC,IAAI,EAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAI,IAAI,CAAC,CAC9D,QAAQ,CAAC,GAAG,CAAE,CAAE,aAAa,CAAE,IAAK,CAAC,CAAC,CAEtC;AACA;AACA,GAAG,CAAC,MAAM,GAAK,gBAAgB,CAAC,CAC9B,eAAe,CAAE,GAAG,CAAC,qBACvB,CAAC,CAAC,CAEF,kDACA,KAAM,cAAa,CAAG,KAAM,cAAa,CAAC,aAAa,CAAE,GAAG,CAAC,CAE7D,GAAI,WAAuB,CAC3B,GAAI,GAAG,CAAC,KAAK,CAAE,CACb,UAAU,CAAG,KAAK,CAAC,YAAY,CAAC,CAC9B,IAAI,CAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CACpB,GAAG,CAAE,GAAG,CAAC,KAAK,CAAC,GACjB,CAAC,CAAE,aAAsC,CAAC,CAC5C,CAAC,IAAM,WAAU,CAAG,IAAI,CAAC,YAAY,CAAC,aAAsC,CAAC,CAE7E,4CACA,UAAU,CAAC,EAAE,CAAC,OAAO,CAAG,KAAY,EAAK,CACvC,GAAK,KAAK,CAA0B,OAAO,GAAK,QAAQ,CAAE,KAAM,MAAK,CACrE,KAAM,KAAI,CAAG,MAAO,IAAG,CAAC,IAAI,GAAK,QAAQ,CAAG,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAG,QAAQ,GAAG,CAAC,IAAI,EAAE,CAEnF,6DACA,OAAS,KAAK,CAAuB,IAAI,EACvC,IAAK,QAAQ,CACX,GAAG,CAAC,MAAM,CAAE,KAAK,CAAC,GAAG,IAAI,+BAA+B,CAAC,CACzD,MAAO,QAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,YAAY,CACf,GAAG,CAAC,MAAM,CAAE,KAAK,CAAC,GAAG,IAAI,oBAAoB,CAAC,CAC9C,MAAO,QAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CACxB,IAAK,UAAS,CACd,QACE,KAAM,MAAK,CACf,CACF,CAAC,CAAC,CAEF,iDACA,UAAU,CAAC,EAAE,CAAC,WAAW,CAAE,IAAM,CAC/B,KAAM,KAAI,CAAG,UAAU,CAAC,OAAO,CAAC,CAAE,CAClC,KAAM,KAAI,CAAG,MAAO,KAAI,GAAK,QAAQ,CAAG,QAAQ,IAAI,EAAE,CAAG,QAAQ,IAAI,CAAC,IAAI,EAAE,CAC5E,GAAG,CAAC,MAAM,CAAE,IAAI,CAAC,uBAAuB,IAAI,OAC1C,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,CAAC,CAChC,CAAC,CAAC,CAEF,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAE3B,MAAO,CACL,aAAa,CACb,UACF,CAAC,CACH","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import"core-js
|
|
1
|
+
import _JSON$parse from"core-js-pure/stable/json/parse.js";import _JSON$stringify from"core-js-pure/stable/json/stringify.js";/**
|
|
2
2
|
* ExpressJS middleware for server-side rendering of a ReactJS app.
|
|
3
|
-
*/import{Buffer}from"node:buffer";import{createCipheriv,randomBytes}from"node:crypto";import fs from"node:fs";import path from"node:path";import{Writable}from"node:stream";import{brotliCompress,brotliDecompress}from"node:zlib";import config from"config";import{cloneDeep,defaults,get,mapValues}from"lodash-es";import{prerenderToNodeStream}from"react-dom/static";import{StaticRouter}from"react-router";import serializeJs from"serialize-javascript";import winston from"winston";import{timer}from"@dr.pogodin/js-utils";import{GlobalStateProvider,SsrContext}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import{setBuildInfo}from"../shared/utils/isomorphy/buildInfo";import Cache from"./Cache";// @ts-expect-error "Property 'SECRET' does not exist on type 'IConfig'."
|
|
3
|
+
*/import{Buffer}from"node:buffer";import{createCipheriv,randomBytes}from"node:crypto";import fs from"node:fs";import path from"node:path";import{Writable}from"node:stream";import{brotliCompress,brotliDecompress}from"node:zlib";import config from"config";import{cloneDeep,defaults,get,mapValues}from"lodash-es";import{prerenderToNodeStream}from"react-dom/static";import{StaticRouter}from"react-router";import serializeJs from"serialize-javascript";import winston from"winston";import{timer}from"@dr.pogodin/js-utils";import{GlobalStateProvider,SsrContext}from"@dr.pogodin/react-global-state";import{HelmetProvider}from"@dr.pogodin/react-helmet";import{setBuildInfo}from"../shared/utils/isomorphy/buildInfo.js";import Cache from"./Cache.js";// @ts-expect-error "Property 'SECRET' does not exist on type 'IConfig'."
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
5
|
import{jsx as _jsx}from"react/jsx-runtime";const{SECRET,...publicConfig}=config.util.toObject(config);// Note: These type definitions for logger are copied from Winston logger,
|
|
6
6
|
// then simplified to make it easier to fit an alternative logger into this
|
|
@@ -8,7 +8,7 @@ import{jsx as _jsx}from"react/jsx-runtime";const{SECRET,...publicConfig}=config.
|
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
11
|
-
export let SCRIPT_LOCATIONS=/*#__PURE__*/function(SCRIPT_LOCATIONS){SCRIPT_LOCATIONS["BODY_OPEN"]="BODY_OPEN";SCRIPT_LOCATIONS["DEFAULT"]="DEFAULT";SCRIPT_LOCATIONS["HEAD_OPEN"]="HEAD_OPEN";return SCRIPT_LOCATIONS}({});export class ServerSsrContext extends SsrContext{chunks=[];status=200;constructor(req,chunkGroups,initialState){super(cloneDeep(initialState)??{});this.chunkGroups=chunkGroups;this.req=req;}}/**
|
|
11
|
+
export let SCRIPT_LOCATIONS=/*#__PURE__*/function(SCRIPT_LOCATIONS){SCRIPT_LOCATIONS["BODY_OPEN"]="BODY_OPEN";SCRIPT_LOCATIONS["DEFAULT"]="DEFAULT";SCRIPT_LOCATIONS["HEAD_OPEN"]="HEAD_OPEN";return SCRIPT_LOCATIONS}({});export class ServerSsrContext extends SsrContext{chunkGroups;chunks=[];redirectTo;req;status=200;constructor(req,chunkGroups,initialState){super(cloneDeep(initialState)??{});this.chunkGroups=chunkGroups;this.req=req;}}/**
|
|
12
12
|
* Reads build-time information about the app. This information is generated
|
|
13
13
|
* by our standard Webpack config for apps, and it is written into
|
|
14
14
|
* ".build-info" file in the context folder specified in Webpack config.
|
|
@@ -16,14 +16,14 @@ export let SCRIPT_LOCATIONS=/*#__PURE__*/function(SCRIPT_LOCATIONS){SCRIPT_LOCAT
|
|
|
16
16
|
* suitable for cryptographical use.
|
|
17
17
|
* @param context Webpack context path used during the build.
|
|
18
18
|
* @return Resolves to the build-time information.
|
|
19
|
-
*/function getBuildInfo(context){const url=path.resolve(context,".build-info");return
|
|
19
|
+
*/function getBuildInfo(context){const url=path.resolve(context,".build-info");return _JSON$parse(fs.readFileSync(url,"utf8"));}/**
|
|
20
20
|
* Attempts to read from disk the named chunk groups mapping generated
|
|
21
21
|
* by Webpack during the compilation.
|
|
22
22
|
* It will not work for development builds, where these stats should be captured
|
|
23
23
|
* via compilator callback.
|
|
24
24
|
* @param buildDir
|
|
25
25
|
* @return
|
|
26
|
-
*/function readChunkGroupsJson(buildDir){const url=path.resolve(buildDir,"__chunk_groups__.json");let res;try{res=
|
|
26
|
+
*/function readChunkGroupsJson(buildDir){const url=path.resolve(buildDir,"__chunk_groups__.json");let res;try{res=_JSON$parse(fs.readFileSync(url,"utf8"));}catch{// TODO: Should we message the error here somehow?
|
|
27
27
|
res=null;}return res;}/**
|
|
28
28
|
* Prepares a new Cipher for data encryption.
|
|
29
29
|
* @param key Encryption key (32-bit random, Base64-encoded key is expected).
|
|
@@ -52,7 +52,7 @@ res=null;}return res;}/**
|
|
|
52
52
|
* @param {object} [options={}]
|
|
53
53
|
* @param {string} [options.defaultLogLevel='info']
|
|
54
54
|
* @return {object}
|
|
55
|
-
*/export function newDefaultLogger({defaultLogLevel="info"}={}){const{format,transports}=winston;return winston.createLogger({format:format.combine(format.splat(),format.timestamp(),format.colorize(),format.printf(({level,message,stack,timestamp,...rest})=>{let res=`${level}\t(at ${timestamp}):\t${message}`;if(Object.keys(rest).length){res+=`\n${
|
|
55
|
+
*/export function newDefaultLogger({defaultLogLevel="info"}={}){const{format,transports}=winston;return winston.createLogger({format:format.combine(format.splat(),format.timestamp(),format.colorize(),format.printf(({level,message,stack,timestamp,...rest})=>{let res=`${level}\t(at ${timestamp}):\t${message}`;if(Object.keys(rest).length){res+=`\n${_JSON$stringify(rest,null,2)}`;}if(stack)res+=`\n${stack}`;return res;})),level:defaultLogLevel,transports:[new transports.Console]});}/**
|
|
56
56
|
* Deduces the map of code chunk groups from the Webpack compilation Stats.
|
|
57
57
|
*/export function deduceChunkGroups(stats){return mapValues(stats.toJson({all:false,chunkGroups:true}).namedChunkGroups,item=>item.assets?.map(({name})=>name)??[]);}/**
|
|
58
58
|
* Creates the middleware.
|