Skip to content

Commit 99923d6

Browse files
committed
Fixes #37882 - Remove @theforeman/vendor
1 parent 56b034d commit 99923d6

File tree

14 files changed

+293
-33
lines changed

14 files changed

+293
-33
lines changed

.npmrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
engine-strict=true
2-
legacy-peer-deps=true

app/assets/javascripts/application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function onContentLoad() {
8080
password_caps_lock_hint();
8181

8282
tfm.i18n.intl.ready.then(function() {
83-
var tz = jstz.determine();
83+
var tz = tfm.jstz.determine();
8484
$.cookie('timezone', tz.name(), {
8585
path: '/',
8686
secure: location.protocol === 'https:',

app/assets/javascripts/host_edit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ function serializeForm() {
402402
}
403403

404404
function subnet_contains(network, cidr, ip) {
405-
if (!ip || 0 === ip.length || !ipaddr.isValid(ip)) {
405+
if (!ip || 0 === ip.length || !tfm.ipaddr.isValid(ip)) {
406406
return;
407407
}
408408

409-
var addr = ipaddr.parse(ip);
410-
var range = ipaddr.parse(network);
409+
var addr = tfm.ipaddr.parse(ip);
410+
var range = tfm.ipaddr.parse(network);
411411

412412
return addr.match(range, cidr);
413413
}

app/assets/javascripts/subnets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function subnetMaskChanged(field) {
6969
}
7070
if ($('input[id^=subnet_type_]:checked').val() === 'Subnet::Ipv4') {
7171
try {
72-
var cidr = ipaddr.IPv4.parse(mask).prefixLengthFromSubnetMask();
72+
var cidr = tfm.ipaddr.IPv4.parse(mask).prefixLengthFromSubnetMask();
7373
} catch (err) {
7474
var cidr = '';
7575
}

app/helpers/reactjs_helper.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ def get_webpack_chunk(name, extension)
3636
data['assetsByChunkName'][name]&.find { |value| value.end_with?(".#{extension}") }
3737
end
3838

39-
def get_webpack_foreman_vendor_js
40-
foreman_vendor_js = get_webpack_chunk('foreman-vendor', 'js')
41-
javascript_include_tag("/webpack/#{foreman_vendor_js}")
42-
end
43-
4439
def get_webpack_foreman_vendor_css
45-
foreman_vendor_css = get_webpack_chunk('foreman-vendor', 'css')
40+
foreman_vendor_css = get_webpack_chunk('vendorStyles', 'css')
4641
stylesheet_link_tag("/webpack/#{foreman_vendor_css}")
4742
end
4843

app/views/layouts/base.html.erb

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<%= favicon_link_tag "favicon.ico"%>
1212

13+
<%= get_webpack_foreman_vendor_css %>
1314
<%= stylesheet_link_tag 'application' %>
1415
<%= yield(:stylesheets) %>
1516

@@ -35,10 +36,10 @@
3536
</head>
3637

3738
<body class='<%= body_css_classes %>'>
38-
<%= get_webpack_foreman_vendor_js %>
39+
3940
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('vendor', 'js')}") %>
40-
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('bundle', 'js')}") %>
4141
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('reactExports', 'js')}") %>
42+
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('bundle', 'js')}") %>
4243

4344
<%= javascript_include_tag 'application' %>
4445
<%= webpacked_plugins_with_global_js %>

config/webpack.config.js

+45-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
var path = require('path');
55
var webpack = require('webpack');
66
const dotenv = require('dotenv');
7+
const root = path.resolve(__dirname, '..');
8+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
9+
710
dotenv.config();
8-
var ForemanVendorPlugin = require('@theforeman/vendor')
9-
.WebpackForemanVendorPlugin;
1011
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
1112
var vendorEntry = require('./webpack.vendor');
1213
var fs = require('fs');
@@ -15,6 +16,18 @@ var pluginUtils = require('../script/plugin_webpack_directories');
1516
var { generateExportsFile }= require('../webpack/assets/javascripts/exportAll');
1617
var CompressionPlugin = require('compression-webpack-plugin');
1718

19+
const packageJsonPath = path.resolve(__dirname,'..', 'package.json');
20+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
21+
const dependencies = packageJson.dependencies || {};
22+
const devDependencies = packageJson.devDependencies || {};
23+
const allDependencies = { ...dependencies, ...devDependencies };
24+
const shared = isPlugin => Object.keys(allDependencies).map(dep => ({
25+
[dep]: {
26+
eager: !isPlugin, // core should load all dependencies eagerly so they will be available for plugins
27+
singleton: true,
28+
requiredVersion: allDependencies[dep],
29+
}}));
30+
1831
class AddRuntimeRequirement {
1932
// to avoid "webpackRequire.l is not a function" error
2033
// enables use of webpack require inside promise new promise
@@ -79,11 +92,18 @@ const commonConfig = function() {
7992
os: require.resolve('os-browserify'),
8093
},
8194
alias: {
95+
'patternfly-react$': path.resolve(__dirname,'..', 'node_modules/patternfly-react/dist/js/index.js'), // to avoid circular dependency in dist/esm
96+
'/node_modules/jquery': path.resolve(__dirname, '..', 'webpack/assets/javascripts/jquery.js'),
97+
'jquery': path.resolve(__dirname, '..', 'webpack/assets/javascripts/jquery.js'),
8298
foremanReact: path.join(
8399
__dirname,
84100
'../webpack/assets/javascripts/react_app'
85101
),
102+
'react/jsx-runtime': 'react/jsx-runtime.js', // for react-dnd
103+
'react/jsx-dev-runtime': 'react/jsx-dev-runtime.js', // for react-dnd
104+
86105
},
106+
87107
},
88108
resolveLoader: {
89109
modules: [path.resolve(__dirname, '..', 'node_modules')],
@@ -117,9 +137,6 @@ const commonConfig = function() {
117137
],
118138
},
119139
plugins: [
120-
new ForemanVendorPlugin({
121-
mode,
122-
}),
123140
new webpack.DefinePlugin({
124141
'process.env': {
125142
NODE_ENV: JSON.stringify(mode),
@@ -160,13 +177,18 @@ const coreConfig = function() {
160177
}
161178

162179
config.entry = {
180+
/* 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 */
163181
bundle: { import: bundleEntry, dependOn: ['vendor', 'reactExports'] },
164-
vendor: vendorEntry,
165-
reactExports: path.join(
182+
reactExports: {
183+
import: path.join(
166184
__dirname,
167185
'..',
168186
'webpack/assets/javascripts/all_react_app_exports.js'
169-
),
187+
),
188+
dependOn: 'vendor',
189+
},
190+
vendor: vendorEntry,
191+
vendorStyles: path.join(__dirname, '..', 'webpack/assets/javascripts/react_app/common/scss/vendor-core.scss'),
170192
};
171193
config.output = {
172194
path: path.join(__dirname, '..', 'public', 'webpack'),
@@ -179,9 +201,12 @@ const coreConfig = function() {
179201
};
180202
var plugins = config.plugins;
181203

204+
plugins.push(
205+
new MiniCssExtractPlugin());
182206
plugins.push(
183207
new ModuleFederationPlugin({
184208
name: 'foremanReact',
209+
shared: shared(false),
185210
})
186211
);
187212
plugins.push(
@@ -191,8 +216,10 @@ const coreConfig = function() {
191216
);
192217
config.plugins = plugins;
193218
var rules = config.module.rules;
219+
194220
rules.push({
195221
test: /\.(sa|sc|c)ss$/,
222+
exclude: /vendor-core/i,
196223
use: [
197224
{
198225
loader: 'style-loader',
@@ -205,6 +232,14 @@ const coreConfig = function() {
205232
'sass-loader',
206233
],
207234
});
235+
rules.push({
236+
test: /vendor-core/i,
237+
use: [
238+
MiniCssExtractPlugin.loader,
239+
'css-loader',
240+
'sass-loader',
241+
],
242+
});
208243
config.module.rules = rules;
209244
return config;
210245
};
@@ -276,8 +311,10 @@ const pluginConfig = function(plugin) {
276311
name: pluginName,
277312
filename: pluginName + '_remoteEntry.js',
278313
exposes: pluginEntries,
314+
shared: shared(true),
279315
})
280316
);
317+
281318
config.plugins = plugins;
282319
var rules = config.module.rules;
283320
rules.push({

config/webpack.vendor.js

+122-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,122 @@
1-
module.exports = ['react-intl', 'intl'];
1+
/* eslint-disable */
2+
3+
module.exports = [
4+
'intl',
5+
/**
6+
* React related
7+
*/
8+
'@apollo/client',
9+
'@apollo/client/link/batch-http',
10+
'@reduxjs/toolkit',
11+
'core-js/shim',
12+
'regenerator-runtime/runtime',
13+
'formik',
14+
'rc-input-number',
15+
'react',
16+
'react-ace',
17+
'react-dom',
18+
'react-dnd',
19+
'react-dnd-html5-backend',
20+
'react-debounce-input',
21+
'react-diff-view',
22+
'react-ellipsis-with-tooltip',
23+
'react-onclickoutside',
24+
'react-password-strength',
25+
'react-router-dom',
26+
'react-router-bootstrap',
27+
'react-loading-skeleton',
28+
'react-redux',
29+
'redux',
30+
'redux-logger',
31+
'redux-thunk',
32+
'reselect',
33+
'prop-types',
34+
'classnames',
35+
'seamless-immutable',
36+
'connected-react-router',
37+
'react-helmet',
38+
'react-intl',
39+
40+
/**
41+
* Patternfly related
42+
*/
43+
'patternfly-react',
44+
'patternfly-react-extensions',
45+
'@patternfly/react-core',
46+
'@patternfly/react-icons',
47+
'@patternfly/react-table',
48+
'@patternfly/react-tokens',
49+
'@patternfly/react-styles',
50+
'@patternfly/react-charts',
51+
// '@redhat-cloud-services/frontend-components',
52+
53+
/**
54+
* ace-builds related
55+
*/
56+
'ace-builds',
57+
'ace-builds/src-noconflict/ace',
58+
'ace-builds/src-noconflict/ext-language_tools',
59+
'ace-builds/src-noconflict/mode-ruby',
60+
'ace-builds/src-noconflict/mode-json',
61+
'ace-builds/src-noconflict/mode-sh',
62+
'ace-builds/src-noconflict/mode-html_ruby',
63+
'ace-builds/src-noconflict/mode-xml',
64+
'ace-builds/src-noconflict/mode-yaml',
65+
'ace-builds/src-noconflict/theme-github',
66+
'ace-builds/src-noconflict/theme-monokai',
67+
'ace-builds/src-noconflict/keybinding-vim',
68+
'ace-builds/src-noconflict/keybinding-emacs',
69+
'ace-builds/src-min-noconflict/ext-searchbox',
70+
71+
/**
72+
* UUID
73+
*/
74+
'uuid',
75+
'uuid/v1',
76+
'uuid/v3',
77+
'uuid/v4',
78+
'uuid/v5',
79+
80+
'jstz',
81+
'diff',
82+
/**
83+
* Custom modules
84+
*/
85+
// {
86+
// name: 'jquery',
87+
// path: '@theforeman/vendor-core/lib/customModules/jquery.js',
88+
// },
89+
// {
90+
// name: 'jstz',
91+
// window: 'jstz',
92+
// },
93+
// {
94+
// name: 'ipaddr.js',
95+
// window: 'ipaddr',
96+
// },
97+
// {
98+
// name: 'diff',
99+
// window: 'diff',
100+
// },
101+
102+
/**
103+
* Other packages
104+
*/
105+
'history',
106+
'number_helpers',
107+
'lodash',
108+
'axios',
109+
'file-saver',
110+
'humanize-duration',
111+
'unidiff',
112+
'urijs',
113+
'yup',
114+
'select2',
115+
'multiselect',
116+
'@novnc/novnc/core/rfb',
117+
'@novnc/novnc',
118+
119+
// '@spice-project/spice-html5',
120+
// '@webcomponents/webcomponentsjs/webcomponents-bundle',
121+
// '@webcomponents/webcomponentsjs/custom-elements-es5-adapter',
122+
];

0 commit comments

Comments
 (0)