@shopgate/webpack 7.31.0-alpha.2 → 7.31.0-alpha.3

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Asserts that a condition is truthy.
3
+ *
4
+ * @param {unknown} condition Condition to assert.
5
+ * @param {string} [msg] Optional error message.
6
+ * @returns {void}
7
+ */
8
+ export function assert(condition, msg) {
9
+ if (!condition) {
10
+ throw new Error(msg);
11
+ }
12
+ }
@@ -0,0 +1,72 @@
1
+ import { assert } from "./assert";
2
+ import { typeGuard } from "./typeGuard";
3
+
4
+ /**
5
+ * Checks whether an argument exposes a non-native custom toString implementation.
6
+ *
7
+ * @param {any} arg Potential value passed to classnames.
8
+ * @returns {boolean} True when a custom toString can be used to derive a class name.
9
+ */
10
+ function hasCustomToString(arg) {
11
+ return (
12
+ typeof arg.toString === 'function' &&
13
+ arg.toString !== Object.prototype.toString &&
14
+ !String(arg.toString).includes('[native code]')
15
+ );
16
+ }
17
+
18
+ /** Copy pasted from
19
+ * https://github.com/emotion-js/emotion/blob/23f43ab9f24d44219b0b007a00f4ac681fe8712e/packages/react/src/class-names.js#L17-L63
20
+ **/
21
+ export const classnames = (args) => {
22
+ const len = args.length;
23
+ let i = 0;
24
+ let cls = "";
25
+ for (; i < len; i++) {
26
+ const arg = args[i];
27
+ if (arg == null)
28
+ continue;
29
+ let toAdd;
30
+ switch (typeof arg) {
31
+ case "boolean":
32
+ break;
33
+ case "object": {
34
+ if (Array.isArray(arg)) {
35
+ toAdd = classnames(arg);
36
+ }
37
+ else {
38
+ assert(!typeGuard(arg, false));
39
+
40
+ // Handle glamor style objects passed to cx() without explicit toString invocation.
41
+ if (hasCustomToString(arg)) {
42
+ toAdd = arg.toString();
43
+ break;
44
+ }
45
+
46
+ if (process.env.NODE_ENV !== "production" &&
47
+ arg.styles !== undefined &&
48
+ arg.name !== undefined) {
49
+ console.error("You have passed styles created with `css` from `@emotion/react` package to the `cx`.\n" +
50
+ "`cx` is meant to compose class names (strings) so you should convert those styles to a class name by passing them to the `css` received from <ClassNames/> component.");
51
+ }
52
+ toAdd = "";
53
+ for (const k in arg) {
54
+ if (arg[k] && k) {
55
+ toAdd && (toAdd += " ");
56
+ toAdd += k;
57
+ }
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ default: {
63
+ toAdd = arg;
64
+ }
65
+ }
66
+ if (toAdd) {
67
+ cls && (cls += " ");
68
+ cls += toAdd;
69
+ }
70
+ }
71
+ return cls;
72
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Tiny type-guard helper compatible with tss-react internals.
3
+ *
4
+ * @param {unknown} _value Input value.
5
+ * @param {boolean} isMatched Match result.
6
+ * @returns {boolean}
7
+ */
8
+ export function typeGuard(_value, isMatched) {
9
+ return isMatched;
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/webpack",
3
- "version": "7.31.0-alpha.2",
3
+ "version": "7.31.0-alpha.3",
4
4
  "description": "The webpack configuration for Shopgate's Engage.",
5
5
  "main": "webpack.config.js",
6
6
  "license": "Apache-2.0",
package/webpack.config.js CHANGED
@@ -113,6 +113,10 @@ const config = {
113
113
  '@shopgate-ps/pwa-extension-kit/': path.resolve(__dirname, 'local-packages/pwa-extension-kit/src/'),
114
114
  '@shopgate/pwa-extension-kit': path.resolve(__dirname, 'local-packages/pwa-extension-kit/src'),
115
115
  '@shopgate/pwa-extension-kit/': path.resolve(__dirname, 'local-packages/pwa-extension-kit/src/'),
116
+
117
+ // Replace tss-react classnames helper with a local patched version
118
+ 'tss-react/esm/tools/classnames.js$': path.resolve(__dirname, 'local-packages/tss-react/esm/tools/classnames.js'),
119
+ 'tss-react/esm/tools/classnames$': path.resolve(__dirname, 'local-packages/tss-react/esm/tools/classnames.js'),
116
120
  },
117
121
  modules: [
118
122
  'node_modules',
@@ -130,6 +134,15 @@ const config = {
130
134
  // provided by extensions via extension-config.json
131
135
  new ShopgateIndexerPlugin(),
132
136
 
137
+ // Ensure internal relative imports inside tss-react resolve
138
+ // to our patched classnames file.
139
+ new webpack.NormalModuleReplacementPlugin(/^\.\/tools\/classnames(\.js)?$/, (resource) => {
140
+ if (resource.context.includes(`${path.sep}tss-react${path.sep}esm`)) {
141
+ // eslint-disable-next-line no-param-reassign
142
+ resource.request = path.resolve(__dirname, 'local-packages/tss-react/esm/tools/classnames.js');
143
+ }
144
+ }),
145
+
133
146
  // Inject environment variables so that they are available within the bundled code
134
147
  new webpack.DefinePlugin({
135
148
  'process.env': {