Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Remove foreman vendor #10342

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
engine-strict=true
legacy-peer-deps=true
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function onContentLoad() {
password_caps_lock_hint();

tfm.i18n.intl.ready.then(function() {
var tz = jstz.determine();
var tz = tfm.jstz.determine();
$.cookie('timezone', tz.name(), {
path: '/',
secure: location.protocol === 'https:',
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/host_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ function serializeForm() {
}

function subnet_contains(network, cidr, ip) {
if (!ip || 0 === ip.length || !ipaddr.isValid(ip)) {
if (!ip || 0 === ip.length || !tfm.ipaddr.isValid(ip)) {
return;
}

var addr = ipaddr.parse(ip);
var range = ipaddr.parse(network);
var addr = tfm.ipaddr.parse(ip);
var range = tfm.ipaddr.parse(network);

return addr.match(range, cidr);
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/subnets.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function subnetMaskChanged(field) {
}
if ($('input[id^=subnet_type_]:checked').val() === 'Subnet::Ipv4') {
try {
var cidr = ipaddr.IPv4.parse(mask).prefixLengthFromSubnetMask();
var cidr = tfm.ipaddr.IPv4.parse(mask).prefixLengthFromSubnetMask();
} catch (err) {
var cidr = '';
}
Expand Down
7 changes: 1 addition & 6 deletions app/helpers/reactjs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ def get_webpack_chunk(name, extension)
data['assetsByChunkName'][name]&.find { |value| value.end_with?(".#{extension}") }
end

def get_webpack_foreman_vendor_js
foreman_vendor_js = get_webpack_chunk('foreman-vendor', 'js')
javascript_include_tag("/webpack/#{foreman_vendor_js}")
end

def get_webpack_foreman_vendor_css
foreman_vendor_css = get_webpack_chunk('foreman-vendor', 'css')
foreman_vendor_css = get_webpack_chunk('vendorStyles', 'css')
stylesheet_link_tag("/webpack/#{foreman_vendor_css}")
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
</head>

<body class='<%= body_css_classes %>'>
<%= get_webpack_foreman_vendor_js %>

<%= javascript_include_tag("/webpack/#{get_webpack_chunk('vendor', 'js')}") %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('bundle', 'js')}") %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('reactExports', 'js')}") %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('bundle', 'js')}") %>
Comment on lines -41 to +42
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if needed


<%= javascript_include_tag 'application' %>
<%= webpacked_plugins_with_global_js %>
Expand Down
53 changes: 45 additions & 8 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
var path = require('path');
var webpack = require('webpack');
const dotenv = require('dotenv');
const root = path.resolve(__dirname, '..');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

dotenv.config();
var ForemanVendorPlugin = require('@theforeman/vendor')
.WebpackForemanVendorPlugin;
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
var vendorEntry = require('./webpack.vendor');
var fs = require('fs');
Expand All @@ -15,6 +16,18 @@ var pluginUtils = require('../script/plugin_webpack_directories');
var { generateExportsFile }= require('../webpack/assets/javascripts/exportAll');
var CompressionPlugin = require('compression-webpack-plugin');

const packageJsonPath = path.resolve(__dirname,'..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const dependencies = packageJson.dependencies || {};
const devDependencies = packageJson.devDependencies || {};
const allDependencies = { ...dependencies, ...devDependencies };
const shared = isPlugin => Object.keys(allDependencies).map(dep => ({
[dep]: {
eager: !isPlugin, // core should load all dependencies eagerly so they will be available for plugins
singleton: true,
requiredVersion: allDependencies[dep],
}}));

class AddRuntimeRequirement {
// to avoid "webpackRequire.l is not a function" error
// enables use of webpack require inside promise new promise
Expand Down Expand Up @@ -79,11 +92,18 @@ const commonConfig = function() {
os: require.resolve('os-browserify'),
},
alias: {
'patternfly-react$': path.resolve(__dirname,'..', 'node_modules/patternfly-react/dist/js/index.js'), // to avoid circular dependency in dist/esm
'/node_modules/jquery': path.resolve(__dirname, '..', 'webpack/assets/javascripts/jquery.js'),
'jquery': path.resolve(__dirname, '..', 'webpack/assets/javascripts/jquery.js'),
foremanReact: path.join(
__dirname,
'../webpack/assets/javascripts/react_app'
),
'react/jsx-runtime': 'react/jsx-runtime.js', // for react-dnd
'react/jsx-dev-runtime': 'react/jsx-dev-runtime.js', // for react-dnd

},

},
resolveLoader: {
modules: [path.resolve(__dirname, '..', 'node_modules')],
Expand Down Expand Up @@ -117,9 +137,6 @@ const commonConfig = function() {
],
},
plugins: [
new ForemanVendorPlugin({
mode,
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(mode),
Expand Down Expand Up @@ -160,13 +177,18 @@ const coreConfig = function() {
}

config.entry = {
/* keep bundle entry files and reactExports seperate to avoid late loading issues of mixed files, import in react_app only from react_app and node_modules */
bundle: { import: bundleEntry, dependOn: ['vendor', 'reactExports'] },
vendor: vendorEntry,
reactExports: path.join(
reactExports: {
import: path.join(
__dirname,
'..',
'webpack/assets/javascripts/all_react_app_exports.js'
),
),
dependOn: 'vendor',
},
vendor: vendorEntry,
vendorStyles: path.join(__dirname, '..', 'webpack/assets/javascripts/react_app/common/scss/vendor-core.scss'),
};
config.output = {
path: path.join(__dirname, '..', 'public', 'webpack'),
Expand All @@ -179,9 +201,12 @@ const coreConfig = function() {
};
var plugins = config.plugins;

plugins.push(
new MiniCssExtractPlugin());
plugins.push(
new ModuleFederationPlugin({
name: 'foremanReact',
shared: shared(false),
})
);
plugins.push(
Expand All @@ -191,8 +216,10 @@ const coreConfig = function() {
);
config.plugins = plugins;
var rules = config.module.rules;

rules.push({
test: /\.(sa|sc|c)ss$/,
exclude: /vendor-core/i,
use: [
{
loader: 'style-loader',
Expand All @@ -205,6 +232,14 @@ const coreConfig = function() {
'sass-loader',
],
});
rules.push({
test: /vendor-core/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
});
config.module.rules = rules;
return config;
};
Expand Down Expand Up @@ -276,8 +311,10 @@ const pluginConfig = function(plugin) {
name: pluginName,
filename: pluginName + '_remoteEntry.js',
exposes: pluginEntries,
shared: shared(true),
})
);

config.plugins = plugins;
var rules = config.module.rules;
rules.push({
Expand Down
123 changes: 122 additions & 1 deletion config/webpack.vendor.js
Original file line number Diff line number Diff line change
@@ -1 +1,122 @@
module.exports = ['react-intl', 'intl'];
/* eslint-disable */

module.exports = [
'intl',
/**
* React related
*/
'@apollo/client',
'@apollo/client/link/batch-http',
'@reduxjs/toolkit',
'core-js/shim',
'regenerator-runtime/runtime',
'formik',
'rc-input-number',
'react',
'react-ace',
'react-dom',
'react-dnd',
'react-dnd-html5-backend',
'react-debounce-input',
'react-diff-view',
'react-ellipsis-with-tooltip',
'react-onclickoutside',
'react-password-strength',
'react-router-dom',
'react-router-bootstrap',
'react-loading-skeleton',
'react-redux',
'redux',
'redux-logger',
'redux-thunk',
'reselect',
'prop-types',
'classnames',
'seamless-immutable',
'connected-react-router',
'react-helmet',
'react-intl',

/**
* Patternfly related
*/
'patternfly-react',
'patternfly-react-extensions',
'@patternfly/react-core',
'@patternfly/react-icons',
'@patternfly/react-table',
'@patternfly/react-tokens',
'@patternfly/react-styles',
'@patternfly/react-charts',
// '@redhat-cloud-services/frontend-components',

/**
* ace-builds related
*/
'ace-builds',
'ace-builds/src-noconflict/ace',
'ace-builds/src-noconflict/ext-language_tools',
'ace-builds/src-noconflict/mode-ruby',
'ace-builds/src-noconflict/mode-json',
'ace-builds/src-noconflict/mode-sh',
'ace-builds/src-noconflict/mode-html_ruby',
'ace-builds/src-noconflict/mode-xml',
'ace-builds/src-noconflict/mode-yaml',
'ace-builds/src-noconflict/theme-github',
'ace-builds/src-noconflict/theme-monokai',
'ace-builds/src-noconflict/keybinding-vim',
'ace-builds/src-noconflict/keybinding-emacs',
'ace-builds/src-min-noconflict/ext-searchbox',

/**
* UUID
*/
'uuid',
'uuid/v1',
'uuid/v3',
'uuid/v4',
'uuid/v5',

'jstz',
'diff',
/**
* Custom modules
*/
// {
// name: 'jquery',
// path: '@theforeman/vendor-core/lib/customModules/jquery.js',
// },
// {
// name: 'jstz',
// window: 'jstz',
// },
// {
// name: 'ipaddr.js',
// window: 'ipaddr',
// },
// {
// name: 'diff',
// window: 'diff',
// },

/**
* Other packages
*/
'history',
'number_helpers',
'lodash',
'axios',
'file-saver',
'humanize-duration',
'unidiff',
'urijs',
'yup',
'select2',
'multiselect',
'@novnc/novnc/core/rfb',
'@novnc/novnc',

// '@spice-project/spice-html5',
// '@webcomponents/webcomponentsjs/webcomponents-bundle',
// '@webcomponents/webcomponentsjs/custom-elements-es5-adapter',
];
32 changes: 0 additions & 32 deletions developer_docs/adding-dependencies.asciidoc

This file was deleted.

Loading
Loading