@redhat-cloud-services/frontend-components-config-utilities 1.5.22 → 1.5.24

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.
Files changed (2) hide show
  1. package/chunk-mapper.js +45 -21
  2. package/package.json +1 -1
package/chunk-mapper.js CHANGED
@@ -1,35 +1,59 @@
1
+ const hotChunkRegex = RegExp('\\.hot-update\\.js$');
1
2
  class ChunkMapper {
2
3
  constructor(options) {
4
+ const { _unstableHotReload, ...rest } = options;
3
5
  this.config = {};
4
- this.options = options || {};
6
+ this.options = rest || {};
7
+ this._unstableHotReload = _unstableHotReload;
5
8
  }
6
9
 
7
10
  apply(compiler) {
8
11
  compiler.hooks.emit.tap('ChunkMapper', (compilation) => {
9
12
  const prefix = this.options.prefix || (RegExp('^/.*/$').test(compiler.options.output.publicPath) ? compiler.options.output.publicPath : '/');
10
- compilation.chunks.forEach(({ name, files, runtime }) => {
13
+ if (this._unstableHotReload) {
11
14
  const modules = Array.isArray(this.options.modules) ? this.options.modules : [this.options.modules];
12
- if (modules.find((oneEntry) => RegExp(`${oneEntry}$`).test(runtime))) {
13
- this.config[runtime] = {
14
- ...(this.config[runtime] || {}),
15
- ...(name === runtime
16
- ? {
17
- entry: Array.from(files)
18
- .map((item) => `${prefix}${item}`)
19
- .filter((file, _index, array) => {
20
- if (array.find((item) => !RegExp('\\.hot-update\\.js$').test(item))) {
21
- return !RegExp('\\.hot-update\\.js$').test(file);
22
- }
15
+ // TODO: Investigate if it is possible we could use the same script for normal builds
16
+ const hotEntries = Array.from(compilation.chunks)
17
+ .filter(({ name, runtime }) => !!modules.find((moduleName) => moduleName === name) || name === runtime)
18
+ .map(({ files }) =>
19
+ Array.from(files)
20
+ .filter((file) => !hotChunkRegex.test(file))
21
+ .map((file) => `${prefix}${file}`)
22
+ )
23
+ .flat();
23
24
 
24
- return true;
25
- }),
26
- }
27
- : {
28
- modules: [...(this.config[runtime].modules || []), ...Array.from(files).map((item) => `${prefix}${item}`)],
29
- }),
25
+ modules.forEach((name) => {
26
+ this.config = {
27
+ [name]: {
28
+ entry: hotEntries,
29
+ },
30
30
  };
31
- }
32
- });
31
+ });
32
+ } else {
33
+ compilation.chunks.forEach(({ name, files, runtime }) => {
34
+ const modules = Array.isArray(this.options.modules) ? this.options.modules : [this.options.modules];
35
+ if (modules.find((oneEntry) => RegExp(`${oneEntry}$`).test(runtime))) {
36
+ this.config[runtime] = {
37
+ ...(this.config[runtime] || {}),
38
+ ...(name === runtime
39
+ ? {
40
+ entry: Array.from(files)
41
+ .map((item) => `${prefix}${item}`)
42
+ .filter((file, _index, array) => {
43
+ if (array.find((item) => !hotChunkRegex.test(item))) {
44
+ return !hotChunkRegex.test(file);
45
+ }
46
+
47
+ return true;
48
+ }),
49
+ }
50
+ : {
51
+ modules: [...(this.config[runtime].modules || []), ...Array.from(files).map((item) => `${prefix}${item}`)],
52
+ }),
53
+ };
54
+ }
55
+ });
56
+ }
33
57
 
34
58
  compilation.assets['fed-mods.json'] = {
35
59
  source: () => JSON.stringify(this.config, null, 4),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config-utilities",
3
- "version": "1.5.22",
3
+ "version": "1.5.24",
4
4
  "description": "Utilities for shared config used in RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {