@dr.pogodin/react-utils 1.45.0 → 1.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  type RequireWeakOptionsT = {
2
2
  basePath?: string;
3
- throwOnError?: boolean;
4
3
  };
5
4
  type RequireWeakResT<T> = T extends {
6
5
  default: infer D;
@@ -24,6 +24,11 @@ function configFactory(ops) {
24
24
  ];
25
25
  if (!ops.dontUseProgressPlugin)
26
26
  plugins.push(new webpack_1.ProgressPlugin());
27
+ plugins.push(new webpack_1.DefinePlugin({
28
+ // TODO: This is a hotfix - when Webpack build of the library is loaded
29
+ // it should consider itself running at the client side.
30
+ REACT_UTILS_WEBPACK_BUNDLE: 'true',
31
+ }));
27
32
  return {
28
33
  context: ops.context,
29
34
  entry: ops.entry,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.45.0",
2
+ "version": "1.46.1",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -73,7 +73,7 @@
73
73
  "@types/node-forge": "^1.3.14",
74
74
  "@types/pretty": "^2.0.3",
75
75
  "@types/react": "^19.2.2",
76
- "@types/react-dom": "^19.2.1",
76
+ "@types/react-dom": "^19.2.2",
77
77
  "@types/request-ip": "^0.0.41",
78
78
  "@types/serialize-javascript": "^5.0.4",
79
79
  "@types/serve-favicon": "^2.5.7",
@@ -103,7 +103,7 @@
103
103
  "resolve-url-loader": "^5.0.0",
104
104
  "sass": "^1.93.2",
105
105
  "sass-loader": "^16.0.5",
106
- "sitemap": "^8.0.0",
106
+ "sitemap": "^8.0.1",
107
107
  "source-map-loader": "^5.0.0",
108
108
  "stylelint": "^16.25.0",
109
109
  "stylelint-config-standard-scss": "^16.0.0",
@@ -9,7 +9,8 @@ export const IS_CLIENT_SIDE: boolean = typeof process !== 'object'
9
9
  // object, but without `versions` sub-object inside it.
10
10
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11
11
  || !process.versions?.node
12
- || !!global.REACT_UTILS_FORCE_CLIENT_SIDE;
12
+ || !!global.REACT_UTILS_FORCE_CLIENT_SIDE
13
+ || typeof REACT_UTILS_WEBPACK_BUNDLE !== 'undefined';
13
14
 
14
15
  /**
15
16
  * `true` within the server-side environment (node), `false` at client-side.
@@ -4,7 +4,6 @@ import { IS_CLIENT_SIDE } from './isomorphy';
4
4
 
5
5
  type RequireWeakOptionsT = {
6
6
  basePath?: string;
7
- throwOnError?: boolean;
8
7
  };
9
8
 
10
9
  type RequireWeakResT<T> = T extends { default: infer D }
@@ -32,46 +31,34 @@ export function requireWeak<T extends object>(
32
31
  let ops: RequireWeakOptionsT;
33
32
  if (typeof basePathOrOptions === 'string') {
34
33
  basePath = basePathOrOptions;
35
- ops = {};
36
34
  } else {
37
35
  ops = basePathOrOptions ?? {};
38
36
  ({ basePath } = ops);
39
37
  }
40
38
 
41
- // TODO: On one hand, this try/catch wrap silencing errors is bad, as it may
42
- // hide legit errors, in a way difficult to notice and understand; but on the
43
- // other hand it fails for some (unclear, but legit?) reasons in some
44
- // environments,
45
- // like during the static code generation for docs. Perhaps, something should
46
- // be implemented differently here.
47
- try {
48
- // eslint-disable-next-line no-eval
49
- const req = eval('require') as (path: string) => unknown;
39
+ // eslint-disable-next-line no-eval
40
+ const req = eval('require') as (path: string) => unknown;
50
41
 
51
- // eslint-disable-next-line @typescript-eslint/unbound-method
52
- const { resolve } = req('path') as typeof PathNS;
42
+ // eslint-disable-next-line @typescript-eslint/unbound-method
43
+ const { resolve } = req('path') as typeof PathNS;
53
44
 
54
- const path = basePath ? resolve(basePath, modulePath) : modulePath;
55
- const module = req(path) as T;
45
+ const path = basePath ? resolve(basePath, modulePath) : modulePath;
46
+ const module = req(path) as T;
56
47
 
57
- if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;
48
+ if (!('default' in module) || !module.default) return module as RequireWeakResT<T>;
58
49
 
59
- const { default: def, ...named } = module;
50
+ const { default: def, ...named } = module;
60
51
 
61
- const res = def as RequireWeakResT<T>;
52
+ const res = def as RequireWeakResT<T>;
62
53
 
63
- Object.entries(named).forEach(([name, value]) => {
64
- const assigned = res[name as keyof RequireWeakResT<T>];
65
- if (assigned) (res[name as keyof RequireWeakResT<T>] as unknown) = value;
66
- else if (assigned !== value) {
67
- throw Error('Conflict between default and named exports');
68
- }
69
- });
70
- return res;
71
- } catch (error) {
72
- if (ops.throwOnError) throw error;
73
- return null;
74
- }
54
+ Object.entries(named).forEach(([name, value]) => {
55
+ const assigned = res[name as keyof RequireWeakResT<T>];
56
+ if (assigned) (res[name as keyof RequireWeakResT<T>] as unknown) = value;
57
+ else if (assigned !== value) {
58
+ throw Error('Conflict between default and named exports');
59
+ }
60
+ });
61
+ return res;
75
62
  }
76
63
 
77
64
  /**
package/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // TODO: Double-check that let does not work?
2
2
  /* eslint-disable no-var */
3
3
  declare var IS_REACT_ACT_ENVIRONMENT: boolean | undefined;
4
+ declare var REACT_UTILS_WEBPACK_BUNDLE: boolean | undefined;
4
5
  declare var REACT_UTILS_LIBRARY_LOADED: boolean | undefined;
5
6
  declare var REACT_UTILS_FORCE_CLIENT_SIDE: boolean | undefined;
6
7
  /* eslint-enable no-var */