storybook-builder-rsbuild 3.3.4 → 3.4.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.
@@ -15,7 +15,10 @@ interface WebpackConfiguration {
15
15
  module?: ModuleConfig;
16
16
  resolve?: ResolveConfig;
17
17
  optimization?: any;
18
- devtool?: false | string;
18
+ devtool?: false | string | {
19
+ type: 'all' | 'javascript' | 'css';
20
+ use: any;
21
+ }[];
19
22
  }
20
23
  type BuilderOptions = {
21
24
  fsCache?: boolean;
@@ -1,85 +1,7 @@
1
1
  import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_common_7991bda6__ from "storybook/internal/common";
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__ from "storybook/internal/node-logger";
4
- var __webpack_modules__ = {
5
- 980: (__unused_webpack_module, exports) => {
6
- var __webpack_unused_export__;
7
- __webpack_unused_export__ = { value: true };
8
- exports.TW = void 0;
9
- function dedent(templ) {
10
- var values = [];
11
- for (var _i = 1; _i < arguments.length; _i++) {
12
- values[_i - 1] = arguments[_i];
13
- }
14
- var strings = Array.from(typeof templ === "string" ? [templ] : templ);
15
- strings[strings.length - 1] = strings[strings.length - 1].replace(
16
- /\r?\n([\t ]*)$/,
17
- "",
18
- );
19
- var indentLengths = strings.reduce(function (arr, str) {
20
- var matches = str.match(/\n([\t ]+|(?!\s).)/g);
21
- if (matches) {
22
- return arr.concat(
23
- matches.map(function (match) {
24
- var _a, _b;
25
- return (_b =
26
- (_a = match.match(/[\t ]/g)) === null || _a === void 0
27
- ? void 0
28
- : _a.length) !== null && _b !== void 0
29
- ? _b
30
- : 0;
31
- }),
32
- );
33
- }
34
- return arr;
35
- }, []);
36
- if (indentLengths.length) {
37
- var pattern_1 = new RegExp(
38
- "\n[\t ]{" + Math.min.apply(Math, indentLengths) + "}",
39
- "g",
40
- );
41
- strings = strings.map(function (str) {
42
- return str.replace(pattern_1, "\n");
43
- });
44
- }
45
- strings[0] = strings[0].replace(/^\r?\n/, "");
46
- var string = strings[0];
47
- values.forEach(function (value, i) {
48
- var endentations = string.match(/(?:^|\n)( *)$/);
49
- var endentation = endentations ? endentations[1] : "";
50
- var indentedValue = value;
51
- if (typeof value === "string" && value.includes("\n")) {
52
- indentedValue = String(value)
53
- .split("\n")
54
- .map(function (str, i) {
55
- return i === 0 ? str : "" + endentation + str;
56
- })
57
- .join("\n");
58
- }
59
- string += indentedValue + strings[i + 1];
60
- });
61
- return string;
62
- }
63
- exports.TW = dedent;
64
- __webpack_unused_export__ = dedent;
65
- },
66
- };
67
- var __webpack_module_cache__ = {};
68
- function __nccwpck_require__(moduleId) {
69
- var cachedModule = __webpack_module_cache__[moduleId];
70
- if (cachedModule !== undefined) {
71
- return cachedModule.exports;
72
- }
73
- var module = (__webpack_module_cache__[moduleId] = { exports: {} });
74
- var threw = true;
75
- try {
76
- __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
77
- threw = false;
78
- } finally {
79
- if (threw) delete __webpack_module_cache__[moduleId];
80
- }
81
- return module.exports;
82
- }
4
+ var __nccwpck_require__ = {};
83
5
  (() => {
84
6
  __nccwpck_require__.d = (exports, definition) => {
85
7
  for (var key in definition) {
@@ -147,7 +69,61 @@ const node_logger_namespaceObject = node_logger_x({
147
69
  ["logger"]: () =>
148
70
  __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__.logger,
149
71
  });
150
- var dist = __nccwpck_require__(980);
72
+ function dedent(templ) {
73
+ var values = [];
74
+ for (var _i = 1; _i < arguments.length; _i++) {
75
+ values[_i - 1] = arguments[_i];
76
+ }
77
+ var strings = Array.from(typeof templ === "string" ? [templ] : templ);
78
+ strings[strings.length - 1] = strings[strings.length - 1].replace(
79
+ /\r?\n([\t ]*)$/,
80
+ "",
81
+ );
82
+ var indentLengths = strings.reduce(function (arr, str) {
83
+ var matches = str.match(/\n([\t ]+|(?!\s).)/g);
84
+ if (matches) {
85
+ return arr.concat(
86
+ matches.map(function (match) {
87
+ var _a, _b;
88
+ return (_b =
89
+ (_a = match.match(/[\t ]/g)) === null || _a === void 0
90
+ ? void 0
91
+ : _a.length) !== null && _b !== void 0
92
+ ? _b
93
+ : 0;
94
+ }),
95
+ );
96
+ }
97
+ return arr;
98
+ }, []);
99
+ if (indentLengths.length) {
100
+ var pattern_1 = new RegExp(
101
+ "\n[\t ]{".concat(Math.min.apply(Math, indentLengths), "}"),
102
+ "g",
103
+ );
104
+ strings = strings.map(function (str) {
105
+ return str.replace(pattern_1, "\n");
106
+ });
107
+ }
108
+ strings[0] = strings[0].replace(/^\r?\n/, "");
109
+ var string = strings[0];
110
+ values.forEach(function (value, i) {
111
+ var endentations = string.match(/(?:^|\n)( *)$/);
112
+ var endentation = endentations ? endentations[1] : "";
113
+ var indentedValue = value;
114
+ if (typeof value === "string" && value.includes("\n")) {
115
+ indentedValue = String(value)
116
+ .split("\n")
117
+ .map(function (str, i) {
118
+ return i === 0 ? str : "".concat(endentation).concat(str);
119
+ })
120
+ .join("\n");
121
+ }
122
+ string += indentedValue + strings[i + 1];
123
+ });
124
+ return string;
125
+ }
126
+ const esm = null && dedent;
151
127
  var dist_filename = external_node_url_namespaceObject.fileURLToPath(
152
128
  import.meta.url,
153
129
  );
@@ -170,7 +146,7 @@ var checkWebpackVersion = (webpack, specifier, caption) => {
170
146
  return;
171
147
  }
172
148
  webpack.version !== specifier &&
173
- node_logger_namespaceObject.logger.warn((0, dist.TW)`
149
+ node_logger_namespaceObject.logger.warn(dedent`
174
150
  Unexpected webpack version in ${caption}:
175
151
  - Received '${webpack.version}'
176
152
  - Expected '${specifier}'
@@ -268,7 +244,7 @@ function webpackIncludeRegexp(specifier) {
268
244
  }
269
245
  function toImportFnPart(specifier) {
270
246
  let { directory, importPathMatcher } = specifier;
271
- return (0, dist.TW)`
247
+ return dedent`
272
248
  async (path) => {
273
249
  if (!${importPathMatcher}.exec(path)) {
274
250
  return;
@@ -289,7 +265,7 @@ function toImportFn(stories, { needPipelinedImport } = {}) {
289
265
  return (
290
266
  needPipelinedImport &&
291
267
  (pipelinedImport = `\n const importPipeline = ${importPipeline};\n const pipeline = importPipeline();\n `),
292
- (0, dist.TW)`
268
+ dedent`
293
269
  ${pipelinedImport}
294
270
 
295
271
  const importers = [
@@ -1 +1 @@
1
- {"name":"@storybook/core-webpack","version":"10.3.5","funding":{"type":"opencollective","url":"https://opencollective.com/storybook"},"license":"MIT","types":"index.d.ts","type":"module"}
1
+ {"name":"@storybook/core-webpack","version":"10.5.5","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_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as rsbuildReal from '@rsbuild/core';
2
2
  import { DevConfig, RsbuildConfig } from '@rsbuild/core';
3
- import { BuilderResult as BuilderResult$1, Builder, Options, StorybookConfigRaw, TypescriptOptions as TypescriptOptions$1 } from 'storybook/internal/types';
3
+ import { BuilderResult as BuilderResult$1, Builder, Options, StorybookConfigRaw, TypescriptOptions as TypescriptOptions$1, NormalizedStoriesSpecifier } from 'storybook/internal/types';
4
4
  import { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
5
5
 
6
6
  type RsbuildStats = {
@@ -48,6 +48,19 @@ interface BuilderResult extends BuilderResult$1 {
48
48
  stats?: Stats;
49
49
  }
50
50
 
51
+ /**
52
+ * Re-assert Storybook core's intent to keep `node_modules` out of the stories
53
+ * context. Core's `(?!.*node_modules)` guard relies on webpack's context
54
+ * dropping `node_modules`; Rspack's `ContextModule` enumerates it, so a
55
+ * dependency shipping `.stories.*` gets swept in. We append a separator-anchored
56
+ * `webpackExclude` to every generated `webpackInclude`, except specifiers that
57
+ * intentionally glob into `node_modules` (real segment or alternation branch) —
58
+ * matching the webpack builder, which surfaces those.
59
+ *
60
+ * TODO: remove once the upstream Rspack fix ships in a released `@rspack/core`
61
+ * — https://github.com/web-infra-dev/rspack/pull/14576.
62
+ */
63
+ declare const excludeNodeModulesFromStoryContext: (importFnSource: string, stories: NormalizedStoriesSpecifier[]) => string;
51
64
  declare const getVirtualModules: (options: Options) => Promise<{
52
65
  virtualModules: Record<string, string>;
53
66
  entries: string[];
@@ -64,10 +77,18 @@ declare const executor: {
64
77
  };
65
78
  declare const getConfig: RsbuildBuilder['getConfig'];
66
79
  declare function bail(): Promise<void>;
80
+ /**
81
+ * Returns a {@link ChangeDetectionAdapter} bound to the Rspack compiler created by `start()`.
82
+ *
83
+ * Storybook core only invokes this after `start()` has resolved, so `activeCompiler` is populated
84
+ * in practice. The guard is defensive: it fails loudly on an unexpected call-before-start rather
85
+ * than silently binding to an undefined compiler.
86
+ */
87
+ declare const changeDetectionAdapter: NonNullable<RsbuildBuilder['changeDetectionAdapter']>;
67
88
  declare const start: RsbuildBuilder['start'];
68
89
  declare const build: ({ options }: BuilderStartOptions) => Promise<Stats>;
69
90
  declare const corePresets: string[];
70
91
  declare const previewMainTemplate: () => string;
71
92
 
72
- export { bail, build, corePresets, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start };
93
+ export { bail, build, changeDetectionAdapter, corePresets, excludeNodeModulesFromStoryContext, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start };
73
94
  export type { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.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-L73IVHZJ.js";
16
+ } from "./_node-chunks/chunk-NXNFA2RX.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({
@@ -41,6 +41,66 @@ import sirv from "sirv";
41
41
  import { getPresets, resolveAddonName } from "storybook/internal/common";
42
42
  import { WebpackInvocationError } from "storybook/internal/server-errors";
43
43
 
44
+ // src/change-detection-adapter/index.ts
45
+ import { normalize } from "pathe";
46
+ import { logger } from "storybook/internal/node-logger";
47
+ function createRspackChangeDetectionAdapter(compiler) {
48
+ return {
49
+ async getResolveConfig() {
50
+ let resolveOpts = compiler.options.resolve;
51
+ return {
52
+ projectRoot: compiler.context,
53
+ alias: normaliseRspackAlias(resolveOpts.alias),
54
+ conditions: resolveOpts.conditionNames
55
+ };
56
+ },
57
+ onFileChange(handler) {
58
+ let active = !0, seeded = !1, seenFiles = /* @__PURE__ */ new Set();
59
+ return compiler.hooks.afterCompile.tap(
60
+ "StorybookChangeDetection",
61
+ (compilation) => {
62
+ for (let filePath of compilation.fileDependencies)
63
+ seenFiles.add(normalize(filePath));
64
+ seeded = !0;
65
+ }
66
+ ), compiler.hooks.watchRun.tap(
67
+ "StorybookChangeDetection",
68
+ (watchingCompiler) => {
69
+ if (active) {
70
+ for (let filePath of watchingCompiler.modifiedFiles ?? []) {
71
+ let path = normalize(filePath), kind = seeded && !seenFiles.has(path) ? "add" : "change";
72
+ seenFiles.add(path), handler({ kind, path });
73
+ }
74
+ for (let filePath of watchingCompiler.removedFiles ?? []) {
75
+ let path = normalize(filePath);
76
+ seenFiles.delete(path), handler({ kind: "unlink", path });
77
+ }
78
+ }
79
+ }
80
+ ), () => {
81
+ active = !1;
82
+ };
83
+ }
84
+ };
85
+ }
86
+ function normaliseRspackAlias(alias) {
87
+ if (!alias) return;
88
+ let record = {};
89
+ for (let [key, value] of Object.entries(alias))
90
+ if (typeof value == "string")
91
+ record[key] = value;
92
+ else if (Array.isArray(value)) {
93
+ let stringValues = value.filter(
94
+ (item) => typeof item == "string"
95
+ ), replacement = stringValues[0];
96
+ if (replacement == null) continue;
97
+ stringValues.length > 1 && logger.debug(
98
+ `Change detection: Rspack alias "${key}" has ${stringValues.length} values; using only the first: "${replacement}"`
99
+ ), record[key] = replacement;
100
+ }
101
+ return Object.keys(record).length > 0 ? record : void 0;
102
+ }
103
+
44
104
  // src/chromatic-stats.ts
45
105
  import { isAbsolute, relative } from "node:path";
46
106
  var isRecord = (val) => val != null && typeof val == "object" && Array.isArray(val) === !1, toPosixPath = (filePath) => filePath.split("\\").join("/"), toNormalizedModulePath = (modulePath) => typeof modulePath != "string" || modulePath.length === 0 ? null : isAbsolute(modulePath) ? toPosixPath(relative(process.cwd(), modulePath)) : toPosixPath(modulePath), toAbsolutePathFromIdentifier = (identifier) => {
@@ -136,20 +196,20 @@ var isRecord = (val) => val != null && typeof val == "object" && Array.isArray(v
136
196
  // src/logger.ts
137
197
  import { logger as rsbuildLogger } from "@rsbuild/core";
138
198
  import picocolors from "picocolors";
139
- import { logger } from "storybook/internal/node-logger";
199
+ import { logger as logger2 } from "storybook/internal/node-logger";
140
200
  function overrideRsbuildLogger() {
141
201
  let logWithPrefix = (fn) => (msg) => fn(
142
202
  `${picocolors.black(picocolors.bgBlueBright("Rsbuild"))} ${String(msg)}`
143
203
  );
144
204
  rsbuildLogger.override({
145
- error: logWithPrefix(logger.error),
146
- warn: logWithPrefix(logger.warn),
147
- info: logWithPrefix((msg) => logger.log(msg, { spacing: 0 })),
148
- start: logWithPrefix(logger.info),
149
- ready: logWithPrefix(logger.info),
150
- success: logWithPrefix(logger.info),
151
- log: logWithPrefix(logger.info),
152
- debug: logWithPrefix(logger.debug)
205
+ error: logWithPrefix(logger2.error),
206
+ warn: logWithPrefix(logger2.warn),
207
+ info: logWithPrefix((msg) => logger2.log(msg, { spacing: 0 })),
208
+ start: logWithPrefix(logger2.info),
209
+ ready: logWithPrefix(logger2.info),
210
+ success: logWithPrefix(logger2.info),
211
+ log: logWithPrefix(logger2.info),
212
+ debug: logWithPrefix(logger2.debug)
153
213
  });
154
214
  }
155
215
 
@@ -167,9 +227,9 @@ import {
167
227
  normalizeStories as normalizeStories2,
168
228
  stringifyProcessEnvs
169
229
  } from "storybook/internal/common";
170
- import { logger as logger3 } from "storybook/internal/node-logger";
230
+ import { logger as logger4 } from "storybook/internal/node-logger";
171
231
  import { globalsNameReferenceMap } from "storybook/internal/preview/globals";
172
- import { dedent } from "ts-dedent";
232
+ import { dedent as dedent2 } from "ts-dedent";
173
233
 
174
234
  // src/preview/detect-msw.ts
175
235
  import { existsSync } from "node:fs";
@@ -205,65 +265,7 @@ import {
205
265
  import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
206
266
  import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_common_7991bda6__ from "storybook/internal/common";
207
267
  import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__ from "storybook/internal/node-logger";
208
- var __webpack_modules__ = {
209
- 980: (__unused_webpack_module, exports) => {
210
- var __webpack_unused_export__;
211
- __webpack_unused_export__ = { value: !0 }, exports.TW = void 0;
212
- function dedent2(templ) {
213
- for (var values = [], _i = 1; _i < arguments.length; _i++)
214
- values[_i - 1] = arguments[_i];
215
- var strings = Array.from(typeof templ == "string" ? [templ] : templ);
216
- strings[strings.length - 1] = strings[strings.length - 1].replace(
217
- /\r?\n([\t ]*)$/,
218
- ""
219
- );
220
- var indentLengths = strings.reduce(function(arr, str) {
221
- var matches = str.match(/\n([\t ]+|(?!\s).)/g);
222
- return matches ? arr.concat(
223
- matches.map(function(match) {
224
- var _a, _b;
225
- return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
226
- })
227
- ) : arr;
228
- }, []);
229
- if (indentLengths.length) {
230
- var pattern_1 = new RegExp(
231
- `
232
- [ ]{` + Math.min.apply(Math, indentLengths) + "}",
233
- "g"
234
- );
235
- strings = strings.map(function(str) {
236
- return str.replace(pattern_1, `
237
- `);
238
- });
239
- }
240
- strings[0] = strings[0].replace(/^\r?\n/, "");
241
- var string = strings[0];
242
- return values.forEach(function(value, i) {
243
- var endentations = string.match(/(?:^|\n)( *)$/), endentation = endentations ? endentations[1] : "", indentedValue = value;
244
- typeof value == "string" && value.includes(`
245
- `) && (indentedValue = String(value).split(`
246
- `).map(function(str, i2) {
247
- return i2 === 0 ? str : "" + endentation + str;
248
- }).join(`
249
- `)), string += indentedValue + strings[i + 1];
250
- }), string;
251
- }
252
- exports.TW = dedent2, __webpack_unused_export__ = dedent2;
253
- }
254
- }, __webpack_module_cache__ = {};
255
- function __nccwpck_require__(moduleId) {
256
- var cachedModule = __webpack_module_cache__[moduleId];
257
- if (cachedModule !== void 0)
258
- return cachedModule.exports;
259
- var module = __webpack_module_cache__[moduleId] = { exports: {} }, threw = !0;
260
- try {
261
- __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__), threw = !1;
262
- } finally {
263
- threw && delete __webpack_module_cache__[moduleId];
264
- }
265
- return module.exports;
266
- }
268
+ var __nccwpck_require__ = {};
267
269
  __nccwpck_require__.d = (exports, definition) => {
268
270
  for (var key in definition)
269
271
  __nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key) && Object.defineProperty(exports, key, {
@@ -306,7 +308,48 @@ var common_namespaceObject = x({
306
308
  };
307
309
  var node_logger_namespaceObject = node_logger_x({
308
310
  logger: () => __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__.logger
309
- }), dist = __nccwpck_require__(980), dist_filename = external_node_url_namespaceObject.fileURLToPath(
311
+ });
312
+ function dedent(templ) {
313
+ for (var values = [], _i = 1; _i < arguments.length; _i++)
314
+ values[_i - 1] = arguments[_i];
315
+ var strings = Array.from(typeof templ == "string" ? [templ] : templ);
316
+ strings[strings.length - 1] = strings[strings.length - 1].replace(
317
+ /\r?\n([\t ]*)$/,
318
+ ""
319
+ );
320
+ var indentLengths = strings.reduce(function(arr, str) {
321
+ var matches = str.match(/\n([\t ]+|(?!\s).)/g);
322
+ return matches ? arr.concat(
323
+ matches.map(function(match) {
324
+ var _a, _b;
325
+ return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
326
+ })
327
+ ) : arr;
328
+ }, []);
329
+ if (indentLengths.length) {
330
+ var pattern_1 = new RegExp(
331
+ `
332
+ [ ]{`.concat(Math.min.apply(Math, indentLengths), "}"),
333
+ "g"
334
+ );
335
+ strings = strings.map(function(str) {
336
+ return str.replace(pattern_1, `
337
+ `);
338
+ });
339
+ }
340
+ strings[0] = strings[0].replace(/^\r?\n/, "");
341
+ var string = strings[0];
342
+ return values.forEach(function(value, i) {
343
+ var endentations = string.match(/(?:^|\n)( *)$/), endentation = endentations ? endentations[1] : "", indentedValue = value;
344
+ typeof value == "string" && value.includes(`
345
+ `) && (indentedValue = String(value).split(`
346
+ `).map(function(str, i2) {
347
+ return i2 === 0 ? str : "".concat(endentation).concat(str);
348
+ }).join(`
349
+ `)), string += indentedValue + strings[i + 1];
350
+ }), string;
351
+ }
352
+ var dist_filename = external_node_url_namespaceObject.fileURLToPath(
310
353
  import.meta.url
311
354
  ), dist_dirname = external_node_path_namespaceObject.dirname(dist_filename), dist_require = external_node_module_namespaceObject.createRequire(
312
355
  import.meta.url
@@ -321,7 +364,7 @@ var node_logger_namespaceObject = node_logger_x({
321
364
  );
322
365
  return;
323
366
  }
324
- webpack.version !== specifier && node_logger_namespaceObject.logger.warn((0, dist.TW)`
367
+ webpack.version !== specifier && node_logger_namespaceObject.logger.warn(dedent`
325
368
  Unexpected webpack version in ${caption}:
326
369
  - Received '${webpack.version}'
327
370
  - Expected '${specifier}'
@@ -390,7 +433,7 @@ function webpackIncludeRegexp(specifier) {
390
433
  }
391
434
  function toImportFnPart(specifier) {
392
435
  let { directory, importPathMatcher } = specifier;
393
- return (0, dist.TW)`
436
+ return dedent`
394
437
  async (path) => {
395
438
  if (!${importPathMatcher}.exec(path)) {
396
439
  return;
@@ -411,7 +454,7 @@ function toImportFn(stories, { needPipelinedImport } = {}) {
411
454
  return needPipelinedImport && (pipelinedImport = `
412
455
  const importPipeline = ${importPipeline};
413
456
  const pipeline = importPipeline();
414
- `), (0, dist.TW)`
457
+ `), dedent`
415
458
  ${pipelinedImport}
416
459
 
417
460
  const importers = [
@@ -442,7 +485,26 @@ var toRequireContext = (specifier) => {
442
485
  }, __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;
443
486
 
444
487
  // src/preview/virtual-module-mapping.ts
445
- var getVirtualModules = async (options) => {
488
+ var NODE_MODULES_GLOB_TOKEN = /(?:^|[\\/(|,{])node_modules(?:$|[\\/)|,}])/, toWebpackIncludeGlob = ({
489
+ directory,
490
+ files
491
+ }) => [".", ".."].includes(directory) ? files : `${directory.replace(/^(\.+\/)+/, "/")}/${files}`, targetsNodeModules = (specifier) => NODE_MODULES_GLOB_TOKEN.test(toWebpackIncludeGlob(specifier)), excludeNodeModulesFromStoryContext = (importFnSource, stories) => {
492
+ let specifierIndex = 0;
493
+ return importFnSource.split(`
494
+ `).flatMap((line) => {
495
+ if (!line.includes("webpackInclude:"))
496
+ return [line];
497
+ let specifier = stories[specifierIndex++];
498
+ if (specifier && targetsNodeModules(specifier))
499
+ return [line];
500
+ let indent = line.slice(0, line.length - line.trimStart().length);
501
+ return [
502
+ line,
503
+ `${indent}/* webpackExclude: /[\\\\/]node_modules[\\\\/]/ */`
504
+ ];
505
+ }).join(`
506
+ `);
507
+ }, getVirtualModules = async (options) => {
446
508
  let virtualModules = {}, builderOptions = await getBuilderOptions(options), workingDir = process.cwd(), isProd = options.configType === "PRODUCTION", nonNormalizedStories = await options.presets.apply("stories", []), entries = [], stories = normalizeStories(nonNormalizedStories, {
447
509
  configDir: options.configDir,
448
510
  workingDir
@@ -454,9 +516,12 @@ var getVirtualModules = async (options) => {
454
516
  )).map((entry) => typeof entry == "object" ? entry.absolute : slash(entry)),
455
517
  loadPreviewOrConfigFile(options)
456
518
  ].filter(Boolean), storiesFilename = "storybook-stories.js", storiesPath = resolve2(join(workingDir, storiesFilename)), needPipelinedImport = builderOptions.lazyCompilation !== !1 && !isProd;
457
- virtualModules[storiesPath] = __webpack_exports__toImportFn(stories, {
458
- needPipelinedImport
459
- });
519
+ virtualModules[storiesPath] = excludeNodeModulesFromStoryContext(
520
+ __webpack_exports__toImportFn(stories, {
521
+ needPipelinedImport
522
+ }),
523
+ stories
524
+ );
460
525
  let configEntryPath = resolve2(join(workingDir, "storybook-config-entry.js"));
461
526
  return virtualModules[configEntryPath] = (await readTemplate(
462
527
  __require.resolve(
@@ -533,7 +598,8 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
533
598
  nonNormalizedStories,
534
599
  _modulesCount,
535
600
  build2,
536
- tagsOptions
601
+ tagsOptions,
602
+ htmlLang
537
603
  ] = await Promise.all([
538
604
  presets.apply("core"),
539
605
  presets.apply("frameworkOptions"),
@@ -547,12 +613,13 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
547
613
  presets.apply("stories", []),
548
614
  options.cache?.get("modulesCount", 1e3),
549
615
  options.presets.apply("build"),
550
- presets.apply("tags", {})
616
+ presets.apply("tags", {}),
617
+ presets.apply("htmlLang", "en")
551
618
  ]), stories = normalizeStories2(nonNormalizedStories, {
552
619
  configDir: options.configDir,
553
620
  workingDir
554
621
  }), shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler, tsCheckOptions = typescriptOptions.checkOptions || {}, builderOptions = await getBuilderOptions2(options), cacheConfig = builderOptions.fsCache ? !0 : void 0, shouldDisableDevFeatures = process.env.SB_RSBUILD_TEST_MINIMAL_DEV === "true", lazyCompilationConfig;
555
- isProd || (shouldDisableDevFeatures ? lazyCompilationConfig = !1 : builderOptions.lazyCompilation !== void 0 ? lazyCompilationConfig = builderOptions.lazyCompilation : await isMswActive(options) ? (lazyCompilationConfig = !1, logger3.warn(dedent`
622
+ isProd || (shouldDisableDevFeatures ? lazyCompilationConfig = !1 : builderOptions.lazyCompilation !== void 0 ? lazyCompilationConfig = builderOptions.lazyCompilation : await isMswActive(options) ? (lazyCompilationConfig = !1, logger4.warn(dedent2`
556
623
  Detected mockServiceWorker.js in staticDirs. Lazy compilation has been disabled
557
624
  automatically to avoid a Service Worker race that can leave the preview iframe
558
625
  blank on cold story loads. Set \`lazyCompilation\` explicitly in your builder
@@ -562,14 +629,14 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
562
629
  });
563
630
  let shouldDisableHmr = shouldDisableDevFeatures;
564
631
  if (!template)
565
- throw new Error(dedent`
632
+ throw new Error(dedent2`
566
633
  Storybook's Webpack5 builder requires a template to be specified.
567
634
  Somehow you've ended up with a falsy value for the template option.
568
635
 
569
636
  Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
570
637
  `);
571
638
  let externals = globalsNameReferenceMap;
572
- build2?.test?.disableBlocks && (externals["@storybook/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__");
639
+ build2?.test?.disableBlocks && (externals["@storybook/addon-docs/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__");
573
640
  let { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options), contentFromConfig = {}, { content } = await loadConfig({
574
641
  cwd: workingDir,
575
642
  path: rsbuildConfigPath
@@ -613,7 +680,28 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
613
680
  css: !options.build?.test?.disableSourcemaps
614
681
  },
615
682
  distPath: {
616
- root: resolve3(process.cwd(), outputDir)
683
+ root: resolve3(process.cwd(), outputDir),
684
+ // Flat output, matching the official webpack5 builder. With
685
+ // `assetPrefix: ''` every context resolves relative URLs against
686
+ // itself, so nesting breaks worker chunks and CSS url(). See the
687
+ // "Preview Output Layout" docs section (#522).
688
+ //
689
+ // Load-bearing — these four carry the relative URLs that break:
690
+ js: "",
691
+ jsAsync: "",
692
+ // does not inherit `js`, must be explicit
693
+ css: "",
694
+ cssAsync: "",
695
+ // does not inherit `css`, must be explicit
696
+ // Parity with the webpack5 builder's flat layout. `filename` stacks on
697
+ // top of `distPath`, so image/font/media still land under the
698
+ // `static/media/` prefix set below.
699
+ svg: "",
700
+ font: "",
701
+ image: "",
702
+ media: "",
703
+ wasm: "",
704
+ assets: ""
617
705
  },
618
706
  filename: {
619
707
  js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
@@ -696,7 +784,13 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
696
784
  ...config.resolve.extensions ?? [],
697
785
  ...builtInResolveExtensions
698
786
  ])
699
- ), config.watchOptions = {
787
+ ), config.resolve.conditionNames = [
788
+ ...config.resolve.conditionNames ?? [],
789
+ "storybook",
790
+ "stories",
791
+ "test",
792
+ "..."
793
+ ], config.watchOptions = {
700
794
  ignored: /node_modules/
701
795
  }, config.ignoreWarnings = [
702
796
  ...config.ignoreWarnings || [],
@@ -761,6 +855,7 @@ var require2 = createRequire(import.meta.url), getAbsolutePath = (input) => {
761
855
  TAGS_OPTIONS: tagsOptions,
762
856
  ...build2?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {}
763
857
  },
858
+ htmlLang,
764
859
  headHtmlSnippet,
765
860
  bodyHtmlSnippet
766
861
  }
@@ -848,11 +943,17 @@ var rsbuild = async (_, options) => {
848
943
  typescriptOptions,
849
944
  frameworkOptions
850
945
  });
851
- }, server;
946
+ }, server, activeCompiler;
852
947
  async function bail() {
853
- return server?.close();
948
+ return activeCompiler = void 0, server?.close();
854
949
  }
855
- var start = async ({
950
+ var changeDetectionAdapter = () => {
951
+ if (!activeCompiler)
952
+ throw new Error(
953
+ "builder-rsbuild: changeDetectionAdapter() called before start(); the Rspack compiler is not ready yet."
954
+ );
955
+ return createRspackChangeDetectionAdapter(activeCompiler);
956
+ }, start = async ({
856
957
  startTime,
857
958
  options,
858
959
  router,
@@ -871,7 +972,11 @@ var start = async ({
871
972
  printUrls: !1
872
973
  }
873
974
  }
874
- }), rsbuildServer = await rsbuildBuild.createDevServer(), waitFirstCompileDone = new Promise((resolve4) => {
975
+ });
976
+ rsbuildBuild.onAfterCreateCompiler(({ compiler }) => {
977
+ activeCompiler = "compilers" in compiler ? compiler.compilers[0] : compiler;
978
+ });
979
+ let rsbuildServer = await rsbuildBuild.createDevServer(), waitFirstCompileDone = new Promise((resolve4) => {
875
980
  rsbuildBuild.onDevCompileDone(({ stats: stats2, isFirstCompile }) => {
876
981
  isFirstCompile && resolve4(stats2);
877
982
  });
@@ -923,7 +1028,9 @@ function getRandomPort(host) {
923
1028
  export {
924
1029
  bail,
925
1030
  build,
1031
+ changeDetectionAdapter,
926
1032
  corePresets,
1033
+ excludeNodeModulesFromStoryContext,
927
1034
  executor,
928
1035
  getConfig,
929
1036
  getVirtualModules,
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.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-L73IVHZJ.js";
12
+ import "../_node-chunks/chunk-NXNFA2RX.js";
13
13
 
14
14
  // src/loaders/export-order-loader.ts
15
15
  import assert from "node:assert";
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.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-L73IVHZJ.js";
12
+ import "../_node-chunks/chunk-NXNFA2RX.js";
13
13
 
14
14
  // src/loaders/rsbuild-automock-loader.ts
15
15
  import { babelParser, getAutomockCode } from "storybook/internal/mocking-utils";
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.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-L73IVHZJ.js";
12
+ import "../_node-chunks/chunk-NXNFA2RX.js";
13
13
 
14
14
  // src/loaders/storybook-mock-transform-loader.ts
15
15
  import { rewriteSbMockImportCalls } from "storybook/internal/mocking-utils";
@@ -1,15 +1,15 @@
1
- import CJS_COMPAT_NODE_URL_9822f21edcc46e85 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_9822f21edcc46e85 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_9822f21edcc46e85 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_95ee734c542e82b6 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_95ee734c542e82b6 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_95ee734c542e82b6 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_9822f21edcc46e85.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_9822f21edcc46e85.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_9822f21edcc46e85.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_95ee734c542e82b6.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_95ee734c542e82b6.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_95ee734c542e82b6.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-L73IVHZJ.js";
12
+ import "./_node-chunks/chunk-NXNFA2RX.js";
13
13
 
14
14
  // src/preview-preset.ts
15
15
  import { createRequire } from "node:module";
@@ -19,6 +19,9 @@ import { findConfigFile } from "storybook/internal/common";
19
19
  // src/plugins/rspack-inject-mocker-runtime-plugin.ts
20
20
  import { getMockerRuntime } from "storybook/internal/mocking-utils";
21
21
  var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePlugin = class {
22
+ constructor() {
23
+ this.cachedRuntime = null;
24
+ }
22
25
  getHtmlPlugin(compiler) {
23
26
  try {
24
27
  return compiler.options.plugins?.find((plugin) => {
@@ -42,15 +45,15 @@ var PLUGIN_NAME = "RspackInjectMockerRuntimePlugin", RspackInjectMockerRuntimePl
42
45
  PLUGIN_NAME,
43
46
  (data, cb) => {
44
47
  try {
45
- let runtimeScriptContent = getMockerRuntime(), runtimeAssetName = "mocker-runtime-injected.js", Sources = compiler.webpack?.sources;
48
+ let runtimeScriptContent = this.cachedRuntime ?? (this.cachedRuntime = getMockerRuntime()), runtimeAssetName = "mocker-runtime-injected.js", Sources = compiler.webpack?.sources;
46
49
  if (!Sources?.RawSource)
47
50
  throw new Error(
48
51
  "rspack sources is not available on compiler.webpack"
49
52
  );
50
- compilation.emitAsset(
53
+ compilation.getAsset(runtimeAssetName) || (compilation.emitAsset(
51
54
  runtimeAssetName,
52
55
  new Sources.RawSource(runtimeScriptContent)
53
- ), data.assets.js.unshift(runtimeAssetName), cb(null, data);
56
+ ), data.assets.js.unshift(runtimeAssetName)), cb(null, data);
54
57
  } catch (error) {
55
58
  cb(error);
56
59
  }
@@ -79,22 +82,32 @@ function normalizePath(filePath) {
79
82
  var RspackMockPlugin = class {
80
83
  constructor(options) {
81
84
  this.mockMap = /* @__PURE__ */ new Map();
85
+ this.candidateSpecifiers = /* @__PURE__ */ new Set();
82
86
  if (!options.previewConfigPath)
83
87
  throw new Error(`[${PLUGIN_NAME2}] \`previewConfigPath\` is required.`);
84
88
  this.options = options;
85
89
  }
86
90
  apply(compiler) {
87
91
  let logger = compiler.getInfrastructureLogger(PLUGIN_NAME2), updateMocks = () => {
92
+ let mTimePreviewConfig = this.getPreviewConfigMtime(compiler);
93
+ if (this.lastPreviewMtime !== void 0 && mTimePreviewConfig !== void 0 && mTimePreviewConfig === this.lastPreviewMtime)
94
+ return;
95
+ let resolved = this.extractAndResolveMocks(compiler);
88
96
  this.mockMap = new Map(
89
- this.extractAndResolveMocks(compiler).flatMap((mock) => [
97
+ resolved.flatMap((mock) => [
90
98
  [normalizePath(mock.absolutePath), mock],
91
99
  [normalizePath(mock.absolutePath.replace(/\.[^.]+$/, "")), mock]
92
100
  ])
93
- ), logger.info(`Mock map updated with ${this.mockMap.size / 2} mocks.`);
101
+ ), this.candidateSpecifiers = new Set(resolved.map((mock) => mock.path)), this.lastPreviewMtime = mTimePreviewConfig, resolved.length > 0 && logger.info(`Mock map updated with ${resolved.length} mocks.`);
94
102
  };
95
103
  compiler.hooks.beforeRun.tap(PLUGIN_NAME2, updateMocks), compiler.hooks.watchRun.tap(PLUGIN_NAME2, updateMocks), new rspack.NormalModuleReplacementPlugin(/.*/, (resource) => {
96
104
  try {
97
- let path = resource.request, importer = resource.context, absolutePath = getIsExternal(path, importer) ? resolveExternalModule(path, importer) : resolveWithExtensions(path, importer), normalizedAbsolutePath = normalizePath(absolutePath);
105
+ if (this.mockMap.size === 0)
106
+ return;
107
+ let path = resource.request, importer = resource.context, isExternal = getIsExternal(path, importer);
108
+ if (isExternal && !this.candidateSpecifiers.has(path))
109
+ return;
110
+ let absolutePath = isExternal ? resolveExternalModule(path, importer) : resolveWithExtensions(path, importer), normalizedAbsolutePath = normalizePath(absolutePath);
98
111
  this.mockMap.has(normalizedAbsolutePath) && (resource.request = this.mockMap.get(
99
112
  normalizedAbsolutePath
100
113
  ).replacementResource);
@@ -107,6 +120,13 @@ var RspackMockPlugin = class {
107
120
  isAbsolute(mock.replacementResource) && mock.replacementResource.includes("__mocks__") && compilation.contextDependencies.add(dirname(mock.replacementResource));
108
121
  });
109
122
  }
123
+ getPreviewConfigMtime(compiler) {
124
+ try {
125
+ return compiler.inputFileSystem.statSync?.(this.options.previewConfigPath)?.mtime?.getTime?.();
126
+ } catch {
127
+ return;
128
+ }
129
+ }
110
130
  extractAndResolveMocks(compiler) {
111
131
  let { previewConfigPath, configDir } = this.options, logger = compiler.getInfrastructureLogger(PLUGIN_NAME2), mocks = extractMockCalls(
112
132
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "3.3.4",
3
+ "version": "3.4.0",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -43,42 +43,43 @@
43
43
  "!src/**/*"
44
44
  ],
45
45
  "dependencies": {
46
- "@rsbuild/plugin-type-check": "^1.3.4",
47
- "@vitest/mocker": "3.2.4",
46
+ "@rsbuild/plugin-type-check": "^1.6.0",
47
+ "@vitest/mocker": "3.2.7",
48
48
  "browser-assert": "^1.2.1",
49
49
  "case-sensitive-paths-webpack-plugin": "^2.4.0",
50
50
  "cjs-module-lexer": "^2.2.0",
51
51
  "constants-browserify": "^1.0.0",
52
52
  "es-module-lexer": "^1.7.0",
53
- "fs-extra": "^11.3.5",
53
+ "fs-extra": "^11.4.0",
54
54
  "magic-string": "^0.30.21",
55
55
  "path-browserify": "^1.0.1",
56
+ "pathe": "^2.0.3",
56
57
  "picocolors": "^1.1.1",
57
58
  "process": "^0.11.10",
58
- "rsbuild-plugin-html-minifier-terser": "^1.1.3",
59
+ "rsbuild-plugin-html-minifier-terser": "^1.1.5",
59
60
  "sirv": "^2.0.4",
60
- "ts-dedent": "^2.2.0",
61
+ "ts-dedent": "^2.3.0",
61
62
  "url": "^0.11.4",
62
63
  "util": "^0.12.5",
63
64
  "util-deprecate": "^1.0.2"
64
65
  },
65
66
  "devDependencies": {
66
- "@rsbuild/core": "^2.0.5",
67
- "@storybook/core-webpack": "10.3.5",
67
+ "@rsbuild/core": "^2.1.9",
68
+ "@storybook/core-webpack": "10.5.5",
68
69
  "@types/fs-extra": "^11.0.4",
69
70
  "@types/node": "^22.0.0",
70
71
  "@types/pretty-hrtime": "^1.0.3",
71
- "prebundle": "^1.6.4",
72
+ "prebundle": "^1.6.5",
72
73
  "pretty-hrtime": "^1.0.3",
73
74
  "slash": "^5.1.0",
74
- "storybook": "10.3.5",
75
+ "storybook": "10.5.5",
75
76
  "typescript": "^5.9.3"
76
77
  },
77
78
  "peerDependencies": {
78
79
  "@rsbuild/core": "^1.5.0 || ^2.0.0-0",
79
80
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
80
81
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
81
- "storybook": "^10.3.5"
82
+ "storybook": "^10.5.5"
82
83
  },
83
84
  "peerDependenciesMeta": {
84
85
  "react": {
@@ -1,5 +1,5 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en">
2
+ <html lang="<%= htmlLang %>">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <title><%= htmlWebpackPlugin.options.title || 'Storybook'%></title>
@@ -28,7 +28,6 @@ const preview = new PreviewWeb(importFn, getProjectAnnotations)
28
28
 
29
29
  window.__STORYBOOK_PREVIEW__ = preview
30
30
  window.__STORYBOOK_STORY_STORE__ = preview.storyStore
31
- window.__STORYBOOK_ADDONS_CHANNEL__ = channel
32
31
 
33
32
  if (import.meta.webpackHot) {
34
33
  import.meta.webpackHot.addStatusHandler((status) => {