From fa8205c889ea78525e78eaf8343658c691eebf0e Mon Sep 17 00:00:00 2001 From: MariaAga Date: Tue, 29 Oct 2024 16:47:47 +0000 Subject: [PATCH] Fixes #37819 - Remove @theforeman/builder usage --- .babelrc.js | 5 ++++- .eslintrc | 1 + config/webpack.config.js | 17 ++++++++--------- package.json | 5 +++-- webpack/babel/index.js | 3 +++ webpack/babel/presets.js | 6 ++++++ 6 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 webpack/babel/index.js create mode 100644 webpack/babel/presets.js diff --git a/.babelrc.js b/.babelrc.js index 45cb3784f7a..d77cc01e669 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -1,3 +1,6 @@ +const path = require('path'); +const babelPresets = path.resolve(__dirname, 'webpack','babel', 'presets.js'); + module.exports = { - presets: ['@theforeman/builder/babel'], + presets: require(babelPresets), }; diff --git a/.eslintrc b/.eslintrc index 0f541f19ff3..2c25bc4fb9d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -33,6 +33,7 @@ "checkbox", "clearbutton", "clearfix", + "commonjs", "comms", "consts", "cpu", diff --git a/config/webpack.config.js b/config/webpack.config.js index 17c8186432e..20bcec3526d 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -14,6 +14,7 @@ const { ModuleFederationPlugin } = require('webpack').container; var pluginUtils = require('../script/plugin_webpack_directories'); var { generateExportsFile }= require('../webpack/assets/javascripts/exportAll'); var CompressionPlugin = require('compression-webpack-plugin'); +const root = path.resolve(__dirname, '..'); class AddRuntimeRequirement { // to avoid "webpackRequire.l is not a function" error @@ -32,7 +33,7 @@ class AddRuntimeRequirement { } const supportedLocales = () => { - const localeDir = path.join(__dirname, '..', 'locale'); + const localeDir = path.resolve(root, 'locale'); // Find all files in ./locale/* const localesFiles = fs.readdirSync(localeDir); @@ -86,7 +87,7 @@ const commonConfig = function() { }, }, resolveLoader: { - modules: [path.resolve(__dirname, '..', 'node_modules')], + modules: [path.resolve(root, 'node_modules')], }, module: { rules: [ @@ -97,7 +98,7 @@ const commonConfig = function() { exclude: /node_modules(?!\/(@novnc|unidiff))/, loader: 'babel-loader', options: { - presets: [require.resolve('@theforeman/builder/babel')], + presets: [path.resolve(root, 'webpack/babel')], }, }, { @@ -152,7 +153,7 @@ const coreConfig = function() { '..', 'webpack/assets/javascripts/bundle.js' ); - config.context = path.resolve(__dirname, '..'); + config.context = root; if (config.mode == 'production') { var chunkFilename = '[name]-[chunkhash].js' } else { @@ -162,14 +163,12 @@ const coreConfig = function() { config.entry = { bundle: { import: bundleEntry, dependOn: ['vendor', 'reactExports'] }, vendor: vendorEntry, - reactExports: path.join( - __dirname, - '..', + reactExports: path.resolve(root, 'webpack/assets/javascripts/all_react_app_exports.js' ), }; config.output = { - path: path.join(__dirname, '..', 'public', 'webpack'), + path: path.resolve(root, 'public', 'webpack'), publicPath: '/webpack/', library: { name: ['TheForeman', '[name]'], @@ -262,7 +261,7 @@ const pluginConfig = function(plugin) { }; var configModules = config.resolve.modules || []; // make webpack to resolve modules from core first - configModules.unshift(path.resolve(__dirname, '..', 'node_modules')); + configModules.unshift(path.resolve(root, 'node_modules')); // add plugin's node_modules to the reslver list configModules.push(path.resolve(pluginRoot, 'node_modules')); configModules.push('node_modules/'); diff --git a/package.json b/package.json index 7ae5676471f..68475052dbc 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,9 @@ "react-intl": "^2.8.0" }, "devDependencies": { - "@babel/core": "^7.7.0", - "@theforeman/builder": "^13.1.0", + "@babel/core": "~7.25.2", + "@babel/preset-env": "~7.25.2", + "@babel/preset-react": "~7.25.2", "@theforeman/eslint-plugin-foreman": "^13.1.0", "@theforeman/eslint-plugin-rules": "^13.1.0", "@theforeman/test": "^13.1.0", diff --git a/webpack/babel/index.js b/webpack/babel/index.js new file mode 100644 index 00000000000..e25f7dd8b58 --- /dev/null +++ b/webpack/babel/index.js @@ -0,0 +1,3 @@ +const presets = require('./presets'); + +module.exports = () => ({ presets }); diff --git a/webpack/babel/presets.js b/webpack/babel/presets.js new file mode 100644 index 00000000000..faeef37778d --- /dev/null +++ b/webpack/babel/presets.js @@ -0,0 +1,6 @@ +const presets = [ + [require.resolve('@babel/preset-env'), { modules: 'commonjs' }], + require.resolve('@babel/preset-react'), +]; + +module.exports = presets;