Skip to content

feat(enhanced): add request to consume share #3307

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

Merged
merged 7 commits into from
Dec 5, 2024

Conversation

ScriptedAlchemy
Copy link
Member

@ScriptedAlchemy ScriptedAlchemy commented Dec 3, 2024

Description

This pull request includes several changes to enhance the functionality of the ConsumeSharedModule and ConsumeSharedPlugin in the packages/enhanced library. The changes include adding new properties and methods to handle module layers and issuer layers, updating dependencies, and improving the resolution of shared modules.

Enhancements to ConsumeSharedModule and ConsumeSharedPlugin:

  • Added new properties request, layer, and issuerLayer to the ConsumeOptions type to support more granular control over module sharing. [1] [2] [3]
  • Updated the ConsumeSharedModule class to use the new layer property during initialization and in the identifier and readableIdentifier methods. [1] [2] [3]
  • Modified the ConsumeSharedPlugin class to include the new properties in the consume options and to use a helper function createLookupKey for creating composite keys with issuer layers. [1] [2] [3] [4] [5] [6] [7] [8]

Dependency updates:

  • Added webpack-cli as a new dependency in package.json.
  • Introduced a new script enhanced:jest for running Jest tests with experimental VM modules.

Improvements to shared module resolution:

  • Enhanced the resolveMatchedConfigs function to handle the new request, layer, and issuerLayer properties, and to use regular expressions for matching relative and absolute paths. [1] [2] [3] [4] [5]

Related Issue

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

netlify bot commented Dec 3, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 104785a
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/674e7ad09f7f5c00081e2f03
😎 Deploy Preview https://deploy-preview-3307--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ScriptedAlchemy ScriptedAlchemy changed the base branch from main to consume-share-layers December 3, 2024 03:29
} else if (config.layer) {
return `(${config.layer})${request}`;
} else {
return request;
Copy link
Member Author

Choose a reason for hiding this comment

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

used for when there is no layer etc,

// module request prefix
prefixed.set(request, config);
const key = createCompositeKey(resolveRequest, config);
Copy link
Member Author

Choose a reason for hiding this comment

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

with the request param, i can now support prefix shared etc without a problem

Copy link

changeset-bot bot commented Dec 3, 2024

🦋 Changeset detected

Latest commit: 92cebbb

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

This PR includes changesets to release 27 packages
Name Type
@module-federation/enhanced Major
@module-federation/modern-js Major
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Major
@module-federation/storybook-addon Patch
@module-federation/modernjsapp Patch
@module-federation/runtime Major
@module-federation/rspack Major
@module-federation/webpack-bundler-runtime Major
@module-federation/sdk Major
@module-federation/runtime-tools Major
@module-federation/managers Major
@module-federation/manifest Major
@module-federation/dts-plugin Major
@module-federation/third-party-dts-extractor Major
@module-federation/devtools Major
@module-federation/bridge-react Major
@module-federation/bridge-vue3 Major
@module-federation/bridge-shared Major
@module-federation/bridge-react-webpack-plugin Major
@module-federation/retry-plugin Major
@module-federation/data-prefetch Major
@module-federation/error-codes Major
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new 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

@ScriptedAlchemy ScriptedAlchemy changed the title Update consume share layer feat(enhanced): aadd request to consume share Dec 3, 2024
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

The pull request introduces several enhancements to the "ConsumeSharedPlugin" and related functionality in the "enhanced" package. The key changes are:

  • Added an optional "request" property to the "ConsumesConfig" interface and the "ConsumeOptions" type. This allows specifying the actual request to use for importing the shared module, rather than relying on the property name/key. This provides more flexibility in how the shared module is imported and consumed.
  • Introduced a new helper function "createLookupKey" to generate a composite key for looking up "unresolvedConsumes" based on the request and the issuer layer. This improvement helps in handling layer-specific requests in the "ConsumeSharedPlugin".
  • Simplified the logic for finding a matching "ConsumeOptions" and creating the "ConsumeSharedModule" accordingly.
  • Added a new function "resolveMatchedConfigs" that resolves shared module configurations based on their request type (relative, absolute, or module request) and updates the "resolveContext" object with the resolved and unresolved configurations, as well as the "contextDependencies" and "missingDependencies".
  • Updated the validation schema for the "ConsumeSharedPlugin" object to include the new "request" property.
  • Added new test cases for the "layers-consume-loader" feature, covering additional scenarios related to layer inheritance and shared dependencies.

These changes aim to enhance the flexibility and functionality of the "ConsumeSharedPlugin" and the overall shared module handling in the "enhanced" package.

File Summaries
File Summary
packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts The code changes introduce a new optional property request to the ConsumesConfig interface. This property allows specifying the actual request to use for importing the shared module, rather than relying on the property name/key. This provides more flexibility in how the shared module is imported and consumed.
packages/enhanced/src/lib/sharing/ConsumeSharedModule.ts The code changes introduce a new optional property request to the ConsumeOptions type. This property allows specifying the actual request to use for importing the module, instead of using the property name/key as the default. This enhancement provides more flexibility in configuring the import process for shared modules.
packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts The code changes introduce a new helper function createLookupKey to generate a composite key for looking up unresolvedConsumes based on the request and the issuer layer. The main purpose of this change is to improve the handling of layer-specific requests in the ConsumeSharedPlugin. Additionally, the code simplifies the logic for finding a matching ConsumeOptions and creates the ConsumeSharedModule accordingly.
packages/enhanced/src/lib/sharing/resolveMatchedConfigs.ts The code changes introduce a new function resolveMatchedConfigs that takes a compilation object and a list of shared module configurations, and resolves the configurations based on their request type (relative, absolute, or module request). The function creates a composite key for each configuration based on the request and optional layer information, and then uses the Webpack resolver to resolve the configurations. The resolved configurations are stored in a resolved map, while the unresolved configurations are stored in an unresolved map. The function also updates the contextDependencies and missingDependencies properties of the resolveContext object.
packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.check.ts The changes introduce a new property 'request' to the validation schema for the 'ConsumeSharedPlugin' object. This addition ensures that the schema correctly validates the presence of the 'request' property, which is likely a new feature or requirement for the 'ConsumeSharedPlugin' functionality.
packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.ts The code changes introduce a new property called "request" to the "ConsumeSharedPlugin" schema. This property allows for specifying the actual request to use for importing a module, which can be different from the property name or key. This addition provides more flexibility in how shared modules are consumed, enabling developers to customize the import process as needed.
packages/enhanced/test/configCases/sharing/layers-consume-loader/src/index.js The code changes introduce new test cases for the "layers-consume-loader" feature. The primary modifications include adding two new test files, "lib-two.test.js" and "prefixed-share.test.js", which likely cover additional scenarios related to layer inheritance and shared dependencies.

@ScriptedAlchemy ScriptedAlchemy changed the title feat(enhanced): aadd request to consume share feat(enhanced): add request to consume share Dec 3, 2024
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: 14

Configuration

Squadron Mode: essential

Commits Reviewed

9884030e46a90a3d8bf215ddb2fc8e2b639d2995...76b53caf9615c2682aa124028181cc1ecc621aaa

Files Reviewed
  • packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts
  • packages/enhanced/src/lib/sharing/resolveMatchedConfigs.ts
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/src/index.js
  • packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts
  • packages/enhanced/src/lib/sharing/ConsumeSharedModule.ts
  • packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.check.ts
  • packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.ts
Files Ignored

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

  • .changeset/brown-badgers-fetch.md
  • packages/enhanced/test/ConfigTestCases.template.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/loaders/multi-pkg-layer-loader.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/lib2/index.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/multi-pkg/thing1.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/multi-pkg/thing2.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/different-layers.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/lib-two.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/prefixed-share.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/unlayered-share.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/webpack.config.js

@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 3, 2024
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: 12

Configuration

Squadron Mode: essential

Commits Reviewed

04b8ffdd26412715669fa17f9413b0d5b7275d23...92cebbb662d45d79af268a8bdf1c4a981f270ee3

Files Reviewed
  • packages/enhanced/src/lib/sharing/ConsumeSharedPlugin.ts
  • packages/enhanced/src/lib/sharing/resolveMatchedConfigs.ts
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/src/index.js
  • packages/enhanced/src/declarations/plugins/sharing/ConsumeSharedPlugin.d.ts
  • packages/enhanced/src/lib/sharing/ConsumeSharedModule.ts
  • packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.check.ts
  • packages/enhanced/src/schemas/sharing/ConsumeSharedPlugin.ts
Files Ignored

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

  • .changeset/brown-badgers-fetch.md
  • packages/enhanced/test/ConfigTestCases.template.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/loaders/multi-pkg-layer-loader.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/lib2/index.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/multi-pkg/thing1.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/node_modules/multi-pkg/thing2.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/different-layers.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/lib-two.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/prefixed-share.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/tests/unlayered-share.test.js
  • packages/enhanced/test/configCases/sharing/layers-consume-loader/webpack.config.js

@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 4, 2024
@ScriptedAlchemy ScriptedAlchemy merged commit 7852878 into consume-share-layers Dec 5, 2024
10 checks passed
@ScriptedAlchemy ScriptedAlchemy deleted the update-consume-share-layer branch December 5, 2024 18:44
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.

1 participant