@dr.pogodin/react-utils 1.26.0 → 1.26.2

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 (29) hide show
  1. package/build/development/shared/components/ScalableRect/index.js +1 -1
  2. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  3. package/build/development/shared/components/Throbber/index.js.map +1 -1
  4. package/build/development/web.bundle.js +1 -1
  5. package/build/production/shared/components/ScalableRect/index.js +1 -1
  6. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  7. package/build/production/shared/components/Throbber/index.js.map +1 -1
  8. package/build/production/web.bundle.js +1 -1
  9. package/build/production/web.bundle.js.map +1 -1
  10. package/build/types-code/shared/components/Throbber/index.d.ts +1 -0
  11. package/config/babel/node-ssr.d.ts +17 -0
  12. package/config/babel/node-ssr.js +91 -0
  13. package/config/babel/webpack.d.ts +40 -0
  14. package/config/babel/webpack.js +107 -0
  15. package/config/webpack/app-base.d.ts +140 -0
  16. package/config/webpack/app-base.js +313 -0
  17. package/config/webpack/app-development.d.ts +13 -0
  18. package/config/webpack/app-development.js +69 -0
  19. package/config/webpack/app-production.d.ts +16 -0
  20. package/config/webpack/app-production.js +57 -0
  21. package/config/webpack/lib-base.d.ts +20 -0
  22. package/config/webpack/lib-base.js +154 -0
  23. package/config/webpack/lib-development.d.ts +5 -0
  24. package/config/webpack/lib-development.js +33 -0
  25. package/config/webpack/lib-production.d.ts +5 -0
  26. package/config/webpack/lib-production.js +40 -0
  27. package/package.json +3 -3
  28. package/src/shared/components/ScalableRect/index.tsx +1 -1
  29. package/src/shared/components/Throbber/index.tsx +1 -0
@@ -1,6 +1,7 @@
1
1
  import { type Theme } from '@dr.pogodin/react-themes';
2
2
  type PropsT = {
3
3
  theme: Theme & {
4
+ bouncing?: string;
4
5
  container?: string;
5
6
  circle?: string;
6
7
  };
@@ -0,0 +1,17 @@
1
+ import { type BabelCompilerI, type ConfigT, type OptionsT as WebpackConfigOptionsT } from './webpack';
2
+ type OptionsT = WebpackConfigOptionsT & {
3
+ baseAssetsOutputPath?: string;
4
+ };
5
+ /**
6
+ * Generates Babel config for NodeJS compilation and server-side execution.
7
+ * @param babel Babel compiler instance.
8
+ * @param [ops] Preset options. It supports all options accepted by
9
+ * the underlying {@link module:babel/webpack preset for Webpack}, but it
10
+ * overrides `targets` option by `current node` value, and also accepts
11
+ * the following additional options:
12
+ * @param [ops.baseAssetsOutputPath] Path prefix for emitted image
13
+ * assets.
14
+ * @return Generated config.
15
+ */
16
+ export default function getConfig(babel: BabelCompilerI, ops?: OptionsT): ConfigT;
17
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const lodash_1 = require("lodash");
28
+ const webpack_1 = __importStar(require("./webpack"));
29
+ /**
30
+ * Creates a new base config.
31
+ * @param {object} babel Babel compiler.
32
+ * @param {object} [options] It supports all options of
33
+ * {@link module:babel/webpack.getPreset babel/webpack's getPreset()},
34
+ * but it overrides `targets` option with `current node` value, and further
35
+ * accepts the following:
36
+ * @param {string} [options.baseAssetsOutputPath] Path prefix for emitted
37
+ * image assets.
38
+ * @return {object} Created config object.
39
+ * @ignore
40
+ */
41
+ function newBase(babel, options = {}) {
42
+ const config = (0, webpack_1.default)(babel, Object.assign(Object.assign({}, options), { targets: 'current node' }));
43
+ const baseAssetsOutputPath = options.baseAssetsOutputPath || '';
44
+ config.plugins.push(['@dr.pogodin/transform-assets', {
45
+ extensions: ['gif', 'jpeg', 'jpg', 'png'],
46
+ name: `${baseAssetsOutputPath}/images/[md4:hash:20].[ext]`,
47
+ }]);
48
+ const moduleResolverPluginOps = (config.plugins.find((x) => x[0] === 'module-resolver'))[1];
49
+ moduleResolverPluginOps.transformFunctions = [
50
+ 'requireWeak',
51
+ 'resolveWeak',
52
+ 'webpack.requireWeak',
53
+ 'webpack.resolveWeak',
54
+ ];
55
+ if (babel.env() === webpack_1.ENVIRONMENTS.DEV) {
56
+ (0, lodash_1.pull)(config.plugins, 'react-refresh/babel');
57
+ }
58
+ return config;
59
+ }
60
+ /**
61
+ * Updates given `config` with styling ((S)CSS-related) setup.
62
+ *
63
+ * **Beware:** It mutates `config`.
64
+ *
65
+ * @param {object} config
66
+ * @return {object} Returns mutated config for chaining.
67
+ * @ignore
68
+ */
69
+ function addStyling(config) {
70
+ const cssModulesOps = config.plugins.find(([name]) => name === '@dr.pogodin/react-css-modules')[1];
71
+ cssModulesOps.replaceImport = true;
72
+ return config;
73
+ }
74
+ /**
75
+ * Generates Babel config for NodeJS compilation and server-side execution.
76
+ * @param babel Babel compiler instance.
77
+ * @param [ops] Preset options. It supports all options accepted by
78
+ * the underlying {@link module:babel/webpack preset for Webpack}, but it
79
+ * overrides `targets` option by `current node` value, and also accepts
80
+ * the following additional options:
81
+ * @param [ops.baseAssetsOutputPath] Path prefix for emitted image
82
+ * assets.
83
+ * @return Generated config.
84
+ */
85
+ function getConfig(babel, ops = {}) {
86
+ const config = newBase(babel, ops);
87
+ if (!ops.noStyling)
88
+ addStyling(config);
89
+ return config;
90
+ }
91
+ exports.default = getConfig;
@@ -0,0 +1,40 @@
1
+ export interface BabelCompilerI {
2
+ env: () => string;
3
+ }
4
+ /**
5
+ * Supported Babel environments.
6
+ */
7
+ export declare enum ENVIRONMENTS {
8
+ DEV = "development",
9
+ PROD = "production",
10
+ TEST = "test"
11
+ }
12
+ export interface PresetOrPluginOptionsI {
13
+ }
14
+ type PresetOrPluginT = string | [string, PresetOrPluginOptionsI];
15
+ export type ConfigT = {
16
+ presets: PresetOrPluginT[];
17
+ plugins: PresetOrPluginT[];
18
+ };
19
+ export type OptionsT = {
20
+ noRR?: boolean;
21
+ noStyling?: boolean;
22
+ targets?: string | string[] | {
23
+ [key: string]: string;
24
+ };
25
+ typescript?: boolean;
26
+ };
27
+ /**
28
+ * Generates Babel preset for Webpack.
29
+ * @param babel Babel compiler.
30
+ * @param [ops] Preset options.
31
+ * @param [ops.noRR] If truthy `react-refresh/babel` plugin is not
32
+ * included into config, no matter the environment.
33
+ * @param [ops.noStyling] If truthy all setup related to styling
34
+ * ((S)CSS processing) will be skipped.
35
+ * @param [ops.targets=defaults] Targets for
36
+ * `@babel/preset-env`.
37
+ * @return Generated config.
38
+ */
39
+ export default function getPreset(babel: BabelCompilerI, ops?: OptionsT): ConfigT;
40
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENTS = void 0;
4
+ const { generateScopedNameFactory, } = require('@dr.pogodin/babel-plugin-react-css-modules/utils');
5
+ const generateScopedNameDev = generateScopedNameFactory('[package]___[path][name]___[local]___[hash:base64:6]');
6
+ const generateScopedNameProd = generateScopedNameFactory('[hash:base64:6]');
7
+ /**
8
+ * Supported Babel environments.
9
+ */
10
+ var ENVIRONMENTS;
11
+ (function (ENVIRONMENTS) {
12
+ ENVIRONMENTS["DEV"] = "development";
13
+ ENVIRONMENTS["PROD"] = "production";
14
+ ENVIRONMENTS["TEST"] = "test";
15
+ })(ENVIRONMENTS || (exports.ENVIRONMENTS = ENVIRONMENTS = {}));
16
+ /**
17
+ * Creates a new base config.
18
+ * @param [options] Base config options.
19
+ * @return Generated config.
20
+ */
21
+ function newBaseConfig(options) {
22
+ return {
23
+ presets: [
24
+ // Chrome 69 is the browser for Android API 28.
25
+ ['@babel/env', { targets: options.targets || 'defaults or chrome >= 69' }],
26
+ // TODO: Starting from Babel 8, "automatic" will be the default runtime,
27
+ // thus once upgraded to Babel 8, runtime should be removed from
28
+ // @babel/react options below.
29
+ ['@babel/react', { runtime: 'automatic' }],
30
+ '@dr.pogodin/babel-preset-svgr',
31
+ ],
32
+ plugins: [
33
+ ['module-resolver', {
34
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
35
+ root: [
36
+ './src/shared',
37
+ './src',
38
+ ],
39
+ }],
40
+ '@babel/transform-runtime',
41
+ ],
42
+ };
43
+ }
44
+ /**
45
+ * Updates given `config` with styling ((S)CSS-related) setup.
46
+ *
47
+ * **Beware:** It mutates `config`.
48
+ *
49
+ * @param {object} config
50
+ * @param {string} env Target environment: `development` or `production`.
51
+ * @return {object} Returns mutated config for chaining.
52
+ * @ignore
53
+ */
54
+ function addStyling(config, env) {
55
+ const cssModulesOps = {
56
+ autoResolveMultipleImports: true,
57
+ filetypes: {
58
+ '.scss': { syntax: 'postcss-scss' },
59
+ },
60
+ };
61
+ config.plugins.push(['@dr.pogodin/react-css-modules', cssModulesOps]);
62
+ switch (env) {
63
+ case ENVIRONMENTS.DEV:
64
+ case ENVIRONMENTS.TEST:
65
+ cssModulesOps.generateScopedName = generateScopedNameDev;
66
+ break;
67
+ case ENVIRONMENTS.PROD:
68
+ cssModulesOps.generateScopedName = generateScopedNameProd;
69
+ break;
70
+ default:
71
+ }
72
+ return config;
73
+ }
74
+ /**
75
+ * Generates Babel preset for Webpack.
76
+ * @param babel Babel compiler.
77
+ * @param [ops] Preset options.
78
+ * @param [ops.noRR] If truthy `react-refresh/babel` plugin is not
79
+ * included into config, no matter the environment.
80
+ * @param [ops.noStyling] If truthy all setup related to styling
81
+ * ((S)CSS processing) will be skipped.
82
+ * @param [ops.targets=defaults] Targets for
83
+ * `@babel/preset-env`.
84
+ * @return Generated config.
85
+ */
86
+ function getPreset(babel, ops = {}) {
87
+ const env = babel.env();
88
+ const res = newBaseConfig(ops);
89
+ if (!ops.noStyling)
90
+ addStyling(res, env);
91
+ if (env === ENVIRONMENTS.DEV && !ops.noRR) {
92
+ res.plugins.push('react-refresh/babel');
93
+ }
94
+ // Conditional to not require non-TypeScript projects to install TypeScript-
95
+ // specific dependencies for build process.
96
+ if (ops.typescript) {
97
+ res.presets.push(['@babel/typescript', {
98
+ // This ensures TypeScript compilation does not remove "unused" imports,
99
+ // as in most cases it considers assets (e.g. stylesheet) imports as
100
+ // unused, while other steps of our build process rely on them
101
+ // (e.g. @dr.pogodin/react-css-modules plugin).
102
+ onlyRemoveTypeImports: true,
103
+ }]);
104
+ }
105
+ return res;
106
+ }
107
+ exports.default = getPreset;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @category Configs
3
+ * @module webpack/app-base
4
+ * @desc
5
+ * Base [Webpack](https://webpack.js.org/) configuration for apps.
6
+ */
7
+ /// <reference types="node" />
8
+ import nodeFs from 'fs';
9
+ import { type Configuration } from 'webpack';
10
+ export type BuildInfoT = {
11
+ key: string;
12
+ publicPath: string;
13
+ timestamp: string;
14
+ useServiceWorker: boolean;
15
+ };
16
+ export type OptionsT = {
17
+ babelEnv: string;
18
+ babelLoaderOptions?: object;
19
+ context: string;
20
+ cssLocalIdent?: string;
21
+ dontEmitBuildInfo?: boolean;
22
+ dontUseProgressPlugin?: boolean;
23
+ entry: string | string[];
24
+ fs?: typeof nodeFs;
25
+ keepBuildInfo?: boolean | BuildInfoT;
26
+ mode: 'development' | 'none' | 'production';
27
+ outputPath?: string;
28
+ publicPath?: string;
29
+ sitemap?: string;
30
+ typescript?: boolean;
31
+ workbox?: boolean | object;
32
+ };
33
+ /**
34
+ * Creates a new Webpack config object, and performs some auxiliary operations
35
+ * on the way.
36
+ * @param {object} ops Configuration params. This allows to modify some
37
+ * frequently changed options in a convenient way, without a need to manipulate
38
+ * directly with the created config object.
39
+ * @param {string} ops.babelEnv Babel environment to use for the Babel
40
+ * compilation step.
41
+ * @param {object} [ops.babelLoaderOptions] Overrides for default Babel options
42
+ * of JSX and SVG files loader.
43
+ * @param ops.context Base URL for resolution of relative config paths.
44
+ * @param {string} [ops.cssLocalIdent=hash:base64:6] The template for
45
+ * CSS classnames generation by the Webpack's `css-loader`; it is passed into
46
+ * the `localIdentName` param of the loader. It should match the corresponding
47
+ * setting in the Babel config.
48
+ * @param {boolean} [ops.dontEmitBuildInfo] If set the `.build-info` file won't
49
+ * be created at the disk during the compilation.
50
+ * @param [ops.dontUseProgressPlugin] Set to not include progress
51
+ * plugin.
52
+ * @param {string|string[]} ops.entry Entry points for "main" chunk. The config
53
+ * will prepend them by some necessary polyfills, e.g.:
54
+ * ([babel-polyfill](https://babeljs.io/docs/usage/polyfill/),
55
+ * [nodelist-foreach-polyfill](https://www.npmjs.com/package/nodelist-foreach-polyfill)).
56
+ * @param {boolean|object} ops.workbox If evaluates to a truthy value,
57
+ * [Workbox's InjectManifest plugin](https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#injectmanifest_plugin)
58
+ * is added to the array of Webpack plugins, to generate service worker for
59
+ * browser. If the value is an object, it is merged into the options passed
60
+ * into the plugin, otherwise default options are used:
61
+ * ```json
62
+ * {
63
+ * "importWorkboxFrom": "local",
64
+ * "swSrc": "@dr.pogodin/react-utils/config/workbox/default.js",
65
+ * "swDest": "__service-worker.js"
66
+ * }
67
+ * ```
68
+ * If service worker is generated by this option, it will be automatically
69
+ * initiated at the client side by the standard
70
+ * [client-side initialization script](docs/client.md)
71
+ * provided by **@dr.pogodin/react-utils**. Note that `swDest`'s value cannot be
72
+ * overriden by config options provided via `workbox` object.
73
+ * @param {object} [ops.fs] Filesystem to use instead of the Node's FS.
74
+ * @param {boolean|object} [ops.keepBuildInfo] If `true` and a `.build-info`
75
+ * file from a previous build exists in the context directory, it will be
76
+ * loaded and used, rather than re-generated by the config factory. It allows
77
+ * to re-create the Webpack config during a server launch without re-generation
78
+ * of the build info file created during a previous build (and thus bundled
79
+ * into the frontend bundle). If an object is provided, it will be used as
80
+ * the build info, instead of trying to load it from the filesystem. This
81
+ * feature is intended for testing context.
82
+ * @param {string} ops.mode
83
+ * [Webpack mode](https://webpack.js.org/concepts/mode/).
84
+ * @param {string} [ops.outputPath=build] Optional. Output path for the build.
85
+ * @param {string} ops.publicPath Base URL for the output of the build assets.
86
+ * @param {string} [ops.sitemap] The path to JS or JSON config for sitemap.
87
+ * It can be relative to the context, and can be a factory, which returns
88
+ * the config. The config should be compatible with
89
+ * [`sitemap`](https://www.npmjs.com/package/sitemap) library, and if
90
+ * provided the Webpack config factory will use it to gererate `sitemap.xml`
91
+ * file in the output folder, and then serve it from the app root.
92
+ * @return The generated config will opt to:
93
+ * - Bundle the font assets (EOF, OTF, SVG, TTF, WOFF, WOFF2 files from
94
+ * the `src/assets/fonts` folder of your source code will be bundled
95
+ * and output into the `[PUBLIC_PATH]/fonts` folder);
96
+ * - Bundle image assets (GIF, JPEG, JPG, PNG files from any folder of
97
+ * your source code will be bundled and output into the
98
+ * `[PUBLIC_PATH]/images` folder);
99
+ * - Bundle SCSS files from any folder of your source code, beside
100
+ * `node_modules` and its subfolders. The files will be compiled,
101
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
102
+ * bundles;
103
+ * - Bundle CSS files from any folder of your code. The files will be
104
+ * bundled and extracted into the `[PUBLIC_PATH]/[CHUNK_NAME].css`
105
+ * bundles;
106
+ * - Bundle JS, JSX, and SVG files; they will be compiled into the
107
+ * `[PUBLIC_PATH]/[CHUNK_NAME].js` bundles, using the Babel environment
108
+ * specified in the factory options, and
109
+ * [`config/babel/webpack`](./babel-config.js#webpack) config.
110
+ *
111
+ * - The following path aliases will be automatically set:
112
+ * - **`assets`** for `[CONTEXT]/src/assets`;
113
+ * - **`components`** for `[CONTEXT]/src/shared/components`;
114
+ * - **`fonts`** for `[CONTEXT]/src/assets/fonts`;
115
+ * - **`styles`** for `[CONTEXT]/src/styles`.
116
+ *
117
+ * Also `resolve.symlinks` Webpack option is set to *false* to avoid problems
118
+ * with resolution of assets from packages linked with `npm link`.
119
+ *
120
+ * - The following global variables will be emulated inside the output
121
+ * JS bundle:
122
+ * - **`BUILD_RNDKEY`** &mdash; A random 32 bit key that can be used
123
+ * for encryption, it is set just as a global variable accessible in
124
+ * the code;
125
+ * - **`BUILD_TIMESTAMP`** &mdash; UTC timestamp of the beginning of
126
+ * the build;
127
+ * - **`FRONT_END`** &mdash; It will be set *true* inside the bundle,
128
+ * so that shared code can use it to determine that it is executed
129
+ * at the client side.
130
+ *
131
+ * - It also opts to polyfill the `__dirname` global variable,
132
+ * and to ignore imports of the `fs` Node package;
133
+ *
134
+ * - Also, it will store to the disk (re-writes if exists) the file
135
+ * `[CONTEXT]/.build-info` which will contain a stringified JSON
136
+ * object with the following fields:
137
+ * - **`rndkey`** &mdash; The value set for `BUILD_RNDKEY`;
138
+ * - **`timestamp`** &mdash; The value set for `BUILD_TIMESTAMP`.
139
+ */
140
+ export default function configFactory(ops: OptionsT): Configuration;