@dr.pogodin/react-utils 1.46.2 → 1.47.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/babel.config.js +1 -0
  2. package/babel.libweb.config.js +16 -0
  3. package/bin/build.js +16 -10
  4. package/bin/setup.js +11 -8
  5. package/build/development/client/getInj.js.map +1 -1
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/client/init.js.map +1 -1
  8. package/build/development/index.js +7 -1
  9. package/build/development/index.js.map +1 -1
  10. package/build/development/server/Cache.js.map +1 -1
  11. package/build/development/server/index.js +13 -8
  12. package/build/development/server/index.js.map +1 -1
  13. package/build/development/server/renderer.js +15 -8
  14. package/build/development/server/renderer.js.map +1 -1
  15. package/build/development/server/server.js +7 -5
  16. package/build/development/server/server.js.map +1 -1
  17. package/build/development/shared/components/Button/index.js +6 -6
  18. package/build/development/shared/components/Button/index.js.map +1 -1
  19. package/build/development/shared/components/Checkbox/index.js +8 -8
  20. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  21. package/build/development/shared/components/GenericLink/index.js +5 -1
  22. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  23. package/build/development/shared/components/Input/index.js +10 -9
  24. package/build/development/shared/components/Input/index.js.map +1 -1
  25. package/build/development/shared/components/Link.js.map +1 -1
  26. package/build/development/shared/components/Modal/index.js +8 -6
  27. package/build/development/shared/components/Modal/index.js.map +1 -1
  28. package/build/development/shared/components/NavLink.js.map +1 -1
  29. package/build/development/shared/components/PageLayout/index.js +6 -6
  30. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  31. package/build/development/shared/components/TextArea/index.js +13 -9
  32. package/build/development/shared/components/TextArea/index.js.map +1 -1
  33. package/build/development/shared/components/Throbber/index.js +6 -6
  34. package/build/development/shared/components/Throbber/index.js.map +1 -1
  35. package/build/development/shared/components/WithTooltip/Tooltip.js +1 -0
  36. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  37. package/build/development/shared/components/WithTooltip/index.js +7 -7
  38. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  39. package/build/development/shared/components/YouTubeVideo/index.js +9 -9
  40. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  41. package/build/development/shared/components/index.js.map +1 -1
  42. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  43. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  44. package/build/development/shared/components/selectors/CustomDropdown/index.js +11 -11
  45. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  46. package/build/development/shared/components/selectors/NativeDropdown/index.js +12 -12
  47. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  48. package/build/development/shared/components/selectors/Switch/index.js +7 -7
  49. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  50. package/build/development/shared/utils/config.js.map +1 -1
  51. package/build/development/shared/utils/globalState.js.map +1 -1
  52. package/build/development/shared/utils/index.js.map +1 -1
  53. package/build/development/shared/utils/jest/E2eSsrEnv.js +14 -10
  54. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  55. package/build/development/shared/utils/splitComponent.js +1 -0
  56. package/build/development/shared/utils/splitComponent.js.map +1 -1
  57. package/build/development/shared/utils/time.js.map +1 -1
  58. package/build/production/client/getInj.js.map +1 -1
  59. package/build/production/client/index.js.map +1 -1
  60. package/build/production/client/init.js.map +1 -1
  61. package/build/production/index.js +4 -1
  62. package/build/production/index.js.map +1 -1
  63. package/build/production/server/Cache.js.map +1 -1
  64. package/build/production/server/index.js +5 -5
  65. package/build/production/server/index.js.map +1 -1
  66. package/build/production/server/renderer.js +7 -7
  67. package/build/production/server/renderer.js.map +1 -1
  68. package/build/production/server/server.js +4 -4
  69. package/build/production/server/server.js.map +1 -1
  70. package/build/production/shared/components/Button/index.js +1 -1
  71. package/build/production/shared/components/Button/index.js.map +1 -1
  72. package/build/production/shared/components/Checkbox/index.js +1 -1
  73. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  74. package/build/production/shared/components/GenericLink/index.js +2 -2
  75. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  76. package/build/production/shared/components/Input/index.js +1 -1
  77. package/build/production/shared/components/Input/index.js.map +1 -1
  78. package/build/production/shared/components/Link.js.map +1 -1
  79. package/build/production/shared/components/Modal/index.js +1 -1
  80. package/build/production/shared/components/Modal/index.js.map +1 -1
  81. package/build/production/shared/components/NavLink.js.map +1 -1
  82. package/build/production/shared/components/PageLayout/index.js +1 -1
  83. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  84. package/build/production/shared/components/TextArea/index.js +1 -1
  85. package/build/production/shared/components/TextArea/index.js.map +1 -1
  86. package/build/production/shared/components/Throbber/index.js +1 -1
  87. package/build/production/shared/components/Throbber/index.js.map +1 -1
  88. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  89. package/build/production/shared/components/WithTooltip/index.js +1 -1
  90. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  91. package/build/production/shared/components/YouTubeVideo/index.js +1 -1
  92. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  93. package/build/production/shared/components/index.js.map +1 -1
  94. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +1 -1
  95. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  96. package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
  97. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  98. package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
  99. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  100. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  101. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  102. package/build/production/shared/utils/config.js.map +1 -1
  103. package/build/production/shared/utils/globalState.js.map +1 -1
  104. package/build/production/shared/utils/index.js.map +1 -1
  105. package/build/production/shared/utils/jest/E2eSsrEnv.js +8 -7
  106. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  107. package/build/production/shared/utils/splitComponent.js.map +1 -1
  108. package/build/production/shared/utils/time.js.map +1 -1
  109. package/build/web/client/getInj.js +54 -0
  110. package/build/web/client/getInj.js.map +1 -0
  111. package/build/web/client/index.js +38 -0
  112. package/build/web/client/index.js.map +1 -0
  113. package/build/web/client/init.js +49 -0
  114. package/build/web/client/init.js.map +1 -0
  115. package/build/web/index.js +25 -0
  116. package/build/web/index.js.map +1 -0
  117. package/build/web/server/Cache.js +54 -0
  118. package/build/web/server/Cache.js.map +1 -0
  119. package/build/web/server/index.js +211 -0
  120. package/build/web/server/index.js.map +1 -0
  121. package/build/web/server/renderer.js +516 -0
  122. package/build/web/server/renderer.js.map +1 -0
  123. package/build/web/server/server.js +231 -0
  124. package/build/web/server/server.js.map +1 -0
  125. package/build/web/server/utils/errors.js +103 -0
  126. package/build/web/server/utils/errors.js.map +1 -0
  127. package/build/web/server/utils/index.js +4 -0
  128. package/build/web/server/utils/index.js.map +1 -0
  129. package/build/web/shared/components/Button/index.js +90 -0
  130. package/build/web/shared/components/Button/index.js.map +1 -0
  131. package/build/web/shared/components/Button/style.scss +54 -0
  132. package/build/web/shared/components/Checkbox/index.js +35 -0
  133. package/build/web/shared/components/Checkbox/index.js.map +1 -0
  134. package/build/web/shared/components/Checkbox/theme.scss +63 -0
  135. package/build/web/shared/components/GenericLink/index.js +107 -0
  136. package/build/web/shared/components/GenericLink/index.js.map +1 -0
  137. package/build/web/shared/components/GenericLink/style.scss +3 -0
  138. package/build/web/shared/components/Input/index.js +71 -0
  139. package/build/web/shared/components/Input/index.js.map +1 -0
  140. package/build/web/shared/components/Input/theme.scss +52 -0
  141. package/build/web/shared/components/Link.js +20 -0
  142. package/build/web/shared/components/Link.js.map +1 -0
  143. package/build/web/shared/components/Modal/base-theme.scss +38 -0
  144. package/build/web/shared/components/Modal/index.js +128 -0
  145. package/build/web/shared/components/Modal/index.js.map +1 -0
  146. package/build/web/shared/components/Modal/styles.scss +3 -0
  147. package/build/web/shared/components/NavLink.js +13 -0
  148. package/build/web/shared/components/NavLink.js.map +1 -0
  149. package/build/web/shared/components/PageLayout/base-theme.scss +30 -0
  150. package/build/web/shared/components/PageLayout/index.js +38 -0
  151. package/build/web/shared/components/PageLayout/index.js.map +1 -0
  152. package/build/web/shared/components/TextArea/index.js +106 -0
  153. package/build/web/shared/components/TextArea/index.js.map +1 -0
  154. package/build/web/shared/components/TextArea/style.scss +68 -0
  155. package/build/web/shared/components/Throbber/index.js +26 -0
  156. package/build/web/shared/components/Throbber/index.js.map +1 -0
  157. package/build/web/shared/components/Throbber/theme.scss +26 -0
  158. package/build/web/shared/components/WithTooltip/Tooltip.js +226 -0
  159. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -0
  160. package/build/web/shared/components/WithTooltip/default-theme.scss +36 -0
  161. package/build/web/shared/components/WithTooltip/index.js +117 -0
  162. package/build/web/shared/components/WithTooltip/index.js.map +1 -0
  163. package/build/web/shared/components/YouTubeVideo/base.scss +15 -0
  164. package/build/web/shared/components/YouTubeVideo/index.js +56 -0
  165. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -0
  166. package/build/web/shared/components/YouTubeVideo/throbber.scss +11 -0
  167. package/build/web/shared/components/index.js +18 -0
  168. package/build/web/shared/components/index.js.map +1 -0
  169. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +79 -0
  170. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -0
  171. package/build/web/shared/components/selectors/CustomDropdown/Options/style.scss +6 -0
  172. package/build/web/shared/components/selectors/CustomDropdown/index.js +120 -0
  173. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -0
  174. package/build/web/shared/components/selectors/CustomDropdown/theme.scss +118 -0
  175. package/build/web/shared/components/selectors/NativeDropdown/index.js +82 -0
  176. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -0
  177. package/build/web/shared/components/selectors/NativeDropdown/theme.scss +81 -0
  178. package/build/web/shared/components/selectors/Switch/index.js +49 -0
  179. package/build/web/shared/components/selectors/Switch/index.js.map +1 -0
  180. package/build/web/shared/components/selectors/Switch/theme.scss +39 -0
  181. package/build/web/shared/components/selectors/common.js +12 -0
  182. package/build/web/shared/components/selectors/common.js.map +1 -0
  183. package/build/web/shared/components/selectors/index.js +4 -0
  184. package/build/web/shared/components/selectors/index.js.map +1 -0
  185. package/build/web/shared/utils/config.js +21 -0
  186. package/build/web/shared/utils/config.js.map +1 -0
  187. package/build/web/shared/utils/globalState.js +15 -0
  188. package/build/web/shared/utils/globalState.js.map +1 -0
  189. package/build/web/shared/utils/index.js +13 -0
  190. package/build/web/shared/utils/index.js.map +1 -0
  191. package/build/web/shared/utils/isomorphy/buildInfo.js +44 -0
  192. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -0
  193. package/build/web/shared/utils/isomorphy/environment-check.js +17 -0
  194. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -0
  195. package/build/web/shared/utils/isomorphy/index.js +36 -0
  196. package/build/web/shared/utils/isomorphy/index.js.map +1 -0
  197. package/build/web/shared/utils/jest/E2eSsrEnv.js +230 -0
  198. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -0
  199. package/build/web/shared/utils/jest/global.js +4 -0
  200. package/build/web/shared/utils/jest/global.js.map +1 -0
  201. package/build/web/shared/utils/jest/index.js +165 -0
  202. package/build/web/shared/utils/jest/index.js.map +1 -0
  203. package/build/web/shared/utils/splitComponent.js +221 -0
  204. package/build/web/shared/utils/splitComponent.js.map +1 -0
  205. package/build/web/shared/utils/time.js +85 -0
  206. package/build/web/shared/utils/time.js.map +1 -0
  207. package/build/web/shared/utils/webpack.js +61 -0
  208. package/build/web/shared/utils/webpack.js.map +1 -0
  209. package/build/web/styles/_global/reset.css +52 -0
  210. package/build/web/styles/_mixins/fonts.scss +40 -0
  211. package/build/web/styles/_mixins/media.scss +150 -0
  212. package/build/web/styles/_mixins/typography.scss +83 -0
  213. package/build/web/styles/global.scss +11 -0
  214. package/build/web/styles/mixins.scss +6 -0
  215. package/config/babel/node-ssr.js +5 -2
  216. package/config/webpack/app-base.js +10 -7
  217. package/config/webpack/app-development.js +3 -2
  218. package/package.json +16 -27
  219. package/src/index.ts +7 -1
  220. package/src/server/index.ts +6 -8
  221. package/src/server/renderer.tsx +7 -9
  222. package/src/server/server.ts +3 -5
  223. package/src/shared/components/Modal/base-theme.scss +1 -1
  224. package/src/shared/components/PageLayout/base-theme.scss +1 -1
  225. package/src/shared/utils/jest/E2eSsrEnv.ts +8 -1
  226. package/build/development/__chunk_groups__.json +0 -6
  227. package/build/development/style.css +0 -909
  228. package/build/development/web.bundle.js +0 -752
  229. package/build/production/__chunk_groups__.json +0 -6
  230. package/build/production/style.css +0 -2
  231. package/build/production/style.css.map +0 -1
  232. package/build/production/web.bundle.js +0 -3
  233. package/build/production/web.bundle.js.LICENSE.txt +0 -9
  234. package/build/production/web.bundle.js.map +0 -1
  235. package/dev-styles.js +0 -1
  236. package/null.js +0 -1
  237. package/prod-styles.js +0 -1
package/babel.config.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /* global module */
3
3
 
4
4
  module.exports = {
5
+ plugins: ['babel-plugin-transform-import-meta'],
5
6
  presets: [
6
7
  ['./config/babel/node-ssr', {
7
8
  typescript: true,
@@ -0,0 +1,16 @@
1
+ // PoC: The new way to compile the library for distribution and further Webpack
2
+ // consumption. Essentially, it just compiles out TypeScript, and uses Babel
3
+ // Module resolver to replace aliased paths. The rest of the bundling will be
4
+ // performed by Webpack build of the host code.
5
+
6
+ /* global module */
7
+
8
+ module.exports = {
9
+ presets: [
10
+ ['./config/babel/webpack', {
11
+ noRR: true,
12
+ noStyling: true,
13
+ typescript: true,
14
+ }],
15
+ ],
16
+ };
package/bin/build.js CHANGED
@@ -1,26 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /* eslint-disable import/no-commonjs, no-console */
4
- /* global console, process, require */
3
+ /* eslint-disable no-console */
4
+ /* global console, process */
5
5
 
6
- const childProcess = require('node:child_process');
7
- const fs = require('node:fs');
8
- const path = require('node:path');
6
+ import childProcess from 'node:child_process';
7
+ import fs from 'node:fs';
8
+ import { createRequire } from 'node:module';
9
+ import path from 'node:path';
9
10
 
10
- const { isFunction, mapValues, merge } = require('lodash');
11
- const { program } = require('commander');
11
+ import isFunction from 'lodash/isFunction.js';
12
+ import mapValues from 'lodash/mapValues.js';
13
+ import merge from 'lodash/merge.js';
14
+
15
+ import { program } from 'commander';
12
16
 
13
17
  // TODO: Disabled, because ESLint still does not support "exports" declarations
14
18
  // in "package.json", and "rimraf" does not declare fallback entrance.
15
19
  // See: https://github.com/import-js/eslint-plugin-import/issues/1810
16
20
  // and update, once that issue is resolved.
17
- const { rimraf } = require('rimraf');
21
+ import { rimraf } from 'rimraf';
18
22
 
19
23
  /* eslint-disable import/no-extraneous-dependencies */
20
24
  // To support TS configs for Webpack.
21
- const register = require('@babel/register/experimental-worker');
25
+ import register from '@babel/register/experimental-worker.js';
22
26
 
23
- const webpack = require('webpack');
27
+ import webpack from 'webpack';
24
28
  /* eslint-enable import/no-extraneous-dependencies */
25
29
 
26
30
  const BUILD_TYPES = {
@@ -107,6 +111,8 @@ register({
107
111
  root: process.cwd(),
108
112
  });
109
113
 
114
+ const require = createRequire(import.meta.url);
115
+
110
116
  // eslint-disable-next-line import/no-dynamic-require
111
117
  let webpackConfig = require(path.resolve(cwd, cmdLineArgs.webpackConfig));
112
118
  if ('default' in webpackConfig) webpackConfig = webpackConfig.default;
package/bin/setup.js CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /* eslint-disable import/no-commonjs, no-console */
4
- /* global console, process, require */
3
+ /* eslint-disable no-console */
4
+ /* global console, process */
5
5
 
6
- const { spawnSync } = require('node:child_process');
7
- const fs = require('node:fs');
8
- const path = require('node:path');
6
+ import { spawnSync } from 'node:child_process';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
9
 
10
- const { clone } = require('lodash');
11
- const { program } = require('commander');
10
+ import clone from 'lodash/clone.js';
11
+ import { program } from 'commander';
12
12
 
13
13
  const NPM_COMMAND = process.platform === 'win32' ? 'npm.cmd' : 'npm';
14
14
 
@@ -173,7 +173,10 @@ function getHostPackageJson() {
173
173
  */
174
174
  function getPackageJson(packageName = '@dr.pogodin/react-utils') {
175
175
  let url = packageName === '@dr.pogodin/react-utils' ? '..' : packageName;
176
- url = path.dirname(require.resolve(url));
176
+
177
+ // TODO: .slice(5) cuts out file:// schema in front of the URL.
178
+ url = path.dirname(import.meta.resolve(url).slice(5));
179
+
177
180
  for (;;) {
178
181
  const files = fs.readdirSync(url);
179
182
  if (files.includes('package.json')) {
@@ -1 +1 @@
1
- {"version":3,"file":"getInj.js","names":["_forge","_interopRequireDefault","require","_buildInfo","inj","metaElement","document","querySelector","remove","data","forge","util","decode64","content","key","getBuildInfo","d","cipher","createDecipher","start","iv","slice","length","update","createBuffer","finish","decodeUtf8","output","eval","window","REACT_UTILS_INJECTION","getInj"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\n// Note: this way, only required part of \"node-forge\": AES, and some utils,\n// is bundled into client-side code.\nimport forge from 'node-forge/lib/forge';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'node-forge/lib/aes';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\n// Safeguard is needed here, because the server-side version of Docusaurus docs\n// is compiled (at least now) with settings suggesting it is a client-side\n// environment, but there is no document.\nlet inj: InjT = {};\n\nconst metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\nif (metaElement) {\n metaElement.remove();\n let data = forge.util.decode64(metaElement.content);\n\n const { key } = getBuildInfo();\n const d = forge.cipher.createDecipher('AES-CBC', key);\n d.start({ iv: data.slice(0, key.length) });\n d.update(forge.util.createBuffer(data.slice(key.length)));\n d.finish();\n\n data = forge.util.decodeUtf8(d.output.data);\n\n // TODO: Double-check, if there is a safer alternative to parse it?\n // eslint-disable-next-line no-eval\n inj = eval(`(${data})`) as InjT;\n} else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n inj = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n} else {\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 inj = {};\n}\n\nexport default function getInj(): InjT {\n return inj;\n}\n"],"mappings":";;;;;;;AAMA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGAA,OAAA;AAIA,IAAAC,UAAA,GAAAD,OAAA;AAbA;;AAEA;;AAEA;AACA;;AAGA;;AAOA;AACA;AACA;AACA,IAAIE,GAAS,GAAG,CAAC,CAAC;AAElB,MAAMC,WAAmC,GAAG,OAAOC,QAAQ,KAAK,WAAW,GACvE,IAAI,GAAGA,QAAQ,CAACC,aAAa,CAAC,2BAA2B,CAAC;AAE9D,IAAIF,WAAW,EAAE;EACfA,WAAW,CAACG,MAAM,CAAC,CAAC;EACpB,IAAIC,IAAI,GAAGC,cAAK,CAACC,IAAI,CAACC,QAAQ,CAACP,WAAW,CAACQ,OAAO,CAAC;EAEnD,MAAM;IAAEC;EAAI,CAAC,GAAG,IAAAC,uBAAY,EAAC,CAAC;EAC9B,MAAMC,CAAC,GAAGN,cAAK,CAACO,MAAM,CAACC,cAAc,CAAC,SAAS,EAAEJ,GAAG,CAAC;EACrDE,CAAC,CAACG,KAAK,CAAC;IAAEC,EAAE,EAAEX,IAAI,CAACY,KAAK,CAAC,CAAC,EAAEP,GAAG,CAACQ,MAAM;EAAE,CAAC,CAAC;EAC1CN,CAAC,CAACO,MAAM,CAACb,cAAK,CAACC,IAAI,CAACa,YAAY,CAACf,IAAI,CAACY,KAAK,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,CAAC;EACzDN,CAAC,CAACS,MAAM,CAAC,CAAC;EAEVhB,IAAI,GAAGC,cAAK,CAACC,IAAI,CAACe,UAAU,CAACV,CAAC,CAACW,MAAM,CAAClB,IAAI,CAAC;;EAE3C;EACA;EACAL,GAAG,GAAGwB,IAAI,CAAC,IAAInB,IAAI,GAAG,CAAS;AACjC,CAAC,MAAM,IAAI,OAAOoB,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACC,qBAAqB,EAAE;EACxE1B,GAAG,GAAGyB,MAAM,CAACC,qBAAqB;EAClC,OAAOD,MAAM,CAACC,qBAAqB;AACrC,CAAC,MAAM;EACL;EACA;EACA;EACA1B,GAAG,GAAG,CAAC,CAAC;AACV;AAEe,SAAS2B,MAAMA,CAAA,EAAS;EACrC,OAAO3B,GAAG;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"getInj.js","names":["_forge","_interopRequireDefault","require","_buildInfo","inj","metaElement","document","querySelector","remove","data","default","util","decode64","content","key","getBuildInfo","d","cipher","createDecipher","start","iv","slice","length","update","createBuffer","finish","decodeUtf8","output","eval","window","REACT_UTILS_INJECTION","getInj"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\n// Note: this way, only required part of \"node-forge\": AES, and some utils,\n// is bundled into client-side code.\nimport forge from 'node-forge/lib/forge';\n\n// eslint-disable-next-line import/no-unassigned-import\nimport 'node-forge/lib/aes';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\n// Safeguard is needed here, because the server-side version of Docusaurus docs\n// is compiled (at least now) with settings suggesting it is a client-side\n// environment, but there is no document.\nlet inj: InjT = {};\n\nconst metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\nif (metaElement) {\n metaElement.remove();\n let data = forge.util.decode64(metaElement.content);\n\n const { key } = getBuildInfo();\n const d = forge.cipher.createDecipher('AES-CBC', key);\n d.start({ iv: data.slice(0, key.length) });\n d.update(forge.util.createBuffer(data.slice(key.length)));\n d.finish();\n\n data = forge.util.decodeUtf8(d.output.data);\n\n // TODO: Double-check, if there is a safer alternative to parse it?\n // eslint-disable-next-line no-eval\n inj = eval(`(${data})`) as InjT;\n} else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n inj = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n} else {\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 inj = {};\n}\n\nexport default function getInj(): InjT {\n return inj;\n}\n"],"mappings":";;;;;;;AAMA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGAA,OAAA;AAIA,IAAAC,UAAA,GAAAD,OAAA;AAbA;;AAEA;;AAEA;AACA;;AAGA;;AAOA;AACA;AACA;AACA,IAAIE,GAAS,GAAG,CAAC,CAAC;AAElB,MAAMC,WAAmC,GAAG,OAAOC,QAAQ,KAAK,WAAW,GACvE,IAAI,GAAGA,QAAQ,CAACC,aAAa,CAAC,2BAA2B,CAAC;AAE9D,IAAIF,WAAW,EAAE;EACfA,WAAW,CAACG,MAAM,CAAC,CAAC;EACpB,IAAIC,IAAI,GAAGT,MAAA,CAAAU,OAAK,CAACC,IAAI,CAACC,QAAQ,CAACP,WAAW,CAACQ,OAAO,CAAC;EAEnD,MAAM;IAAEC;EAAI,CAAC,GAAG,IAAAX,UAAA,CAAAY,YAAY,EAAC,CAAC;EAC9B,MAAMC,CAAC,GAAGhB,MAAA,CAAAU,OAAK,CAACO,MAAM,CAACC,cAAc,CAAC,SAAS,EAAEJ,GAAG,CAAC;EACrDE,CAAC,CAACG,KAAK,CAAC;IAAEC,EAAE,EAAEX,IAAI,CAACY,KAAK,CAAC,CAAC,EAAEP,GAAG,CAACQ,MAAM;EAAE,CAAC,CAAC;EAC1CN,CAAC,CAACO,MAAM,CAACvB,MAAA,CAAAU,OAAK,CAACC,IAAI,CAACa,YAAY,CAACf,IAAI,CAACY,KAAK,CAACP,GAAG,CAACQ,MAAM,CAAC,CAAC,CAAC;EACzDN,CAAC,CAACS,MAAM,CAAC,CAAC;EAEVhB,IAAI,GAAGT,MAAA,CAAAU,OAAK,CAACC,IAAI,CAACe,UAAU,CAACV,CAAC,CAACW,MAAM,CAAClB,IAAI,CAAC;;EAE3C;EACA;EACAL,GAAG,GAAGwB,IAAI,CAAC,IAAInB,IAAI,GAAG,CAAS;AACjC,CAAC,MAAM,IAAI,OAAOoB,MAAM,KAAK,WAAW,IAAIA,MAAM,CAACC,qBAAqB,EAAE;EACxE1B,GAAG,GAAGyB,MAAM,CAACC,qBAAqB;EAClC,OAAOD,MAAM,CAACC,qBAAqB;AACrC,CAAC,MAAM;EACL;EACA;EACA;EACA1B,GAAG,GAAG,CAAC,CAAC;AACV;AAEe,SAAS2B,MAAMA,CAAA,EAAS;EACrC,OAAO3B,GAAG;AACZ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_client","require","_reactHelmet","_reactRouter","_reactGlobalState","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","container","document","getElementById","Error","scene","jsx","GlobalStateProvider","initialState","getInj","ISTATE","children","BrowserRouter","HelmetProvider","dontHydrate","root","createRoot","render","hydrateRoot"],"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 { HelmetProvider } from '@dr.pogodin/react-helmet';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\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 default function Launch(\n Application: ComponentType,\n options: OptionsT = {},\n): void {\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={getInj().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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AAA8B,IAAAM,WAAA,GAAAN,OAAA;AAV9B;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACe,SAASO,MAAMA,CAC5BC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EAChB;EACN,MAAMC,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACT,IAAAR,WAAA,CAAAS,GAAA,EAACZ,iBAAA,CAAAa,mBAAmB;IAACC,YAAY,EAAE,IAAAC,eAAM,EAAC,CAAC,CAACC,MAAM,IAAIV,OAAO,CAACQ,YAAa;IAAAG,QAAA,eACzE,IAAAd,WAAA,CAAAS,GAAA,EAACb,YAAA,CAAAmB,aAAa;MAAAD,QAAA,eACZ,IAAAd,WAAA,CAAAS,GAAA,EAACd,YAAA,CAAAqB,cAAc;QAAAF,QAAA,eACb,IAAAd,WAAA,CAAAS,GAAA,EAACP,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACc,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAG,IAAAC,kBAAU,EAACf,SAAS,CAAC;IAClCc,IAAI,CAACE,MAAM,CAACZ,KAAK,CAAC;EACpB,CAAC,MAAM,IAAAa,mBAAW,EAACjB,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_client","require","_reactHelmet","_reactRouter","_reactGlobalState","_getInj","_interopRequireDefault","_jsxRuntime","Launch","Application","options","container","document","getElementById","Error","scene","jsx","GlobalStateProvider","initialState","default","ISTATE","children","BrowserRouter","HelmetProvider","dontHydrate","root","createRoot","render","hydrateRoot"],"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 { HelmetProvider } from '@dr.pogodin/react-helmet';\nimport { BrowserRouter } from 'react-router';\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\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 default function Launch(\n Application: ComponentType,\n options: OptionsT = {},\n): void {\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={getInj().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":";;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AAA8B,IAAAM,WAAA,GAAAN,OAAA;AAV9B;AACA;;AAgBA;AACA;AACA;AACA;AACA;AACe,SAASO,MAAMA,CAC5BC,WAA0B,EAC1BC,OAAiB,GAAG,CAAC,CAAC,EAChB;EACN,MAAMC,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,YAAY,CAAC;EACvD,IAAI,CAACF,SAAS,EAAE,MAAMG,KAAK,CAAC,wCAAwC,CAAC;EACrE,MAAMC,KAAK,gBACT,IAAAR,WAAA,CAAAS,GAAA,EAACZ,iBAAA,CAAAa,mBAAmB;IAACC,YAAY,EAAE,IAAAb,OAAA,CAAAc,OAAM,EAAC,CAAC,CAACC,MAAM,IAAIV,OAAO,CAACQ,YAAa;IAAAG,QAAA,eACzE,IAAAd,WAAA,CAAAS,GAAA,EAACb,YAAA,CAAAmB,aAAa;MAAAD,QAAA,eACZ,IAAAd,WAAA,CAAAS,GAAA,EAACd,YAAA,CAAAqB,cAAc;QAAAF,QAAA,eACb,IAAAd,WAAA,CAAAS,GAAA,EAACP,WAAW,IAAE;MAAC,CACD;IAAC,CACJ;EAAC,CACG,CACtB;EAED,IAAIC,OAAO,CAACc,WAAW,EAAE;IACvB,MAAMC,IAAI,GAAG,IAAAzB,OAAA,CAAA0B,UAAU,EAACf,SAAS,CAAC;IAClCc,IAAI,CAACE,MAAM,CAACZ,KAAK,CAAC;EACpB,CAAC,MAAM,IAAAf,OAAA,CAAA4B,WAAW,EAACjB,SAAS,EAAEI,KAAK,CAAC;AACtC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":["_buildInfo","require","buildInfo","getBuildInfo","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":";;AAMA,IAAAA,UAAA,GAAAC,OAAA;AANA;AACA;AACA;;AAEA;;AAIA,MAAMC,SAAS,GAAG,IAAAC,uBAAY,EAAC,CAAC;;AAEhC;;AAUA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACzC;EACAC,OAAO,CAACC,IAAI,CAAC,wDAAwD,CAAC;;EAEtE;EACAC,MAAM,CAACC,kBAAkB,GAAGC,UAAU;AACxC;;AAEA;AACA,MAAM;EAAEC;AAAiB,CAAC,GAAGV,SAAS;AACtC,IAAIU,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;UACjD;UACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,EAAEH,GAAG,CAAC;QACpC,CAAC,CAAC,OAAOI,GAAG,EAAE;UACZ;UACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,EAAEC,GAAG,CAAC;QAC7C;MACF,CAAC,EAAE,CAAC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
1
+ {"version":3,"file":"init.js","names":["_buildInfo","require","buildInfo","getBuildInfo","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":";;AAMA,IAAAA,UAAA,GAAAC,OAAA;AANA;AACA;AACA;;AAEA;;AAIA,MAAMC,SAAS,GAAG,IAAAF,UAAA,CAAAG,YAAY,EAAC,CAAC;;AAEhC;;AAUA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;EACzC;EACAC,OAAO,CAACC,IAAI,CAAC,wDAAwD,CAAC;;EAEtE;EACAC,MAAM,CAACC,kBAAkB,GAAGC,UAAU;AACxC;;AAEA;AACA,MAAM;EAAEC;AAAiB,CAAC,GAAGV,SAAS;AACtC,IAAIU,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;UACjD;UACAV,OAAO,CAACW,GAAG,CAAC,gBAAgB,EAAEH,GAAG,CAAC;QACpC,CAAC,CAAC,OAAOI,GAAG,EAAE;UACZ;UACAZ,OAAO,CAACW,GAAG,CAAC,yBAAyB,EAAEC,GAAG,CAAC;QAC7C;MACF,CAAC,EAAE,CAAC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
@@ -177,7 +177,13 @@ Object.keys(_components).forEach(function (key) {
177
177
  if (global.REACT_UTILS_LIBRARY_LOADED) {
178
178
  throw Error('React utils library is already loaded');
179
179
  } else global.REACT_UTILS_LIBRARY_LOADED = true;
180
- const server = exports.server = _utils.webpack.requireWeak("./server", __dirname);
180
+
181
+ // TODO: This is a rapid workaround to get rid of __dirname. I guess, later
182
+ // we'll re-implement requireWeak() to accept import.meta.url directly, and
183
+ // this workaround won't be needed.
184
+ let dirname = require('url').pathToFileURL(__filename).toString();
185
+ dirname = dirname.slice(5, dirname.lastIndexOf('/'));
186
+ const server = exports.server = _utils.webpack.requireWeak("./server", dirname);
181
187
  const client = exports.client = server ? undefined
182
188
 
183
189
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_utils","require","_reactGlobalState","_components","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","global","REACT_UTILS_LIBRARY_LOADED","Error","server","webpack","requireWeak","__dirname","client","undefined","default"],"sources":["../../src/index.ts"],"sourcesContent":["import 'styles/global.scss';\n\nimport { webpack } from 'utils';\n\nimport type * as ClientM from './client';\nimport type * as ServerFactoryM from './server';\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).\nif (global.REACT_UTILS_LIBRARY_LOADED) {\n throw Error('React utils library is already loaded');\n} else global.REACT_UTILS_LIBRARY_LOADED = true;\n\nconst server = webpack.requireWeak<typeof ServerFactoryM>('./server', __dirname);\n\nconst client = server\n ? undefined\n\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n : (require('./client') as typeof ClientM).default;\n\nexport {\n type AsyncCollectionT,\n type AsyncCollectionLoaderT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\n GlobalStateProvider,\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 assertEmptyObject,\n config,\n Barrier,\n Cached,\n Emitter,\n isomorphy,\n getSsrContext,\n type Listener,\n type ObjectKey,\n Semaphore,\n splitComponent,\n type Theme,\n themed,\n ThemeProvider,\n time,\n webpack,\n withRetries,\n} from 'utils';\n\nexport { client, server };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAqBA,IAAAC,iBAAA,GAAAD,OAAA;AAmBA,IAAAE,WAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAnCA;AACA;AACA;AACA;AACA,IAAIS,MAAM,CAACC,0BAA0B,EAAE;EACrC,MAAMC,KAAK,CAAC,uCAAuC,CAAC;AACtD,CAAC,MAAMF,MAAM,CAACC,0BAA0B,GAAG,IAAI;AAE/C,MAAME,MAAM,GAAAP,OAAA,CAAAO,MAAA,GAAGC,cAAO,CAACC,WAAW,aAAoCC,SAAS,CAAC;AAEhF,MAAMC,MAAM,GAAAX,OAAA,CAAAW,MAAA,GAAGJ,MAAM,GACjBK;;AAEF;AAAA,EACGvB,OAAO,WAAW,CAAC,CAAoBwB,OAAO","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_utils","require","_reactGlobalState","_components","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","global","REACT_UTILS_LIBRARY_LOADED","Error","dirname","pathToFileURL","__filename","toString","slice","lastIndexOf","server","webpack","requireWeak","client","undefined","default"],"sources":["../../src/index.ts"],"sourcesContent":["import 'styles/global.scss';\n\nimport { webpack } from 'utils';\n\nimport type * as ClientM from './client';\nimport type * as ServerFactoryM from './server';\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).\nif (global.REACT_UTILS_LIBRARY_LOADED) {\n throw Error('React utils library is already loaded');\n} else global.REACT_UTILS_LIBRARY_LOADED = true;\n\n// TODO: This is a rapid workaround to get rid of __dirname. I guess, later\n// we'll re-implement requireWeak() to accept import.meta.url directly, and\n// this workaround won't be needed.\nlet dirname = import.meta.url;\ndirname = dirname.slice(5, dirname.lastIndexOf('/'));\n\nconst server = webpack.requireWeak<typeof ServerFactoryM>('./server', dirname);\n\nconst client = server\n ? undefined\n\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n : (require('./client') as typeof ClientM).default;\n\nexport {\n type AsyncCollectionT,\n type AsyncCollectionLoaderT,\n type AsyncDataEnvelopeT,\n type AsyncDataLoaderT,\n type ForceT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n type UseGlobalStateResT,\n type ValueOrInitializerT,\n getGlobalState,\n GlobalStateProvider,\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 assertEmptyObject,\n config,\n Barrier,\n Cached,\n Emitter,\n isomorphy,\n getSsrContext,\n type Listener,\n type ObjectKey,\n Semaphore,\n splitComponent,\n type Theme,\n themed,\n ThemeProvider,\n time,\n webpack,\n withRetries,\n} from 'utils';\n\nexport { client, server };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AA2BA,IAAAC,iBAAA,GAAAD,OAAA;AAmBA,IAAAE,WAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,WAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,WAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,WAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAzCA;AACA;AACA;AACA;AACA,IAAIS,MAAM,CAACC,0BAA0B,EAAE;EACrC,MAAMC,KAAK,CAAC,uCAAuC,CAAC;AACtD,CAAC,MAAMF,MAAM,CAACC,0BAA0B,GAAG,IAAI;;AAE/C;AACA;AACA;AACA,IAAIE,OAAO,GAAAlB,OAAA,QAAAmB,aAAA,CAAAC,UAAA,EAAAC,QAAA,EAAkB;AAC7BH,OAAO,GAAGA,OAAO,CAACI,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAACK,WAAW,CAAC,GAAG,CAAC,CAAC;AAEpD,MAAMC,MAAM,GAAAb,OAAA,CAAAa,MAAA,GAAGC,cAAO,CAACC,WAAW,aAAoCR,OAAO,CAAC;AAE9E,MAAMS,MAAM,GAAAhB,OAAA,CAAAgB,MAAA,GAAGH,MAAM,GACjBI;;AAEF;AAAA,EACG5B,OAAO,WAAW,CAAC,CAAoB6B,OAAO","ignoreList":[]}
@@ -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","exports","default"],"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;AACe,MAAMA,KAAK,CAAS;EACzBC,KAAK,GAAwC,CAAC,CAAC;EAE/CC,IAAI,GAAG,CAAC;EA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AAC;QAC1B,IAAI,CAACrB,IAAI,IAAIQ,IAAI,CAACR,IAAI;QACtB,IAAI,IAAI,CAACA,IAAI,GAAG,IAAI,CAACE,OAAO,GAAG,CAAC,EAAE;MACpC;IACF;EACF;AACF;AAACoB,OAAA,CAAAC,OAAA,GAAAzB,KAAA","ignoreList":[]}
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","exports","default"],"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;AACe,MAAMA,KAAK,CAAS;EACzBC,KAAK,GAAwC,CAAC,CAAC;EAE/CC,I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AAK,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;AAAAoB,OAAA,CAAAC,OAAA,GAAAzB,KAAA","ignoreList":[]}
@@ -20,7 +20,12 @@ Object.defineProperty(exports, "getDefaultCspSettings", {
20
20
  require("source-map-support/register");
21
21
  var _nodeHttp = _interopRequireDefault(require("node:http"));
22
22
  var _nodeHttps = _interopRequireDefault(require("node:https"));
23
- var _lodash = require("lodash");
23
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
24
+ var _defaults = _interopRequireDefault(require("lodash/defaults"));
25
+ var _isFinite = _interopRequireDefault(require("lodash/isFinite"));
26
+ var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
27
+ var _isString = _interopRequireDefault(require("lodash/isString"));
28
+ var _toNumber = _interopRequireDefault(require("lodash/toNumber"));
24
29
  require("raf/polyfill");
25
30
  var _server = _interopRequireWildcard(require("./server"));
26
31
  var _renderer = require("./renderer");
@@ -39,9 +44,9 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
39
44
  * @return Port number (Number), name (String), or false.
40
45
  */
41
46
  function normalizePort(value) {
42
- const port = (0, _lodash.toNumber)(value);
43
- if ((0, _lodash.isFinite)(port)) return port; /* port number */
44
- if (!(0, _lodash.isNumber)(port)) return value; /* named pipe */
47
+ const port = (0, _toNumber.default)(value);
48
+ if ((0, _isFinite.default)(port)) return port; /* port number */
49
+ if (!(0, _isNumber.default)(port)) return value; /* named pipe */
45
50
  return false;
46
51
  }
47
52
  /**
@@ -164,11 +169,11 @@ function normalizePort(value) {
164
169
  */
165
170
  async function launchServer(webpackConfig, options = {}) {
166
171
  /* Options normalization. */
167
- const ops = (0, _lodash.cloneDeep)(options);
172
+ const ops = (0, _cloneDeep.default)(options);
168
173
 
169
174
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
170
175
  ops.port = normalizePort(ops.port || process.env.PORT || 3000);
171
- (0, _lodash.defaults)(ops, {
176
+ (0, _defaults.default)(ops, {
172
177
  httpsRedirect: true
173
178
  });
174
179
 
@@ -191,7 +196,7 @@ async function launchServer(webpackConfig, options = {}) {
191
196
  /* Sets error handler for HTTP(S) server. */
192
197
  httpServer.on('error', error => {
193
198
  if (error.syscall !== 'listen') throw error;
194
- const bind = (0, _lodash.isString)(ops.port) ? `Pipe ${ops.port}` : `Port ${ops.port}`;
199
+ const bind = (0, _isString.default)(ops.port) ? `Pipe ${ops.port}` : `Port ${ops.port}`;
195
200
 
196
201
  /* Human-readable message for some specific listen errors. */
197
202
  switch (error.code) {
@@ -210,7 +215,7 @@ async function launchServer(webpackConfig, options = {}) {
210
215
  /* Listening event handler for HTTP(S) server. */
211
216
  httpServer.on('listening', () => {
212
217
  const addr = httpServer.address();
213
- const bind = (0, _lodash.isString)(addr) ? `pipe ${addr}` : `port ${addr.port}`;
218
+ const bind = (0, _isString.default)(addr) ? `pipe ${addr}` : `port ${addr.port}`;
214
219
  ops.logger.info(`Server listening on ${bind} in ${process.env.NODE_ENV} mode`);
215
220
  });
216
221
  httpServer.listen(ops.port);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["require","_nodeHttp","_interopRequireDefault","_nodeHttps","_lodash","_server","_interopRequireWildcard","_renderer","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","normalizePort","value","port","toNumber","isFinite","isNumber","launchServer","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","logger","newDefaultLogger","defaultLogLevel","defaultLoggerLogLevel","expressServer","serverFactory","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","undefined","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS","getDefaultCspSettings","errors"],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport {\n cloneDeep,\n defaults,\n isFinite,\n isNumber,\n isString,\n toNumber,\n} from 'lodash';\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';\n\nimport type { Configuration } from 'webpack';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport { errors } from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport { errors, getDefaultCspSettings, type ServerT };\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), or false.\n */\nfunction normalizePort(value: number | string) {\n const port = toNumber(value);\n if (isFinite(port)) return port; /* port number */\n if (!isNumber(port)) return value; /* named pipe */\n return false;\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)` &rArr; `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` &ndash; the cache key for the response;\n * - `maxage?: number` &ndash; 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 default 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 = isString(ops.port) ? `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 = isString(addr) ? `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\nlaunchServer.SCRIP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AM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AA9BjC;;AAeA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA,SAASkB,aAAaA,CAACC,KAAsB,EAAE;EAC7C,MAAMC,IAAI,GAAG,IAAAC,gBAAQ,EAACF,KAAK,CAAC;EAC5B,IAAI,IAAAG,gBAAQ,EAACF,IAAI,CAAC,EAAE,OAAOA,IAAI,CAAC,CAAC;EACjC,IAAI,CAAC,IAAAG,gBAAQ,EAACH,IAAI,CAAC,EAAE,OAAOD,KAAK,CAAC,CAAC;EACnC,OAAO,KAAK;AACd;AAYA;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;AACe,eAAeK,YAAYA,CACxCC,aAA4B,EAC5BC,OAAiB,GAAG,CAAC,CAAC,EAIrB;EACD;EACA,MAAMC,GAAG,GAAG,IAAAC,iBAAS,EAACF,OAAO,CAAC;;EAE9B;EACAC,GAAG,CAACP,IAAI,GAAGF,aAAa,CAACS,GAAG,CAACP,IAAI,IAAIS,OAAO,C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B,KAAKC,SAAS;MACd;QACE,MAAMN,KAAK;IACf;EACF,CAAC,CAAC;;EAEF;EACAP,UAAU,CAACM,EAAE,CAAC,WAAW,EAAE,MAAM;IAC/B,MAAMQ,IAAI,GAAGd,UAAU,CAACe,OAAO,CAAC,CAAE;IAClC,MAAMN,IAAI,GAAG,IAAAC,gBAAQ,EAACI,IAAI,CAAC,GAAG,QAAQA,IAAI,EAAE,GAAG,QAAQA,IAAI,CAAClC,IAAI,EAAE;IAClEO,GAAG,CAACO,MAAM,CAAEsB,IAAI,CAAC,uBAAuBP,IAAI,OAC1CpB,OAAO,CAACC,GAAG,CAAC2B,QAAQ,OAAO,CAAC;EAChC,CAAC,CAAC;EAEFjB,UAAU,CAACkB,MAAM,CAAC/B,GAAG,CAACP,IAAI,CAAC;EAE3B,OAAO;IACLkB,aAAa;IACbE;EACF,CAAC;AACH;AAEAhB,YAAY,CAACmC,gBAAgB,GAAGA,0BAAgB;AAChDnC,YAAY,CAACoC,qBAAqB,GAAGA,6BAAqB;AAC1DpC,YAAY,CAACqC,MAAM,GAAGA,aAAM","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["require","_nodeHttp","_interopRequireDefault","_nodeHttps","_cloneDeep","_defaults","_isFinite","_isNumber","_isString","_toNumber","_server","_interopRequireWildcard","_renderer","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","normalizePort","value","port","toNumber","isFinite","isNumber","launchServer","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","logger","newDefaultLogger","defaultLogLevel","defaultLoggerLogLevel","expressServer","serverFactory","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","undefined","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS","getDefaultCspSettings","errors"],"sources":["../../../src/server/index.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'source-map-support/register';\n\nimport http from 'node:http';\nimport https from 'node:https';\n\nimport cloneDeep from 'lodash/cloneDeep';\nimport defaults from 'lodash/defaults';\nimport isFinite from 'lodash/isFinite';\nimport isNumber from 'lodash/isNumber';\nimport isString from 'lodash/isString';\nimport toNumber from 'lodash/toNumber';\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';\n\nimport type { Configuration } from 'webpack';\n\nimport serverFactory, {\n type OptionsT as ServerOptionsT,\n type ServerT,\n getDefaultCspSettings,\n} from './server';\n\nimport { SCRIPT_LOCATIONS, newDefaultLogger } from './renderer';\n\nimport { errors } from './utils';\n\nexport type {\n BeforeRenderResT,\n BeforeRenderT,\n ConfigT,\n ServerSsrContext,\n} from './renderer';\n\nexport { errors, getDefaultCspSettings, type ServerT };\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), or false.\n */\nfunction normalizePort(value: number | string) {\n const port = toNumber(value);\n if (isFinite(port)) return port; /* port number */\n if (!isNumber(port)) return value; /* named pipe */\n return false;\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)` &rArr; `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` &ndash; the cache key for the response;\n * - `maxage?: number` &ndash; 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 default 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 = isString(ops.port) ? `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 = isString(addr) ? `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\nlaunchServer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cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AA5Bf;;AAaA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA,SAASkB,aAAaA,CAACC,KAAsB,EAAE;EAC7C,MAAMC,IAAI,GAAG,IAAAC,iBAAQ,EAACF,KAAK,CAAC;EAC5B,IAAI,IAAAG,iBAAQ,EAACF,IAAI,CAAC,EAAE,OAAOA,IAAI,CAAC,CAAC;EACjC,IAAI,CAAC,IAAAG,iBAAQ,EAACH,IAAI,CAAC,EAAE,OAAOD,KAAK,CAAC,CAAC;EACnC,OAAO,KAAK;AACd;AAYA;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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AAM,CAAEa,KAAK,CAAC,GAAGE,IAAI,+BAA+B,CAAC;QACzD,OAAOpB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAK,YAAY;QACfzB,GAAG,CAACO,MAAM,CAAEa,KAAK,CAAC,GAAGE,IAAI,oBAAoB,CAAC;QAC9C,OAAOpB,OAAO,CAACuB,IAAI,CAAC,CAAC,CAAC;MACxB,KAAKC,SAAS;MACd;QACE,MAAMN,KAAK;IACf;EACF,CAAC,CAAC;;EAEF;EACAP,UAAU,CAACM,EAAE,CAAC,WAAW,EAAE,MAAM;IAC/B,MAAMQ,IAAI,GAAGd,UAAU,CAACe,OAAO,CAAC,CAAE;IAClC,MAAMN,IAAI,GAAG,IAAAC,iBAAQ,EAACI,IAAI,CAAC,GAAG,QAAQA,IAAI,EAAE,GAAG,QAAQA,IAAI,CAAClC,IAAI,EAAE;IAClEO,GAAG,CAACO,MAAM,CAAEsB,IAAI,CAAC,uBAAuBP,IAAI,OAC1CpB,OAAO,CAACC,GAAG,CAAC2B,QAAQ,OAAO,CAAC;EAChC,CAAC,CAAC;EAEFjB,UAAU,CAACkB,MAAM,CAAC/B,GAAG,CAACP,IAAI,CAAC;EAE3B,OAAO;IACLkB,aAAa;IACbE;EACF,CAAC;AACH;AAEAhB,YAAY,CAACmC,gBAAgB,GAAGA,0BAAgB;AAChDnC,YAAY,CAACoC,qBAAqB,GAAGA,6BAAqB;AAC1DpC,YAAY,CAACqC,MAAM,GAAGA,aAAM","ignoreList":[]}
@@ -15,7 +15,13 @@ var _nodeZlib = require("node:zlib");
15
15
  var _winston = _interopRequireDefault(require("winston"));
16
16
  var _reactGlobalState = require("@dr.pogodin/react-global-state");
17
17
  var _jsUtils = require("@dr.pogodin/js-utils");
18
- var _lodash = require("lodash");
18
+ var _clone = _interopRequireDefault(require("lodash/clone"));
19
+ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
20
+ var _defaults = _interopRequireDefault(require("lodash/defaults"));
21
+ var _get = _interopRequireDefault(require("lodash/get"));
22
+ var _isString = _interopRequireDefault(require("lodash/isString"));
23
+ var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
24
+ var _omit = _interopRequireDefault(require("lodash/omit"));
19
25
  var _config = _interopRequireDefault(require("config"));
20
26
  var _nodeForge = _interopRequireDefault(require("node-forge"));
21
27
  var _static = require("react-dom/static");
@@ -29,7 +35,7 @@ var _jsxRuntime = require("react/jsx-runtime");
29
35
  * ExpressJS middleware for server-side rendering of a ReactJS app.
30
36
  */
31
37
 
32
- const sanitizedConfig = (0, _lodash.omit)(_config.default, 'SECRET');
38
+ const sanitizedConfig = (0, _omit.default)(_config.default, 'SECRET');
33
39
 
34
40
  // Note: These type definitions for logger are copied from Winston logger,
35
41
  // then simplified to make it easier to fit an alternative logger into this
@@ -39,6 +45,7 @@ const sanitizedConfig = (0, _lodash.omit)(_config.default, 'SECRET');
39
45
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
40
46
 
41
47
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
48
+
42
49
  let SCRIPT_LOCATIONS = exports.SCRIPT_LOCATIONS = /*#__PURE__*/function (SCRIPT_LOCATIONS) {
43
50
  SCRIPT_LOCATIONS["BODY_OPEN"] = "BODY_OPEN";
44
51
  SCRIPT_LOCATIONS["DEFAULT"] = "DEFAULT";
@@ -49,12 +56,11 @@ class ServerSsrContext extends _reactGlobalState.SsrContext {
49
56
  chunks = [];
50
57
  status = 200;
51
58
  constructor(req, chunkGroups, initialState) {
52
- super((0, _lodash.cloneDeep)(initialState) ?? {});
59
+ super((0, _cloneDeep.default)(initialState) ?? {});
53
60
  this.chunkGroups = chunkGroups;
54
61
  this.req = req;
55
62
  }
56
63
  }
57
- exports.ServerSsrContext = ServerSsrContext;
58
64
  /**
59
65
  * Reads build-time information about the app. This information is generated
60
66
  * by our standard Webpack config for apps, and it is written into
@@ -64,6 +70,7 @@ exports.ServerSsrContext = ServerSsrContext;
64
70
  * @param context Webpack context path used during the build.
65
71
  * @return Resolves to the build-time information.
66
72
  */
73
+ exports.ServerSsrContext = ServerSsrContext;
67
74
  function getBuildInfo(context) {
68
75
  const url = _nodePath.default.resolve(context, '.build-info');
69
76
  return JSON.parse(_nodeFs.default.readFileSync(url, 'utf8'));
@@ -154,7 +161,7 @@ function groupExtraScripts(scripts = []) {
154
161
  [SCRIPT_LOCATIONS.HEAD_OPEN]: ''
155
162
  };
156
163
  for (const script of scripts) {
157
- if ((0, _lodash.isString)(script)) {
164
+ if ((0, _isString.default)(script)) {
158
165
  if (script) res[SCRIPT_LOCATIONS.DEFAULT] += script;
159
166
  } else if (script.code) {
160
167
  if (script.location in res) res[script.location] += script.code;else throw Error(`Invalid location "${script.location}"`);
@@ -227,7 +234,7 @@ function newDefaultLogger({
227
234
  * @return Created middleware.
228
235
  */
229
236
  function factory(webpackConfig, options) {
230
- const ops = (0, _lodash.defaults)((0, _lodash.clone)(options), {
237
+ const ops = (0, _defaults.default)((0, _clone.default)(options), {
231
238
  beforeRender: async () => Promise.resolve({}),
232
239
  maxSsrRounds: 10,
233
240
  ssrTimeout: 1000,
@@ -321,9 +328,9 @@ function factory(webpackConfig, options) {
321
328
  // attached to the request (in dev mode), or from a file output during
322
329
  // the build (in prod mode).
323
330
  let chunkGroups;
324
- const webpackStats = (0, _lodash.get)(res.locals, 'webpack.devMiddleware.stats');
331
+ const webpackStats = (0, _get.default)(res.locals, 'webpack.devMiddleware.stats');
325
332
  if (webpackStats) {
326
- chunkGroups = (0, _lodash.mapValues)(webpackStats.toJson({
333
+ chunkGroups = (0, _mapValues.default)(webpackStats.toJson({
327
334
  all: false,
328
335
  chunkGroups: true
329
336
  }).namedChunkGroups, item => item.assets?.map(({