@module-federation/storybook-addon 6.0.12 → 6.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CHANGELOG.md +11 -0
- package/dist/preset.js +38 -11
- package/dist/preset.js.map +1 -1
- package/package.json +6 -6
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @module-federation/storybook-addon
|
|
2
2
|
|
|
3
|
+
## 6.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f81b587: Expand `@storybook/node-logger` peer dependency range to include Storybook v9 and v10.
|
|
8
|
+
- 5a8db3e: Pass all Rsbuild Module Federation options through the Storybook addon preset so advanced options such as `dts.consumeTypes.remoteTypeUrls`, `manifest`, and `runtimePlugins` are preserved.
|
|
9
|
+
- Updated dependencies [4da5508]
|
|
10
|
+
- Updated dependencies [b9b3b8c]
|
|
11
|
+
- @module-federation/enhanced@2.5.1
|
|
12
|
+
- @module-federation/sdk@2.5.1
|
|
13
|
+
|
|
3
14
|
## 6.0.12
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/preset.js
CHANGED
|
@@ -17,6 +17,37 @@ const correctImportPath = (context, entryFile) => {
|
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/utils/with-module-federation-enhanced-rsbuild.ts
|
|
20
|
+
const MODULE_FEDERATION_OPTION_KEYS = [
|
|
21
|
+
"async",
|
|
22
|
+
"bridge",
|
|
23
|
+
"dev",
|
|
24
|
+
"dts",
|
|
25
|
+
"experiments",
|
|
26
|
+
"exposes",
|
|
27
|
+
"filename",
|
|
28
|
+
"getPublicPath",
|
|
29
|
+
"implementation",
|
|
30
|
+
"injectTreeShakingUsedExports",
|
|
31
|
+
"library",
|
|
32
|
+
"manifest",
|
|
33
|
+
"name",
|
|
34
|
+
"remoteType",
|
|
35
|
+
"remotes",
|
|
36
|
+
"runtime",
|
|
37
|
+
"runtimePlugins",
|
|
38
|
+
"shareScope",
|
|
39
|
+
"shareStrategy",
|
|
40
|
+
"shared",
|
|
41
|
+
"treeShakingDir",
|
|
42
|
+
"treeShakingSharedExcludePlugins",
|
|
43
|
+
"treeShakingSharedPlugins",
|
|
44
|
+
"virtualRuntimeEntry"
|
|
45
|
+
];
|
|
46
|
+
const getModuleFederationOptions = (options) => {
|
|
47
|
+
const moduleFederationOptions = {};
|
|
48
|
+
for (const key of MODULE_FEDERATION_OPTION_KEYS) if (options[key] !== void 0) moduleFederationOptions[key] = options[key];
|
|
49
|
+
return moduleFederationOptions;
|
|
50
|
+
};
|
|
20
51
|
const tempDirPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);
|
|
21
52
|
const PLUGIN_NAME = "module-federation-storybook-addon";
|
|
22
53
|
const bootstrapPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}/storybook-bootstrap.js`);
|
|
@@ -29,6 +60,7 @@ const writeBootstrap = (context, entryPath) => {
|
|
|
29
60
|
fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));
|
|
30
61
|
};
|
|
31
62
|
const withModuleFederation = (rsbuildConfig, options) => {
|
|
63
|
+
const moduleFederationOptions = getModuleFederationOptions(options);
|
|
32
64
|
rsbuildConfig.plugins ??= [];
|
|
33
65
|
rsbuildConfig.source ??= {};
|
|
34
66
|
rsbuildConfig.source.entry ??= {};
|
|
@@ -46,14 +78,15 @@ const withModuleFederation = (rsbuildConfig, options) => {
|
|
|
46
78
|
});
|
|
47
79
|
api.modifyBundlerChain(async (chain) => {
|
|
48
80
|
chain.plugin(PLUGIN_NAME).use(ModuleFederationPlugin, [{
|
|
49
|
-
|
|
81
|
+
...moduleFederationOptions,
|
|
82
|
+
name: moduleFederationOptions.name || PLUGIN_NAME,
|
|
50
83
|
shared: {
|
|
51
84
|
react: { singleton: true },
|
|
52
85
|
"react-dom": { singleton: true },
|
|
53
|
-
...
|
|
86
|
+
...moduleFederationOptions.shared
|
|
54
87
|
},
|
|
55
|
-
remotes: { ...
|
|
56
|
-
shareStrategy:
|
|
88
|
+
remotes: { ...moduleFederationOptions.remotes },
|
|
89
|
+
shareStrategy: moduleFederationOptions.shareStrategy
|
|
57
90
|
}]);
|
|
58
91
|
});
|
|
59
92
|
}
|
|
@@ -64,13 +97,7 @@ const withModuleFederation = (rsbuildConfig, options) => {
|
|
|
64
97
|
//#endregion
|
|
65
98
|
//#region preset.ts
|
|
66
99
|
var preset_default = { rsbuildFinal: (config, options) => {
|
|
67
|
-
|
|
68
|
-
return withModuleFederation(config, {
|
|
69
|
-
name,
|
|
70
|
-
remotes,
|
|
71
|
-
shared,
|
|
72
|
-
shareStrategy
|
|
73
|
-
});
|
|
100
|
+
return withModuleFederation(config, options);
|
|
74
101
|
} };
|
|
75
102
|
|
|
76
103
|
//#endregion
|
package/dist/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","names":[],"sources":["../src/utils/correctImportPath.ts","../src/utils/with-module-federation-enhanced-rsbuild.ts","../preset.ts"],"sourcesContent":["import path from 'node:path';\n\nexport const correctImportPath = (context: string, entryFile: string) => {\n if (typeof process !== 'undefined') {\n if (process?.platform !== 'win32') {\n return entryFile;\n }\n\n if (entryFile.match(/^\\.?\\.\\\\/) || !entryFile.match(/^[A-Z]:\\\\\\\\/i)) {\n return entryFile.replace(/\\\\/g, '/');\n }\n\n const joint = path.win32.relative(context, entryFile);\n const relative = joint.replace(/\\\\/g, '/');\n\n if (relative.includes('node_modules/')) {\n return relative.split('node_modules/')[1];\n }\n\n return `./${relative}`;\n }\n return null;\n};\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';\nimport { TEMP_DIR } from '@module-federation/sdk';\n\nimport { correctImportPath } from './correctImportPath.js';\n\nimport type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\n\nconst tempDirPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);\nexport const PLUGIN_NAME = 'module-federation-storybook-addon';\n// add bootstrap for host project\nconst bootstrapPath = path.resolve(\n process.cwd(),\n `node_modules/${TEMP_DIR}/storybook-bootstrap.js`,\n);\nconst generateBootstrap = (context: string, entryPath: string) => {\n return `import('${correctImportPath(context, entryPath)}');`;\n};\nconst writeBootstrap = (context: string, entryPath: string) => {\n if (!fs.existsSync(tempDirPath)) {\n fs.mkdirSync(tempDirPath);\n }\n\n if (fs.existsSync(bootstrapPath)) {\n fs.unlinkSync(bootstrapPath);\n }\n fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));\n};\nexport const withModuleFederation = (\n rsbuildConfig: RsbuildConfig,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n) => {\n rsbuildConfig.plugins ??= [];\n rsbuildConfig.source ??= {};\n rsbuildConfig.source.entry ??= {};\n const entry = rsbuildConfig.source.entry;\n const context = rsbuildConfig.root || process.cwd();\n for (const entryName in entry) {\n if (Array.isArray(entry[entryName])) {\n writeBootstrap(context, entry[entryName][0]);\n entry[entryName] = [bootstrapPath];\n }\n }\n\n const rsbuildPlugin: RsbuildPlugin = {\n name: 'module-federation-storybook-plugin',\n setup: function (api) {\n api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {\n const mfConfig: RsbuildConfig = {\n dev: {\n // remoteEntry already includes one hmr runtime, and an additional one is not necessary.\n hmr: false,\n },\n };\n return mergeRsbuildConfig(config, mfConfig);\n });\n\n api.modifyBundlerChain(async (chain) => {\n chain.plugin(PLUGIN_NAME).use(ModuleFederationPlugin, [\n {\n name:
|
|
1
|
+
{"version":3,"file":"preset.js","names":[],"sources":["../src/utils/correctImportPath.ts","../src/utils/with-module-federation-enhanced-rsbuild.ts","../preset.ts"],"sourcesContent":["import path from 'node:path';\n\nexport const correctImportPath = (context: string, entryFile: string) => {\n if (typeof process !== 'undefined') {\n if (process?.platform !== 'win32') {\n return entryFile;\n }\n\n if (entryFile.match(/^\\.?\\.\\\\/) || !entryFile.match(/^[A-Z]:\\\\\\\\/i)) {\n return entryFile.replace(/\\\\/g, '/');\n }\n\n const joint = path.win32.relative(context, entryFile);\n const relative = joint.replace(/\\\\/g, '/');\n\n if (relative.includes('node_modules/')) {\n return relative.split('node_modules/')[1];\n }\n\n return `./${relative}`;\n }\n return null;\n};\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';\nimport { TEMP_DIR } from '@module-federation/sdk';\n\nimport { correctImportPath } from './correctImportPath.js';\n\nimport type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\n\ntype StorybookRsbuildOptions =\n moduleFederationPlugin.ModuleFederationPluginOptions &\n Record<string, unknown>;\n\n// Storybook passes its full `Options` object (configDir, configType, presets,\n// presetsList, cache, features, packageJson, port, ...) as the second argument\n// to the `rsbuildFinal` hook. The enhanced `ModuleFederationPlugin` schema is\n// strict (`additionalProperties: false`) and rejects any unknown key, so we\n// must keep only valid Module Federation options and drop Storybook metadata.\n// An allowlist is used (rather than stripping known Storybook keys) so the\n// addon stays robust as Storybook adds new metadata fields.\nconst MODULE_FEDERATION_OPTION_KEYS = [\n 'async',\n 'bridge',\n 'dev',\n 'dts',\n 'experiments',\n 'exposes',\n 'filename',\n 'getPublicPath',\n 'implementation',\n 'injectTreeShakingUsedExports',\n 'library',\n 'manifest',\n 'name',\n 'remoteType',\n 'remotes',\n 'runtime',\n 'runtimePlugins',\n 'shareScope',\n 'shareStrategy',\n 'shared',\n 'treeShakingDir',\n 'treeShakingSharedExcludePlugins',\n 'treeShakingSharedPlugins',\n 'virtualRuntimeEntry',\n] as const satisfies ReadonlyArray<\n keyof moduleFederationPlugin.ModuleFederationPluginOptions\n>;\n\nconst getModuleFederationOptions = (\n options: StorybookRsbuildOptions,\n): moduleFederationPlugin.ModuleFederationPluginOptions => {\n const moduleFederationOptions: moduleFederationPlugin.ModuleFederationPluginOptions =\n {};\n\n for (const key of MODULE_FEDERATION_OPTION_KEYS) {\n if (options[key] !== undefined) {\n (moduleFederationOptions as Record<string, unknown>)[key] = options[key];\n }\n }\n\n return moduleFederationOptions;\n};\n\nconst tempDirPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);\nexport const PLUGIN_NAME = 'module-federation-storybook-addon';\n// add bootstrap for host project\nconst bootstrapPath = path.resolve(\n process.cwd(),\n `node_modules/${TEMP_DIR}/storybook-bootstrap.js`,\n);\nconst generateBootstrap = (context: string, entryPath: string) => {\n return `import('${correctImportPath(context, entryPath)}');`;\n};\nconst writeBootstrap = (context: string, entryPath: string) => {\n if (!fs.existsSync(tempDirPath)) {\n fs.mkdirSync(tempDirPath);\n }\n\n if (fs.existsSync(bootstrapPath)) {\n fs.unlinkSync(bootstrapPath);\n }\n fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));\n};\nexport const withModuleFederation = (\n rsbuildConfig: RsbuildConfig,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n) => {\n const moduleFederationOptions = getModuleFederationOptions(\n options as StorybookRsbuildOptions,\n );\n\n rsbuildConfig.plugins ??= [];\n rsbuildConfig.source ??= {};\n rsbuildConfig.source.entry ??= {};\n const entry = rsbuildConfig.source.entry;\n const context = rsbuildConfig.root || process.cwd();\n for (const entryName in entry) {\n if (Array.isArray(entry[entryName])) {\n writeBootstrap(context, entry[entryName][0]);\n entry[entryName] = [bootstrapPath];\n }\n }\n\n const rsbuildPlugin: RsbuildPlugin = {\n name: 'module-federation-storybook-plugin',\n setup: function (api) {\n api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {\n const mfConfig: RsbuildConfig = {\n dev: {\n // remoteEntry already includes one hmr runtime, and an additional one is not necessary.\n hmr: false,\n },\n };\n return mergeRsbuildConfig(config, mfConfig);\n });\n\n api.modifyBundlerChain(async (chain) => {\n chain.plugin(PLUGIN_NAME).use(ModuleFederationPlugin, [\n {\n ...moduleFederationOptions,\n name: moduleFederationOptions.name || PLUGIN_NAME,\n shared: {\n react: {\n singleton: true,\n },\n 'react-dom': {\n singleton: true,\n },\n ...moduleFederationOptions.shared,\n },\n remotes: {\n ...moduleFederationOptions.remotes,\n },\n shareStrategy: moduleFederationOptions.shareStrategy,\n },\n ]);\n });\n },\n };\n\n rsbuildConfig.plugins.push(rsbuildPlugin);\n return rsbuildConfig;\n};\n\nexport default withModuleFederation;\n","import { withModuleFederation } from './src/utils/with-module-federation-enhanced-rsbuild.js';\n\nimport type { RsbuildConfig } from '@rsbuild/core';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\n\nexport default {\n rsbuildFinal: (\n config: RsbuildConfig,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n ) => {\n return withModuleFederation(config, options);\n },\n};\nexport { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild.js';\n"],"mappings":";;;;;;AAEA,MAAa,qBAAqB,SAAiB,cAAsB;AACvE,KAAI,OAAO,YAAY,aAAa;AAClC,MAAI,SAAS,aAAa,QACxB,QAAO;AAGT,MAAI,UAAU,MAAM,WAAW,IAAI,CAAC,UAAU,MAAM,eAAe,CACjE,QAAO,UAAU,QAAQ,OAAO,IAAI;EAItC,MAAM,WADQ,KAAK,MAAM,SAAS,SAAS,UAAU,CAC9B,QAAQ,OAAO,IAAI;AAE1C,MAAI,SAAS,SAAS,gBAAgB,CACpC,QAAO,SAAS,MAAM,gBAAgB,CAAC;AAGzC,SAAO,KAAK;;AAEd,QAAO;;;;;ACAT,MAAM,gCAAgC;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAID,MAAM,8BACJ,YACyD;CACzD,MAAM,0BACJ,EAAE;AAEJ,MAAK,MAAM,OAAO,8BAChB,KAAI,QAAQ,SAAS,OACnB,CAAC,wBAAoD,OAAO,Q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AAG,wBAAwB,SAC5B;KACD,eAAe,wBAAwB;KACxC,CACF,CAAC;KACF;;EAEL,CAEwC;AACzC,QAAO;;;;;AC1IT,qBAAe,EACb,eACE,QACA,YACG;AACH,QAAO,qBAAqB,QAAQ,QAAQ;GAE/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/storybook-addon",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.13",
|
|
4
4
|
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@module-federation/enhanced": "2.5.
|
|
53
|
-
"@module-federation/sdk": "2.5.
|
|
52
|
+
"@module-federation/enhanced": "2.5.1",
|
|
53
|
+
"@module-federation/sdk": "2.5.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@nx/module-federation": ">= 16.0.0",
|
|
@@ -60,16 +60,16 @@
|
|
|
60
60
|
"@storybook/core": "^8.4.6",
|
|
61
61
|
"webpack": "5.104.1",
|
|
62
62
|
"webpack-virtual-modules": "0.6.2",
|
|
63
|
-
"@module-federation/utilities": "3.1.
|
|
63
|
+
"@module-federation/utilities": "3.1.96"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@rsbuild/core": "^1.0.1 || ^2.0.0-0",
|
|
67
|
-
"@module-federation/sdk": "^2.5.
|
|
67
|
+
"@module-federation/sdk": "^2.5.1",
|
|
68
68
|
"@nx/react": ">= 16.0.0",
|
|
69
69
|
"@nx/webpack": ">= 16.0.0",
|
|
70
70
|
"@nx/module-federation": ">= 16.0.0",
|
|
71
71
|
"@storybook/core": ">= 8.2.0",
|
|
72
|
-
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^8.0.0",
|
|
72
|
+
"@storybook/node-logger": "^6.5.16 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
73
73
|
"storybook": ">= 8.2.0",
|
|
74
74
|
"webpack": "^5.75.0",
|
|
75
75
|
"webpack-virtual-modules": "0.6.2"
|