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

Add option to specify "filePath" for dts generateTypes #2550

Closed
2 tasks done
YanPes opened this issue May 28, 2024 · 8 comments
Closed
2 tasks done

Add option to specify "filePath" for dts generateTypes #2550

YanPes opened this issue May 28, 2024 · 8 comments

Comments

@YanPes
Copy link
Contributor

YanPes commented May 28, 2024

Clear and concise description of the problem

In order to address the generated types of a certain manifest.json file behind a proxy, it is necessary to parse and overwrite the manifest.json fields metaData.types.zip and metaData.types.api because the default paths of the generated types are not reachable for our use-cases.

Currently, we use a custom plugin that is overwriting the variables afterBuild to have a valid pointer when calling the manifest.json which is very inconvenient.

Suggested solution

The request is to provide more control over the file generation by adding a filePath field in the generatedTypes object.

...
new ModuleFederationPlugin({
  ...moduleFederationConfig,
  manifest: {
    filePath: 'my/custom/path'
  },
  dts: {
    generatedTypes: {
      typesFolder: 'mf-custom-types',
      // new requested field to give more control over the behavior of module federation file orchestration
      filePath; 'my/custom/path/'
    }
  }
})
...

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.
@YanPes
Copy link
Contributor Author

YanPes commented May 28, 2024

@ScriptedAlchemy: As requested, here the created issue and your association to it. Thank you in advance 👍

@ScriptedAlchemy
Copy link
Member

Do you have an idea in the source code about where you would implement this update?
Is this something you want to send a PR for or would like us to look into?

@ScriptedAlchemy
Copy link
Member

@YanPes is this not something that publicPath: auto resolves?

@YanPes
Copy link
Contributor Author

YanPes commented May 30, 2024

@ScriptedAlchemy I just found the publicPath === 'auto' in DTSManager.ts. We will update the MF version and test the new feature. Thanks for the hint - I will give an update soon!

@ScriptedAlchemy
Copy link
Member

Yeah we recently added it since users were not thrilled about needing to know the url upfront at build haha.

@YanPes
Copy link
Contributor Author

YanPes commented Jun 20, 2024

To load the remotes via traefik proxy we need Modern.js to serve the files inside the static folder.
Our custom plugin moves the .zip and d.ts files from the dist root to the assets folder so it can be accessed by other applications. At the same time the content of the manifest.json is adapted to point to the correct folder of the .zip and d.ts's.
This then allowed us to load the zip from another container.

function afterFederation(module: string, publicPath: string) {
  const assetFolder = `modules/${module}/static/js/`;
  const typesFolder = `mf-${module}-types`;
  const manifestFile = path.join(
    './',
    '/dist/' + assetFolder + 'mf-manifest.json',
  );
  updateManifestJson(manifestFile, assetFolder, typesFolder, publicPath);
  moveTypes(assetFolder, typesFolder, '.zip');
  moveTypes(assetFolder, typesFolder, '.d.ts');
}

It would be great to have a native integration solving this issue. As requested above the easiest solution would be to have a manual override of the dist path of the generatedTypes defined inside the DTSmanager.ts.

generatedTypes: {
      typesFolder: 'mf-custom-types',
      // new requested field to give more control over the behavior of module federation file orchestration
      filePath; 'my/custom/path/'
    }

@ScriptedAlchemy
Copy link
Member

@YanPes merged

@YanPes
Copy link
Contributor Author

YanPes commented Jul 2, 2024

@ScriptedAlchemy Tested on our side - Works as expected! Thanks to all contributors for your fast action!

This issue was closed.
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

No branches or pull requests

2 participants