storybook-builder-rsbuild 3.0.0 → 3.1.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.
@@ -155,27 +155,21 @@ var dist_dirname = external_node_path_namespaceObject.dirname(dist_filename);
155
155
  var dist_require = external_node_module_namespaceObject.createRequire(
156
156
  import.meta.url,
157
157
  );
158
- var __defProp = Object.defineProperty;
159
- var __name = (target, value) =>
160
- __defProp(target, "name", { value, configurable: true });
161
- var webpackConfigs = ["webpack.config", "webpackfile"];
162
- var loadCustomWebpackConfig = __name(
163
- async (configDir) =>
158
+ var webpackConfigs = ["webpack.config", "webpackfile"],
159
+ loadCustomWebpackConfig = async (configDir) =>
164
160
  (0, common_namespaceObject.serverRequire)(
165
161
  webpackConfigs.map((configName) =>
166
162
  (0, external_node_path_namespaceObject.resolve)(configDir, configName),
167
163
  ),
168
- ),
169
- "loadCustomWebpackConfig",
170
- );
171
- var checkWebpackVersion = __name((webpack, specifier, caption) => {
164
+ );
165
+ var checkWebpackVersion = (webpack, specifier, caption) => {
172
166
  if (!webpack.version) {
173
167
  node_logger_namespaceObject.logger.info(
174
168
  "Skipping webpack version check, no version available",
175
169
  );
176
170
  return;
177
171
  }
178
- if (webpack.version !== specifier) {
172
+ webpack.version !== specifier &&
179
173
  node_logger_namespaceObject.logger.warn((0, dist.TW)`
180
174
  Unexpected webpack version in ${caption}:
181
175
  - Received '${webpack.version}'
@@ -185,34 +179,28 @@ var checkWebpackVersion = __name((webpack, specifier, caption) => {
185
179
 
186
180
  For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
187
181
  `);
188
- }
189
- }, "checkWebpackVersion");
182
+ };
190
183
  function mergePluginsField(defaultPlugins = [], customPlugins = []) {
191
184
  return [...defaultPlugins, ...customPlugins];
192
185
  }
193
- __name(mergePluginsField, "mergePluginsField");
194
186
  function mergeRulesField(defaultRules = [], customRules = []) {
195
187
  return [...defaultRules, ...customRules];
196
188
  }
197
- __name(mergeRulesField, "mergeRulesField");
198
189
  function mergeExtensionsField(
199
190
  { extensions: defaultExtensions = [] },
200
191
  { extensions: customExtensions = [] },
201
192
  ) {
202
193
  return [...defaultExtensions, ...customExtensions];
203
194
  }
204
- __name(mergeExtensionsField, "mergeExtensionsField");
205
195
  function mergeAliasField(
206
196
  { alias: defaultAlias = {} },
207
197
  { alias: customAlias = {} },
208
198
  ) {
209
199
  return { ...defaultAlias, ...customAlias };
210
200
  }
211
- __name(mergeAliasField, "mergeAliasField");
212
201
  function mergeModuleField(a, b) {
213
202
  return { ...a, ...b, rules: mergeRulesField(a.rules || [], b.rules || []) };
214
203
  }
215
- __name(mergeModuleField, "mergeModuleField");
216
204
  function mergeResolveField(
217
205
  { resolve: defaultResolve = {} },
218
206
  { resolve: customResolve = {} },
@@ -224,14 +212,12 @@ function mergeResolveField(
224
212
  extensions: mergeExtensionsField(defaultResolve, customResolve),
225
213
  };
226
214
  }
227
- __name(mergeResolveField, "mergeResolveField");
228
215
  function mergeOptimizationField(
229
216
  { optimization: defaultOptimization = {} },
230
217
  { optimization: customOptimization = {} },
231
218
  ) {
232
219
  return { ...defaultOptimization, ...customOptimization };
233
220
  }
234
- __name(mergeOptimizationField, "mergeOptimizationField");
235
221
  function mergeConfigs(config, customConfig) {
236
222
  return {
237
223
  ...customConfig,
@@ -243,49 +229,45 @@ function mergeConfigs(config, customConfig) {
243
229
  optimization: mergeOptimizationField(config, customConfig),
244
230
  };
245
231
  }
246
- __name(mergeConfigs, "mergeConfigs");
247
232
  function importPipeline() {
248
233
  let importGate = Promise.resolve();
249
234
  return async (importFn) => {
250
235
  await importGate;
251
- const moduleExportsPromise = importFn();
252
- importGate = importGate.then(async () => {
253
- await moduleExportsPromise;
254
- });
255
- return moduleExportsPromise;
236
+ let moduleExportsPromise = importFn();
237
+ return (
238
+ (importGate = importGate.then(async () => {
239
+ await moduleExportsPromise;
240
+ })),
241
+ moduleExportsPromise
242
+ );
256
243
  };
257
244
  }
258
- __name(importPipeline, "importPipeline");
259
245
  function adjustRegexToExcludeNodeModules(originalRegex) {
260
- const originalRegexString = originalRegex.source;
261
- const startsWithCaret = originalRegexString.startsWith("^");
262
- const excludeNodeModulesPattern = startsWithCaret
263
- ? "(?!.*node_modules)"
264
- : "^(?!.*node_modules)";
265
- const adjustedRegexString = startsWithCaret
266
- ? `^${excludeNodeModulesPattern}${originalRegexString.substring(1)}`
267
- : excludeNodeModulesPattern + originalRegexString;
246
+ let originalRegexString = originalRegex.source,
247
+ startsWithCaret = originalRegexString.startsWith("^"),
248
+ excludeNodeModulesPattern = startsWithCaret
249
+ ? "(?!.*node_modules)"
250
+ : "^(?!.*node_modules)",
251
+ adjustedRegexString = startsWithCaret
252
+ ? `^${excludeNodeModulesPattern}${originalRegexString.substring(1)}`
253
+ : excludeNodeModulesPattern + originalRegexString;
268
254
  return new RegExp(adjustedRegexString);
269
255
  }
270
- __name(adjustRegexToExcludeNodeModules, "adjustRegexToExcludeNodeModules");
271
256
  function webpackIncludeRegexp(specifier) {
272
- const { directory, files } = specifier;
273
- const directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, "/");
274
- const webpackIncludeGlob = [".", ".."].includes(directory)
275
- ? files
276
- : `${directoryWithoutLeadingDots}/${files}`;
277
- const webpackIncludeRegexpWithCaret = webpackIncludeGlob.includes(
278
- "node_modules",
279
- )
280
- ? (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob)
281
- : adjustRegexToExcludeNodeModules(
282
- (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob),
283
- );
257
+ let { directory, files } = specifier,
258
+ directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, "/"),
259
+ webpackIncludeGlob = [".", ".."].includes(directory)
260
+ ? files
261
+ : `${directoryWithoutLeadingDots}/${files}`,
262
+ webpackIncludeRegexpWithCaret = webpackIncludeGlob.includes("node_modules")
263
+ ? (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob)
264
+ : adjustRegexToExcludeNodeModules(
265
+ (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob),
266
+ );
284
267
  return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ""));
285
268
  }
286
- __name(webpackIncludeRegexp, "webpackIncludeRegexp");
287
269
  function toImportFnPart(specifier) {
288
- const { directory, importPathMatcher } = specifier;
270
+ let { directory, importPathMatcher } = specifier;
289
271
  return (0, dist.TW)`
290
272
  async (path) => {
291
273
  if (!${importPathMatcher}.exec(path)) {
@@ -302,17 +284,16 @@ function toImportFnPart(specifier) {
302
284
 
303
285
  `;
304
286
  }
305
- __name(toImportFnPart, "toImportFnPart");
306
287
  function toImportFn(stories, { needPipelinedImport } = {}) {
307
- let pipelinedImport = `const pipeline = (x) => x();`;
308
- if (needPipelinedImport) {
309
- pipelinedImport = `\n const importPipeline = ${importPipeline};\n const pipeline = importPipeline();\n `;
310
- }
311
- return (0, dist.TW)`
288
+ let pipelinedImport = "const pipeline = (x) => x();";
289
+ return (
290
+ needPipelinedImport &&
291
+ (pipelinedImport = `\n const importPipeline = ${importPipeline};\n const pipeline = importPipeline();\n `),
292
+ (0, dist.TW)`
312
293
  ${pipelinedImport}
313
294
 
314
295
  const importers = [
315
- ${stories.map(toImportFnPart).join(",\n")}
296
+ ${stories.map(toImportFnPart).join(`,\n`)}
316
297
  ];
317
298
 
318
299
  export async function importFn(path) {
@@ -323,23 +304,22 @@ function toImportFn(stories, { needPipelinedImport } = {}) {
323
304
  }
324
305
  }
325
306
  }
326
- `;
307
+ `
308
+ );
327
309
  }
328
- __name(toImportFn, "toImportFn");
329
- var toRequireContext = __name((specifier) => {
330
- const { directory, files } = specifier;
331
- const match = (0, common_namespaceObject.globToRegexp)(`./${files}`);
332
- return {
333
- path: directory,
334
- recursive: files.includes("**") || files.split("/").length > 1,
335
- match,
310
+ var toRequireContext = (specifier) => {
311
+ let { directory, files } = specifier,
312
+ match = (0, common_namespaceObject.globToRegexp)(`./${files}`);
313
+ return {
314
+ path: directory,
315
+ recursive: files.includes("**") || files.split("/").length > 1,
316
+ match,
317
+ };
318
+ },
319
+ toRequireContextString = (specifier) => {
320
+ let { path: p, recursive: r, match: m } = toRequireContext(specifier);
321
+ return `require.context('${p}', ${r}, ${m})`;
336
322
  };
337
- }, "toRequireContext");
338
- var toRequireContextString = __name((specifier) => {
339
- const { path: p, recursive: r, match: m } = toRequireContext(specifier);
340
- const result = `require.context('${p}', ${r}, ${m})`;
341
- return result;
342
- }, "toRequireContextString");
343
323
  var __webpack_exports__checkWebpackVersion = __webpack_exports__.il;
344
324
  var __webpack_exports__loadCustomWebpackConfig = __webpack_exports__.Tu;
345
325
  var __webpack_exports__mergeConfigs = __webpack_exports__.SV;
@@ -1 +1 @@
1
- {"name":"@storybook/core-webpack","version":"10.0.7","funding":{"type":"opencollective","url":"https://opencollective.com/storybook"},"license":"MIT","types":"index.d.ts","type":"module"}
1
+ {"name":"@storybook/core-webpack","version":"10.1.2","funding":{"type":"opencollective","url":"https://opencollective.com/storybook"},"license":"MIT","types":"index.d.ts","type":"module"}
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_8698d093820fd910 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_8698d093820fd910 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_8698d093820fd910 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_8698d093820fd910.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_8698d093820fd910.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_8698d093820fd910.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_8698d093820fd910 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_8698d093820fd910 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_8698d093820fd910 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_8698d093820fd910.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_8698d093820fd910.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_8698d093820fd910.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -13,7 +13,7 @@ import {
13
13
  __commonJS,
14
14
  __require,
15
15
  __toESM
16
- } from "./_node-chunks/chunk-EUKC5ATQ.js";
16
+ } from "./_node-chunks/chunk-J52G566E.js";
17
17
 
18
18
  // ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
19
19
  var require_pretty_hrtime = __commonJS({
@@ -201,14 +201,11 @@ var node_logger_namespaceObject = node_logger_x({
201
201
  import.meta.url
202
202
  ), dist_dirname = external_node_path_namespaceObject.dirname(dist_filename), dist_require = external_node_module_namespaceObject.createRequire(
203
203
  import.meta.url
204
- ), __defProp = Object.defineProperty, __name = (target, value) => __defProp(target, "name", { value, configurable: !0 }), webpackConfigs = ["webpack.config", "webpackfile"], loadCustomWebpackConfig = __name(
205
- async (configDir) => (0, common_namespaceObject.serverRequire)(
206
- webpackConfigs.map(
207
- (configName) => (0, external_node_path_namespaceObject.resolve)(configDir, configName)
208
- )
209
- ),
210
- "loadCustomWebpackConfig"
211
- ), checkWebpackVersion = __name((webpack, specifier, caption) => {
204
+ ), webpackConfigs = ["webpack.config", "webpackfile"], loadCustomWebpackConfig = async (configDir) => (0, common_namespaceObject.serverRequire)(
205
+ webpackConfigs.map(
206
+ (configName) => (0, external_node_path_namespaceObject.resolve)(configDir, configName)
207
+ )
208
+ ), checkWebpackVersion = (webpack, specifier, caption) => {
212
209
  if (!webpack.version) {
213
210
  node_logger_namespaceObject.logger.info(
214
211
  "Skipping webpack version check, no version available"
@@ -224,27 +221,22 @@ var node_logger_namespaceObject = node_logger_x({
224
221
 
225
222
  For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
226
223
  `);
227
- }, "checkWebpackVersion");
224
+ };
228
225
  function mergePluginsField(defaultPlugins = [], customPlugins = []) {
229
226
  return [...defaultPlugins, ...customPlugins];
230
227
  }
231
- __name(mergePluginsField, "mergePluginsField");
232
228
  function mergeRulesField(defaultRules = [], customRules = []) {
233
229
  return [...defaultRules, ...customRules];
234
230
  }
235
- __name(mergeRulesField, "mergeRulesField");
236
231
  function mergeExtensionsField({ extensions: defaultExtensions = [] }, { extensions: customExtensions = [] }) {
237
232
  return [...defaultExtensions, ...customExtensions];
238
233
  }
239
- __name(mergeExtensionsField, "mergeExtensionsField");
240
234
  function mergeAliasField({ alias: defaultAlias = {} }, { alias: customAlias = {} }) {
241
235
  return { ...defaultAlias, ...customAlias };
242
236
  }
243
- __name(mergeAliasField, "mergeAliasField");
244
237
  function mergeModuleField(a, b) {
245
238
  return { ...a, ...b, rules: mergeRulesField(a.rules || [], b.rules || []) };
246
239
  }
247
- __name(mergeModuleField, "mergeModuleField");
248
240
  function mergeResolveField({ resolve: defaultResolve = {} }, { resolve: customResolve = {} }) {
249
241
  return {
250
242
  ...defaultResolve,
@@ -253,11 +245,9 @@ function mergeResolveField({ resolve: defaultResolve = {} }, { resolve: customRe
253
245
  extensions: mergeExtensionsField(defaultResolve, customResolve)
254
246
  };
255
247
  }
256
- __name(mergeResolveField, "mergeResolveField");
257
248
  function mergeOptimizationField({ optimization: defaultOptimization = {} }, { optimization: customOptimization = {} }) {
258
249
  return { ...defaultOptimization, ...customOptimization };
259
250
  }
260
- __name(mergeOptimizationField, "mergeOptimizationField");
261
251
  function mergeConfigs(config, customConfig) {
262
252
  return {
263
253
  ...customConfig,
@@ -269,7 +259,6 @@ function mergeConfigs(config, customConfig) {
269
259
  optimization: mergeOptimizationField(config, customConfig)
270
260
  };
271
261
  }
272
- __name(mergeConfigs, "mergeConfigs");
273
262
  function importPipeline() {
274
263
  let importGate = Promise.resolve();
275
264
  return async (importFn) => {
@@ -280,21 +269,16 @@ function importPipeline() {
280
269
  }), moduleExportsPromise;
281
270
  };
282
271
  }
283
- __name(importPipeline, "importPipeline");
284
272
  function adjustRegexToExcludeNodeModules(originalRegex) {
285
273
  let originalRegexString = originalRegex.source, startsWithCaret = originalRegexString.startsWith("^"), excludeNodeModulesPattern = startsWithCaret ? "(?!.*node_modules)" : "^(?!.*node_modules)", adjustedRegexString = startsWithCaret ? `^${excludeNodeModulesPattern}${originalRegexString.substring(1)}` : excludeNodeModulesPattern + originalRegexString;
286
274
  return new RegExp(adjustedRegexString);
287
275
  }
288
- __name(adjustRegexToExcludeNodeModules, "adjustRegexToExcludeNodeModules");
289
276
  function webpackIncludeRegexp(specifier) {
290
- let { directory, files } = specifier, directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, "/"), webpackIncludeGlob = [".", ".."].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`, webpackIncludeRegexpWithCaret = webpackIncludeGlob.includes(
291
- "node_modules"
292
- ) ? (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob) : adjustRegexToExcludeNodeModules(
277
+ let { directory, files } = specifier, directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, "/"), webpackIncludeGlob = [".", ".."].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`, webpackIncludeRegexpWithCaret = webpackIncludeGlob.includes("node_modules") ? (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob) : adjustRegexToExcludeNodeModules(
293
278
  (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob)
294
279
  );
295
280
  return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ""));
296
281
  }
297
- __name(webpackIncludeRegexp, "webpackIncludeRegexp");
298
282
  function toImportFnPart(specifier) {
299
283
  let { directory, importPathMatcher } = specifier;
300
284
  return (0, dist.TW)`
@@ -313,7 +297,6 @@ function toImportFnPart(specifier) {
313
297
 
314
298
  `;
315
299
  }
316
- __name(toImportFnPart, "toImportFnPart");
317
300
  function toImportFn(stories, { needPipelinedImport } = {}) {
318
301
  let pipelinedImport = "const pipeline = (x) => x();";
319
302
  return needPipelinedImport && (pipelinedImport = `
@@ -337,18 +320,17 @@ function toImportFn(stories, { needPipelinedImport } = {}) {
337
320
  }
338
321
  `;
339
322
  }
340
- __name(toImportFn, "toImportFn");
341
- var toRequireContext = __name((specifier) => {
323
+ var toRequireContext = (specifier) => {
342
324
  let { directory, files } = specifier, match = (0, common_namespaceObject.globToRegexp)(`./${files}`);
343
325
  return {
344
326
  path: directory,
345
327
  recursive: files.includes("**") || files.split("/").length > 1,
346
328
  match
347
329
  };
348
- }, "toRequireContext"), toRequireContextString = __name((specifier) => {
330
+ }, toRequireContextString = (specifier) => {
349
331
  let { path: p, recursive: r, match: m } = toRequireContext(specifier);
350
332
  return `require.context('${p}', ${r}, ${m})`;
351
- }, "toRequireContextString"), __webpack_exports__checkWebpackVersion = __webpack_exports__.il, __webpack_exports__loadCustomWebpackConfig = __webpack_exports__.Tu, __webpack_exports__mergeConfigs = __webpack_exports__.SV, __webpack_exports__toImportFn = __webpack_exports__.T1, __webpack_exports__toImportFnPart = __webpack_exports__.i8, __webpack_exports__toRequireContext = __webpack_exports__.sg, __webpack_exports__toRequireContextString = __webpack_exports__.HO, __webpack_exports__webpackIncludeRegexp = __webpack_exports__.hO;
333
+ }, __webpack_exports__checkWebpackVersion = __webpack_exports__.il, __webpack_exports__loadCustomWebpackConfig = __webpack_exports__.Tu, __webpack_exports__mergeConfigs = __webpack_exports__.SV, __webpack_exports__toImportFn = __webpack_exports__.T1, __webpack_exports__toImportFnPart = __webpack_exports__.i8, __webpack_exports__toRequireContext = __webpack_exports__.sg, __webpack_exports__toRequireContextString = __webpack_exports__.HO, __webpack_exports__webpackIncludeRegexp = __webpack_exports__.hO;
352
334
 
353
335
  // src/preview/virtual-module-mapping.ts
354
336
  var getVirtualModules = async (options) => {
@@ -408,7 +390,7 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
408
390
  ".json",
409
391
  ".cjs"
410
392
  ], globalPath = maybeGetAbsolutePath("@storybook/global"), storybookPaths = {
411
- // biome-ignore lint/complexity/useLiteralKeys: <explanation>
393
+ // biome-ignore lint/complexity/useLiteralKeys: dynamic key required for conditional spread
412
394
  ...globalPath ? { "@storybook/global": globalPath } : {}
413
395
  }, iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
414
396
  let { rsbuildConfigPath, addonDocs } = await getBuilderOptions2(options), webpackConfigFromPresets = await options.presets.apply("webpack", {}, options);
@@ -567,7 +549,7 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
567
549
  swc: (config) => {
568
550
  config.env ??= {}, config.env.bugfixes = !0;
569
551
  },
570
- rspack: (config, { addRules, rspack: rspack2, mergeConfig }) => {
552
+ rspack: (config, { addRules, rspack, mergeConfig }) => {
571
553
  if (addRules({
572
554
  test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
573
555
  exclude: /node_modules/,
@@ -598,16 +580,16 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
598
580
  url: require2.resolve("url"),
599
581
  fs: !1,
600
582
  constants: require2.resolve("constants-browserify")
601
- }, config.optimization ??= {}, config.optimization.runtimeChunk = !0, config.optimization.usedExports = options.build?.test?.disableTreeShaking ? !1 : isProd, config.optimization.moduleIds = "named", config.module ??= {}, config.module.parser ??= {}, config.module.parser.javascript ??= {}, config.module.parser.javascript.exportsPresence = !1, !rspack2.experiments?.VirtualModulesPlugin)
583
+ }, config.optimization ??= {}, config.optimization.runtimeChunk = !0, config.optimization.usedExports = options.build?.test?.disableTreeShaking ? !1 : isProd, config.optimization.moduleIds = "named", config.module ??= {}, config.module.parser ??= {}, config.module.parser.javascript ??= {}, config.module.parser.javascript.exportsPresence = !1, !rspack.experiments?.VirtualModulesPlugin)
602
584
  throw new Error(
603
585
  "rspack.experiments.VirtualModulesPlugin requires at least 1.5.0 version of @rsbuild/core, please upgrade or downgrade storybook-rsbuild-builder to lower version."
604
586
  );
605
587
  return config.plugins ??= [], config.plugins.push(
606
588
  ...[
607
- Object.keys(virtualModuleMapping).length > 0 ? new rspack2.experiments.VirtualModulesPlugin(
589
+ Object.keys(virtualModuleMapping).length > 0 ? new rspack.experiments.VirtualModulesPlugin(
608
590
  virtualModuleMapping
609
591
  ) : null,
610
- new rspack2.ProvidePlugin({
592
+ new rspack.ProvidePlugin({
611
593
  process: require2.resolve("process/browser.js")
612
594
  }),
613
595
  new CaseSensitivePathsPlugin()
@@ -673,7 +655,7 @@ var getIsReactVersion18or19 = async (options) => {
673
655
  await readFile(join3(reactDom, "package.json"), "utf-8")
674
656
  );
675
657
  return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
676
- }, applyReactShims = async (config, options) => await getIsReactVersion18or19(options) ? {} : {
658
+ }, applyReactShims = async (_config, options) => await getIsReactVersion18or19(options) ? {} : {
677
659
  resolve: {
678
660
  alias: {
679
661
  "@storybook/react-dom-shim": "@storybook/react-dom-shim/react-16"
@@ -737,8 +719,7 @@ var start = async ({
737
719
  startTime,
738
720
  options,
739
721
  router,
740
- server: storybookServer,
741
- channel
722
+ server: storybookServer
742
723
  }) => {
743
724
  overrideRsbuildLogger();
744
725
  let { createRsbuild } = await executor.get(options), config = await getConfig(options), rsbuildBuild = await createRsbuild({
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_8698d093820fd910 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_8698d093820fd910 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_8698d093820fd910 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_8698d093820fd910.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_8698d093820fd910.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_8698d093820fd910.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import "../_node-chunks/chunk-EUKC5ATQ.js";
12
+ import "../_node-chunks/chunk-J52G566E.js";
13
13
 
14
14
  // src/loaders/export-order-loader.ts
15
15
  import assert from "node:assert";
@@ -0,0 +1,22 @@
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "../_node-chunks/chunk-J52G566E.js";
13
+
14
+ // src/loaders/rsbuild-automock-loader.ts
15
+ import { babelParser, getAutomockCode } from "storybook/internal/mocking-utils";
16
+ function rsbuildAutomockLoader(source) {
17
+ let isSpy = this.getOptions().spy === "true";
18
+ return getAutomockCode(source, isSpy, babelParser).toString();
19
+ }
20
+ export {
21
+ rsbuildAutomockLoader as default
22
+ };
@@ -0,0 +1,30 @@
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "../_node-chunks/chunk-J52G566E.js";
13
+
14
+ // src/loaders/storybook-mock-transform-loader.ts
15
+ import { rewriteSbMockImportCalls } from "storybook/internal/mocking-utils";
16
+ import { logger } from "storybook/internal/node-logger";
17
+ var storybookMockTransformLoader = function(source, sourceMap, meta) {
18
+ let callback = this.async();
19
+ try {
20
+ let result = rewriteSbMockImportCalls(source);
21
+ callback(null, result.code, result.map || void 0, meta);
22
+ } catch (error) {
23
+ logger.debug(
24
+ `Could not transform sb.mock(import(...)) calls in ${this.resourcePath}: ${error}`
25
+ ), callback(null, source, sourceMap, meta);
26
+ }
27
+ }, storybook_mock_transform_loader_default = storybookMockTransformLoader;
28
+ export {
29
+ storybook_mock_transform_loader_default as default
30
+ };
@@ -1,20 +1,171 @@
1
- import CJS_COMPAT_NODE_URL_8698d093820fd910 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_8698d093820fd910 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_8698d093820fd910 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_533231c99a932017 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_533231c99a932017 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_533231c99a932017 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_8698d093820fd910.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_8698d093820fd910.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_8698d093820fd910.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_533231c99a932017.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_533231c99a932017.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_533231c99a932017.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
+ import "./_node-chunks/chunk-J52G566E.js";
13
+
14
+ // src/preview-preset.ts
15
+ import { createRequire } from "node:module";
16
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
17
+ import { findConfigFile } from "storybook/internal/common";
18
+
19
+ // src/plugins/rspack-inject-mocker-runtime-plugin.ts
20
+ import { getMockerRuntime } from "storybook/internal/mocking-utils";
21
+ var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePlugin = class {
22
+ getHtmlPlugin(compiler) {
23
+ try {
24
+ return compiler.options.plugins?.find((plugin) => {
25
+ let name = plugin?.constructor?.name;
26
+ return name === "HtmlRspackPlugin" || name === "HtmlWebpackPlugin";
27
+ })?.constructor;
28
+ } catch (error) {
29
+ return compiler.getInfrastructureLogger(PLUGIN_NAME).warn(
30
+ `Unable to locate HTML plugin for mock runtime injection: ${error}`
31
+ ), null;
32
+ }
33
+ }
34
+ apply(compiler) {
35
+ let HtmlPlugin = this.getHtmlPlugin(compiler);
36
+ if (!HtmlPlugin || typeof HtmlPlugin.getHooks != "function") {
37
+ compiler.getInfrastructureLogger(PLUGIN_NAME).warn("HTML plugin is not available. Cannot inject mocker runtime.");
38
+ return;
39
+ }
40
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
41
+ HtmlPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync(
42
+ PLUGIN_NAME,
43
+ (data, cb) => {
44
+ try {
45
+ let runtimeScriptContent = getMockerRuntime(), runtimeAssetName = "./mocker-runtime-injected.js", Sources = compiler.webpack?.sources;
46
+ if (!Sources?.RawSource)
47
+ throw new Error(
48
+ "rspack sources is not available on compiler.webpack"
49
+ );
50
+ compilation.emitAsset(
51
+ runtimeAssetName,
52
+ new Sources.RawSource(runtimeScriptContent)
53
+ ), data.assets.js.unshift(runtimeAssetName), cb(null, data);
54
+ } catch (error) {
55
+ cb(error);
56
+ }
57
+ }
58
+ );
59
+ });
60
+ }
61
+ };
62
+
63
+ // src/plugins/rspack-mock-plugin.ts
64
+ import { dirname, isAbsolute } from "node:path";
65
+ import { fileURLToPath } from "node:url";
66
+ import { rspack } from "@rsbuild/core";
67
+ import { findMockRedirect } from "@vitest/mocker/redirect";
12
68
  import {
13
- __require
14
- } from "./_node-chunks/chunk-EUKC5ATQ.js";
69
+ babelParser,
70
+ extractMockCalls,
71
+ getIsExternal,
72
+ resolveExternalModule,
73
+ resolveWithExtensions
74
+ } from "storybook/internal/mocking-utils";
75
+ var PLUGIN_NAME2 = "RspackMockPlugin";
76
+ function normalizePath(filePath) {
77
+ return filePath.replace(/\\/g, "/");
78
+ }
79
+ var RspackMockPlugin = class {
80
+ constructor(options) {
81
+ this.mockMap = /* @__PURE__ */ new Map();
82
+ if (!options.previewConfigPath)
83
+ throw new Error(`[${PLUGIN_NAME2}] \`previewConfigPath\` is required.`);
84
+ this.options = options;
85
+ }
86
+ apply(compiler) {
87
+ let logger = compiler.getInfrastructureLogger(PLUGIN_NAME2), updateMocks = () => {
88
+ this.mockMap = new Map(
89
+ this.extractAndResolveMocks(compiler).flatMap((mock) => [
90
+ [normalizePath(mock.absolutePath), mock],
91
+ [normalizePath(mock.absolutePath.replace(/\.[^.]+$/, "")), mock]
92
+ ])
93
+ ), logger.info(`Mock map updated with ${this.mockMap.size / 2} mocks.`);
94
+ };
95
+ compiler.hooks.beforeRun.tap(PLUGIN_NAME2, updateMocks), compiler.hooks.watchRun.tap(PLUGIN_NAME2, updateMocks), new rspack.NormalModuleReplacementPlugin(/.*/, (resource) => {
96
+ try {
97
+ let path = resource.request, importer = resource.context, absolutePath = getIsExternal(path, importer) ? resolveExternalModule(path, importer) : resolveWithExtensions(path, importer), normalizedAbsolutePath = normalizePath(absolutePath);
98
+ this.mockMap.has(normalizedAbsolutePath) && (resource.request = this.mockMap.get(
99
+ normalizedAbsolutePath
100
+ ).replacementResource);
101
+ } catch {
102
+ logger.debug(`Could not resolve mock for "${resource.request}".`);
103
+ }
104
+ }).apply(compiler), compiler.hooks.afterCompile.tap(PLUGIN_NAME2, (compilation) => {
105
+ compilation.fileDependencies.add(this.options.previewConfigPath);
106
+ for (let mock of this.mockMap.values())
107
+ isAbsolute(mock.replacementResource) && mock.replacementResource.includes("__mocks__") && compilation.contextDependencies.add(dirname(mock.replacementResource));
108
+ });
109
+ }
110
+ extractAndResolveMocks(compiler) {
111
+ let { previewConfigPath, configDir } = this.options, logger = compiler.getInfrastructureLogger(PLUGIN_NAME2), mocks = extractMockCalls(
112
+ {
113
+ previewConfigPath,
114
+ configDir: configDir ?? dirname(previewConfigPath)
115
+ },
116
+ babelParser,
117
+ compiler.context,
118
+ findMockRedirect
119
+ ), resolvedMocks = [];
120
+ for (let mock of mocks)
121
+ try {
122
+ let { absolutePath, redirectPath } = mock, replacementResource;
123
+ redirectPath ? replacementResource = redirectPath : replacementResource = `${fileURLToPath(
124
+ import.meta.resolve(
125
+ "storybook-builder-rsbuild/loaders/rsbuild-automock-loader"
126
+ )
127
+ )}?spy=${mock.spy}!${absolutePath}`, resolvedMocks.push({
128
+ ...mock,
129
+ replacementResource
130
+ });
131
+ } catch {
132
+ logger.warn(
133
+ `Could not resolve mock for "${mock.path}". It will be ignored.`
134
+ );
135
+ }
136
+ return resolvedMocks;
137
+ }
138
+ };
15
139
 
16
140
  // src/preview-preset.ts
17
- var previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
141
+ var require2 = createRequire(import.meta.url), previewMainTemplate = () => require2.resolve("storybook-builder-rsbuild/templates/preview.ejs");
142
+ async function rsbuildFinal(config, options) {
143
+ let previewConfigPath = findConfigFile("preview", options.configDir);
144
+ if (!previewConfigPath)
145
+ return config;
146
+ let applyMocking = (rspackConfig, utils) => (utils.addRules({
147
+ test: /preview\.(t|j)sx?$/,
148
+ use: [
149
+ {
150
+ loader: fileURLToPath2(
151
+ import.meta.resolve(
152
+ "storybook-builder-rsbuild/loaders/storybook-mock-transform-loader"
153
+ )
154
+ )
155
+ }
156
+ ]
157
+ }), rspackConfig.plugins ??= [], rspackConfig.plugins.push(new RspackMockPlugin({ previewConfigPath })), rspackConfig.plugins.push(new RspackInjectMockerRuntimePlugin()), rspackConfig);
158
+ return {
159
+ ...config,
160
+ tools: {
161
+ ...config.tools,
162
+ rspack: Array.isArray(config.tools?.rspack) ? [...config.tools.rspack, applyMocking] : [config.tools?.rspack, applyMocking].filter(
163
+ (v) => !!v
164
+ )
165
+ }
166
+ };
167
+ }
18
168
  export {
19
- previewMainTemplate
169
+ previewMainTemplate,
170
+ rsbuildFinal
20
171
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -24,6 +24,8 @@
24
24
  "default": "./dist/index.js"
25
25
  },
26
26
  "./loaders/export-order-loader": "./dist/loaders/export-order-loader.js",
27
+ "./loaders/rsbuild-automock-loader": "./dist/loaders/rsbuild-automock-loader.js",
28
+ "./loaders/storybook-mock-transform-loader": "./dist/loaders/storybook-mock-transform-loader.js",
27
29
  "./package.json": "./package.json",
28
30
  "./presets/preview-preset": "./dist/preview-preset.js",
29
31
  "./templates/preview.ejs": "./templates/preview.ejs",
@@ -42,9 +44,10 @@
42
44
  ],
43
45
  "dependencies": {
44
46
  "@rsbuild/plugin-type-check": "^1.2.4",
47
+ "@vitest/mocker": "3.2.4",
45
48
  "browser-assert": "^1.2.1",
46
49
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
47
- "cjs-module-lexer": "^1.4.3",
50
+ "cjs-module-lexer": "^2.1.1",
48
51
  "constants-browserify": "^1.0.0",
49
52
  "es-module-lexer": "^1.7.0",
50
53
  "fs-extra": "^11.3.2",
@@ -61,23 +64,21 @@
61
64
  },
62
65
  "devDependencies": {
63
66
  "@rsbuild/core": "^1.6.7",
64
- "@storybook/core-webpack": "^10.0.0",
65
- "@types/find-cache-dir": "^5.0.2",
67
+ "@storybook/core-webpack": "10.1.2",
66
68
  "@types/fs-extra": "^11.0.4",
67
69
  "@types/node": "^22.0.0",
68
70
  "@types/pretty-hrtime": "^1.0.3",
69
- "find-cache-dir": "^5.0.0",
70
71
  "prebundle": "^1.6.0",
71
72
  "pretty-hrtime": "^1.0.3",
72
73
  "slash": "^5.1.0",
73
- "storybook": "10.0.8",
74
+ "storybook": "10.1.2",
74
75
  "typescript": "^5.9.3"
75
76
  },
76
77
  "peerDependencies": {
77
78
  "@rsbuild/core": "^1.5.0",
78
79
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
79
80
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
80
- "storybook": "^10.0.0"
81
+ "storybook": "^10.1.0"
81
82
  },
82
83
  "peerDependenciesMeta": {
83
84
  "react": {
@@ -97,7 +98,9 @@
97
98
  "entries": [
98
99
  "./src/index.ts",
99
100
  "./src/preview-preset.ts",
100
- "./src/loaders/export-order-loader.ts"
101
+ "./src/loaders/export-order-loader.ts",
102
+ "./src/loaders/storybook-mock-transform-loader.ts",
103
+ "./src/loaders/rsbuild-automock-loader.ts"
101
104
  ],
102
105
  "platform": "node"
103
106
  },
@@ -1,11 +1,9 @@
1
+ import { importFn } from '{{storiesFilename}}'
2
+ import { global } from '@storybook/global'
1
3
  import { createBrowserChannel } from 'storybook/internal/channels'
2
4
  import { STORY_HOT_UPDATED } from 'storybook/internal/core-events'
3
5
  import { isPreview } from 'storybook/internal/csf'
4
-
5
- import { global } from '@storybook/global'
6
-
7
- import { PreviewWeb, addons, composeConfigs } from 'storybook/preview-api'
8
- import { importFn } from '{{storiesFilename}}'
6
+ import { addons, composeConfigs, PreviewWeb } from 'storybook/preview-api'
9
7
 
10
8
  const getProjectAnnotations = () => {
11
9
  const previewAnnotations = ['{{previewAnnotations_requires}}']