Skip to content

Commit 3f9677d

Browse files
feat(storybook-addon): use new api to get the storybook virtual static modules (#3298)
Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent eda5184 commit 3f9677d

File tree

6 files changed

+69
-26
lines changed

6 files changed

+69
-26
lines changed

.changeset/tame-taxis-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/storybook-addon': major
3+
---
4+
5+
Use new api to get the virtual static modules

packages/storybook-addon/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = storybookConfig;
4545

4646
### Rsbuild App or Rslib Module
4747

48-
```
48+
```js
4949
import { dirname, join } from 'node:path';
5050
import type { StorybookConfig } from 'storybook-react-rsbuild';
5151

packages/storybook-addon/jest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ export default {
1212
},
1313
moduleFileExtensions: ['ts', 'js', 'html'],
1414
coverageDirectory: '../../coverage/packages/storybook-addon',
15+
// https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest
16+
testEnvironment: 'jest-fixed-jsdom',
1517
};

packages/storybook-addon/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@module-federation/storybook-addon",
3-
"version": "3.0.18",
3+
"version": "3.1.0",
44
"description": "Storybook addon to consume remote module federated apps/components",
55
"type": "commonjs",
66
"license": "MIT",
@@ -53,28 +53,30 @@
5353
"@module-federation/sdk": "workspace:*"
5454
},
5555
"devDependencies": {
56+
"jest-fixed-jsdom": "^0.0.9",
5657
"@module-federation/utilities": "workspace:*",
5758
"@rsbuild/core": "^1.0.19",
58-
"@storybook/core-common": "7.6.20",
5959
"@storybook/node-logger": "7.6.20",
60+
"@storybook/core": "^8.4.6",
6061
"webpack": "5.93.0",
6162
"webpack-virtual-modules": "0.6.2"
6263
},
6364
"peerDependencies": {
6465
"@rsbuild/core": "^1.0.1",
6566
"@module-federation/utilities": "^3.1.38",
67+
"@module-federation/sdk": "^0.8.0",
6668
"@nx/react": ">= 16.0.0",
6769
"@nx/webpack": ">= 16.0.0",
68-
"@storybook/core-common": "^6.5.16 || ^7.0.0 || ^ 8.0.0",
69-
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^ 8.0.0",
70+
"@storybook/core": ">= 8.2.0",
71+
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^8.0.0",
7072
"webpack": "^5.75.0",
71-
"webpack-virtual-modules": "^0.5.0 || ^0.6.0"
73+
"webpack-virtual-modules": "0.6.2"
7274
},
7375
"peerDependenciesMeta": {
7476
"@rsbuild/core": {
7577
"optional": true
7678
},
77-
"@module-federation/utilities": {
79+
"@module-federation/sdk": {
7880
"optional": true
7981
},
8082
"@nx/react": {
@@ -83,7 +85,7 @@
8385
"@nx/webpack": {
8486
"optional": true
8587
},
86-
"@storybook/core-common": {
88+
"@storybook/core": {
8789
"optional": true
8890
},
8991
"@storybook/node-logger": {

packages/storybook-addon/src/lib/storybook-addon.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ import fs from 'fs';
22
import { dirname, join } from 'path';
33
import * as process from 'process';
44
import VirtualModulesPlugin from 'webpack-virtual-modules';
5-
import { container, Configuration } from 'webpack';
5+
import { container, type Configuration } from 'webpack';
66
import { logger } from '@storybook/node-logger';
7-
// NOTE: @storybook/core-common is deprecated while still available, considering importing
8-
// from 'storybook/internal/common' or '@storybook/core'. Considering requires Storybook 8
9-
// at least and change this in the next breaking change version.
10-
import { normalizeStories } from '@storybook/core-common';
11-
import { ModuleFederationPluginOptions } from '@module-federation/utilities';
12-
13-
import { ModuleFederationConfig } from '@nx/webpack';
7+
import { normalizeStories } from '@storybook/core/common';
148
import withModuleFederation from '../utils/with-module-federation';
159
import { correctImportPath } from '../utils/correctImportPath';
1610

11+
import type { moduleFederationPlugin } from '@module-federation/sdk';
12+
import type { ModuleFederationConfig } from '@nx/webpack';
13+
1714
const { ModuleFederationPlugin } = container;
1815

1916
export type Preset = string | { name: string };
2017

2118
type Options = {
22-
moduleFederationConfig?: ModuleFederationPluginOptions;
19+
moduleFederationConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
2320
nxModuleFederationConfig?: ModuleFederationConfig;
2421
presets: {
2522
apply<T>(preset: Preset): Promise<T>;
@@ -70,17 +67,16 @@ export const webpack = async (
7067
);
7168

7269
const index = plugins.findIndex(
73-
//@ts-ignore
74-
(plugin) => plugin.constructor.name === 'VirtualModulesPlugin',
70+
(plugin) => plugin?.constructor.name === 'VirtualModulesPlugin',
7571
);
7672

7773
if (index !== -1) {
7874
logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`);
7975

80-
/* eslint-disable @typescript-eslint/no-explicit-any */
81-
const plugin = plugins[index] as any;
76+
const plugin = plugins[index] as VirtualModulesPlugin;
8277

83-
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?
78+
const virtualEntries: Record<string, string> =
79+
plugin.getModuleList('static');
8480
const virtualEntriesPaths: string[] = Object.keys(virtualEntries);
8581

8682
logger.info(`=> [MF] Write files from VirtualModulesPlugin`);

pnpm-lock.yaml

Lines changed: 42 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)