From 3d299f7656fc0e0393be09db1977c95e2247d1c2 Mon Sep 17 00:00:00 2001 From: MariaAga Date: Fri, 13 Sep 2024 17:47:54 +0100 Subject: [PATCH] Fixes #37819 - Remove @theforeman/builder usage --- .babelrc.js | 5 ++++- .eslintrc | 1 + config/webpack.config.js | 17 ++++++++--------- package.json | 13 +++++++++++-- webpack/babel/index.js | 4 ++++ webpack/babel/plugins.js | 8 ++++++++ webpack/babel/presets.js | 6 ++++++ 7 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 webpack/babel/index.js create mode 100644 webpack/babel/plugins.js create mode 100644 webpack/babel/presets.js diff --git a/.babelrc.js b/.babelrc.js index 45cb3784f7a..83a296cd187 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -1,3 +1,6 @@ +const path = require('path'); +const babelPresets = path.resolve(__dirname, 'webpack', 'presets.js'); + module.exports = { - presets: ['@theforeman/builder/babel'], + presets: [babelPresets], }; diff --git a/.eslintrc b/.eslintrc index 0de7f9bd00b..c9f63639c21 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..cde4305a945 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: [require.resolve('../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..9439085665b 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,16 @@ "react-intl": "^2.8.0" }, "devDependencies": { - "@babel/core": "^7.7.0", - "@theforeman/builder": "^13.1.0", + "@babel/core": "~7.25.2", + "@babel/plugin-proposal-class-properties": "7.16.7", + "@babel/plugin-proposal-object-rest-spread": "7.16.7", + "@babel/plugin-syntax-dynamic-import": "^7.2.0", + "@babel/plugin-transform-modules-amd": "7.9.0", + "@babel/plugin-transform-modules-commonjs": "7.9.0", + "@babel/plugin-transform-modules-systemjs": "7.9.0", + "@babel/plugin-transform-object-assign": "^7.2.0", + "@babel/preset-env": "7.9.5", + "@babel/preset-react": "7.16.7", "@theforeman/eslint-plugin-foreman": "^13.1.0", "@theforeman/eslint-plugin-rules": "^13.1.0", "@theforeman/test": "^13.1.0", @@ -39,6 +47,7 @@ "argv-parse": "^1.0.1", "babel-eslint": "^10.0.0", "babel-loader": "^8.0.0", + "babel-plugin-dynamic-import-node": "2.3.0", "buffer": "^5.7.1", "compression-webpack-plugin": "^10.0.0", "cross-env": "^5.2.0", diff --git a/webpack/babel/index.js b/webpack/babel/index.js new file mode 100644 index 00000000000..75b89e8cf2b --- /dev/null +++ b/webpack/babel/index.js @@ -0,0 +1,4 @@ +const presets = require('./presets'); +const plugins = require('./plugins'); + +module.exports = () => ({ presets, plugins }); diff --git a/webpack/babel/plugins.js b/webpack/babel/plugins.js new file mode 100644 index 00000000000..810ffb498eb --- /dev/null +++ b/webpack/babel/plugins.js @@ -0,0 +1,8 @@ +module.exports = [ + require.resolve('@babel/plugin-proposal-class-properties'), + require.resolve('@babel/plugin-proposal-object-rest-spread'), + require.resolve('@babel/plugin-proposal-optional-chaining'), + require.resolve('@babel/plugin-transform-object-assign'), + require.resolve('@babel/plugin-syntax-dynamic-import'), + require.resolve('@babel/plugin-syntax-optional-chaining'), +]; 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;