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

CONSOLE-3905: (deps) upgrade to webpack 5 #14378

Merged
merged 10 commits into from
Dec 6, 2024
42 changes: 42 additions & 0 deletions frontend/get-active-plugins.js
logonoff marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable tsdoc/syntax */
logonoff marked this conversation as resolved.
Show resolved Hide resolved
// @ts-check

/**
* Get the current Console active plugins virtual module information.
*
* This module is executed by webpack `val-loader` which uses the resulting `code` as actual module source.
*
*
* @param {object} options
* @param {() => import('./packages/console-plugin-sdk/src/codegen/active-plugins').ActivePluginsModuleData} options.getModuleData
* @param {import('webpack').LoaderContext<any>} loaderContext
*
* @returns {{code: string}} Generated module source code.
*/
const getActivePlugins = ({ getModuleData }, loaderContext) => {
const {
code,
diagnostics: { errors, warnings },
fileDependencies,
} = getModuleData();
// eslint-disable-next-line no-console
console.log(
`Console active plugins virtual module code generated with ${errors.length} errors and ${warnings.length} warnings`,
);

errors.forEach((msg) => {
loaderContext.emitError(new Error(msg));
});

warnings.forEach((msg) => {
loaderContext.emitWarning(new Error(msg));
});

fileDependencies.forEach((file) => {
loaderContext.addDependency(file);
});

return { code };
};

module.exports = getActivePlugins;
31 changes: 14 additions & 17 deletions frontend/package.json
logonoff marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"d3": "^5.16.0",
"file-saver": "1.3.x",
"focus-trap-react": "^6.0.0",
"formik": "2.0.3",
"formik": "^2.1.5",
"fuzzysearch": "1.0.x",
"gherkin-lint": "^4.1.3",
"git-url-parse": "^11.4.0",
Expand All @@ -185,14 +185,15 @@
"lodash-es": "^4.17.21",
"monaco-languageclient": "^0.13.0",
"murmurhash-js": "1.0.x",
"node-polyfill-webpack-plugin": "^4.0.0",
"openshift-logos-icon": "1.7.1",
"pluralize": "^8.0.0",
"point-in-svg-path": "1.0.1",
"popper.js": "^1.16.1",
"prop-types": "15.7.x",
"react": "^17.0.1",
"react-dnd": "^9.4.0",
"react-dnd-html5-backend": "^9.4.0",
"react-dnd": "^11.1.3",
"react-dnd-html5-backend": "^11.1.3",
"react-dom": "^17.0.1",
"react-draggable": "4.x",
"react-helmet": "^6.1.0",
Expand Down Expand Up @@ -265,19 +266,16 @@
"@types/react-virtualized": "9.x",
"@types/semver": "^6.0.0",
"@types/showdown": "1.9.4",
"@types/webpack": "4.x",
"@types/webpack-dev-server": "^4.7.2",
"@wojtekmaj/enzyme-adapter-react-17": "^0.4.1",
"acorn": "^7.0.0",
"acorn-jsx": "5.2.0",
"babel-loader": "^8.2.1",
"babel-plugin-transform-imports": "1.5.1",
"browser-env": "3.x",
"cache-loader": "^4.1.0",
"chalk": "2.4.x",
"circular-dependency-plugin": "5.x",
"comment-json": "4.x",
"copy-webpack-plugin": "^6.4.1",
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^5.2.7",
"cypress": "^13.10.0",
"cypress-axe": "^0.12.0",
Expand All @@ -286,12 +284,13 @@
"cypress-jest-adapter": "^0.1.1",
"cypress-multi-reporters": "^1.4.0",
"enzyme": "3.10.x",
"esbuild-loader": "^4.2.2",
logonoff marked this conversation as resolved.
Show resolved Hide resolved
"file-loader": "6.2.0",
"find-up": "4.x",
"fork-ts-checker-webpack-plugin": "6.5.3",
"fork-ts-checker-webpack-plugin": "9.0.2",
logonoff marked this conversation as resolved.
Show resolved Hide resolved
"glob": "7.x",
"graphql-tag": "^2.10.3",
"html-webpack-plugin": "4.5.2",
"html-webpack-plugin": "5.6.3",
"html-webpack-skip-assets-plugin": "^1.0.4",
"husky": "^8.0.3",
"i18next-parser": "^8.9.0",
Expand All @@ -303,7 +302,7 @@
"jest-resolve": "^26.4.0",
"jest-transform-graphql": "^2.1.0",
"lint-staged": "^10.2.2",
"mini-css-extract-plugin": "^1.6.2",
"mini-css-extract-plugin": "^2.9.1",
"minimist": "1.2.5",
"mocha-junit-reporter": "^1.23.3",
"mochawesome": "^6.1.1",
Expand All @@ -312,7 +311,6 @@
"mock-socket": "^9.0.3",
"monaco-editor": "^0.28.1",
"monaco-editor-webpack-plugin": "^4.2.0",
"null-loader": "^4.0.1",
"prettier": "2.0.5",
"react-refresh": "^0.10.0",
"read-pkg": "5.x",
Expand All @@ -321,17 +319,16 @@
"sass": "^1.42.1",
"sass-loader": "^10.1.1",
"style-loader": "^2.0.0",
"thread-loader": "^3.0.4",
"thread-loader": "^4.0.4",
"ts-jest": "21.x",
"ts-loader": "^8.4.0",
"ts-node": "10.9.2",
"typescript": "4.5.5",
"umd-compat-loader": "^2.1.2",
"webpack": "^4.47.0",
"val-loader": "^6.0.0",
logonoff marked this conversation as resolved.
Show resolved Hide resolved
"webpack": "^5.75.0",
logonoff marked this conversation as resolved.
Show resolved Hide resolved
"webpack-bundle-analyzer": "4.10.2",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.0",
"webpack-virtual-modules": "^0.6.2"
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
},
"engines": {
"node": ">=18.x"
Expand Down
3 changes: 1 addition & 2 deletions frontend/packages/console-dynamic-plugin-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"ejs": "3.x",
"fs-extra": "9.x",
"ts-json-schema-generator": "0.98.0",
"tsutils": "3.21.0",
"webpack": "^5.75.0"
"tsutils": "3.21.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,10 @@ export const getWebpackPackage: GetPackageDefinition = (
main: 'lib/lib-webpack.js',
...commonManifestFields,
dependencies: {
...parseDeps(
sdkPackage,
['@openshift/dynamic-plugin-sdk-webpack', 'webpack'],
missingDepCallback,
),
...parseDeps(sdkPackage, ['@openshift/dynamic-plugin-sdk-webpack'], missingDepCallback),
...parseDeps(
rootPackage,
['ajv', 'chalk', 'comment-json', 'find-up', 'glob', 'read-pkg', 'semver'],
['ajv', 'chalk', 'comment-json', 'find-up', 'glob', 'read-pkg', 'semver', 'webpack'],
missingDepCallback,
),
...parseDepsAs(rootPackage, { 'lodash-es': 'lodash' }, missingDepCallback),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as fs from 'fs';
import * as path from 'path';
import * as _ from 'lodash';
import {
isEncodedCodeRef,
parseEncodedCodeRefValue,
} from '@console/dynamic-plugin-sdk/src/coderefs/coderef-resolver';
import { extensionsFile } from '@console/dynamic-plugin-sdk/src/constants';
import { ConsoleExtensionsJSON } from '@console/dynamic-plugin-sdk/src/schema/console-extensions';
import { EncodedCodeRef } from '@console/dynamic-plugin-sdk/src/types';
import { parseJSONC } from '@console/dynamic-plugin-sdk/src/utils/jsonc';
Expand All @@ -13,8 +15,56 @@ import { Extension, ActivePlugin } from '../typings';
import { trimStartMultiLine } from '../utils/string';
import { consolePkgScope, PluginPackage } from './plugin-resolver';

const getExtensionsFilePath = (pkg: PluginPackage) => path.resolve(pkg._path, extensionsFile);

/**
* Guess the file path of the module (e.g., the extension,
* any barrel/index file) based on the given base path.
*
* Returns the base path if no file is found.
*/
const guessModuleFilePath = (basePath: string) => {
const extensions = ['.tsx', '.ts', '.jsx', '.js'];

// Sometimes the module is an index file, but the exposed module path only specifies the directory.
// In that case, we need an explicit check for the index file.
const indexModulePaths = ['index.ts', 'index.js'].map((i) => path.resolve(basePath, i));
logonoff marked this conversation as resolved.
Show resolved Hide resolved

const pathsToCheck = [...indexModulePaths, ...extensions.map((ext) => `${basePath}${ext}`)];

for (const p of pathsToCheck) {
if (fs.existsSync(p)) {
return p;
}
}

// A file couldn't be found, return the original module path. A compilation warning
// may be pushed by `getActivePluginsModuleData`
return basePath;
logonoff marked this conversation as resolved.
Show resolved Hide resolved
};

const getExposedModuleFilePath = (pkg: PluginPackage, moduleName: string) => {
const modulePath = path.resolve(pkg._path, pkg.consolePlugin.exposedModules[moduleName]);
logonoff marked this conversation as resolved.
Show resolved Hide resolved

// Check if there is a file extension (no extra guessing needed)
if (!path.extname(modulePath)) {
logonoff marked this conversation as resolved.
Show resolved Hide resolved
return guessModuleFilePath(modulePath);
}

return modulePath;
};

export type ActivePluginsModuleData = {
/** Generated module source code. */
code: string;
/** Diagnostics collected while generating module source code. */
diagnostics: { errors: string[]; warnings: string[] };
/** Absolute file paths representing webpack file dependencies of the generated module. */
fileDependencies: string[];
};

/**
* Generate the `@console/active-plugins` virtual module source.
* Generate the Console active plugins virtual module source.
*/
export const getActivePluginsModule = (
pluginPackages: PluginPackage[],
Expand Down Expand Up @@ -149,3 +199,45 @@ export const getDynamicExtensions = (

return trimStartMultiLine(source);
};

export const getActivePluginsModuleData = (
pluginPackages: PluginPackage[],
): ActivePluginsModuleData => {
const errors: string[] = [];
const warnings: string[] = [];
const fileDependencies: string[] = [];

const code = getActivePluginsModule(
pluginPackages,
() => `
import { applyCodeRefSymbol } from '@console/dynamic-plugin-sdk/src/coderefs/coderef-resolver';
`,
(pkg) =>
getDynamicExtensions(
pkg,
getExtensionsFilePath(pkg),
(errorMessage) => {
errors.push(errorMessage);
},
(codeRefSource) => `applyCodeRefSymbol(${codeRefSource})`,
),
);

for (const pkg of pluginPackages) {
fileDependencies.push(getExtensionsFilePath(pkg));

Object.keys(pkg.consolePlugin.exposedModules || {}).forEach((moduleName) => {
const moduleFilePath = getExposedModuleFilePath(pkg, moduleName);

if (fs.existsSync(moduleFilePath) && fs.statSync(moduleFilePath).isFile()) {
fileDependencies.push(moduleFilePath);
} else {
warnings.push(
`Exposed module '${moduleName}' in static plugin ${pkg.name} refers to non-existent file ${moduleFilePath}`,
);
}
});
}

return { code, diagnostics: { errors, warnings }, fileDependencies };
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const formikFormProps: FormikProps<FormikValues> = {
handleReset: jest.fn(),
handleSubmit: jest.fn(),
getFieldProps: jest.fn(),
getFieldHelpers: jest.fn(),
handleBlur: jest.fn(),
handleChange: jest.fn(),
initialErrors: {},
Expand Down
Loading