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

chore(rsbuild-plugin): split setUp function to help extend #3215

Merged
merged 6 commits into from
Dec 26, 2024

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Nov 12, 2024

Description

split setUp function to help extend

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

changeset-bot bot commented Nov 12, 2024

🦋 Changeset detected

Latest commit: cd5269c

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/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
@module-federation/modern-js Patch
@module-federation/runtime Patch
@module-federation/enhanced Patch
@module-federation/rspack Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/data-prefetch Patch
@module-federation/error-codes Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/modernjsapp Patch
@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

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit cd5269c
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/676d1adbc1a20c0008ecbadc
😎 Deploy Preview https://deploy-preview-3215--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.

@2heal1 2heal1 force-pushed the chore/split-rsbuild-plugin branch 2 times, most recently from de22c3e to c8f070d Compare November 14, 2024 09:47
@2heal1 2heal1 force-pushed the chore/split-rsbuild-plugin branch from c1a5841 to 983b487 Compare November 29, 2024 06:53
@2heal1 2heal1 force-pushed the chore/split-rsbuild-plugin branch 3 times, most recently from e31faef to 6623262 Compare December 18, 2024 09:33
@2heal1
Copy link
Member Author

2heal1 commented Dec 20, 2024

It will be merged in two weekes

@2heal1 2heal1 force-pushed the chore/split-rsbuild-plugin branch from 6623262 to 2f4fef8 Compare December 20, 2024 02:42
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 focuses on improving the extensibility and maintainability of the ModuleFederationPlugin by introducing a centralized reference to the plugin's name. The changes span across multiple files in the packages/enhanced and packages/rspack directories, and they involve the following key updates:

  • A new PLUGIN_NAME constant has been introduced and exported from various modules, including ModuleFederationPlugin. This allows for a consistent and easily accessible reference to the plugin's name, which can be useful for logging, configuration, or integration with other parts of the application.
  • The name property of the ModuleFederationPlugin class has been updated to use the PLUGIN_NAME constant, further centralizing the plugin's name and making it more easily reusable across the codebase.
  • The new PLUGIN_NAME exports enable better extensibility and customization of the plugin, as users can now access the plugin's name directly without having to rely on implicit references or internal implementation details.

These changes aim to improve the overall maintainability and scalability of the ModuleFederationPlugin by providing a more structured and extensible approach to managing the plugin's name and related functionality.

File Summaries
File Summary
packages/enhanced/src/index.ts The code changes introduce a new export, PLUGIN_NAME, from the ModuleFederationPlugin module. This change likely aims to provide a centralized and easily accessible reference to the plugin's name, which can be useful for various purposes, such as logging, configuration, or integration with other parts of the application.
packages/enhanced/src/rspack.ts The code changes introduce a new export for the PLUGIN_NAME constant from the @module-federation/rspack/plugin module. This change likely aims to provide additional functionality or information related to the ModuleFederationPlugin that is being exported.
packages/enhanced/src/webpack.ts The code changes introduce a new constant PLUGIN_NAME and export it alongside the ModuleFederationPlugin from the ./wrapper/ModuleFederationPlugin module. This modification likely aims to provide a more explicit and accessible reference to the plugin name, potentially improving the extensibility and maintainability of the codebase.
packages/enhanced/src/wrapper/ModuleFederationPlugin.ts The code changes introduce a new export for the PLUGIN_NAME constant, which was previously defined as a private variable. This change allows the plugin name to be accessed and used outside of the ModuleFederationPlugin class, potentially enabling better extensibility and customization of the plugin.
packages/rspack/src/ModuleFederationPlugin.ts The code changes introduce a new constant PLUGIN_NAME and update the name property of the ModuleFederationPlugin class to use this constant. This change likely aims to centralize the plugin name and make it more easily accessible or reusable across the codebase.
packages/rspack/src/index.ts The code changes introduce a new export, PLUGIN_NAME, from the ModuleFederationPlugin module. This change likely aims to provide a more comprehensive API for the plugin, allowing users to access the plugin's name directly.

@2heal1 2heal1 force-pushed the chore/split-rsbuild-plugin branch from cd3287b to d0074b0 Compare December 24, 2024 16:55
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: 8

Configuration

Squadron Mode: essential

Commits Reviewed

2f4fef827f713e9fe279c36153762ea60cb48525...f9f5c25b441783fe6890ed584542ddde1d2bdc37

Files Reviewed
  • packages/enhanced/src/index.ts
  • packages/enhanced/src/rspack.ts
  • packages/enhanced/src/webpack.ts
  • packages/enhanced/src/wrapper/ModuleFederationPlugin.ts
  • packages/rspack/src/ModuleFederationPlugin.ts
  • packages/rspack/src/index.ts
Files Ignored

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

  • .changeset/angry-spoons-wink.md
  • .changeset/spicy-roses-hear.md
  • apps/rslib-module/.storybook/main.ts
  • apps/rslib-module/package.json
  • apps/rslib-module/rslib.config.ts
  • packages/modernjs/package.json
  • packages/modernjs/src/cli/utils.ts
  • packages/rsbuild-plugin/package.json
  • packages/rsbuild-plugin/rollup.config.js
  • packages/rsbuild-plugin/src/cli/index.ts
  • packages/rsbuild-plugin/src/utils/autoDeleteSplitChunkCacheGroups.ts
  • packages/rsbuild-plugin/src/utils/index.ts
  • packages/storybook-addon/package.json
  • packages/storybook-addon/preset.ts
  • packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts
  • pnpm-lock.yaml

export {
default as ModuleFederationPlugin,
PLUGIN_NAME,
} from './wrapper/ModuleFederationPlugin';
export { default as ContainerReferencePlugin } from './wrapper/ContainerReferencePlugin';
export { default as SharePlugin } from './wrapper/SharePlugin';
export { default as ContainerPlugin } from './wrapper/ContainerPlugin';
Copy link
Contributor

Choose a reason for hiding this comment

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

The export statement for ContainerPlugin appears to be truncated. Complete the line to properly export the plugin:

Suggested change
export { default as ContainerPlugin } from './wrapper/ContainerPlugin';
export { default as ContainerPlugin } from './wrapper/ContainerPlugin';

@@ -1,5 +1,8 @@
import type { moduleFederationPlugin } from '@module-federation/sdk';
Copy link
Contributor

Choose a reason for hiding this comment

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

The import statement only imports the type but not the actual module. If the module is needed at runtime, consider importing both:

Suggested change
import type { moduleFederationPlugin } from '@module-federation/sdk';
import { moduleFederationPlugin } from '@module-federation/sdk';

Comment on lines 1 to 8
import type { moduleFederationPlugin } from '@module-federation/sdk';
export { default as ModuleFederationPlugin } from './wrapper/ModuleFederationPlugin';
export {
default as ModuleFederationPlugin,
PLUGIN_NAME,
} from './wrapper/ModuleFederationPlugin';
export { default as ContainerReferencePlugin } from './wrapper/ContainerReferencePlugin';
export { default as SharePlugin } from './wrapper/SharePlugin';
export { default as ContainerPlugin } from './wrapper/ContainerPlugin';
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding JSDoc comments for the exported plugins to improve API documentation. This will help users understand the purpose and usage of each plugin. For example:
/**

  • Exports core Module Federation plugins for webpack configuration
  • @module ModuleFederationPlugins
    */

Also consider grouping related exports together with explanatory comments for better code organization.

Comment on lines +1 to +4
import {
default as ModuleFederationPlugin,
PLUGIN_NAME,
} from './wrapper/ModuleFederationPlugin';
Copy link
Contributor

Choose a reason for hiding this comment

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

The import statement could be more specific about what's being imported. Instead of using 'default as', consider importing the plugin directly for better clarity and readability. Here's a suggested change:

Suggested change
import {
default as ModuleFederationPlugin,
PLUGIN_NAME,
} from './wrapper/ModuleFederationPlugin';
import ModuleFederationPlugin, { PLUGIN_NAME } from './wrapper/ModuleFederationPlugin';

This makes it immediately clear what's being imported without the 'default as' indirection.

export class ModuleFederationPlugin implements RspackPluginInstance {
readonly name = 'RspackModuleFederationPlugin';
readonly name = PLUGIN_NAME;
private _options: moduleFederationPlugin.ModuleFederationPluginOptions;
Copy link
Contributor

Choose a reason for hiding this comment

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

The type name moduleFederationPlugin.ModuleFederationPluginOptions uses camelCase for the namespace which is unconventional. TypeScript namespaces typically use PascalCase. Consider renaming to ModuleFederationPlugin.ModuleFederationPluginOptions or creating a dedicated types file.

export class ModuleFederationPlugin implements RspackPluginInstance {
readonly name = 'RspackModuleFederationPlugin';
readonly name = PLUGIN_NAME;
private _options: moduleFederationPlugin.ModuleFederationPluginOptions;
private _statsPlugin?: StatsPlugin;
Copy link
Contributor

Choose a reason for hiding this comment

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

The optional _statsPlugin property is using a nullable type with ?. Consider using a more explicit initialization to null or defining it as non-nullable if it's required after initialization. This helps with type safety and makes the intent clearer. ```suggestion
private _statsPlugin: StatsPlugin | null = null;

@@ -1,4 +1,4 @@
export { ModuleFederationPlugin } from './ModuleFederationPlugin';
export { ModuleFederationPlugin, PLUGIN_NAME } from './ModuleFederationPlugin';
import { container } from '@rspack/core';
export const ContainerPlugin = container.ContainerPlugin;
export const ContainerReferencePlugin = container.ContainerReferencePlugin;
Copy link
Contributor

Choose a reason for hiding this comment

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

The ContainerReferencePlugin export appears to be incomplete. The line ends with "Contain" which seems to be truncated. This should be completed to properly export the plugin: ```suggestion
export const ContainerReferencePlugin = container.ContainerReferencePlugin;

Comment on lines +1 to 4
export { ModuleFederationPlugin, PLUGIN_NAME } from './ModuleFederationPlugin';
import { container } from '@rspack/core';
export const ContainerPlugin = container.ContainerPlugin;
export const ContainerReferencePlugin = container.ContainerReferencePlugin;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider grouping related exports and imports together for better code organization. Move the import statement before the exports:

Suggested change
export { ModuleFederationPlugin, PLUGIN_NAME } from './ModuleFederationPlugin';
import { container } from '@rspack/core';
export const ContainerPlugin = container.ContainerPlugin;
export const ContainerReferencePlugin = container.ContainerReferencePlugin;
import { container } from '@rspack/core';
export { ModuleFederationPlugin, PLUGIN_NAME } from './ModuleFederationPlugin';
export const ContainerPlugin = container.ContainerPlugin;
export const ContainerReferencePlugin = container.ContainerReferencePlugin;

@2heal1 2heal1 changed the title WIP: chore(rsbuild-plugin): split setUp function to help extend chore(rsbuild-plugin): split setUp function to help extend Dec 26, 2024
@2heal1 2heal1 merged commit a1d46b7 into main Dec 26, 2024
18 checks passed
@2heal1 2heal1 deleted the chore/split-rsbuild-plugin branch December 26, 2024 09:15
@2heal1 2heal1 mentioned this pull request Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants