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

fix(dts-plugin): lazy emit subsequent type generations #3345

Merged
merged 16 commits into from
Dec 13, 2024

Conversation

ScriptedAlchemy
Copy link
Member

Description

Do not block compilation seal on followup compilations

Related Issue

#3110 (comment)

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 Dec 12, 2024

🦋 Changeset detected

Latest commit: e966cd9

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/dts-plugin Patch
@module-federation/enhanced Patch
@module-federation/manifest 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/runtime Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers 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/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 Dec 12, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit e966cd9
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/675b65a7e4ee810007945a86
😎 Deploy Preview https://deploy-preview-3345--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
Copy link
Member

2heal1 commented Dec 12, 2024

the ci error can be reproduced locally , looks like the webpack types mismatch

packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts:109:15 - error TS2554: Expected 2 arguments, but got 3.

109               (err) => {
                  ~~~~~~~~~~
110                 if (err) reject(err);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
120                 }
    ~~~~~~~~~~~~~~~~~
121               },
    ~~~~~~~~~~~~~~~
    ```

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

The pull request focuses on improving the behavior and performance of the dts-plugin module in the context of Module Federation. The key changes include:

  1. Enhancing the DTSManager class to handle various scenarios more gracefully, such as multiple exposed components, empty expose maps, missing remote manifests, and download errors.
  2. Updating the DtsWorker to avoid blocking the compilation seal on subsequent type generations, allowing for more efficient type processing.
  3. Improving the handling of type definitions archives, including constructing correct file paths, creating archives, and downloading them with retry logic and error handling.
  4. Introducing a new emitTypesFiles function in the GenerateTypesPlugin to write the generated types files to the output directory, without blocking the compilation seal.

These changes aim to improve the overall reliability, performance, and error handling of the dts-plugin module, ensuring a more robust and efficient Module Federation setup.

File Summaries
File Summary
packages/dts-plugin/src/core/lib/DTSManager.general.spec.ts The code changes focus on improving the behavior of the DTSManager class in the dts-plugin module. The key modifications are:
  1. The generateAPITypes method has been updated to handle both multiple exposed components and empty expose maps, ensuring the correct generation of API types.

  2. The requestRemoteManifest method has been enhanced to handle various scenarios, including non-manifest URLs, manifest URLs with auto publicPath, manifest URLs without API types, and manifest fetch errors.

  3. The consumeTargetRemotes method has been updated to handle the case where the zipUrl is missing, throwing an appropriate error.

  4. The updateTypes method has been modified to handle missing remote options gracefully.

  5. The downloadAPITypes method has been improved to handle missing apiTypeUrl and download errors, and to correctly replace the remote alias in the downloaded content.

  6. The consumeAPITypes method has been updated to handle cases where there are no loaded remote API aliases and when there are existing API types files. |
    | packages/dts-plugin/src/core/lib/DtsWorker.spec.ts | The code changes in this file focus on improving the handling of subsequent type generations in the DTS plugin. The key modifications are:

  7. Ensuring that the compilation seal is not blocked on followup compilations, allowing for more efficient type generation.

  8. Implementing graceful handling of worker process termination, including cases where the termination process fails.

  9. Introducing debug mode handling, where errors are logged when in debug mode, but not logged when in non-debug mode. |
    | packages/dts-plugin/src/core/lib/archiveHandler.test.ts | The code changes in this file focus on improving the handling of type definitions archives in the dts-plugin module. The key modifications are:

  10. The retrieveTypesZipPath and retrieveTypesArchiveDestinationPath functions have been added to handle the construction of zip file paths and destination paths for type definitions, respectively.

  11. The createTypesArchive function has been enhanced to correctly create the type definitions archive, handling both the presence and absence of type definition files, as well as nested directory structures.

  12. The downloadTypesArchive function has been updated to handle various scenarios, including retrying on network failures, gracefully handling empty archives, cleaning up existing folders, and continuing without error when abortOnError is set to false. |
    | packages/dts-plugin/src/core/lib/consumeTypes.spec.ts | The code changes introduce a new test suite for the consumeTypes function, which is responsible for consuming types in the context of a module federation setup. The tests cover the creation of a DTSManager instance with different options, as well as the handling of errors that may occur during the consumeTypes operation. |
    | packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts | The code changes introduce a new function emitTypesFiles that is responsible for writing the generated types files to the output directory. This function is called when the plugin has already compiled once, to avoid blocking the compilation seal on subsequent compilations. The changes also include some additional logic to determine the correct output path for the types files based on the module federation configuration. |

Choose a reason for hiding this comment

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

That's interesting. I haven't seen named changesets before. "Twelve Dingos Ring", what is that even mean 😅
image

Is it used in conversations? Like, "Hey, we've fixed type generation in the twelve dingos ring changeset!"

Copy link

@steven-pribilinskiy steven-pribilinskiy Dec 12, 2024

Choose a reason for hiding this comment

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

Oh, you're using Cursor, nice! Recently I've tried the "Agentic" Windsurf , but it doesn't work with Windows WSL. And then Cursor was updated with it's own version of Agents in the Composer.

John Lindquist has posted some nice vids on the subject matter:

Copy link
Member Author

Choose a reason for hiding this comment

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

Agent does pretty good job in cursor, however llama 3.3 is getting pretty good, would be nice to try it out since unlimited tokens is a game changer

Choose a reason for hiding this comment

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

For LLama it can get more expensive if you use it via some API like Perplexity. Dunno about Amazon Bedrock.
Running it locally, an underperforming 7b model on a 4090 is probably not an option.
Buying an H100 for tens of thousands is not an option too.

Btw, Google is cooking too

./packages/typescript
./packages/native-*
./apps
packages/storybook-addon

Choose a reason for hiding this comment

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

i wonder why these remain with ./ prefix

./tmp
./scripts
./.git

'compiledTypesFolder',
);
beforeEach(() => {
vi.clearAllMocks();
Copy link

@steven-pribilinskiy steven-pribilinskiy Dec 12, 2024

Choose a reason for hiding this comment

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

Is there a reason to not put

import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    clearMocks: true,

into vitest.config.ts?

@ScriptedAlchemy ScriptedAlchemy force-pushed the non-blocking-dts-rebuild branch from 1cb9405 to c6f2c41 Compare December 12, 2024 20:40
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: 9

Configuration

Squadron Mode: essential

Commits Reviewed

8e172c84773d04a4ca25d6e50f8be41306382483...9eeaa440c4243b9b076e9f8f54afc74b1fcca081

Files Reviewed
  • packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts
  • packages/dts-plugin/src/core/lib/archiveHandler.test.ts
  • packages/dts-plugin/src/core/lib/DtsWorker.spec.ts
Files Ignored

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

  • .changeset/twelve-dingos-ring.md
  • .cursorignore
  • apps/manifest-demo/3010-rspack-provider/rspack.config.js
  • apps/react-ts-host/webpack.config.js
  • apps/react-ts-nested-remote/webpack.config.js
  • apps/react-ts-remote/rspack.config.js
  • apps/react-ts-remote/webpack.config.js
  • package.json

@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@module-federation module-federation deleted a comment from squadronai bot Dec 12, 2024
@ScriptedAlchemy ScriptedAlchemy merged commit 5ea7aea into main Dec 13, 2024
16 checks passed
@ScriptedAlchemy ScriptedAlchemy deleted the non-blocking-dts-rebuild branch December 13, 2024 04:07
@2heal1 2heal1 mentioned this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants