@pushwoosh/frontend-builder-engine 5.2.0 → 5.3.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.
package/README.md CHANGED
@@ -81,6 +81,25 @@ React 19, bundled into `index.mjs` while `react` itself stays external. Componen
81
81
  handle are left as they are (the default `panicThreshold: 'none'`). The option affects application
82
82
  builds only; `lib:build` does not read it.
83
83
 
84
+ ### Shared kit (opt-in)
85
+
86
+ With `sharedKit: true` the kit stops being bundled into the app: `@pushwoosh/dumb-components`,
87
+ `smart-components-kit`, `kit-helpers`, `kit-constants`, `kit-typography`, `kit-charts`, `spa-context`,
88
+ `single-spa`, `brand-book` and `@pushwoosh/kit-icons` join `defaultExternals` and load from the CDN
89
+ through the root-config import map, like `@pushwoosh/http-client`. `applicationExternals` receives the
90
+ extended list.
91
+
92
+ ```js
93
+ module.exports = {
94
+ sharedKit: true,
95
+ };
96
+ ```
97
+
98
+ Only the package roots are external, because only roots are in the import map. A deep import such as
99
+ `@pushwoosh/dumb-components/polyglot` would be bundled into the app as a second copy of the module
100
+ (its own React contexts), so with `sharedKit` it fails the build instead; import the kit through its
101
+ roots. Turn the option on after every one of these names is in the import map.
102
+
84
103
  ## Migration from v3
85
104
 
86
105
  v3 is deprecated: its `dist/index.js` is not an ES module, and the platform loads native ES modules
@@ -30,6 +30,32 @@ const defaultExternals = [
30
30
  '@pushwoosh/session-store',
31
31
  ];
32
32
 
33
+ const sharedKitExternals = [
34
+ '@pushwoosh/dumb-components',
35
+ '@pushwoosh/smart-components-kit',
36
+ '@pushwoosh/kit-helpers',
37
+ '@pushwoosh/kit-constants',
38
+ '@pushwoosh/kit-typography',
39
+ '@pushwoosh/kit-charts',
40
+ '@pushwoosh/spa-context',
41
+ '@pushwoosh/single-spa',
42
+ '@pushwoosh/brand-book',
43
+ '@pushwoosh/kit-icons',
44
+ ];
45
+
46
+ class SharedKitDeepImportGuard {
47
+ apply(compiler) {
48
+ compiler.hooks.normalModuleFactory.tap('SharedKitDeepImportGuard', (factory) => {
49
+ factory.hooks.beforeResolve.tap('SharedKitDeepImportGuard', ({ request }) => {
50
+ const root = sharedKitExternals.find((name) => request.startsWith(`${name}/`));
51
+ if (root) {
52
+ throw new Error(`${request}: with sharedKit the kit loads from the import map by its package root only, import from '${root}'`);
53
+ }
54
+ });
55
+ });
56
+ }
57
+ }
58
+
33
59
  module.exports = (webpackConfigEnv, argv) => {
34
60
  const cwd = process.cwd();
35
61
  const pushwooshConfig = loadPushwooshConfig();
@@ -43,6 +69,8 @@ module.exports = (webpackConfigEnv, argv) => {
43
69
  const isProduction = NODE_ENV === 'production';
44
70
  const variables = loadVariables(!isProduction);
45
71
 
72
+ const externals = pushwooshConfig.sharedKit ? [...defaultExternals, ...sharedKitExternals] : defaultExternals;
73
+
46
74
  const defaultConfig = singleSpaDefaults({
47
75
  orgName,
48
76
  projectName,
@@ -69,8 +97,9 @@ module.exports = (webpackConfigEnv, argv) => {
69
97
  '~/src': path.resolve(cwd, './src'),
70
98
  },
71
99
  },
72
- externals: pushwooshConfig.applicationExternals ? pushwooshConfig.applicationExternals(defaultExternals) : defaultExternals,
100
+ externals: pushwooshConfig.applicationExternals ? pushwooshConfig.applicationExternals(externals) : externals,
73
101
  plugins: [
102
+ ...(pushwooshConfig.sharedKit ? [new SharedKitDeepImportGuard()] : []),
74
103
  new webpack.DefinePlugin({
75
104
  process: {
76
105
  env: JSON.stringify({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/frontend-builder-engine",
3
- "version": "5.2.0",
3
+ "version": "5.3.1",
4
4
  "description": "Pushwoosh frontend builder engine",
5
5
  "repository": {
6
6
  "type": "git",