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

feat: recursive search for shared version #2681

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

robdonn
Copy link
Contributor

@robdonn robdonn commented Jun 28, 2024

Description

Allows @module-federation/enhanced to recursively search for the version of a shared module when it is not defined in it's closest package.json. A common pattern for monorepos is to have dependencies installed in the root package.json.

/monorepo
├── package.json        <---------- "lib1" dependency defined here
├── apps
│   ├── app1
│   │   ├── package.json
│   │   ├── node_modules
│   │   ├── webpack.config.js     <-------- "lib1" added to "shared" configuration here
│   │   └── src
│   │       ├── index.js
│   │       └── ...
│   └── app2
│       ├── package.json
│       ├── node_modules
│   │   ├── webpack.config.js
│       └── src
│           ├── index.js
│           └── ...
└── node_modules

Related Issue

#2680

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

changeset-bot bot commented Jun 28, 2024

🦋 Changeset detected

Latest commit: e36fd74

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 37 packages
Name Type
@module-federation/enhanced Minor
@module-federation/modern-js Minor
@module-federation/nextjs-mf Patch
@module-federation/node Patch
3008-runtime-remote Patch
host Patch
host-v5 Patch
host-vue3 Patch
remote1 Patch
remote2 Patch
remote3 Patch
remote4 Patch
@module-federation/modernjs Patch
modernjs-ssr-dynamic-nested-remote Patch
modernjs-ssr-dynamic-remote-new-version Patch
modernjs-ssr-dynamic-remote Patch
modernjs-ssr-host Patch
modernjs-ssr-nested-remote Patch
modernjs-ssr-remote-new-version Patch
modernjs-ssr-remote Patch
@module-federation/runtime Minor
@module-federation/rspack Minor
@module-federation/webpack-bundler-runtime Minor
@module-federation/sdk Minor
@module-federation/runtime-tools Minor
@module-federation/managers Minor
@module-federation/manifest Minor
@module-federation/dts-plugin Minor
@module-federation/third-party-dts-extractor Minor
@module-federation/devtools Minor
@module-federation/bridge-react Minor
@module-federation/bridge-vue3 Minor
@module-federation/bridge-shared Minor
@module-federation/bridge-react-webpack-plugin Minor
@module-federation/retry-plugin Minor
@module-federation/esbuild Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jun 28, 2024

Deploy Preview for module-federation-docs failed. Why did it fail? →

Name Link
🔨 Latest commit e36fd74
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/66e9c6acc8871e000886cd74

@robdonn robdonn force-pushed the feat/recursive-shared-version-search branch 2 times, most recently from 5b9a3ac to 6d7a50b Compare June 28, 2024 11:30
@ScriptedAlchemy
Copy link
Member

I will have to see about backporting this to rspack first before i can consider merge, will follow up

@robdonn
Copy link
Contributor Author

robdonn commented Jun 29, 2024

I will have to see about backporting this to rspack first before i can consider merge, will follow up

No problem, let me know if you need any more info/context

@ScriptedAlchemy
Copy link
Member

no, it makes sense. Just need to look at the rust end and sync the implementation

@robdonn robdonn force-pushed the feat/recursive-shared-version-search branch from cb92225 to 79b38b5 Compare July 21, 2024 17:31
@robdonn robdonn force-pushed the feat/recursive-shared-version-search branch from 79b38b5 to a4c6d41 Compare September 3, 2024 15:49
Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Summary

This pull request introduces a significant enhancement to the @module-federation/enhanced package by enabling recursive searching for the version of shared modules. This functionality is particularly beneficial for monorepo setups where dependencies are often defined in the root package.json, rather than in individual application directories.

Key changes include:

  • Implemented logic to traverse parent directories to locate the version of a shared module when it is not specified in the closest package.json.
  • Improved compatibility with monorepo structures, allowing for seamless integration of shared dependencies across multiple applications.
  • Added error handling to provide warnings when the required version cannot be determined, enhancing the robustness of the module.
  • Comprehensive tests have been added to ensure the reliability of the new feature, with all existing tests passing successfully.

Overall, these changes enhance the functionality of the module federation setup, making it more adaptable to complex project structures while maintaining a user-friendly experience.

File Summaries
File Summary
packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts Enhancements have been made to enable recursive searching for the version of a shared module when it is not specified in the nearest package.json. The changes primarily involve modifying the logic to traverse parent directories until the required version is found, improving compatibility with monorepo structures where dependencies may be defined at the root level. This update also includes error handling to ensure that appropriate warnings are issued when the version cannot be determined.

Issues Reviewed:

Issue Result Reason
2680 The pull request addresses the issue of resolving shared dependency versions in a monorepo setup, as described in the associated issue.

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 0

Configuration

Squadron Mode: essential

Commits Reviewed

13861194dc80ea7ea416d3bd9fe45dc348ef9d97...a4c6d417937f7d93dcce1eaaa832b0cf47f47a5f

Files Reviewed
  • packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/lucky-fans-exist.md
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib4/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib4/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib5/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/store/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/store/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/relative1.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/relative2.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib1/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib1/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib2/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib3/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib3/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/webpack.config.js

@robdonn robdonn force-pushed the feat/recursive-shared-version-search branch from a4c6d41 to e36fd74 Compare September 17, 2024 18:12
Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 6

Configuration

Squadron Mode: essential

Commits Reviewed

13975e1793d1e1eda4b3aed0ed919fddcff02aaf...e36fd749db46438c4097ab3b54130a6514109157

Files Reviewed
  • packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/lucky-fans-exist.md
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib4/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib4/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/lib5/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/store/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/node_modules/store/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/relative1.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/app1/relative2.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib1/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib1/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib2/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib3/index.js
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/node_modules/lib3/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/package.json
  • packages/enhanced/test/configCases/sharing/share-plugin-monorepo/webpack.config.js

@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants