@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.
Files changed (210) hide show
  1. package/babel.scripts.config.js +19 -0
  2. package/bin/build.js +274 -164
  3. package/build/development/client/getInj.js +18 -29
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +11 -14
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/client/init.js +9 -17
  8. package/build/development/client/init.js.map +1 -1
  9. package/build/development/index.js +26 -4
  10. package/build/development/index.js.map +1 -1
  11. package/build/development/server/Cache.js +15 -20
  12. package/build/development/server/Cache.js.map +1 -1
  13. package/build/development/server/index.js +142 -160
  14. package/build/development/server/index.js.map +1 -1
  15. package/build/development/server/renderer.js +150 -197
  16. package/build/development/server/renderer.js.map +1 -1
  17. package/build/development/server/server.js +63 -86
  18. package/build/development/server/server.js.map +1 -1
  19. package/build/development/server/utils/errors.js +72 -87
  20. package/build/development/server/utils/errors.js.map +1 -1
  21. package/build/development/shared/components/Button/index.js +8 -17
  22. package/build/development/shared/components/Button/index.js.map +1 -1
  23. package/build/development/shared/components/Checkbox/index.js +4 -4
  24. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  25. package/build/development/shared/components/GenericLink/index.js +54 -58
  26. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  27. package/build/development/shared/components/Input/index.js +16 -24
  28. package/build/development/shared/components/Input/index.js.map +1 -1
  29. package/build/development/shared/components/Link.js +2 -5
  30. package/build/development/shared/components/Link.js.map +1 -1
  31. package/build/development/shared/components/Modal/index.js +28 -41
  32. package/build/development/shared/components/Modal/index.js.map +1 -1
  33. package/build/development/shared/components/NavLink.js +2 -3
  34. package/build/development/shared/components/NavLink.js.map +1 -1
  35. package/build/development/shared/components/PageLayout/index.js +19 -20
  36. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  37. package/build/development/shared/components/TextArea/index.js +12 -28
  38. package/build/development/shared/components/TextArea/index.js.map +1 -1
  39. package/build/development/shared/components/Throbber/index.js +11 -12
  40. package/build/development/shared/components/Throbber/index.js.map +1 -1
  41. package/build/development/shared/components/WithTooltip/Tooltip.js +46 -68
  42. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  43. package/build/development/shared/components/WithTooltip/index.js +21 -28
  44. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  45. package/build/development/shared/components/YouTubeVideo/index.js +21 -25
  46. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  47. package/build/development/shared/components/index.js +1 -3
  48. package/build/development/shared/components/index.js.map +1 -1
  49. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +6 -7
  50. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  51. package/build/development/shared/components/selectors/CustomDropdown/index.js +7 -9
  52. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  53. package/build/development/shared/components/selectors/NativeDropdown/index.js +23 -27
  54. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  55. package/build/development/shared/components/selectors/Switch/index.js +4 -4
  56. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  57. package/build/development/shared/components/selectors/common.js +2 -5
  58. package/build/development/shared/components/selectors/common.js.map +1 -1
  59. package/build/development/shared/utils/config.js +11 -15
  60. package/build/development/shared/utils/config.js.map +1 -1
  61. package/build/development/shared/utils/globalState.js +1 -7
  62. package/build/development/shared/utils/globalState.js.map +1 -1
  63. package/build/development/shared/utils/index.js +2 -2
  64. package/build/development/shared/utils/index.js.map +1 -1
  65. package/build/development/shared/utils/isomorphy/buildInfo.js +15 -24
  66. package/build/development/shared/utils/isomorphy/buildInfo.js.map +1 -1
  67. package/build/development/shared/utils/isomorphy/environment-check.js +4 -9
  68. package/build/development/shared/utils/isomorphy/environment-check.js.map +1 -1
  69. package/build/development/shared/utils/isomorphy/index.js +17 -23
  70. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  71. package/build/development/shared/utils/jest/E2eSsrEnv.js +48 -77
  72. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  73. package/build/development/shared/utils/jest/index.js +48 -72
  74. package/build/development/shared/utils/jest/index.js.map +1 -1
  75. package/build/development/shared/utils/splitComponent.js +67 -74
  76. package/build/development/shared/utils/splitComponent.js.map +1 -1
  77. package/build/development/shared/utils/time.js +25 -28
  78. package/build/development/shared/utils/time.js.map +1 -1
  79. package/build/development/shared/utils/webpack.js +22 -29
  80. package/build/development/shared/utils/webpack.js.map +1 -1
  81. package/build/production/client/getInj.js.map +1 -1
  82. package/build/production/client/index.js.map +1 -1
  83. package/build/production/index.js +26 -1
  84. package/build/production/index.js.map +1 -1
  85. package/build/production/server/Cache.js.map +1 -1
  86. package/build/production/server/index.js.map +1 -1
  87. package/build/production/server/renderer.js.map +1 -1
  88. package/build/production/server/server.js.map +1 -1
  89. package/build/production/shared/components/Button/index.js.map +1 -1
  90. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  91. package/build/production/shared/components/GenericLink/index.js +2 -2
  92. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  93. package/build/production/shared/components/Input/index.js.map +1 -1
  94. package/build/production/shared/components/Link.js.map +1 -1
  95. package/build/production/shared/components/Modal/index.js.map +1 -1
  96. package/build/production/shared/components/NavLink.js.map +1 -1
  97. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  98. package/build/production/shared/components/TextArea/index.js.map +1 -1
  99. package/build/production/shared/components/Throbber/index.js.map +1 -1
  100. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  101. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  102. package/build/production/shared/components/index.js.map +1 -1
  103. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  104. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  105. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  106. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  107. package/build/production/shared/utils/config.js.map +1 -1
  108. package/build/production/shared/utils/index.js.map +1 -1
  109. package/build/production/shared/utils/jest/index.js.map +1 -1
  110. package/build/production/shared/utils/splitComponent.js +20 -3
  111. package/build/production/shared/utils/splitComponent.js.map +1 -1
  112. package/build/production/shared/utils/time.js.map +1 -1
  113. package/build/production/shared/utils/webpack.js.map +1 -1
  114. package/build/types-code/shared/components/GenericLink/index.d.ts +0 -1
  115. package/build/web/client/getInj.js +10 -70
  116. package/build/web/client/getInj.js.map +1 -1
  117. package/build/web/client/index.js +2 -27
  118. package/build/web/client/index.js.map +1 -1
  119. package/build/web/client/init.js +10 -44
  120. package/build/web/client/init.js.map +1 -1
  121. package/build/web/index.js +26 -6
  122. package/build/web/index.js.map +1 -1
  123. package/build/web/server/Cache.js +3 -41
  124. package/build/web/server/Cache.js.map +1 -1
  125. package/build/web/server/index.js +7 -78
  126. package/build/web/server/index.js.map +1 -1
  127. package/build/web/server/renderer.js +61 -420
  128. package/build/web/server/renderer.js.map +1 -1
  129. package/build/web/server/server.js +38 -212
  130. package/build/web/server/server.js.map +1 -1
  131. package/build/web/server/utils/errors.js +9 -48
  132. package/build/web/server/utils/errors.js.map +1 -1
  133. package/build/web/server/utils/index.js +1 -2
  134. package/build/web/server/utils/index.js.map +1 -1
  135. package/build/web/shared/components/Button/index.js +12 -101
  136. package/build/web/shared/components/Button/index.js.map +1 -1
  137. package/build/web/shared/components/Checkbox/index.js +1 -40
  138. package/build/web/shared/components/Checkbox/index.js.map +1 -1
  139. package/build/web/shared/components/Checkbox/theme.scss +1 -0
  140. package/build/web/shared/components/GenericLink/index.js +12 -65
  141. package/build/web/shared/components/GenericLink/index.js.map +1 -1
  142. package/build/web/shared/components/GenericLink/style.scss +1 -0
  143. package/build/web/shared/components/Input/index.js +11 -69
  144. package/build/web/shared/components/Input/index.js.map +1 -1
  145. package/build/web/shared/components/Link.js +2 -12
  146. package/build/web/shared/components/Link.js.map +1 -1
  147. package/build/web/shared/components/Modal/index.js +10 -130
  148. package/build/web/shared/components/Modal/index.js.map +1 -1
  149. package/build/web/shared/components/NavLink.js +2 -10
  150. package/build/web/shared/components/NavLink.js.map +1 -1
  151. package/build/web/shared/components/PageLayout/index.js +2 -27
  152. package/build/web/shared/components/PageLayout/index.js.map +1 -1
  153. package/build/web/shared/components/TextArea/index.js +21 -106
  154. package/build/web/shared/components/TextArea/index.js.map +1 -1
  155. package/build/web/shared/components/Throbber/index.js +2 -24
  156. package/build/web/shared/components/Throbber/index.js.map +1 -1
  157. package/build/web/shared/components/WithTooltip/Tooltip.js +16 -145
  158. package/build/web/shared/components/WithTooltip/Tooltip.js.map +1 -1
  159. package/build/web/shared/components/WithTooltip/index.js +12 -104
  160. package/build/web/shared/components/WithTooltip/index.js.map +1 -1
  161. package/build/web/shared/components/YouTubeVideo/index.js +5 -43
  162. package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
  163. package/build/web/shared/components/index.js +1 -15
  164. package/build/web/shared/components/index.js.map +1 -1
  165. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js +6 -81
  166. package/build/web/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  167. package/build/web/shared/components/selectors/CustomDropdown/index.js +7 -122
  168. package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  169. package/build/web/shared/components/selectors/NativeDropdown/index.js +7 -68
  170. package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  171. package/build/web/shared/components/selectors/Switch/index.js +1 -49
  172. package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
  173. package/build/web/shared/components/selectors/common.js +1 -10
  174. package/build/web/shared/components/selectors/common.js.map +1 -1
  175. package/build/web/shared/components/selectors/index.js +1 -3
  176. package/build/web/shared/components/selectors/index.js.map +1 -1
  177. package/build/web/shared/utils/config.js +6 -40
  178. package/build/web/shared/utils/config.js.map +1 -1
  179. package/build/web/shared/utils/globalState.js +2 -11
  180. package/build/web/shared/utils/globalState.js.map +1 -1
  181. package/build/web/shared/utils/index.js +1 -9
  182. package/build/web/shared/utils/index.js.map +1 -1
  183. package/build/web/shared/utils/isomorphy/buildInfo.js +4 -25
  184. package/build/web/shared/utils/isomorphy/buildInfo.js.map +1 -1
  185. package/build/web/shared/utils/isomorphy/environment-check.js +3 -9
  186. package/build/web/shared/utils/isomorphy/environment-check.js.map +1 -1
  187. package/build/web/shared/utils/isomorphy/index.js +5 -27
  188. package/build/web/shared/utils/isomorphy/index.js.map +1 -1
  189. package/build/web/shared/utils/jest/E2eSsrEnv.js +51 -221
  190. package/build/web/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  191. package/build/web/shared/utils/jest/global.js +1 -3
  192. package/build/web/shared/utils/jest/global.js.map +1 -1
  193. package/build/web/shared/utils/jest/index.js +27 -146
  194. package/build/web/shared/utils/jest/index.js.map +1 -1
  195. package/build/web/shared/utils/splitComponent.js +34 -197
  196. package/build/web/shared/utils/splitComponent.js.map +1 -1
  197. package/build/web/shared/utils/time.js +5 -69
  198. package/build/web/shared/utils/time.js.map +1 -1
  199. package/build/web/shared/utils/webpack.js +6 -53
  200. package/build/web/shared/utils/webpack.js.map +1 -1
  201. package/config/babel/webpack.js +1 -1
  202. package/eslint.config.mjs +1 -0
  203. package/package.json +5 -8
  204. package/config/webpack/lib-base.d.ts +0 -22
  205. package/config/webpack/lib-base.js +0 -167
  206. package/config/webpack/lib-development.d.ts +0 -5
  207. package/config/webpack/lib-development.js +0 -35
  208. package/config/webpack/lib-production.d.ts +0 -5
  209. package/config/webpack/lib-production.js +0 -42
  210. package/webpack.config.ts +0 -49
@@ -0,0 +1,19 @@
1
+ // Babel config for compilation of helper scripts (bin-ts-src > bin).
2
+
3
+ /* global module */
4
+
5
+ module.exports = {
6
+ plugins: [
7
+ ['@babel/transform-runtime', { useESModules: true }],
8
+ ],
9
+ presets: [
10
+ ['@babel/env', {
11
+ bugfixes: true,
12
+ corejs: '3.49',
13
+ modules: false,
14
+ targets: 'maintained node versions',
15
+ useBuiltIns: 'usage',
16
+ }],
17
+ '@babel/typescript',
18
+ ],
19
+ };
package/bin/build.js CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /* eslint-disable no-console, import/no-extraneous-dependencies */
4
- /* global console, process */
5
-
4
+ //* global console, process */
5
+ import "core-js/modules/es.iterator.constructor.js";
6
+ import "core-js/modules/es.iterator.for-each.js";
7
+ import "core-js/modules/es.iterator.map.js";
8
+ import "core-js/modules/es.json.stringify.js";
6
9
  import childProcess from 'node:child_process';
7
10
  import fs from 'node:fs';
8
11
  import { createRequire } from 'node:module';
9
12
  import path from 'node:path';
10
-
11
- import { program } from 'commander';
12
13
  import { mapValues, merge } from 'lodash-es';
13
14
 
14
15
  // TODO: Disabled, because ESLint still does not support "exports" declarations
@@ -16,221 +17,330 @@ import { mapValues, merge } from 'lodash-es';
16
17
  // See: https://github.com/import-js/eslint-plugin-import/issues/1810
17
18
  // and update, once that issue is resolved.
18
19
  import { rimraf } from 'rimraf';
20
+ import withWebpackBuild from 'webpack';
19
21
 
20
- import webpack from 'webpack';
21
-
22
+ // TODO: Double-check, do we need it still? Can we do something better?
22
23
  // To support TS configs for Webpack.
24
+ // @ts-expect-error "No types for this module exist yet"
23
25
  import register from '@babel/register/experimental-worker.js';
24
-
25
- const BUILD_TYPES = {
26
- DEVELOPMENT: 'development',
27
- PRODUCTION: 'production',
28
- };
29
-
30
- const VALID_BUILD_TYPES = Object.values(BUILD_TYPES);
31
-
26
+ import { program } from '@commander-js/extra-typings';
27
+ const validBuildTypes = ['app-development', 'app-production', 'library'];
32
28
  /**
33
29
  * Auxiliary wrapper around the command execution in a child process.
34
30
  *
35
31
  * TODO: Move to a server-side unitility module.
36
32
  * TODO: The same code is duplicated in one of the tests.
37
- * @ignore
38
- * @param {String} command Command to execute;
39
- * @param {Object} [options] See https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
40
- * @return {Promise} Resolves to { error, stdout, stderr }.
33
+ *
34
+ * @param command - Command to execute;
35
+ * @param options - See https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
36
+ * @return Resolves to { error, stdout, stderr }.
41
37
  */
42
38
  async function exec(command, options = {}) {
43
- return await new Promise((resolve) => {
44
- const child = childProcess.exec(
45
- command,
46
- options,
47
- (...args) => resolve(args),
48
- );
49
- child.stderr.pipe(process.stderr);
50
- child.stdout.pipe(process.stdout);
39
+ return await new Promise(resolve => {
40
+ const child = childProcess.exec(command, options, (error, stdout, stderr) => {
41
+ resolve({
42
+ error,
43
+ stderr,
44
+ stdout
45
+ });
46
+ });
47
+ child.stderr?.pipe(process.stderr);
48
+ child.stdout?.pipe(process.stdout);
51
49
  });
52
50
  }
53
51
 
54
52
  /* Command-line config. */
55
- program
56
- .description('Library build script')
57
- .option(
58
- '-t, --build-type <type>',
59
- `build type: ${VALID_BUILD_TYPES.join(', ')}`,
60
- )
61
- .option('-c, --copy-files <regex>', 'copy files matching the pattern into the build folder')
62
- .option('-i, --in-dir <path>', 'input folder for the build', 'src')
63
- .option('--lib', 'library build', false)
64
- .option('--no-babel', 'opts out the Babel (server-side code) build')
65
- .option('--no-webpack', 'opts out the Webpack (client-side code) build')
66
- .option('-o, --out-dir <path>', 'output folder for the build', 'build')
67
- .option('-w, --watch', 'build, watch, and rebuild on source changes')
68
- .option('--babel-config <path>', 'path to the Babel config')
69
- .option(
70
- '--webpack-config <path>',
71
- 'path to the webpack config',
72
- 'webpack.config.js',
73
- );
74
-
75
- program.parse(process.argv);
76
- const cmdLineArgs = program.opts();
77
-
78
- const { buildType } = cmdLineArgs;
79
-
53
+ const args = program.description('Application / library build script').requiredOption('-t, --build-type <type>', `build type: ${validBuildTypes.map(type => `"${type}"`).join(', ')}`).option('-c, --copy-files <regex>', 'copy files matching the pattern into the build folder').option('-i, --in-dir <path>', 'input folder for the build', 'src').option('-o, --out-dir <path>', 'output folder for the build', 'build').option('-w, --watch', 'build, watch, and rebuild on source changes').option('--webpack-config <path>', 'path to the webpack config', 'webpack.config.ts').parse(process.argv).opts();
80
54
  if (program.args.length) {
81
- const details = program.args.map((x) => `\t${x}`).join('\n');
55
+ const details = program.args.map(x => `\t${x}`).join('\n');
82
56
  program.error(`Unrecognized arguments:\n${details}`);
83
57
  }
84
58
 
85
- /* Validates the build type argument, */
86
- if (!VALID_BUILD_TYPES.includes(buildType)) {
87
- throw new Error('Invalid build type');
59
+ /**
60
+ * Asserts the given string is a valid build type.
61
+ */
62
+ function assertBuildType(buildType) {
63
+ if (!validBuildTypes.includes(buildType)) {
64
+ throw Error('Unknown build type');
65
+ }
88
66
  }
89
67
 
90
68
  /* Resolves the target build directory. */
91
69
  const cwd = process.cwd();
92
- const inDir = path.resolve(cwd, cmdLineArgs.inDir);
93
-
94
- let outDir = path.resolve(cwd, cmdLineArgs.outDir);
95
- if (cmdLineArgs.lib) outDir += `/${buildType}`;
70
+ const buildDir = path.resolve(cwd, args.outDir);
71
+ const sourceDir = path.resolve(cwd, args.inDir);
96
72
 
97
73
  /* Prepares output directory: cleans existing files, creates the folders. */
98
- rimraf.sync(outDir);
99
- fs.mkdirSync(outDir, { recursive: true });
100
-
101
- /* ************************************************************************** */
102
- /* Webpack compilation of isomorphic library bundle. */
103
-
104
- register({
105
- envName: 'production',
106
- extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
107
- root: process.cwd(),
74
+ rimraf.sync(buildDir);
75
+ fs.mkdirSync(buildDir, {
76
+ recursive: true
108
77
  });
109
78
 
110
- const require = createRequire(import.meta.url);
111
-
112
- // eslint-disable-next-line import/no-dynamic-require
113
- let webpackConfig = require(path.resolve(cwd, cmdLineArgs.webpackConfig));
114
- if ('default' in webpackConfig) webpackConfig = webpackConfig.default;
115
- if (typeof webpackConfig === 'function') webpackConfig = webpackConfig(buildType);
79
+ /**
80
+ * The build of TypeScript types for TS code modules.
81
+ *
82
+ * For now, it relies on the standard names of configuration files.
83
+ */
84
+ async function buildCodeTypes() {
85
+ console.log('Building code types...');
86
+ await exec(`${cwd}/node_modules/.bin/tsc --project tsconfig.types.json`);
87
+ await exec(`${cwd}/node_modules/.bin/tsc-alias -p tsconfig.types.json`);
88
+ }
116
89
 
117
- let webpackOutDir = outDir;
118
- if (!cmdLineArgs.lib) webpackOutDir += '/web-public';
90
+ /**
91
+ * The build of TypeScript types for SCSS modules.
92
+ *
93
+ * As of now, all configuration comes from the "typed-scss-modules.config.ts"
94
+ * file, and we just assume it exists, and has a valid config, matching other
95
+ * configurations passed into this script, or selected automatically.
96
+ */
97
+ async function buildScssTypes() {
98
+ console.log('Building SCSS types...');
99
+ await exec(`${cwd}/node_modules/.bin/typed-scss-modules .`);
100
+ }
101
+ let isRequireUpgraded = false;
102
+ const webpackOutDir = `${buildDir}/web-public`;
119
103
 
120
- merge(webpackConfig, {
121
- output: { path: webpackOutDir },
122
- });
104
+ /**
105
+ * Creates a new Webpack compiler.
106
+ */
107
+ function newWebpackCompiler() {
108
+ if (!isRequireUpgraded) {
109
+ isRequireUpgraded = true;
110
+
111
+ // TODO: We don't have types for this function, see a related comment
112
+ // earlier.
113
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
114
+ register({
115
+ envName: 'production',
116
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
117
+ root: process.cwd()
118
+ });
119
+ }
120
+ const require = createRequire(import.meta.url);
121
+
122
+ // TODO: Search harder, perhaps such types are already declared by Webpack?
123
+
124
+ // TODO: Can we actually assert the input is a correct Webpack configuration?
125
+ // eslint-disable-next-line import/no-dynamic-require
126
+ const configFile = require(path.resolve(cwd, args.webpackConfig));
127
+ const configOrFactory = 'default' in configFile ? configFile.default : configFile;
128
+ if (!args.buildType) throw Error('Build type must be specified for Webpack build');
129
+ assertBuildType(args.buildType);
130
+ let webpackEnv;
131
+ switch (args.buildType) {
132
+ case 'app-development':
133
+ webpackEnv = 'development';
134
+ break;
135
+ case 'app-production':
136
+ webpackEnv = 'production';
137
+ break;
138
+ case 'library':
139
+ default:
140
+ throw Error('Unexpected build type');
141
+ }
142
+ const config = typeof configOrFactory === 'function' ? configOrFactory(webpackEnv) : configOrFactory;
143
+ merge(config, {
144
+ output: {
145
+ path: webpackOutDir
146
+ }
147
+ });
148
+ const webpackCompiler = withWebpackBuild(config);
123
149
 
124
- const webpackCompiler = webpack(webpackConfig);
150
+ // TODO: Do we need to connect it some other way to
151
+ // output progress with Webpack@5?
152
+ // webpackCompiler.apply(new webpack.ProgressPlugin());
125
153
 
126
- // TODO: Do we need to connect it some other way to
127
- // output progress with Webpack@5?
128
- // webpackCompiler.apply(new webpack.ProgressPlugin());
154
+ return webpackCompiler;
155
+ }
129
156
 
130
157
  /**
131
158
  * The handler of Webpack compilation results, written according to Webpack docs
132
159
  * https://webpack.js.org/api/node/#error-handling
133
- * @ignore
134
- * @param {Object} error
135
- * @param {Object} stats
160
+ * @param error
161
+ * @param stats
136
162
  */
137
163
  function handleWebpackCompilationResults(error, stats) {
164
+ assertBuildType(args.buildType);
138
165
  if (error) {
139
- console.error(error.stack || error);
140
- if (error.details) console.error(error.details);
141
- if (buildType !== BUILD_TYPES.DEVELOPMENT) {
142
- process.exitCode = 1;
143
- return;
144
- }
166
+ console.error(error.stack ?? error);
167
+ if (error.message) console.error(error.message);
168
+ process.exitCode = 1;
169
+ return;
145
170
  }
146
-
147
- const info = stats.toJson();
148
- if (stats.hasErrors()) {
149
- console.error('Error defailts:', info.errors);
150
- if (buildType !== BUILD_TYPES.DEVELOPMENT) {
151
- process.exitCode = 1;
152
- return;
153
- }
171
+ const info = stats?.toJson();
172
+ if (stats?.hasErrors()) {
173
+ console.error('Error defailts:', info?.errors);
174
+ process.exitCode = 1;
175
+ return;
154
176
  }
155
- if (stats.hasWarnings()) console.warn(info.warnings);
156
-
157
- console.log(stats.toString({ colors: true }));
177
+ if (stats?.hasWarnings()) console.warn(info?.warnings);
178
+ console.log(stats?.toString({
179
+ colors: true
180
+ }));
158
181
 
159
182
  // Here we emit the mapping of named chunk groups, needed at runtime
160
183
  // for SSR and code-splitting.
161
- const chunks = mapValues(
162
- stats.toJson({ all: false, chunkGroups: true }).namedChunkGroups,
163
- (item) => item.assets.map(({ name }) => name),
164
- );
165
- fs.writeFileSync(
166
- `${webpackOutDir}/__chunk_groups__.json`,
167
- JSON.stringify(chunks, null, 2),
168
- );
184
+ const chunks = mapValues(stats?.toJson({
185
+ all: false,
186
+ chunkGroups: true
187
+ }).namedChunkGroups, item => item.assets?.map(({
188
+ name
189
+ }) => name));
190
+ fs.writeFileSync(`${webpackOutDir}/__chunk_groups__.json`, JSON.stringify(chunks, null, 2));
169
191
  }
170
192
 
171
- if (cmdLineArgs.webpack) {
172
- if (cmdLineArgs.watch) {
173
- webpackCompiler.watch({}, handleWebpackCompilationResults);
174
- } else {
175
- webpackCompiler.run(handleWebpackCompilationResults);
176
- webpackCompiler.close(() => null);
193
+ /**
194
+ * Builds the app bundle for web.
195
+ */
196
+ function buildWebBundle() {
197
+ const webpackCompiler = newWebpackCompiler();
198
+ webpackCompiler.run(handleWebpackCompilationResults);
199
+ webpackCompiler.close(() => undefined);
200
+ }
201
+ /**
202
+ * Runs Babel compilation.
203
+ * @param buildType - Build type; one of the BUILD_TYPES values.
204
+ * @param configPath - Optional. Path to the config file.
205
+ * If relative, it will be resolved relative to the current working directory.
206
+ * If absent, Babel will try to locate the default config file its usual way.
207
+ * @param extensions - Optional. Array of extensions
208
+ * to transform, each starting with the leading dot (e.g. '.ts'). If absent,
209
+ * Babel will use its default set of extensions.
210
+ * @param keepFileExtensions - Optional. If set, Babel will
211
+ * keep the original extensions for the transformed files; otherwise the will
212
+ * be turned into '.js' files.
213
+ * @param outDir - Output folder.
214
+ * @param srcDir - Source folder.
215
+ * @param watch - Optional. If set, Babel will be run in watch
216
+ * mode.
217
+ */
218
+ async function runBabel({
219
+ buildType,
220
+ configPath,
221
+ copyFiles,
222
+ extensions,
223
+ keepFileExtensions,
224
+ outDir,
225
+ srcDir,
226
+ watch
227
+ }) {
228
+ let command = `${cwd}/node_modules/.bin/babel ${srcDir} --out-dir ${outDir} --source-maps`;
229
+ if (buildType === 'production') command += ' --minified';
230
+ if (configPath) {
231
+ const url = path.resolve(cwd, configPath);
232
+ command += ` --config-file ${url}`;
177
233
  }
234
+ if (copyFiles) command += ' --copy-files';
235
+ command += ` -x ${extensions.join(',')}`;
236
+ if (keepFileExtensions) command += ' --keep-file-extension';
237
+ if (watch) command += ' --watch';
238
+ await exec(command, {
239
+ env: {
240
+ ...process.env,
241
+ BABEL_ENV: buildType
242
+ }
243
+ });
178
244
  }
179
245
 
180
- /* ************************************************************************** */
181
- /* Babel compilation of JS, JSX, and SVG files. */
182
-
183
- // TODO: It needs an option to build TS project, and use TypeScript in that case
184
- // to do TypeScript build with "tsc".
185
-
186
- const BABEL_EXEC_OPTIONS = {
187
- env: { ...process.env, BABEL_ENV: buildType },
188
- };
189
-
190
- let BABEL_CMD_BASE = `${cwd}/node_modules/.bin/babel`;
191
- BABEL_CMD_BASE += ` ${inDir} --out-dir ${outDir} --source-maps`;
192
- if (buildType === BUILD_TYPES.PRODUCTION) BABEL_CMD_BASE += ' --minified';
193
-
194
- if (cmdLineArgs.babelConfig) {
195
- const url = path.resolve(cwd, cmdLineArgs.babelConfig);
196
- BABEL_CMD_BASE += ` --config-file ${url}`;
246
+ /**
247
+ * Builds the "intermediate" library code with Babel. Essentially, it compiles
248
+ * out TypeScript, and produces JavaScript code which should be further compiled
249
+ * with Babel for server-side use, or bundled with Webpack for client-side
250
+ * execution. Any non-TS assets in the source are copied over to the build
251
+ * folder, conserving their location relative to the source / build folder root.
252
+ * @param watch
253
+ */
254
+ async function buildLibIntermediates(watch) {
255
+ if (!watch) console.log('Building library intermediates...');
256
+ await runBabel({
257
+ buildType: 'production',
258
+ configPath: './babel.libweb.config.js',
259
+ copyFiles: true,
260
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
261
+ outDir: `${buildDir}/web`,
262
+ srcDir: sourceDir,
263
+ watch
264
+ });
197
265
  }
198
-
199
- /* TODO: The watch is deactivated for Babel compilation because of SVG files:
200
- * currently there is no way to tell Babel that SVG files should be compiled
201
- * keeping their SVG extensions, while JS and JSX are compiled with extensions
202
- * turned into JS, and any other files should be just copied over. For non-watch
203
- * builds it is not a grave problem, as we can do two passes: first compiling
204
- * JS, JSX, and copying all other files; then the second pass to compile SVG
205
- * files keeping extensions. */
206
- /*
207
- if (cmdLineArgs.watch) BABEL_CMD_JS += ' --watch';
208
- */
209
-
210
- const BABEL_CMD_JS = `${BABEL_CMD_BASE} -x .js,.jsx,.ts,.tsx`;
211
- const BABEL_CMD_SVG = `${BABEL_CMD_BASE} --extensions ".svg" --keep-file-extension`;
212
-
213
- async function babelBuild() {
214
- await exec(BABEL_CMD_JS, BABEL_EXEC_OPTIONS);
215
- await exec(BABEL_CMD_SVG, BABEL_EXEC_OPTIONS);
266
+ /**
267
+ * Builds with Babel the library code for server-side environment.
268
+ */
269
+ async function buildWithBabelForServerSide({
270
+ buildType,
271
+ configPath,
272
+ outDir,
273
+ srcDir
274
+ }) {
275
+ console.log(`Building with Babel for server-side environment in "${buildType}" mode...`);
276
+ await runBabel({
277
+ buildType,
278
+ configPath,
279
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
280
+ outDir,
281
+ srcDir
282
+ });
283
+ await runBabel({
284
+ buildType,
285
+ configPath,
286
+ extensions: ['.svg'],
287
+ keepFileExtensions: true,
288
+ outDir,
289
+ srcDir
290
+ });
216
291
  }
217
292
 
218
- if (cmdLineArgs.babel) babelBuild();
219
-
220
- // If opted, copy files matching the pattern into the build folder.
221
-
293
+ /**
294
+ * Copies the files matching the pattern into the build folder.
295
+ */
222
296
  function copyFromFolder(from, to, regex) {
223
- fs.readdirSync(from, { withFileTypes: true }).forEach((item) => {
297
+ console.log('Copying files...');
298
+ fs.readdirSync(from, {
299
+ withFileTypes: true
300
+ }).forEach(item => {
224
301
  if (item.isDirectory()) {
225
302
  copyFromFolder(`${from}/${item.name}`, `${to}/${item.name}`, regex);
226
303
  } else if (item.isFile() && item.name.match(regex)) {
227
- fs.mkdirSync(to, { recursive: true });
304
+ fs.mkdirSync(to, {
305
+ recursive: true
306
+ });
228
307
  fs.copyFileSync(`${from}/${item.name}`, `${to}/${item.name}`);
229
308
  }
230
309
  });
231
310
  }
232
-
233
- if (cmdLineArgs.copyFiles) {
234
- const regex = new RegExp(cmdLineArgs.copyFiles);
235
- copyFromFolder(inDir, outDir, regex);
236
- }
311
+ void (async () => {
312
+ assertBuildType(args.buildType);
313
+ await buildScssTypes();
314
+ if (args.buildType === 'library') {
315
+ await buildCodeTypes();
316
+ await buildLibIntermediates();
317
+ await buildWithBabelForServerSide({
318
+ buildType: 'development',
319
+ configPath: 'babel.module.config.js',
320
+ outDir: `${buildDir}/development`,
321
+ srcDir: `${buildDir}/web`
322
+ });
323
+ await buildWithBabelForServerSide({
324
+ buildType: 'production',
325
+ configPath: 'babel.module.config.js',
326
+ outDir: `${buildDir}/production`,
327
+ srcDir: `${buildDir}/web`
328
+ });
329
+ }
330
+ if (args.buildType === 'app-development' || args.buildType === 'app-production') {
331
+ await buildWithBabelForServerSide({
332
+ buildType: 'development',
333
+ outDir: buildDir,
334
+ srcDir: sourceDir
335
+ });
336
+ buildWebBundle();
337
+ }
338
+ if (args.copyFiles) {
339
+ const regex = new RegExp(args.copyFiles);
340
+ copyFromFolder(sourceDir, buildDir, regex);
341
+ }
342
+ if (args.watch) {
343
+ console.log('Enabling the watch mode...');
344
+ if (args.buildType === 'library') await buildLibIntermediates(true);
345
+ }
346
+ })();
@@ -4,33 +4,28 @@ import "core-js/modules/es.array-buffer.transfer-to-fixed-length.js";
4
4
  import "core-js/modules/es.typed-array.to-reversed.js";
5
5
  import "core-js/modules/es.typed-array.to-sorted.js";
6
6
  import "core-js/modules/es.typed-array.with.js";
7
- import "core-js/modules/web.dom-exception.stack.js";
8
- // Encapsulates retrieval of server-side data injection into HTML template.
9
-
7
+ import "core-js/modules/web.dom-exception.stack.js"; // Encapsulates retrieval of server-side data injection into HTML template.
10
8
  /* global document */
11
-
12
- import { SEC_MS, timer } from '@dr.pogodin/js-utils';
9
+ import { SEC_MS, timer } from "@dr.pogodin/js-utils";
13
10
  import { getBuildInfo } from "../shared/utils/isomorphy/buildInfo.js";
14
11
  let inj;
15
12
  export default function getInj() {
16
13
  inj ??= (async () => {
17
- const metaElement = typeof document === 'undefined' ? null : document.querySelector('meta[itemprop="drpruinj"]');
14
+ const metaElement = typeof document === "undefined" ? null : document.querySelector("meta[itemprop=\"drpruinj\"]");
18
15
  if (metaElement) {
19
- metaElement.remove();
20
-
21
- // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
16
+ metaElement.remove(); // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be
22
17
  // preferred, but it is not supported by older environments yet.
23
18
  const data = atob(metaElement.content);
24
19
  if (!window.isSecureContext) {
25
- if (window.location.protocol === 'https:') {
26
- throw Error('Loaded via HTTPS, but it is not considered a secure context');
27
- } else if (window.location.protocol !== 'http:') {
28
- throw Error('Unexpected protocol');
20
+ if (window.location.protocol === "https:") {
21
+ throw Error("Loaded via HTTPS, but it is not considered a secure context");
22
+ } else if (window.location.protocol !== "http:") {
23
+ throw Error("Unexpected protocol");
29
24
  }
30
- const target = window.location.href.replace(/^http:/, 'https:');
25
+ const target = window.location.href.replace(/^http:/, "https:");
31
26
  window.location.replace(target);
32
27
  await timer(3 * SEC_MS);
33
- throw Error('Failed to move into secure context');
28
+ throw Error("Failed to move into secure context");
34
29
  }
35
30
  const {
36
31
  key
@@ -39,29 +34,23 @@ export default function getInj() {
39
34
  const dataBuffer = Uint8Array.from(data.slice(16), code);
40
35
  const ivBuffer = Uint8Array.from(data.slice(0, 16), code);
41
36
  const keyBuffer = Uint8Array.from(atob(key), code);
42
- const cKey = await window.crypto.subtle.importKey('raw', keyBuffer, {
43
- name: 'AES-CBC'
44
- }, false, ['decrypt']);
37
+ const cKey = await window.crypto.subtle.importKey("raw", keyBuffer, {
38
+ name: "AES-CBC"
39
+ }, false, ["decrypt"]);
45
40
  const buffer = await window.crypto.subtle.decrypt({
46
41
  iv: ivBuffer,
47
- name: 'AES-CBC'
42
+ name: "AES-CBC"
48
43
  }, cKey, dataBuffer);
49
- const decoder = new TextDecoder();
50
-
51
- // eslint-disable-next-line no-eval
52
- const res = eval(`(${decoder.decode(buffer)})`);
53
-
54
- // NOTE: This is important, to be able to return the injection
44
+ const decoder = new TextDecoder(); // eslint-disable-next-line no-eval
45
+ const res = eval(`(${decoder.decode(buffer)})`); // NOTE: This is important, to be able to return the injection
55
46
  // synchronously once it is initialized.
56
47
  inj = res;
57
48
  return res;
58
- } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
49
+ } else if (typeof window !== "undefined" && window.REACT_UTILS_INJECTION) {
59
50
  const res = window.REACT_UTILS_INJECTION;
60
51
  delete window.REACT_UTILS_INJECTION;
61
52
  return res;
62
- }
63
-
64
- // Otherwise, a bunch of dependent stuff will easily fail in non-standard
53
+ } // Otherwise, a bunch of dependent stuff will easily fail in non-standard
65
54
  // environments, where no client-side initialization is performed. Like tests,
66
55
  // Docusaurus examples, etc.
67
56
  return {};
@@ -1 +1 @@
1
- {"version":3,"file":"getInj.js","names":["SEC_MS","timer","getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","window","isSecureContext","location","protocol","Error","target","href","replace","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","crypto","subtle","importKey","name","buffer","decrypt","iv","decoder","TextDecoder","res","eval","decode","REACT_UTILS_INJECTION"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport { SEC_MS, timer } from '@dr.pogodin/js-utils';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n if (!window.isSecureContext) {\n if (window.location.protocol === 'https:') {\n throw Error('Loaded via HTTPS, but it is not considered a secure context');\n } else if (window.location.protocol !== 'http:') {\n throw Error('Unexpected protocol');\n }\n\n const target = window.location.href.replace(/^http:/, 'https:');\n window.location.replace(target);\n\n await timer(3 * SEC_MS);\n throw Error('Failed to move into secure context');\n }\n\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n return {};\n })();\n\n return inj;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA,SAASA,MAAM,EAAEC,KAAK,QAAQ,sBAAsB;AAAA,SAI3CC,YAAY;AAErB,IAAIC,GAAqC;AAEzC,eAAe,SAASC,MAAMA,CAAA,EAAyB;EACrDD,GAAG,KAAK,CAAC,YAAY;IACnB,MAAME,WAAmC,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MAAMS,IAAI,GAAG,MAAMlB,MAAM,CAACmB,MAAM,CAACC,MAAM,CAACC,SAAS,CAC/C,KAAK,EACLJ,SAAS,EACT;QAAEK,IAAI,EAAE;MAAU,CAAC,EACnB,KAAK,EACL,CAAC,SAAS,CACZ,CAAC;MAED,MAAMC,MAAM,GAAG,MAAMvB,MAAM,CAACmB,MAAM,CAACC,MAAM,CAACI,OAAO,CAAC;QAChDC,EAAE,EAAET,QAAQ;QACZM,IAAI,EAAE;MACR,CAAC,EAAEJ,IAAI,EAAEN,UAAU,CAAC;MAEpB,MAAMc,OAAO,GAAG,IAAIC,WAAW,CAAC,CAAC;;MAEjC;MACA,MAAMC,GAAG,GAAGC,IAAI,CAAC,IAAIH,OAAO,CAACI,MAAM,CAACP,MAAM,CAAC,GAAG,CAAS;;MAEvD;MACA;MACAhC,GAAG,GAAGqC,GAAG;MAET,OAAOA,GAAG;IACZ,CAAC,MAAM,IAAI,OAAO5B,MAAM,KAAK,WAAW,IAAIA,MAAM,CAAC+B,qBAAqB,EAAE;MACxE,MAAMH,GAAG,GAAG5B,MAAM,CAAC+B,qBAAqB;MACxC,OAAO/B,MAAM,CAAC+B,qBAAqB;MACnC,OAAOH,GAAG;IACZ;;IAEA;IACA;IACA;IACA,OAAO,CAAC,CAAC;EACX,CAAC,EAAE,CAAC;EAEJ,OAAOrC,GAAG;AACZ","ignoreList":[]}
1
+ {"version":3,"file":"getInj.js","names":["SEC_MS","timer","getBuildInfo","inj","getInj","metaElement","document","querySelector","remove","data","atob","content","window","isSecureContext","location","protocol","Error","target","href","replace","key","code","x","charCodeAt","dataBuffer","Uint8Array","from","slice","ivBuffer","keyBuffer","cKey","crypto","subtle","importKey","name","buffer","decrypt","iv","decoder","TextDecoder","res","eval","decode","REACT_UTILS_INJECTION"],"sources":["../../../src/client/getInj.ts"],"sourcesContent":["// Encapsulates retrieval of server-side data injection into HTML template.\n\n/* global document */\n\nimport { SEC_MS, timer } from '@dr.pogodin/js-utils';\n\nimport type { InjT } from 'utils/globalState';\n\nimport { getBuildInfo } from 'utils/isomorphy/buildInfo';\n\nlet inj: InjT | Promise<InjT> | undefined;\n\nexport default function getInj(): InjT | Promise<InjT> {\n inj ??= (async () => {\n const metaElement: HTMLMetaElement | null = typeof document === 'undefined'\n ? null : document.querySelector('meta[itemprop=\"drpruinj\"]');\n\n if (metaElement) {\n metaElement.remove();\n\n // NOTE: Since 2025 there is Uint8Array.fromBase64(), which should be\n // preferred, but it is not supported by older environments yet.\n const data = atob(metaElement.content);\n\n if (!window.isSecureContext) {\n if (window.location.protocol === 'https:') {\n throw Error('Loaded via HTTPS, but it is not considered a secure context');\n } else if (window.location.protocol !== 'http:') {\n throw Error('Unexpected protocol');\n }\n\n const target = window.location.href.replace(/^http:/, 'https:');\n window.location.replace(target);\n\n await timer(3 * SEC_MS);\n throw Error('Failed to move into secure context');\n }\n\n const { key } = getBuildInfo();\n\n const code = (x: string) => x.charCodeAt(0);\n const dataBuffer = Uint8Array.from(data.slice(16), code);\n const ivBuffer = Uint8Array.from(data.slice(0, 16), code);\n const keyBuffer = Uint8Array.from(atob(key), code);\n\n const cKey = await window.crypto.subtle.importKey(\n 'raw',\n keyBuffer,\n { name: 'AES-CBC' },\n false,\n ['decrypt'],\n );\n\n const buffer = await window.crypto.subtle.decrypt({\n iv: ivBuffer,\n name: 'AES-CBC',\n }, cKey, dataBuffer);\n\n const decoder = new TextDecoder();\n\n // eslint-disable-next-line no-eval\n const res = eval(`(${decoder.decode(buffer)})`) as InjT;\n\n // NOTE: This is important, to be able to return the injection\n // synchronously once it is initialized.\n inj = res;\n\n return res;\n } else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {\n const res = window.REACT_UTILS_INJECTION;\n delete window.REACT_UTILS_INJECTION;\n return res;\n }\n\n // Otherwise, a bunch of dependent stuff will easily fail in non-standard\n // environments, where no client-side initialization is performed. Like tests,\n // Docusaurus examples, etc.\n return {};\n })();\n\n return inj;\n}\n"],"mappings":";;;;;;oDAAA;A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