Skip to content

Commit

Permalink
Fixes #37252 - prevent duplicate foremanReact in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Mar 13, 2024
1 parent 8c140b0 commit 87133aa
Show file tree
Hide file tree
Showing 6 changed files with 1,110 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"ascii",
"auditable",
"Autocompletion",
"autogenerated",
"bool",
"bootable",
"Borderless",
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<%= get_webpack_foreman_vendor_js %>
<%= javascript_include_tag('/webpack/vendor.js') %>
<%= javascript_include_tag('/webpack/bundle.js') %>
<%= javascript_include_tag('/webpack/reactExports.js') %>

<%= javascript_include_tag 'application' %>
<%= webpacked_plugins_with_global_js %>
Expand Down
26 changes: 26 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var vendorEntry = require('./webpack.vendor');
var fs = require('fs');
const { ModuleFederationPlugin } = require('webpack').container;
var pluginUtils = require('../script/plugin_webpack_directories');
var { generateExportsFile }= require('../webpack/assets/javascripts/exportAll');

class AddRuntimeRequirement {
// to avoid "webpackRequire.l is not a function" error
Expand Down Expand Up @@ -153,10 +154,19 @@ const coreConfig = function() {
config.entry = {
bundle: { import: bundleEntry, dependOn: 'vendor' },
vendor: vendorEntry,
reactExports: path.join(
__dirname,
'..',
'webpack/assets/javascripts/all_react_app_exports.js'
),
};
config.output = {
path: path.join(__dirname, '..', 'public', 'webpack'),
publicPath: '/webpack/',
library: {
name: ['TheForeman', '[id]'],
type: 'var',
},
};
var plugins = config.plugins;

Expand Down Expand Up @@ -196,6 +206,21 @@ const pluginConfig = function(plugin) {
var config = commonConfig();
config.context = path.join(pluginRoot, 'webpack');
config.entry = {};

function convertImportStatement(importStatement) {
const importPath = importStatement;
const importPathParts = importPath.split('/');
const newImportName = importPathParts.slice(1).join('_');
return newImportName;
}
config.externals = function({ request }, callback) {
if (/^foremanReact(\/.*)?$/.test(request)) {
const prefix = 'var TheForeman.reactExports.';
const newPath = prefix + convertImportStatement(request.substring('foremanReact'.length));
return callback(null, newPath);
}
return callback();
};
var pluginEntries = {
'./index': path.resolve(pluginRoot, 'webpack', 'index'),
};
Expand Down Expand Up @@ -262,6 +287,7 @@ const pluginConfig = function(plugin) {
};

module.exports = function(env, argv) {
generateExportsFile();
const { pluginName } = env;
var pluginsDirs = pluginUtils.getPluginDirs('pipe');
var pluginsInfo = {};
Expand Down
Loading

0 comments on commit 87133aa

Please sign in to comment.