@redhat-cloud-services/frontend-components-config 4.6.7 → 4.6.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config",
3
- "version": "4.6.7",
3
+ "version": "4.6.8",
4
4
  "description": "Config plugins and settings for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -53,7 +53,7 @@
53
53
  "util": "^0.12.4",
54
54
  "webpack": "^5.55.1",
55
55
  "webpack-cli": "^4.8.0",
56
- "webpack-dev-server": "4.3.1",
56
+ "webpack-dev-server": "4.8.1",
57
57
  "write-file-webpack-plugin": "^4.5.1",
58
58
  "yargs": "^17.2.1"
59
59
  }
package/src/plugins.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { SourceMapDevToolPlugin } = require('webpack');
2
- const { ProvidePlugin } = require('webpack');
2
+ const { ProvidePlugin, DefinePlugin } = require('webpack');
3
3
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
4
  const { CleanWebpackPlugin } = require('clean-webpack-plugin');
5
5
  const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -17,6 +17,7 @@ module.exports = ({
17
17
  generateSourceMaps,
18
18
  plugins,
19
19
  useChromeTemplate = false,
20
+ definePlugin = {},
20
21
  } = {}) => [
21
22
  ...(generateSourceMaps
22
23
  ? [
@@ -53,6 +54,11 @@ module.exports = ({
53
54
  },
54
55
  ...(replacePlugin || []),
55
56
  ]),
57
+ new DefinePlugin({
58
+ // we have to wrap the appname string in another string because of how define plugin explodes strings
59
+ CRC_APP_NAME: JSON.stringify(insights?.appname),
60
+ ...(definePlugin || {}),
61
+ }),
56
62
  ]),
57
63
  new ProvidePlugin({
58
64
  process: 'process/browser.js',
@@ -2,17 +2,18 @@ import plugins from './plugins';
2
2
 
3
3
  const HTML_WEBPACK = 2;
4
4
  const REPLACE = 3;
5
+ const DEFINE_PLUGIN = 4;
5
6
 
6
7
  describe('plugins generations, no option', () => {
7
8
  const enabledPlugins = plugins();
8
9
 
9
10
  it('should generate plugins', () => {
10
- expect(enabledPlugins.length).toBe(6);
11
+ expect(enabledPlugins.length).toBe(7);
11
12
  });
12
13
 
13
14
  it('should generate plugins with sourceMaps', () => {
14
15
  const enabledPlugins = plugins({ generateSourceMaps: true });
15
- expect(enabledPlugins.length).toBe(7);
16
+ expect(enabledPlugins.length).toBe(8);
16
17
  });
17
18
 
18
19
  it('should generate correct template path for HtmlWebpackPlugin', () => {
@@ -52,3 +53,19 @@ it('replacePlugin should update', () => {
52
53
  });
53
54
  enabledPlugins[REPLACE].replace({ html: '@@another string @@env' }, (_, { html }) => expect(html).toBe('test-string string '));
54
55
  });
56
+
57
+ it('definePlugin should have default replace of CRC_APP_NAME', () => {
58
+ const enabledPlugins = plugins({
59
+ insights: { appname: 'test_app' },
60
+ });
61
+ expect(enabledPlugins[DEFINE_PLUGIN].definitions.CRC_APP_NAME).toBe('"test_app"');
62
+ });
63
+
64
+ it('definePlugin should update', () => {
65
+ const enabledPlugins = plugins({
66
+ definePlugin: {
67
+ SOME_VAR: JSON.stringify('test_val'),
68
+ },
69
+ });
70
+ expect(enabledPlugins[DEFINE_PLUGIN].definitions.SOME_VAR).toBe('"test_val"');
71
+ });