@pushwoosh/frontend-builder-engine 5.3.1 → 5.4.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/README.md CHANGED
@@ -95,10 +95,19 @@ module.exports = {
95
95
  };
96
96
  ```
97
97
 
98
+ A list externalises only the named kit packages, the rest stays bundled; `true` is the full list above.
99
+ A name outside that list fails the build.
100
+
101
+ ```js
102
+ module.exports = {
103
+ sharedKit: ['@pushwoosh/kit-icons'],
104
+ };
105
+ ```
106
+
98
107
  Only the package roots are external, because only roots are in the import map. A deep import such as
99
108
  `@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.
109
+ (its own React contexts), so with `sharedKit` it fails the build instead, for the externalised packages
110
+ only; import them through their roots. Turn the option on after every listed name is in the import map.
102
111
 
103
112
  ## Migration from v3
104
113
 
@@ -43,11 +43,32 @@ const sharedKitExternals = [
43
43
  '@pushwoosh/kit-icons',
44
44
  ];
45
45
 
46
+ const resolveSharedKit = (option) => {
47
+ if (!option) {
48
+ return [];
49
+ }
50
+ if (option === true) {
51
+ return sharedKitExternals;
52
+ }
53
+ if (!Array.isArray(option)) {
54
+ throw new Error('pushwoosh.config.js: sharedKit must be true or a list of kit package names');
55
+ }
56
+ const unknown = option.filter((name) => !sharedKitExternals.includes(name));
57
+ if (unknown.length > 0) {
58
+ throw new Error(`pushwoosh.config.js: sharedKit lists ${unknown.join(', ')}, not a kit package; allowed: ${sharedKitExternals.join(', ')}`);
59
+ }
60
+ return option;
61
+ };
62
+
46
63
  class SharedKitDeepImportGuard {
64
+ constructor(packages) {
65
+ this.packages = packages;
66
+ }
67
+
47
68
  apply(compiler) {
48
69
  compiler.hooks.normalModuleFactory.tap('SharedKitDeepImportGuard', (factory) => {
49
70
  factory.hooks.beforeResolve.tap('SharedKitDeepImportGuard', ({ request }) => {
50
- const root = sharedKitExternals.find((name) => request.startsWith(`${name}/`));
71
+ const root = this.packages.find((name) => request.startsWith(`${name}/`));
51
72
  if (root) {
52
73
  throw new Error(`${request}: with sharedKit the kit loads from the import map by its package root only, import from '${root}'`);
53
74
  }
@@ -69,7 +90,8 @@ module.exports = (webpackConfigEnv, argv) => {
69
90
  const isProduction = NODE_ENV === 'production';
70
91
  const variables = loadVariables(!isProduction);
71
92
 
72
- const externals = pushwooshConfig.sharedKit ? [...defaultExternals, ...sharedKitExternals] : defaultExternals;
93
+ const sharedKit = resolveSharedKit(pushwooshConfig.sharedKit);
94
+ const externals = [...defaultExternals, ...sharedKit];
73
95
 
74
96
  const defaultConfig = singleSpaDefaults({
75
97
  orgName,
@@ -99,7 +121,7 @@ module.exports = (webpackConfigEnv, argv) => {
99
121
  },
100
122
  externals: pushwooshConfig.applicationExternals ? pushwooshConfig.applicationExternals(externals) : externals,
101
123
  plugins: [
102
- ...(pushwooshConfig.sharedKit ? [new SharedKitDeepImportGuard()] : []),
124
+ ...(sharedKit.length > 0 ? [new SharedKitDeepImportGuard(sharedKit)] : []),
103
125
  new webpack.DefinePlugin({
104
126
  process: {
105
127
  env: JSON.stringify({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/frontend-builder-engine",
3
- "version": "5.3.1",
3
+ "version": "5.4.0",
4
4
  "description": "Pushwoosh frontend builder engine",
5
5
  "repository": {
6
6
  "type": "git",