Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: RedHatInsights/frontend-components
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 53eccb8c303b15bbe5b50f6d384de2c2fc1cbfe5
Choose a base ref
...
head repository: RedHatInsights/frontend-components
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cc52975945bf5cec478a3fad6d91c5b1ae4d4b70
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Oct 24, 2022

  1. Copy the full SHA
    2c78e0e View commit details
  2. Copy the full SHA
    ec88b91 View commit details
  3. Merge pull request #1643 from Hyperkid123/ts-fork-optional

    Use ForkTsCheckerWebpackPlugin only if tsconfig exists.
    Hyperkid123 authored Oct 24, 2022
    Copy the full SHA
    cc52975 View commit details
Showing with 73 additions and 57 deletions.
  1. +1 −1 packages/config/package.json
  2. +54 −49 packages/config/src/plugins.js
  3. +18 −7 packages/config/src/plugins.test.js
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redhat-cloud-services/frontend-components-config",
"version": "4.6.23",
"version": "4.6.24",
"description": "Config plugins and settings for RedHat Cloud Services project.",
"main": "index.js",
"bin": {
103 changes: 54 additions & 49 deletions packages/config/src/plugins.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
const ChunkMapperPlugin = require('@redhat-cloud-services/frontend-components-config-utilities/chunk-mapper');
const jsVarName = require('@redhat-cloud-services/frontend-components-config-utilities/jsVarName');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { glob } = require('glob');
const path = require('path');

module.exports = ({
rootFolder,
@@ -19,53 +21,56 @@ module.exports = ({
plugins,
useChromeTemplate = true,
definePlugin = {},
} = {}) => [
...(generateSourceMaps
? [
new SourceMapDevToolPlugin({
test: 'js',
exclude: /(node_modules|bower_components)/i,
filename: 'sourcemaps/[name].[contenthash].js.map',
}),
]
: []),
new MiniCssExtractPlugin({
chunkFilename: 'css/[name].[contenthash].css',
filename: 'css/[name].[contenthash].css',
ignoreOrder: true,
}),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: useChromeTemplate ? ['**/*', '!index.html'] : ['**/*'],
}),
...(useChromeTemplate
? []
: [
new HtmlWebpackPlugin({
title: 'My App',
filename: 'index.html',
template: `${rootFolder || ''}/src/index.html`,
inject: false,
...(htmlPlugin || {}),
}),
new HtmlReplaceWebpackPlugin([
{
pattern: '@@env',
replacement: appDeployment || '',
},
...(replacePlugin || []),
} = {}) => {
const hasTsConfig = glob.sync(path.resolve(rootFolder, './{tsconfig.json,!(node_modules)/**/tsconfig.json}')).length > 0;
return [
...(generateSourceMaps
? [
new SourceMapDevToolPlugin({
test: 'js',
exclude: /(node_modules|bower_components)/i,
filename: 'sourcemaps/[name].[contenthash].js.map',
}),
]
: []),
new MiniCssExtractPlugin({
chunkFilename: 'css/[name].[contenthash].css',
filename: 'css/[name].[contenthash].css',
ignoreOrder: true,
}),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: useChromeTemplate ? ['**/*', '!index.html'] : ['**/*'],
}),
...(useChromeTemplate
? []
: [
new HtmlWebpackPlugin({
title: 'My App',
filename: 'index.html',
template: `${rootFolder || ''}/src/index.html`,
inject: false,
...(htmlPlugin || {}),
}),
new HtmlReplaceWebpackPlugin([
{
pattern: '@@env',
replacement: appDeployment || '',
},
...(replacePlugin || []),
]),
]),
]),
new DefinePlugin({
// we have to wrap the appname string in another string because of how define plugin explodes strings
CRC_APP_NAME: JSON.stringify(insights?.appname),
...(definePlugin || {}),
}),
new ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
new ChunkMapperPlugin({ modules: [...(insights ? [jsVarName(insights.appname)] : []), ...(modules || [])] }),
new ForkTsCheckerWebpackPlugin(),
...(plugins || []),
];
new DefinePlugin({
// we have to wrap the appname string in another string because of how define plugin explodes strings
CRC_APP_NAME: JSON.stringify(insights?.appname),
...(definePlugin || {}),
}),
new ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
new ChunkMapperPlugin({ modules: [...(insights ? [jsVarName(insights.appname)] : []), ...(modules || [])] }),
...(hasTsConfig ? [new ForkTsCheckerWebpackPlugin()] : []),
...(plugins || []),
];
};
25 changes: 18 additions & 7 deletions packages/config/src/plugins.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import plugins from './plugins';
import path from 'path';

const HTML_WEBPACK = 2;
const REPLACE = 3;
const DEFINE_PLUGIN = 4;

describe('plugins generations, no option', () => {
const enabledPlugins = plugins({ useChromeTemplate: false });
const enabledPlugins = plugins({ useChromeTemplate: false, rootFolder: '/foo/bar' });

it('should generate plugins', () => {
expect(enabledPlugins.length).toBe(8);
expect(enabledPlugins.length).toBe(7);
});

it('should generate plugins with sourceMaps', () => {
const enabledPlugins = plugins({ generateSourceMaps: true, useChromeTemplate: false });
expect(enabledPlugins.length).toBe(9);
const enabledPlugins = plugins({ generateSourceMaps: true, useChromeTemplate: false, rootFolder: '/foo/bar' });
expect(enabledPlugins.length).toBe(8);
});

it('should generate correct template path for HtmlWebpackPlugin', () => {
expect(enabledPlugins[HTML_WEBPACK].userOptions.template).toBe('/src/index.html');
expect(enabledPlugins[HTML_WEBPACK].userOptions.template).toBe('/foo/bar/src/index.html');
});
});

describe('TS for plugins', () => {
const pluginsWithTs = plugins({ generateSourceMaps: true, useChromeTemplate: false, rootFolder: path.resolve(__dirname, '../../../') });
it('should have TSForkPlugin and 9 plugins in todal', () => {
expect(pluginsWithTs).toHaveLength(9);
});
});

@@ -30,21 +38,22 @@ describe('rootFolder', () => {
});

describe('appDeployment', () => {
const enabledPlugins = plugins({ appDeployment: '/test/folder', useChromeTemplate: false });
const enabledPlugins = plugins({ appDeployment: '/test/folder', useChromeTemplate: false, rootFolder: '/foo/bar' });

it('should replace correct string', () => {
enabledPlugins[REPLACE].replace({ html: 'string @@env' }, (_, { html }) => expect(html).toBe('string /test/folder'));
});
});

it('htmlPlugin should update', () => {
const enabledPlugins = plugins({ htmlPlugin: { title: 'myTitle' }, useChromeTemplate: false });
const enabledPlugins = plugins({ htmlPlugin: { title: 'myTitle' }, useChromeTemplate: false, rootFolder: '/foo/bar' });
expect(enabledPlugins[HTML_WEBPACK].userOptions.title).toBe('myTitle');
});

it('replacePlugin should update', () => {
const enabledPlugins = plugins({
useChromeTemplate: false,
rootFolder: '/foo/bar',
replacePlugin: [
{
pattern: '@@another',
@@ -58,13 +67,15 @@ it('replacePlugin should update', () => {
it('definePlugin should have default replace of CRC_APP_NAME', () => {
const enabledPlugins = plugins({
useChromeTemplate: false,
rootFolder: '/foo/bar',
insights: { appname: 'test_app' },
});
expect(enabledPlugins[DEFINE_PLUGIN].definitions.CRC_APP_NAME).toBe('"test_app"');
});

it('definePlugin should update', () => {
const enabledPlugins = plugins({
rootFolder: '/foo/bar',
useChromeTemplate: false,
definePlugin: {
SOME_VAR: JSON.stringify('test_val'),