@dr.pogodin/react-utils 1.8.5 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build.js +0 -129
- package/bin/release.sh +1 -1
- package/bin/setup.js +0 -44
- package/build/development/client/index.js +0 -6
- package/build/development/client/index.js.map +1 -1
- package/build/development/client/init.js +3 -1
- package/build/development/client/init.js.map +1 -1
- package/build/development/index.js +14 -19
- package/build/development/index.js.map +1 -1
- package/build/development/server/index.js +1 -51
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/renderer.js +10 -4
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/server/server.js +1 -1
- package/build/development/server/utils/errors.js +3 -3
- package/build/development/shared/components/Button/index.js +7 -42
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +7 -14
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/CodeSplit/index.js +9 -66
- package/build/development/shared/components/CodeSplit/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +9 -35
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/GenericLink/index.js +1 -23
- package/build/development/shared/components/GenericLink/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +6 -19
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/MetaTags.js +0 -21
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +5 -39
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/NavLink.js +0 -10
- package/build/development/shared/components/NavLink.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +6 -31
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/ScalableRect/index.js +2 -8
- package/build/development/shared/components/ScalableRect/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +10 -22
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +7 -13
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +9 -15
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +18 -18
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/shared/utils/config.js +0 -22
- package/build/development/shared/utils/config.js.map +1 -1
- package/build/development/shared/utils/index.js +11 -29
- package/build/development/shared/utils/index.js.map +1 -1
- package/build/development/shared/utils/isomorphy.js +3 -44
- package/build/development/shared/utils/isomorphy.js.map +1 -1
- package/build/development/shared/utils/jest.js +12 -126
- package/build/development/shared/utils/jest.js.map +1 -1
- package/build/development/shared/utils/url.js +1 -1
- package/build/development/shared/utils/webpack.js +0 -4
- package/build/development/shared/utils/webpack.js.map +1 -1
- package/build/development/style.css +149 -149
- package/build/development/web.bundle.js +33 -33
- package/build/production/client/index.js +0 -6
- package/build/production/client/index.js.map +1 -1
- package/build/production/client/init.js +2 -1
- package/build/production/client/init.js.map +1 -1
- package/build/production/index.js +2 -11
- package/build/production/index.js.map +1 -1
- package/build/production/server/index.js +1 -49
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/renderer.js +2 -2
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/server/server.js +1 -1
- package/build/production/server/utils/errors.js +1 -1
- package/build/production/shared/components/Button/index.js +2 -37
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +2 -9
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/CodeSplit/index.js +2 -65
- package/build/production/shared/components/CodeSplit/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js +2 -24
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/GenericLink/index.js +1 -23
- package/build/production/shared/components/GenericLink/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +2 -13
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/MetaTags.js +0 -21
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -34
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/NavLink.js +1 -10
- package/build/production/shared/components/NavLink.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -25
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/ScalableRect/index.js +1 -7
- package/build/production/shared/components/ScalableRect/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +2 -13
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +1 -7
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +1 -7
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/shared/utils/config.js +1 -21
- package/build/production/shared/utils/config.js.map +1 -1
- package/build/production/shared/utils/index.js +1 -20
- package/build/production/shared/utils/index.js.map +1 -1
- package/build/production/shared/utils/isomorphy.js +1 -40
- package/build/production/shared/utils/isomorphy.js.map +1 -1
- package/build/production/shared/utils/jest.js +2 -112
- package/build/production/shared/utils/jest.js.map +1 -1
- package/build/production/shared/utils/url.js +1 -1
- package/build/production/shared/utils/webpack.js +0 -4
- package/build/production/shared/utils/webpack.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/config/babel/node-ssr.js +1 -8
- package/config/babel/webpack.js +1 -8
- package/config/jest/default.js +0 -34
- package/config/shared/utils.js +9 -100
- package/config/stylelint/default.js +2 -19
- package/config/webpack/app-base.js +3 -6
- package/config/webpack/app-development.js +0 -23
- package/config/webpack/app-production.js +0 -20
- package/config/webpack/lib-base.js +3 -66
- package/config/webpack/lib-development.js +0 -10
- package/config/webpack/lib-production.js +0 -9
- package/index.js +21 -10
- package/package.json +34 -36
- package/src/index.js +6 -61
- package/src/styles/_mixins/fonts.scss +4 -4
- package/src/styles/mixins.scss +1 -1
- package/build/development/styles/global-docs.js +0 -29
- package/build/development/styles/global-docs.js.map +0 -1
- package/build/development/styles/mixins.js +0 -103
- package/build/development/styles/mixins.js.map +0 -1
- package/build/production/styles/global-docs.js +0 -28
- package/build/production/styles/global-docs.js.map +0 -1
- package/build/production/styles/mixins.js +0 -101
- package/build/production/styles/mixins.js.map +0 -1
- package/config/eslint/docs.js +0 -40
- package/config/jsdoc/config.js +0 -34
- package/src/README.md +0 -130
package/bin/build.js
CHANGED
|
@@ -1,134 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* @category NodeJS Scripts
|
|
5
|
-
* @const react-utils-build
|
|
6
|
-
* @desc
|
|
7
|
-
* NodeJS script encapsulating Babel and Webpack compilation of this library,
|
|
8
|
-
* and of dependant projects. It also provides a working alternative for the
|
|
9
|
-
* `npm link` command.
|
|
10
|
-
*
|
|
11
|
-
* **Why?** There are two reasons:
|
|
12
|
-
* 1. The compilation of this library and its dependant projects follows
|
|
13
|
-
* the same logic: prepare the build output directory, removing any
|
|
14
|
-
* artifacts of previous builds, or creating the folder; bundle
|
|
15
|
-
* the isomorphic package with Webpack; compile the server-side code with
|
|
16
|
-
* Babel. Having the dedicated script which handles it saves us from copying
|
|
17
|
-
* necessary commands between different codebases.
|
|
18
|
-
* 2. `npm link` command does not work well for many packages, including this
|
|
19
|
-
* library. The symbol links created by `npm link` easily break stuff in
|
|
20
|
-
* obscure ways. This script provides the option to watch and build a code
|
|
21
|
-
* into the specified directory. Thus, instead of linking
|
|
22
|
-
* `@dr.pogodin/react-utils`, or another dependency, into a `host-package`,
|
|
23
|
-
* this script allows to build it directly into
|
|
24
|
-
* `host-package/node_modules/@dr.pogodin/react-utils/build` folder,
|
|
25
|
-
* making any changes immediately available to the host package.
|
|
26
|
-
*
|
|
27
|
-
* ### Usage
|
|
28
|
-
* From this library codebase call it as
|
|
29
|
-
* ```bash
|
|
30
|
-
* $ ./bin/build.js -h
|
|
31
|
-
* ```
|
|
32
|
-
* From a host package codebase call it as
|
|
33
|
-
* ```bash
|
|
34
|
-
* $ ./node_modules/.bin/react-utils-build -h
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* Here is the usage information output by these commands:
|
|
38
|
-
* ```
|
|
39
|
-
* Usage: build [options]
|
|
40
|
-
*
|
|
41
|
-
* Library build script
|
|
42
|
-
*
|
|
43
|
-
* Options:
|
|
44
|
-
* --lib library build (default: false)
|
|
45
|
-
* -i, --in-dir <path> input folder for the build (default: "src")
|
|
46
|
-
* -o, --out-dir <path> output folder for the build (default: "build")
|
|
47
|
-
* -t, --build-type <type> build type: development, production
|
|
48
|
-
* -w, --watch build, watch, and rebuild on source changes
|
|
49
|
-
* --webpack-config <path> path to the webpack config (default: "webpack.
|
|
50
|
-
* onfig.js")
|
|
51
|
-
* -c, --copy-files <regex> copy files matching the pattern into the build folder
|
|
52
|
-
* -h, --help display help for command
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* To just build the package in development and production (with optimizations)
|
|
56
|
-
* modes we do:
|
|
57
|
-
* ```bash
|
|
58
|
-
* $ ./bin/build -t development --lib
|
|
59
|
-
* $ ./bin/build -t production --lib
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* These commands take the source code from `src` folder in the current
|
|
63
|
-
* directory, and build it to the `build/development` and `build/production`
|
|
64
|
-
* * output folders. `-i` and `-o` options allow to specify different input
|
|
65
|
-
* and output folders (`/development` or `/production` suffixes are append
|
|
66
|
-
* automatically to the output path specified by `-o` option, if `--lib` flag
|
|
67
|
-
* is set).
|
|
68
|
-
*
|
|
69
|
-
* For a web app build, omit the `--lib` flag. Without it Babel part of
|
|
70
|
-
* the build will output directly to the specified output directory,
|
|
71
|
-
* and Webpack part of the build will output inside `web-public` folder inside
|
|
72
|
-
* it (we assume that a web app will publically share outcomes of the Webpack
|
|
73
|
-
* build, thus compiling the bundle to the dedicated folder allows to not
|
|
74
|
-
* expose the outputs of Babel compilation, intended for server-side use only).
|
|
75
|
-
*
|
|
76
|
-
* **BEWARE:** To achieve folder structure described above this build script has
|
|
77
|
-
* to overwrite `context` and `publicPath` fields of the Webpack config you pass
|
|
78
|
-
* in.
|
|
79
|
-
*
|
|
80
|
-
* `--webpack-config` option allows to specify the Webpack config file
|
|
81
|
-
* (by default it is expected to be inside the `webpack.config.js` file in
|
|
82
|
-
* the current working directory).
|
|
83
|
-
*
|
|
84
|
-
* **WARNING:** The `--watch` option described below currently works only for
|
|
85
|
-
* Webpack part of the build. To enable it for Babel part requires a small
|
|
86
|
-
* update of Babel CLI: https://github.com/babel/babel/issues/10551
|
|
87
|
-
*
|
|
88
|
-
* To use this script as an alternative for `npm link`, as explained
|
|
89
|
-
* [above](#npm-link-issue), add `-w` option, and use `-o` to specify
|
|
90
|
-
* the correct output path inside the target host package. For example,
|
|
91
|
-
* if a package `A` depends on the library `B`, and the library `B` is built
|
|
92
|
-
* into `B/build` folder by this build script, then the installation path of
|
|
93
|
-
* `B` modules inside `A` is (most probably) `A/node_modules/B/build`. You can
|
|
94
|
-
* install a local copy of `B` into `A` like this:
|
|
95
|
-
*
|
|
96
|
-
* - Build and pack `B`, doing inside its root:
|
|
97
|
-
* ```bash
|
|
98
|
-
* $ ./bin/build --lib -t development && ./bin/build --lib -t production
|
|
99
|
-
* $ npm pack
|
|
100
|
-
* ```
|
|
101
|
-
* It will product the file `B-<version>.tgz` inside `B` codebase.
|
|
102
|
-
*
|
|
103
|
-
* - Install the packed local version of `B` into `A` doing in the `A`'s
|
|
104
|
-
* codebase root:
|
|
105
|
-
* ```bash
|
|
106
|
-
* $ rm -rf node_modules/B
|
|
107
|
-
* $ npm install /path/to/B/B-<version>.tgz
|
|
108
|
-
* ```
|
|
109
|
-
*
|
|
110
|
-
* - Now, inside `B`'s codebase root start the watch & build of the library's
|
|
111
|
-
* development or production version (whatever you need for your testing and
|
|
112
|
-
* development case):
|
|
113
|
-
* ```bash
|
|
114
|
-
* $ ./bin/build --lib -t development -w -o /path/to/A/node_modules/B/build
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* - Now you can start `A` and verify that any changes of `B` are propagated
|
|
118
|
-
* into `A` codebase. Once you done with your work, don't forget to revert
|
|
119
|
-
* `A`'s dependency on the local `B` package back to its remote version
|
|
120
|
-
* (the local dependency is saved into `package.json` automatically, even if
|
|
121
|
-
* not opted in). You can do it by `$ npm install --save B@<version>`, or
|
|
122
|
-
* just reverting the change `package.json` manually or with your version
|
|
123
|
-
* control.
|
|
124
|
-
*
|
|
125
|
-
* If you know what you are doing, most probably you do not need all these
|
|
126
|
-
* steps, and just running
|
|
127
|
-
* ```bash
|
|
128
|
-
* $ /path/to/B/bin/build --lib -t development -w -o /path/to/A/node_modules/B/build
|
|
129
|
-
* ```
|
|
130
|
-
* will work for you the same.
|
|
131
|
-
*/
|
|
132
3
|
/* eslint-disable import/no-dynamic-require, no-console */
|
|
133
4
|
|
|
134
5
|
const childProcess = require('child_process');
|
package/bin/release.sh
CHANGED
|
@@ -15,7 +15,7 @@ sudo apt-get update && sudo apt-get install google-cloud-sdk
|
|
|
15
15
|
echo $GCLOUD_KEY > ${HOME}/gcloud-key.json
|
|
16
16
|
gcloud auth activate-service-account --key-file ${HOME}/gcloud-key.json
|
|
17
17
|
gcloud config set project dr-pogodin-studio-website
|
|
18
|
-
gsutil rsync -d -r docs gs://docs.pogodin.studio/react-utils
|
|
18
|
+
gsutil rsync -d -r docs/build gs://docs.pogodin.studio/react-utils
|
|
19
19
|
|
|
20
20
|
# Library package release.
|
|
21
21
|
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
package/bin/setup.js
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* @category NodeJS Scripts
|
|
5
|
-
* @const react-utils-setup
|
|
6
|
-
* @desc
|
|
7
|
-
* ```bash
|
|
8
|
-
* $ ./node_modules/.bin/react-utils-setup [options] [libraries...]
|
|
9
|
-
* ```
|
|
10
|
-
* The NodeJS script for library setup and upgrades. It helps to install library
|
|
11
|
-
* depedencies into a host package, using the same versions, and also saving
|
|
12
|
-
* them into the host's `package.json`.
|
|
13
|
-
*
|
|
14
|
-
* This script installs each library from the whitespace separated list
|
|
15
|
-
* `[libraries...]`. After installing each library, it also installs into the
|
|
16
|
-
* host package:
|
|
17
|
-
*
|
|
18
|
-
* 1. All development dependencies of that library, with the versions taken from
|
|
19
|
-
* the library's `package.json`. Installed dependencies are also saved as dev
|
|
20
|
-
* dependencies of the host package.
|
|
21
|
-
*
|
|
22
|
-
* 2. All production dependencies, commong between the library and the host
|
|
23
|
-
* package, using the versions from the library's `package.json`.
|
|
24
|
-
* The versions are also saved into the host's `package.json`.
|
|
25
|
-
*
|
|
26
|
-
* If no `[libraries...]` are specified, the latest version of
|
|
27
|
-
* `@dr.pogodin/react-utils` is installed by default.
|
|
28
|
-
*
|
|
29
|
-
* With `--just-fix-deps` no libraries are installed, but their currently
|
|
30
|
-
* installed versions are checked, and their dependencies are installed into
|
|
31
|
-
* the host package in the way described above.
|
|
32
|
-
*
|
|
33
|
-
* In other words, the command
|
|
34
|
-
* ```bash
|
|
35
|
-
* $ ./node_modules/.bin/react-utils-setup
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* is equivalent to calling
|
|
39
|
-
* ```bash
|
|
40
|
-
* $ npm install --save @dr.pogodin/react-utils@latest
|
|
41
|
-
* $ npm install --save-dev dev-dep-1@version dev-dep-2@version ...
|
|
42
|
-
* $ npm install --save prod-dep-1@version prod-dep-2@version ...
|
|
43
|
-
* ```
|
|
44
|
-
* where the lists of dev and prod dependencies are formed in the way described
|
|
45
|
-
* above.
|
|
46
|
-
*/
|
|
47
3
|
/* eslint-disable import/no-extraneous-dependencies, no-console */
|
|
48
4
|
|
|
49
5
|
const { spawnSync } = require('child_process');
|
|
@@ -20,12 +20,6 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
20
20
|
/* global document, window */
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* @category Utilities
|
|
24
|
-
* @func client
|
|
25
|
-
* @desc
|
|
26
|
-
* ```js
|
|
27
|
-
* import { client } from '@dr.pogodin/react-utils';
|
|
28
|
-
* ```
|
|
29
23
|
* Prepares and launches the app at client side.
|
|
30
24
|
* @param {object} Application Root application component
|
|
31
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.jsx"],"names":["Launch","Application","ReactDom","hydrate","window","ISTATE","document","getElementById"],"mappings":";;;;;;;;;AAGA;;AAEA;;AACA;;;;AANA;;AACA;;AAOA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.jsx"],"names":["Launch","Application","ReactDom","hydrate","window","ISTATE","document","getElementById"],"mappings":";;;;;;;;;AAGA;;AAEA;;AACA;;;;AANA;;AACA;;AAOA;AACA;AACA;AACA;AACe,SAASA,MAAT,CAAgBC,WAAhB,EAA6B;AAC1CC,oBAASC,OAAT,eACE,qBAAC,qCAAD;AAAqB,IAAA,YAAY,EAAEC,MAAM,CAACC,MAA1C;AAAA,2BACE,qBAAC,6BAAD;AAAA,6BACE,qBAAC,WAAD;AADF;AADF,IADF,EAMGC,QAAQ,CAACC,cAAT,CAAwB,YAAxB,CANH;AAOD","sourcesContent":["// Initialization of client-side code.\n/* global document, window */\n\nimport { GlobalStateProvider } from '@dr.pogodin/react-global-state';\n\nimport ReactDom from 'react-dom';\nimport { BrowserRouter } from 'react-router-dom';\n\n/**\n * Prepares and launches the app at client side.\n * @param {object} Application Root application component\n */\nexport default function Launch(Application) {\n ReactDom.hydrate((\n <GlobalStateProvider initialState={window.ISTATE}>\n <BrowserRouter>\n <Application />\n </BrowserRouter>\n </GlobalStateProvider>\n ), document.getElementById('react-view'));\n}\n"],"file":"index.js"}
|
|
@@ -90,7 +90,9 @@ if (window.INJ) {
|
|
|
90
90
|
});
|
|
91
91
|
decipher.update(_forge.default.util.createBuffer(data.slice(32)));
|
|
92
92
|
decipher.finish();
|
|
93
|
-
data =
|
|
93
|
+
data = _forge.default.util.decodeUtf8(decipher.output.data);
|
|
94
|
+
data = eval("(".concat(data, ")")); // eslint-disable-line no-eval
|
|
95
|
+
|
|
94
96
|
window.CHUNK_GROUPS = data.CHUNK_GROUPS;
|
|
95
97
|
window.CONFIG = data.CONFIG;
|
|
96
98
|
window.ISTATE = data.ISTATE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/init.js"],"names":["BUILD_INFO","window","TRU_BUILD_INFO","TRU_KEEP_INJ_SCRIPT","block","document","querySelector","getElementsByTagName","removeChild","useServiceWorker","navigator","addEventListener","serviceWorker","register","reg","console","log","INJ","key","data","forge","util","decode64","decipher","cipher","createDecipher","start","iv","slice","update","createBuffer","finish","
|
|
1
|
+
{"version":3,"sources":["../../../src/client/init.js"],"names":["BUILD_INFO","window","TRU_BUILD_INFO","TRU_KEEP_INJ_SCRIPT","block","document","querySelector","getElementsByTagName","removeChild","useServiceWorker","navigator","addEventListener","serviceWorker","register","reg","console","log","INJ","key","data","forge","util","decode64","decipher","cipher","createDecipher","start","iv","slice","update","createBuffer","finish","decodeUtf8","output","eval","CHUNK_GROUPS","CONFIG","ISTATE"],"mappings":";;;;;;;;AAQA;;AACA;;AATA;AACA;AACA;;AAEA;AAEA;AACA;;AAIA;AACA;AACA,IAAI,OAAOA,UAAP,KAAsB,WAA1B,EAAuC;AACrCC,EAAAA,MAAM,CAACC,cAAP,GAAwBF,UAAxB;AACD;AAED;AACA;;;AACA,IAAI,CAACC,MAAM,CAACE,mBAAZ,EAAiC;AAC/B,MAAMC,KAAK,GAAGC,QAAQ,CAACC,aAAT,CAAuB,kBAAv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,CAAxB,CAAhB;AACAL,EAAAA,QAAQ,CAACQ,MAAT;AAEAZ,EAAAA,IAAI,GAAGC,eAAMC,IAAN,CAAWW,UAAX,CAAsBT,QAAQ,CAACU,MAAT,CAAgBd,IAAtC,CAAP;AACAA,EAAAA,IAAI,GAAGe,IAAI,YAAKf,IAAL,OAAX,CATc,CASY;;AAE1BlB,EAAAA,MAAM,CAACkC,YAAP,GAAsBhB,IAAI,CAACgB,YAA3B;AACAlC,EAAAA,MAAM,CAACmC,MAAP,GAAgBjB,IAAI,CAACiB,MAArB;AACAnC,EAAAA,MAAM,CAACoC,MAAP,GAAgBlB,IAAI,CAACkB,MAArB;AACD,CAdD,MAcO;AACL;AACA;AACApC,EAAAA,MAAM,CAACkC,YAAP,GAAsB,EAAtB;AACAlC,EAAAA,MAAM,CAACmC,MAAP,GAAgB,EAAhB;AACD","sourcesContent":["/**\n * Initialization of client-side environment.\n */\n\n/* global BUILD_INFO, document, window */\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';\nimport 'node-forge/lib/aes';\n\n/* `BUILD_INFO` is always injected by Webpack build, but this check is needed\n * to adopt the code for usage in tests. */\nif (typeof BUILD_INFO !== 'undefined') {\n window.TRU_BUILD_INFO = BUILD_INFO;\n}\n\n/* Removes data injection script out of the document.\n * The if block is here for test purposes. */\nif (!window.TRU_KEEP_INJ_SCRIPT) {\n const block = document.querySelector('script[id=\"inj\"]');\n if (block) document.getElementsByTagName('body')[0].removeChild(block);\n}\n\n/* TODO: A proper logger should be moved to `@dr.pogodin/react-utils`. */\n/* eslint-disable no-console */\nconst { useServiceWorker } = window.TRU_BUILD_INFO;\nif (useServiceWorker) {\n const { navigator } = window;\n if ('serviceWorker' in navigator) {\n window.addEventListener('load', async () => {\n try {\n const reg = await navigator\n .serviceWorker.register('/__service-worker.js');\n console.log('SW registered:', reg);\n } catch (err) {\n console.log('SW registration failed:', err);\n }\n });\n }\n}\n/* eslint-enable no-console */\n\n/* Decodes data injected at the server side. */\nif (window.INJ) {\n const { key } = window.TRU_BUILD_INFO;\n let data = forge.util.decode64(window.INJ);\n const decipher = forge.cipher.createDecipher('AES-CBC', key);\n decipher.start({ iv: data.slice(0, 32) });\n decipher.update(forge.util.createBuffer(data.slice(32)));\n decipher.finish();\n\n data = forge.util.decodeUtf8(decipher.output.data);\n data = eval(`(${data})`); // eslint-disable-line no-eval\n\n window.CHUNK_GROUPS = data.CHUNK_GROUPS;\n window.CONFIG = data.CONFIG;\n window.ISTATE = data.ISTATE;\n} else {\n // This is possible when the client-side bundle is launched as a stand-alone\n // precompiled website, rather than served by react-utils' based server.\n window.CHUNK_GROUPS = {};\n window.CONFIG = {};\n}\n"],"file":"init.js"}
|
|
@@ -16,6 +16,13 @@ var _exportNames = {
|
|
|
16
16
|
useAsyncData: true,
|
|
17
17
|
useGlobalState: true
|
|
18
18
|
};
|
|
19
|
+
Object.defineProperty(exports, "GlobalStateProvider", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _reactGlobalState.GlobalStateProvider;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
exports.PT = void 0;
|
|
19
26
|
Object.defineProperty(exports, "_", {
|
|
20
27
|
enumerable: true,
|
|
21
28
|
get: function () {
|
|
@@ -34,12 +41,7 @@ Object.defineProperty(exports, "getGlobalState", {
|
|
|
34
41
|
return _reactGlobalState.getGlobalState;
|
|
35
42
|
}
|
|
36
43
|
});
|
|
37
|
-
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return _reactGlobalState.GlobalStateProvider;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
44
|
+
exports.server = void 0;
|
|
43
45
|
Object.defineProperty(exports, "useAsyncCollection", {
|
|
44
46
|
enumerable: true,
|
|
45
47
|
get: function () {
|
|
@@ -58,7 +60,6 @@ Object.defineProperty(exports, "useGlobalState", {
|
|
|
58
60
|
return _reactGlobalState.useGlobalState;
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
|
-
exports.PT = exports.server = void 0;
|
|
62
63
|
|
|
63
64
|
var _utils = require("./shared/utils");
|
|
64
65
|
|
|
@@ -107,18 +108,12 @@ let server = null; // eslint-disable-line import/no-mutable-exports
|
|
|
107
108
|
exports.server = server;
|
|
108
109
|
|
|
109
110
|
if (_utils.isomorphy.IS_SERVER_SIDE) {
|
|
110
|
-
|
|
111
|
+
try {
|
|
112
|
+
const path = _utils.webpack.requireWeak('path');
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
exports.server = server = _utils.webpack.requireWeak(path.resolve(__dirname, './server'));
|
|
115
|
+
} catch (error) {
|
|
116
|
+
exports.server = server = null;
|
|
117
|
+
}
|
|
113
118
|
}
|
|
114
|
-
/**
|
|
115
|
-
* @category Utilities
|
|
116
|
-
* @module _
|
|
117
|
-
* @desc
|
|
118
|
-
* ```js
|
|
119
|
-
* import { _ } from '@dr.pogodin/react-utils';
|
|
120
|
-
* ```
|
|
121
|
-
* `_` is just an alias for [lodash](https://lodash.com/docs) library,
|
|
122
|
-
* which provides various generic JS helpers.
|
|
123
|
-
*/
|
|
124
119
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.js"],"names":["server","isomorphy","IS_SERVER_SIDE","path","webpack","requireWeak","resolve","__dirname"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.js"],"names":["server","isomorphy","IS_SERVER_SIDE","path","webpack","requireWeak","resolve","__dirname","error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AAyBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAbA;;AACA;;;;;;AAGA;;AAQA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AAtBA,IAAIA,MAAM,GAAG,IAAb,C,CAAmB;;;;AACnB,IAAIC,iBAAUC,cAAd,EAA8B;AAC5B,MAAI;AACF,UAAMC,IAAI,GAAGC,eAAQC,WAAR,CAAoB,MAApB,CAAb;;AACA,qBAAAL,MAAM,GAAGI,eAAQC,WAAR,CAAoBF,IAAI,CAACG,OAAL,CAAaC,SAAb,EAAwB,UAAxB,CAApB,CAAT;AACD,GAHD,CAGE,OAAOC,KAAP,EAAc;AACd,qBAAAR,MAAM,GAAG,IAAT;AACD;AACF","sourcesContent":["import 'styles/global.scss';\n\nimport { isomorphy, webpack } from 'utils';\n\nlet server = null; // eslint-disable-line import/no-mutable-exports\nif (isomorphy.IS_SERVER_SIDE) {\n try {\n const path = webpack.requireWeak('path');\n server = webpack.requireWeak(path.resolve(__dirname, './server'));\n } catch (error) {\n server = null;\n }\n}\n\nexport { default as _ } from 'lodash';\nexport { default as api } from 'axios';\nexport * as PT from 'prop-types';\n\nexport {\n getGlobalState,\n GlobalStateProvider,\n useAsyncCollection,\n useAsyncData,\n useGlobalState,\n} from '@dr.pogodin/react-global-state';\n\nexport * from 'components';\nexport * from 'utils';\n\nexport { server };\n"],"file":"index.js"}
|
|
@@ -8,13 +8,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
getDefaultCspSettings: true
|
|
10
10
|
};
|
|
11
|
+
exports.default = void 0;
|
|
11
12
|
Object.defineProperty(exports, "getDefaultCspSettings", {
|
|
12
13
|
enumerable: true,
|
|
13
14
|
get: function () {
|
|
14
15
|
return _server.getDefaultCspSettings;
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
|
-
exports.default = void 0;
|
|
18
18
|
|
|
19
19
|
require("source-map-support/register");
|
|
20
20
|
|
|
@@ -74,56 +74,6 @@ function normalizePort(value) {
|
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
* @category Utilities
|
|
78
|
-
* @callback BeforeRenderHook
|
|
79
|
-
* @desc A hook for {@link server}'s `beforeRender` option.
|
|
80
|
-
* @param {object} req Incoming ExpressJS HTTP request, with some extra
|
|
81
|
-
* fields attached:
|
|
82
|
-
* - `.nonce: string` – CSP nonce for `<script>` tags, which should be
|
|
83
|
-
* added to the tags injected into the page to allow them to work.
|
|
84
|
-
* @param {object} config Application config that server wants to
|
|
85
|
-
* inject into generated HTML template.
|
|
86
|
-
* @return {Promise<{
|
|
87
|
-
* configToInject: object,
|
|
88
|
-
* extraScript: Array<object|string>,
|
|
89
|
-
* initialState: object
|
|
90
|
-
* }>} `Promise` resolving to the object with fields:
|
|
91
|
-
* - `[configToInject]` (_Object_) – Optional. The actual config object
|
|
92
|
-
* to inject into the generated page. If not provided, the `config` provided as
|
|
93
|
-
* argument will be injected as is.
|
|
94
|
-
* - `[extraScripts]` (_Array of Objects and/or Strings_) – Optional.
|
|
95
|
-
* Additional scripts to inject into the generated page. Each script given
|
|
96
|
-
* as a string will be injected as is in the end of generated document's
|
|
97
|
-
* `<body>`, just before the main application bundle. Each script given as
|
|
98
|
-
* an object is expected to have two fields: `code` holding the actual code
|
|
99
|
-
* to inject, and `location` specifying where to inject that `code`. The valid
|
|
100
|
-
* locations are exposed via the `server.SCRIPT_LOCATIONS` object. The scripts
|
|
101
|
-
* intended for the same location are injected in the order
|
|
102
|
-
* they are listed in the `extraScript` array.
|
|
103
|
-
* - `[initialState]` (_Object_) – Optional. Initial value of the global
|
|
104
|
-
* state.
|
|
105
|
-
*
|
|
106
|
-
* `server.SCRIPT_LOCATIONS`
|
|
107
|
-
* - `server.SCRIPT_LOCATIONS.BODY_OPEN` – Right after the opening
|
|
108
|
-
* `<body>`
|
|
109
|
-
* tag.
|
|
110
|
-
* - `server.SCRIPT_LOCATIONS.DEFAULT` – In the end of `<body>` block, just
|
|
111
|
-
* before the main application bundle.
|
|
112
|
-
* - `server.SCRIPT_LOCATIONS.HEAD_OPEN` – Right after the opening
|
|
113
|
-
* `<head>` tag.
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @category Utilities
|
|
118
|
-
* @func server
|
|
119
|
-
* @desc
|
|
120
|
-
* ```js
|
|
121
|
-
* import { server } from '@dr.pogodin/react-utils`;
|
|
122
|
-
* import webpackConfig from 'path/to/your/webpack.config';
|
|
123
|
-
* server(webpackConfig);
|
|
124
|
-
* // Web server is up, running, and serving the app specified by the provided
|
|
125
|
-
* // Webpack config.
|
|
126
|
-
* ```
|
|
127
77
|
* Creates and launches web-server for ReactJS application. Allows zero
|
|
128
78
|
* or detailed configuration, supports server-side rendering,
|
|
129
79
|
* and development tools, including Hot Module Reloading (HMR).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.js"],"names":["DEFAULT_MAX_SSR_ROUNDS","DEFAULT_SSR_TIMEOUT","normalizePort","value","port","_","toNumber","isFinite","isNumber","launch","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","maxSsrRounds","ssrTimeout","staticCacheSize","isUndefined","logger","format","transports","winston","createLogger","level","defaultLoggerLogLevel","combine","splat","timestamp","colorize","printf","message","stack","rest","res","Object","keys","length","JSON","stringify","Console","expressServer","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAGA;;AAEA;;AAEA;;AACA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AATA;AAWA;AACA,MAAMA,sBAAsB,GAAG,EAA/B;AACA,MAAMC,mBAAmB,GAAG,IAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,aAAT,CAAuBC,KAAvB,EAA8B;AAC5B,QAAMC,IAAI,GAAGC,gBAAEC,QAAF,CAAWH,KAAX,CAAb;;AACA,MAAIE,gBAAEE,QAAF,CAAWH,IAAX,CAAJ,EAAsB,OAAOA,IAAP;AAAa;;AACnC,MAAI,CAACC,gBAAEG,QAAF,CAAWJ,IAAX,CAAL,EAAuB,OAAOD,KAAP;AAAc;;AACrC,SAAO,KAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,MAAf,CAAsBC,aAAtB,EAAqCC,OAArC,EAA8C;AAC5C;AACA,QAAMC,GAAG,GAAGD,OAAO,GAAGN,gBAAEQ,SAAF,CAAYF,OAAZ,CAAH,GAA0B,EAA7C;AACAC,EAAAA,GAAG,CAACR,IAAJ,GAAWF,aAAa,CAACU,GAAG,CAACR,IAAJ,IAAYU,OAAO,CAACC,GAAR,CAAYC,IAAxB,IAAg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AAF,CAAWG,IAAX,IAAoB,QAAOA,IAAK,EAAhC,GAAqC,QAAOA,IAAI,CAACvD,IAAK,EAAnE;AACAQ,IAAAA,GAAG,CAACW,MAAJ,CAAWsC,IAAX,CAAiB,uBAAsBN,IAAK,OAC1CzC,OAAO,CAACC,GAAR,CAAY+C,QAAS,OADvB;AAED,GALD;AAOAhB,EAAAA,UAAU,CAACiB,MAAX,CAAkBnD,GAAG,CAACR,IAAtB;AAEA,SAAO;AACLyC,IAAAA,aADK;AAELC,IAAAA;AAFK,GAAP;AAID;;AAEDrC,MAAM,CAACuD,gBAAP,GAA0BA,0BAA1B;eAEevD,M","sourcesContent":["import 'source-map-support/register';\n\nimport _ from 'lodash';\nimport http from 'http';\nimport https from 'https';\n\n/* Polyfill required by ReactJS. */\nimport 'raf/polyfill';\n\nimport winston from 'winston';\n\nimport serverFactory from './server';\nimport { SCRIPT_LOCATIONS } from './renderer';\n\nexport { getDefaultCspSettings } from './server';\nexport * from './utils';\n\n// Various default settings of server factory (launch() function).\nconst DEFAULT_MAX_SSR_ROUNDS = 10;\nconst DEFAULT_SSR_TIMEOUT = 1000;\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @ignore\n * @param {String} value Port name or number.\n * @return Port number (Number), name (String), or false.\n */\nfunction normalizePort(value) {\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\n/**\n * @category Utilities\n * @callback BeforeRenderHook\n * @desc A hook for {@link server}'s `beforeRender` option.\n * @param {object} req Incoming ExpressJS HTTP request, with some extra\n * fields attached:\n * - `.nonce: string` – CSP nonce for `<script>` tags, which should be\n * added to the tags injected into the page to allow them to work.\n * @param {object} config Application config that server wants to\n * inject into generated HTML template.\n * @return {Promise<{\n * configToInject: object,\n * extraScript: Array<object|string>,\n * initialState: object\n * }>} `Promise` resolving to the object with fields:\n * - `[configToInject]` (_Object_) – Optional. The actual config object\n * to inject into the generated page. If not provided, the `config` provided as\n * argument will be injected as is.\n * - `[extraScripts]` (_Array of Objects and/or Strings_) – Optional.\n * Additional scripts to inject into the generated page. Each script given\n * as a string will be injected as is in the end of generated document's\n * `<body>`, just before the main application bundle. Each script given as\n * an object is expected to have two fields: `code` holding the actual code\n * to inject, and `location` specifying where to inject that `code`. The valid\n * locations are exposed via the `server.SCRIPT_LOCATIONS` object. The scripts\n * intended for the same location are injected in the order\n * they are listed in the `extraScript` array.\n * - `[initialState]` (_Object_) – Optional. Initial value of the global\n * state.\n *\n * `server.SCRIPT_LOCATIONS`\n * - `server.SCRIPT_LOCATIONS.BODY_OPEN` – Right after the opening\n * `<body>`\n * tag.\n * - `server.SCRIPT_LOCATIONS.DEFAULT` – In the end of `<body>` block, just\n * before the main application bundle.\n * - `server.SCRIPT_LOCATIONS.HEAD_OPEN` – Right after the opening\n * `<head>` tag.\n*/\n\n/**\n * @category Utilities\n * @func server\n * @desc\n * ```js\n * import { server } from '@dr.pogodin/react-utils`;\n * import webpackConfig from 'path/to/your/webpack.config';\n * server(webpackConfig);\n * // Web server is up, running, and serving the app specified by the provided\n * // Webpack config.\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 * See {@link module:ReactGlobalState ReactGlobalState} for some additional\n * notes related to SSR, access to incoming requests during SSR, _etc._\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel=info] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return {Promise<{ expressServer: object, httpServer: object }>} Resolves to\n * an object with created Express and HTTP servers.\n */\nasync function launch(webpackConfig, options) {\n /* Options normalization. */\n const ops = options ? _.cloneDeep(options) : {};\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n _.defaults(ops, {\n httpsRedirect: true,\n maxSsrRounds: DEFAULT_MAX_SSR_ROUNDS,\n ssrTimeout: DEFAULT_SSR_TIMEOUT,\n });\n if (!ops.staticCacheSize) ops.staticCacheSize = 1.e7;\n\n if (_.isUndefined(ops.logger)) {\n const { format, transports } = winston;\n ops.logger = winston.createLogger({\n level: ops.defaultLoggerLogLevel || 'info',\n format: format.combine(\n format.splat(),\n format.timestamp(),\n format.colorize(),\n format.printf(\n ({\n level,\n message,\n timestamp,\n stack,\n ...rest\n }) => {\n let res = `${level}\\t(at ${timestamp}):\\t${message}`;\n if (Object.keys(rest).length) {\n res += `\\n${JSON.stringify(rest, null, 2)}`;\n }\n if (stack) res += `\\n${stack}`;\n return res;\n },\n ),\n ),\n transports: [new transports.Console()],\n });\n }\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer);\n } else httpServer = http.createServer(expressServer);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error) => {\n if (error.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.code) {\n case 'EACCES':\n ops.logger.error(`${bind} requires elevated privileges`);\n process.exit(1);\n break;\n case 'EADDRINUSE':\n ops.logger.error(`${bind} is already in use`);\n process.exit(1);\n break;\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\nlaunch.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;\n\nexport default launch;\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.js"],"names":["DEFAULT_MAX_SSR_ROUNDS","DEFAULT_SSR_TIMEOUT","normalizePort","value","port","_","toNumber","isFinite","isNumber","launch","webpackConfig","options","ops","cloneDeep","process","env","PORT","defaults","httpsRedirect","maxSsrRounds","ssrTimeout","staticCacheSize","isUndefined","logger","format","transports","winston","createLogger","level","defaultLoggerLogLevel","combine","splat","timestamp","colorize","printf","message","stack","rest","res","Object","keys","length","JSON","stringify","Console","expressServer","httpServer","https","createServer","cert","key","http","on","error","syscall","bind","isString","code","exit","addr","address","info","NODE_ENV","listen","SCRIPT_LOCATIONS"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAGA;;AAEA;;AAEA;;AACA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AATA;AAWA;AACA,MAAMA,sBAAsB,GAAG,EAA/B;AACA,MAAMC,mBAAmB,GAAG,IAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,aAAT,CAAuBC,KAAvB,EAA8B;AAC5B,QAAMC,IAAI,GAAGC,gBAAEC,QAAF,CAAWH,KAAX,CAAb;;AACA,MAAIE,gBAAEE,QAAF,CAAWH,IAAX,CAAJ,EAAsB,OAAOA,IAAP;AAAa;;AACnC,MAAI,CAACC,gBAAEG,QAAF,CAAWJ,IAAX,CAAL,EAAuB,OAAOD,KAAP;AAAc;;AACrC,SAAO,KAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeM,MAAf,CAAsBC,aAAtB,EAAqCC,OAArC,EAA8C;AAC5C;AACA,QAAMC,GAAG,GAAGD,OAAO,GAAGN,gBAAEQ,SAAF,CAAYF,OAAZ,CAAH,GAA0B,EAA7C;AACAC,EAAAA,GAAG,CAACR,IAAJ,GAAWF,aAAa,CAACU,GAAG,CAACR,IAAJ,IAAYU,OAAO,CAACC,GAAR,CAAYC,IAAxB,IAAgC,IAAjC,CAAxB;;AACAX,kBAAEY,QAAF,CAAWL,GAAX,EAAgB;AACdM,IAAAA,aAAa,EAAE,IADD;AAEdC,IAAAA,YAAY,EAAEnB,sBAFA;AAGdoB,IAAAA,UAAU,EAAEnB;AAHE,GAAhB;;AAKA,MAAI,CAACW,GAAG,CAACS,eAAT,EAA0BT,GAAG,CAACS,eAAJ,GAAsB,IAAtB;;AAE1B,MAAIhB,gBAAEiB,WAAF,CAAcV,GAAG,CAACW,MAAlB,CAAJ,EAA+B;AAC7B,UAAM;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAyBC,gBAA/B;AACAd,IAAAA,GAAG,CAACW,MAAJ,GAAaG,iBAAQC,YAAR,CAAqB;AAChCC,MAAAA,KAAK,E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,KAAD,IAAW;AAChC,QAAIA,KAAK,CAACC,OAAN,KAAkB,QAAtB,EAAgC,MAAMD,KAAN;AAChC,UAAME,IAAI,GAAGlD,gBAAEmD,QAAF,CAAW5C,GAAG,CAACR,IAAf,IAAwB,QAAOQ,GAAG,CAACR,IAAK,EAAxC,GAA6C,QAAOQ,GAAG,CAACR,IAAK,EAA1E;AAEA;;AACA,YAAQiD,KAAK,CAACI,IAAd;AACE,WAAK,QAAL;AACE7C,QAAAA,GAAG,CAACW,MAAJ,CAAW8B,KAAX,CAAkB,GAAEE,IAAK,+BAAzB;AACAzC,QAAAA,OAAO,CAAC4C,IAAR,CAAa,CAAb;AACA;;AACF,WAAK,YAAL;AACE9C,QAAAA,GAAG,CAACW,MAAJ,CAAW8B,KAAX,CAAkB,GAAEE,IAAK,oBAAzB;AACAzC,QAAAA,OAAO,CAAC4C,IAAR,CAAa,CAAb;AACA;;AACF;AACE,cAAML,KAAN;AAVJ;AAYD,GAjBD;AAmBA;;AACAP,EAAAA,UAAU,CAACM,EAAX,CAAc,WAAd,EAA2B,MAAM;AAC/B,UAAMO,IAAI,GAAGb,UAAU,CAACc,OAAX,EAAb;AACA,UAAML,IAAI,GAAGlD,gBAAEmD,QAAF,CAAWG,IAAX,IAAoB,QAAOA,IAAK,EAAhC,GAAqC,QAAOA,IAAI,CAACvD,IAAK,EAAnE;AACAQ,IAAAA,GAAG,CAACW,MAAJ,CAAWsC,IAAX,CAAiB,uBAAsBN,IAAK,OAC1CzC,OAAO,CAACC,GAAR,CAAY+C,QAAS,OADvB;AAED,GALD;AAOAhB,EAAAA,UAAU,CAACiB,MAAX,CAAkBnD,GAAG,CAACR,IAAtB;AAEA,SAAO;AACLyC,IAAAA,aADK;AAELC,IAAAA;AAFK,GAAP;AAID;;AAEDrC,MAAM,CAACuD,gBAAP,GAA0BA,0BAA1B;eAEevD,M","sourcesContent":["import 'source-map-support/register';\n\nimport _ from 'lodash';\nimport http from 'http';\nimport https from 'https';\n\n/* Polyfill required by ReactJS. */\nimport 'raf/polyfill';\n\nimport winston from 'winston';\n\nimport serverFactory from './server';\nimport { SCRIPT_LOCATIONS } from './renderer';\n\nexport { getDefaultCspSettings } from './server';\nexport * from './utils';\n\n// Various default settings of server factory (launch() function).\nconst DEFAULT_MAX_SSR_ROUNDS = 10;\nconst DEFAULT_SSR_TIMEOUT = 1000;\n\n/**\n * Normalizes a port into a number, string, or false.\n * TODO: Drop this function?\n * @ignore\n * @param {String} value Port name or number.\n * @return Port number (Number), name (String), or false.\n */\nfunction normalizePort(value) {\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\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 * See {@link module:ReactGlobalState ReactGlobalState} for some additional\n * notes related to SSR, access to incoming requests during SSR, _etc._\n *\n * @param {object} webpackConfig Webpack configuration used to build\n * the frontend bundle. In production mode the server will read out of it\n * `context`, `publicPath`, and a few other parameters, necessary to locate\n * and serve the app bundle. In development mode the server will use entire\n * provided config to build the app bundle in memory, and further watch and\n * update it via HMR.\n * @param {object} [options] Additional parameters.\n * @param {Component} [options.Application] The root ReactJS component of\n * the app to use for the server-side rendering. When not provided\n * the server-side rendering is disabled.\n * @param {function} [options.beforeExpressJsError] Asynchronous callback\n * (`(server) => Promise<boolean>`) to be executed just before the default error\n * handler is added to ExpressJS server. If the callback is provided and its\n * result resolves to a truthy value, `react-utils` won't attach the default\n * error handler.\n * @param {function} [options.beforeExpressJsSetup] Asynchronous callback\n * (`(server) => Promise) to be executed right after ExpressJS server creation,\n * before any configuration is performed.\n * @param {BeforeRenderHook} [options.beforeRender] The hook to run just before\n * the server-side rendering. For each incoming request, it will be executed\n * just before the HTML markup is generated at the server. It allows to load\n * and provide the data necessary for server-side rendering, and also to inject\n * additional configuration and scripts into the generated HTML code.\n * @param {boolean} [options.noCsp] Set `true` to disable\n * Content-Security-Policy (CSP) headers altogether.\n * @param {function} [options.cspSettingsHook] A hook allowing\n * to customize [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)\n * settings for [helmet](https://github.com/helmetjs/helmet)'s\n * `contentSecurityPolicy` middleware on per-request basis.\n *\n * If provided it should be a with signature: \\\n * `(defaultSettings: object, req: object)` ⇒ `object` \\\n * which gets the default settings (also used without the hook),\n * and the incoming request object. The hook response will be passed\n * as options to the helmet `contentSecurityPolicy` middleware.\n *\n * Currently, the default settings is the following object in production\n * environment:\n * ```js\n * {\n * directives: {\n * defaultSrc: [\"'self'\"],\n * baseUri: [\"'self'\"],\n * blockAllMixedContent: [],\n * fontSrc: [\"'self'\", 'https:', 'data:'],\n * frameAncestors: [\"'self'\"],\n * frameSrc: [\"'self'\", 'https://*.youtube.com'],\n * imgSrc: [\"'self'\", 'data:'],\n * objectSrc: [\"'none'\"],\n * scriptSrc: [\"'self'\", \"'unsafe-eval'\", `'nonce-UNIQUE_NONCE_VALUE'`],\n * scriptSrcAttr: [\"'none'\"],\n * styleSrc: [\"'self'\", 'https:', \"'unsafe-inline'\"],\n * upgradeInsecureRequests: [] // Removed in dev mode.\n * }\n * }\n * ```\n * It matches the default value used by Helmet with a few updates:\n * - YouTube host is whitelisted in the `frameSrc` directive to ensure\n * the {@link YouTubeVideo} component works.\n * - An unique per-request nonce is added to `scriptSrc` directive to\n * whitelist auxiliary scripts injected by react-utils. The actual nonce\n * value can be fetched by host code via `.nonce` field of `req` argument\n * of `.beforeRender` hook.\n * - `upgradeInsecureRequests` directive is removed in development mode,\n * to simplify local testing with http requests.\n * @param {string} [options.defaultLoggerLogLevel=info] Log level for\n * the default logger, which is created if no `logger` option provided.\n * @param {boolean} [options.devMode] Pass in `true` to start the server in\n * development mode.\n * @param {string} [options.favicon] Path to the favicon to use by the server.\n * By default no favicon is used.\n * @param {object} [options.https] If provided, HTTPS server will be started,\n * instead of HTTP otherwise. The object should provide SSL certificate and key\n * via two string fields: `cert`, and `key`.\n * @param {string} [options.https.cert] SSL Certificate.\n * @param {string} [options.https.key] SSL key.\n * @param {boolean} [options.httpsRedirect=true] Pass in `true` to enable\n * automatic redirection of all incoming HTTP requests to HTTPS.\n *\n * To smoothly use it at `localhost` you need to run the server in HTTPS mode,\n * and also properly create and install a self-signed SSL sertificate on your\n * system. This article is helpful:\n * [How to get HTTPS working on your local development environment in 5 minutes](https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec)\n * @param {Logger} [options.logger] The logger to use at server side.\n * By default [`winston`](https://www.npmjs.com/package/winston) logger\n * with console transport is used. The logger you provide, or the default\n * `winston` logger otherwise, will be attached to the created ExpressJS server\n * object.\n * @param {function} [options.onExpressJsSetup] An async callback\n * (`(server) => Promise`) to be triggered when most of the server\n * configuration is completed, just before the server-side renderer,\n * and the default error handler are attached. You can use it to mount\n * custom API routes. The server-side logger can be accessed as `server.logger`.\n * @param {number|string} [options.port=3000] The port to start the server on.\n * @param {number} [options.staticCacheSize=1.e7] The maximum\n * static cache size in bytes. Defaults to ~10 MB.\n * @param {function} [options.staticCacheController] When given, it activates,\n * and controls the static caching of generated HTML markup. When this function\n * is provided, on each incoming request it is triggered with the request\n * passed in as the argument. To attempt to serve the response from the cache\n * it should return the object with the following fields:\n * - `key: string` – the cache key for the response;\n * - `maxage?: number` – the maximum age of cached result in ms.\n * If undefined - infinite age is assumed.\n * @param {number} [options.maxSsrRounds=10] Maximum number of SSR rounds.\n * @param {number} [options.ssrTimeout=1000] SSR timeout in milliseconds,\n * defaults to 1 second.\n * @return {Promise<{ expressServer: object, httpServer: object }>} Resolves to\n * an object with created Express and HTTP servers.\n */\nasync function launch(webpackConfig, options) {\n /* Options normalization. */\n const ops = options ? _.cloneDeep(options) : {};\n ops.port = normalizePort(ops.port || process.env.PORT || 3000);\n _.defaults(ops, {\n httpsRedirect: true,\n maxSsrRounds: DEFAULT_MAX_SSR_ROUNDS,\n ssrTimeout: DEFAULT_SSR_TIMEOUT,\n });\n if (!ops.staticCacheSize) ops.staticCacheSize = 1.e7;\n\n if (_.isUndefined(ops.logger)) {\n const { format, transports } = winston;\n ops.logger = winston.createLogger({\n level: ops.defaultLoggerLogLevel || 'info',\n format: format.combine(\n format.splat(),\n format.timestamp(),\n format.colorize(),\n format.printf(\n ({\n level,\n message,\n timestamp,\n stack,\n ...rest\n }) => {\n let res = `${level}\\t(at ${timestamp}):\\t${message}`;\n if (Object.keys(rest).length) {\n res += `\\n${JSON.stringify(rest, null, 2)}`;\n }\n if (stack) res += `\\n${stack}`;\n return res;\n },\n ),\n ),\n transports: [new transports.Console()],\n });\n }\n\n /* Creates servers, resolves and sets the port. */\n const expressServer = await serverFactory(webpackConfig, ops);\n\n let httpServer;\n if (ops.https) {\n httpServer = https.createServer({\n cert: ops.https.cert,\n key: ops.https.key,\n }, expressServer);\n } else httpServer = http.createServer(expressServer);\n\n /* Sets error handler for HTTP(S) server. */\n httpServer.on('error', (error) => {\n if (error.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.code) {\n case 'EACCES':\n ops.logger.error(`${bind} requires elevated privileges`);\n process.exit(1);\n break;\n case 'EADDRINUSE':\n ops.logger.error(`${bind} is already in use`);\n process.exit(1);\n break;\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\nlaunch.SCRIPT_LOCATIONS = SCRIPT_LOCATIONS;\n\nexport default launch;\n"],"file":"index.js"}
|
|
@@ -5,9 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.isBrotliAcceptable = isBrotliAcceptable;
|
|
9
|
-
exports.default = factory;
|
|
10
8
|
exports.SCRIPT_LOCATIONS = void 0;
|
|
9
|
+
exports.default = factory;
|
|
10
|
+
exports.isBrotliAcceptable = isBrotliAcceptable;
|
|
11
11
|
|
|
12
12
|
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
13
13
|
|
|
@@ -29,6 +29,8 @@ var _reactHelmet = require("react-helmet");
|
|
|
29
29
|
|
|
30
30
|
var _reactRouterDom = require("react-router-dom");
|
|
31
31
|
|
|
32
|
+
var _serializeJavascript = _interopRequireDefault(require("serialize-javascript"));
|
|
33
|
+
|
|
32
34
|
var _time = _interopRequireDefault(require("../shared/utils/time"));
|
|
33
35
|
|
|
34
36
|
var _Cache = _interopRequireDefault(require("./Cache"));
|
|
@@ -285,11 +287,15 @@ function factory(webpackConfig, options) {
|
|
|
285
287
|
|
|
286
288
|
|
|
287
289
|
delete ssrContext.state.dr_pogodin_react_utils___split_components;
|
|
288
|
-
|
|
290
|
+
const payload = (0, _serializeJavascript.default)({
|
|
289
291
|
CHUNK_GROUPS: chunkGroups,
|
|
290
292
|
CONFIG: configToInject || sanitizedConfig,
|
|
291
293
|
ISTATE: ssrContext.state
|
|
292
|
-
}
|
|
294
|
+
}, {
|
|
295
|
+
ignoreFunction: true,
|
|
296
|
+
unsafe: true
|
|
297
|
+
});
|
|
298
|
+
cipher.update(_nodeForge.default.util.createBuffer(payload, 'utf8'));
|
|
293
299
|
cipher.finish();
|
|
294
300
|
|
|
295
301
|
const INJ = _nodeForge.default.util.encode64(`${iv}${cipher.output.data}`);
|