diff --git a/.changeset/tame-taxis-mix.md b/.changeset/tame-taxis-mix.md new file mode 100644 index 0000000000..61489f9599 --- /dev/null +++ b/.changeset/tame-taxis-mix.md @@ -0,0 +1,5 @@ +--- +'@module-federation/storybook-addon': major +--- + +Use new api to get the virtual static modules diff --git a/packages/storybook-addon/README.md b/packages/storybook-addon/README.md index 675b1c92ff..f17f18d99c 100644 --- a/packages/storybook-addon/README.md +++ b/packages/storybook-addon/README.md @@ -45,7 +45,7 @@ module.exports = storybookConfig; ### Rsbuild App or Rslib Module -``` +```js import { dirname, join } from 'node:path'; import type { StorybookConfig } from 'storybook-react-rsbuild'; diff --git a/packages/storybook-addon/jest.config.ts b/packages/storybook-addon/jest.config.ts index 4d3eba9c9b..d8ecedee47 100644 --- a/packages/storybook-addon/jest.config.ts +++ b/packages/storybook-addon/jest.config.ts @@ -12,4 +12,6 @@ export default { }, moduleFileExtensions: ['ts', 'js', 'html'], coverageDirectory: '../../coverage/packages/storybook-addon', + // https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest + testEnvironment: 'jest-fixed-jsdom', }; diff --git a/packages/storybook-addon/src/lib/storybook-addon.ts b/packages/storybook-addon/src/lib/storybook-addon.ts index 7e1cb9bcf6..32ba5cd63c 100644 --- a/packages/storybook-addon/src/lib/storybook-addon.ts +++ b/packages/storybook-addon/src/lib/storybook-addon.ts @@ -2,24 +2,21 @@ import fs from 'fs'; import { dirname, join } from 'path'; import * as process from 'process'; import VirtualModulesPlugin from 'webpack-virtual-modules'; -import { container, Configuration } from 'webpack'; +import { container, type Configuration } from 'webpack'; import { logger } from '@storybook/node-logger'; -// NOTE: @storybook/core-common is deprecated while still available, considering importing -// from 'storybook/internal/common' or '@storybook/core'. Considering requires Storybook 8 -// at least and change this in the next breaking change version. -import { normalizeStories } from '@storybook/core-common'; -import { ModuleFederationPluginOptions } from '@module-federation/utilities'; - -import { ModuleFederationConfig } from '@nx/webpack'; +import { normalizeStories } from '@storybook/core/common'; import withModuleFederation from '../utils/with-module-federation'; import { correctImportPath } from '../utils/correctImportPath'; +import type { moduleFederationPlugin } from '@module-federation/sdk'; +import type { ModuleFederationConfig } from '@nx/webpack'; + const { ModuleFederationPlugin } = container; export type Preset = string | { name: string }; type Options = { - moduleFederationConfig?: ModuleFederationPluginOptions; + moduleFederationConfig?: moduleFederationPlugin.ModuleFederationPluginOptions; nxModuleFederationConfig?: ModuleFederationConfig; presets: { apply(preset: Preset): Promise; @@ -70,17 +67,16 @@ export const webpack = async ( ); const index = plugins.findIndex( - //@ts-ignore - (plugin) => plugin.constructor.name === 'VirtualModulesPlugin', + (plugin) => plugin?.constructor.name === 'VirtualModulesPlugin', ); if (index !== -1) { logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`); - /* eslint-disable @typescript-eslint/no-explicit-any */ - const plugin = plugins[index] as any; + const plugin = plugins[index] as VirtualModulesPlugin; - const virtualEntries = plugin._staticModules; // TODO: Exist another way to get virtual modules? Or maybe it's good idea to open a PR adding a method to get modules? + const virtualEntries: Record = + plugin.getModuleList('static'); const virtualEntriesPaths: string[] = Object.keys(virtualEntries); logger.info(`=> [MF] Write files from VirtualModulesPlugin`);