module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.27k stars 184 forks source link

fix(node): allow fetch override on runtime plugin #2603

Closed ScriptedAlchemy closed 1 week ago

ScriptedAlchemy commented 3 weeks ago

Description

Allow internal fetch method to be overriden

Related Issue

fixes: https://github.com/module-federation/core/issues/2534

Types of changes

Checklist

changeset-bot[bot] commented 3 weeks ago

🦋 Changeset detected

Latest commit: 71b088766670a4b8011ec287a0a9ccd133a75edf

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

This PR includes changesets to release 26 packages | Name | Type | | ---------------------------------------------- | ----- | | @module-federation/sdk | Patch | | @module-federation/node | Minor | | @module-federation/runtime | Patch | | @module-federation/devtools | Patch | | @module-federation/dts-plugin | Patch | | @module-federation/enhanced | Patch | | @module-federation/managers | Patch | | @module-federation/manifest | Patch | | @module-federation/nextjs-mf | Patch | | @module-federation/rspack | Patch | | @module-federation/utilities | Patch | | @module-federation/webpack-bundler-runtime | Patch | | @module-federation/bridge-react-webpack-plugin | Patch | | @module-federation/runtime-tools | Patch | | 3008-runtime-remote | Patch | | host | Patch | | host-v5 | Patch | | host-vue3 | Patch | | remote1 | Patch | | remote2 | Patch | | remote3 | Patch | | @module-federation/modernjs | Patch | | @module-federation/third-party-dts-extractor | Patch | | @module-federation/bridge-react | Patch | | @module-federation/bridge-vue3 | Patch | | @module-federation/bridge-shared | 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

netlify[bot] commented 3 weeks ago

Deploy Preview for module-federation-docs ready!

Name Link
Latest commit 71b088766670a4b8011ec287a0a9ccd133a75edf
Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/667d0a25f7c5030008ac3326
Deploy Preview https://deploy-preview-2603--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 commented 1 week ago

@quantum-1986 - im working on integrating the chunk load cycle on the server with our runtime apis, so you can now do the following:

You can do this as a hook from the runtime plugins docs.

export default function (): FederationRuntimePlugin {
  return {
    name: 'node-federation-plugin',
    fetch(url, init) {
      console.log('HOOK', url);

      return fetch(url, init);
    },
    beforeInit(args) {

      //patch webpack chunk loading handlers etc (this is what i do) 
2heal1 commented 1 week ago

I don't know how we get fetch now from this pr , because i see you will use __webpack_require__.federation.instance.loaderHook.lifecycle.fetch.emit , it will return undefined in the node-host demo

image

ScriptedAlchemy commented 1 week ago

I don't know how we get fetch now from this pr , because i see you will use __webpack_require__.federation.instance.loaderHook.lifecycle.fetch.emit , it will return undefined in the node-host demo

image

yeah im working on a fix