@dr.pogodin/react-utils 1.49.1 → 1.50.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/babel.scripts.config.js +19 -0
- package/bin/build.js +274 -164
- package/build/development/client/getInj.js +18 -29
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +11 -14
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +9 -17
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +26 -4
- package/build/development/index.js.map +1 -1
- package/build/development/server/Cache.js +15 -20
- package/build/development/server/Cache.js.map +1 -1
- package/build/development/server/index.js +142 -160
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +150 -197
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +63 -86
- package/build/development/server/server.js.map +1 -1
- package/build/development/server/utils/errors.js +72 -87
- package/build/development/server/utils/errors.js.map +1 -1
- package/build/development/shared/components/Button/index.js +8 -17
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +4 -4
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +54 -58
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +16 -24
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Link.js +2 -5
- package/build/development/shared/components/Link.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +28 -41
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +2 -3
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +19 -20
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +12 -28
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +11 -12
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +21 -28
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +21 -25
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +1 -3
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
- package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +4 -4
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js +2 -5
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/utils/config.js +11 -15
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/globalState.js +1 -7
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/index.js +2 -2
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
- package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
- package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/development/shared/utils/isomorphy/index.js +17 -23
- package/build/development/shared/utils/isomorphy/index.js.map +1 -1
- package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
- package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/development/shared/utils/jest/index.js +48 -72
- package/build/development/shared/utils/jest/index.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +67 -74
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +25 -28
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/shared/utils/webpack.js +22 -29
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +26 -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.map +1 -1
- package/build/production/server/server.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 +2 -2
- 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/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.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/jest/index.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +20 -3
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
- package/build/web/client/getInj.js +10 -70
- package/build/web/client/getInj.js.map +1 -1
- package/build/web/client/index.js +2 -27
- package/build/web/client/index.js.map +1 -1
- package/build/web/client/init.js +10 -44
- package/build/web/client/init.js.map +1 -1
- package/build/web/index.js +26 -6
- package/build/web/index.js.map +1 -1
- package/build/web/server/Cache.js +3 -41
- package/build/web/server/Cache.js.map +1 -1
- package/build/web/server/index.js +7 -78
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/renderer.js +61 -420
- package/build/web/server/renderer.js.map +1 -1
- package/build/web/server/server.js +38 -212
- package/build/web/server/server.js.map +1 -1
- package/build/web/server/utils/errors.js +9 -48
- package/build/web/server/utils/errors.js.map +1 -1
- package/build/web/server/utils/index.js +1 -2
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +12 -101
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -40
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/theme.scss +1 -0
- package/build/web/shared/components/GenericLink/index.js +12 -65
- package/build/web/shared/components/GenericLink/index.js.map +1 -1
- package/build/web/shared/components/GenericLink/style.scss +1 -0
- package/build/web/shared/components/Input/index.js +11 -69
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Link.js +2 -12
- package/build/web/shared/components/Link.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +10 -130
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/NavLink.js +2 -10
- package/build/web/shared/components/NavLink.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +2 -27
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +21 -106
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +2 -24
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
- package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +12 -104
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +5 -43
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/index.js +1 -15
- package/build/web/shared/components/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
- package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -49
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/web/shared/components/selectors/common.js +1 -10
- package/build/web/shared/components/selectors/common.js.map +1 -1
- package/build/web/shared/components/selectors/index.js +1 -3
- package/build/web/shared/components/selectors/index.js.map +1 -1
- package/build/web/shared/utils/config.js +6 -40
- package/build/web/shared/utils/config.js.map +1 -1
- package/build/web/shared/utils/globalState.js +2 -11
- package/build/web/shared/utils/globalState.js.map +1 -1
- package/build/web/shared/utils/index.js +1 -9
- package/build/web/shared/utils/index.js.map +1 -1
- package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
- package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
- package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
- package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
- package/build/web/shared/utils/isomorphy/index.js +5 -27
- package/build/web/shared/utils/isomorphy/index.js.map +1 -1
- package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
- package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
- package/build/web/shared/utils/jest/global.js +1 -3
- package/build/web/shared/utils/jest/global.js.map +1 -1
- package/build/web/shared/utils/jest/index.js +27 -146
- package/build/web/shared/utils/jest/index.js.map +1 -1
- package/build/web/shared/utils/splitComponent.js +34 -197
- package/build/web/shared/utils/splitComponent.js.map +1 -1
- package/build/web/shared/utils/time.js +5 -69
- package/build/web/shared/utils/time.js.map +1 -1
- package/build/web/shared/utils/webpack.js +6 -53
- package/build/web/shared/utils/webpack.js.map +1 -1
- package/config/babel/webpack.js +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +5 -8
- package/config/webpack/lib-base.d.ts +0 -22
- package/config/webpack/lib-base.js +0 -167
- package/config/webpack/lib-development.d.ts +0 -5
- package/config/webpack/lib-development.js +0 -35
- package/config/webpack/lib-production.d.ts +0 -5
- package/config/webpack/lib-production.js +0 -42
- package/webpack.config.ts +0 -49
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// Initialization of client-side code.
|
|
2
|
-
/* global document */
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
|
|
7
|
-
import { HelmetProvider } from '@dr.pogodin/react-helmet';
|
|
2
|
+
/* global document */import { createRoot, hydrateRoot } from "react-dom/client";
|
|
3
|
+
import { BrowserRouter } from "react-router";
|
|
4
|
+
import { GlobalStateProvider } from "@dr.pogodin/react-global-state";
|
|
5
|
+
import { HelmetProvider } from "@dr.pogodin/react-helmet";
|
|
8
6
|
import getInj from "./getInj.js";
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime"; /**
|
|
8
|
+
* Prepares and launches the app at client side.
|
|
9
|
+
* @param Application Root application component
|
|
10
|
+
* @param [options={}] Optional. Additional settings.
|
|
11
|
+
*/
|
|
15
12
|
export async function launchClient(Application, options = {}) {
|
|
16
13
|
const inj = await getInj();
|
|
17
|
-
const container = document.getElementById(
|
|
18
|
-
if (!container) throw Error(
|
|
14
|
+
const container = document.getElementById("react-view");
|
|
15
|
+
if (!container) throw Error("Failed to find container for React app");
|
|
19
16
|
const scene = /*#__PURE__*/_jsx(GlobalStateProvider, {
|
|
20
17
|
initialState: inj.ISTATE ?? options.initialState,
|
|
21
18
|
children: /*#__PURE__*/_jsx(BrowserRouter, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","getInj","jsx","_jsx","launchClient","Application","options","inj","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"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 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 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
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRoot","hydrateRoot","BrowserRouter","GlobalStateProvider","HelmetProvider","getInj","jsx","_jsx","launchClient","Application","options","inj","container","document","getElementById","Error","scene","initialState","ISTATE","children","dontHydrate","root","render"],"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 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 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,SAASA,UAAU,EAAEC,WAAW,QAAQ,kBAAkB;AAC1D,SAASC,aAAa,QAAQ,cAAc;AAE5C,SAASC,mBAAmB,QAAQ,gCAAgC;AACpE,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,OAAOC,MAAM;AAAiB,SAAAC,GAAA,IAAAC,IAAA,4BAO9B;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAChCC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EACP;EACf,MAAMC,GAAG,GAAG,MAAMN,MAAM,CAAC,CAAC;EAE1B,MAAMO,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACTT,IAAA,CAACJ,mBAAmB;IAACc,YAAY,EAAEN,GAAG,CAACO,MAAM,IAAIR,OAAO,CAACO,YAAa;IAAAE,QAAA,eACpEZ,IAAA,CAACL,aAAa;MAAAiB,QAAA,eACZZ,IAAA,CAACH,cAAc;QAAAe,QAAA,eACbZ,IAAA,CAACE,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACU,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAGrB,UAAU,CAACY,SAAS,CAAC;IAClCS,IAAI,CAACC,MAAM,CAACN,KAAK,CAAC;EACpB,CAAC,MAAMf,WAAW,CAACW,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
|
|
@@ -3,19 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/* global window */
|
|
5
5
|
import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
|
|
6
|
-
const buildInfo = getBuildInfo();
|
|
7
|
-
|
|
8
|
-
// TODO: Should be moved into buildInfo module?
|
|
9
|
-
|
|
10
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
6
|
+
const buildInfo = getBuildInfo(); // TODO: Should be moved into buildInfo module?
|
|
7
|
+
if (process.env.NODE_ENV !== "production") {
|
|
11
8
|
// eslint-disable-next-line no-console
|
|
12
|
-
console.warn(
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
9
|
+
console.warn("Dev mode: \"BUILD_INFO\" attached to the global \"window\""); // eslint-disable-next-line no-underscore-dangle
|
|
15
10
|
window.__DEV_BUILD_INFO__ = BUILD_INFO;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */
|
|
11
|
+
} /* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */
|
|
19
12
|
const {
|
|
20
13
|
useServiceWorker
|
|
21
14
|
} = buildInfo;
|
|
@@ -23,20 +16,19 @@ if (useServiceWorker) {
|
|
|
23
16
|
const {
|
|
24
17
|
navigator
|
|
25
18
|
} = window;
|
|
26
|
-
if (
|
|
27
|
-
window.addEventListener(
|
|
19
|
+
if ("serviceWorker" in navigator) {
|
|
20
|
+
window.addEventListener("load", () => {
|
|
28
21
|
void (async () => {
|
|
29
22
|
try {
|
|
30
23
|
// Note: no matter the "publicPath", we want to serve the service worker
|
|
31
24
|
// from the web app root, to allow it control any and all pages of the
|
|
32
25
|
// web app (otherwise, it will be restricted to the scope of its path).
|
|
33
26
|
// The server takes it into account.
|
|
34
|
-
const reg = await navigator.serviceWorker.register(
|
|
35
|
-
|
|
36
|
-
console.log('SW registered:', reg);
|
|
27
|
+
const reg = await navigator.serviceWorker.register("/__service-worker.js"); // eslint-disable-next-line no-console
|
|
28
|
+
console.log("SW registered:", reg);
|
|
37
29
|
} catch (err) {
|
|
38
30
|
// eslint-disable-next-line no-console
|
|
39
|
-
console.log(
|
|
31
|
+
console.log("SW registration failed:", err);
|
|
40
32
|
}
|
|
41
33
|
})();
|
|
42
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":["getBuildInfo","buildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"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;AAEA;AAAA,SAE0BA,YAAY;AAEtC,MAAMC,SAAS,GAAGD,YAAY,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"init.js","names":["getBuildInfo","buildInfo","process","env","NODE_ENV","console","warn","window","__DEV_BUILD_INFO__","BUILD_INFO","useServiceWorker","navigator","addEventListener","reg","serviceWorker","register","log","err"],"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;AAEA;AAAA,SAE0BA,YAAY;AAEtC,MAAMC,SAAS,GAAGD,YAAY,CAAC,CAAC,CAEhC;AAUA,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACzC;EACAC,OAAO,CAACC,IAAI,CAAC,4DAAwD,CAAC,CAEtE;EACAC,MAAM,CAACC,kBAAkB,GAAGC,UAAU;AACxC,CAEA;AACA,MAAM;EAAEC;AAAiB,CAAC,GAAGT,SAAS;AACtC,IAAIS,gBAAgB,EAAE;EACpB,MAAM;IAAEC;EAAU,CAAC,GAAGJ,MAAM;EAC5B,IAAI,eAAe,IAAII,SAAS,EAAE;IAChCJ,MAAM,CAACK,gBAAgB,CAAC,MAAM,EAAE,MAAM;MACpC,KAAK,CAAC,YAAY;QAChB,IAAI;UACF;UACA;UACA;UACA;UACA,MAAMC,GAAG,GAAG,MAAMF,SAAS,CACxBG,aAAa,CAACC,QAAQ,CAAC,sBAAsB,CAAC,CACjD;UACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,EAAEH,GAAG,CAAC;QACpC,CAAE,QAAOI,GAAG,EAAE;UACZ;UACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,EAAEC,GAAG,CAAC;QAC7C;MACF,CAAC,EAAE,CAAC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
+
// TODO: For now I commented out this safeguard check, as I am not sure how
|
|
2
|
+
// to easily make it work: it should not be triggered in HMR mode, but if I
|
|
3
|
+
// add the code relying on import.meta, it fails in Jest environment, because
|
|
4
|
+
// Jest does not support ES modules yet, and import.meta is not support in
|
|
5
|
+
// CommonJS modules, and the "babel-plugin-transform-import-meta" plugin
|
|
6
|
+
// we use to workaround this issue for import.meta.dirname, etc. does not
|
|
7
|
+
// transform import.meta.webpackHot
|
|
1
8
|
// It is a safeguard against multiple instances / versions of the library
|
|
2
9
|
// being loaded into environment by mistake (e.g. because of different
|
|
3
10
|
// packages pinning down different exact versions of the lib, thus preventing
|
|
4
11
|
// a proper dedupe and using a single common library version).
|
|
5
|
-
if (global.REACT_UTILS_LIBRARY_LOADED) {
|
|
6
|
-
throw Error('React utils library is already loaded');
|
|
7
|
-
} else global.REACT_UTILS_LIBRARY_LOADED = true;
|
|
8
|
-
|
|
12
|
+
// if (global.REACT_UTILS_LIBRARY_LOADED) {
|
|
13
|
+
// throw Error('React utils library is already loaded');
|
|
14
|
+
// } else global.REACT_UTILS_LIBRARY_LOADED = true;
|
|
15
|
+
/*
|
|
16
|
+
declare global {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
18
|
+
interface ImportMeta {
|
|
19
|
+
webpackHot?: {
|
|
20
|
+
dispose(cb: () => void): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (import.meta.webpackHot) {
|
|
26
|
+
import.meta.webpackHot.dispose(() => {
|
|
27
|
+
delete global.REACT_UTILS_LIBRARY_LOADED;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
*/export { GlobalStateProvider, getGlobalState, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType } from "@dr.pogodin/react-global-state";
|
|
9
31
|
export * from "./shared/components/index.js";
|
|
10
32
|
export { Barrier, Cached, Emitter, Semaphore, THEME_COMPOSE, THEME_PRIORITY, ThemeProvider, assertEmptyObject, getConfig, getSsrContext, isomorphy, splitComponent, time, useTheme, webpack, withRetries } from "./shared/utils/index.js";
|
|
11
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["GlobalStateProvider","getGlobalState","newAsyncDataEnvelope","useAsyncCollection","useAsyncData","useGlobalState","withGlobalStateType","Barrier","Cached","Emitter","Semaphore","THEME_COMPOSE","THEME_PRIORITY","ThemeProvider","assertEmptyObject","getConfig","getSsrContext","isomorphy","splitComponent","time","useTheme","webpack","withRetries"],"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 getGlobalState,\n newAsyncDataEnvelope,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\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 getSsrContext,\n isomorphy,\n splitComponent,\n time,\n useTheme,\n webpack,\n withRetries,\n} from 'utils';\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,SAMEA,mBAAmB,EAKnBC,cAAc,EACdC,oBAAoB,EACpBC,kBAAkB,EAClBC,YAAY,EACZC,cAAc,EACdC,mBAAmB,QACd,gCAAgC;AAEvC;AAAA,SAWEC,OAAO,EACPC,MAAM,EACNC,OAAO,EAGPC,SAAS,EACTC,aAAa,EACbC,cAAc,EAEdC,aAAa,EACbC,iBAAiB,EACjBC,SAAS,EACTC,aAAa,EACbC,SAAS,EACTC,cAAc,EACdC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,WAAW","ignoreList":[]}
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Implements the static cache.
|
|
3
|
-
*/
|
|
4
|
-
export default class Cache {
|
|
3
|
+
*/export default class Cache {
|
|
5
4
|
items = {};
|
|
6
5
|
size = 0;
|
|
7
6
|
constructor(maxSize) {
|
|
8
7
|
this.maxSize = maxSize;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* or stale.
|
|
18
|
-
*/
|
|
8
|
+
} /**
|
|
9
|
+
* Cache lookup.
|
|
10
|
+
* @param key Item key to look for.
|
|
11
|
+
* @param [maxage=Number.MAX_VALUE] Optional. The maximum age of
|
|
12
|
+
* cached item to serve. Default to infinite.
|
|
13
|
+
* @returns Cached item, or null if the item is absent in cache,
|
|
14
|
+
* or stale.
|
|
15
|
+
*/
|
|
19
16
|
get({
|
|
20
17
|
key,
|
|
21
18
|
maxage = Number.MAX_VALUE
|
|
22
19
|
}) {
|
|
23
20
|
const item = this.items[key];
|
|
24
21
|
return item && Date.now() - item.timestamp < maxage ? item.data : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* @param size Byte size of the item.
|
|
32
|
-
*/
|
|
22
|
+
} /**
|
|
23
|
+
* Adds item to cache.
|
|
24
|
+
* @param data Item to add.
|
|
25
|
+
* @param key Key to store the item at.
|
|
26
|
+
* @param size Byte size of the item.
|
|
27
|
+
*/
|
|
33
28
|
add(data, key, size) {
|
|
34
29
|
const cached = this.items[key];
|
|
35
30
|
if (cached) this.size -= cached.size;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.js","names":["Cache","items","size","constructor","maxSize","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","cached","entries","Object","sort","a","b","entry","itemKey"],"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
|
|
1
|
+
{"version":3,"file":"Cache.js","names":["Cache","items","size","constructor","maxSize","get","key","maxage","Number","MAX_VALUE","item","Date","now","timestamp","data","add","cached","entries","Object","sort","a","b","entry","itemKey"],"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,eAAe,MAAMA,KAAc;EACzBC,KAAK,GAAwC,CAAC,CAAC;EAE/CC,IAAI,GAAG,CAAC;EAEhBC,WAAWA,CAASC,OAAe,EAAE;IAAA,KAAjBA,OAAe,GAAfA,OAAmB;EAAA,CAEvC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,GAAGA,CAAC;IACFC,GAAG;IACHC,MAAM,GAAGC,MAAM,CAACC;EAIlB,CAAC,EAAiB;IAChB,MAAMC,IAAI,GAAG,IAAI,CAACT,KAAK,CAACK,GAAG,CAAC;IAC5B,OAAOI,IAAI,IAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,GAAGF,IAAI,CAACG,SAAS,GAAGN,MAAM,GAAGG,IAAI,CAACI,IAAI,GAAG,IAAI;EACxE,CAEA;AACF;AACA;AACA;AACA;AACA;EACEC,GAAGA,CAACD,IAAY,EAAER,GAAW,EAAEJ,IAAY,EAAQ;IACjD,MAAMc,MAAM,GAAG,IAAI,CAACf,KAAK,CAACK,GAAG,CAAC;IAC9B,IAAIU,MAAM,EAAE,IAAI,CAACd,IAAI,IAAIc,MAAM,CAACd,IAAI;IAEpC,IAAI,CAACD,KAAK,CAACK,GAAG,CAAC,GAAG;MAAEQ,IAAI;MAAEZ,IAAI;MAAEW,SAAS,EAAEF,IAAI,CAACC,GAAG,CAAC;IAAE,CAAC;IACvD,IAAI,CAACV,IAAI,IAAIA,IAAI;IAEjB,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACE,OAAO,EAAE;MAC5B,MAAMa,OAAO,GAAGC,MAAM,CAACD,OAAO,CAAC,IAAI,CAAChB,KAAK,CAAC;MAC1CgB,OAAO,CAACE,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,CAACP,SAAS,GAAGQ,CAAC,CAAC,CAAC,CAAC,CAACR,SAAS,CAAC;MAEvD,KAAK,MAAMS,KAAK,IAAIL,OAAO,EAAE;QAC3B,MAAM,CAACM,OAAO,EAAEb,IAAI,CAAC,GAAGY,KAAK;QAC7B,OAAO,IAAI,CAACrB,KAAK,CAACsB,OAAO,CAAC;QAC1B,IAAI,CAACrB,IAAI,IAAIQ,IAAI,CAACR,IAAI;QACtB,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACE,OAAO,GAAG,CAAC,EAAE;MACpC;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,164 +1,152 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-unassigned-import
|
|
2
|
-
import
|
|
3
|
-
import http from
|
|
4
|
-
import https from
|
|
5
|
-
import { cloneDeep, defaults } from
|
|
6
|
-
|
|
7
|
-
// Polyfill required by ReactJS.
|
|
2
|
+
import "source-map-support/register.js";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
import { cloneDeep, defaults } from "lodash-es"; // Polyfill required by ReactJS.
|
|
8
6
|
// TODO: Double-check, if it is still required by React v19?
|
|
9
7
|
// eslint-disable-next-line import/no-unassigned-import
|
|
10
|
-
import
|
|
8
|
+
import "raf/polyfill.js";
|
|
11
9
|
import { SCRIPT_LOCATIONS, newDefaultLogger } from "./renderer.js";
|
|
12
10
|
import serverFactory, { getDefaultCspSettings } from "./server.js";
|
|
13
11
|
export * from "./utils/index.js";
|
|
14
|
-
export { SCRIPT_LOCATIONS, getDefaultCspSettings };
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @return Port number (Number), name (String).
|
|
21
|
-
*/
|
|
12
|
+
export { SCRIPT_LOCATIONS, getDefaultCspSettings }; /**
|
|
13
|
+
* Normalizes a port into a number, string, or false.
|
|
14
|
+
* TODO: Drop this function?
|
|
15
|
+
* @param value Port name or number.
|
|
16
|
+
* @return Port number (Number), name (String).
|
|
17
|
+
*/
|
|
22
18
|
function normalizePort(value) {
|
|
23
|
-
const port = typeof value ===
|
|
19
|
+
const port = typeof value === "string" ? parseInt(value) : value;
|
|
24
20
|
if (Number.isFinite(port)) return port; /* port number */
|
|
25
21
|
return value; /* named pipe */
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*/
|
|
22
|
+
} /**
|
|
23
|
+
* Creates and launches web-server for ReactJS application. Allows zero
|
|
24
|
+
* or detailed configuration, supports server-side rendering,
|
|
25
|
+
* and development tools, including Hot Module Reloading (HMR).
|
|
26
|
+
*
|
|
27
|
+
* NOTE: Many of options defined below are passed down to the server and
|
|
28
|
+
* renderer factories, and their declared default values are set in those
|
|
29
|
+
* factories, rather than here.
|
|
30
|
+
*
|
|
31
|
+
* @param {object} webpackConfig Webpack configuration used to build
|
|
32
|
+
* the frontend bundle. In production mode the server will read out of it
|
|
33
|
+
* `context`, `publicPath`, and a few other parameters, necessary to locate
|
|
34
|
+
* and serve the app bundle. In development mode the server will use entire
|
|
35
|
+
* provided config to build the app bundle in memory, and further watch and
|
|
36
|
+
* update it via HMR.
|
|
37
|
+
* @param {object} [options] Additional parameters.
|
|
38
|
+
* @param {Component} [options.Application] The root ReactJS component of
|
|
39
|
+
* the app to use for the server-side rendering. When not provided
|
|
40
|
+
* the server-side rendering is disabled.
|
|
41
|
+
* @param {function} [options.beforeExpressJsError] Asynchronous callback
|
|
42
|
+
* (`(server) => Promise<boolean>`) to be executed just before the default error
|
|
43
|
+
* handler is added to ExpressJS server. If the callback is provided and its
|
|
44
|
+
* result resolves to a truthy value, `react-utils` won't attach the default
|
|
45
|
+
* error handler.
|
|
46
|
+
* @param {function} [options.beforeExpressJsSetup] Asynchronous callback
|
|
47
|
+
* (`(server) => Promise) to be executed right after ExpressJS server creation,
|
|
48
|
+
* before any configuration is performed.
|
|
49
|
+
* @param {BeforeRenderHook} [options.beforeRender] The hook to run just before
|
|
50
|
+
* the server-side rendering. For each incoming request, it will be executed
|
|
51
|
+
* just before the HTML markup is generated at the server. It allows to load
|
|
52
|
+
* and provide the data necessary for server-side rendering, and also to inject
|
|
53
|
+
* additional configuration and scripts into the generated HTML code.
|
|
54
|
+
* @param {boolean} [options.noCsp] Set `true` to disable
|
|
55
|
+
* Content-Security-Policy (CSP) headers altogether.
|
|
56
|
+
* @param {function} [options.cspSettingsHook] A hook allowing
|
|
57
|
+
* to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
|
|
58
|
+
* settings for [helmet](https://github.com/helmetjs/helmet)'s
|
|
59
|
+
* `contentSecurityPolicy` middleware on per-request basis.
|
|
60
|
+
*
|
|
61
|
+
* If provided it should be a with signature: \
|
|
62
|
+
* `(defaultSettings: object, req: object)` ⇒ `object` \
|
|
63
|
+
* which gets the default settings (also used without the hook),
|
|
64
|
+
* and the incoming request object. The hook response will be passed
|
|
65
|
+
* as options to the helmet `contentSecurityPolicy` middleware.
|
|
66
|
+
*
|
|
67
|
+
* Currently, the default settings is the following object in production
|
|
68
|
+
* environment:
|
|
69
|
+
* ```js
|
|
70
|
+
* {
|
|
71
|
+
* directives: {
|
|
72
|
+
* defaultSrc: ["'self'"],
|
|
73
|
+
* baseUri: ["'self'"],
|
|
74
|
+
* blockAllMixedContent: [],
|
|
75
|
+
* fontSrc: ["'self'", 'https:', 'data:'],
|
|
76
|
+
* frameAncestors: ["'self'"],
|
|
77
|
+
* frameSrc: ["'self'", 'https://*.youtube.com'],
|
|
78
|
+
* imgSrc: ["'self'", 'data:'],
|
|
79
|
+
* objectSrc: ["'none'"],
|
|
80
|
+
* scriptSrc: ["'self'", "'unsafe-eval'", `'nonce-UNIQUE_NONCE_VALUE'`],
|
|
81
|
+
* scriptSrcAttr: ["'none'"],
|
|
82
|
+
* styleSrc: ["'self'", 'https:', "'unsafe-inline'"],
|
|
83
|
+
* upgradeInsecureRequests: [] // Removed in dev mode.
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
* It matches the default value used by Helmet with a few updates:
|
|
88
|
+
* - YouTube host is whitelisted in the `frameSrc` directive to ensure
|
|
89
|
+
* the {@link YouTubeVideo} component works.
|
|
90
|
+
* - An unique per-request nonce is added to `scriptSrc` directive to
|
|
91
|
+
* whitelist auxiliary scripts injected by react-utils. The actual nonce
|
|
92
|
+
* value can be fetched by host code via `.nonce` field of `req` argument
|
|
93
|
+
* of `.beforeRender` hook.
|
|
94
|
+
* - `upgradeInsecureRequests` directive is removed in development mode,
|
|
95
|
+
* to simplify local testing with http requests.
|
|
96
|
+
* @param {string} [options.defaultLoggerLogLevel='info'] Log level for
|
|
97
|
+
* the default logger, which is created if no `logger` option provided.
|
|
98
|
+
* @param {boolean} [options.devMode] Pass in `true` to start the server in
|
|
99
|
+
* development mode.
|
|
100
|
+
* @param {string} [options.favicon] Path to the favicon to use by the server.
|
|
101
|
+
* By default no favicon is used.
|
|
102
|
+
* @param {object} [options.https] If provided, HTTPS server will be started,
|
|
103
|
+
* instead of HTTP otherwise. The object should provide SSL certificate and key
|
|
104
|
+
* via two string fields: `cert`, and `key`.
|
|
105
|
+
* @param {string} [options.https.cert] SSL Certificate.
|
|
106
|
+
* @param {string} [options.https.key] SSL key.
|
|
107
|
+
* @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable
|
|
108
|
+
* automatic redirection of all incoming HTTP requests to HTTPS.
|
|
109
|
+
*
|
|
110
|
+
* To smoothly use it at `localhost` you need to run the server in HTTPS mode,
|
|
111
|
+
* and also properly create and install a self-signed SSL sertificate on your
|
|
112
|
+
* system. This article is helpful:
|
|
113
|
+
* [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)
|
|
114
|
+
* @param {Logger} [options.logger] The logger to use at server side.
|
|
115
|
+
* By default [`winston`](https://www.npmjs.com/package/winston) logger
|
|
116
|
+
* with console transport is used. The logger you provide, or the default
|
|
117
|
+
* `winston` logger otherwise, will be attached to the created ExpressJS server
|
|
118
|
+
* object.
|
|
119
|
+
* @param {function} [options.onExpressJsSetup] An async callback
|
|
120
|
+
* (`(server) => Promise`) to be triggered when most of the server
|
|
121
|
+
* configuration is completed, just before the server-side renderer,
|
|
122
|
+
* and the default error handler are attached. You can use it to mount
|
|
123
|
+
* custom API routes. The server-side logger can be accessed as `server.logger`.
|
|
124
|
+
* @param {number|string} [options.port=3000] The port to start the server on.
|
|
125
|
+
* @param {number} [options.staticCacheSize=1.e7] The maximum
|
|
126
|
+
* static cache size in bytes. Defaults to ~10 MB.
|
|
127
|
+
* @param {function} [options.staticCacheController] When given, it activates,
|
|
128
|
+
* and controls the static caching of generated HTML markup. When this function
|
|
129
|
+
* is provided, on each incoming request it is triggered with the request
|
|
130
|
+
* passed in as the argument. To attempt to serve the response from the cache
|
|
131
|
+
* it should return the object with the following fields:
|
|
132
|
+
* - `key: string` – the cache key for the response;
|
|
133
|
+
* - `maxage?: number` – the maximum age of cached result in ms.
|
|
134
|
+
* If undefined - infinite age is assumed.
|
|
135
|
+
* @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.
|
|
136
|
+
* @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,
|
|
137
|
+
* defaults to 1 second.
|
|
138
|
+
* @return Resolves to an object with created Express and HTTP servers.
|
|
139
|
+
*/
|
|
145
140
|
export async function launchServer(webpackConfig, options = {}) {
|
|
146
|
-
/* Options normalization. */
|
|
147
|
-
const ops = cloneDeep(options);
|
|
148
|
-
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
141
|
+
/* Options normalization. */const ops = cloneDeep(options); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
150
142
|
ops.port = normalizePort(ops.port || process.env.PORT || 3000);
|
|
151
143
|
defaults(ops, {
|
|
152
144
|
httpsRedirect: true
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// TODO: Need a separate type for normalized options, which guarantees
|
|
145
|
+
}); // TODO: Need a separate type for normalized options, which guarantees
|
|
156
146
|
// the logger is set!
|
|
157
147
|
ops.logger ??= newDefaultLogger({
|
|
158
148
|
defaultLogLevel: ops.defaultLoggerLogLevel
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
/* Creates servers, resolves and sets the port. */
|
|
149
|
+
}); /* Creates servers, resolves and sets the port. */
|
|
162
150
|
const expressServer = await serverFactory(webpackConfig, ops);
|
|
163
151
|
let httpServer;
|
|
164
152
|
if (ops.https) {
|
|
@@ -166,31 +154,25 @@ export async function launchServer(webpackConfig, options = {}) {
|
|
|
166
154
|
cert: ops.https.cert,
|
|
167
155
|
key: ops.https.key
|
|
168
156
|
}, expressServer);
|
|
169
|
-
} else httpServer = http.createServer(expressServer);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (error.syscall !== 'listen') throw error;
|
|
174
|
-
const bind = typeof ops.port === 'string' ? `Pipe ${ops.port}` : `Port ${ops.port}`;
|
|
175
|
-
|
|
176
|
-
/* Human-readable message for some specific listen errors. */
|
|
157
|
+
} else httpServer = http.createServer(expressServer); /* Sets error handler for HTTP(S) server. */
|
|
158
|
+
httpServer.on("error", error => {
|
|
159
|
+
if (error.syscall !== "listen") throw error;
|
|
160
|
+
const bind = typeof ops.port === "string" ? `Pipe ${ops.port}` : `Port ${ops.port}`; /* Human-readable message for some specific listen errors. */
|
|
177
161
|
switch (error.code) {
|
|
178
|
-
case
|
|
162
|
+
case "EACCES":
|
|
179
163
|
ops.logger.error(`${bind} requires elevated privileges`);
|
|
180
164
|
return process.exit(1);
|
|
181
|
-
case
|
|
165
|
+
case "EADDRINUSE":
|
|
182
166
|
ops.logger.error(`${bind} is already in use`);
|
|
183
167
|
return process.exit(1);
|
|
184
168
|
case undefined:
|
|
185
169
|
default:
|
|
186
170
|
throw error;
|
|
187
171
|
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
/* Listening event handler for HTTP(S) server. */
|
|
191
|
-
httpServer.on('listening', () => {
|
|
172
|
+
}); /* Listening event handler for HTTP(S) server. */
|
|
173
|
+
httpServer.on("listening", () => {
|
|
192
174
|
const addr = httpServer.address();
|
|
193
|
-
const bind = typeof addr ===
|
|
175
|
+
const bind = typeof addr === "string" ? `pipe ${addr}` : `port ${addr.port}`;
|
|
194
176
|
ops.logger.info(`Server listening on ${bind} in ${process.env.NODE_ENV} mode`);
|
|
195
177
|
});
|
|
196
178
|
httpServer.listen(ops.port);
|