@module-federation/storybook-addon 0.0.0-feat-node-support-1702930274548

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/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@module-federation/storybook-addon",
3
+ "version": "0.0.0-feat-node-support-1702930274548",
4
+ "description": "Storybook addon to consume remote module federated apps/components",
5
+ "license": "MIT",
6
+ "repository": "https://github.com/module-federation/universe/tree/main/packages/storybook-addon",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "keywords": [
11
+ "module-federation",
12
+ "typescript",
13
+ "storybook",
14
+ "addon"
15
+ ],
16
+ "author": "Fiodorov Andrei <hello@fyodorovandrei.com> (https://github.com/fyodorovandrei)",
17
+ "devDependencies": {
18
+ "@storybook/core-common": "7.4.6",
19
+ "@storybook/node-logger": "7.4.6",
20
+ "webpack": "5.88.2",
21
+ "webpack-virtual-modules": "0.6.1",
22
+ "@module-federation/utilities": "3.0.0",
23
+ "@nx/react": "^17.1.3",
24
+ "@nx/webpack": "^17.1.3"
25
+ },
26
+ "peerDependencies": {
27
+ "@storybook/core-common": "^6.5.16 || ^7.0.0",
28
+ "@storybook/node-logger": "^6.5.16 || ^7.0.0",
29
+ "webpack": "^5.75.0",
30
+ "webpack-virtual-modules": "^0.5.0 || ^0.6.0",
31
+ "@module-federation/utilities": "3.0.0",
32
+ "@nx/react": "~16.0.0 || ~17.0.0",
33
+ "@nx/webpack": "~16.0.0 || ~17.0.0"
34
+ },
35
+ "main": "./src/index.js",
36
+ "type": "commonjs"
37
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/storybook-addon';
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
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);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/storybook-addon/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
@@ -0,0 +1,17 @@
1
+ import { Configuration } from 'webpack';
2
+ import { ModuleFederationPluginOptions } from '@module-federation/utilities';
3
+ import { ModuleFederationConfig } from '@nx/webpack';
4
+ import withModuleFederation from '../utils/with-module-federation';
5
+ export type Preset = string | {
6
+ name: string;
7
+ };
8
+ type Options = {
9
+ moduleFederationConfig?: ModuleFederationPluginOptions;
10
+ nxModuleFederationConfig?: ModuleFederationConfig;
11
+ presets: {
12
+ apply<T>(preset: Preset): Promise<T>;
13
+ };
14
+ configDir: string;
15
+ };
16
+ export { withModuleFederation };
17
+ export declare const webpack: (webpackConfig: Configuration, options: Options) => Promise<Configuration>;
@@ -0,0 +1,145 @@
1
+ "use strict";
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 __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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.webpack = exports.withModuleFederation = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = require("path");
32
+ const process = __importStar(require("process"));
33
+ const webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
34
+ const webpack_1 = require("webpack");
35
+ const node_logger_1 = require("@storybook/node-logger");
36
+ const core_common_1 = require("@storybook/core-common");
37
+ const with_module_federation_1 = __importDefault(require("../utils/with-module-federation"));
38
+ exports.withModuleFederation = with_module_federation_1.default;
39
+ const correctImportPath_1 = require("../utils/correctImportPath");
40
+ const { ModuleFederationPlugin } = webpack_1.container;
41
+ const webpack = async (webpackConfig, options) => {
42
+ const { plugins = [], context: webpackContext } = webpackConfig;
43
+ const { moduleFederationConfig, presets, nxModuleFederationConfig } = options;
44
+ const context = webpackContext || process.cwd();
45
+ // Detect webpack version. More about storybook webpack config https://storybook.js.org/docs/react/addons/writing-presets#webpack
46
+ const webpackVersion = await presets.apply('webpackVersion');
47
+ node_logger_1.logger.info(`=> [MF] Webpack ${webpackVersion} version detected`);
48
+ if (webpackVersion !== '5') {
49
+ throw new Error('Webpack 5 required: Configure Storybook to use the webpack5 builder');
50
+ }
51
+ if (nxModuleFederationConfig) {
52
+ node_logger_1.logger.info(`=> [MF] Detect NX configuration`);
53
+ const wmf = await (0, with_module_federation_1.default)(nxModuleFederationConfig);
54
+ webpackConfig = {
55
+ ...webpackConfig,
56
+ ...wmf(webpackConfig),
57
+ };
58
+ }
59
+ if (moduleFederationConfig) {
60
+ node_logger_1.logger.info(`=> [MF] Push Module Federation plugin`);
61
+ plugins.push(new ModuleFederationPlugin(moduleFederationConfig));
62
+ }
63
+ const entries = await presets.apply('entries');
64
+ const bootstrap = entries.map((entryFile) => `import '${(0, correctImportPath_1.correctImportPath)(context, entryFile)}';`);
65
+ const index = plugins.findIndex(
66
+ //@ts-ignore
67
+ (plugin) => plugin.constructor.name === 'VirtualModulesPlugin');
68
+ if (index !== -1) {
69
+ node_logger_1.logger.info(`=> [MF] Detected plugin VirtualModulesPlugin`);
70
+ /* eslint-disable @typescript-eslint/no-explicit-any */
71
+ const plugin = plugins[index];
72
+ 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?
73
+ const virtualEntriesPaths = Object.keys(virtualEntries);
74
+ node_logger_1.logger.info(`=> [MF] Write files from VirtualModulesPlugin`);
75
+ for (const virtualEntryPath of virtualEntriesPaths) {
76
+ const nodeModulesPath = '/node_modules/';
77
+ const filePathFromProjectRootDir = virtualEntryPath.replace(context, '');
78
+ let sourceCode = virtualEntries[virtualEntryPath];
79
+ let finalPath = virtualEntryPath;
80
+ let finalDir = (0, path_1.dirname)(virtualEntryPath);
81
+ // If virtual file is not in directory node_modules, move file in directory node_modules/.cache/storybook
82
+ if (!filePathFromProjectRootDir.startsWith(nodeModulesPath)) {
83
+ finalPath = (0, path_1.join)(context, nodeModulesPath, '.cache', 'storybook', filePathFromProjectRootDir);
84
+ finalDir = (0, path_1.dirname)(finalPath);
85
+ // Fix storybook stories' path in virtual module
86
+ if (
87
+ // For storybook version before 7
88
+ filePathFromProjectRootDir === '/generated-stories-entry.cjs' ||
89
+ // For storybook version 7
90
+ filePathFromProjectRootDir === '/storybook-stories.js') {
91
+ const isStorybookVersion7 = filePathFromProjectRootDir === '/storybook-stories.js';
92
+ const nonNormalizedStories = await presets.apply('stories');
93
+ const stories = (0, core_common_1.normalizeStories)(nonNormalizedStories, {
94
+ configDir: options.configDir,
95
+ workingDir: context,
96
+ });
97
+ // For each story fix the import path
98
+ stories.forEach((story) => {
99
+ // Go up 3 times because the file was moved in /node_modules/.cache/storybook
100
+ const newDirectory = (0, path_1.join)('..', '..', '..', story.directory);
101
+ // Adding trailing slash for story directory in storybook v7
102
+ const oldSrc = isStorybookVersion7
103
+ ? `'${story.directory}/'`
104
+ : `'${story.directory}'`;
105
+ const newSrc = isStorybookVersion7
106
+ ? `'${newDirectory}/'`
107
+ : `'${newDirectory}'`;
108
+ // Fix story directory
109
+ sourceCode = sourceCode.replace(oldSrc, newSrc);
110
+ });
111
+ }
112
+ }
113
+ if (!fs_1.default.existsSync(finalDir)) {
114
+ fs_1.default.mkdirSync(finalDir, { recursive: true });
115
+ }
116
+ fs_1.default.writeFileSync(finalPath, sourceCode);
117
+ bootstrap.push(`import '${(0, correctImportPath_1.correctImportPath)(context, finalPath)}';`);
118
+ }
119
+ }
120
+ /**
121
+ * Create a new VirtualModulesPlugin plugin to fix error "Shared module is not available for eager consumption"
122
+ * Entry file content is moved in bootstrap file. More details in the webpack documentation:
123
+ * https://webpack.js.org/concepts/module-federation/#uncaught-error-shared-module-is-not-available-for-eager-consumption
124
+ * */
125
+ const virtualModulePlugin = new webpack_virtual_modules_1.default({
126
+ './__entry.js': `import('./__bootstrap.js');`,
127
+ './__bootstrap.js': bootstrap.join('\n'),
128
+ });
129
+ let action = 'Push';
130
+ if (index === -1) {
131
+ plugins.push(virtualModulePlugin);
132
+ }
133
+ else {
134
+ plugins[index] = virtualModulePlugin;
135
+ action = 'Replace';
136
+ }
137
+ node_logger_1.logger.info(`=> [MF] ${action} plugin VirtualModulesPlugin to bootstrap entry point`);
138
+ return {
139
+ ...webpackConfig,
140
+ entry: ['./__entry.js'],
141
+ plugins,
142
+ };
143
+ };
144
+ exports.webpack = webpack;
145
+ //# sourceMappingURL=storybook-addon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storybook-addon.js","sourceRoot":"","sources":["../../../../../packages/storybook-addon/src/lib/storybook-addon.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,+BAAqC;AACrC,iDAAmC;AACnC,sFAA2D;AAC3D,qCAAmD;AACnD,wDAAgD;AAChD,wDAA0D;AAI1D,6FAAmE;AAgB1D,+BAhBF,gCAAoB,CAgBE;AAf7B,kEAA+D;AAE/D,MAAM,EAAE,sBAAsB,EAAE,GAAG,mBAAS,CAAC;AAetC,MAAM,OAAO,GAAG,KAAK,EAC1B,aAA4B,EAC5B,OAAgB,EACQ,EAAE;IAC1B,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC;IAChE,MAAM,EAAE,sBAAsB,EAAE,OAAO,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;IAC9E,MAAM,OAAO,GAAG,cAAc,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEhD,iIAAiI;IACjI,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC7D,oBAAM,CAAC,IAAI,CAAC,mBAAmB,cAAc,mBAAmB,CAAC,CAAC;IAElE,IAAI,cAAc,KAAK,GAAG,EAAE;QAC1B,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;KACH;IAED,IAAI,wBAAwB,EAAE;QAC5B,oBAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;QAE/C,MAAM,GAAG,GAAG,MAAM,IAAA,gCAAoB,EAAC,wBAAwB,CAAC,CAAC;QAEjE,aAAa,GAAG;YACd,GAAG,aAAa;YAChB,GAAG,GAAG,CAAC,aAAa,CAAC;SACtB,CAAC;KACH;IAED,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U,CAAC,QAAQ,CAAC,EAAE;gBAC5B,YAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;aAC7C;YAED,YAAE,CAAC,aAAa,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YACxC,SAAS,CAAC,IAAI,CAAC,WAAW,IAAA,qCAAiB,EAAC,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SACtE;KACF;IAED;;;;SAIK;IACL,MAAM,mBAAmB,GAAG,IAAI,iCAAoB,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;QAChB,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;KACnC;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,GAAG,mBAAmB,CAAC;QACrC,MAAM,GAAG,SAAS,CAAC;KACpB;IACD,oBAAM,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;AA5IW,QAAA,OAAO,WA4IlB"}
@@ -0,0 +1 @@
1
+ export declare const correctImportPath: (context: string, entryFile: string) => any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.correctImportPath = void 0;
4
+ const correctImportPath = (context, entryFile) => {
5
+ if (typeof process !== 'undefined') {
6
+ if (process?.platform !== 'win32') {
7
+ return entryFile;
8
+ }
9
+ if (entryFile.match(/^\.?\.\\/) || !entryFile.match(/^[A-Z]:\\\\/i)) {
10
+ return entryFile.replace(/\\/g, '/');
11
+ }
12
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
13
+ const path = require('path');
14
+ const joint = path.win32.relative(context, entryFile);
15
+ const relative = joint.replace(/\\/g, '/');
16
+ if (relative.includes('node_modules/')) {
17
+ return relative.split('node_modules/')[1];
18
+ }
19
+ return `./${relative}`;
20
+ }
21
+ return null;
22
+ };
23
+ exports.correctImportPath = correctImportPath;
24
+ //# sourceMappingURL=correctImportPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correctImportPath.js","sourceRoot":"","sources":["../../../../../packages/storybook-addon/src/utils/correctImportPath.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;IACtE,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;QAClC,IAAI,OAAO,EAAE,QAAQ,KAAK,OAAO,EAAE;YACjC,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE;YACnE,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SACtC;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;YACtC,OAAO,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C;QAED,OAAO,KAAK,QAAQ,EAAE,CAAC;KACxB;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAtBW,QAAA,iBAAiB,qBAsB5B"}
@@ -0,0 +1,4 @@
1
+ import { Configuration } from 'webpack';
2
+ import { ModuleFederationConfig } from '@nx/webpack';
3
+ declare const withModuleFederation: (options: ModuleFederationConfig) => Promise<(config: Configuration) => Configuration>;
4
+ export default withModuleFederation;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@nx/react/src/module-federation/utils");
4
+ const webpack_1 = require("webpack");
5
+ const { ModuleFederationPlugin } = webpack_1.container;
6
+ const updateMappedRemotes = (remotes) => {
7
+ const newRemotes = {};
8
+ Object.keys(remotes).forEach((key) => {
9
+ newRemotes[key] = `${key}@${remotes[key]}`;
10
+ });
11
+ return newRemotes;
12
+ };
13
+ const withModuleFederation = async (options) => {
14
+ const { mappedRemotes, sharedDependencies } = await (0, utils_1.getModuleFederationConfig)(options);
15
+ return (config) => {
16
+ config.experiments = { outputModule: false };
17
+ config.optimization = {
18
+ runtimeChunk: false,
19
+ };
20
+ config.output = {
21
+ publicPath: 'auto',
22
+ };
23
+ config.plugins = config.plugins || [];
24
+ config.plugins.push(new ModuleFederationPlugin({
25
+ name: options.name,
26
+ filename: 'remoteEntry.js',
27
+ shared: sharedDependencies,
28
+ exposes: options.exposes,
29
+ remotes: updateMappedRemotes(mappedRemotes),
30
+ }));
31
+ return config;
32
+ };
33
+ };
34
+ exports.default = withModuleFederation;
35
+ //# sourceMappingURL=with-module-federation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-module-federation.js","sourceRoot":"","sources":["../../../../../packages/storybook-addon/src/utils/with-module-federation.ts"],"names":[],"mappings":";;AAAA,iEAAkF;AAClF,qCAAmD;AAInD,MAAM,EAAE,sBAAsB,EAAE,GAAG,mBAAS,CAAC;AAE7C,MAAM,mBAAmB,GAAG,CAAC,OAA+B,EAAE,EAAE;IAC9D,MAAM,UAAU,GAA2B,EAAE,CAAC;IAE9C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EA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