Skip to content

@module-federation/native-federation-typescript - support destination folder, loadRemote typings and other improvements #2606

@crutch12

Description

@crutch12

Clear and concise description of the problem

Hi @ilteoood 👋

It would be great to have more flexibility in @module-federation/native-federation-typescript plugin

Here are my comments:

NativeFederationTypeScriptRemote

  1. typesFolder: './types/@my-mf-types' (nested) generates empty ./dist/types folder
  2. When using with @module-federation/enhanced/webpack (or @module-federation/manifest), this plugin doesn't change mf-manifest.json file. Example:
// webpack.config.js
const { ModuleFederationPlugin } = require('@module-federation/enhanced/webpack')
const { NativeFederationTypeScriptRemote } = require('@module-federation/native-federation-typescript/webpack')

plugins: [
  new ModuleFederationPlugin({
    ...federationConfig,
    dts: false, // disable to generate with NativeFederationTypeScriptRemote
  }),
  NativeFederationTypeScriptRemote({
    moduleFederationConfig: federationConfig,
    typesFolder: './types/@my-mf-types',
  }),
],

// generated mf-manifest.json
// ...
"metaData": {
   // ...
  "types": {
    "path": "",
    "name": "",
    "zip": "",
    "api": ""
  },
},
// ...

NativeFederationTypeScriptHost

  1. typesFolder is also used as link to remote (example: https://.../${typesFolder}.zip). So I can't change this parameter at all
    (source: https://github.com/module-federation/core/blob/main/packages/native-federation-typescript/src/configurations/hostPlugin.ts#L22)

  2. deleteTypesFolder deletes @mf-types/@example/app before @mf-types.zip is successfully downloaded. If server is down - plugin removes your types
    (source: https://github.com/module-federation/core/blob/main/packages/native-federation-typescript/src/lib/archiveHandler.ts#L74)

  3. HostPlugin doesn't generates ./@mf-types/index.d.ts with loadRemote typings (unlike @module-federation/dts-plugin)

  4. You can't set @mf-types.zip path for every remote separately

Suggested solution

NativeFederationTypeScriptRemote

  1. Allow nested typesFolder
  2. Implement integration with @module-federation/manifest (maybe using additional props or plugins)

NativeFederationTypeScriptHost

  1. typesFolder should be used only as download destination directory path

  2. deleteTypesFolder shouldn't delete types on error (if server is not available)

  3. Implement ./@mf-types/index.d.ts generation for loadRemote function, just like in @module-federation/dts-plugin
    (source: https://github.com/module-federation/core/blob/main/packages/dts-plugin/src/core/lib/DTSManager.ts#L290)
    (example: https://github.com/module-federation/module-federation-examples/blob/11dcb0d6d28c26733da82e3805d7c2e3c9f4c65d/rspack_hmr/host/%40mf-types/index.d.ts)

Allow additional parameters in remotes section. Example:

// plugin config
remotes: [
  {
    entry: 'https://.../remoteEntry.js',
    typesZip: '@my-mf-types.zip' // or 'https://.../@my-mf-types.zip'
    // also add .zip automatically, if value has no `.zip` substring
  }
]

OR/AND

Take @mf-types.zip path from mf-manifest.json (types section`). Example:

// plugin config
remotes: [
  {
    entry: 'https://.../mf-manifest.json',
  }
]
// mf-manifest.json
metaData: {
  types: {
    zip: './@my-mf-types.zip'
  }
}

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions