Skip to content

Improve handling of aliased Console provided shared modules#16376

Open
vojtechszocs wants to merge 1 commit intoopenshift:mainfrom
vojtechszocs:improve-aliased-shared-module-handling
Open

Improve handling of aliased Console provided shared modules#16376
vojtechszocs wants to merge 1 commit intoopenshift:mainfrom
vojtechszocs:improve-aliased-shared-module-handling

Conversation

@vojtechszocs
Copy link
Copy Markdown
Contributor

@vojtechszocs vojtechszocs commented Apr 29, 2026

Analysis / Root cause

Some of Console provided shared modules are aliased for backwards compatibility with older Console plugins.

  • react-router-dom ▶️ react-router
  • react-router-dom-v5-compat ▶️ react-router

We should improve existing code which handles aliased shared modules.

Solution description

  • use appropriate module metadata instead of hard-coded assumptions
  • emit warning when building a plugin that uses aliased module(s)
  • add test for monkeyPatchSharedScope to ensure all aliases are set up as expected
  • ensure getSharedScope has the right type - webpack provided __webpack_share_scopes__ type is incorrect

Screenshots / screen recording

N/A - no visual impact

Test cases

  • in browser - compare window.webpackSharedScope before vs after PR - should be the same object
  • demo plugin - add react-router-dom and/or react-router-dom-v5-compat to dependencies - should emit warning(s)
    [WARNING] Console provided shared module ${moduleName} is aliased, beware of potential skew between aliased vs actual module code
    

Reviewers and assignees

/assign @logonoff

Summary by CodeRabbit

  • New Features

    • Added shared module aliasing support with detection and warnings for aliased dependencies.
  • Bug Fixes

    • Enhanced dependency validation to detect all missing dependencies without suppression.
    • Improved shared module peer dependency calculation with refined metadata handling.
    • Updated warning message format from deprecation-specific to generic notification style.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 29, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vojtechszocs

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the component/sdk Related to console-plugin-sdk label Apr 29, 2026
@openshift-ci openshift-ci Bot added plugin-api-changed Categorizes a PR as containing plugin API changes approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 29, 2026
@vojtechszocs vojtechszocs force-pushed the improve-aliased-shared-module-handling branch from c91a3f9 to 3aaa97e Compare April 29, 2026 19:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

This changeset refines shared module handling in the console dynamic plugin SDK. It introduces stricter dependency validation in the package definition parser, adds type safety for webpack share scopes, and implements a runtime aliasing mechanism for react-router-dom variants. The changes expand shared module metadata to track aliased flag, enabling more precise peerDependencies generation and warning classification. A new test validates the aliasing behavior. The deprecation warning prefix is generalized to [WARNING]. These modifications improve dependency resolution accuracy and provide better runtime compatibility for router aliasing scenarios.

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is comprehensive and well-structured, addressing analysis/root cause, solution, test cases, and reviewer assignment. However, the PR title lacks the required Jira issue prefix. Add Jira issue prefix to PR title (e.g., 'CONSOLE-XXXX: Improve handling of aliased Console provided shared modules') as specified in the description template.
✅ Passed checks (11 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the primary change: improving the handling of aliased shared modules, which is core to all file changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed This PR modifies TypeScript/JavaScript frontend code with Jest tests, not Go code with Ginkgo tests, making this check inapplicable.
Test Structure And Quality ✅ Passed Custom check designed for Ginkgo test code is not applicable to Jest frontend unit tests in TypeScript/JavaScript.
Microshift Test Compatibility ✅ Passed PR contains no Ginkgo e2e tests; only Jest unit test added. Custom check for MicroShift test compatibility is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed SNO compatibility check applies exclusively to Ginkgo e2e tests. This PR contains only TypeScript/JavaScript frontend code and Jest unit tests with no Go files or Ginkgo e2e tests present.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only frontend SDK TypeScript/JavaScript code with no Kubernetes manifests, deployment configs, or scheduling constraints.
Ote Binary Stdout Contract ✅ Passed OTE Binary Stdout Contract check is inapplicable to TypeScript/JavaScript frontend modifications; PR affects only Console SDK files, no Go binaries or test infrastructure.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR modifies only JavaScript/TypeScript SDK files and Jest unit tests; no Ginkgo e2e tests present, so IPv4/connectivity check is not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Linked repositories: Couldn't analyze openshift/console-operator - clone failed: Clone operation failed: Cloning into '/home/jailuser/git'...
warning: templates not found in /usr/share/git-core/templates
fatal: unable to access 'https://github.com/openshift/console-operator.git/': Failed to connect to github.com port 443 after 134962 ms: Couldn't connect to server


Review rate limit: 8/10 reviews remaining, refill in 10 minutes and 1 second.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@frontend/packages/console-dynamic-plugin-sdk/src/runtime/__tests__/plugin-shared-modules.spec.ts`:
- Around line 16-27: The test currently uses structural equality checks for
aliases; change the two alias assertions that compare
testScope['react-router-dom'] and testScope['react-router-dom-v5-compat'] to
testScope['react-router'] from using toEqual to using toBe so the test asserts
identity (same object) rather than deep equality; update the assertions in
plugin-shared-modules.spec.ts where testScope is compared so both alias checks
use toBe.

In
`@frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts`:
- Around line 142-149: The warning selection logic in the ConsoleRemotePlugin
uses a ternary that checks deprecated first, which causes aliased warnings
(aliased from getSharedModuleMetadata for moduleName) to be shadowed; update the
logic in the block that calls getSharedModuleMetadata and hasPackageDependency
so aliased is checked before deprecated (or push both messages explicitly) —
e.g., change the conditional used in warnings.push that currently references
deprecated ? ... : ... to first check aliased and emit the alias-skew message
for aliased modules, otherwise emit the deprecated message, ensuring the code
paths in getSharedModuleMetadata, aliased, deprecated, hasPackageDependency, and
warnings.push correctly surface alias warnings for react-router-dom*.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: a8462503-dcf0-4d34-a5cd-144d309402ff

📥 Commits

Reviewing files that changed from the base of the PR and between 335d6bd and 3aaa97e.

📒 Files selected for processing (6)
  • frontend/packages/console-dynamic-plugin-sdk/scripts/package-definitions.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/runtime/__tests__/plugin-shared-modules.spec.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/runtime/plugin-init.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/runtime/plugin-shared-modules.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/shared-modules/shared-modules-meta.ts
  • frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts
📜 Review details
🔇 Additional comments (5)
frontend/packages/console-dynamic-plugin-sdk/src/runtime/plugin-init.ts (1)

83-86: Warning prefix update looks fine.

Using the generic [WARNING] prefix keeps the legacy callback aligned with the broader shared-module warning wording.

frontend/packages/console-dynamic-plugin-sdk/src/runtime/__tests__/plugin-shared-modules.spec.ts (1)

1-8: Verify the type-only import compiles here.

ReturnType<typeof getSharedScope> usually needs a value import, so please confirm this passes under the repo's TypeScript settings or switch to a value import / exported scope type.

frontend/packages/console-dynamic-plugin-sdk/scripts/package-definitions.ts (1)

79-80: Dependency filtering now matches the new metadata model.

Surfacing missing deps while excluding aliased shared modules from peerDependencies looks consistent with the runtime aliasing change.

Also applies to: 92-107

frontend/packages/console-dynamic-plugin-sdk/src/shared-modules/shared-modules-meta.ts (1)

20-28: Metadata additions look consistent.

Adding aliased here gives the downstream warning and peerDependency filters a single source of truth.

Also applies to: 70-88

frontend/packages/console-dynamic-plugin-sdk/src/runtime/plugin-shared-modules.ts (1)

15-64: The helper refactor looks good.

The explicit share-scope typing and optional scope parameter keep the runtime behavior intact while making the alias patching easier to test.

Comment on lines +16 to +27
expect(Object.keys(testScope)).toEqual([
'react-router',
'react-router-dom',
'react-router-dom-v5-compat',
]);

expect(testScope['react-router']).toEqual({
'7.13.1': { from: 'openshift-console', eager: true, loaded: 1, get: getModule },
});

expect(testScope['react-router-dom']).toEqual(testScope['react-router']);
expect(testScope['react-router-dom-v5-compat']).toEqual(testScope['react-router']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Assert alias identity, not just structural equality.

toEqual would still pass if the aliases were copied instead of pointing at the same module map. Use toBe for the alias checks so this test actually covers the wiring.

🛠️ Suggested test tweak
-    expect(testScope['react-router-dom']).toEqual(testScope['react-router']);
-    expect(testScope['react-router-dom-v5-compat']).toEqual(testScope['react-router']);
+    expect(testScope['react-router-dom']).toBe(testScope['react-router']);
+    expect(testScope['react-router-dom-v5-compat']).toBe(testScope['react-router']);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/packages/console-dynamic-plugin-sdk/src/runtime/__tests__/plugin-shared-modules.spec.ts`
around lines 16 - 27, The test currently uses structural equality checks for
aliases; change the two alias assertions that compare
testScope['react-router-dom'] and testScope['react-router-dom-v5-compat'] to
testScope['react-router'] from using toEqual to using toBe so the test asserts
identity (same object) rather than deep equality; update the assertions in
plugin-shared-modules.spec.ts where testScope is compared so both alias checks
use toBe.

Comment on lines +142 to 149
const { deprecated, aliased } = getSharedModuleMetadata(moduleName);

if (deprecated && hasPackageDependency(pkg, moduleName)) {
if ((deprecated || aliased) && hasPackageDependency(pkg, moduleName)) {
warnings.push(
`[DEPRECATION WARNING] Console provided shared module ${moduleName} has been deprecated: ${deprecated}`,
deprecated
? `[WARNING] Console provided shared module ${moduleName} has been deprecated: ${deprecated}`
: `[WARNING] Console provided shared module ${moduleName} is aliased, beware of potential skew between aliased vs actual module code`,
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Alias warnings are currently shadowed.

These modules still have a truthy deprecated message in metadata, so this ternary will keep emitting the old deprecation text and never the new alias-skew warning for react-router-dom*.

If the build should surface the alias message, branch on aliased first or emit both warnings explicitly.

🔧 Possible fix
-    if ((deprecated || aliased) && hasPackageDependency(pkg, moduleName)) {
-      warnings.push(
-        deprecated
-          ? `[WARNING] Console provided shared module ${moduleName} has been deprecated: ${deprecated}`
-          : `[WARNING] Console provided shared module ${moduleName} is aliased, beware of potential skew between aliased vs actual module code`,
-      );
+    if (aliased && hasPackageDependency(pkg, moduleName)) {
+      warnings.push(
+        `[WARNING] Console provided shared module ${moduleName} is aliased, beware of potential skew between aliased vs actual module code`,
+      );
+    } else if (deprecated && hasPackageDependency(pkg, moduleName)) {
+      warnings.push(
+        `[WARNING] Console provided shared module ${moduleName} has been deprecated: ${deprecated}`,
+      );
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts`
around lines 142 - 149, The warning selection logic in the ConsoleRemotePlugin
uses a ternary that checks deprecated first, which causes aliased warnings
(aliased from getSharedModuleMetadata for moduleName) to be shadowed; update the
logic in the block that calls getSharedModuleMetadata and hasPackageDependency
so aliased is checked before deprecated (or push both messages explicitly) —
e.g., change the conditional used in warnings.push that currently references
deprecated ? ... : ... to first check aliased and emit the alias-skew message
for aliased modules, otherwise emit the deprecated message, ensuring the code
paths in getSharedModuleMetadata, aliased, deprecated, hasPackageDependency, and
warnings.push correctly surface alias warnings for react-router-dom*.

Comment on lines +146 to 149
deprecated
? `[WARNING] Console provided shared module ${moduleName} has been deprecated: ${deprecated}`
: `[WARNING] Console provided shared module ${moduleName} is aliased, beware of potential skew between aliased vs actual module code`,
);
Copy link
Copy Markdown
Member

@logonoff logonoff Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the aliased shared module warning is never shown (as both react-router-dom and react-router-dom-v5-compat are both deprecated).. can we make the assumption that all aliased shared modules are also deprecated and remove this check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A shared module that is aliased doesn't necessarily have to be deprecated - I think these are orthogonal concepts.

You are correct that react-router-dom and react-router-dom-v5-compat modules are currently both aliased and deprecated.

This code is meant to print just one warning per each aliased and/or deprecated module, with deprecation having higher priority.

I'll think about this some more but the general idea was to keep track of which modules are aliased (in addition to tracking their deprecated status).

*/
export const monkeyPatchSharedScope = () => {
const scope = getSharedScope();
export const monkeyPatchSharedScope = (scope = getSharedScope()) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does scope need to be typed now?

Suggested change
export const monkeyPatchSharedScope = (scope = getSharedScope()) => {
export const monkeyPatchSharedScope = (scope: WebpackShareScopes = getSharedScope()) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript will infer the type of scope based on default parameter initializer getSharedScope().

The inferred type of getSharedScope() expression is WebpackShareScopes[string] instead of the suggested WebpackShareScopes (the latter represents the object containing one or more share scope objects - in Console we use just one default share scope object).

{
  [moduleName: string]: {
    [moduleVersion: string]: { /* module data for name@version */ };
  };
}

We could explicitly type scope as WebpackShareScopes[string] but I don't think it's necessary due to above mentioned type inference.

Comment on lines +100 to +103
// Exclude modules for which a plugin provided fallback version is disallowed.
// Also exclude modules whose implementation is aliased to another module.
!allowFallback &&
!aliased
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
// Exclude modules for which a plugin provided fallback version is disallowed.
// Also exclude modules whose implementation is aliased to another module.
!allowFallback &&
!aliased
// Exclude modules for which a plugin provided fallback version is disallowed.
!allowFallback &&
// Also exclude modules whose implementation is aliased to another module.
!aliased

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@logonoff
Copy link
Copy Markdown
Member

/label px-approved
/label docs-approved

@openshift-ci openshift-ci Bot added px-approved Signifies that Product Support has signed off on this PR docs-approved Signifies that Docs has signed off on this PR labels Apr 29, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 29, 2026

@vojtechszocs: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-gcp-console 3aaa97e link true /test e2e-gcp-console

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/sdk Related to console-plugin-sdk docs-approved Signifies that Docs has signed off on this PR plugin-api-changed Categorizes a PR as containing plugin API changes px-approved Signifies that Product Support has signed off on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants