@modern-js/storybook-builder 2.46.0 → 2.47.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/cjs/build.js CHANGED
@@ -35,7 +35,7 @@ __export(build_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(build_exports);
37
37
  var import_path = require("path");
38
- var import_webpack_dev_middleware = __toESM(require("@modern-js/builder-shared/webpack-dev-middleware"));
38
+ var import_webpack_dev_middleware = __toESM(require("@rsbuild/shared/webpack-dev-middleware"));
39
39
  var import_webpack_hot_middleware = __toESM(require("webpack-hot-middleware"));
40
40
  var import_serve_static = __toESM(require("serve-static"));
41
41
  var import_utils = require("@modern-js/utils");
package/dist/cjs/core.js CHANGED
@@ -21,7 +21,8 @@ __export(core_exports, {
21
21
  getCompiler: () => getCompiler
22
22
  });
23
23
  module.exports = __toCommonJS(core_exports);
24
- var import_builder = require("@modern-js/builder");
24
+ var import_uni_builder = require("@modern-js/uni-builder");
25
+ var import_shared = require("@rsbuild/shared");
25
26
  var import_core = require("@modern-js/core");
26
27
  var import_utils = require("./utils");
27
28
  var import_plugin_storybook = require("./plugin-storybook");
@@ -32,18 +33,14 @@ async function getCompiler(cwd, builderOptions, options) {
32
33
  const res = await (0, import_utils.runWithErrorMsg)(() => (0, import_core.loadConfig)(cwd, builderOptions.configPath || (0, import_utils.getConfigFileName)()), "Failed to load config");
33
34
  const loadedConfig = res ? res.config : {};
34
35
  const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
35
- const provider = await (0, import_utils.getProvider)(bundler, (0, import_builder.mergeBuilderConfig)(finalConfig, builderOptions.builderConfig) || {});
36
- if (!provider) {
37
- if (bundler) {
38
- throw new Error(`You choose to use ${bundler}, but @modern-js/builder-${bundler}-provider not found in your project, please install it`);
39
- } else {
40
- throw new Error(`Please install one provider first, try install @modern-js/builder-rspack-provider or @modern-js/builder-webpack-provider first`);
41
- }
42
- }
43
- const builder = await (0, import_builder.createBuilder)(provider, {
36
+ const uniBuilderConfig = builderOptions.builderConfig ? (0, import_shared.mergeRsbuildConfig)(finalConfig, builderOptions.builderConfig) : finalConfig || {};
37
+ const bundlerType = bundler || "webpack";
38
+ const builder = await (0, import_uni_builder.createUniBuilder)({
39
+ bundlerType,
44
40
  cwd,
45
41
  target: "web",
46
- framework: "modern.js storybook",
42
+ frameworkConfigPath: (res === null || res === void 0 ? void 0 : res.path) ? res.path : void 0,
43
+ config: bundlerType === "webpack" ? await (0, import_plugin_storybook.addonBabelAdapter)(uniBuilderConfig, options) : uniBuilderConfig,
47
44
  entry: {
48
45
  main: entries
49
46
  }
@@ -33,6 +33,7 @@ __export(docgen_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(docgen_exports);
35
35
  var import_utils = require("@modern-js/utils");
36
+ var import_shared = require("@rsbuild/shared");
36
37
  async function applyDocgenWebpack(chain, options) {
37
38
  const typescriptOptions = await options.presets.apply("typescript", {});
38
39
  const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions || {};
@@ -50,14 +51,14 @@ async function applyDocgenWebpack(chain, options) {
50
51
  } else if (reactDocgen === "react-docgen") {
51
52
  const loader = require.resolve("./loader");
52
53
  const resolveOptions = chain.toConfig().resolve;
53
- chain.module.rule(import_utils.CHAIN_ID.RULE.JS).use("react-docgen").loader(loader).options({
54
+ chain.module.rule(import_shared.CHAIN_ID.RULE.JS).use("react-docgen").loader(loader).options({
54
55
  resolveOptions
55
- }).after(import_utils.CHAIN_ID.USE.BABEL).after(import_utils.CHAIN_ID.USE.ESBUILD).after(import_utils.CHAIN_ID.USE.SWC).end();
56
- const tsRuls = chain.module.rule(import_utils.CHAIN_ID.RULE.TS);
56
+ }).after(import_shared.CHAIN_ID.USE.BABEL).after(import_shared.CHAIN_ID.USE.ESBUILD).after(import_shared.CHAIN_ID.USE.SWC).end();
57
+ const tsRuls = chain.module.rule(import_shared.CHAIN_ID.RULE.TS);
57
58
  if (tsRuls.uses.values().length !== 0) {
58
59
  tsRuls.use("react-docgen").loader(loader).options({
59
60
  resolveOptions
60
- }).after(import_utils.CHAIN_ID.USE.TS).after(import_utils.CHAIN_ID.USE.ESBUILD).after(import_utils.CHAIN_ID.USE.SWC).end();
61
+ }).after(import_shared.CHAIN_ID.USE.TS).after(import_shared.CHAIN_ID.USE.ESBUILD).after(import_shared.CHAIN_ID.USE.SWC).end();
61
62
  }
62
63
  }
63
64
  }
@@ -28,15 +28,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var plugin_storybook_exports = {};
30
30
  __export(plugin_storybook_exports, {
31
+ addonBabelAdapter: () => addonBabelAdapter,
31
32
  finalize: () => finalize,
32
33
  pluginStorybook: () => pluginStorybook
33
34
  });
34
35
  module.exports = __toCommonJS(plugin_storybook_exports);
35
36
  var import_path = require("path");
36
37
  var import_utils = require("@modern-js/utils");
37
- var import_builder_shared = require("@modern-js/builder-shared");
38
38
  var import_core_common = require("@storybook/core-common");
39
39
  var import_globals = require("@storybook/preview/globals");
40
+ var import_shared = require("@rsbuild/shared");
40
41
  var import_csf_plugin = require("@storybook/csf-plugin");
41
42
  var import_minimatch = require("minimatch");
42
43
  var import_utils2 = require("./utils");
@@ -68,7 +69,7 @@ const pluginStorybook = (cwd, options) => {
68
69
  const absolutePattern = (0, import_path.isAbsolute)(pattern) ? pattern : (0, import_path.join)(options.configDir, pattern);
69
70
  return absolutePattern;
70
71
  });
71
- api.modifyBuilderConfig(async (builderConfig) => {
72
+ api.modifyRsbuildConfig(async (builderConfig) => {
72
73
  await prepareStorybookModules(api.context.cachePath, cwd, options, builderConfig, storyPatterns);
73
74
  await applyDefines(builderConfig, options);
74
75
  await applyHTML(builderConfig, options);
@@ -83,13 +84,13 @@ const pluginStorybook = (cwd, options) => {
83
84
  await applyMdxLoader(config, options);
84
85
  await applyCsfPlugin(config, options);
85
86
  };
86
- if ("modifyWebpackConfig" in api) {
87
+ if (api.context.bundlerType === "webpack") {
87
88
  addonAdapter(api, options);
88
89
  api.modifyWebpackConfig(modifyConfig);
89
90
  api.modifyWebpackChain(async (chain) => {
90
91
  await (0, import_docgen.applyDocgenWebpack)(chain, options);
91
92
  });
92
- } else if ("modifyRspackConfig" in api) {
93
+ } else {
93
94
  api.modifyRspackConfig(async (config) => {
94
95
  await modifyConfig(config);
95
96
  await (0, import_docgen.applyDocgenRspack)(config, options);
@@ -136,7 +137,9 @@ async function prepareStorybookModules(tempDir, cwd, options, builderConfig, sto
136
137
  builderConfig.source.alias = (0, import_utils.applyOptionsChain)({
137
138
  ...storybookPaths,
138
139
  ...mappingsAlias
139
- }, builderConfig.source.alias);
140
+ }, builderConfig.source.alias, {
141
+ target: "web"
142
+ });
140
143
  if ((0, import_utils2.isDev)()) {
141
144
  const watcher = await watchStories(storyPatterns, cwd, write);
142
145
  onClose(async () => {
@@ -248,7 +251,7 @@ async function applyMdxLoader(config, options) {
248
251
  }
249
252
  function applyExternals(builderConfig) {
250
253
  var _builderConfig_output;
251
- const config = (0, import_builder_shared.mergeBuilderConfig)({
254
+ const config = (0, import_shared.mergeRsbuildConfig)({
252
255
  output: {
253
256
  ...builderConfig.output,
254
257
  externals: (_builderConfig_output = builderConfig.output) === null || _builderConfig_output === void 0 ? void 0 : _builderConfig_output.externals
@@ -310,7 +313,9 @@ async function applyReact(config, options) {
310
313
  (_source = (_config = config).source) !== null && _source !== void 0 ? _source : _config.source = {};
311
314
  config.source.alias = (0, import_utils.applyOptionsChain)({
312
315
  "@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-18"
313
- }, config.source.alias);
316
+ }, config.source.alias, {
317
+ target: "web"
318
+ });
314
319
  }
315
320
  }
316
321
  async function watchStories(patterns, cwd, writeModule) {
@@ -334,57 +339,60 @@ async function watchStories(patterns, cwd, writeModule) {
334
339
  }
335
340
  function addonAdapter(api, options) {
336
341
  const { presets } = options;
337
- api.modifyBuilderConfig(async (finalConfig) => {
338
- var _finalConfig;
339
- const babelOptions = await presets.apply("babel", {}, {
340
- ...options
341
- });
342
- var _tools;
343
- (_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
344
- const userConfig = finalConfig.tools.babel;
345
- finalConfig.tools.babel = (config, utils) => {
346
- const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
347
- const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
348
- const replaceOrInsert = (plugin, plugins) => {
349
- const pluginName = getPluginName(plugin);
350
- for (let i = 0; i < plugins.length; i++) {
351
- if (getPluginName(plugins[i]) === pluginName) {
352
- if (getOptions(plugin)) {
353
- import_utils.logger.info(`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`);
354
- plugins[i] = plugin;
355
- }
356
- return;
357
- }
358
- }
359
- plugins.push(plugin);
360
- };
361
- const currentPlugins = config.plugins || [];
362
- const currentPresets = config.presets || [];
363
- for (const plugin of babelOptions.plugins || []) {
364
- replaceOrInsert(plugin, currentPlugins);
365
- }
366
- for (const preset of babelOptions.presets || []) {
367
- replaceOrInsert(preset, currentPresets);
368
- }
369
- const finalConfig2 = {
370
- ...babelOptions,
371
- plugins: currentPlugins,
372
- presets: currentPresets
373
- };
374
- if (userConfig) {
375
- return (0, import_utils.applyOptionsChain)(finalConfig2, userConfig, utils);
376
- } else {
377
- return finalConfig2;
378
- }
379
- };
380
- });
381
342
  api.modifyWebpackConfig(async (config) => {
382
343
  const finalDefaultConfig = await presets.apply("webpackFinal", config, options);
383
344
  return finalDefaultConfig;
384
345
  });
385
346
  }
347
+ async function addonBabelAdapter(finalConfig, options) {
348
+ var _finalConfig;
349
+ const { presets } = options;
350
+ const babelOptions = await presets.apply("babel", {}, {
351
+ ...options
352
+ });
353
+ var _tools;
354
+ (_tools = (_finalConfig = finalConfig).tools) !== null && _tools !== void 0 ? _tools : _finalConfig.tools = {};
355
+ const userConfig = finalConfig.tools.babel;
356
+ finalConfig.tools.babel = (config, utils) => {
357
+ const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
358
+ const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
359
+ const replaceOrInsert = (plugin, plugins) => {
360
+ const pluginName = getPluginName(plugin);
361
+ for (let i = 0; i < plugins.length; i++) {
362
+ if (getPluginName(plugins[i]) === pluginName) {
363
+ if (getOptions(plugin)) {
364
+ import_utils.logger.info(`Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`);
365
+ plugins[i] = plugin;
366
+ }
367
+ return;
368
+ }
369
+ }
370
+ plugins.push(plugin);
371
+ };
372
+ const currentPlugins = config.plugins || [];
373
+ const currentPresets = config.presets || [];
374
+ for (const plugin of babelOptions.plugins || []) {
375
+ replaceOrInsert(plugin, currentPlugins);
376
+ }
377
+ for (const preset of babelOptions.presets || []) {
378
+ replaceOrInsert(preset, currentPresets);
379
+ }
380
+ const finalConfig2 = {
381
+ ...babelOptions,
382
+ plugins: currentPlugins,
383
+ presets: currentPresets
384
+ };
385
+ if (userConfig) {
386
+ return (0, import_utils.applyOptionsChain)(finalConfig2, userConfig, utils);
387
+ } else {
388
+ return finalConfig2;
389
+ }
390
+ };
391
+ return finalConfig;
392
+ }
386
393
  // Annotate the CommonJS export names for ESM import in node:
387
394
  0 && (module.exports = {
395
+ addonBabelAdapter,
388
396
  finalize,
389
397
  pluginStorybook
390
398
  });
@@ -58,6 +58,8 @@ const modern = (builderConfig, options) => {
58
58
  var _builderConfig_output;
59
59
  return {
60
60
  ...builderConfig,
61
+ // modern plugin can't be used as Rsbuild plugin
62
+ plugins: [],
61
63
  output: {
62
64
  ...builderConfig.output,
63
65
  disableInlineRuntimeChunk: true,
package/dist/cjs/types.js CHANGED
@@ -18,10 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var types_exports = {};
20
20
  __export(types_exports, {
21
- defineConfig: () => import_cli.defineConfig
21
+ defineConfig: () => defineConfig
22
22
  });
23
23
  module.exports = __toCommonJS(types_exports);
24
- var import_cli = require("@modern-js/builder/cli");
24
+ function defineConfig(config) {
25
+ return config;
26
+ }
25
27
  // Annotate the CommonJS export names for ESM import in node:
26
28
  0 && (module.exports = {
27
29
  defineConfig
package/dist/cjs/utils.js CHANGED
@@ -33,7 +33,6 @@ __export(utils_exports, {
33
33
  VIRTUAL_MODULE_BASE: () => VIRTUAL_MODULE_BASE,
34
34
  getAbsolutePath: () => getAbsolutePath,
35
35
  getConfigFileName: () => getConfigFileName,
36
- getProvider: () => getProvider,
37
36
  isDev: () => isDev,
38
37
  maybeGetAbsolutePath: () => maybeGetAbsolutePath,
39
38
  requireResolve: () => requireResolve,
@@ -52,24 +51,6 @@ const requireResolve = (importer, path2) => {
52
51
  const require1 = (0, import_node_module.createRequire)(importer);
53
52
  require1.resolve(path2);
54
53
  };
55
- async function getProvider(bundler, builderConfig) {
56
- try {
57
- if (bundler === "webpack") {
58
- const { builderWebpackProvider } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-webpack-provider")));
59
- return builderWebpackProvider({
60
- builderConfig
61
- });
62
- } else if (bundler === "rspack") {
63
- const { builderRspackProvider } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-rspack-provider")));
64
- return builderRspackProvider({
65
- builderConfig
66
- });
67
- } else {
68
- return await getProvider("webpack", builderConfig) || await getProvider("rspack", builderConfig);
69
- }
70
- } catch (e) {
71
- }
72
- }
73
54
  async function virtualModule(tempDir, cwd, virtualModuleMap) {
74
55
  import_utils.fs.ensureDirSync(tempDir);
75
56
  const alias = {};
@@ -148,7 +129,6 @@ function getConfigFileName() {
148
129
  VIRTUAL_MODULE_BASE,
149
130
  getAbsolutePath,
150
131
  getConfigFileName,
151
- getProvider,
152
132
  isDev,
153
133
  maybeGetAbsolutePath,
154
134
  requireResolve,
package/dist/esm/build.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { dirname, join, parse } from "path";
2
- import webpackDevMiddleware from "@modern-js/builder-shared/webpack-dev-middleware";
2
+ import webpackDevMiddleware from "@rsbuild/shared/webpack-dev-middleware";
3
3
  import webpackHotMiddleware from "webpack-hot-middleware";
4
4
  import serveStatic from "serve-static";
5
5
  import { fs } from "@modern-js/utils";
package/dist/esm/core.js CHANGED
@@ -1,7 +1,8 @@
1
- import { createBuilder, mergeBuilderConfig } from "@modern-js/builder";
1
+ import { createUniBuilder } from "@modern-js/uni-builder";
2
+ import { mergeRsbuildConfig } from "@rsbuild/shared";
2
3
  import { loadConfig } from "@modern-js/core";
3
- import { getConfigFileName, getProvider, runWithErrorMsg } from "./utils";
4
- import { pluginStorybook } from "./plugin-storybook";
4
+ import { getConfigFileName, runWithErrorMsg } from "./utils";
5
+ import { pluginStorybook, addonBabelAdapter } from "./plugin-storybook";
5
6
  async function getCompiler(cwd, builderOptions, options) {
6
7
  const { bundler } = builderOptions;
7
8
  const { presets } = options;
@@ -12,25 +13,17 @@ async function getCompiler(cwd, builderOptions, options) {
12
13
  );
13
14
  const loadedConfig = res ? res.config : {};
14
15
  const finalConfig = await presets.apply("modern", loadedConfig) || loadedConfig;
15
- const provider = await getProvider(
16
- bundler,
17
- mergeBuilderConfig(finalConfig, builderOptions.builderConfig) || {}
18
- );
19
- if (!provider) {
20
- if (bundler) {
21
- throw new Error(
22
- `You choose to use ${bundler}, but @modern-js/builder-${bundler}-provider not found in your project, please install it`
23
- );
24
- } else {
25
- throw new Error(
26
- `Please install one provider first, try install @modern-js/builder-rspack-provider or @modern-js/builder-webpack-provider first`
27
- );
28
- }
29
- }
30
- const builder = await createBuilder(provider, {
16
+ const uniBuilderConfig = builderOptions.builderConfig ? mergeRsbuildConfig(
17
+ finalConfig,
18
+ builderOptions.builderConfig
19
+ ) : finalConfig || {};
20
+ const bundlerType = bundler || "webpack";
21
+ const builder = await createUniBuilder({
22
+ bundlerType,
31
23
  cwd,
32
24
  target: "web",
33
- framework: "modern.js storybook",
25
+ frameworkConfigPath: (res == null ? void 0 : res.path) ? res.path : void 0,
26
+ config: bundlerType === "webpack" ? await addonBabelAdapter(uniBuilderConfig, options) : uniBuilderConfig,
34
27
  entry: {
35
28
  main: entries
36
29
  }
@@ -1,4 +1,5 @@
1
- import { CHAIN_ID, logger } from "@modern-js/utils";
1
+ import { logger } from "@modern-js/utils";
2
+ import { CHAIN_ID } from "@rsbuild/shared";
2
3
  async function applyDocgenWebpack(chain, options) {
3
4
  const typescriptOptions = await options.presets.apply(
4
5
  "typescript",
@@ -6,9 +6,6 @@ import {
6
6
  applyOptionsChain,
7
7
  logger
8
8
  } from "@modern-js/utils";
9
- import {
10
- mergeBuilderConfig
11
- } from "@modern-js/builder-shared";
12
9
  import {
13
10
  normalizeStories,
14
11
  stringifyProcessEnvs,
@@ -17,6 +14,9 @@ import {
17
14
  loadPreviewOrConfigFile
18
15
  } from "@storybook/core-common";
19
16
  import { globalsNameReferenceMap } from "@storybook/preview/globals";
17
+ import {
18
+ mergeRsbuildConfig
19
+ } from "@rsbuild/shared";
20
20
  import { unplugin as csfPlugin } from "@storybook/csf-plugin";
21
21
  import { minimatch } from "minimatch";
22
22
  import {
@@ -53,7 +53,7 @@ const pluginStorybook = (cwd, options) => {
53
53
  const absolutePattern = isAbsolute(pattern) ? pattern : join(options.configDir, pattern);
54
54
  return absolutePattern;
55
55
  });
56
- api.modifyBuilderConfig(async (builderConfig) => {
56
+ api.modifyRsbuildConfig(async (builderConfig) => {
57
57
  await prepareStorybookModules(
58
58
  api.context.cachePath,
59
59
  cwd,
@@ -73,13 +73,13 @@ const pluginStorybook = (cwd, options) => {
73
73
  await applyMdxLoader(config, options);
74
74
  await applyCsfPlugin(config, options);
75
75
  };
76
- if ("modifyWebpackConfig" in api) {
76
+ if (api.context.bundlerType === "webpack") {
77
77
  addonAdapter(api, options);
78
78
  api.modifyWebpackConfig(modifyConfig);
79
79
  api.modifyWebpackChain(async (chain) => {
80
80
  await applyDocgenWebpack(chain, options);
81
81
  });
82
- } else if ("modifyRspackConfig" in api) {
82
+ } else {
83
83
  api.modifyRspackConfig(async (config) => {
84
84
  await modifyConfig(config);
85
85
  await applyDocgenRspack(config, options);
@@ -124,7 +124,8 @@ async function prepareStorybookModules(tempDir, cwd, options, builderConfig, sto
124
124
  ...storybookPaths,
125
125
  ...mappingsAlias
126
126
  },
127
- builderConfig.source.alias
127
+ builderConfig.source.alias,
128
+ { target: "web" }
128
129
  );
129
130
  if (isDev()) {
130
131
  const watcher = await watchStories(storyPatterns, cwd, write);
@@ -254,7 +255,7 @@ async function applyMdxLoader(config, options) {
254
255
  }
255
256
  function applyExternals(builderConfig) {
256
257
  var _a;
257
- const config = mergeBuilderConfig(
258
+ const config = mergeRsbuildConfig(
258
259
  {
259
260
  output: {
260
261
  ...builderConfig.output,
@@ -331,7 +332,8 @@ async function applyReact(config, options) {
331
332
  {
332
333
  "@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-18"
333
334
  },
334
- config.source.alias
335
+ config.source.alias,
336
+ { target: "web" }
335
337
  );
336
338
  }
337
339
  }
@@ -358,49 +360,6 @@ async function watchStories(patterns, cwd, writeModule) {
358
360
  }
359
361
  function addonAdapter(api, options) {
360
362
  const { presets } = options;
361
- api.modifyBuilderConfig(async (finalConfig) => {
362
- var _a;
363
- const babelOptions = await presets.apply("babel", {}, { ...options });
364
- (_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
365
- const userConfig = finalConfig.tools.babel;
366
- finalConfig.tools.babel = (config, utils) => {
367
- const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
368
- const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
369
- const replaceOrInsert = (plugin, plugins) => {
370
- const pluginName = getPluginName(plugin);
371
- for (let i = 0; i < plugins.length; i++) {
372
- if (getPluginName(plugins[i]) === pluginName) {
373
- if (getOptions(plugin)) {
374
- logger.info(
375
- `Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`
376
- );
377
- plugins[i] = plugin;
378
- }
379
- return;
380
- }
381
- }
382
- plugins.push(plugin);
383
- };
384
- const currentPlugins = config.plugins || [];
385
- const currentPresets = config.presets || [];
386
- for (const plugin of babelOptions.plugins || []) {
387
- replaceOrInsert(plugin, currentPlugins);
388
- }
389
- for (const preset of babelOptions.presets || []) {
390
- replaceOrInsert(preset, currentPresets);
391
- }
392
- const finalConfig2 = {
393
- ...babelOptions,
394
- plugins: currentPlugins,
395
- presets: currentPresets
396
- };
397
- if (userConfig) {
398
- return applyOptionsChain(finalConfig2, userConfig, utils);
399
- } else {
400
- return finalConfig2;
401
- }
402
- };
403
- });
404
363
  api.modifyWebpackConfig(async (config) => {
405
364
  const finalDefaultConfig = await presets.apply(
406
365
  "webpackFinal",
@@ -410,7 +369,53 @@ function addonAdapter(api, options) {
410
369
  return finalDefaultConfig;
411
370
  });
412
371
  }
372
+ async function addonBabelAdapter(finalConfig, options) {
373
+ var _a;
374
+ const { presets } = options;
375
+ const babelOptions = await presets.apply("babel", {}, { ...options });
376
+ (_a = finalConfig.tools) != null ? _a : finalConfig.tools = {};
377
+ const userConfig = finalConfig.tools.babel;
378
+ finalConfig.tools.babel = (config, utils) => {
379
+ const getPluginName = (plugin) => Array.isArray(plugin) ? plugin[0] : plugin;
380
+ const getOptions = (plugin) => Array.isArray(plugin) ? plugin[1] : null;
381
+ const replaceOrInsert = (plugin, plugins) => {
382
+ const pluginName = getPluginName(plugin);
383
+ for (let i = 0; i < plugins.length; i++) {
384
+ if (getPluginName(plugins[i]) === pluginName) {
385
+ if (getOptions(plugin)) {
386
+ logger.info(
387
+ `Detected duplicated babel plugin or presets: ${pluginName}, overrides with the new one`
388
+ );
389
+ plugins[i] = plugin;
390
+ }
391
+ return;
392
+ }
393
+ }
394
+ plugins.push(plugin);
395
+ };
396
+ const currentPlugins = config.plugins || [];
397
+ const currentPresets = config.presets || [];
398
+ for (const plugin of babelOptions.plugins || []) {
399
+ replaceOrInsert(plugin, currentPlugins);
400
+ }
401
+ for (const preset of babelOptions.presets || []) {
402
+ replaceOrInsert(preset, currentPresets);
403
+ }
404
+ const finalConfig2 = {
405
+ ...babelOptions,
406
+ plugins: currentPlugins,
407
+ presets: currentPresets
408
+ };
409
+ if (userConfig) {
410
+ return applyOptionsChain(finalConfig2, userConfig, utils);
411
+ } else {
412
+ return finalConfig2;
413
+ }
414
+ };
415
+ return finalConfig;
416
+ }
413
417
  export {
418
+ addonBabelAdapter,
414
419
  finalize,
415
420
  pluginStorybook
416
421
  };
@@ -25,6 +25,8 @@ const modern = (builderConfig, options) => {
25
25
  var _a;
26
26
  return {
27
27
  ...builderConfig,
28
+ // modern plugin can't be used as Rsbuild plugin
29
+ plugins: [],
28
30
  output: {
29
31
  ...builderConfig.output,
30
32
  disableInlineRuntimeChunk: true,
package/dist/esm/types.js CHANGED
@@ -1,4 +1,6 @@
1
- import { defineConfig } from "@modern-js/builder/cli";
1
+ function defineConfig(config) {
2
+ return config;
3
+ }
2
4
  export {
3
5
  defineConfig
4
6
  };
package/dist/esm/utils.js CHANGED
@@ -8,24 +8,6 @@ const requireResolve = (importer, path2) => {
8
8
  const require2 = createRequire(importer);
9
9
  require2.resolve(path2);
10
10
  };
11
- async function getProvider(bundler, builderConfig) {
12
- try {
13
- if (bundler === "webpack") {
14
- const { builderWebpackProvider } = await import("@modern-js/builder-webpack-provider");
15
- return builderWebpackProvider({
16
- builderConfig
17
- });
18
- } else if (bundler === "rspack") {
19
- const { builderRspackProvider } = await import("@modern-js/builder-rspack-provider");
20
- return builderRspackProvider({
21
- builderConfig
22
- });
23
- } else {
24
- return await getProvider("webpack", builderConfig) || await getProvider("rspack", builderConfig);
25
- }
26
- } catch (e) {
27
- }
28
- }
29
11
  async function virtualModule(tempDir, cwd, virtualModuleMap) {
30
12
  fs.ensureDirSync(tempDir);
31
13
  const alias = {};
@@ -101,7 +83,6 @@ export {
101
83
  VIRTUAL_MODULE_BASE,
102
84
  getAbsolutePath,
103
85
  getConfigFileName,
104
- getProvider,
105
86
  isDev,
106
87
  maybeGetAbsolutePath,
107
88
  requireResolve,
@@ -1,4 +1,4 @@
1
1
  import type { Options } from '@storybook/types';
2
- import type { Compiler } from '@modern-js/builder-shared/webpack-dev-middleware';
2
+ import type { Compiler } from '@rsbuild/shared/webpack-dev-middleware';
3
3
  import type { BuilderOptions } from './types';
4
4
  export declare function getCompiler(cwd: string, builderOptions: BuilderOptions, options: Options): Promise<Compiler>;
@@ -1,6 +1,5 @@
1
1
  import type { Options } from '@storybook/types';
2
- import { RspackConfig } from '@modern-js/builder-rspack-provider';
3
- import { WebpackChain } from '@modern-js/builder-webpack-provider';
2
+ import type { RspackConfig, WebpackChain } from '@rsbuild/shared';
4
3
  export type DocgenOptions = {
5
4
  reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
6
5
  reactDocgenTypescriptOptions?: any;
@@ -1,6 +1,6 @@
1
- import { BuilderPlugin } from '@modern-js/builder-shared';
2
1
  import type { Options } from '@storybook/types';
3
- import type { BuilderPluginAPI as WebpackAPI } from '@modern-js/builder-webpack-provider';
4
- import type { BuilderPluginAPI as RspackAPI } from '@modern-js/builder-rspack-provider';
2
+ import { type RsbuildPlugin } from '@rsbuild/shared';
3
+ import { BuilderConfig } from './types';
5
4
  export declare function finalize(): Promise<void>;
6
- export declare const pluginStorybook: (cwd: string, options: Options) => BuilderPlugin<WebpackAPI | RspackAPI>;
5
+ export declare const pluginStorybook: (cwd: string, options: Options) => RsbuildPlugin;
6
+ export declare function addonBabelAdapter(finalConfig: BuilderConfig, options: Options): Promise<BuilderConfig>;
@@ -1,5 +1,5 @@
1
1
  import type { Options } from '@storybook/types';
2
- import { BuilderConfig } from './types';
2
+ import type { UniBuilderConfig } from '@modern-js/uni-builder';
3
3
  export declare const previewMainTemplate: () => string;
4
4
  export declare const entries: (_: unknown, options: Options) => Promise<string[]>;
5
- export declare const modern: (builderConfig: BuilderConfig, options: Options) => BuilderConfig;
5
+ export declare const modern: (builderConfig: UniBuilderConfig, options: Options) => UniBuilderConfig;
@@ -1,15 +1,12 @@
1
- import type { BuilderConfig as WebpackBuilderConfig } from '@modern-js/builder-webpack-provider';
2
- import type { BuilderConfig as RspackBuilderConfig } from '@modern-js/builder-rspack-provider';
3
- import { BuilderPlugin } from '@modern-js/builder-shared';
1
+ import type { RsbuildPlugin } from '@rsbuild/shared';
2
+ import type { UniBuilderConfig } from '@modern-js/uni-builder';
4
3
  export type BundlerType = 'webpack' | 'rspack';
5
- export type { WebpackBuilderConfig, RspackBuilderConfig };
6
- export type AllBuilderConfig = WebpackBuilderConfig | RspackBuilderConfig;
7
4
  export type BuilderOptions = {
8
5
  bundler?: BundlerType;
9
- builderConfig?: AllBuilderConfig;
6
+ builderConfig?: UniBuilderConfig;
10
7
  configPath?: string;
11
8
  };
12
- export type BuilderConfig = AllBuilderConfig & {
13
- builderPlugins?: BuilderPlugin[];
9
+ export type BuilderConfig = UniBuilderConfig & {
10
+ builderPlugins?: RsbuildPlugin[];
14
11
  };
15
- export { defineConfig } from '@modern-js/builder/cli';
12
+ export declare function defineConfig(config: UniBuilderConfig): UniBuilderConfig;
@@ -1,11 +1,7 @@
1
- import { BuilderWebpackProvider } from '@modern-js/builder-webpack-provider';
2
- import { BuilderRspackProvider } from '@modern-js/builder-rspack-provider';
3
- import { AllBuilderConfig } from './types';
4
1
  export declare const VIRTUAL_MODULE_BASE = ".MODERN_STORYBOOK";
5
2
  export declare const STORIES_FILENAME = "storybook-stories.js";
6
3
  export declare const STORYBOOK_CONFIG_ENTRY = "storybook-config-entry.js";
7
4
  export declare const requireResolve: (importer: string, path: string) => void;
8
- export declare function getProvider(bundler: 'webpack' | 'rspack' | undefined, builderConfig: AllBuilderConfig): Promise<BuilderWebpackProvider | BuilderRspackProvider | undefined>;
9
5
  export declare function virtualModule(tempDir: string, cwd: string, virtualModuleMap: Record<string, string>): Promise<[Record<string, string>, (p: string, content: string) => void]>;
10
6
  export declare function toImportFn(cwd: string, stories: string[]): Promise<string>;
11
7
  export declare function getAbsolutePath<I extends string>(input: I): I;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/storybook-builder",
3
- "version": "2.46.0",
3
+ "version": "2.47.0",
4
4
  "description": "modern.js support for storybook",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,18 +51,19 @@
51
51
  },
52
52
  "license": "MIT",
53
53
  "dependencies": {
54
+ "@rsbuild/shared": "0.4.4",
54
55
  "@rspack/plugin-react-refresh": "0.4.5",
55
- "@storybook/components": "~7.6.1",
56
- "@storybook/core-common": "~7.6.1",
57
- "@storybook/csf-plugin": "~7.6.1",
56
+ "@storybook/components": "~7.6.12",
57
+ "@storybook/core-common": "~7.6.12",
58
+ "@storybook/csf-plugin": "~7.6.12",
58
59
  "@storybook/global": "~5.0.0",
59
60
  "@storybook/mdx1-csf": "~1.0.0",
60
61
  "@storybook/mdx2-csf": "~1.1.0",
61
- "@storybook/preview": "~7.6.1",
62
- "@storybook/preview-api": "~7.6.1",
62
+ "@storybook/preview": "~7.6.12",
63
+ "@storybook/preview-api": "~7.6.12",
63
64
  "@storybook/react-docgen-typescript-plugin": "1.0.6--canary.9.0c3f3b7.0",
64
- "@storybook/router": "~7.6.1",
65
- "@storybook/theming": "~7.6.1",
65
+ "@storybook/router": "~7.6.12",
66
+ "@storybook/theming": "~7.6.12",
66
67
  "ast-types": "^0.14.2",
67
68
  "minimatch": "^9.0.3",
68
69
  "react-docgen": "6.0.0-alpha.3",
@@ -71,34 +72,19 @@
71
72
  "serve-static": "^1.14.1",
72
73
  "tinypool": "^0.8.0",
73
74
  "webpack-hot-middleware": "^2.25.4",
74
- "@modern-js/core": "2.46.0",
75
- "@modern-js/builder": "2.46.0",
76
- "@modern-js/runtime": "2.46.0",
77
- "@modern-js/builder-shared": "2.46.0",
78
- "@modern-js/utils": "2.46.0"
75
+ "@modern-js/uni-builder": "2.47.0",
76
+ "@modern-js/runtime": "2.47.0",
77
+ "@modern-js/core": "2.47.0",
78
+ "@modern-js/utils": "2.47.0"
79
79
  },
80
80
  "devDependencies": {
81
- "@storybook/types": "~7.6.1",
81
+ "@storybook/types": "~7.6.12",
82
82
  "@types/babel__core": "^7.20.1",
83
83
  "@types/serve-static": "^1.13.10",
84
84
  "@types/webpack-hot-middleware": "^2.25.6",
85
85
  "typescript": "^5.2.2",
86
- "@modern-js/builder-rspack-provider": "2.46.0",
87
- "@modern-js/builder-webpack-provider": "2.46.0",
88
- "@modern-js/core": "2.46.0",
89
- "@scripts/build": "2.46.0"
90
- },
91
- "peerDependencies": {
92
- "@modern-js/builder-webpack-provider": "^2.46.0",
93
- "@modern-js/builder-rspack-provider": "^2.46.0"
94
- },
95
- "peerDependenciesMeta": {
96
- "@modern-js/builder-webpack-provider": {
97
- "optional": true
98
- },
99
- "@modern-js/builder-rspack-provider": {
100
- "optional": true
101
- }
86
+ "@modern-js/core": "2.47.0",
87
+ "@scripts/build": "2.47.0"
102
88
  },
103
89
  "publishConfig": {
104
90
  "registry": "https://registry.npmjs.org/",