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: split runtime as core and entry #3154

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

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Nov 1, 2024

Description

  1. split runtime into two parts : runtime-core entry
  • runtime-core: no sideEffect
  • entry: has sideEffect , it will cache federationInstance
  1. add externalRuntime and provideExternalRuntime field to help optimize assets size

About next major version

Plans to make @module-federation/runtime-core to become @module-federation/runtime , because currently the runtime package has sideEffects which can no be extends easily , like external it by cdn etc.

So , it's necessary to change it . We can only export init to users , users should store the instance by theirselves .

This will make a break change ,so it's just a plan , we can do it on 1.0.0 version . cc @ScriptedAlchemy @zhoushaw

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 Nov 1, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 2f5bc75
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/676546681f084d0008630afc
😎 Deploy Preview https://deploy-preview-3154--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.

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

Here is a concise summary of the pull request:

The core changes in this pull request involve splitting the runtime module into two parts: runtime-core and entry. The runtime-core is designed to have no side effects, while the entry part has side effects and will cache the federationInstance. This separation aims to improve the modularity and maintainability of the runtime component.

The key changes include:

  • Externalization of the runtime-core module, allowing it to be provided independently from the entry module.
  • Addition of new configuration options to support the split runtime, including externalRuntime and provideExternalRuntime.
  • Refactoring of various utility functions, hooks, and handlers to accommodate the split runtime structure.
  • Improvements to the overall structure and organization of the runtime-related code, with a focus on separation of concerns and modularity.

These changes are expected to enhance the integration of the runtime module with the existing codebase, providing more flexibility and better maintainability in the long run.

File Summaries
File Summary
packages/enhanced/src/lib/container/ModuleFederationPlugin.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is designed to have no side effects, while the entry part has side effects and will cache the federationInstance. Additionally, the runtime-core is now externalized, and the code adds support for providing an external runtime core plugin and an external runtime configuration.
packages/enhanced/src/schemas/container/ContainerPlugin.check.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core has no side effects, while the entry part has side effects and will cache the federationInstance. This change aims to externalize the runtime-core for better modularity and maintainability.
packages/enhanced/src/schemas/container/ContainerPlugin.ts The code changes introduce a new configuration option called "externalRuntime" to the ContainerPlugin schema. This option allows the runtime to be split into two parts: "runtime-core" and "entry". The "runtime-core" part has no side effects, while the "entry" part has side effects and will cache the federationInstance.
packages/rspack/src/ModuleFederationPlugin.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now external and has no side effects, while the entry part has side effects and caches the federation instance. Additionally, the changes introduce an option to provide an external runtime-core and externalize it from the bundle.
packages/runtime-core/src/constant.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and will cache the federationInstance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/core.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core has no side effects, while the entry part has side effects and will cache the federationInstance. Additionally, the runtime-core is now externalized. The changes also include the addition of various hooks and handlers, such as SnapshotHandler, SharedHandler, and RemoteHandler, which handle different aspects of the runtime functionality.
packages/runtime-core/src/global.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core has no side effects, while the entry part has side effects and will cache the federationInstance. Additionally, the runtime-core is now externalized.
packages/runtime-core/src/helpers.ts The code changes introduce a new module that exports two utility objects: GlobalUtils and ShareUtils. The GlobalUtils object provides a collection of functions related to managing global state and information, such as setting and retrieving global federation instances, snapshots, and preloaded data. The ShareUtils object provides functions for managing shared module registrations and scopes.
packages/runtime-core/src/index.ts This code change splits the runtime into two parts: runtime-core and entry. The runtime-core has no side effects, while the entry part has side effects and will cache the federationInstance. The changes also externalize the runtime-core and update the exports to include various utility functions, types, and modules related to the federation runtime.
packages/runtime-core/src/module/index.ts The changes in this file involve splitting the runtime into two separate parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will handle caching the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/plugins/generate-preload-assets.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation allows for better modularity and flexibility in the codebase.
packages/runtime-core/src/plugins/snapshot/SnapshotHandler.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/plugins/snapshot/index.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and will cache the federationInstance.
packages/runtime-core/src/remote/index.ts The changes in this file involve splitting the runtime into two separate parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will handle caching the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/shared/index.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance.
packages/runtime-core/src/type/config.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/type/index.ts This change separates the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This refactoring aims to externalize the runtime-core module, potentially improving modularity and flexibility.
packages/runtime-core/src/type/plugin.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now externalized and has no side effects, while the entry part has side effects and will cache the federationInstance.
packages/runtime-core/src/type/preload.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation of concerns improves the overall structure and maintainability of the codebase.
packages/runtime-core/src/types.ts The changes in this file involve the addition of a new export statement that re-exports all the types from the './type' module. This change likely aims to simplify the API and make it easier to access the necessary types from a single entry point.
packages/runtime-core/src/utils/env.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now externalized and has no side effects, while the entry part has side effects and will cache the federationInstance.
packages/runtime-core/src/utils/hooks/asyncHook.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/hooks/asyncWaterfallHooks.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation of concerns improves the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/hooks/index.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance.
packages/runtime-core/src/utils/hooks/pluginSystem.ts The code changes introduce a split in the runtime module, separating it into a core part and an entry part. The core part has no side effects, while the entry part caches the federation instance. This change aims to improve the modularity and maintainability of the runtime component.
packages/runtime-core/src/utils/hooks/syncHook.ts The changes in this file split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/hooks/syncWaterfallHook.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now externalized and has no side effects, while the entry part has side effects and will cache the federationInstance.
packages/runtime-core/src/utils/index.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/load.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federationInstance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/logger.ts The changes in this file split the runtime into two separate parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module has side effects and will cache the federation instance.
packages/runtime-core/src/utils/manifest.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/plugin.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/preload.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/semver/compare.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now externalized and has no side effects, while the entry part has side effects and will cache the federationInstance.
packages/runtime-core/src/utils/semver/constants.ts The changes in this file involve splitting the runtime into two separate parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will handle caching of the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/semver/index.ts The code changes split the runtime into two separate parts: runtime-core and entry. The runtime-core module is now externalized and has no side effects, while the entry module handles caching of the federation instance and has side effects.
packages/runtime-core/src/utils/semver/parser.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core is designed to have no side effects, while the entry part has side effects and will cache the federationInstance. This separation aims to externalize the runtime-core for improved modularity and flexibility.
packages/runtime-core/src/utils/semver/utils.ts The changes in this file involve splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will cache the federation instance. This separation aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/share.ts The changes in this file involve splitting the runtime into two separate parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will handle caching the federation instance. This separation of concerns aims to improve the overall structure and maintainability of the codebase.
packages/runtime-core/src/utils/tool.ts The code changes introduce a split of the runtime into two parts: runtime-core and entry. The runtime-core is now external and has no side effects, while the entry part has side effects and will cache the federationInstance.
packages/runtime-plugins/inject-external-runtime-core-plugin/src/index.ts This code change introduces a plugin that injects the external runtime-core module into the global scope, ensuring that there is only one instance of the runtime-core being used across the application. The plugin checks if there is an existing runtime-core instance and warns the user if there is a mismatch in the version or the name of the provider. This change is likely part of a larger effort to split the runtime into a core and an entry module, where the core module has no side effects and the entry module handles the caching of the federation instance.
packages/runtime-tools/src/runtime-core.ts The changes in this file involve exporting all the functionality from the @module-federation/runtime/core module, effectively making the current file an entry point for the runtime-core functionality.
packages/runtime/src/core.ts The code changes split the runtime into two parts: runtime-core and entry. The runtime-core has no side effects, while the entry part has side effects and will cache the federationInstance. Additionally, the runtime-core has been externalized.
packages/runtime/src/helpers.ts The code changes split the runtime into two parts: runtime-core and entry. The runtime-core module has no side effects, while the entry module has side effects and caches the federation instance. The changes also externalize the runtime-core module and provide a helper object that exposes the necessary global utilities and share-related functions.
packages/runtime/src/index.ts The code changes in this file are focused on splitting the runtime into two parts: runtime-core and entry. The runtime-core module is designed to have no side effects, while the entry module will cache the FederationInstance. The changes also involve externalizing the runtime-core module and updating the imports and exports accordingly.
packages/runtime/src/types.ts The code changes split the runtime module into two parts: runtime-core and entry. The runtime-core module is now externalized and has no side effects, while the entry module has side effects and caches the federation instance.
packages/runtime/src/utils.ts The code changes introduce a new utility function getGlobalFederationInstance that retrieves a specific instance of the FederationHost based on the provided name and version. Additionally, a helper function getBuilderId is added to fetch the build identifier, which is used to identify the correct FederationHost instance when multiple instances exist.
packages/sdk/src/types/plugins/ModuleFederationPlugin.ts The changes in this file introduce two new configuration options for the ModuleFederationPluginOptions interface: "externalRuntime" and "provideExternalRuntime". These options allow for the runtime to be split into two parts - "runtime-core" and "entry" - where "runtime-core" has no side effects and "entry" caches the federation instance.

it('verify resources when URL specifies protocol (http)', () => {
const url = 'http://a.b.c';
const scriptElement = document.createElement('script');
scriptElement.src = url;

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium test

Script loaded using unencrypted connection.
Copy link

changeset-bot bot commented Nov 9, 2024

🦋 Changeset detected

Latest commit: 2f5bc75

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

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

@ScriptedAlchemy ScriptedAlchemy force-pushed the chore/external-runtime-core branch from 67a6235 to d56d6fa Compare November 9, 2024 02:38
@ScriptedAlchemy ScriptedAlchemy changed the title WIP: chore: split runtime as core and entry chore: split runtime as core and entry Nov 22, 2024
@ScriptedAlchemy ScriptedAlchemy mentioned this pull request Dec 3, 2024
5 tasks
@ScriptedAlchemy ScriptedAlchemy force-pushed the chore/external-runtime-core branch from f7479be to 8e13a48 Compare December 3, 2024 23:36
@2heal1
Copy link
Member Author

2heal1 commented Dec 20, 2024

processing this pr now

@2heal1
Copy link
Member Author

2heal1 commented Dec 20, 2024

@ScriptedAlchemy hey , i add externalRuntime field to help users access this feature easier ,WDYT ?

@ScriptedAlchemy
Copy link
Member

@2heal1 i like it! I can review more tomorrow.
Is this ready to merge?

@2heal1
Copy link
Member Author

2heal1 commented Dec 20, 2024

@2heal1 i like it! I can review more tomorrow. Is this ready to merge?

It needs to be tested in byte repo , but not longer , next Monday can be ready .

@2heal1
Copy link
Member Author

2heal1 commented Dec 20, 2024

Also i add some info for version 1.0.0 .

Plans to make @module-federation/runtime-core to become @module-federation/runtime , because currently the runtime package has sideEffects which can no be extends easily , like external it by cdn etc.

So , it's necessary to change it . We can only export init to users , users should store the instance by theirselves .

This will make a break change ,so it's just a plan , we can do it on 1.0.0 version . WDYT @ScriptedAlchemy @zhoushaw

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