@dr.pogodin/react-utils 1.57.0-alpha.2 → 1.57.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/release.sh CHANGED
@@ -23,4 +23,4 @@ gsutil -m rsync -d -r docs/build gs://docs.pogodin.studio/react-utils
23
23
 
24
24
  # Library package release.
25
25
  export NPM_ID_TOKEN=$(circleci run oidc get --claims '{"aud": "npm:registry.npmjs.org"}')
26
- npm publish --access public --tag v1.57-alpha
26
+ npm publish --access public
@@ -1,2 +1,2 @@
1
- import type { InjT } from '../shared/utils/globalState';
1
+ import type { InjT } from '../shared/utils/globalState.js';
2
2
  export default function getInj(): InjT | Promise<InjT>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Initialization of client-side environment.
3
3
  */
4
- import { type BuildInfoT } from '../shared/utils/isomorphy/buildInfo';
4
+ import { type BuildInfoT } from '../shared/utils/isomorphy/buildInfo.js';
5
5
  declare global {
6
6
  interface Window {
7
7
  __DEV_BUILD_INFO__: BuildInfoT | undefined;
@@ -6,7 +6,7 @@ declare global {
6
6
  }
7
7
  }
8
8
  export { type AsyncCollectionLoaderT, type AsyncCollectionT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, GlobalStateProvider, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, useGlobalStateObject, withGlobalStateType, } from '@dr.pogodin/react-global-state';
9
- export * from './shared/components';
9
+ export * from './shared/components/index.js';
10
10
  export { type BeforeRenderResT, type BeforeRenderT, type ConfigT, type ServerSsrContext, type ServerT, } from './server';
11
- export { Barrier, Cached, Emitter, type Listener, type ObjectKey, Semaphore, THEME_COMPOSE, THEME_PRIORITY, type Theme, ThemeProvider, assertEmptyObject, getConfig, setClientChunkGroups, splitComponent, time, useSsrContext, useTheme, webpack, withRetries, } from './shared/utils';
12
- export * from './shared/utils/isomorphy';
11
+ export { Barrier, Cached, Emitter, type Listener, type ObjectKey, Semaphore, THEME_COMPOSE, THEME_PRIORITY, type Theme, ThemeProvider, assertEmptyObject, getConfig, setClientChunkGroups, splitComponent, time, useSsrContext, useTheme, webpack, withRetries, } from './shared/utils/index.js';
12
+ export * from './shared/utils/isomorphy/index.js';
@@ -6,8 +6,8 @@ import type { ComponentType } from 'react';
6
6
  import type { Configuration, Stats } from 'webpack';
7
7
  import winston from 'winston';
8
8
  import { SsrContext } from '@dr.pogodin/react-global-state';
9
- import type { ChunkGroupsT, SsrContextT } from '../shared/utils/globalState';
10
- import { type BuildInfoT } from '../shared/utils/isomorphy/buildInfo';
9
+ import type { ChunkGroupsT, SsrContextT } from '../shared/utils/globalState.js';
10
+ import { type BuildInfoT } from '../shared/utils/isomorphy/buildInfo.js';
11
11
  interface LogMethodI {
12
12
  (level: string, message: string, ...meta: unknown[]): void;
13
13
  }
@@ -2,15 +2,15 @@
2
2
  * Just an aggregation of all exported components into a single module.
3
3
  */
4
4
  export { MetaTags } from '@dr.pogodin/react-helmet';
5
- export * from './selectors';
6
- export { BaseButton, default as Button } from './Button';
7
- export { default as Checkbox } from './Checkbox';
8
- export { default as Input } from './Input';
9
- export { default as Link } from './Link';
10
- export { BaseModal, default as Modal } from './Modal';
11
- export { default as NavLink } from './NavLink';
12
- export { default as PageLayout } from './PageLayout';
13
- export { default as Throbber } from './Throbber';
14
- export { default as WithTooltip } from './WithTooltip';
15
- export { default as YouTubeVideo } from './YouTubeVideo';
5
+ export * from './selectors/index.js';
6
+ export { BaseButton, default as Button } from './Button/index.js';
7
+ export { default as Checkbox } from './Checkbox/index.js';
8
+ export { default as Input } from './Input/index.js';
9
+ export { default as Link } from './Link.js';
10
+ export { BaseModal, default as Modal } from './Modal/index.js';
11
+ export { default as NavLink } from './NavLink.js';
12
+ export { default as PageLayout } from './PageLayout/index.js';
13
+ export { default as Throbber } from './Throbber/index.js';
14
+ export { default as WithTooltip } from './WithTooltip/index.js';
15
+ export { default as YouTubeVideo } from './YouTubeVideo/index.js';
16
16
  export { default as TextArea } from './TextArea';
@@ -11,7 +11,7 @@ export type OptionsT = {
11
11
  babelLoaderExclude?: RuleSetRule['exclude'];
12
12
  babelLoaderOptions?: object;
13
13
  context: string;
14
- cssLocalIdent: string;
14
+ cssLocalIdent?: string;
15
15
  dontEmitBuildInfo?: boolean;
16
16
  dontUseProgressPlugin?: boolean;
17
17
  entry: string | string[];
@@ -133,4 +133,4 @@ export type OptionsT = {
133
133
  * - **`rndkey`** &mdash; The value set for `BUILD_RNDKEY`;
134
134
  * - **`timestamp`** &mdash; The value set for `BUILD_TIMESTAMP`.
135
135
  */
136
- export default function configFactory(ops: OptionsT): Configuration;
136
+ export default function configFactory({ babelEnv, babelLoaderExclude, babelLoaderOptions, context, cssLocalIdent, dontEmitBuildInfo, dontUseProgressPlugin, entry, fs, keepBuildInfo, mode, outputPath, publicPath, sitemap, typescript, workbox, }: OptionsT): Configuration;
@@ -3,7 +3,7 @@ import { randomBytes } from 'node:crypto';
3
3
  import nodeFs from 'node:fs';
4
4
  import { createRequire } from 'node:module';
5
5
  import { resolve } from 'node:path';
6
- import { clone, defaults, isFunction, isObject, } from 'lodash-es';
6
+ import { isFunction } from 'lodash-es';
7
7
  import { SitemapStream, streamToPromise } from 'sitemap';
8
8
  // NOTE: As "webpack" is still distributed as CJS module, now that we have
9
9
  // switched to MJS, importing plugins from it in MJS import style does not work,
@@ -122,21 +122,13 @@ const require = createRequire(import.meta.url);
122
122
  * - **`rndkey`** &mdash; The value set for `BUILD_RNDKEY`;
123
123
  * - **`timestamp`** &mdash; The value set for `BUILD_TIMESTAMP`.
124
124
  */
125
- export default function configFactory(ops) {
126
- var _a;
127
- const o = defaults(clone(ops), {
128
- babelLoaderOptions: {},
129
- cssLocalIdent: '[hash:base64:6]',
130
- outputPath: 'build/web-public',
131
- publicPath: '',
132
- });
133
- const fs = (_a = ops.fs) !== null && _a !== void 0 ? _a : nodeFs;
125
+ export default function configFactory({ babelEnv, babelLoaderExclude, babelLoaderOptions = {}, context, cssLocalIdent = '[hash:base64:6]', dontEmitBuildInfo, dontUseProgressPlugin, entry, fs = nodeFs, keepBuildInfo, mode, outputPath = 'build/web-public', publicPath = '', sitemap, typescript, workbox, }) {
134
126
  // TODO: Should it be improved and re-validated? Are we using it in any project
135
127
  // as is?
136
128
  /* TODO: This works in practice, but being async and not awaited it is a bad
137
129
  * pattern. */
138
- if (o.sitemap) {
139
- const sitemapUrl = resolve(o.context, o.sitemap);
130
+ if (sitemap) {
131
+ const sitemapUrl = resolve(context, sitemap);
140
132
  // eslint-disable-next-line import/no-dynamic-require
141
133
  let source = require(sitemapUrl);
142
134
  if (isFunction(source))
@@ -146,11 +138,11 @@ export default function configFactory(ops) {
146
138
  sm.write(item);
147
139
  });
148
140
  sm.end();
149
- void streamToPromise(sm).then((sitemap) => {
150
- const outUrl = resolve(o.context, o.outputPath);
141
+ void streamToPromise(sm).then((sitemapRes) => {
142
+ const outUrl = resolve(context, outputPath);
151
143
  if (!fs.existsSync(outUrl))
152
144
  fs.mkdirSync(outUrl);
153
- fs.writeFileSync(resolve(o.context, o.outputPath, 'sitemap.xml'), new DataView(sitemap.buffer));
145
+ fs.writeFileSync(resolve(context, outputPath, 'sitemap.xml'), new DataView(sitemapRes.buffer));
154
146
  });
155
147
  }
156
148
  // TODO: Once all assets are named by hashes, we probably don't need build
@@ -159,10 +151,10 @@ export default function configFactory(ops) {
159
151
  // timestamp, and any other similar information to the actual app, so it
160
152
  // can be used in some scenarious.
161
153
  let buildInfo;
162
- const buildInfoUrl = resolve(o.context, '.build-info');
163
- if (o.keepBuildInfo) {
154
+ const buildInfoUrl = resolve(context, '.build-info');
155
+ if (keepBuildInfo) {
164
156
  // If "true" - attempt to load from the filesystem.
165
- if (o.keepBuildInfo === true) {
157
+ if (keepBuildInfo === true) {
166
158
  if (fs.existsSync(buildInfoUrl)) {
167
159
  buildInfo = JSON.parse(fs.readFileSync(buildInfoUrl, 'utf8'));
168
160
  }
@@ -170,7 +162,7 @@ export default function configFactory(ops) {
170
162
  // to use in the build.
171
163
  }
172
164
  else
173
- buildInfo = o.keepBuildInfo;
165
+ buildInfo = keepBuildInfo;
174
166
  }
175
167
  // Even if "keepBuildInfo" option was provided, we still generate a new
176
168
  // build info object in case nothing could be loaded.
@@ -178,57 +170,55 @@ export default function configFactory(ops) {
178
170
  /* A random 32-bit key, that can be used for encryption. */
179
171
  key: randomBytes(32).toString('base64'),
180
172
  /* Public path used during build. */
181
- publicPath: o.publicPath,
173
+ publicPath,
182
174
  /* `true` if client-side code should setup a service worker. */
183
- useServiceWorker: Boolean(o.workbox),
175
+ useServiceWorker: Boolean(workbox),
184
176
  // Build timestamp.
185
177
  timestamp: new Date().toISOString(),
186
178
  }));
187
179
  // If not opted-out, we write the build info to the filesystem. We also attach
188
180
  // it to the factory function itself, so it can be easily accessed right after
189
181
  // the factory call in testing scenarios.
190
- if (!o.dontEmitBuildInfo) {
182
+ if (!dontEmitBuildInfo) {
191
183
  // Note: this is needed if "fs" option is provided, to ensure the factory
192
184
  // does not crash if the folder is not created in that filesystem.
193
- fs.mkdirSync(o.context, { recursive: true });
185
+ fs.mkdirSync(context, { recursive: true });
194
186
  fs.writeFileSync(buildInfoUrl, JSON.stringify(buildInfo));
195
187
  }
196
188
  /* Entry points normalization. */
197
- const entry = [
189
+ const normalizedEntry = [
198
190
  'nodelist-foreach-polyfill',
199
- ...Array.isArray(o.entry) ? o.entry : [o.entry],
191
+ ...Array.isArray(entry) ? entry : [entry],
200
192
  ];
201
193
  const plugins = [
202
194
  new webpack.DefinePlugin({ BUILD_INFO: JSON.stringify(buildInfo) }),
203
195
  ];
204
- if (!ops.dontUseProgressPlugin)
196
+ if (!dontUseProgressPlugin)
205
197
  plugins.push(new webpack.ProgressPlugin());
206
198
  /* Adds InjectManifest plugin from WorkBox, if opted to. */
207
- if (o.workbox) {
208
- if (!isObject(o.workbox))
209
- o.workbox = {};
210
- plugins.push(new WorkboxPlugin.InjectManifest(Object.assign(Object.assign({ swSrc: resolve(import.meta.dirname, '../workbox/default.js') }, o.workbox), { swDest: '__service-worker.js' })));
199
+ if (workbox) {
200
+ plugins.push(new WorkboxPlugin.InjectManifest(Object.assign(Object.assign({ swSrc: resolve(import.meta.dirname, '../workbox/default.js') }, workbox === true ? {} : workbox), { swDest: '__service-worker.js' })));
211
201
  }
212
- let { babelLoaderExclude } = ops;
213
- if (babelLoaderExclude) {
214
- if (!Array.isArray(babelLoaderExclude))
202
+ let babelLoaderExclude2 = babelLoaderExclude;
203
+ if (babelLoaderExclude2) {
204
+ if (!Array.isArray(babelLoaderExclude2))
215
205
  throw Error('Not supported');
216
206
  // BEWARE: This ensures Babel loader does not process CoreJS library,
217
207
  // which would break it creating circular references in its code.
218
- babelLoaderExclude = [...babelLoaderExclude, COREJS_REGEX];
208
+ babelLoaderExclude2 = [...babelLoaderExclude2, COREJS_REGEX];
219
209
  }
220
210
  else {
221
- babelLoaderExclude = [COREJS_REGEX];
211
+ babelLoaderExclude2 = [COREJS_REGEX];
222
212
  }
223
213
  const res = {
224
- context: o.context,
225
- entry,
214
+ context,
215
+ entry: normalizedEntry,
226
216
  experiments: { css: true },
227
- mode: o.mode,
217
+ mode,
228
218
  module: {
229
219
  generator: {
230
220
  'css/module': {
231
- localIdentName: localIdentNameFactory(o.cssLocalIdent),
221
+ localIdentName: localIdentNameFactory(cssLocalIdent),
232
222
  },
233
223
  },
234
224
  parser: {
@@ -254,11 +244,11 @@ export default function configFactory(ops) {
254
244
  // Loads JS modules (.cjs, .js, .jsx, .mjs); TS modules (.ts, .tsx);
255
245
  // and SVG assets (.svg).
256
246
  test: /\.(cjs|js|jsx|mjs|svg|ts|tsx)$/,
257
- exclude: babelLoaderExclude,
247
+ exclude: babelLoaderExclude2,
258
248
  loader: 'babel-loader',
259
- options: Object.assign({ babelrc: false, configFile: false, envName: o.babelEnv, presets: [['@dr.pogodin/react-utils/config/babel/webpack', {
260
- typescript: ops.typescript,
261
- }]], sourceType: 'unambiguous' }, o.babelLoaderOptions),
249
+ options: Object.assign({ babelrc: false, configFile: false, envName: babelEnv, presets: [['@dr.pogodin/react-utils/config/babel/webpack', {
250
+ typescript,
251
+ }]], sourceType: 'unambiguous' }, babelLoaderOptions),
262
252
  }, {
263
253
  /* Loads image assets. */
264
254
  test: /\.(gif|jpe?g|png)$/,
@@ -284,17 +274,17 @@ export default function configFactory(ops) {
284
274
  output: {
285
275
  chunkFilename: '[contenthash].js',
286
276
  filename: '[contenthash].js',
287
- path: resolve(import.meta.dirname, o.context, o.outputPath),
288
- publicPath: `${o.publicPath}/`,
277
+ path: resolve(import.meta.dirname, context, outputPath),
278
+ publicPath: `${publicPath}/`,
289
279
  },
290
280
  plugins,
291
281
  resolve: {
292
282
  alias: {
293
283
  // Aliases to JS an JSX files are handled by Babel.
294
- assets: resolve(o.context, 'src/assets'),
295
- components: resolve(o.context, 'src/shared/components'),
296
- fonts: resolve(o.context, 'src/assets/fonts'),
297
- styles: resolve(o.context, 'src/styles'),
284
+ assets: resolve(context, 'src/assets'),
285
+ components: resolve(context, 'src/shared/components'),
286
+ fonts: resolve(context, 'src/assets/fonts'),
287
+ styles: resolve(context, 'src/styles'),
298
288
  },
299
289
  extensions: [
300
290
  '.ts',
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.57.0-alpha.2",
2
+ "version": "1.57.0",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-run-with-babel": "bin/run-with-babel.js",
@@ -11,16 +11,16 @@
11
11
  "dependencies": {
12
12
  "@babel/runtime-corejs3": "^8.0.6",
13
13
  "@commander-js/extra-typings": "^15.0.0",
14
- "@dr.pogodin/babel-plugin-react-css-modules": "^8.0.0-alpha.8",
15
- "@dr.pogodin/csurf": "^1.17.1",
14
+ "@dr.pogodin/babel-plugin-react-css-modules": "^8.0.0",
15
+ "@dr.pogodin/csurf": "^1.18.1",
16
16
  "@dr.pogodin/js-utils": "^0.2.0",
17
17
  "@dr.pogodin/react-global-state": "^0.25.0",
18
- "@dr.pogodin/react-helmet": "^3.2.3",
18
+ "@dr.pogodin/react-helmet": "^3.3.2",
19
19
  "@dr.pogodin/react-themes": "^1.11.0",
20
20
  "@jest/environment": "^30.5.2",
21
21
  "axios": "^1.20.0",
22
22
  "commander": "^15.0.0",
23
- "compression": "^1.8.1",
23
+ "compression": "^1.8.2",
24
24
  "config": "^5.0.1",
25
25
  "cookie": "^2.0.1",
26
26
  "cookie-parser": "^1.4.7",
@@ -31,15 +31,15 @@
31
31
  "helmet": "^8.3.0",
32
32
  "http-status-codes": "^2.3.0",
33
33
  "lodash-es": "^4.18.1",
34
- "morgan": "^1.12.0",
34
+ "morgan": "^1.12.1",
35
35
  "qs": "^6.16.0",
36
36
  "raf": "^3.4.1",
37
- "react": "^19.2.8",
38
- "react-dom": "^19.2.8",
39
- "react-router": "^8.3.1",
37
+ "react": "^19.3.0",
38
+ "react-dom": "^19.3.0",
39
+ "react-router": "^8.4.0",
40
40
  "request-ip": "^3.3.0",
41
41
  "rimraf": "^6.1.3",
42
- "serialize-javascript": "^7.1.1",
42
+ "serialize-javascript": "^7.1.2",
43
43
  "serve-favicon": "^2.5.1",
44
44
  "source-map-support": "^0.5.21",
45
45
  "winston": "^3.19.0"
@@ -60,7 +60,7 @@
60
60
  "@jest/globals": "^30.5.2",
61
61
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
62
62
  "@standard-schema/spec": "^1.1.0",
63
- "@testing-library/dom": "^10.4.1",
63
+ "@testing-library/dom": "^10.4.2",
64
64
  "@testing-library/react": "^16.3.3",
65
65
  "@testing-library/user-event": "^14.6.7",
66
66
  "@tsconfig/recommended": "^1.0.13",
@@ -74,8 +74,8 @@
74
74
  "@types/lodash-es": "^4.17.12",
75
75
  "@types/morgan": "^1.9.10",
76
76
  "@types/pretty": "^2.0.3",
77
- "@types/react": "^19.2.18",
78
- "@types/react-dom": "^19.2.7",
77
+ "@types/react": "^19.3.0",
78
+ "@types/react-dom": "^19.3.0",
79
79
  "@types/request-ip": "^0.0.41",
80
80
  "@types/serialize-javascript": "^5.0.4",
81
81
  "@types/serve-favicon": "^2.5.7",
@@ -86,27 +86,27 @@
86
86
  "babel-plugin-module-resolver": "^5.0.3",
87
87
  "babel-plugin-polyfill-corejs3": "^1.0.0",
88
88
  "babel-plugin-react-compiler": "^1.0.0",
89
- "cssnano": "^9.1.2",
89
+ "cssnano": "^9.2.2",
90
90
  "identity-obj-proxy": "^3.0.0",
91
91
  "jest": "^30.5.2",
92
92
  "jest-environment-jsdom": "^30.5.2",
93
93
  "memfs": "^4.71.0",
94
- "minimizer-webpack-plugin": "^5.12.0",
94
+ "minimizer-webpack-plugin": "^5.13.0",
95
95
  "mockdate": "^3.0.5",
96
96
  "nodelist-foreach-polyfill": "^1.2.0",
97
97
  "postcss": "^8.5.28",
98
98
  "postcss-scss": "^4.0.9",
99
99
  "pretty": "^2.0.0",
100
- "react-refresh": "^0.18.0",
100
+ "react-refresh": "^0.19.0",
101
101
  "sass": "^1.104.1",
102
102
  "sass-loader": "^17.0.1",
103
103
  "sitemap": "^9.0.1",
104
104
  "source-map-loader": "^5.0.0",
105
- "stylelint": "^17.15.0",
105
+ "stylelint": "^17.16.0",
106
106
  "stylelint-config-standard-scss": "^17.0.0",
107
- "supertest": "^7.2.2",
108
- "tsc-alias": "^1.9.4",
109
- "tstyche": "^7.2.4",
107
+ "supertest": "^7.3.1",
108
+ "tsc-alias": "^1.9.7",
109
+ "tstyche": "^7.2.5",
110
110
  "typed-scss-modules": "^8.1.1",
111
111
  "typescript": "^6.0.3",
112
112
  "webpack": "^5.111.1",