@module-federation/storybook-addon 4.0.35 → 5.0.0
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/package.json +5 -4
- package/dist/preset.d.ts +1 -1
- package/dist/preset.js +4 -8
- package/dist/preset.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -17
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/storybook-addon.d.ts +1 -1
- package/dist/src/lib/storybook-addon.js +30 -70
- package/dist/src/lib/storybook-addon.js.map +1 -1
- package/dist/src/utils/correctImportPath.js +1 -5
- package/dist/src/utils/correctImportPath.js.map +1 -1
- package/dist/src/utils/with-module-federation-enhanced-rsbuild.js +18 -25
- package/dist/src/utils/with-module-federation-enhanced-rsbuild.js.map +1 -1
- package/dist/src/utils/with-module-federation.js +5 -7
- package/dist/src/utils/with-module-federation.js.map +1 -1
- package/package.json +6 -6
package/dist/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/storybook-addon",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@rsbuild/core": "^1.0.1",
|
|
66
|
-
"@module-federation/sdk": "^0.21.
|
|
66
|
+
"@module-federation/sdk": "^0.21.5",
|
|
67
67
|
"@nx/react": ">= 16.0.0",
|
|
68
68
|
"@nx/webpack": ">= 16.0.0",
|
|
69
69
|
"@storybook/core": ">= 8.2.0",
|
|
@@ -96,5 +96,6 @@
|
|
|
96
96
|
"webpack-virtual-modules": {
|
|
97
97
|
"optional": true
|
|
98
98
|
}
|
|
99
|
-
}
|
|
99
|
+
},
|
|
100
|
+
"module": "./src/index.js"
|
|
100
101
|
}
|
package/dist/preset.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ declare const _default: {
|
|
|
4
4
|
rsbuildFinal: (config: RsbuildConfig, options: moduleFederationPlugin.ModuleFederationPluginOptions) => RsbuildConfig;
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
|
7
|
-
export { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild';
|
|
7
|
+
export { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
package/dist/preset.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.PLUGIN_NAME = void 0;
|
|
4
|
-
const with_module_federation_enhanced_rsbuild_1 = require("./src/utils/with-module-federation-enhanced-rsbuild");
|
|
5
|
-
exports.default = {
|
|
1
|
+
import { withModuleFederation } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
|
2
|
+
export default {
|
|
6
3
|
rsbuildFinal: (config, options) => {
|
|
7
4
|
const { remotes, shared, name, shareStrategy } = options;
|
|
8
|
-
return
|
|
5
|
+
return withModuleFederation(config, {
|
|
9
6
|
name,
|
|
10
7
|
remotes,
|
|
11
8
|
shared,
|
|
@@ -13,6 +10,5 @@ exports.default = {
|
|
|
13
10
|
});
|
|
14
11
|
},
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(exports, "PLUGIN_NAME", { enumerable: true, get: function () { return with_module_federation_enhanced_rsbuild_2.PLUGIN_NAME; } });
|
|
13
|
+
export { PLUGIN_NAME } from './src/utils/with-module-federation-enhanced-rsbuild.js';
|
|
18
14
|
//# sourceMappingURL=preset.js.map
|
package/dist/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../preset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preset.js","sourceRoot":"","sources":["../preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAK9F,eAAe;IACb,YAAY,EAAE,CACZ,MAAqB,EACrB,OAA6D,EAC7D,EAAE;QACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;QAEzD,OAAO,oBAAoB,CAAC,MAAM,EAAE;YAClC,IAAI;YACJ,OAAO;YACP,MAAM;YACN,aAAa;SACd,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AACF,OAAO,EAAE,WAAW,EAAE,MAAM,wDAAwD,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './lib/storybook-addon';
|
|
1
|
+
export * from './lib/storybook-addon.js';
|
package/dist/src/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./lib/storybook-addon"), exports);
|
|
1
|
+
export * from './lib/storybook-addon.js';
|
|
18
2
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Configuration } from 'webpack';
|
|
2
|
-
import withModuleFederation from '../utils/with-module-federation';
|
|
2
|
+
import withModuleFederation from '../utils/with-module-federation.js';
|
|
3
3
|
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
4
4
|
import type { ModuleFederationConfig } from '@nx/webpack';
|
|
5
5
|
export type Preset = string | {
|
|
@@ -1,95 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.webpack = exports.withModuleFederation = void 0;
|
|
40
|
-
const fs_1 = __importDefault(require("fs"));
|
|
41
|
-
const path_1 = require("path");
|
|
42
|
-
const process = __importStar(require("process"));
|
|
43
|
-
const webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
|
|
44
|
-
const webpack_1 = require("webpack");
|
|
45
|
-
const node_logger_1 = require("@storybook/node-logger");
|
|
46
|
-
const common_1 = require("@storybook/core/common");
|
|
47
|
-
const with_module_federation_1 = __importDefault(require("../utils/with-module-federation"));
|
|
48
|
-
exports.withModuleFederation = with_module_federation_1.default;
|
|
49
|
-
const correctImportPath_1 = require("../utils/correctImportPath");
|
|
50
|
-
const { ModuleFederationPlugin } = webpack_1.container;
|
|
51
|
-
const webpack = async (webpackConfig, options) => {
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import * as process from 'process';
|
|
4
|
+
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
5
|
+
import { container, } from 'webpack';
|
|
6
|
+
import { logger } from '@storybook/node-logger';
|
|
7
|
+
import { normalizeStories } from '@storybook/core/common';
|
|
8
|
+
import withModuleFederation from '../utils/with-module-federation.js';
|
|
9
|
+
import { correctImportPath } from '../utils/correctImportPath.js';
|
|
10
|
+
const { ModuleFederationPlugin } = container;
|
|
11
|
+
export { withModuleFederation };
|
|
12
|
+
export const webpack = async (webpackConfig, options) => {
|
|
52
13
|
const { plugins = [], context: webpackContext } = webpackConfig;
|
|
53
14
|
const { moduleFederationConfig, presets, nxModuleFederationConfig } = options;
|
|
54
15
|
const context = webpackContext || process.cwd();
|
|
55
16
|
// Detect webpack version. More about storybook webpack config https://storybook.js.org/docs/react/addons/writing-presets#webpack
|
|
56
17
|
const webpackVersion = await presets.apply('webpackVersion');
|
|
57
|
-
|
|
18
|
+
logger.info(`=> [MF] Webpack ${webpackVersion} version detected`);
|
|
58
19
|
if (webpackVersion !== '5') {
|
|
59
20
|
throw new Error('Webpack 5 required: Configure Storybook to use the webpack5 builder');
|
|
60
21
|
}
|
|
61
22
|
if (nxModuleFederationConfig) {
|
|
62
|
-
|
|
63
|
-
const wmf = await (
|
|
23
|
+
logger.info(`=> [MF] Detect NX configuration`);
|
|
24
|
+
const wmf = await withModuleFederation(nxModuleFederationConfig);
|
|
64
25
|
webpackConfig = {
|
|
65
26
|
...webpackConfig,
|
|
66
27
|
...wmf(webpackConfig),
|
|
67
28
|
};
|
|
68
29
|
}
|
|
69
30
|
if (moduleFederationConfig) {
|
|
70
|
-
|
|
31
|
+
logger.info(`=> [MF] Push Module Federation plugin`);
|
|
71
32
|
// @ts-ignore enhanced add new remoteType 'module-import'
|
|
72
33
|
plugins.push(new ModuleFederationPlugin(moduleFederationConfig));
|
|
73
34
|
}
|
|
74
35
|
const entries = await presets.apply('entries');
|
|
75
|
-
const bootstrap = entries.map((entryFile) => `import '${
|
|
36
|
+
const bootstrap = entries.map((entryFile) => `import '${correctImportPath(context, entryFile)}';`);
|
|
76
37
|
const index = plugins.findIndex((plugin) => plugin?.constructor.name === 'VirtualModulesPlugin');
|
|
77
38
|
if (index !== -1) {
|
|
78
|
-
|
|
39
|
+
logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`);
|
|
79
40
|
const plugin = plugins[index];
|
|
80
41
|
const virtualEntries = plugin.getModuleList('static');
|
|
81
42
|
const virtualEntriesPaths = Object.keys(virtualEntries);
|
|
82
|
-
|
|
43
|
+
logger.info(`=> [MF] Write files from VirtualModulesPlugin`);
|
|
83
44
|
for (const virtualEntryPath of virtualEntriesPaths) {
|
|
84
45
|
const nodeModulesPath = '/node_modules/';
|
|
85
46
|
const filePathFromProjectRootDir = virtualEntryPath.replace(context, '');
|
|
86
47
|
let sourceCode = virtualEntries[virtualEntryPath];
|
|
87
48
|
let finalPath = virtualEntryPath;
|
|
88
|
-
let finalDir =
|
|
49
|
+
let finalDir = dirname(virtualEntryPath);
|
|
89
50
|
// If virtual file is not in directory node_modules, move file in directory node_modules/.cache/storybook
|
|
90
51
|
if (!filePathFromProjectRootDir.startsWith(nodeModulesPath)) {
|
|
91
|
-
finalPath =
|
|
92
|
-
finalDir =
|
|
52
|
+
finalPath = join(context, nodeModulesPath, '.cache', 'storybook', filePathFromProjectRootDir);
|
|
53
|
+
finalDir = dirname(finalPath);
|
|
93
54
|
// Fix storybook stories' path in virtual module
|
|
94
55
|
if (
|
|
95
56
|
// For storybook version before 7
|
|
@@ -98,14 +59,14 @@ const webpack = async (webpackConfig, options) => {
|
|
|
98
59
|
filePathFromProjectRootDir === '/storybook-stories.js') {
|
|
99
60
|
const isStorybookVersion7 = filePathFromProjectRootDir === '/storybook-stories.js';
|
|
100
61
|
const nonNormalizedStories = await presets.apply('stories');
|
|
101
|
-
const stories =
|
|
62
|
+
const stories = normalizeStories(nonNormalizedStories, {
|
|
102
63
|
configDir: options.configDir,
|
|
103
64
|
workingDir: context,
|
|
104
65
|
});
|
|
105
66
|
// For each story fix the import path
|
|
106
67
|
stories.forEach((story) => {
|
|
107
68
|
// Go up 3 times because the file was moved in /node_modules/.cache/storybook
|
|
108
|
-
const newDirectory =
|
|
69
|
+
const newDirectory = join('..', '..', '..', story.directory);
|
|
109
70
|
// Adding trailing slash for story directory in storybook v7
|
|
110
71
|
const oldSrc = isStorybookVersion7
|
|
111
72
|
? `'${story.directory}/'`
|
|
@@ -118,11 +79,11 @@ const webpack = async (webpackConfig, options) => {
|
|
|
118
79
|
});
|
|
119
80
|
}
|
|
120
81
|
}
|
|
121
|
-
if (!
|
|
122
|
-
|
|
82
|
+
if (!fs.existsSync(finalDir)) {
|
|
83
|
+
fs.mkdirSync(finalDir, { recursive: true });
|
|
123
84
|
}
|
|
124
|
-
|
|
125
|
-
bootstrap.push(`import '${
|
|
85
|
+
fs.writeFileSync(finalPath, sourceCode);
|
|
86
|
+
bootstrap.push(`import '${correctImportPath(context, finalPath)}';`);
|
|
126
87
|
}
|
|
127
88
|
}
|
|
128
89
|
/**
|
|
@@ -130,7 +91,7 @@ const webpack = async (webpackConfig, options) => {
|
|
|
130
91
|
* Entry file content is moved in bootstrap file. More details in the webpack documentation:
|
|
131
92
|
* https://webpack.js.org/concepts/module-federation/#uncaught-error-shared-module-is-not-available-for-eager-consumption
|
|
132
93
|
* */
|
|
133
|
-
const virtualModulePlugin = new
|
|
94
|
+
const virtualModulePlugin = new VirtualModulesPlugin({
|
|
134
95
|
'./__entry.js': `import('./__bootstrap.js');`,
|
|
135
96
|
'./__bootstrap.js': bootstrap.join('\n'),
|
|
136
97
|
});
|
|
@@ -142,12 +103,11 @@ const webpack = async (webpackConfig, options) => {
|
|
|
142
103
|
plugins[index] = virtualModulePlugin;
|
|
143
104
|
action = 'Replace';
|
|
144
105
|
}
|
|
145
|
-
|
|
106
|
+
logger.info(`=> [MF] ${action} plugin VirtualModulesPlugin to bootstrap entry point`);
|
|
146
107
|
return {
|
|
147
108
|
...webpackConfig,
|
|
148
109
|
entry: ['./__entry.js'],
|
|
149
110
|
plugins,
|
|
150
111
|
};
|
|
151
112
|
};
|
|
152
|
-
exports.webpack = webpack;
|
|
153
113
|
//# sourceMappingURL=storybook-addon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storybook-addon.js","sourceRoot":"","sources":["../../../src/lib/storybook-addon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storybook-addon.js","sourceRoot":"","sources":["../../../src/lib/storybook-addon.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,C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AC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,CAAC;YAED,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACxC,SAAS,CAAC,IAAI,CAAC,WAAW,iBAAiB,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED;;;;SAIK;IACL,MAAM,mBAAmB,GAAG,IAAI,oBAAoB,CAAC;QACnD,cAAc,EAAE,6BAA6B;QAC7C,kBAAkB,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;KACzC,CAAC,CAAC;IAEH,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,mBAAuD,CAAC,CAAC;IACxE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,GAAG,mBAAuD,CAAC;QACzE,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,CAAC,IAAI,CACT,WAAW,MAAM,uDAAuD,CACzE,CAAC;IAEF,OAAO;QACL,GAAG,aAAa;QAChB,KAAK,EAAE,CAAC,cAAc,CAAC;QACvB,OAAO;KACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.correctImportPath = void 0;
|
|
4
|
-
const correctImportPath = (context, entryFile) => {
|
|
1
|
+
export const correctImportPath = (context, entryFile) => {
|
|
5
2
|
if (typeof process !== 'undefined') {
|
|
6
3
|
if (process?.platform !== 'win32') {
|
|
7
4
|
return entryFile;
|
|
@@ -20,5 +17,4 @@ const correctImportPath = (context, entryFile) => {
|
|
|
20
17
|
}
|
|
21
18
|
return null;
|
|
22
19
|
};
|
|
23
|
-
exports.correctImportPath = correctImportPath;
|
|
24
20
|
//# sourceMappingURL=correctImportPath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correctImportPath.js","sourceRoot":"","sources":["../../../src/utils/correctImportPath.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"correctImportPath.js","sourceRoot":"","sources":["../../../src/utils/correctImportPath.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;IACtE,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,IAAI,OAAO,EAAE,QAAQ,KAAK,OAAO,EAAE,CAAC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;YACpE,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACvC,CAAC;QAED,8DAA8D;QAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE3C,IAAI,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,KAAK,QAAQ,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const rspack_1 = require("@module-federation/enhanced/rspack");
|
|
10
|
-
const sdk_1 = require("@module-federation/sdk");
|
|
11
|
-
const correctImportPath_1 = require("./correctImportPath");
|
|
12
|
-
const tempDirPath = node_path_1.default.resolve(process.cwd(), `node_modules/${sdk_1.TEMP_DIR}`);
|
|
13
|
-
exports.PLUGIN_NAME = 'module-federation-storybook-addon';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
+
import { TEMP_DIR } from '@module-federation/sdk';
|
|
5
|
+
import { correctImportPath } from './correctImportPath.js';
|
|
6
|
+
const tempDirPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);
|
|
7
|
+
export const PLUGIN_NAME = 'module-federation-storybook-addon';
|
|
14
8
|
// add bootstrap for host project
|
|
15
|
-
const bootstrapPath =
|
|
9
|
+
const bootstrapPath = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}/storybook-bootstrap.js`);
|
|
16
10
|
const generateBootstrap = (context, entryPath) => {
|
|
17
|
-
return `import('${
|
|
11
|
+
return `import('${correctImportPath(context, entryPath)}');`;
|
|
18
12
|
};
|
|
19
13
|
const writeBootstrap = (context, entryPath) => {
|
|
20
|
-
if (!
|
|
21
|
-
|
|
14
|
+
if (!fs.existsSync(tempDirPath)) {
|
|
15
|
+
fs.mkdirSync(tempDirPath);
|
|
22
16
|
}
|
|
23
|
-
if (
|
|
24
|
-
|
|
17
|
+
if (fs.existsSync(bootstrapPath)) {
|
|
18
|
+
fs.unlinkSync(bootstrapPath);
|
|
25
19
|
}
|
|
26
|
-
|
|
20
|
+
fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));
|
|
27
21
|
};
|
|
28
|
-
const withModuleFederation = (rsbuildConfig, options) => {
|
|
22
|
+
export const withModuleFederation = (rsbuildConfig, options) => {
|
|
29
23
|
rsbuildConfig.plugins ??= [];
|
|
30
24
|
rsbuildConfig.source ??= {};
|
|
31
25
|
rsbuildConfig.source.entry ??= {};
|
|
@@ -50,9 +44,9 @@ const withModuleFederation = (rsbuildConfig, options) => {
|
|
|
50
44
|
return mergeRsbuildConfig(config, mfConfig);
|
|
51
45
|
});
|
|
52
46
|
api.modifyBundlerChain(async (chain) => {
|
|
53
|
-
chain.plugin(
|
|
47
|
+
chain.plugin(PLUGIN_NAME).use(ModuleFederationPlugin, [
|
|
54
48
|
{
|
|
55
|
-
name: options.name ||
|
|
49
|
+
name: options.name || PLUGIN_NAME,
|
|
56
50
|
shared: {
|
|
57
51
|
react: {
|
|
58
52
|
singleton: true,
|
|
@@ -74,6 +68,5 @@ const withModuleFederation = (rsbuildConfig, options) => {
|
|
|
74
68
|
rsbuildConfig.plugins.push(rsbuildPlugin);
|
|
75
69
|
return rsbuildConfig;
|
|
76
70
|
};
|
|
77
|
-
|
|
78
|
-
exports.default = exports.withModuleFederation;
|
|
71
|
+
export default withModuleFederation;
|
|
79
72
|
//# sourceMappingURL=with-module-federation-enhanced-rsbuild.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-module-federation-enhanced-rsbuild.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation-enhanced-rsbuild.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"with-module-federation-enhanced-rsbuild.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation-enhanced-rsbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MA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,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const webpack_1 = require("webpack");
|
|
5
|
-
const { ModuleFederationPlugin } = webpack_1.container;
|
|
1
|
+
import { getModuleFederationConfig } from '@nx/module-federation/src/with-module-federation/webpack/utils';
|
|
2
|
+
import { container } from 'webpack';
|
|
3
|
+
const { ModuleFederationPlugin } = container;
|
|
6
4
|
const updateMappedRemotes = (remotes) => {
|
|
7
5
|
const newRemotes = {};
|
|
8
6
|
Object.keys(remotes).forEach((key) => {
|
|
@@ -11,7 +9,7 @@ const updateMappedRemotes = (remotes) => {
|
|
|
11
9
|
return newRemotes;
|
|
12
10
|
};
|
|
13
11
|
const withModuleFederation = async (options) => {
|
|
14
|
-
const { mappedRemotes, sharedDependencies } = await
|
|
12
|
+
const { mappedRemotes, sharedDependencies } = await getModuleFederationConfig(options);
|
|
15
13
|
return (config) => {
|
|
16
14
|
config.experiments = { outputModule: false };
|
|
17
15
|
config.optimization = {
|
|
@@ -31,5 +29,5 @@ const withModuleFederation = async (options) => {
|
|
|
31
29
|
return config;
|
|
32
30
|
};
|
|
33
31
|
};
|
|
34
|
-
|
|
32
|
+
export default withModuleFederation;
|
|
35
33
|
//# sourceMappingURL=with-module-federation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../src/utils/with-module-federation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAiB,MAAM,SAAS,CAAC;AAInD,MAAM,EAAE,sBAAsB,EAAE,GAAG,SAAS,CAAC;AAE7C,MAAM,mBAA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
+
"version": "5.0.0",
|
|
4
4
|
"description": "Storybook addon to consume remote module federated apps/components",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@module-federation/
|
|
53
|
-
"@module-federation/
|
|
52
|
+
"@module-federation/enhanced": "0.21.5",
|
|
53
|
+
"@module-federation/sdk": "0.21.5"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"jest-fixed-jsdom": "^0.0.9",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"@storybook/core": "^8.4.6",
|
|
60
60
|
"webpack": "5.94.0",
|
|
61
61
|
"webpack-virtual-modules": "0.6.2",
|
|
62
|
-
"@module-federation/utilities": "3.1.
|
|
62
|
+
"@module-federation/utilities": "3.1.76"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@rsbuild/core": "^1.0.1",
|
|
66
|
-
"@module-federation/sdk": "^0.21.
|
|
66
|
+
"@module-federation/sdk": "^0.21.5",
|
|
67
67
|
"@nx/react": ">= 16.0.0",
|
|
68
68
|
"@nx/webpack": ">= 16.0.0",
|
|
69
69
|
"@storybook/core": ">= 8.2.0",
|